Add support for canceling authorized payments and adjust payment transition states

This commit is contained in:
Tomasz Kaliński 2026-06-08 08:16:26 +02:00
parent 92ef8a2200
commit b7aa5f8387
3 changed files with 14 additions and 1 deletions

View file

@ -20,7 +20,10 @@ framework:
- !php/const Sylius\Component\Core\OrderPaymentStates::STATE_REFUNDED
transitions:
!php/const Sylius\Component\Core\OrderPaymentTransitions::TRANSITION_REQUEST_PAYMENT:
from: !php/const Sylius\Component\Core\OrderPaymentStates::STATE_CART
from:
- !php/const Sylius\Component\Core\OrderPaymentStates::STATE_CART
- !php/const Sylius\Component\Core\OrderPaymentStates::STATE_AUTHORIZED
- !php/const Sylius\Component\Core\OrderPaymentStates::STATE_PARTIALLY_AUTHORIZED
to: !php/const Sylius\Component\Core\OrderPaymentStates::STATE_AWAITING_PAYMENT
!php/const Sylius\Component\Core\OrderPaymentTransitions::TRANSITION_PARTIALLY_AUTHORIZE:
from:

View file

@ -29,6 +29,8 @@
<tag name="kernel.event_listener" event="workflow.sylius_payment.completed.process" priority="100" />
<tag name="kernel.event_listener" event="workflow.sylius_payment.completed.refund" priority="100" />
<tag name="kernel.event_listener" event="workflow.sylius_payment.completed.authorize" priority="100" />
<tag name="kernel.event_listener" event="workflow.sylius_payment.completed.cancel" priority="50" />
<tag name="kernel.event_listener" event="workflow.sylius_payment.completed.fail" priority="50" />
</service>
</services>
</container>

View file

@ -105,6 +105,14 @@ final class OrderPaymentStateResolver implements StateResolverInterface
return OrderPaymentTransitions::TRANSITION_REQUEST_PAYMENT;
}
$hasReplayablePayment =
!$this->getPaymentsWithState($order, PaymentInterface::STATE_CART)->isEmpty()
|| !$this->getPaymentsWithState($order, PaymentInterface::STATE_NEW)->isEmpty();
if ($hasReplayablePayment) {
return OrderPaymentTransitions::TRANSITION_REQUEST_PAYMENT;
}
return null;
}