From e068f7ce0e8c8381b9d9fcfc8485cc225534e48b Mon Sep 17 00:00:00 2001 From: Olivier ALLAIN Date: Fri, 27 Jan 2023 10:27:27 +0100 Subject: [PATCH] fix cancel payment --- src/Controller/CancelLastPayPalPaymentAction.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Controller/CancelLastPayPalPaymentAction.php b/src/Controller/CancelLastPayPalPaymentAction.php index 9d587293..351b4061 100644 --- a/src/Controller/CancelLastPayPalPaymentAction.php +++ b/src/Controller/CancelLastPayPalPaymentAction.php @@ -51,6 +51,14 @@ public function __invoke(Request $request): Response $paymentStateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH); $paymentStateMachine->apply(PaymentTransitions::TRANSITION_CANCEL); + /** @var PaymentInterface $lastPayment */ + $lastPayment = $order->getLastPayment(); + if ($lastPayment->getState() === PaymentInterface::STATE_NEW) { + $this->objectManager->flush(); + + return new Response('', Response::HTTP_NO_CONTENT); + } + $this->orderPaymentProcessor->process($order); $this->objectManager->flush();