diff --git a/src/Controller/CancelLastPayPalPaymentAction.php b/src/Controller/CancelLastPayPalPaymentAction.php index 9d587293..597d9500 100644 --- a/src/Controller/CancelLastPayPalPaymentAction.php +++ b/src/Controller/CancelLastPayPalPaymentAction.php @@ -49,10 +49,12 @@ public function __invoke(Request $request): Response $payment = $order->getLastPayment(); $paymentStateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH); - $paymentStateMachine->apply(PaymentTransitions::TRANSITION_CANCEL); + if ($paymentStateMachine->can(PaymentTransitions::TRANSITION_CANCEL)) { + $paymentStateMachine->apply(PaymentTransitions::TRANSITION_CANCEL); - $this->orderPaymentProcessor->process($order); - $this->objectManager->flush(); + $this->orderPaymentProcessor->process($order); + $this->objectManager->flush(); + } return new Response('', Response::HTTP_NO_CONTENT); } diff --git a/src/Controller/CancelPayPalPaymentAction.php b/src/Controller/CancelPayPalPaymentAction.php index b8e7c06d..7f635ecb 100644 --- a/src/Controller/CancelPayPalPaymentAction.php +++ b/src/Controller/CancelPayPalPaymentAction.php @@ -50,12 +50,14 @@ public function __invoke(Request $request): Response $order = $payment->getOrder(); $paymentStateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH); - $paymentStateMachine->apply(PaymentTransitions::TRANSITION_CANCEL); + if ($paymentStateMachine->can(PaymentTransitions::TRANSITION_CANCEL)) { + $paymentStateMachine->apply(PaymentTransitions::TRANSITION_CANCEL); - $this->orderPaymentProcessor->process($order); - $this->objectManager->flush(); + $this->orderPaymentProcessor->process($order); + $this->objectManager->flush(); - $this->flashBag->add('success', 'sylius.pay_pal.payment_cancelled'); + $this->flashBag->add('success', 'sylius.pay_pal.payment_cancelled'); + } return new Response('', Response::HTTP_NO_CONTENT); }