Skip to content

Commit

Permalink
RATESWSX-321: fix deletion of ratepay-data if payment-method got swit…
Browse files Browse the repository at this point in the history
…ched
  • Loading branch information
rommelfreddy committed Dec 5, 2024
1 parent c3fa507 commit 8724a93
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/Components/Checkout/SalesChannel/HandlePaymentMethodRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8724a93

Please sign in to comment.