PaymentReviewStatusHandler.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\SubjectReader;
  9. use Magento\Payment\Gateway\Response\HandlerInterface;
  10. use Magento\Sales\Model\Order\Payment;
  11. /**
  12. * Processes payment information from a void transaction response
  13. */
  14. class PaymentReviewStatusHandler implements HandlerInterface
  15. {
  16. private const REVIEW_PENDING_STATUSES = [
  17. 'FDSPendingReview',
  18. 'FDSAuthorizedPendingReview'
  19. ];
  20. private const REVIEW_DECLINED_STATUSES = [
  21. 'void',
  22. 'declined'
  23. ];
  24. /**
  25. * @var SubjectReader
  26. */
  27. private $subjectReader;
  28. /**
  29. * @param SubjectReader $subjectReader
  30. */
  31. public function __construct(SubjectReader $subjectReader)
  32. {
  33. $this->subjectReader = $subjectReader;
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function handle(array $handlingSubject, array $response): void
  39. {
  40. $paymentDO = $this->subjectReader->readPayment($handlingSubject);
  41. $payment = $paymentDO->getPayment();
  42. if ($payment instanceof Payment) {
  43. $paymentDO = $this->subjectReader->readPayment($handlingSubject);
  44. $payment = $paymentDO->getPayment();
  45. $status = $response['transaction']['transactionStatus'];
  46. // This data is only used when updating the order payment via Get Payment Update
  47. if (!in_array($status, self::REVIEW_PENDING_STATUSES)) {
  48. $denied = in_array($status, self::REVIEW_DECLINED_STATUSES);
  49. $payment->setData('is_transaction_denied', $denied);
  50. $payment->setData('is_transaction_approved', !$denied);
  51. }
  52. }
  53. }
  54. }