diff --git a/vendor/magento/module-paypal/Controller/Ipn/Index.php b/vendor/magento/module-paypal/Controller/Ipn/Index.php index a879266bc19..da3ed29bf54 100644 --- a/vendor/magento/module-paypal/Controller/Ipn/Index.php +++ b/vendor/magento/module-paypal/Controller/Ipn/Index.php @@ -1,8 +1,7 @@ getRequest()->getPostValue(); $this->_ipnFactory->create(['data' => $data])->processIpnRequest(); - $incrementId = $this->getRequest()->getPostValue()['invoice']; - $this->_eventManager->dispatch( - 'paypal_checkout_success', - [ - 'order' => $this->orderFactory->create()->loadByIncrementId($incrementId) - ] - ); + $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); diff --git a/vendor/magento/module-paypal/Model/Exception/UnknownIpnException.php b/vendor/magento/module-paypal/Model/Exception/UnknownIpnException.php new file mode 100644 index 00000000000..0e033a4e5f7 --- /dev/null +++ b/vendor/magento/module-paypal/Model/Exception/UnknownIpnException.php @@ -0,0 +1,17 @@ +getRequestData('invoice'); + if (!$incrementId) { + throw new UnknownIpnException( + __('Missing invoice field in IPN request.') + ); + } $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId); if (!$this->_order->getId()) { // phpcs:ignore Magento2.Exceptions.DirectThrow