#Timmy-Checkout-Sessions
1 messages · Page 1 of 1 (latest)
Hi! Checkout sessions are active for 24 hours before they automatically expire if they aren't actioned. However, the point here is that you should store Checkout Sessions in your database alongside with your customer info to authenticate your customer and provision access to the Billing Portal.
So I need the session info to allow the customer to access the Customer Portal
What if the user wants to access the Customer Portal 24h after he subscribed to my service?
In the quickstart guide the Checkout Session ID is just used to access the Customer ID that you are providing access to the Customer Portal
The Session itself isn't relevant other than to access the corresponding Customer ID
However this is usually done via storing Customer data in your database and however you want to authenticate the customer.
It is really up to you... using the Checkout Session to grab the Customer ID is just an example of a route you could go
Interesting, what route should I go though? I guess I could just store the Stripe Customer Id in my user table right?
Yeah usually people store that data in their own database, and then you retrieve the data from your database when you authenticate the customer that is visiting your site
Using only the Stripe customer id doesn't cause any security threads right?
No that ID can only be used with your key
Checkout will create a customer automatically if you don't pass one to the Checkout Session (see: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer)
So it is up to you for whether you want to create the Customer ahead of time, or if it is a Customer that is returning to purchase again you will want to pass their Customer ID.
So I should store the Stripe Customer Id to my database once the user initates a checkout right?
I would store it if they successfully complete a Checkout Session
So once a certain event gets triggered?
Yeah. When Checkout.Session.Completed hits your webhook endpoint
That is the recommended route
Awesome thanks
okay so
- Customer Sings up -> logs in
- Customer initiates checkout process
- Stripe creates a customer
- Payment went through (Customer actually subscribed)
- I store the Stripe Customer Id to my db
Yeah. Only clarification is that Stripe only creates the Customer if the Session is successful.
So 3/4 essentially happen in tandem
But yeah that flow is correct
Yes if the Session is successfully completed. This doesn't necessary mean payment as you could start a trial subscription for instance
I see
Okay so once Checkout.Session.Completed gets triggered I basically store the Stripe customer id in my db and
set a db value to true (for example) so the user actually has access to what he paid for
Yep
I store the Stripe Customer Id so the user can later access the Customer portal for example
Using the other events right?
So if the user cancels the subscriptions an event will trigger and call my webhook
Yep
Awesome thanks, I understand Stripe much better now 😄
Is there a way for me to save this conversation and somehow archive it?
The thread will get archived and you can come back to it. I'm not actually sure how long it is retained tbh
No just a random name lol
👍
Hey sorry to disturb you, I have one more question 😅
so I am trying to write the Stripe Customer Id to my db once the Checkout.Session.Completed even triggers
How do I know to which User (in my db) the Stripe customer id belongs to
Do I need to save the Session Id of the checkout process and then find a user that has that session id once Checkout.Session.Completed gets triggered
and then assign the Stripe user id to that db user?
To summarize: How do I map the info I get in the Checkout.Session.Completed event to a specific user in my database
Hi there, jumping in to help 🙂
Usually, when the customers log into your website, you would find the relative Stripe Customer id associated with them from your database.
If this is a new customer, create a new id for them [0].
Then call the create Session API providing this in the customer field [1].
[0] https://stripe.com/docs/api/customers/create
[1] https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer
Thanks for getting back to me ^^
So the new stripe user gets created once I open a new checkout session without providing a customer right?
I don’t create the user manually right now
Based on the documentation I am supposed to associate the stripe user with my user once Checkout.Session.Completed gets triggered
So should I just associate my stripe user with my user once the person creates a new checkout session?
@wooden hearth If the Checkout Session is in payment or subscription mode, Checkout will create a new customer object based on information provided https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-customer
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yes that is what’s currently happening
Now I just need to assign that stripe user is to my user (in my db)
Which I am supposed to do using the Checkout.Session.Completed event
Yes, you can get the customer from customer property of the session object.
But that event only knows the stripe user id
I think you mean customer ID. you can get the customer object by using the retrieve API https://stripe.com/docs/api/customers/retrieve
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 sorry I mean the customer id
So how am I supposed to map the stripe customer id to a user in my db in the Checkout.Session.Completed event?
How do you store the customer object in your DB?
I am not 100% sure what you mean but:
The user creates an account
Signs in
Pays using stripe
Every user in my db has a property called ‘StripeCustomerId’
Also I just saw that the checkout session object has a property called ‘client_reference_id’
Should I use that? (do I have access to that in the Checkout.Session.Completed event?
Also please excuse my bad writing I am on my phone right now 😅
No worries, I'd suggest you to use the customer.id, which is a unique key, to map the Stripe customer to your DB.
I have the stripe customer id but I don’t know which of my user it belongs to
The event doesn’t give me any information
Do you have an event ID that I can take a look?
No worries, I'll keep this thread open so feel free to come back and either my colleague or I will continue helping you