FetchTransactionInfoCommand.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\Config;
  9. use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
  10. use Magento\Payment\Gateway\Command\CommandPool;
  11. use Magento\Payment\Gateway\Command\CommandPoolInterface;
  12. use Magento\Payment\Gateway\CommandInterface;
  13. use Magento\Payment\Gateway\Response\HandlerInterface;
  14. /**
  15. * Syncs the transaction status with authorize.net
  16. */
  17. class FetchTransactionInfoCommand implements CommandInterface
  18. {
  19. /**
  20. * @var CommandPool
  21. */
  22. private $commandPool;
  23. /**
  24. * @var SubjectReader
  25. */
  26. private $subjectReader;
  27. /**
  28. * @var Config
  29. */
  30. private $config;
  31. /**
  32. * @var HandlerInterface|null
  33. */
  34. private $handler;
  35. /**
  36. * @param CommandPoolInterface $commandPool
  37. * @param SubjectReader $subjectReader
  38. * @param Config $config
  39. * @param HandlerInterface|null $handler
  40. */
  41. public function __construct(
  42. CommandPoolInterface $commandPool,
  43. SubjectReader $subjectReader,
  44. Config $config,
  45. HandlerInterface $handler = null
  46. ) {
  47. $this->commandPool = $commandPool;
  48. $this->subjectReader = $subjectReader;
  49. $this->config = $config;
  50. $this->handler = $handler;
  51. }
  52. /**
  53. * @inheritdoc
  54. */
  55. public function execute(array $commandSubject): array
  56. {
  57. $paymentDO = $this->subjectReader->readPayment($commandSubject);
  58. $order = $paymentDO->getOrder();
  59. $command = $this->commandPool->get('get_transaction_details');
  60. $result = $command->execute($commandSubject);
  61. $response = $result->get();
  62. if ($this->handler) {
  63. $this->handler->handle($commandSubject, $response);
  64. }
  65. $additionalInformationKeys = $this->config->getTransactionInfoSyncKeys($order->getStoreId());
  66. $rawDetails = [];
  67. foreach ($additionalInformationKeys as $key) {
  68. if (isset($response['transaction'][$key])) {
  69. $rawDetails[$key] = $response['transaction'][$key];
  70. }
  71. }
  72. return $rawDetails;
  73. }
  74. }