FLUX-SE / SyliusPayumStripePlugin

Sylius Payum Stripe gateway plugin (with SCA support)
MIT License
55 stars 24 forks source link

Canceling an unpaid order results in an error #59

Open sinkgregor opened 2 months ago

sinkgregor commented 2 months ago

Hello,

We have encountered an error. When we cancel an order for a customer in the administration, we receive an error indicating that the payment cannot be canceled because the payment is already expired.

The error:

[2024-08-13T12:02:15.944658+02:00] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Messenger\Exception\HandlerFailedException: "Handling "FluxSE\SyliusPayumStripePlugin\Command\CancelPayment" failed: Request Cancel{model: ArrayObject} is not supported. Make sure the gateway supports the requests and there is an action which supports this request (The method returns true). There may be a bug, so look for a related issue on the issue tracker." at DoctrineTransactionMiddleware.php line 42 {"exception":"[object] (Symfony\Component\Messenger\Exception\HandlerFailedException(code: 0): Handling \"FluxSE\SyliusPayumStripePlugin\Command\CancelPayment\" failed: Request Cancel{model: ArrayObject} is not supported. Make sure the gateway supports the requests and there is an action which supports this request (The method returns true). There may be a bug, so look for a related issue on the issue tracker. at /var/www/project/vendor/symfony/doctrine-bridge/Messenger/DoctrineTransactionMiddleware.php:42)\n[previous exception] [object] (Payum\Core\Exception\RequestNotSupportedException(code: 0): Request Cancel{model: ArrayObject} is not supported. Make sure the gateway supports the requests and there is an action which supports this request (The method returns true). There may be a bug, so look for a related issue on the issue tracker. at /var/www/project/vendor/payum/payum/src/Payum/Core/Exception/RequestNotSupportedException.php:57)"} []

Steps to replicate:

  1. Create a new order.
  2. Initiate payment, but do not complete it.
  3. Cancel the order in the administration.

Possible Solution: This could be resolved if the CancelOrderProcessor does not attempt to cancel the payment if the payment is in the state new, or if the CancelPaymentHandler checks whether the transaction is already expired.

This issue interferes with canceling orders because when the cancellation fails, the order is also not canceled, as the transaction is rolled back.

Prometee commented 2 months ago

Hello @sinkgregor!

I'm aware of this issue but frankly I postponed to fix it due to lack of time right now. However it can be easily ignored by sending the CancelPayment command to an async task with this config :

# config/packages/messenger.yaml
framework:
    messenger:
        routing:
            'FluxSE\SyliusPayumStripePlugin\Command\CancelPayment': main
            'FluxSE\SyliusPayumStripePlugin\Command\CaptureAuthorizedPayment': main
            'FluxSE\SyliusPayumStripePlugin\Command\RefundPayment': main

It is far from perfect but can allow you to wait for the fix.

What you suggested is one way to fix this issue, if you can submit a PR I would be glad to review it and help you doing so.