|
1
|
|
|
<?php |
|
2
|
|
|
namespace Test\Pagantis\OrdersApiClient; |
|
3
|
|
|
|
|
4
|
|
|
use Pagantis\OrdersApiClient\Client; |
|
5
|
|
|
use Pagantis\OrdersApiClient\Model\ApiConfiguration; |
|
6
|
|
|
use Pagantis\OrdersApiClient\Model\Order; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class ClientTest |
|
10
|
|
|
* @package Pagantis\Test |
|
11
|
|
|
*/ |
|
12
|
|
|
class ClientTest extends AbstractTest |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Demo Public Key For access the service |
|
16
|
|
|
*/ |
|
17
|
|
|
const PUBLIC_KEY = 'tk_fd53cd467ba49022e4f8215e'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Demo Private Key For access the service |
|
21
|
|
|
*/ |
|
22
|
|
|
const PRIVATE_KEY = '21e57baa97459f6a'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var Order |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $order; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* testClassExists |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testClassExists() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertTrue(class_exists('Pagantis\OrdersApiClient\Client')); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @throws \Httpful\Exception\ConnectionErrorException |
|
39
|
|
|
* @throws \Pagantis\OrdersApiClient\Exception\ClientException |
|
40
|
|
|
* @throws \ReflectionException |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testConstructorArguments() |
|
43
|
|
|
{ |
|
44
|
|
|
$array = array('key' => 'value'); |
|
45
|
|
|
$apiClient = new Client( |
|
46
|
|
|
self::PUBLIC_KEY, |
|
47
|
|
|
self::PRIVATE_KEY, |
|
48
|
|
|
ApiConfiguration::BASE_URI, |
|
49
|
|
|
$array |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$apiClientReflection = new \ReflectionClass('Pagantis\OrdersApiClient\Client'); |
|
53
|
|
|
|
|
54
|
|
|
$property = $apiClientReflection->getProperty('apiConfiguration'); |
|
55
|
|
|
$property->setAccessible(true); |
|
56
|
|
|
|
|
57
|
|
|
/** @var ApiConfiguration $apiConfiguration */ |
|
58
|
|
|
$apiConfiguration = $property->getValue($apiClient); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertSame(ApiConfiguration::BASE_URI, $apiConfiguration->getBaseUri()); |
|
61
|
|
|
$this->assertSame(self::PRIVATE_KEY, $apiConfiguration->getPrivateKey()); |
|
62
|
|
|
$this->assertSame(self::PUBLIC_KEY, $apiConfiguration->getPublicKey()); |
|
63
|
|
|
$this->assertSame($array, $apiConfiguration->getHeaders()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return ApiConfiguration |
|
68
|
|
|
* @throws \Pagantis\OrdersApiClient\Exception\ClientException |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getApiConfiguration() |
|
71
|
|
|
{ |
|
72
|
|
|
$apiConfiguration = new ApiConfiguration(); |
|
73
|
|
|
$apiConfiguration |
|
74
|
|
|
->setBaseUri(ApiConfiguration::BASE_URI) |
|
75
|
|
|
->setPrivateKey(self::PRIVATE_KEY) |
|
76
|
|
|
->setPublicKey(self::PUBLIC_KEY) |
|
77
|
|
|
; |
|
78
|
|
|
|
|
79
|
|
|
return $apiConfiguration; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* testCreateOrder |
|
84
|
|
|
* |
|
85
|
|
|
* @return bool|false|Order|string |
|
86
|
|
|
* @throws \Httpful\Exception\ConnectionErrorException |
|
87
|
|
|
* @throws \Exception |
|
88
|
|
|
*/ |
|
89
|
|
|
public function testCreateOrder() |
|
90
|
|
|
{ |
|
91
|
|
|
$orderJson = file_get_contents($this->resourcePath.'Order.json'); |
|
92
|
|
|
$object = json_decode($orderJson); |
|
93
|
|
|
$order = new Order(); |
|
94
|
|
|
$order->import($object); |
|
95
|
|
|
$order |
|
96
|
|
|
->setActionUrls(null) |
|
97
|
|
|
->setApiVersion(null) |
|
98
|
|
|
->setConfirmedAt(null) |
|
99
|
|
|
->setCreatedAt(null) |
|
100
|
|
|
->setExpiresAt(null) |
|
101
|
|
|
->setUnconfirmedAt(null) |
|
102
|
|
|
->setGracePeriod(null) |
|
103
|
|
|
->setGracePeriodMonth(null) |
|
104
|
|
|
->setId(null) |
|
105
|
|
|
->setStatus(null) |
|
106
|
|
|
; |
|
107
|
|
|
|
|
108
|
|
|
$orderReflectionClass = new \ReflectionClass('Pagantis\OrdersApiClient\Model\Order'); |
|
109
|
|
|
$property = $orderReflectionClass->getProperty('refunds'); |
|
110
|
|
|
$property->setAccessible(true); |
|
111
|
|
|
$property->setValue($order, null); |
|
112
|
|
|
|
|
113
|
|
|
$apiClient = new Client( |
|
114
|
|
|
self::PUBLIC_KEY, |
|
115
|
|
|
self::PRIVATE_KEY, |
|
116
|
|
|
ApiConfiguration::BASE_URI |
|
117
|
|
|
); |
|
118
|
|
|
|
|
119
|
|
|
$orderCreated = $apiClient->createOrder($order); |
|
120
|
|
|
$this->assertEquals($order->getConfiguration(), $orderCreated->getConfiguration()); |
|
121
|
|
|
$this->assertEquals($order->getShoppingCart(), $orderCreated->getShoppingCart()); |
|
122
|
|
|
$this->assertInstanceOf('Pagantis\OrdersApiClient\Model\Order', $order); |
|
123
|
|
|
$formUrl = $orderCreated->getActionUrls()->getForm(); |
|
124
|
|
|
$this->assertTrue(Order\Configuration\Urls::urlValidate($formUrl)); |
|
125
|
|
|
|
|
126
|
|
|
$this->order = $orderCreated; |
|
127
|
|
|
|
|
128
|
|
|
return $orderCreated; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* testGetOrder |
|
133
|
|
|
* |
|
134
|
|
|
* @return bool|false|Order|string |
|
135
|
|
|
* |
|
136
|
|
|
* @throws \Exception |
|
137
|
|
|
*/ |
|
138
|
|
|
public function testGetOrder() |
|
139
|
|
|
{ |
|
140
|
|
|
if (!$this->order instanceof Order) { |
|
|
|
|
|
|
141
|
|
|
$this->testCreateOrder(); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
$orderJson = file_get_contents($this->resourcePath.'Order.json'); |
|
145
|
|
|
$object = json_decode($orderJson); |
|
146
|
|
|
$order = new Order(); |
|
147
|
|
|
$order->import($object); |
|
148
|
|
|
|
|
149
|
|
|
$apiClient = new Client( |
|
150
|
|
|
self::PUBLIC_KEY, |
|
151
|
|
|
self::PRIVATE_KEY, |
|
152
|
|
|
ApiConfiguration::BASE_URI |
|
153
|
|
|
); |
|
154
|
|
|
|
|
155
|
|
|
$orderRetrieved = $apiClient->getOrder($this->order->getId()); |
|
156
|
|
|
|
|
157
|
|
|
$this->assertEquals($order->getConfiguration(), $orderRetrieved->getConfiguration()); |
|
158
|
|
|
$this->assertEquals($order->getShoppingCart(), $orderRetrieved->getShoppingCart()); |
|
159
|
|
|
$this->assertInstanceOf('Pagantis\OrdersApiClient\Model\Order', $order); |
|
160
|
|
|
$this->order->setConfirmedAt(null); |
|
161
|
|
|
$orderRetrieved->setConfirmedAt(null); |
|
162
|
|
|
$orderRetrieved->setUnconfirmedAt($this->order->getUnconfirmedAt()); |
|
163
|
|
|
$this->assertEquals($this->order, $orderRetrieved); |
|
164
|
|
|
|
|
165
|
|
|
return $orderRetrieved; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* testListOrders |
|
170
|
|
|
* |
|
171
|
|
|
* @return bool|false|Order[]|string |
|
172
|
|
|
* |
|
173
|
|
|
* @throws \Exception |
|
174
|
|
|
*/ |
|
175
|
|
|
public function testListOrders() |
|
176
|
|
|
{ |
|
177
|
|
|
$apiClient = new Client( |
|
178
|
|
|
self::PUBLIC_KEY, |
|
179
|
|
|
self::PRIVATE_KEY, |
|
180
|
|
|
ApiConfiguration::BASE_URI |
|
181
|
|
|
); |
|
182
|
|
|
|
|
183
|
|
|
$ordersRetrieved = $apiClient->listOrders(array( |
|
184
|
|
|
'pageSize' => 10, |
|
185
|
|
|
'page' => 1, |
|
186
|
|
|
'status' => Order::STATUS_CREATED, |
|
187
|
|
|
)); |
|
188
|
|
|
|
|
189
|
|
|
foreach ($ordersRetrieved as $order) { |
|
190
|
|
|
$this->assertInstanceOf('Pagantis\OrdersApiClient\Model\Order', $order); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
return $ordersRetrieved; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* testConfirmOrder |
|
198
|
|
|
* |
|
199
|
|
|
* @return bool|false|Order|string |
|
200
|
|
|
* |
|
201
|
|
|
* @throws \Exception |
|
202
|
|
|
*/ |
|
203
|
|
|
public function testConfirmOrder() |
|
204
|
|
|
{ |
|
205
|
|
|
//Need to mark order as authorized |
|
206
|
|
|
return true; |
|
207
|
|
|
|
|
208
|
|
|
if (!$this->order instanceof Order) { |
|
|
|
|
|
|
209
|
|
|
$this->testCreateOrder(); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
$orderJson = file_get_contents($this->resourcePath.'Order.json'); |
|
213
|
|
|
$object = json_decode($orderJson); |
|
214
|
|
|
$order = new Order(); |
|
215
|
|
|
$order->import($object); |
|
216
|
|
|
|
|
217
|
|
|
$apiClient = new Client( |
|
218
|
|
|
self::PUBLIC_KEY, |
|
219
|
|
|
self::PRIVATE_KEY, |
|
220
|
|
|
ApiConfiguration::BASE_URI |
|
221
|
|
|
); |
|
222
|
|
|
|
|
223
|
|
|
$orderRetrieved = $apiClient->confirmOrder($this->order->getId()); |
|
224
|
|
|
|
|
225
|
|
|
$this->assertEquals($order->getConfiguration(), $orderRetrieved->getConfiguration()); |
|
226
|
|
|
$this->assertEquals($order->getShoppingCart(), $orderRetrieved->getShoppingCart()); |
|
227
|
|
|
$this->assertInstanceOf('Pagantis\OrdersApiClient\Model\Order', $order); |
|
228
|
|
|
|
|
229
|
|
|
return $orderRetrieved; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* testRefundOrder |
|
234
|
|
|
* |
|
235
|
|
|
* @return bool|false|Order\Refund|string |
|
236
|
|
|
* |
|
237
|
|
|
* @throws \Exception |
|
238
|
|
|
*/ |
|
239
|
|
|
public function testRefundOrder() |
|
240
|
|
|
{ |
|
241
|
|
|
//need to mark other as confirmed |
|
242
|
|
|
return true; |
|
243
|
|
|
|
|
244
|
|
|
if (!$this->order instanceof Order) { |
|
|
|
|
|
|
245
|
|
|
$this->testCreateOrder(); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
$apiClient = new Client( |
|
249
|
|
|
self::PUBLIC_KEY, |
|
250
|
|
|
self::PRIVATE_KEY, |
|
251
|
|
|
ApiConfiguration::BASE_URI |
|
252
|
|
|
); |
|
253
|
|
|
|
|
254
|
|
|
$refund = new Order\Refund(); |
|
255
|
|
|
$refund |
|
256
|
|
|
->setPromotedAmount(0) |
|
257
|
|
|
->setTotalAmount(10) |
|
258
|
|
|
; |
|
259
|
|
|
|
|
260
|
|
|
$refund = $apiClient->refundOrder($this->order->getId(), $refund); |
|
261
|
|
|
$this->assertInstanceOf('Pagantis\OrdersApiClient\Model\Refund', $refund); |
|
262
|
|
|
|
|
263
|
|
|
return $refund; |
|
264
|
|
|
} |
|
265
|
|
|
} |
|
266
|
|
|
|