forked from bowanddrape/php-taxcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smoketest.php
168 lines (137 loc) · 4.11 KB
/
smoketest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/**
* This is not an exhaustive test.
*
* The purpose of the smoketest is to quickly identify if something has broken
* integration with the TaxCloud API. The smoketest goes through the process
* required by TaxCloud and actually makes connections to TaxCloud.
*/
// API credentials loaded from environment variables.
$apiLoginID = $_ENV["TaxCloud_apiLoginID"];
$apiKey = $_ENV["TaxCloud_apiKey"];
$uspsUserID = $_ENV["TaxCloud_uspsUserID"];
// Some variable that need to be unique, but can't change.
$orderID = rand();
$cartID = rand(1, 999);
/**
* Show us what step we are on.
*/
function step($message) {
global $STEPCOUNTER;
printf("\nStep %d. %s\n", $STEPCOUNTER++, sprintf($message));
}
require_once 'lib/php-taxcloud.php';
$client = new \TaxCloud\Client();
step('Ping');
$pingParams = new \TaxCloud\Request\Ping($apiLoginID, $apiKey);
try {
$client->Ping($pingParams);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
step('Get TICs');
$params = new \TaxCloud\Request\GetTICs($apiLoginID, $apiKey);
try {
$client->GetTICs($params);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
step('GetTICGroups');
$params = new \TaxCloud\Request\GetTICGroups($apiLoginID, $apiKey);
try {
$client->getTICGroups($params);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
step('Get TICs By Group');
$params = new \TaxCloud\Request\GetTICsByGroup($apiLoginID, $apiKey, 10000);
try {
$client->GetTICsByGroup($params);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
step('Cart Item');
$cartItems = array();
$cartItem = new \TaxCloud\CartItem($cartID + 1, 'ABC123', '00000', 12.00, 1);
$cartItems[] = $cartItem;
print_r($cartItem);
step('Cart Item - Shipping');
$cartItemShipping = new \TaxCloud\CartItem($cartID + 2, 'SHIPPING123', 11010, 8.95, 1);
$cartItems[] = $cartItemShipping;
print_r($cartItemShipping);
step('Cart Items Array');
print_r($cartItems);
step('Verify Address');
$address = new \TaxCloud\Address(
'206 Pike St',
'',
'Atlanta',
'GA',
// Intentionally wrong zip
'98000',
''
);
$verifyAddress = new \TaxCloud\Request\VerifyAddress($uspsUserID, $address);
try {
$address = $client->VerifyAddress($verifyAddress);
}
catch (\TaxCloud\Exceptions\USPSIDException $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
return;
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
step('Lookup');
$originAddress = new \TaxCloud\Address(
$address->getAddress1(),
$address->getAddress2(),
$address->getCity(),
$address->getState(),
$address->getZip5(),
$address->getZip4()
);
$destAddress = new \TaxCloud\Address(
'PO Box 573',
'',
'Clinton',
'OK',
'73601',
''
);
$lookup = new \TaxCloud\Request\Lookup($apiLoginID, $apiKey, '123', $cartID, $cartItems, $originAddress, $destAddress);
try {
$client->Lookup($lookup);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
step('Authorized');
$authorization = new \TaxCloud\Request\Authorized($apiLoginID, $apiKey, '123', $cartID, $cartItems, $orderID, date("c"));
try {
$client->Authorized($authorization);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
step('Captured');
$capture = new \TaxCloud\Request\Captured($apiLoginID, $apiKey, $orderID);
try {
$client->Captured($capture);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
step('Authorized With Capture');
$lookup = new \TaxCloud\Request\Lookup($apiLoginID, $apiKey, '123', $cartID + 1, $cartItems, $originAddress, $destAddress);
$client->Lookup($lookup);
$authcap = new \TaxCloud\Request\AuthorizedWithCapture($apiLoginID, $apiKey, '123', $cartID + 1, $orderID + 1, date("c"), date("c"));
try {
$client->AuthorizedWithCapture($authcap);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
step('Returned');
$return = new \TaxCloud\Request\Returned($apiLoginID, $apiKey, $orderID + 1, $cartItems, date("c"));
try {
$client->Returned($return);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}