From 07a7b88a78ca9ef95de7e62746bc9411c1da00a7 Mon Sep 17 00:00:00 2001 From: Frederik Rommel Date: Thu, 5 Dec 2024 16:03:46 +0100 Subject: [PATCH] RATESWSX-321: fix deletion of ratepay-data if payment-method got switched --- CHANGELOG.md | 1 + .../SalesChannel/HandlePaymentMethodRoute.php | 32 ++++++++----------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 601df443..8c252e84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## WIP * RATESWSX-320: dfp: remove validation & improve user-identification +* RATESWSX-321: fix deletion of ratepay-data if payment-method got switched ## Version 7.1.2 - Released on 2024-10-17 diff --git a/src/Components/Checkout/SalesChannel/HandlePaymentMethodRoute.php b/src/Components/Checkout/SalesChannel/HandlePaymentMethodRoute.php index 418ee369..2f259cde 100644 --- a/src/Components/Checkout/SalesChannel/HandlePaymentMethodRoute.php +++ b/src/Components/Checkout/SalesChannel/HandlePaymentMethodRoute.php @@ -44,28 +44,24 @@ public function getDecorated(): AbstractHandlePaymentMethodRoute public function load(Request $request, SalesChannelContext $context): HandlePaymentMethodRouteResponse { - if ($request->headers->count() === 0) { - // it seems like that this is not an API request. This should be an internal call of the route. - // the module should only handle API calls. - return $this->innerService->load($request, $context); - } - $orderId = $request->request->getAlnum('orderId'); + /** @var OrderEntity|null $order */ + $order = !empty($orderId) ? $this->orderRepository->search(CriteriaHelper::getCriteriaForOrder($orderId), $context->getContext())->first() : null; - $paymentHandlerIdentifier = null; - $order = null; - if (!empty($orderId)) { - /** @var OrderEntity|null $order */ - $order = $this->orderRepository->search(CriteriaHelper::getCriteriaForOrder($orderId), $context->getContext())->first(); - if ($order instanceof OrderEntity && ($transaction = $order->getTransactions()->last()) instanceof OrderTransactionEntity) { - $paymentHandlerIdentifier = $transaction->getPaymentMethod()->getHandlerIdentifier(); + if ($request->headers->count() !== 0) { + // we only validate API requests + $paymentHandlerIdentifier = null; + if (!empty($orderId)) { + if ($order instanceof OrderEntity && ($transaction = $order->getTransactions()->last()) instanceof OrderTransactionEntity) { + $paymentHandlerIdentifier = $transaction->getPaymentMethod()->getHandlerIdentifier(); + } + } else { + $paymentHandlerIdentifier = $context->getPaymentMethod()->getHandlerIdentifier(); } - } else { - $paymentHandlerIdentifier = $context->getPaymentMethod()->getHandlerIdentifier(); - } - if ($paymentHandlerIdentifier !== null && is_subclass_of($paymentHandlerIdentifier, AbstractPaymentHandler::class)) { - $this->dataValidationService->validatePaymentData(new DataBag($request->request->all()), $context, $order ?? null); + if ($paymentHandlerIdentifier !== null && is_subclass_of($paymentHandlerIdentifier, AbstractPaymentHandler::class)) { + $this->dataValidationService->validatePaymentData(new DataBag($request->request->all()), $context, $order ?? null); + } } $result = $this->innerService->load($request, $context);