stripe.js: can I cancel a PaymentIntent?

489 views
Skip to first unread message

EML

unread,
Feb 24, 2023, 11:03:42 AM2/24/23
to Stripe API Discussion
I can't find a way to cancel a PaymentIntent in stripe.js - is there one?

Problem:

1 - client requests a payment
2 - server creates a PI, and returns a client secret to the client
3 - the client now backs out of the payment.

It seems that the client must now return a cancellation request to the server, together with the  client secret, and the server now has to look up the payment ID from the secret, and then issue an API call to cancel the payment ID. It would be a lot simpler if the client could cancel directly from the client secret, if possible.

Amanda Lee

unread,
Feb 24, 2023, 11:10:29 AM2/24/23
to Stripe API Discussion, EML
Hello,

Unfortunately there is no way to cancel a PaymentIntent using the Stripe.js library, but a quick suggestion that will save you some extra calls would be to send both the client secret and Payment Intent ID back to your client when the Payment Intent is created. 
  1. Client requests a payment
  2. Server creates a PI, and returns a client secret and PaymentIntent ID to the client
  3. The client now backs out of the payment.
  4. Client sends a cancellation request to the server with the PaymentIntent ID
  5. Server makes the request to Stripe to cancel the PaymentIntent
Since the client is sending the PaymentIntent ID back to the server instead of the client secret, you can skip the step of having to look up the PaymentIntent ID from the client secret.

I hope that helps!
Amanda

Reply all
Reply to author
Forward
0 new messages