_logger = $logger; $this->_ipnFactory = $ipnFactory; $this->orderFactory = $orderFactory ?: ObjectManager::getInstance()->get(OrderFactory::class); parent::__construct($context); } /** * @inheritDoc */ public function createCsrfValidationException( RequestInterface $request ): ?InvalidRequestException { return null; } /** * @inheritDoc */ public function validateForCsrf(RequestInterface $request): ?bool { return true; } /** * Instantiate IPN model and pass IPN request to it * * @return void */ public function execute() { if (!$this->getRequest()->isPost()) { return; } try { $data = $this->getRequest()->getPostValue(); $this->_ipnFactory->create(['data' => $data])->processIpnRequest(); $incrementId = $data['invoice'] ?? null; if ($incrementId) { $this->_eventManager->dispatch( 'paypal_checkout_success', [ 'order' => $this->orderFactory->create()->loadByIncrementId($incrementId) ] ); } } catch (RemoteServiceUnavailableException $e) { $this->_logger->critical($e); $this->getResponse()->setStatusHeader(503, '1.1', 'Service Unavailable')->sendResponse(); /** @todo eliminate usage of exit statement */ // phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage exit; } catch (UnknownIpnException $e) { $this->_logger->warning($e); } catch (\Exception $e) { $this->_logger->critical($e); $this->getResponse()->setHttpResponseCode(500); } } }