From c4737982eaf893983a934a84f2f757f757f161e6 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Tue, 5 Nov 2024 09:44:53 +0200 Subject: [PATCH] Removed capture status check in payment controller --- controllers/front/payment.php | 16 +++++++--------- .../EventSubscriber/CheckoutEventSubscriber.php | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/controllers/front/payment.php b/controllers/front/payment.php index ce806e4cc..758caddec 100644 --- a/controllers/front/payment.php +++ b/controllers/front/payment.php @@ -155,16 +155,14 @@ private function createOrder($payPalOrderFromCache, $payPalOrder) /** @var CommandBusInterface $commandBus */ $commandBus = $this->module->getService('ps_checkout.bus.command'); - $capture = $payPalOrderFromCache['purchase_units'][0]['payments']['captures'][0]; - if ($capture['status'] === 'COMPLETED') { - $commandBus->handle(new CreateOrderCommand($payPalOrder->getId()->getValue(), $capture)); - if ($payPalOrder->getPaymentTokenId() && $payPalOrder->checkCustomerIntent(PayPalOrder::CUSTOMER_INTENT_FAVORITE)) { - /** @var PaymentTokenRepository $paymentTokenRepository */ - $paymentTokenRepository = $this->module->getService(PaymentTokenRepository::class); - $paymentTokenRepository->setTokenFavorite($payPalOrder->getPaymentTokenId()); - } - $this->redirectToOrderConfirmationPage($payPalOrder->getIdCart(), $capture['id'], $payPalOrderFromCache['status']); + $capture = $payPalOrderFromCache['purchase_units'][0]['payments']['captures'][0] ?? null; + $commandBus->handle(new CreateOrderCommand($payPalOrder->getId()->getValue(), $capture)); + if ($payPalOrder->getPaymentTokenId() && $payPalOrder->checkCustomerIntent(PayPalOrder::CUSTOMER_INTENT_FAVORITE)) { + /** @var PaymentTokenRepository $paymentTokenRepository */ + $paymentTokenRepository = $this->module->getService(PaymentTokenRepository::class); + $paymentTokenRepository->setTokenFavorite($payPalOrder->getPaymentTokenId()); } + $this->redirectToOrderConfirmationPage($payPalOrder->getIdCart(), $capture['id'], $payPalOrderFromCache['status']); } /** diff --git a/src/Checkout/EventSubscriber/CheckoutEventSubscriber.php b/src/Checkout/EventSubscriber/CheckoutEventSubscriber.php index cb3bc979f..3ace90834 100644 --- a/src/Checkout/EventSubscriber/CheckoutEventSubscriber.php +++ b/src/Checkout/EventSubscriber/CheckoutEventSubscriber.php @@ -133,7 +133,7 @@ public function proceedToPayment(CheckoutCompletedEvent $event) $this->checkoutChecker->continueWithAuthorization($event->getCartId()->getValue(), $payPalOrder); } catch (PsCheckoutException $exception) { if ($exception->getCode() === PsCheckoutException::PAYPAL_ORDER_ALREADY_CAPTURED) { - $capture = $payPalOrder['purchase_units'][0]['payments']['captures'][0] ?? null; + $capture = isset($payPalOrder['purchase_units'][0]['payments']['captures'][0]) ? $payPalOrder['purchase_units'][0]['payments']['captures'][0] : null; $this->commandBus->handle(new CreateOrderCommand($event->getPayPalOrderId()->getValue(), $capture)); return; @@ -172,7 +172,7 @@ public function proceedToPayment(CheckoutCompletedEvent $event) $event->getPayPalOrderId()->getValue() )); $payPalOrder = $getPayPalOrderForCheckoutCompletedQueryResult->getPayPalOrder(); - $capture = $payPalOrder['purchase_units'][0]['payments']['captures'][0] ?? null; + $capture = isset($payPalOrder['purchase_units'][0]['payments']['captures'][0]) ? $payPalOrder['purchase_units'][0]['payments']['captures'][0] : null; } $this->commandBus->handle(new CreateOrderCommand($event->getPayPalOrderId()->getValue(), $capture));