#jay492
1 messages ยท Page 1 of 1 (latest)
Hello again!
hi, sorry the other person wasn't that helpful ๐ข
Customer portal ONLY needs a customer ID - it doesn't need a checkout session ID at all. It just so happens that the way your code works it's using the Checkout Session ID to get the Customer ID that's tied to it
would you be able to give the provide code?
so you saying storing session id is too much?
We don't write code for you here but I can help point you in the right direction
Backing up here for a minute - is there a reason you don't want to use the no code customer portal?
This will really make your life way easier
no reason but
i want to try using low-code to implement, i think it gonns be good experience
Integrating with the customer portal isn't really low effort though - the expecation is that your site should have some form of authentication so that you know exactly which customer you're working with
We already have the authentification thing. We hold a session for each customer so we just have to store the right information and take it out
Gotcha - then as long as you have authentication, it's on you to tie that session to a stripe Customer and then create a portal session
You don't need to tie it to a Checkout Sesion ID
You just need to tie it to a Stripe Customer
There's really a ton of different things you can do, it just depends on what your integration is doing
Like if your authentication is already tied to a customer email, you could just use stripe's list Customers API and find the relevant customer with that email (https://stripe.com/docs/api/customers/list#list_customers-email)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
what do you recommend to store?
Again, it's really up to you - you could do this without storing any customers at all like I just mentioned.
why cannot we just store session id so that the customer don't have to go through the email process?
email is already tied to the user account
Like I already mentioned - it's totally fine for you to do that, it'll just result in more calls because the Session ID would need you to re-retrive the Checkout Session to get the Customer ID
At a minimum you need a Customer ID to create a portal session
It's completely up to you how you get or store that Customer ID
how do you get the customer id while making the create-checkout-session?
this is what i have
You would get one back AFTER the checkout session is completed
what do you mean by that
๐ Taking over this thread, catching up now
sweet thank you
After the Checkout Session is completed, i.e. customer completes the payment, a customer ID will be created for you. Your system can then retrieve the customer ID (or even better, store it in your database for future usage) that you can use it to create a portal session
in where should i do that? and how can i cess to the customer id?
i don't see the customer id in the code
After the Checkout Session is completed, Stripe will send checkout.session.completed event to your Webhook endpoint which you can retrieve customer ID from customer field: https://stripe.com/docs/payments/checkout/fulfill-orders#fulfill
Alternatively, you can make a Checkout Session retrieval API to get customer only after Checkout Session is completed. If Checkout Session is not completed yet, customer field will be empty
does stripe do this automatically(sending it to webhook)?
Yes, this is automatic
Your code only handles customer.* related event so far. checkout.session.completed event should be included to get and save the customer field from a given checkout session as stated in https://stripe.com/docs/payments/checkout/fulfill-orders#fulfill
so i add in to the webhook? // Handle the checkout.session.completed event
if (event.type === 'checkout.session.completed') {
// Retrieve the session. If you require line items in the response, you may include them by expanding line_items.
const sessionWithLineItems = await stripe.checkout.sessions.retrieve(
event.data.object.id,
{
expand: ['line_items'],
}
);
const lineItems = sessionWithLineItems.line_items;
// Fulfill the purchase...
fulfillOrder(lineItems);
}
will lineItems have the customer id? and i can store that to our database?
stripe.checkout.sessions.retrieve() is not necessary unless you would like to retrieve the product information.
You can access the Checkout Session object directly with:
checkoutSession = event.data.object;
Then find the customer from this checkoutSession
can you do like checkoutsession.customer?
Yes, I'd recommend giving a try in test mode
of course
checkoutSession = event.data.object;
customerID = checkoutsession.customer
and store the customerID in the database?
Yup!
will this logic be fine?
This logic looks fine to me
at last
why don't you just simply
store the session uid? coz you only need session id so i feel like if i store the session id while making the create-checkout-session, you can provide customer an unique page
if i use the webhook, how can i use the customer id to provide the unque portal page?
You can store the Checkout Session ID and retrieve it later, but the downside is that you will make more requests to Stripe to retrieve Customer ID.
Please note that Stripe has rate limit for the request at 100 requests per second: https://stripe.com/docs/rate-limits If the traffic is high, rate limit will be hit when attempting to retrieve a Checkout Session
if i use the webhook, how can i use the customer id to provide the unque portal page?
Once the customer ID is saved in your database, your system is free to create portal session at anytime
right that's why you suggesting to use the webhook..?
Yes
No problem! Happy to help ๐
you are the best
ah is it better to store the checkoutSession = event.data.object; or the checkoutSession.customer?
either will do right?
If you only need customer, then checkoutSession.customer should be sufficient unless you need other information