SaleCommandTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. use Magento\Sales\Model\Order\Payment\Transaction;
  12. class SaleCommandTest extends AbstractTest
  13. {
  14. /**
  15. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/environment sandbox
  16. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/login someusername
  17. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_key somepassword
  18. * @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_signature_key abc
  19. */
  20. public function testSaleCommand()
  21. {
  22. /** @var CommandPoolInterface $commandPool */
  23. $commandPool = $this->objectManager->get('AuthorizenetAcceptjsCommandPool');
  24. $command = $commandPool->get('sale');
  25. $order = include __DIR__ . '/../../_files/full_order.php';
  26. $payment = $order->getPayment();
  27. $paymentDO = $this->paymentFactory->create($payment);
  28. $expectedRequest = include __DIR__ . '/../../_files/expected_request/sale.php';
  29. $response = include __DIR__ . '/../../_files/response/sale.php';
  30. $this->clientMock->method('setRawData')
  31. ->with(json_encode($expectedRequest), 'application/json');
  32. $this->responseMock->method('getBody')
  33. ->willReturn(json_encode($response));
  34. $command->execute([
  35. 'payment' => $paymentDO,
  36. 'amount' => 100.00
  37. ]);
  38. /** @var Payment $payment */
  39. $rawDetails = [
  40. 'authCode' => 'abc123',
  41. 'avsResultCode' => 'Y',
  42. 'cvvResultCode' => 'P',
  43. 'cavvResultCode' => '2',
  44. 'accountType' => 'Visa',
  45. ];
  46. $this->assertSame('1111', $payment->getCcLast4());
  47. $this->assertSame('Y', $payment->getCcAvsStatus());
  48. $transactionDetails = $payment->getTransactionAdditionalInfo();
  49. foreach ($rawDetails as $key => $value) {
  50. $this->assertSame($value, $payment->getAdditionalInformation($key));
  51. $this->assertSame($value, $transactionDetails[Transaction::RAW_DETAILS][$key]);
  52. }
  53. $this->assertSame('123456', $payment->getTransactionId());
  54. $this->assertSame('123456', $transactionDetails['real_transaction_id']);
  55. $this->assertTrue($payment->getShouldCloseParentTransaction());
  56. $this->assertFalse($payment->getData('is_transaction_closed'));
  57. }
  58. }