FetchTransactionInfoCommandTest.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\AuthorizenetAcceptjs\Gateway\Command;
  8. use Magento\AuthorizenetAcceptjs\Gateway\AbstractTest;
  9. use Magento\Payment\Gateway\Command\CommandPoolInterface;
  10. use Magento\Sales\Model\Order\Payment;
  11. class FetchTransactionInfoCommandTest extends AbstractTest
  12. {
  13. /**
  14. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/environment sandbox
  15. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/login someusername
  16. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_key somepassword
  17. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_signature_key abc
  18. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/transactionSyncKeys transId,transactionType
  19. * @magentoDataFixture Magento/AuthorizenetAcceptjs/Fixture/order_auth_only.php
  20. */
  21. public function testTransactionApproved()
  22. {
  23. /** @var CommandPoolInterface $commandPool */
  24. $commandPool = $this->objectManager->get('AuthorizenetAcceptjsCommandPool');
  25. $command = $commandPool->get('fetch_transaction_information');
  26. $order = $this->getOrderWithIncrementId('100000002');
  27. $payment = $order->getPayment();
  28. $paymentDO = $this->paymentFactory->create($payment);
  29. $expectedRequest = include __DIR__ . '/../../_files/expected_request/transaction_details_authorized.php';
  30. $response = include __DIR__ . '/../../_files/response/transaction_details_authorized.php';
  31. $this->clientMock->method('setRawData')
  32. ->with(json_encode($expectedRequest), 'application/json');
  33. $this->responseMock->method('getBody')
  34. ->willReturn(json_encode($response));
  35. $result = $command->execute([
  36. 'payment' => $paymentDO
  37. ]);
  38. $expected = [
  39. 'transId' => '1234',
  40. 'transactionType' => 'authOnlyTransaction'
  41. ];
  42. $this->assertSame($expected, $result);
  43. /** @var Payment $payment */
  44. $this->assertTrue($payment->getIsTransactionApproved());
  45. $this->assertFalse($payment->getIsTransactionDenied());
  46. }
  47. /**
  48. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/environment sandbox
  49. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/login someusername
  50. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_key somepassword
  51. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_signature_key abc
  52. * * @magentoConfigFixture default_store payment/authorizenet_acceptjs/transactionSyncKeys transId,transactionType
  53. * @magentoDataFixture Magento/AuthorizenetAcceptjs/Fixture/order_auth_only.php
  54. */
  55. public function testTransactionVoided()
  56. {
  57. /** @var CommandPoolInterface $commandPool */
  58. $commandPool = $this->objectManager->get('AuthorizenetAcceptjsCommandPool');
  59. $command = $commandPool->get('fetch_transaction_information');
  60. $order = $this->getOrderWithIncrementId('100000002');
  61. $payment = $order->getPayment();
  62. $paymentDO = $this->paymentFactory->create($payment);
  63. $expectedRequest = include __DIR__ . '/../../_files/expected_request/transaction_details_authorized.php';
  64. $response = include __DIR__ . '/../../_files/response/transaction_details_voided.php';
  65. $this->clientMock->method('setRawData')
  66. ->with(json_encode($expectedRequest), 'application/json');
  67. $this->responseMock->method('getBody')
  68. ->willReturn(json_encode($response));
  69. $result = $command->execute([
  70. 'payment' => $paymentDO
  71. ]);
  72. $expected = [
  73. 'transId' => '1234',
  74. 'transactionType' => 'authOnlyTransaction'
  75. ];
  76. $this->assertSame($expected, $result);
  77. /** @var Payment $payment */
  78. $this->assertFalse($payment->getIsTransactionApproved());
  79. $this->assertTrue($payment->getIsTransactionDenied());
  80. }
  81. /**
  82. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/environment sandbox
  83. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/login someusername
  84. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_key somepassword
  85. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_signature_key abc
  86. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/transactionSyncKeys transId,transactionType
  87. * @magentoDataFixture Magento/AuthorizenetAcceptjs/Fixture/order_auth_only.php
  88. */
  89. public function testTransactionDenied()
  90. {
  91. /** @var CommandPoolInterface $commandPool */
  92. $commandPool = $this->objectManager->get('AuthorizenetAcceptjsCommandPool');
  93. $command = $commandPool->get('fetch_transaction_information');
  94. $order = $this->getOrderWithIncrementId('100000002');
  95. $payment = $order->getPayment();
  96. $paymentDO = $this->paymentFactory->create($payment);
  97. $expectedRequest = include __DIR__ . '/../../_files/expected_request/transaction_details_authorized.php';
  98. $response = include __DIR__ . '/../../_files/response/transaction_details_voided.php';
  99. $this->clientMock->method('setRawData')
  100. ->with(json_encode($expectedRequest), 'application/json');
  101. $this->responseMock->method('getBody')
  102. ->willReturn(json_encode($response));
  103. $result = $command->execute([
  104. 'payment' => $paymentDO
  105. ]);
  106. $expected = [
  107. 'transId' => '1234',
  108. 'transactionType' => 'authOnlyTransaction'
  109. ];
  110. $this->assertSame($expected, $result);
  111. /** @var Payment $payment */
  112. $this->assertFalse($payment->getIsTransactionApproved());
  113. $this->assertTrue($payment->getIsTransactionDenied());
  114. }
  115. /**
  116. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/environment sandbox
  117. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/login someusername
  118. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_key somepassword
  119. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_signature_key abc
  120. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/transactionSyncKeys transId,transactionType
  121. * @magentoDataFixture Magento/AuthorizenetAcceptjs/Fixture/order_auth_only.php
  122. */
  123. public function testTransactionPending()
  124. {
  125. /** @var CommandPoolInterface $commandPool */
  126. $commandPool = $this->objectManager->get('AuthorizenetAcceptjsCommandPool');
  127. $command = $commandPool->get('fetch_transaction_information');
  128. $order = $this->getOrderWithIncrementId('100000002');
  129. $payment = $order->getPayment();
  130. $paymentDO = $this->paymentFactory->create($payment);
  131. $expectedRequest = include __DIR__ . '/../../_files/expected_request/transaction_details_authorized.php';
  132. $response = include __DIR__ . '/../../_files/response/transaction_details_fds_pending.php';
  133. $this->clientMock->method('setRawData')
  134. ->with(json_encode($expectedRequest), 'application/json');
  135. $this->responseMock->method('getBody')
  136. ->willReturn(json_encode($response));
  137. $result = $command->execute([
  138. 'payment' => $paymentDO
  139. ]);
  140. $expected = [
  141. 'transId' => '1234',
  142. 'transactionType' => 'authOnlyTransaction'
  143. ];
  144. $this->assertSame($expected, $result);
  145. /** @var Payment $payment */
  146. $this->assertNull($payment->getIsTransactionApproved());
  147. $this->assertNull($payment->getIsTransactionDenied());
  148. }
  149. }