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

"You cannot cancel this PaymentIntent because it has a status of canceled" error #64

Open
stuffmatic opened this issue May 31, 2020 · 10 comments
Labels
v4.x Issues and PRs targeting the classic frontend (before v5)

Comments

@stuffmatic
Copy link
Contributor

I've started seeing an error that I haven't seen before when trying to proceed from the payment step:

Spree::Core::GatewayError (You cannot cancel this PaymentIntent because it has a
status of canceled. Only a PaymentIntent with one of the following statuses may be
canceled: requires_payment_method, requires_capture, requires_confirmation, requires_action.):

As far as I can tell, I haven't made any changes to my code that would explain this and I'm using a test card number that I've successfully used before (4242 4242 4242 4242).

Here's the full stacktrace

I'm using solidus_stripe 4.0.0, solidus 2.10 and rails 6.0.2.2.

Any clues would be greatly appreciated.

@stuffmatic
Copy link
Contributor Author

stuffmatic commented May 31, 2020

Update: I tried the checkout flow in a private window and it seems to work, so maybe I've got some stale cookie data or something. Regardless, it would be nice if the error above is propagated to the frontend so it can be displayed. Currently nothing happens after the crash and the frontend remains "locked" until manually reloaded.

@spaghetticode
Copy link
Member

Hi @stuffmatic, thanks for sharing this issue. I have never seen that error before payment complete, and from what you wrote it seems to be related to your specific session, so it may be hard to reproduce.

FYI I fixed the very same error recently when refunding an order, see #56. The fix is still only in master, so you may want to bundle that branch until a new release is created.

@stuffmatic
Copy link
Contributor Author

@spaghetticode Yeah, this seems to be an unlikely corner case, so I'm not too concerned about this happening. However, it would be nice if the error was passed to the frontend in the same way as other errors (payment declined etc). Currently, it seems like SolidusStripe::IntentsController#create_payment is crashing with a status 500.

@spaghetticode
Copy link
Member

@stuffmatic what you say about the 500 error makes sense, we need to avoid that the FE interface stops being responsive under those circumstances. A simple solution that comes to my mind is we can rescue Spree::Core::GatewayError in CreateIntentsPaymentService#call and make it return false. Not really sure if we want to expose the original Stripe error message to the FE as well.

By the way, did you happen to see more instances of that error?

@stuffmatic
Copy link
Contributor Author

By the way, did you happen to see more instances of that error?

@spaghetticode Nope. I saw the issue when picking up development after doing other stuff for at least a week, so I just assumed this had to do with stale session data. Haven't tried to reproduce it since.

@spaghetticode
Copy link
Member

Closing as we have no other occurrences of this issue to discuss ATM, but free to reopen!

@jfturcot
Copy link

I hate to comment on a closed issue, but I just ran into this error and did some investigation. I figured the issue and I wanted to share with you what is going on.

When SolidusStripe::CreateIntentsPaymentService#call is called, it tries to void previous payments that are pending with invalidate_previous_payment_intents_payments. This works fine most of the time, except when a payment has been pre-approved but the order was never completed, after some time Stripe will cancel that payment intent which cannot be cancelled again. When this happens, Stripe returns the error payment_intent_unexpected_state and it is not rescued so it creates a 500 error on the application.

@spaghetticode Would you like me to patch it and send a pull request or is this something you prefer the Solidus team to fix?

@spaghetticode
Copy link
Member

@jfturcot thanks for the explanation, and no worries about the closed issue, it now makes sense to reopen it. Of course, a fix would be welcome. How do you think we should proceed when the error you mentioned (payment_intent_unexpected_state) happens?

@spaghetticode spaghetticode reopened this Sep 1, 2021
@jfturcot
Copy link

jfturcot commented Sep 1, 2021

I will fix it this evening after I am done working, I'll send you a pull request when it's done.

@stale
Copy link

stale bot commented Nov 11, 2022

This issue has been automatically marked as stale because it has not had recent activity. It might be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 11, 2022
@gsmendoza gsmendoza removed the stale label Nov 15, 2022
@elia elia added the v4.x Issues and PRs targeting the classic frontend (before v5) label Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v4.x Issues and PRs targeting the classic frontend (before v5)
Projects
None yet
Development

No branches or pull requests

5 participants