1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once('../vendor/autoload.php'); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* PLEASE FILL YOUR PUBLIC KEY AND PRIVATE KEY |
7
|
|
|
*/ |
8
|
|
|
const PUBLIC_KEY = ''; //Set your public key |
9
|
|
|
const PRIVATE_KEY = ''; //Set your public key |
10
|
|
|
|
11
|
|
|
try { |
12
|
|
|
writeLog('-------------------------------', $withDate = false); |
13
|
|
|
call_user_func('listMethod'); |
14
|
|
|
} catch (\Exception $e) { |
15
|
|
|
echo $e->getMessage(); |
16
|
|
|
exit; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @throws \Httpful\Exception\ConnectionErrorException |
21
|
|
|
* @throws \Pagantis\OrdersApiClient\Exception\ClientException |
22
|
|
|
* @throws Exception |
23
|
|
|
*/ |
24
|
|
|
function listMethod() |
25
|
|
|
{ |
26
|
|
|
$asJson = true; |
27
|
|
|
$withDate = true; |
28
|
|
|
$queryString = array( |
29
|
|
|
'channel' => 'ONLINE', |
30
|
|
|
'pageSize' => 2, |
31
|
|
|
'page' => 1, |
32
|
|
|
'status' => \Pagantis\OrdersApiClient\Model\Order::STATUS_CONFIRMED |
33
|
|
|
); |
34
|
|
|
try { |
35
|
|
|
writeLog('Creating Client', $withDate); |
36
|
|
|
$orderApiClient = new \Pagantis\OrdersApiClient\Client( |
37
|
|
|
PUBLIC_KEY, |
38
|
|
|
PRIVATE_KEY |
39
|
|
|
); |
40
|
|
|
writeLog('Client Created', $withDate); |
41
|
|
|
writeLog('Fetching Orders', $withDate); |
42
|
|
|
/** WARNING: orders must be confirmed on your back office or you will get a empty object */ |
43
|
|
|
$orders = $orderApiClient->listOrders($queryString, $asJson); |
44
|
|
|
writeLog('Orders Fetched', $withDate); |
45
|
|
|
|
46
|
|
|
writeLog($orders, $withDate); |
47
|
|
|
echo $orders; |
48
|
|
|
|
49
|
|
|
} catch (\Exception $exception) { |
50
|
|
|
$exception->getMessage(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param $message |
56
|
|
|
* @param $withDate |
57
|
|
|
* |
58
|
|
|
* @return false|int |
59
|
|
|
*/ |
60
|
|
|
function writeLog( |
61
|
|
|
$message, |
62
|
|
|
$withDate |
63
|
|
|
) { |
64
|
|
|
$dateFormat = '[D M j G:i:s o]'; |
65
|
|
|
if ($withDate) { |
66
|
|
|
$date = getCurrentDate($dateFormat); |
67
|
|
|
return file_put_contents('logs/pagantis.old.log', "$date - 'LIST ORDERS' - $message.\n", |
68
|
|
|
FILE_APPEND); |
69
|
|
|
} |
70
|
|
|
return file_put_contents('logs/pagantis.old.log', "$message.\n", |
71
|
|
|
FILE_APPEND); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param $dateFormat |
76
|
|
|
* |
77
|
|
|
* @return false|string |
78
|
|
|
*/ |
79
|
|
|
function getCurrentDate($dateFormat) |
80
|
|
|
{ |
81
|
|
|
$currentDate = date($dateFormat); |
82
|
|
|
return $currentDate; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param $object |
87
|
|
|
* |
88
|
|
|
* @return false|string |
89
|
|
|
*/ |
90
|
|
|
function jsonEncoded($object) |
91
|
|
|
{ |
92
|
|
|
return json_encode($object, |
93
|
|
|
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return \Pagantis\OrdersApiClient\Client |
99
|
|
|
* @throws \Httpful\Exception\ConnectionErrorException |
100
|
|
|
* @throws \Pagantis\OrdersApiClient\Exception\ClientException |
101
|
|
|
*/ |
102
|
|
|
function getClient() |
103
|
|
|
{ |
104
|
|
|
if (PUBLIC_KEY == '' || PRIVATE_KEY == '') { |
|
|
|
|
105
|
|
|
throw new \Exception('You need set the public and private key'); |
106
|
|
|
} |
107
|
|
|
$orderClient = new \Pagantis\OrdersApiClient\Client(PUBLIC_KEY, PRIVATE_KEY); |
108
|
|
|
return $orderClient; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
|