Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Response.php
Go to the documentation of this file.
1 <?php
7 
22 
27 {
33  private $coreRegistry;
34 
38  private $transaction;
39 
43  private $responseValidator;
44 
48  private $resultLayoutFactory;
49 
53  private $transparent;
54 
58  private $paymentFailures;
59 
63  private $sessionTransparent;
64 
77  public function __construct(
78  Context $context,
79  Registry $coreRegistry,
80  Transaction $transaction,
81  ResponseValidator $responseValidator,
82  LayoutFactory $resultLayoutFactory,
83  Transparent $transparent,
84  Session $sessionTransparent = null,
85  PaymentFailuresInterface $paymentFailures = null
86  ) {
87  parent::__construct($context);
88  $this->coreRegistry = $coreRegistry;
89  $this->transaction = $transaction;
90  $this->responseValidator = $responseValidator;
91  $this->resultLayoutFactory = $resultLayoutFactory;
92  $this->transparent = $transparent;
93  $this->sessionTransparent = $sessionTransparent ?: $this->_objectManager->get(Session::class);
94  $this->paymentFailures = $paymentFailures ?: $this->_objectManager->get(PaymentFailuresInterface::class);
95  }
96 
103  return null;
104  }
105 
109  public function validateForCsrf(RequestInterface $request): ?bool
110  {
111  return true;
112  }
113 
117  public function execute()
118  {
119  $parameters = [];
120  try {
121  $response = $this->transaction->getResponseObject($this->getRequest()->getPostValue());
122  $this->responseValidator->validate($response, $this->transparent);
123  $this->transaction->savePaymentInQuote($response);
124  } catch (LocalizedException $exception) {
125  $parameters['error'] = true;
126  $parameters['error_msg'] = $exception->getMessage();
127  $this->paymentFailures->handle((int)$this->sessionTransparent->getQuoteId(), $parameters['error_msg']);
128  }
129 
130  $this->coreRegistry->register(Iframe::REGISTRY_KEY, $parameters);
131 
132  $resultLayout = $this->resultLayoutFactory->create();
133  $resultLayout->addDefaultHandle();
134  $resultLayout->getLayout()->getUpdate()->load(['transparent_payment_response']);
135 
136  return $resultLayout;
137  }
138 }
$transaction
$response
Definition: 404.php:11
createCsrfValidationException(RequestInterface $request)
Definition: Response.php:100
validateForCsrf(RequestInterface $request)
Definition: Response.php:109
__construct(Context $context, Registry $coreRegistry, Transaction $transaction, ResponseValidator $responseValidator, LayoutFactory $resultLayoutFactory, Transparent $transparent, Session $sessionTransparent=null, PaymentFailuresInterface $paymentFailures=null)
Definition: Response.php:77