1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
require_once('../vendor/autoload.php'); |
5
|
|
|
require_once('../examples/utils/Helpers.php'); |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* PLEASE FILL YOUR PUBLIC KEY AND PRIVATE KEY |
9
|
|
|
*/ |
10
|
|
|
const PUBLIC_KEY = ''; //Set your public key |
11
|
|
|
const PRIVATE_KEY = ''; //Set your public key |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
try { |
15
|
|
|
call_user_func('confirmOrders'); |
16
|
|
|
} catch (\Exception $e) { |
17
|
|
|
echo $e->getMessage(); |
18
|
|
|
exit; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
function confirmOrders() |
22
|
|
|
{ |
23
|
|
|
try { |
24
|
|
|
$fileName = basename(__FILE__); |
25
|
|
|
$withDate = true; |
26
|
|
|
writeLog('Creating Client', $fileName,$withDate); |
27
|
|
|
$orderApiClient = getClient(); |
28
|
|
|
writeLog('Client Created', $fileName,$withDate); |
29
|
|
|
writeLog('Fetching Authorized Orders', $fileName,$withDate); |
30
|
|
|
$authorizedOrders = $orderApiClient->listOrders(array( |
31
|
|
|
'status' => \Pagantis\OrdersApiClient\Model\Order::STATUS_AUTHORIZED |
32
|
|
|
)); |
33
|
|
|
|
34
|
|
|
if (!isAuthorizedOrderCountAboveZero($authorizedOrders)) { |
35
|
|
|
$createdOrders = $orderApiClient->listOrders(array( |
36
|
|
|
'status' => \Pagantis\OrdersApiClient\Model\Order::STATUS_CREATED)); |
37
|
|
|
print("<pre>" . print_r("Number of Created Orders: ". count($createdOrders)."\n"."Number of Authorized Orders: " . count($authorizedOrders)."\n"."", true) . "</pre>"); |
38
|
|
|
exit(); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
writeLog('Confirming all Authorized Orders', $fileName,$withDate); |
41
|
|
|
|
42
|
|
|
$confirmedOrders = getConfirmedOrdersRecursively($authorizedOrders,$orderApiClient); |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
writeLog('Orders Confirmed', $fileName,$withDate); |
46
|
|
|
writeLog(jsonEncoded($confirmedOrders), $fileName,$withDate); |
47
|
|
|
/** WARNING: orders must be confirmed on your back office or you will get a empty object */ |
48
|
|
|
print("<pre>" . print_r($confirmedOrders, true) . "</pre>"); |
49
|
|
|
|
50
|
|
|
} catch (\Exception $exception) { |
51
|
|
|
$exception->getMessage(); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $authorizedOrders |
59
|
|
|
* |
60
|
|
|
* @param \Pagantis\OrdersApiClient\Client $orderApiClient |
61
|
|
|
* |
62
|
|
|
* @return array |
63
|
|
|
* @throws \Pagantis\OrdersApiClient\Exception\ClientException |
64
|
|
|
* @throws Exception |
65
|
|
|
*/ |
66
|
|
|
function getConfirmedOrdersRecursively( |
67
|
|
|
$authorizedOrders, |
68
|
|
|
\Pagantis\OrdersApiClient\Client $orderApiClient |
69
|
|
|
) { |
70
|
|
|
|
71
|
|
|
if (!$orderApiClient instanceof \Pagantis\OrdersApiClient\Client) { |
|
|
|
|
72
|
|
|
throw new \Pagantis\OrdersApiClient\Exception\ClientException('Client Instance Error'); |
73
|
|
|
} |
74
|
|
|
$confirmedOrders = array(); |
75
|
|
|
foreach ($authorizedOrders as $order) { |
76
|
|
|
$orderConfirmed = $orderApiClient->confirmOrder($order->getId()); |
77
|
|
|
array_push($confirmedOrders, $orderConfirmed); |
78
|
|
|
} |
79
|
|
|
return $confirmedOrders; |
80
|
|
|
} |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.