#wellthen ๐Ÿ‡ช๐Ÿ‡บ

1 messages ยท Page 1 of 1 (latest)

junior stumpBOT
static pilot
#

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

lost arrow
#

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?

static pilot
#

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.

lost arrow
#

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

static pilot
#

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.

lost arrow
#

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

static pilot
#

Correct

lost arrow
#

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.

static pilot
lost arrow
#

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?

static pilot
lost arrow
#

This doesn't seem like something I'd use. Klarna doesn't use delayed notifications, correct?

static pilot
#

Correct, Klarna payments are immediate.

lost arrow
#

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?

static pilot
#

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.

lost arrow
#

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?

static pilot
#

If you're working with immediate notification payment methods, then the event itself is enough.

lost arrow
#

so simply receiving that intent and checking the session id is fine?

static pilot
#

Those events contain a Checkout Session rather than an intent, but yes, receiving that event is sufficient.

lost arrow
#

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

static pilot
#

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.

lost arrow
#

can't i do something like this?

static pilot
#

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.

lost arrow
#

I assume that's all I need to do?

static pilot
#

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.

lost arrow
#

Okay. Got any ideas how I can test Klarna?

#

are there any test details I can enter

static pilot
lost arrow
#

Cool, that works. So I assume I get the cash immediately if the client selects to pay later?

#

(klarna pays me?)

lost arrow
#

thanks very much!