TransactionDetailsResponseHandler.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\Response;
  8. use Magento\AuthorizenetAcceptjs\Gateway\Config;
  9. use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
  10. use Magento\AuthorizenetAcceptjs\Gateway\Validator\TransactionResponseValidator;
  11. use Magento\Payment\Gateway\Response\HandlerInterface;
  12. use Magento\Sales\Model\Order\Payment;
  13. /**
  14. * Adds the details to the transaction that should show when the transaction is viewed in the admin
  15. */
  16. class TransactionDetailsResponseHandler implements HandlerInterface
  17. {
  18. /**
  19. * @var SubjectReader
  20. */
  21. private $subjectReader;
  22. /**
  23. * @var Config
  24. */
  25. private $config;
  26. /**
  27. * @param SubjectReader $subjectReader
  28. * @param Config $config
  29. */
  30. public function __construct(SubjectReader $subjectReader, Config $config)
  31. {
  32. $this->subjectReader = $subjectReader;
  33. $this->config = $config;
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function handle(array $handlingSubject, array $response): void
  39. {
  40. $storeId = $this->subjectReader->readStoreId($handlingSubject);
  41. $paymentDO = $this->subjectReader->readPayment($handlingSubject);
  42. $payment = $paymentDO->getPayment();
  43. $transactionResponse = $response['transactionResponse'];
  44. if ($payment instanceof Payment) {
  45. // Add the keys that should show in the transaction details interface
  46. $additionalInformationKeys = $this->config->getAdditionalInfoKeys($storeId);
  47. $rawDetails = [];
  48. foreach ($additionalInformationKeys as $paymentInfoKey) {
  49. if (isset($transactionResponse[$paymentInfoKey])) {
  50. $rawDetails[$paymentInfoKey] = $transactionResponse[$paymentInfoKey];
  51. $payment->setAdditionalInformation($paymentInfoKey, $transactionResponse[$paymentInfoKey]);
  52. }
  53. }
  54. $payment->setTransactionAdditionalInfo(Payment\Transaction::RAW_DETAILS, $rawDetails);
  55. }
  56. }
  57. }