#jay492

1 messages ยท Page 1 of 1 (latest)

alpine spireBOT
delicate apex
#

Hello again!

quartz dirge
#

hi, sorry the other person wasn't that helpful ๐Ÿ˜ข

delicate apex
#

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

quartz dirge
#

would you be able to give the provide code?

#

so you saying storing session id is too much?

delicate apex
#

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

quartz dirge
#

no reason but

#

i want to try using low-code to implement, i think it gonns be good experience

delicate apex
#

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

quartz dirge
#

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

delicate apex
#

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

quartz dirge
#

so what do i have to store?

#

storing session id is too much?

delicate apex
#

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

quartz dirge
#

what do you recommend to store?

delicate apex
#

Again, it's really up to you - you could do this without storing any customers at all like I just mentioned.

quartz dirge
#

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

delicate apex
#

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

quartz dirge
#

how do you get the customer id while making the create-checkout-session?

delicate apex
#

You would get one back AFTER the checkout session is completed

quartz dirge
#

what do you mean by that

safe obsidian
#

๐Ÿ‘‹ Taking over this thread, catching up now

quartz dirge
#

sweet thank you

safe obsidian
#

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

quartz dirge
#

i don't see the customer id in the code

safe obsidian
#

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

quartz dirge
safe obsidian
#

Yes, this is automatic

quartz dirge
#

this is what i have for webhook rn.

safe obsidian
quartz dirge
#

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?

safe obsidian
#

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

quartz dirge
#

can you do like checkoutsession.customer?

safe obsidian
#

Yes, I'd recommend giving a try in test mode

quartz dirge
#

of course

#

checkoutSession = event.data.object;

#

customerID = checkoutsession.customer

#

and store the customerID in the database?

safe obsidian
#

Yup!

quartz dirge
#

will this logic be fine?

safe obsidian
#

This logic looks fine to me

quartz dirge
#

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?

safe obsidian
#

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

quartz dirge
#

right that's why you suggesting to use the webhook..?

safe obsidian
#

Yes

quartz dirge
#

thank you so much for the help, river

#

i will try it and see it

safe obsidian
#

No problem! Happy to help ๐Ÿ˜„

quartz dirge
#

you are the best

#

ah is it better to store the checkoutSession = event.data.object; or the checkoutSession.customer?

#

either will do right?

safe obsidian
#

If you only need customer, then checkoutSession.customer should be sufficient unless you need other information