Stripe Webhook Events - Matching Customer IDs?

Viewed 96

I'm testing a subscription product and firing events locally using stripe listen --forward-to .... I believe my endpoint is set up correctly since it can listen for and receive events.

Issue: the customer IDs in the events do not match.

For example, the id in customer.created is cus_J6l***Yu0

The id in customer.subscription.created is cus_J6l***yVb

Also, the subscription IDs in customer.subscription.created and customer.subscription.updated do not match. sub_J6l***ikY and sub_J6l***ufT respectively.

It's unclear to me how to associate these events with each other. In a production setting, I could have many different customers creating subscriptions at a time. My expectation is that there's a key to associate customers and the subscriptions they create (or subscriptions and a subscription update).

1 Answers

Each Subscription is owned exactly by one Customer, see https://stripe.com/docs/api/subscriptions/object#subscription_object-customer. However, a Customer can have one or more Subscription which probably explains why you see a difference in the subscription ids, i.e. the events are fired for different Subscription but for the same Customer. To view the full list of Subscriptions for a given Customer, see https://stripe.com/docs/api/customers/object#customer_object-subscriptions (note this is an expandable field).

Related