#Horsey

1 messages · Page 1 of 1 (latest)

prisma zenithBOT
vivid bison
#

What immediately comes to mind is that you can use the checkout.session.completed event to save the ID association on your side or set your ID as metadata on the subscription

edgy comet
#

I do save it ... but later, when my webhook endpoint is invoked by Stripe to notify me of a subscription event, that event doesn't have the id. So how would I know its related to the same client?

#

When you say, set the metadata on the subscription ... is that something that can be done via the payment link somehow?

#

Is there another common id between the checkout session completed event and the subscription events?

#

Is it the customer field?

vivid bison
#

Unfortunately it doesn't look like there is a way to set this from the payment link itself. I more meant setting it via a subscription.update call when reacting to the completed event

#

The customer and subscription ID will both be the same between those events

edgy comet
#

Ok, so to be clear this should work:
When I receive the checkout.session.completed event, then I store the provided client_reference_id in association with the customer id from that session. Later, when I get the subscription events, they will have the same customer id, so I can just look up the client reference if again in my own database based on the customer id.

Hope that wasn't too confusing.

#

Am I guaranteed that I won't get the subscription created event before I get the checkout.session.completed? Since everything is asynchronous, I'm worried that if I get the subscription events first, then I will have an error on my server because I won't yet have the association between the customer id and my client reference id.

vivid bison
#

When I receive the checkout.session.completed event, then I store the provided client_reference_id in association with the customer id from that session. Later, when I get the subscription events, they will have the same customer id, so I can just look up the client reference if again in my own database based on the customer id.
Not quite. The client reference ID will show up as the client_reference_id property of the checkout session. The customer field will have the ID of a Stripe Customer ID (cus_123), this event will also include the subscription's ID (sub_123). So you can associate those however you want in your DB at that point

#

Am I guaranteed that I won't get the subscription created event before I get the checkout.session.completed?
Unfortunately not, as you note these events are asynchronous and network latency can also make them arrive out of order. For that reason, we recommend using the API to retreive any objects that you haven't gotten yet if you get events out of order. Trying to think of how to look up the Checkout Session here