Skip to content

Commit db70fae

Browse files
committed
Cancel payment only if it's possible
1 parent c10d26c commit db70fae

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Controller/CancelLastPayPalPaymentAction.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ public function __invoke(Request $request): Response
4949
$payment = $order->getLastPayment();
5050

5151
$paymentStateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH);
52-
$paymentStateMachine->apply(PaymentTransitions::TRANSITION_CANCEL);
52+
if ($paymentStateMachine->can(PaymentTransitions::TRANSITION_CANCEL)) {
53+
$paymentStateMachine->apply(PaymentTransitions::TRANSITION_CANCEL);
5354

54-
$this->orderPaymentProcessor->process($order);
55-
$this->objectManager->flush();
55+
$this->orderPaymentProcessor->process($order);
56+
$this->objectManager->flush();
57+
}
5658

5759
return new Response('', Response::HTTP_NO_CONTENT);
5860
}

src/Controller/CancelPayPalPaymentAction.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ public function __invoke(Request $request): Response
5050
$order = $payment->getOrder();
5151

5252
$paymentStateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH);
53-
$paymentStateMachine->apply(PaymentTransitions::TRANSITION_CANCEL);
53+
if ($paymentStateMachine->can(PaymentTransitions::TRANSITION_CANCEL)) {
54+
$paymentStateMachine->apply(PaymentTransitions::TRANSITION_CANCEL);
5455

55-
$this->orderPaymentProcessor->process($order);
56-
$this->objectManager->flush();
56+
$this->orderPaymentProcessor->process($order);
57+
$this->objectManager->flush();
5758

58-
$this->flashBag->add('success', 'sylius.pay_pal.payment_cancelled');
59+
$this->flashBag->add('success', 'sylius.pay_pal.payment_cancelled');
60+
}
5961

6062
return new Response('', Response::HTTP_NO_CONTENT);
6163
}

0 commit comments

Comments
 (0)