|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* PLEASE SET YOUR PUBLIC KEY AND PRIVATE KEY |
|
6
|
|
|
*/ |
|
7
|
|
|
const PUBLIC_KEY = ''; //Set your public key |
|
8
|
|
|
const PRIVATE_KEY = ''; //Set your public key |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @return \Pagantis\OrdersApiClient\Client |
|
13
|
|
|
* @throws \Httpful\Exception\ConnectionErrorException |
|
14
|
|
|
* @throws \Pagantis\OrdersApiClient\Exception\ClientException |
|
15
|
|
|
*/ |
|
16
|
|
|
function getOrderApiClient() |
|
17
|
|
|
{ |
|
18
|
|
|
$publicKey = PUBLIC_KEY; |
|
19
|
|
|
$privateKey = PRIVATE_KEY; |
|
20
|
|
|
if ($publicKey == '' || $privateKey == '') { |
|
|
|
|
|
|
21
|
|
|
throw new \Exception('You need set the public and private key in examples/utils/Helpers.php'); |
|
22
|
|
|
} |
|
23
|
|
|
$orderClient = new \Pagantis\OrdersApiClient\Client($publicKey, $privateKey); |
|
24
|
|
|
return $orderClient; |
|
25
|
|
|
} |
|
26
|
|
|
/** |
|
27
|
|
|
* @param $message |
|
28
|
|
|
* @param $fileName |
|
29
|
|
|
* @param $withDate bool |
|
30
|
|
|
* |
|
31
|
|
|
* @return false|int |
|
32
|
|
|
*/ |
|
33
|
|
|
function writeLog( |
|
34
|
|
|
$message, |
|
35
|
|
|
$fileName, |
|
36
|
|
|
$withDate |
|
37
|
|
|
) { |
|
38
|
|
|
$dateFormat = '[D M j G:i:s o]'; |
|
39
|
|
|
if ($withDate) { |
|
40
|
|
|
$path = dirname(__FILE__); |
|
|
|
|
|
|
41
|
|
|
$date = getCurrentDate($dateFormat); |
|
42
|
|
|
return file_put_contents( |
|
43
|
|
|
'../pagantis.log', |
|
44
|
|
|
$date . " " . jsonEncoded($fileName) |
|
45
|
|
|
. " $message.\n", |
|
46
|
|
|
FILE_APPEND |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
return file_put_contents( |
|
50
|
|
|
'../pagantis.log', |
|
51
|
|
|
" " . jsonEncoded($fileName) . " $message.\n", |
|
52
|
|
|
FILE_APPEND |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param $dateFormat |
|
58
|
|
|
* |
|
59
|
|
|
* @return false|string |
|
60
|
|
|
*/ |
|
61
|
|
|
function getCurrentDate($dateFormat) |
|
62
|
|
|
{ |
|
63
|
|
|
// TODO https://www.php.net/manual/en/function.date-default-timezone-set.php |
|
64
|
|
|
$currentDate = date($dateFormat); |
|
65
|
|
|
return $currentDate; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param $object |
|
70
|
|
|
* |
|
71
|
|
|
* @return false|string |
|
72
|
|
|
*/ |
|
73
|
|
|
function jsonEncoded($object) |
|
74
|
|
|
{ |
|
75
|
|
|
return json_encode( |
|
76
|
|
|
$object, |
|
77
|
|
|
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param $jsonString |
|
84
|
|
|
* |
|
85
|
|
|
* @return mixed |
|
86
|
|
|
*/ |
|
87
|
|
|
function jsonToArray($jsonString) |
|
88
|
|
|
{ |
|
89
|
|
|
$myArray = json_decode($jsonString, true); |
|
90
|
|
|
return $myArray; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param $authorizedOrders |
|
96
|
|
|
* |
|
97
|
|
|
* @return bool |
|
98
|
|
|
*/ |
|
99
|
|
|
function isOrderCountAboveZero($authorizedOrders) |
|
100
|
|
|
{ |
|
101
|
|
|
if (count($authorizedOrders) >= 1) { |
|
102
|
|
|
return true; |
|
103
|
|
|
} |
|
104
|
|
|
return false; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return bool |
|
109
|
|
|
*/ |
|
110
|
|
|
function areKeysSet() |
|
111
|
|
|
{ |
|
112
|
|
|
if (PUBLIC_KEY == '' || PRIVATE_KEY == '') { |
|
|
|
|
|
|
113
|
|
|
return false; |
|
114
|
|
|
} |
|
115
|
|
|
return true; |
|
116
|
|
|
} |
|
117
|
|
|
|