Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RATESWSX-321: fix deletion of ratepay-data if payment-method got switched #74

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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->attributes->all('_routeScope')[0] ?? null) === 'store-api') {
// 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
Loading