Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Index.php
Go to the documentation of this file.
1 <?php
9 
15 use Magento\Sales\Model\OrderFactory;
16 
21 {
25  protected $_logger;
26 
30  protected $_ipnFactory;
31 
35  private $orderFactory;
36 
43  public function __construct(
44  \Magento\Framework\App\Action\Context $context,
45  \Magento\Paypal\Model\IpnFactory $ipnFactory,
46  \Psr\Log\LoggerInterface $logger,
47  OrderFactory $orderFactory = null
48  ) {
49  $this->_logger = $logger;
50  $this->_ipnFactory = $ipnFactory;
51  $this->orderFactory = $orderFactory ?: ObjectManager::getInstance()->get(OrderFactory::class);
52  parent::__construct($context);
53  }
54 
61  return null;
62  }
63 
67  public function validateForCsrf(RequestInterface $request): ?bool
68  {
69  return true;
70  }
71 
78  public function execute()
79  {
80  if (!$this->getRequest()->isPost()) {
81  return;
82  }
83 
84  try {
85  $data = $this->getRequest()->getPostValue();
86  $this->_ipnFactory->create(['data' => $data])->processIpnRequest();
87  $incrementId = $this->getRequest()->getPostValue()['invoice'];
88  $this->_eventManager->dispatch(
89  'paypal_checkout_success',
90  [
91  'order' => $this->orderFactory->create()->loadByIncrementId($incrementId)
92  ]
93  );
95  $this->_logger->critical($e);
96  $this->getResponse()->setStatusHeader(503, '1.1', 'Service Unavailable')->sendResponse();
98  exit;
99  } catch (\Exception $e) {
100  $this->_logger->critical($e);
101  $this->getResponse()->setHttpResponseCode(500);
102  }
103  }
104 }
createCsrfValidationException(RequestInterface $request)
Definition: Index.php:58
$logger
exit
Definition: redirect.phtml:12
validateForCsrf(RequestInterface $request)
Definition: Index.php:67
__construct(\Magento\Framework\App\Action\Context $context, \Magento\Paypal\Model\IpnFactory $ipnFactory, \Psr\Log\LoggerInterface $logger, OrderFactory $orderFactory=null)
Definition: Index.php:43