Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReturnUrl.php
Go to the documentation of this file.
1 <?php
8 
15 
16 class ReturnUrl extends Payflow implements CsrfAwareActionInterface
17 {
21  protected $allowedOrderStates = [
22  Order::STATE_PROCESSING,
23  Order::STATE_COMPLETE,
24  Order::STATE_PAYMENT_REVIEW
25  ];
26 
34  ];
35 
42  return null;
43  }
44 
48  public function validateForCsrf(RequestInterface $request): ?bool
49  {
50  return true;
51  }
52 
58  public function execute()
59  {
60  $this->_view->loadLayout(false);
62  $redirectBlock = $this->_view->getLayout()->getBlock($this->_redirectBlockName);
63 
64  if ($this->_checkoutSession->getLastRealOrderId()) {
66  $order = $this->_orderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId());
67 
68  if ($order->getIncrementId()) {
69  if ($this->checkOrderState($order)) {
70  $redirectBlock->setData('goto_success_page', true);
71  $this->_eventManager->dispatch('paypal_checkout_success', ['order' => $order]);
72  } else {
73  if ($this->checkPaymentMethod($order)) {
74  $gotoSection = $this->_cancelPayment((string)$this->getRequest()->getParam('RESPMSG'));
75  $redirectBlock->setData('goto_section', $gotoSection);
76  $redirectBlock->setData('error_msg', __('Your payment has been declined. Please try again.'));
77  } else {
78  $redirectBlock->setData('goto_section', false);
79  $redirectBlock->setData('error_msg', __('Requested payment method does not match with order.'));
80  }
81  }
82  }
83  }
84 
85  $this->_view->renderLayout();
86  }
87 
94  protected function checkOrderState(Order $order)
95  {
96  return in_array($order->getState(), $this->allowedOrderStates);
97  }
98 
105  protected function checkPaymentMethod(Order $order)
106  {
107  $payment = $order->getPayment();
108  return in_array($payment->getMethod(), $this->allowedPaymentMethodCodes);
109  }
110 }
$order
Definition: order.php:55
__()
Definition: __.php:13
$payment
Definition: order.php:17
createCsrfValidationException(RequestInterface $request)
Definition: ReturnUrl.php:39
validateForCsrf(RequestInterface $request)
Definition: ReturnUrl.php:48