#mtanzi

1 messages ยท Page 1 of 1 (latest)

noble atlasBOT
crisp spindle
#

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.

blazing mural
#

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?

small briar
#

๐Ÿ‘‹ stepping in as Pompey needs to step away

grave stirrup
small briar
#

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

blazing mural
#

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?

small briar
#

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

blazing mural
#

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.completed webhook event
  • call the Stripe::Session.list API filtering by the newly created customer
  • if the API return any Session with status open we need to expire all the open sessions

If this won't work, what would be a better approach?

Thanks! ๐Ÿ™

small briar
#

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?

blazing mural
#

no worries !

The customer is created by the session checkout

small briar
#

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).

blazing mural
#

yes that was my idea ๐Ÿ˜… .. I though that the checkout.session.completed was returning the customer_id created... but yes the email works well ๐Ÿ‘

#

thanks @small briar now I have a good understanding on how to approach the problem! ๐Ÿ™Œ