Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cancel] - cannot cancel an order with an expired Checkout Session #70

Open
cbastienbaron opened this issue Jan 16, 2025 · 2 comments
Open
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@cbastienbaron
Copy link
Contributor

🖖
we facing to an issue for cancelling former order (presume missing cron for sylius:cancel-unpaid-orders cmd), when admin click on cancel btn from order detail page, we hit a 500 error

Handling "FluxSE\SyliusPayumStripePlugin\Command\CancelPayment" failed: Only Checkout Sessions with a status in ["open"] can be expired. This Checkout Session has a status of `expired`.

and this is the same thing when we run cli cmd bin/console sylius:cancel-unpaid-orders -vv

....
 In ApiErrorException.php line 38:
                                                                                                                     
  [Stripe\Exception\InvalidRequestException]                                                                         
  Only Checkout Sessions with a status in ["open"] can be expired. This Checkout Session has a status of `expired`.  
                                                                                                                     

Exception trace:
  at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php:38
 Stripe\Exception\ApiErrorException::factory() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/stripe/stripe-php/lib/Exception/InvalidRequestException.php:35
 Stripe\Exception\InvalidRequestException::factory() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/stripe/stripe-php/lib/ApiRequestor.php:213
 Stripe\ApiRequestor::_specificAPIError() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/stripe/stripe-php/lib/ApiRequestor.php:175
 Stripe\ApiRequestor->handleErrorResponse() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/stripe/stripe-php/lib/ApiRequestor.php:556
 Stripe\ApiRequestor->_interpretResponse() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/stripe/stripe-php/lib/ApiRequestor.php:124
 Stripe\ApiRequestor->request() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/stripe/stripe-php/lib/ApiOperations/Request.php:78
 Stripe\ApiResource::_staticRequest() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/stripe/stripe-php/lib/ApiOperations/Request.php:42
 Stripe\ApiResource->_request() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/stripe/stripe-php/lib/Checkout/Session.php:130
 Stripe\Checkout\Session->expire() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/flux-se/payum-stripe/src/Action/Api/Resource/ExpireSessionAction.php:42
 FluxSE\PayumStripe\Action\Api\Resource\ExpireSessionAction->expireSession() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/flux-se/payum-stripe/src/Action/Api/Resource/ExpireSessionAction.php:35
 FluxSE\PayumStripe\Action\Api\Resource\ExpireSessionAction->retrieveApiResource() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/flux-se/payum-stripe/src/Action/Api/Resource/AbstractRetrieveAction.php:25
 FluxSE\PayumStripe\Action\Api\Resource\AbstractRetrieveAction->execute() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/payum/payum/src/Payum/Core/Gateway.php:107
 Payum\Core\Gateway->execute() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/flux-se/payum-stripe/src/Action/StripeCheckoutSession/CancelAction.php:37
 FluxSE\PayumStripe\Action\StripeCheckoutSession\CancelAction->execute() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/payum/payum/src/Payum/Core/Gateway.php:107
 Payum\Core\Gateway->execute() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/sylius/sylius/src/Sylius/Bundle/PayumBundle/Action/ExecuteSameRequestWithPaymentDetailsAction.php:38
 Sylius\Bundle\PayumBundle\Action\ExecuteSameRequestWithPaymentDetailsAction->execute() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/payum/payum/src/Payum/Core/Gateway.php:107
 Payum\Core\Gateway->execute() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/payum/payum/src/Payum/Core/Action/ExecuteSameRequestWithModelDetailsAction.php:36
 Payum\Core\Action\ExecuteSameRequestWithModelDetailsAction->execute() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/payum/payum/src/Payum/Core/Gateway.php:107
 Payum\Core\Gateway->execute() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/flux-se/sylius-payum-stripe-plugin/src/CommandHandler/CancelPaymentHandler.php:54
 FluxSE\SyliusPayumStripePlugin\CommandHandler\CancelPaymentHandler->__invoke() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/messenger/Middleware/HandleMessageMiddleware.php:152
 Symfony\Component\Messenger\Middleware\HandleMessageMiddleware->callHandler() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/messenger/Middleware/HandleMessageMiddleware.php:91
 Symfony\Component\Messenger\Middleware\HandleMessageMiddleware->handle() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/messenger/Middleware/SendMessageMiddleware.php:71
 Symfony\Component\Messenger\Middleware\SendMessageMiddleware->handle() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/doctrine-bridge/Messenger/DoctrineTransactionMiddleware.php:31
 Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware->handleForManager() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/doctrine-bridge/Messenger/AbstractDoctrineMiddleware.php:45
 Symfony\Bridge\Doctrine\Messenger\AbstractDoctrineMiddleware->handle() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/messenger/Middleware/ValidationMiddleware.php:45
 Symfony\Component\Messenger\Middleware\ValidationMiddleware->handle() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/messenger/Middleware/FailedMessageProcessingMiddleware.php:34
 Symfony\Component\Messenger\Middleware\FailedMessageProcessingMiddleware->handle() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/messenger/Middleware/DispatchAfterCurrentBusMiddleware.php:68
 Symfony\Component\Messenger\Middleware\DispatchAfterCurrentBusMiddleware->handle() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/messenger/Middleware/RejectRedeliveredMessageMiddleware.php:41
 Symfony\Component\Messenger\Middleware\RejectRedeliveredMessageMiddleware->handle() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/messenger/Middleware/AddBusNameStampMiddleware.php:37
 Symfony\Component\Messenger\Middleware\AddBusNameStampMiddleware->handle() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/messenger/Middleware/TraceableMiddleware.php:40
 Symfony\Component\Messenger\Middleware\TraceableMiddleware->handle() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/messenger/MessageBus.php:70
 Symfony\Component\Messenger\MessageBus->dispatch() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/messenger/TraceableMessageBus.php:38
 Symfony\Component\Messenger\TraceableMessageBus->dispatch() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/flux-se/sylius-payum-stripe-plugin/src/StateMachine/CancelOrderProcessor.php:34
 FluxSE\SyliusPayumStripePlugin\StateMachine\CancelOrderProcessor->__invoke() at n/a:n/a
 call_user_func_array() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/winzou/state-machine/src/SM/Callback/Callback.php:75
 SM\Callback\Callback->call() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/winzou/state-machine-bundle/Callback/ContainerAwareCallback.php:55
 winzou\Bundle\StateMachineBundle\Callback\ContainerAwareCallback->call() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/winzou/state-machine/src/SM/Callback/Callback.php:84
 SM\Callback\Callback->__invoke() at n/a:n/a
 call_user_func() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/winzou/state-machine/src/SM/StateMachine/StateMachine.php:217
 SM\StateMachine\StateMachine->callCallbacks() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/winzou/state-machine/src/SM/StateMachine/StateMachine.php:135
 SM\StateMachine\StateMachine->apply() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/winzou/state-machine/src/SM/Callback/CascadeTransitionCallback.php:58
 SM\Callback\CascadeTransitionCallback->apply() at n/a:n/a
 call_user_func_array() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/winzou/state-machine/src/SM/Callback/Callback.php:75
 SM\Callback\Callback->call() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/winzou/state-machine-bundle/Callback/ContainerAwareCallback.php:55
 winzou\Bundle\StateMachineBundle\Callback\ContainerAwareCallback->call() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/winzou/state-machine/src/SM/Callback/Callback.php:84
 SM\Callback\Callback->__invoke() at n/a:n/a
 call_user_func() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/winzou/state-machine/src/SM/StateMachine/StateMachine.php:217
 SM\StateMachine\StateMachine->callCallbacks() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/winzou/state-machine/src/SM/StateMachine/StateMachine.php:135
 SM\StateMachine\StateMachine->apply() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/sylius/sylius/src/Sylius/Component/Core/Updater/UnpaidOrdersStateUpdater.php:64
 Sylius\Component\Core\Updater\UnpaidOrdersStateUpdater->cancelOrder() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/sylius/sylius/src/Sylius/Component/Core/Updater/UnpaidOrdersStateUpdater.php:49
 Sylius\Component\Core\Updater\UnpaidOrdersStateUpdater->cancel() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/Command/CancelUnpaidOrdersCommand.php:45
 Sylius\Bundle\CoreBundle\Command\CancelUnpaidOrdersCommand->execute() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/console/Command/Command.php:326
 Symfony\Component\Console\Command\Command->run() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/console/Application.php:1096
 Symfony\Component\Console\Application->doRunCommand() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/framework-bundle/Console/Application.php:126
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/console/Application.php:324
 Symfony\Component\Console\Application->doRun() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/framework-bundle/Console/Application.php:80
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/vendor/symfony/console/Application.php:175
 Symfony\Component\Console\Application->run() at /warehouse/sylius/master-forks/s3cr3t-proj3ct/bin/console:38

sylius:cancel-unpaid-orders

a potential solution will be to add an additional check on FluxSE\SyliusPayumStripePlugin\CommandHandler\CancelPaymentHandler to compare field expired_at (in payment detail) to current timestamp and pass if payment already expired

or there is a better solution ?

@Prometee
Copy link
Member

Hello @cbastienbaron!

I was searching for a complementary solution allowing to cancel the expired Stripe Checkout Session, it requires to listen to a new event on the Stripe Webhook endpoint. But if the webhook is not listened, like you explained : the handler must check for the expiration before trying to cancel it.

Are you able to create a PR to do so ?

Temporary solution:
#59 (comment)

@Prometee Prometee added bug Something isn't working good first issue Good for newcomers labels Jan 16, 2025
@cbastienbaron
Copy link
Contributor Author

yup @Prometee i'm on it, finalizing behat tests 👍

cbastienbaron added a commit to cbastienbaron/SyliusPayumStripePlugin that referenced this issue Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants