This repository has been archived by the owner on Mar 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathordering.php
203 lines (181 loc) · 8.74 KB
/
ordering.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
require './vendor/autoload.php';
use APIv3SandboxLib\Controllers\InventoryController;
use APIv3SandboxLib\Controllers\OrderingController;
use APIv3SandboxLib\Models\CartCreateModel;
use APIv3SandboxLib\Models\CartItemModel;
use APIv3SandboxLib\Models\DidCartItemModel;
use APIv3SandboxLib\Models\CapacityCartItemModel;
use APIv3SandboxLib\Models\CreditPackageCartItemModel;
use APIv3SandboxLib\Models\QuantityModel;
use APIv3SandboxLib\Models\DidIdListModel;
use APIv3SandboxLib\Configuration;
use Unirest\Unirest;
// Ordering Flow 1: Account Balance -> createCart -> AddToCart -> get Order product ID -> RemoveFromCart -> listCart -> CheckoutCart -> cancelDids -> listOrder
// Ordering Flow 2: createCart -> deleteCart
/* Operations used:
Account balance
Create cart x2
Delete Cart
Add to cart
Get cart
Remove from cart
Checkout cart
ListDids (inventory)
Cancel dids
List orders
List Carts
*/
Unirest::auth(Configuration::$BasicAuthUserName, Configuration::$BasicAuthPassword);
$controller = new OrderingController();
$inventoryController = new InventoryController();
try{
$accountBal = $controller->getAccountBalance();
echo "<br/><br/><br/>";
echo "<b>accountBal Response</b><br/>";
$balance = $accountBal->accountBalance->balance;
echo "balance: ".$accountBal->accountBalance->balance."<br/>";
echo "threshold: ".$accountBal->accountBalance->threshold."<br/>";
echo "currency: ".$accountBal->accountBalance->currency."<br/>";
echo "active: ".$accountBal->accountBalance->active."<br/>";
//If account balance high enough -> create cart
if ($balance > 100)
{
//Create Cart
$customerReference = "Cart #1";
$description = "Full Cart Checkout";
$body = new CartCreateModel($customerReference, $description);
$createCart = $controller->updateCart($body);
echo "<br/><br/>";
echo "<b>createCart Response</b><br/>";
echo "cartIdentifier: ".$createCart->cart->cartIdentifier."<br/>";
echo "customerReference: ".$createCart->cart->customerReference."<br/>";
echo "description: ".$createCart->cart->description."<br/>";
echo "dateAdded: ".$createCart->cart->dateAdded."<br/>";
echo "orderProducts: ".$createCart->cart->orderProducts[0]."<br/>";
$cartIdentifier = $createCart->cart->cartIdentifier;
//Create Cart to be deleted
$customerReference2 = "Cart #2";
$description2 = "Will be Deleted";
$body = new CartCreateModel($customerReference2, $description2);
$createCart2 = $controller->updateCart($body);
echo "<br/><br/>";
echo "<b>createCart (to be deleted) Response</b><br/>";
echo "cartIdentifier: ".$createCart2->cart->cartIdentifier."<br/>";
echo "customerReference: ".$createCart2->cart->customerReference."<br/>";
echo "description: ".$createCart2->cart->description."<br/>";
echo "dateAdded: ".$createCart2->cart->dateAdded."<br/>";
echo "orderProducts: ".$createCart2->cart->orderProducts[0]."<br/>";
$cartIdentifier2 = $createCart2->cart->cartIdentifier;
//Delete Cart #2
$deleteCart = $controller->deleteCart($cartIdentifier2);
echo "<br/><br/>";
echo "<b>Delete Cart #2 Response</b><br/>";
echo "status: ".$deleteCart->status."<br/>";
echo $cartIdentifier2." has been deleted.";
//Use cartIdentifier to add to cart
$didGroups = $inventoryController->getDidgroups("DNK",0,1,NULL,NULL,NULL,NULL,NULL,NULL);
$didGroupId = $didGroups->didGroups[0]->didGroupId;
echo $didGroupId;
$quantity = 5;
$didCartItem = new DidCartItemModel($didGroupId, $quantity);
$body = new CartItemModel($didCartItem, NULL, NULL);
$addtoCart = $controller->createCartProduct($cartIdentifier, $body);
echo "<br/><br/>";
echo "<b>addtoCart Response</b><br/>";
echo "status: ".$addtoCart->status."<br/>";
echo "<br/><br/>";
//Get orderProductId for removeCart
$listCart = $controller->getCartDetails($cartIdentifier);
echo "<b>Get orderProductId (listCart) Response</b><br/>";
echo "orderProductId: ".$listCart->carts[0]->orderProducts[0]->orderProductId."<br/>";
echo "orderQuantity: ".$listCart->carts[0]->orderProducts[0]->quantity."<br/>";
echo "<br/><br/><br/>";
$orderProductId = $listCart->carts[0]->orderProducts[0]->orderProductId;
$orderQuantity = $listCart->carts[0]->orderProducts[0]->quantity;
//Remove From Cart
function removeFromTheCart($cartIdentifier, $orderProductId) {
$controller = new OrderingController();
$removequantity = 1;
$body = new QuantityModel($removequantity);
$removeFromCart = $controller->createCartProductRemove($cartIdentifier, $orderProductId, $body);
echo "<b>removeFromCart Response</b><br/>";
echo "status: ".$removeFromCart->status."<br/>";
echo 'removed one item';
echo "<br/><br/><br/>";
};
removeFromTheCart($cartIdentifier, $orderProductId);
//List Cart
$listTheCart = $controller->getCartDetails($cartIdentifier);
echo "<b>Get orderProductId (listCart) Response</b><br/>";
echo "orderProductId: ".$listTheCart->carts[0]->orderProducts[0]->orderProductId."<br/>";
echo "orderQuantity: ".$listTheCart->carts[0]->orderProducts[0]->quantity."<br/>";
echo "<br/><br/>";
//Checkout Cart
$cartCheckout = $controller->getCartCheckout($cartIdentifier);
echo "<b>CheckoutCart Response</b><br/>";
echo "orderReference: ".$cartCheckout->productCheckoutList[0]->orderReference."<br/>";
echo "status: ".$cartCheckout->status."<br/>";
echo "<br/><br/>";
$orderReference = $cartCheckout->productCheckoutList[0]->orderReference;
//Cancel DIDs
//First listDidIds
$getDidIds = $inventoryController->getDids(1, 0, NULL, NULL, NULL, NULL, $orderReference);
echo "<b>Get DID Ordered Response</b><br/>";
echo "didid: ".$getDidIds->dids[0]->didId."<br/>";
$didId = $getDidIds->dids[0]->didId;
echo "<br/><br/>";
$didIds = array($didId);
$body = new DidIdListModel($didIds);
$cancelDids = $controller->createCancel($body);
echo "<b>Get Cancel Response</b><br/>";
echo "numberCancelled: ".$cancelDids->numberCancelled."<br/>";
echo "<br/><br/>";
function listTheOrder($orderReference) {
//List Order
$controller = new OrderingController();
$listOrder = $controller->getOrders(0, 1, $orderReference, NULL, NULL, NULL, NULL, NULL, NULL);
echo "<b>List Order Response</b><br/>";
echo "orderId: ".$listOrder->orders[0]->orderId."<br/>";
echo "reference: ".$listOrder->orders[0]->reference."<br/>";
echo "dateAdded: ".$listOrder->orders[0]->dateAdded."<br/>";
echo "dateCanceled: ".$listOrder->orders[0]->dateCanceled."<br/>";
echo "status: ".$listOrder->orders[0]->status."<br/>";
echo "<br/><br/><br/>";
};
listTheOrder($orderReference);
//List Carts
$listCarts = $controller->getCarts(0,2);
echo "<b>Get List Carts Response: Cart 1</b><br/>";
echo "cartIdentifier: ".$listCarts->carts[0]->cartIdentifier."<br/>";
echo "customerReference: ".$listCarts->carts[0]->customerReference."<br/>";
echo "description: ".$listCarts->carts[0]->description."<br/>";
echo "dateAdded: ".$listCarts->carts[0]->dateAdded."<br/>";
echo "orderProductId: ".$listCarts->carts[0]->orderProducts[0]->orderProductId."<br/>";
echo "productType: ".$listCarts->carts[0]->orderProducts[0]->productType."<br/>";
echo "productDescription: ".$listCarts->carts[0]->orderProducts[0]->productDescription."<br/>";
echo "quantity: ".$listCarts->carts[0]->orderProducts[0]->quantity."<br/>";
echo "didgroupId: ".$listCarts->carts[0]->orderProducts[0]->didgroupId."<br/>";
echo "<br/><br/>";
echo "<b>Get List Carts Response: Cart 2</b><br/>";
echo "cartIdentifier: ".$listCarts->carts[1]->cartIdentifier."<br/>";
echo "customerReference: ".$listCarts->carts[1]->customerReference."<br/>";
echo "description: ".$listCarts->carts[1]->description."<br/>";
echo "dateAdded: ".$listCarts->carts[1]->dateAdded."<br/>";
echo "orderProductId: ".$listCarts->carts[1]->orderProducts[0]->orderProductId."<br/>";
echo "productType: ".$listCarts->carts[1]->orderProducts[0]->productType."<br/>";
echo "productDescription: ".$listCarts->carts[1]->orderProducts[0]->productDescription."<br/>";
echo "quantity: ".$listCarts->carts[1]->orderProducts[0]->quantity."<br/>";
echo "didgroupId: ".$listCarts->carts[1]->orderProducts[0]->didgroupId."<br/>";
echo "<br/><br/>";
}else
{
echo "Not enough funds to create cart...";
}
}catch (APIException $e) {
echo 'Caught exception: ', $e->getMessage(), "<br/><br />\n";
echo 'error code is: ', $e->getResponseCode()," ", $e->getReason();
}
?>