#mtanzi
1 messages ยท Page 1 of 1 (latest)
There isn't a stripe configuration to do this but you can do it with webhooks and the API. You can listen for the checkout.session.completed event and then use the expire endpoint in the API https://stripe.com/docs/api/checkout/sessions/expire
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
In addition to the webhook you could also listen on your server for the return URL being hit for that checkout session as well, that can sometimes come in slightly faster but isn't always guarunteed to happen so it is recommended to always at least listen for the webhook.
thank you @crisp spindle !
What is the best way to know if there is an open session for the same customer?
I saw that there is the Session.list API, can I filter by customer?
๐ stepping in as Pompey needs to step away
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yeah what @grave stirrup pointed to will filter Sessions, but that won't actually work though if the Session hasn't been completed yet in terms of filtering by Customer because the Customer won't be created yet
if I call the Stripe::Session.list API when I receive the checkout.session.completed at that point the customer should be already created, no?
if the session.list api return any active session I will proceed to expire them
would that work?
You won't know that the active Session is for that same Customer though
Because the Customer won't be created until the Session is completed
sorry @small briar I might have been missing something ๐
let me recap... I have 2 tab with an active session open... the session on the tab1 succeed...
now what I will do is the following:
- listen to the
checkout.session.completedwebhook event - call the
Stripe::Session.listAPI filtering by the newly created customer - if the API return any Session with status
openwe need to expire all the open sessions
If this won't work, what would be a better approach?
Thanks! ๐
Sorry, I should have asked a clarifying question first: are you passing a Customer ID to the Checkout Session, or having Checkout create Customers for you?
no worries !
The customer is created by the session checkout
Okay so that is why I say you won't receive any Session when you list by Customer here if the second Session hasn't been completed yet.
You can test it out if you like
But the List request should always be empty since the Customer won't actually be created until the Session has been completed, not when it is started.
Thinking of a better approach....
Mostly I don't think there is one and you should de-duplicate after the Session has been completed. So listen for checkout.session.completed and then list Customers by the email of the Customer object that was created using: https://stripe.com/docs/api/customers/list#list_customers-email. If that returns more than 1 then you can handle as you desire (sounds like you would want to cancel the second Subsription).
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.