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 07a7b88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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 07a7b88

Please sign in to comment.