Skip to content
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 @@ -4,6 +4,7 @@

* RATESWSX-306: installment: prevent fatal error message in checkout on unreachable gateway
* RATESWSX-307: add support for login as (third-party modules and Shopware standard since 6.6.5.x)
* RATESWSX-308: remove decorated account order controller

## Version 7.0.1 - Released on 2024-06-07

Expand Down
133 changes: 0 additions & 133 deletions src/Components/Account/Controller/AccountOrderControllerDecorator.php

This file was deleted.

26 changes: 0 additions & 26 deletions src/Components/Account/DependencyInjection/controller.xml

This file was deleted.

1 change: 1 addition & 0 deletions src/Components/Checkout/DependencyInjection/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
decorates="Shopware\Core\Checkout\Payment\SalesChannel\HandlePaymentMethodRoute">
<argument key="$innerService" type="service" id=".inner" />
<argument key="$orderRepository" type="service" id="order.repository" />
<argument key="$ratepayDataRepository" type="service" id="ratepay_order_data.repository" />
</service>

</services>
Expand Down
40 changes: 35 additions & 5 deletions src/Components/Checkout/SalesChannel/HandlePaymentMethodRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,28 @@

use Ratepay\RpayPayments\Components\Checkout\Service\DataValidationService;
use Ratepay\RpayPayments\Components\PaymentHandler\AbstractPaymentHandler;
use Ratepay\RpayPayments\Core\Entity\Extension\OrderExtension;
use Ratepay\RpayPayments\Core\Entity\RatepayOrderDataEntity;
use Ratepay\RpayPayments\Util\CriteriaHelper;
use Ratepay\RpayPayments\Util\MethodHelper;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Checkout\Payment\SalesChannel\AbstractHandlePaymentMethodRoute;
use Shopware\Core\Checkout\Payment\SalesChannel\HandlePaymentMethodRouteResponse;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\Request;
use Throwable;

class HandlePaymentMethodRoute extends AbstractHandlePaymentMethodRoute
{
public function __construct(
private readonly AbstractHandlePaymentMethodRoute $innerService,
private readonly DataValidationService $dataValidationService,
private readonly EntityRepository $orderRepository
private readonly EntityRepository $orderRepository,
private readonly EntityRepository $ratepayDataRepository
) {
}

Expand All @@ -44,10 +50,11 @@ public function load(Request $request, SalesChannelContext $context): HandlePaym
return $this->innerService->load($request, $context);
}

$paymentHandlerIdentifier = null;
if ($request->request->getBoolean('updatePayment')) {
$orderId = $request->request->get('orderId');
$orderId = $request->request->get('orderId');

$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) {
Expand All @@ -61,6 +68,29 @@ public function load(Request $request, SalesChannelContext $context): HandlePaym
$this->dataValidationService->validatePaymentData(new DataBag($request->request->all()), $context, $order ?? null);
}

return $this->innerService->load($request, $context);
$result = $this->innerService->load($request, $context);

$ratepayData = $order?->getExtension(OrderExtension::EXTENSION_NAME);
if ($ratepayData instanceof RatepayOrderDataEntity) {
$orderCriteria = (new Criteria([$orderId]))
->addAssociation('transactions.paymentMethod');

/** @var OrderEntity $order */
$order = $this->orderRepository->search($orderCriteria, $context->getContext())->first();
if (!MethodHelper::isRatepayOrder($order)) {
// if it is not a ratepay order anymore, we delete existing ratepay-data
try {
$this->ratepayDataRepository->delete([[
RatepayOrderDataEntity::FIELD_ID => $ratepayData->getId(),
]], $context->getContext());
} catch (Throwable) {
// catch any exception but not handle it.
// we won't break behaviour of third-party payment methods if deletion fails.
// it is not so bad if we keep the ratepay-data in the database.
}
}
}

return $result;
}
}

This file was deleted.