6
6
7
7
namespace CM \Payments \Test \Integration \Service ;
8
8
9
+ use CM \Payments \Api \Model \Data \PaymentInterfaceFactory ;
9
10
use CM \Payments \Api \Model \PaymentRepositoryInterface ;
10
11
use CM \Payments \Client \Api \ApiClientInterface ;
11
12
use CM \Payments \Api \Service \OrderTransactionServiceInterface ;
12
13
use CM \Payments \Model \Data \Order ;
14
+ use CM \Payments \Model \OrderRepository ;
13
15
use CM \Payments \Service \OrderTransactionService ;
14
16
use CM \Payments \Test \Integration \IntegrationTestCase ;
15
17
use CM \Payments \Test \Mock \MockApiResponse ;
@@ -55,13 +57,7 @@ protected function setUp(): void
55
57
56
58
$ magentoOrder = $ this ->loadOrderById ('100000001 ' );
57
59
58
- $ cmOrder = $ this ->objectManager ->create (Order::class);
59
- $ cmOrder ->setIncrementId ('100000001 ' )
60
- ->setOrderId ($ magentoOrder ->getEntityId ())
61
- ->setOrderKey ('test123 ' );
62
-
63
- $ cmOrderRepository = $ this ->objectManager ->create (\CM \Payments \Model \OrderRepository::class);
64
- $ cmOrderRepository ->save ($ cmOrder );
60
+ $ this ->createCmOrder ($ magentoOrder );
65
61
66
62
$ magentoOrder = $ this ->loadOrderById ('100000001 ' );
67
63
$ this ->adjustMagentoOrder ($ magentoOrder );
@@ -212,11 +208,102 @@ public function testIfCMPaymentIsCreatedInDatabase()
212
208
$ this ->orderTransactionService ->process ('100000001 ' );
213
209
214
210
$ cmPaymentRepository = $ this ->objectManager ->create (PaymentRepositoryInterface::class);
215
-
216
211
$ cmPayment = $ cmPaymentRepository ->getByOrderKey ('test123 ' );
217
212
$ this ->assertSame ('pid4911203603t ' , $ cmPayment ->getPaymentId ());
218
213
}
219
214
215
+ /**
216
+ * @magentoDataFixture Magento/Sales/_files/order.php
217
+ */
218
+ public function testShouldCancelOrderWhenCreditCardDirectPaymentIsCanceled ()
219
+ {
220
+ $ this ->clientMock
221
+ ->expects ($ this ->once ())->method ('execute ' )
222
+ ->willReturn ($ this ->mockApiResponse ->getOrderDetailCanceledPayment ());
223
+
224
+ $ magentoOrder = $ this ->loadOrderById ('100000001 ' );
225
+ $ magentoOrder ->getPayment ()->setMethod ('cm_payments_creditcard ' );
226
+ $ repository = $ this ->objectManager ->get (OrderRepositoryInterface::class);
227
+ $ repository ->save ($ magentoOrder );
228
+
229
+ $ this ->createCmOrder ($ magentoOrder );
230
+
231
+ $ this ->createCMPayment ($ magentoOrder );
232
+
233
+ $ this ->orderTransactionService ->process ('100000001 ' );
234
+
235
+ $ magentoOrder = $ this ->loadOrderById ('100000001 ' );
236
+ $ this ->assertSame ('canceled ' , $ magentoOrder ->getStatus ());
237
+ }
238
+
239
+ /**
240
+ * @magentoDataFixture Magento/Sales/_files/order.php
241
+ */
242
+ public function testShouldNotCancelOrderWhenCreditCardDirectPaymentIsRedirectedForAuthentication ()
243
+ {
244
+ $ this ->clientMock
245
+ ->expects ($ this ->once ())->method ('execute ' )
246
+ ->willReturn ($ this ->mockApiResponse ->getOrderDetailRedirectedForAuthenticationPayment ());
247
+
248
+
249
+ $ magentoOrder = $ this ->loadOrderById ('100000001 ' );
250
+ $ magentoOrder ->getPayment ()->setMethod ('cm_payments_creditcard ' );
251
+ $ repository = $ this ->objectManager ->get (OrderRepositoryInterface::class);
252
+ $ repository ->save ($ magentoOrder );
253
+
254
+ $ this ->createCmOrder ($ magentoOrder );
255
+
256
+ $ this ->createCMPayment ($ magentoOrder );
257
+
258
+ $ this ->orderTransactionService ->process ('100000001 ' );
259
+
260
+ $ magentoOrder = $ this ->loadOrderById ('100000001 ' );
261
+ $ this ->assertSame ('pending_payment ' , $ magentoOrder ->getStatus ());
262
+ }
263
+
264
+ /**
265
+ * @magentoDataFixture Magento/Sales/_files/order.php
266
+ */
267
+ public function testShouldNotCancelOrderWhenIdealPaymentIsCanceled ()
268
+ {
269
+ $ this ->clientMock
270
+ ->expects ($ this ->once ())->method ('execute ' )
271
+ ->willReturn ($ this ->mockApiResponse ->getOrderDetailCanceledPayment ());
272
+
273
+ $ magentoOrder = $ this ->loadOrderById ('100000001 ' );
274
+
275
+ $ magentoOrder ->getPayment ()->setMethod ('cm_payments_ideal ' );
276
+ $ repository = $ this ->objectManager ->get (OrderRepositoryInterface::class);
277
+ $ repository ->save ($ magentoOrder );
278
+
279
+ $ this ->createCmOrder ($ magentoOrder );
280
+ $ this ->orderTransactionService ->process ('100000001 ' );
281
+
282
+ $ magentoOrder = $ this ->loadOrderById ('100000001 ' );
283
+ $ this ->assertSame ('pending_payment ' , $ magentoOrder ->getStatus ());
284
+ }
285
+
286
+ /**
287
+ * @magentoDataFixture Magento/Sales/_files/order.php
288
+ */
289
+ public function testShouldNotCancelOrderWhenCMPaymentNotExists ()
290
+ {
291
+ $ this ->clientMock
292
+ ->expects ($ this ->once ())->method ('execute ' )
293
+ ->willReturn ($ this ->mockApiResponse ->getOrderDetailCanceledPayment ());
294
+
295
+ $ magentoOrder = $ this ->loadOrderById ('100000001 ' );
296
+ $ magentoOrder ->getPayment ()->setMethod ('cm_payments_ideal ' );
297
+ $ repository = $ this ->objectManager ->get (OrderRepositoryInterface::class);
298
+ $ repository ->save ($ magentoOrder );
299
+
300
+ $ this ->createCmOrder ($ magentoOrder );
301
+ $ this ->orderTransactionService ->process ('100000001 ' );
302
+
303
+ $ magentoOrder = $ this ->loadOrderById ('100000001 ' );
304
+ $ this ->assertSame ('pending_payment ' , $ magentoOrder ->getStatus ());
305
+ }
306
+
220
307
/**
221
308
* @param OrderInterface $magentoOrder
222
309
* @return OrderInterface
@@ -234,4 +321,33 @@ private function adjustMagentoOrder(OrderInterface $magentoOrder): OrderInterfac
234
321
235
322
return $ magentoOrder ;
236
323
}
324
+
325
+ /**
326
+ * @param OrderInterface $magentoOrder
327
+ */
328
+ private function createCmOrder (OrderInterface $ magentoOrder ): void
329
+ {
330
+ $ cmOrder = $ this ->objectManager ->create (Order::class);
331
+ $ cmOrder ->setIncrementId ('100000001 ' )
332
+ ->setOrderId ($ magentoOrder ->getEntityId ())
333
+ ->setOrderKey ('test123 ' );
334
+
335
+ $ cmOrderRepository = $ this ->objectManager ->create (OrderRepository::class);
336
+ $ cmOrderRepository ->save ($ cmOrder );
337
+ }
338
+
339
+ /**
340
+ * @param OrderInterface $magentoOrder
341
+ */
342
+ private function createCMPayment (OrderInterface $ magentoOrder ): void
343
+ {
344
+ $ cmPaymentRepository = $ this ->objectManager ->create (PaymentRepositoryInterface::class);
345
+ $ cmPaymentDataFactory = $ this ->objectManager ->create (PaymentInterfaceFactory::class);
346
+ $ cmPayment = $ cmPaymentDataFactory ->create ();
347
+ $ cmPayment ->setOrderId ((int )$ magentoOrder ->getEntityId ());
348
+ $ cmPayment ->setOrderKey ('test123 ' );
349
+ $ cmPayment ->setIncrementId ($ magentoOrder ->getIncrementId ());
350
+ $ cmPayment ->setPaymentId ('pid4911203603t ' );
351
+ $ cmPaymentRepository ->save ($ cmPayment );
352
+ }
237
353
}
0 commit comments