BackendResponse.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. declare(strict_types=1);
  8. namespace Magento\Authorizenet\Controller\Directpost\Payment;
  9. use Magento\Authorizenet\Helper\DataFactory;
  10. use Magento\Authorizenet\Model\Directpost;
  11. use Magento\Authorizenet\Model\DirectpostFactory;
  12. use Magento\Framework\App\Action\Context;
  13. use Magento\Framework\App\CsrfAwareActionInterface;
  14. use Magento\Framework\App\Request\InvalidRequestException;
  15. use Magento\Framework\App\RequestInterface;
  16. use Magento\Framework\Controller\ResultFactory;
  17. use Magento\Framework\Exception\LocalizedException;
  18. use Magento\Framework\Registry;
  19. use Magento\Framework\App\Action\HttpGetActionInterface;
  20. use Magento\Framework\App\Action\HttpPostActionInterface;
  21. use Psr\Log\LoggerInterface;
  22. /**
  23. * Class BackendResponse
  24. * @deprecated 100.3.1 Authorize.net is removing all support for this payment method
  25. */
  26. class BackendResponse extends \Magento\Authorizenet\Controller\Directpost\Payment implements
  27. CsrfAwareActionInterface,
  28. HttpGetActionInterface,
  29. HttpPostActionInterface
  30. {
  31. /**
  32. * @var LoggerInterface
  33. */
  34. private $logger;
  35. /**
  36. * @var DirectpostFactory
  37. */
  38. private $directpostFactory;
  39. /**
  40. * BackendResponse constructor.
  41. *
  42. * @param Context $context
  43. * @param Registry $coreRegistry
  44. * @param DataFactory $dataFactory
  45. * @param DirectpostFactory $directpostFactory
  46. * @param LoggerInterface|null $logger
  47. */
  48. public function __construct(
  49. Context $context,
  50. Registry $coreRegistry,
  51. DataFactory $dataFactory,
  52. DirectpostFactory $directpostFactory,
  53. LoggerInterface $logger = null
  54. ) {
  55. parent::__construct($context, $coreRegistry, $dataFactory);
  56. $this->directpostFactory = $directpostFactory ?: $this->_objectManager->create(DirectpostFactory::class);
  57. $this->logger = $logger ?: $this->_objectManager->get(LoggerInterface::class);
  58. }
  59. /**
  60. * @inheritDoc
  61. */
  62. public function createCsrfValidationException(
  63. RequestInterface $request
  64. ): ?InvalidRequestException {
  65. return null;
  66. }
  67. /**
  68. * @inheritDoc
  69. */
  70. public function validateForCsrf(RequestInterface $request): ?bool
  71. {
  72. return true;
  73. }
  74. /**
  75. * Response action.
  76. *
  77. * Action for Authorize.net SIM Relay Request.
  78. *
  79. * @return \Magento\Framework\Controller\ResultInterface
  80. */
  81. public function execute()
  82. {
  83. $data = $this->getRequest()->getParams();
  84. /** @var Directpost $paymentMethod */
  85. $paymentMethod = $this->directpostFactory->create();
  86. if (!empty($data['store_id'])) {
  87. $paymentMethod->setStore($data['store_id']);
  88. }
  89. $paymentMethod->setResponseData($data);
  90. try {
  91. $paymentMethod->validateResponse();
  92. } catch (LocalizedException $e) {
  93. $this->logger->critical($e->getMessage());
  94. return $this->_redirect('noroute');
  95. }
  96. $this->_responseAction('adminhtml');
  97. return $this->resultFactory->create(ResultFactory::TYPE_PAGE);
  98. }
  99. }