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