From 946cc177658785939ec9f2ab4b3ea728791cae27 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Wed, 13 Dec 2023 09:13:23 +0100 Subject: [PATCH] allow pending payments in checkout workflow --- .../config/pimcore/workflow/coreshop_payment.yml | 2 +- .../StateResolver/OrderPaymentStateResolver.php | 12 ++++++++++++ .../Bundle/PayumBundle/Action/ConfirmOrderAction.php | 3 ++- .../PayumBundle/Action/ResolveNextRouteAction.php | 3 ++- .../Extension/UpdateOrderStateExtension.php | 3 ++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/workflow/coreshop_payment.yml b/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/workflow/coreshop_payment.yml index b2a209443a..3a0f808401 100755 --- a/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/workflow/coreshop_payment.yml +++ b/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/workflow/coreshop_payment.yml @@ -4,7 +4,7 @@ core_shop_workflow: callbacks: after: resolve_state: - on: ['complete', 'refund', 'authorize'] + on: ['complete', 'process', 'refund', 'authorize'] do: ['@CoreShop\Bundle\OrderBundle\StateResolver\OrderPaymentStateResolver', 'resolve'] args: ['object.getOrder()'] add_to_history: diff --git a/src/CoreShop/Bundle/OrderBundle/StateResolver/OrderPaymentStateResolver.php b/src/CoreShop/Bundle/OrderBundle/StateResolver/OrderPaymentStateResolver.php index 6a6f9b4d94..0e7b502320 100644 --- a/src/CoreShop/Bundle/OrderBundle/StateResolver/OrderPaymentStateResolver.php +++ b/src/CoreShop/Bundle/OrderBundle/StateResolver/OrderPaymentStateResolver.php @@ -100,6 +100,18 @@ private function getTargetTransition(OrderInterface $order): ?string return OrderPaymentTransitions::TRANSITION_PARTIALLY_AUTHORIZE; } + // Processing payments + $processingPaymentTotal = 0; + $processingPayments = $this->getPaymentsWithState($order, PaymentInterface::STATE_PROCESSING); + + foreach ($processingPayments as $payment) { + $processingPaymentTotal += $payment->getTotalAmount(); + } + + if (count($processingPayments) > 0 && $processingPaymentTotal >= $order->getPaymentTotal()) { + return OrderPaymentTransitions::TRANSITION_REQUEST_PAYMENT; + } + return null; } diff --git a/src/CoreShop/Bundle/PayumBundle/Action/ConfirmOrderAction.php b/src/CoreShop/Bundle/PayumBundle/Action/ConfirmOrderAction.php index eee4cf6525..20ae57bb94 100644 --- a/src/CoreShop/Bundle/PayumBundle/Action/ConfirmOrderAction.php +++ b/src/CoreShop/Bundle/PayumBundle/Action/ConfirmOrderAction.php @@ -37,7 +37,8 @@ public function execute($request): void $payment = $request->getFirstModel(); $order = $payment->getOrder(); if ($payment->getState() === PaymentInterface::STATE_COMPLETED || - $payment->getState() === PaymentInterface::STATE_AUTHORIZED + $payment->getState() === PaymentInterface::STATE_AUTHORIZED || + $payment->getState() === PaymentInterface::STATE_PROCESSING ) { $this->stateMachineApplier->apply($order, OrderTransitions::IDENTIFIER, OrderTransitions::TRANSITION_CONFIRM); diff --git a/src/CoreShop/Bundle/PayumBundle/Action/ResolveNextRouteAction.php b/src/CoreShop/Bundle/PayumBundle/Action/ResolveNextRouteAction.php index c1a982312f..573b84a7af 100644 --- a/src/CoreShop/Bundle/PayumBundle/Action/ResolveNextRouteAction.php +++ b/src/CoreShop/Bundle/PayumBundle/Action/ResolveNextRouteAction.php @@ -42,7 +42,8 @@ public function execute($request): void ]); if ($payment->getState() === PaymentInterface::STATE_COMPLETED || - $payment->getState() === PaymentInterface::STATE_AUTHORIZED + $payment->getState() === PaymentInterface::STATE_AUTHORIZED || + $payment->getState() === PaymentInterface::STATE_PROCESSING ) { $request->setRouteName('coreshop_checkout_thank_you'); $request->setRouteParameters([ diff --git a/src/CoreShop/Bundle/PayumBundle/Extension/UpdateOrderStateExtension.php b/src/CoreShop/Bundle/PayumBundle/Extension/UpdateOrderStateExtension.php index 41b3cb6027..813be9e076 100644 --- a/src/CoreShop/Bundle/PayumBundle/Extension/UpdateOrderStateExtension.php +++ b/src/CoreShop/Bundle/PayumBundle/Extension/UpdateOrderStateExtension.php @@ -92,7 +92,8 @@ public function onPostExecute(Context $context): void } if ($value === PaymentInterface::STATE_COMPLETED || - $value === PaymentInterface::STATE_AUTHORIZED + $value === PaymentInterface::STATE_AUTHORIZED || + $value === PaymentInterface::STATE_PROCESSING ) { $order = $payment->getOrder(); $this->confirmOrderState($order);