Skip to content

Commit

Permalink
RATESWSX-308: remove decorated account order controller
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy committed Sep 3, 2024
1 parent 6733ab0 commit 5b11f82
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 179 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## WIP

* RATESWSX-308: remove decorated account order controller

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

RATESWSX-303: fix admin-session logout endless redirect & make admin-session urls more unified
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)) {
$order = $this->orderRepository->search(CriteriaHelper::getCriteriaForOrder($orderId), $context->getContext())->first();
if ($order instanceof OrderEntity && ($transaction = $order->getTransactions()->last()) instanceof OrderTransactionEntity) {
$paymentHandlerIdentifier = $transaction->getPaymentMethod()->getHandlerIdentifier();
Expand All @@ -60,6 +67,29 @@ public function load(Request $request, SalesChannelContext $context): HandlePaym
$this->dataValidationService->validatePaymentData(new DataBag($request->request->all()), $order ?? $context);
}

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.

0 comments on commit 5b11f82

Please sign in to comment.