From 5cafcc2bd7e7959f5ea23a17edf60a4a46503214 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Mon, 1 Jul 2024 09:49:39 +0200 Subject: [PATCH] Bugfix: Remove loading page to prevent state issues #786 --- Controller/Checkout/Redirect.php | 63 ++++++++------------------------ 1 file changed, 15 insertions(+), 48 deletions(-) diff --git a/Controller/Checkout/Redirect.php b/Controller/Checkout/Redirect.php index 84c8b3f47f7..04cfcf0817b 100644 --- a/Controller/Checkout/Redirect.php +++ b/Controller/Checkout/Redirect.php @@ -1,6 +1,6 @@ checkoutSession = $checkoutSession; - $this->resultPageFactory = $resultPageFactory; $this->paymentHelper = $paymentHelper; - $this->mollieHelper = $mollieHelper; $this->orderManagement = $orderManagement; $this->config = $config; $this->paymentTokenRepository = $paymentTokenRepository; @@ -125,50 +108,39 @@ public function execute() try { $order = $this->getOrder(); } catch (LocalizedException $exception) { - $this->mollieHelper->addTolog('error', $exception->getMessage()); + $this->config->addTolog('error', $exception->getMessage()); return $this->_redirect('checkout/cart'); } try { - $payment = $order->getPayment(); - if (!isset($payment)) { + if ($order->getPayment() === null) { return $this->_redirect('checkout/cart'); } $method = $order->getPayment()->getMethod(); $methodInstance = $this->getMethodInstance($method); - if ($methodInstance instanceof Mollie) { - $storeId = $order->getStoreId(); - $redirectUrl = $this->redirectUrl->execute($methodInstance, $order); - // This is deprecated since 2.18.0 and will be removed in a future version. - if (!($methodInstance instanceof ApplePay) && - $this->mollieHelper->useLoadingScreen($storeId) - ) { - $resultPage = $this->resultPageFactory->create(); - $resultPage->getLayout()->initMessages(); - $resultPage->getLayout()->getBlock('mollie_loading')->setMollieRedirect($redirectUrl); - return $resultPage; - } else { - return $this->getResponse()->setRedirect($redirectUrl); - } - } else { + if (!$methodInstance instanceof Mollie) { $msg = __('Payment Method not found'); $this->messageManager->addErrorMessage($msg); - $this->mollieHelper->addTolog('error', $msg); + $this->config->addTolog('error', $msg); $this->checkoutSession->restoreQuote(); return $this->_redirect('checkout/cart'); } + + return $this->getResponse()->setRedirect( + $this->redirectUrl->execute($methodInstance, $order) + ); } catch (Exception $exception) { $errorMessage = $this->formatExceptionMessages->execute($exception, $methodInstance ?? null); $this->messageManager->addErrorMessage($errorMessage); - $this->mollieHelper->addTolog('error', $exception->getMessage()); + $this->config->addTolog('error', $exception->getMessage()); $this->checkoutSession->restoreQuote(); $this->cancelUnprocessedOrder($order, $exception->getMessage()); return $this->_redirect('checkout/cart'); } } - private function cancelUnprocessedOrder(OrderInterface $order, $message) + private function cancelUnprocessedOrder(OrderInterface $order, string $message): void { if (!$this->config->cancelFailedOrders()) { return; @@ -184,21 +156,16 @@ private function cancelUnprocessedOrder(OrderInterface $order, $message) $this->orderManagement->cancel($order->getEntityId()); $order->addCommentToStatusHistory($order->getEntityId(), $historyMessage); - $this->mollieHelper->addToLog('info', sprintf('Canceled order %s', $order->getIncrementId())); + $this->config->addToLog('info', sprintf('Canceled order %s', $order->getIncrementId())); } catch (Exception $e) { $message = sprintf('Cannot cancel order %s: %s', $order->getIncrementId(), $e->getMessage()); - $this->mollieHelper->addToLog('error', $message); + $this->config->addToLog('error', $message); } } - /** - * @return OrderInterface - * @throws LocalizedException - */ - private function getOrder() + private function getOrder(): OrderInterface { $token = $this->getRequest()->getParam('paymentToken'); - if (!$token) { throw new LocalizedException(__('The required payment token is not available')); }