#wellthen ๐ช๐บ
1 messages ยท Page 1 of 1 (latest)
You cannot get the Checkout Session's ID directly from a payment_intent.succeeded event.
You can use the ID of the Payment Intent from the event as a filter when listing Checkout Sessions, which will return only the Checkout Session that is related to that intent:
https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-payment_intent
Alternatively, the checkout.session.completed event may also be useful here if you aren't specifically interested in actions on the Payment Intent:
https://stripe.com/docs/api/events/types#event_types-checkout.session.completed
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Can I listen to checkout.session.completed, get the payment intent ID and check if it's paid?
would that be a correct way of checking whether a payment went through?
Yes, you can do that. The checkout.session.completed event contains the Checkout Session object, which has payment_intent field that references the related Payment Intent so you can easily retrieve it and check its status.
would it be a mistake to only listen for checkout.session.completed?
testing the stripe api, it seems that it gets called whenever a card payment gets done
so i'm not sure whether checking the payment intent is even necessary
If you're only processing payments, then it probably isn't necessary. If you later expand what you use Checkout Sessions for, such as using them in setup or subscription mode, then you may need to revisit your event handling code and adapt it to handle those new flows.
so, given that I use only payments, the checkout.session.completed event will only get called if a client finishes a transaction?
successfully, that is
Correct
are there any differences with how I need to handle data if I enable other payment methods for example, such as klarna?
I assume the behaviour with the API would be the same.
You'll want to review your flow if you begin accepting types of payment methods that have delayed notifications (payments where we don't immediately know if they'll succeed like bank transfers). For these, a session can complete and then later have the payment fail.
https://stripe.com/docs/payments/checkout/fulfill-orders#delayed-notification
So, to confirm, checkout.session.completed , in the case of a card payment will mean the payment went through, but in other payment methods, it may mean that the transaction is pending?
Correct, and that isn't for all other payment methods, only ones that have delayed notifications. Our information page about the type of payment method will specify if it uses delayed notifications, as you can see on our ACH page here:
https://stripe.com/docs/payments/ach-debit#:~:text=delayed notification payment method.
This doesn't seem like something I'd use. Klarna doesn't use delayed notifications, correct?
Correct, Klarna payments are immediate.
Is it correct to guess that the Stripe webhooks will always send a checkout.session.completed before payment_intent.succeeded?
or can they send them at any order?
You should never rely on events arriving in a specific order, it's impossible for us to guarantee that the internet won't send some events slower than others.
makes sense
what object should I use to confirm the transaction went through with checkout.session.completed? would checking whether this paid is true be enough?
If you're working with immediate notification payment methods, then the event itself is enough.
so simply receiving that intent and checking the session id is fine?
Those events contain a Checkout Session rather than an intent, but yes, receiving that event is sufficient.
okay, and if I want to enable klarna, would I need to change anything with regards to the API or does Stripe handle it themselves?
I assume payments made via Klarna go to my Stripe account
If you're using automatic payment methods (are not using payment_method_types when creating the Checkout Sessions) then no, you don't need to make changes.
can't i do something like this?
Yes, if you're manually setting the available types of payment methods, then you will need to make code changes to present the new options.
Yup. If you're manually declaring the types of payment methods that you want to offer, then you'll need to update your code that provides those values, but other than that you don't need to make changes.
Yup, test values can be found here:
https://stripe.com/docs/payments/klarna/accept-a-payment?platform=web&ui=checkout#test-integration
Cool, that works. So I assume I get the cash immediately if the client selects to pay later?
(klarna pays me?)
thanks very much!