From a7b2026f3653f39de5ac75f2430be797a508259c Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Wed, 30 Oct 2024 17:39:11 +0200 Subject: [PATCH] Added redirects from payment controller --- controllers/front/payment.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/controllers/front/payment.php b/controllers/front/payment.php index 1f7404b43..b1bd1f6ea 100644 --- a/controllers/front/payment.php +++ b/controllers/front/payment.php @@ -29,7 +29,6 @@ use PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetPayPalOrderForOrderConfirmationQuery; use PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetPayPalOrderForOrderConfirmationQueryResult; use PrestaShop\Module\PrestashopCheckout\PayPal\Order\ValueObject\PayPalOrderId; -use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalOrderProvider; use PrestaShop\Module\PrestashopCheckout\Repository\PaymentTokenRepository; use PrestaShop\Module\PrestashopCheckout\Repository\PayPalOrderRepository; @@ -83,8 +82,6 @@ public function postProcess() /** @var PayPalOrderRepository $payPalOrderRepository */ $payPalOrderRepository = $this->module->getService(PayPalOrderRepository::class); - /** @var PayPalOrderProvider $payPalOrderProvider */ - $payPalOrderProvider = $this->module->getService(PayPalOrderProvider::class); /** @var CommandBusInterface $commandBus */ $commandBus = $this->module->getService('ps_checkout.bus.command'); /** @var Psr\SimpleCache\CacheInterface $payPalOrderCache */ @@ -93,7 +90,14 @@ public function postProcess() $payPalOrder = $payPalOrderRepository->getPayPalOrderById($this->paypalOrderId); if ($payPalOrder->getIdCart() !== $this->context->cart->id) { - throw new Exception('PayPal order does not belong to this customer'); + $this->redirectToOrderPage(); + } + + $orders = new PrestaShopCollection(Order::class); + $orders->where('id_cart', '=', $payPalOrder->getIdCart()); + + if ($orders->count()) { + $this->redirectToOrderHistoryPage(); } /** @var GetPayPalOrderForOrderConfirmationQueryResult $payPalOrderQueryResult */ @@ -101,22 +105,11 @@ public function postProcess() $payPalOrderFromCache = $payPalOrderQueryResult->getOrderPayPal(); if ($payPalOrderFromCache['status'] === 'COMPLETED') { - $orders = new PrestaShopCollection(Order::class); - $orders->where('id_cart', '=', $payPalOrder->getIdCart()); - - if (!$orders->count()) { - $this->createOrder($payPalOrderFromCache, $payPalOrder); - } - + $this->createOrder($payPalOrderFromCache, $payPalOrder); $this->redirectToOrderConfirmationPage($payPalOrder->getIdCart(), $payPalOrderFromCache['purchase_units'][0]['payments']['captures'][0]['id'], $payPalOrderFromCache['status']); } if ($payPalOrderFromCache['status'] === 'PAYER_ACTION_REQUIRED') { - // Delete from cache so when user is redirected from 3DS authentication page the order is fetched from PayPal - if ($payPalOrderCache->has($this->paypalOrderId->getValue())) { - $payPalOrderCache->delete($this->paypalOrderId->getValue()); - } - $this->redirectTo3DSVerification($payPalOrderFromCache); } @@ -235,4 +228,9 @@ private function redirectToOrderConfirmationPage($cartId, $captureId, $payPalOrd )); } } + + private function redirectToOrderHistoryPage() + { + Tools::redirect($this->context->link->getPageLink('history')); + } }