#arcticemerald

1 messages ยท Page 1 of 1 (latest)

late hamletBOT
ornate osprey
#

Interesting. Ok one thing you could do is set your client reference id as metadata on the checkout session itself: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-metadata. Then, when you get the checkout session complete webhook event: https://stripe.com/docs/api/events/types#event_types-checkout.session.completed you can update the customer object with the client reference id on the checkout session object

rocky vine
#

Thank you for the quick response!

Does the checkout.session.completed event guarantee that the payment was successful?

The issue I was concerned about was that if we need to listen to another event to know the subscription was successful (e.g. customer.subscription.created or invoice.paid) there is a potential race condition where we may not update the Customer object with client_reference_id before the invoice.paid webhook is fired. Am I missing something here?

ornate osprey
#

Just curious, why would it be a problem if the customer object is updated with the client reference id prior to invoice.paid being fired?

#

Some delayed notification payment methods might not be successful until after checkout.session.completed fires

rocky vine
#

That case is fine. The issue would be if invoice.paid is fired before the customer is updated in which case there isn't enough information in invoice.paid to associate the payment with a user in our database.

Another approach would be that we store the Stripe customer id in our database but there's still a race here albeit a smaller one: the database update to set the stripe customer id may not happen before we get the invoice.paid webhook.

ornate osprey
#

Got it. Ok I recommend you explicitly create customer objects via the api: https://stripe.com/docs/api/customers/create. Then, grab the customer id in the response object and store that in your database. Then, when you create the checkout session, pass that customer id: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer

rocky vine
#

Ahh okay I think this will work great. I didn't realize I could attach a customer to the checkout session. I'll go try this. Thank you for the help, it is very much appreciated ๐Ÿ™