#arrowcircle

1 messages · Page 1 of 1 (latest)

hardy fractalBOT
warm sentinel
opal onyx
#

I added this, and it returns on session success, but will it be sent on charge_succeeded or charge_failed?

warm sentinel
#

No. It's only attached to the session object

#

If you listen for payment_intent.succeeded instead of charge.succeeded (which is recommended anyway) you can make an additional api call to list checkout sessions by payment intent: https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-payment_intent to get your session and client reference id

opal onyx
#

this means I need to store all the payment_intents ids, that will not have client_reference_id?

#

and how it differs from charge.succeeded?

warm sentinel
#

Payment Intents are the newest version of charges

#

They're build on top of charges

#

So you'll get a payment intent object not a charge object

#

It's up to you though

#

I just suggested you use that instead of charge because there's an easy way to link it to the checkout session so you can get the client reference id via the api endpoint above

opal onyx
#

I still dont get it, If initally I create payment session and add client_reference_id, will it be sent with webhooks about payment_intents in the future of the subscription?

#

And do I get it rights, it's better to listen payment_intent webhooks instead of charge events and checkout session?

warm sentinel
#

Oh these are for subscriptions

#

Ok let me suggest something different then

#

When you initially get a checkout.session.completed event, the event will contain both the subscription id and the client reference id: https://stripe.com/docs/api/checkout/sessions/object. So, once you get that event, I recommend storing a mapping of subscription id -> client_reference_id in your database. Then for future payments, listen to invoice.paid. Really I recommend reading this whole doc to understand subscription events + webhooks before asking further questions: https://stripe.com/docs/billing/subscriptions/webhooks. With invoice.paid, you will get an event when each subscription invoice is paid for every billing cycle. On that invoice object, you can get the subscription: https://stripe.com/docs/api/invoices/object#invoice_object-subscription and then just check your database for the subscription -> client_reference_id mapping to identify the customer.