diff --git a/CHANGELOG.md b/CHANGELOG.md
index e9360f69..840dd22f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/src/Components/Account/Controller/AccountOrderControllerDecorator.php b/src/Components/Account/Controller/AccountOrderControllerDecorator.php
deleted file mode 100644
index d58ca44c..00000000
--- a/src/Components/Account/Controller/AccountOrderControllerDecorator.php
+++ /dev/null
@@ -1,133 +0,0 @@
- ['storefront'],
-])]
-class AccountOrderControllerDecorator
-{
- public function __construct(
- /**
- * @var AccountOrderController
- */
- private readonly StorefrontController $innerService,
- private readonly EntityRepository $orderRepository,
- private readonly RouterInterface $router,
- private readonly EntityRepository $ratepayDataRepository
- ) {
- }
-
- public function updateOrder(string $orderId, Request $request, SalesChannelContext $context): Response
- {
- $orderCriteria = (new Criteria([$orderId]))
- ->addAssociation('transactions.paymentMethod');
-
- /** @var OrderEntity|null $order */
- $order = $this->orderRepository->search($orderCriteria, $context->getContext())->first();
-
- /** @var RatepayOrderDataEntity|null $ratepayData */
- $ratepayData = $order instanceof Entity ? $order->getExtension(OrderExtension::EXTENSION_NAME) : null;
- if ($ratepayData && MethodHelper::isRatepayOrder($order)) {
- if ($ratepayData->isSuccessful()) {
- // You can't change the payment if it is a successful ratepay order
- return new RedirectResponse($this->router->generate('frontend.account.edit-order.page', [
- 'orderId' => $orderId,
- ]));
- }
-
- $this->addRatepayValidationErrors($request);
- }
-
- $return = $this->innerService->updateOrder($orderId, $request, $context);
-
- // check again, if the order is now NOT a ratepay order.
- // if the order has been failed, the customer can switch between the payment methods.
- // after the updateOrder the payment method may not the same as before.
- /** @var OrderEntity $order */
- $order = $this->orderRepository->search($orderCriteria, $context->getContext())->first();
- if ($ratepayData && !MethodHelper::isRatepayOrder($order)) {
- try {
- $event = $this->ratepayDataRepository->delete([[
- RatepayOrderDataEntity::FIELD_ID => $ratepayData->getId(),
- ]], $context->getContext());
- } catch (Exception) {
- // 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 $return;
- }
-
- public function editOrder(string $orderId, Request $request, SalesChannelContext $context): Response
- {
- $this->addRatepayValidationErrors($request);
-
- return $this->innerService->editOrder($orderId, $request, $context);
- }
-
- /* unchanged methods */
-
- public function orderChangePayment(string $orderId, Request $request, SalesChannelContext $context): Response
- {
- return $this->innerService->orderChangePayment($orderId, $request, $context);
- }
-
- public function orderOverview(Request $request, SalesChannelContext $context): Response
- {
- return $this->innerService->orderOverview($request, $context);
- }
-
- public function ajaxOrderDetail(Request $request, SalesChannelContext $context): Response
- {
- return $this->innerService->ajaxOrderDetail($request, $context);
- }
-
- public function cancelOrder(Request $request, SalesChannelContext $context): Response
- {
- return $this->innerService->cancelOrder($request, $context);
- }
-
- public function orderSingleOverview(Request $request, SalesChannelContext $context): Response
- {
- return $this->innerService->orderSingleOverview($request, $context);
- }
-
- protected function addRatepayValidationErrors(Request $request): void
- {
- foreach ($request->get('ratepay-errors', []) as $error) {
- if (($session = $request->getSession()) instanceof Session) {
- $session->getFlashBag()->add('danger', $error);
- }
- }
- }
-}
diff --git a/src/Components/Account/DependencyInjection/controller.xml b/src/Components/Account/DependencyInjection/controller.xml
deleted file mode 100644
index 1a033a7d..00000000
--- a/src/Components/Account/DependencyInjection/controller.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Components/Checkout/DependencyInjection/services.xml b/src/Components/Checkout/DependencyInjection/services.xml
index 6d944ae3..59ad08c6 100644
--- a/src/Components/Checkout/DependencyInjection/services.xml
+++ b/src/Components/Checkout/DependencyInjection/services.xml
@@ -42,6 +42,7 @@
decorates="Shopware\Core\Checkout\Payment\SalesChannel\HandlePaymentMethodRoute">
+
diff --git a/src/Components/Checkout/SalesChannel/HandlePaymentMethodRoute.php b/src/Components/Checkout/SalesChannel/HandlePaymentMethodRoute.php
index 965248d3..64097b00 100644
--- a/src/Components/Checkout/SalesChannel/HandlePaymentMethodRoute.php
+++ b/src/Components/Checkout/SalesChannel/HandlePaymentMethodRoute.php
@@ -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
) {
}
@@ -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) {
@@ -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;
}
}
diff --git a/src/Resources/views/storefront/page/account/order-history/order-item.html.twig b/src/Resources/views/storefront/page/account/order-history/order-item.html.twig
deleted file mode 100644
index cae21f34..00000000
--- a/src/Resources/views/storefront/page/account/order-history/order-item.html.twig
+++ /dev/null
@@ -1,15 +0,0 @@
-{#
- ~ Copyright (c) 2020 Ratepay GmbH
- ~
- ~ For the full copyright and license information, please view the LICENSE
- ~ file that was distributed with this source code.
-#}
-
-{% sw_extends '@Storefront/storefront/page/account/order-history/order-item.html.twig' %}
-
-{% block page_account_order_item_context_menu_content_change_payment_button %}
- {# You can't change the payment if it is a ratepay order #}
- {% if not order.extensions.ratepayData %}
- {{ parent() }}
- {% endif %}
-{% endblock %}