Retrieve user checkout_sessions using stripeid

Viewed 44

I have an application where I am using stripe subscription extension firebase. At one point I want to retrieve user checkout_sessions (preferably the active ones so i can expire them) using user customerId or stripeId (e.g. cus_xxxxxxxxxx). I am not able to find this solution can anyone help me

1 Answers

If your goal is to automatically expire Checkout Sessions, then you can directly set the expires_at property when creating Checkout Sessions (by default the session will automatically expire after 24 hours).

But if that’s not what you need, here are a couple options to list Checkout Sessions for a specific Customer:

List all Checkout Sessions with stripe.checkout.sessions.list and auto-pagination. Then filter them on your end by checking the customer property. However it might be quite slow to iterate over all Checkout Sessions.

Store the Checkout Session ID <-> Customer relationship in your own database or in the metadata field of the Customer using stripe.customers.update. This way, you can access the Checkout Session ID for each Customer.

Related