DataAssignObserver.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\Observer;
  8. use Magento\Framework\Event\Observer;
  9. use Magento\Payment\Observer\AbstractDataAssignObserver;
  10. use Magento\Quote\Api\Data\PaymentInterface;
  11. /**
  12. * Adds the payment info to the payment object
  13. */
  14. class DataAssignObserver extends AbstractDataAssignObserver
  15. {
  16. /**
  17. * @var array
  18. */
  19. private $additionalInformationList = [
  20. 'opaqueDataDescriptor',
  21. 'opaqueDataValue',
  22. 'ccLast4'
  23. ];
  24. /**
  25. * @inheritdoc
  26. */
  27. public function execute(Observer $observer)
  28. {
  29. $data = $this->readDataArgument($observer);
  30. $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
  31. if (!is_array($additionalData)) {
  32. return;
  33. }
  34. $paymentInfo = $this->readPaymentModelArgument($observer);
  35. foreach ($this->additionalInformationList as $additionalInformationKey) {
  36. if (isset($additionalData[$additionalInformationKey])) {
  37. $paymentInfo->setAdditionalInformation(
  38. $additionalInformationKey,
  39. $additionalData[$additionalInformationKey]
  40. );
  41. }
  42. }
  43. }
  44. }