diff --git a/src/DependencyInjection/controllers.xml b/src/DependencyInjection/controllers.xml index 1d6e0d712..a6f7aa755 100644 --- a/src/DependencyInjection/controllers.xml +++ b/src/DependencyInjection/controllers.xml @@ -61,19 +61,6 @@ - - - - - - - - - - - - diff --git a/src/DependencyInjection/webhooks.xml b/src/DependencyInjection/webhooks.xml index 846bcec4e..b575687d0 100644 --- a/src/DependencyInjection/webhooks.xml +++ b/src/DependencyInjection/webhooks.xml @@ -35,6 +35,10 @@ + + + + diff --git a/src/Payone/Webhook/Handler/PaymentStatusHandler.php b/src/Payone/Webhook/Handler/PaymentStatusHandler.php new file mode 100644 index 000000000..cbd82bd4c --- /dev/null +++ b/src/Payone/Webhook/Handler/PaymentStatusHandler.php @@ -0,0 +1,50 @@ +transactionDataHandler->getPaymentTransactionByPayoneTransactionId( + $salesChannelContext->getContext(), + $request->request->getInt('txid') + ); + + if (!$paymentTransaction instanceof PaymentTransaction) { + return; + } + + $this->stateMachineRegistry->transition( + new Transition( + OrderTransactionDefinition::ENTITY_NAME, + $paymentTransaction->getOrderTransaction()->getId(), + StateMachineTransitionActions::ACTION_AUTHORIZE, + 'stateId' + ), + $salesChannelContext->getContext() + ); + } + + public function supports(SalesChannelContext $salesChannelContext, array $data): bool + { + return isset($data['txid']) && ($data['txaction'] ?? null) === 'appointed'; + } +} 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 f47334b72..000000000 --- a/src/Resources/views/storefront/page/account/order-history/order-item.html.twig +++ /dev/null @@ -1,10 +0,0 @@ -{% sw_extends '@Storefront/storefront/page/account/order-history/order-item.html.twig' %} - -{% block page_account_order_item_context_menu_content_change_payment_button %} - {% set RATEPAY_PAYMENT_HANDLER = constant('PayonePayment\\PaymentHandler\\PaymentHandlerGroups::RATEPAY') %} - - {# You can't change the payment if it is a ratepay order #} - {% if order.transactions|last.paymentMethod.handlerIdentifier not in RATEPAY_PAYMENT_HANDLER %} - {{ parent() }} - {% endif %} -{% endblock %} \ No newline at end of file diff --git a/src/Storefront/Controller/Account/AccountOrderControllerDecorator.php b/src/Storefront/Controller/Account/AccountOrderControllerDecorator.php deleted file mode 100644 index a8b0ce724..000000000 --- a/src/Storefront/Controller/Account/AccountOrderControllerDecorator.php +++ /dev/null @@ -1,96 +0,0 @@ - ['storefront']])] -class AccountOrderControllerDecorator extends StorefrontController -{ - /** - * @var AccountOrderController - */ - protected $decoratedController; - - public function __construct(StorefrontController $decoratedController, protected EntityRepository $orderRepository) - { - /** @phpstan-ignore-next-line */ - $this->decoratedController = $decoratedController; - } - - public function orderOverview(Request $request, SalesChannelContext $context): Response - { - return $this->decoratedController->orderOverview($request, $context); - } - - public function cancelOrder(Request $request, SalesChannelContext $context): Response - { - return $this->decoratedController->cancelOrder($request, $context); - } - - public function orderSingleOverview(Request $request, SalesChannelContext $context): Response - { - return $this->decoratedController->orderSingleOverview($request, $context); - } - - public function ajaxOrderDetail(Request $request, SalesChannelContext $context): Response - { - return $this->decoratedController->ajaxOrderDetail($request, $context); - } - - public function editOrder(string $orderId, Request $request, SalesChannelContext $context): Response - { - if ($this->isRatepayOrder($orderId, $context->getContext())) { - return $this->redirectToRoute('frontend.account.order.page'); - } - - return $this->decoratedController->editOrder($orderId, $request, $context); - } - - public function orderChangePayment(string $orderId, Request $request, SalesChannelContext $context): Response - { - return $this->decoratedController->orderChangePayment($orderId, $request, $context); - } - - public function updateOrder(string $orderId, Request $request, SalesChannelContext $context): Response - { - if ($this->isRatepayOrder($orderId, $context->getContext())) { - return $this->redirectToRoute('frontend.account.order.page'); - } - - return $this->decoratedController->updateOrder($orderId, $request, $context); - } - - protected function isRatepayOrder(string $orderId, Context $context): bool - { - $criteria = new Criteria([$orderId]); - $criteria->addAssociation('transactions.paymentMethod'); - - /** @var OrderEntity|null $order */ - $order = $this->orderRepository->search($criteria, $context)->first(); - - if ($order && $order->getTransactions()) { - $transaction = $order->getTransactions()->last(); - - if ($transaction - && $transaction->getPaymentMethod() - && \in_array($transaction->getPaymentMethod()->getHandlerIdentifier(), PaymentHandlerGroups::RATEPAY, true)) { - return true; - } - } - - return false; - } -} diff --git a/tests/Storefront/Controller/Account/AccountOrderControllerDecoratorTest.php b/tests/Storefront/Controller/Account/AccountOrderControllerDecoratorTest.php deleted file mode 100644 index efb284d2b..000000000 --- a/tests/Storefront/Controller/Account/AccountOrderControllerDecoratorTest.php +++ /dev/null @@ -1,200 +0,0 @@ -getContainer()->get(AccountOrderController::class); - - static::assertInstanceOf(AccountOrderControllerDecorator::class, $controller); - } - - public function testItRedirectsFromEditOrderPageToOverviewPageOnRatepayOrder(): void - { - $salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation(); - $order = $this->getRandomOrder($salesChannelContext); - $paymentTransaction = $this->getPaymentTransaction($order, PayoneRatepayDebitPaymentHandler::class); - $order->setTransactions(new OrderTransactionCollection([$paymentTransaction->getOrderTransaction()])); - - $orderRepository = $this->createMock(EntityRepository::class); - $orderRepository->expects(static::once())->method('search')->willReturn( - $this->getEntitySearchResult($order, $salesChannelContext) - ); - - $decoratedController = $this->createMock(AccountOrderController::class); - $decoratedController->expects(static::never())->method('editOrder'); - - $controller = new AccountOrderControllerDecorator( - $decoratedController, - $orderRepository - ); - $controller->setContainer($this->getContainer()); - - $response = $controller->editOrder($order->getId(), new Request(), $salesChannelContext); - - static::assertInstanceOf(RedirectResponse::class, $response); - } - - public function testItNotRedirectsFromEditOrderPageToOverviewPageOnOtherPaymentMethodThanRatepay(): void - { - $salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation(); - $order = $this->getRandomOrder($salesChannelContext); - $paymentTransaction = $this->getPaymentTransaction($order, PayoneDebitPaymentHandler::class); - $order->setTransactions(new OrderTransactionCollection([$paymentTransaction->getOrderTransaction()])); - - $orderRepository = $this->createMock(EntityRepository::class); - $orderRepository->expects(static::once())->method('search')->willReturn( - $this->getEntitySearchResult($order, $salesChannelContext) - ); - - $request = new Request(); - $decoratedController = $this->createMock(AccountOrderController::class); - $decoratedController->expects(static::once())->method('editOrder')->with( - static::equalTo($order->getId()), - static::equalTo($request), - static::equalTo($salesChannelContext) - ); - - $controller = new AccountOrderControllerDecorator( - $decoratedController, - $orderRepository - ); - $controller->setContainer($this->getContainer()); - - $response = $controller->editOrder($order->getId(), $request, $salesChannelContext); - - static::assertNotInstanceOf(RedirectResponse::class, $response); - } - - public function testItRedirectsFromUpdateOrderRequestToOverviewPageOnRatepayOrder(): void - { - $salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation(); - $order = $this->getRandomOrder($salesChannelContext); - $paymentTransaction = $this->getPaymentTransaction($order, PayoneRatepayDebitPaymentHandler::class); - $order->setTransactions(new OrderTransactionCollection([$paymentTransaction->getOrderTransaction()])); - - $orderRepository = $this->createMock(EntityRepository::class); - $orderRepository->expects(static::once())->method('search')->willReturn( - $this->getEntitySearchResult($order, $salesChannelContext) - ); - - $decoratedController = $this->createMock(AccountOrderController::class); - $decoratedController->expects(static::never())->method('updateOrder'); - - $controller = new AccountOrderControllerDecorator( - $decoratedController, - $orderRepository - ); - $controller->setContainer($this->getContainer()); - - $response = $controller->updateOrder($order->getId(), new Request(), $salesChannelContext); - - static::assertInstanceOf(RedirectResponse::class, $response); - } - - public function testItNotRedirectsFromUpdateOrderRequestToOverviewPageOnOtherPaymentMethodThanRatepay(): void - { - $salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation(); - $order = $this->getRandomOrder($salesChannelContext); - $paymentTransaction = $this->getPaymentTransaction($order, PayoneDebitPaymentHandler::class); - $order->setTransactions(new OrderTransactionCollection([$paymentTransaction->getOrderTransaction()])); - - $orderRepository = $this->createMock(EntityRepository::class); - $orderRepository->expects(static::once())->method('search')->willReturn( - $this->getEntitySearchResult($order, $salesChannelContext) - ); - - $request = new Request(); - $decoratedController = $this->createMock(AccountOrderController::class); - $decoratedController->expects(static::once())->method('updateOrder')->with( - static::equalTo($order->getId()), - static::equalTo($request), - static::equalTo($salesChannelContext) - ); - - $controller = new AccountOrderControllerDecorator( - $decoratedController, - $orderRepository - ); - $controller->setContainer($this->getContainer()); - - $response = $controller->updateOrder($order->getId(), $request, $salesChannelContext); - - static::assertNotInstanceOf(RedirectResponse::class, $response); - } - - public function testItCallsParentFunctions(): void - { - $salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation(); - $request = new Request(); - $orderId = Uuid::randomHex(); - - $decoratedController = $this->createMock(AccountOrderController::class); - $decoratedController->expects(static::once())->method('orderOverview')->with( - static::equalTo($request), - static::equalTo($salesChannelContext) - ); - $decoratedController->expects(static::once())->method('cancelOrder')->with( - static::equalTo($request), - static::equalTo($salesChannelContext) - ); - $decoratedController->expects(static::once())->method('orderSingleOverview')->with( - static::equalTo($request), - static::equalTo($salesChannelContext) - ); - $decoratedController->expects(static::once())->method('ajaxOrderDetail')->with( - static::equalTo($request), - static::equalTo($salesChannelContext) - ); - $decoratedController->expects(static::once())->method('orderChangePayment')->with( - static::equalTo($orderId), - static::equalTo($request), - static::equalTo($salesChannelContext) - ); - - $controller = new AccountOrderControllerDecorator( - $decoratedController, - $this->createMock(EntityRepository::class) - ); - - $controller->orderOverview($request, $salesChannelContext); - $controller->cancelOrder($request, $salesChannelContext); - $controller->orderSingleOverview($request, $salesChannelContext); - $controller->ajaxOrderDetail($request, $salesChannelContext); - $controller->orderChangePayment($orderId, $request, $salesChannelContext); - } - - protected function getEntitySearchResult(OrderEntity $order, SalesChannelContext $salesChannelContext): EntitySearchResult - { - return new EntitySearchResult( - 'order', - 1, - new EntityCollection([$order]), - null, - new Criteria(), - $salesChannelContext->getContext() - ); - } -}