#jay492

1 messages ยท Page 1 of 1 (latest)

waxen sierraBOT
fringe thicket
#

Hello! Can you give me more details on where/how you're passing in the session ID?

acoustic ore
#

okay so

#

i am trying to implement a payment system on my website. I have a couple of servers and now users can make (create-checkout-session and create-portal-session). Success.html (opening create-portal) works when user open create-portal right after they registered their payment method(create-checkout-session)

#

When you try to open create-portal-session from a link of success.html, you cannot open the portal-session page

#

To set the portal session from the success.html link, do you have to store the user's unique session id and when they open success.html(create-portal) pass the unique id in server.js?

fringe thicket
#

Just to make sure I understand this right - you're creating a billing portal session right after your checkout session is complete?

acoustic ore
#

yes

#

that works perfectly coz it holds the session for a bit?

#

but then if you try to open a portal session from a seperate link( for example, your member page), it does not like to open an unique page

fringe thicket
#

How is your code currently creating the billing portal session? Is it pulling URL params to get the checkout session ID and getting hte customer ID from there? Is it doing something else?

acoustic ore
#

i used example.com in here but i actually use my domain in my actual code

fringe thicket
#

Just from that, it looks like your code is looking at the request body to pull out the Checkout Session, but the Checkout Session ID is included as a query param - do you have some other code for your success page that's taking the query param and making the request to '/create-portal-session'

acoustic ore
#

this success.html is from the stripe official page but basically i am using this

fringe thicket
#

Okay now I have the full picture

#

Earlier when you said you cannot open the portal-session page - is that when you go to just https://payments.example.co.jp/success.html or is that when you try and go to https://payments.example.co.jp/success.html?session_id=cs_live_123

acoustic ore
#

because the member page link cannot doesn't know the session id

fringe thicket
#

Yeah so that won't work

acoustic ore
#

i'm thinking i might have to connect the session id to the my website's user's session and pull it when the user call the portal session or

#

stripe's no code(portal session )somehow has a page asking for email and send a link through email so if there is a way to do it, that might be another option

fringe thicket
#

Yeah you'll either need to implement the logic on your end to know which "user"/customer is currently logged in and pass that along to create a new portal session

waxen sierraBOT
fringe thicket
#

Or you can completely pivot and just redirect to the no-code portal linkhttps://stripe.com/docs/customer-management/activate-no-code-customer-portal

Set up Stripe's customer portal with a no-code configuration.

acoustic ore
#

ah that was what i was thinking once lol

#

code the create-checkout-session and use the non-code for the create-portal

#

Yeah you'll either need to implement the logic on your end to know which "user"/customer is currently logged in and pass that along to create a new portal session....... so how can i do this? just store the session id in database when user added their payment method, and pull it when they need to open the create-porta-session??

fringe thicket
#

Yeah it'll really depends on your integration - you can tie the PHP session to a customer and use that to grab the customer in the future to create a new customer portal

acoustic ore
#

app.post('/create-portal-session', async (req, res) => {

try{
const { session_id } = req.body;
const checkoutSession = await stripe.checkout.sessions.retrieve(session_id);

#

------------------------------------ --------currently i have this but if i am pulling session id from the database, i don't need to create checkout session right?

fringe thicket
#

Correct - but I do want to mention, this'll only work in some situations. If you had a user opening the sucess page in a completely different browser or computer then it won't work at all

acoustic ore
#

how come?

fringe thicket
#

I need to head out but @onyx lantern can help with any other questions you have

acoustic ore
#

okay thank you

acoustic ore
onyx lantern
#

Hello, I read through the thread but am a bit unclear on what you are trying to do with that latest code snippet. What are you trying to handle about your success page with that API call?

acoustic ore
#

so thinking to store the session id in database when user added their card information and pull it out when user need to open the portal page

#

you just need to store the session id for the portal page right?

onyx lantern
#

The portal page needs the customer ID so as long as you are storing that you are good

acoustic ore
#

but this example code from the stripe document is using session id though..?

onyx lantern
#

That is what the comment in the code is about

// For demonstration purposes, we're using the Checkout session to retrieve the customer ID.
// Typically this is stored alongside the authenticated user in your database.

#

You can use Checkout ID to look up customer ID but Customer ID is ultimately what you need to make the customer portal

#

So you can store whatever you want, as long as you can use it to get the Customer ID

acoustic ore
#

would you be able to provide the code for the customer id?

#

do you mean you can pass customer id into this line?? const checkoutSession = await stripe.checkout.sessions.retrieve(CUSTOMERID);

onyx lantern
#

It is shaped like cus_123

#

No

#

You use the Checkout Session ID to retrieve sessions, that Session will have a Customer ID shaped like (cus_123) on it, you can use that to create customer portal sessions

#

I'd highly recommend trying this code out yourself. It should make these things a lot clearer

acoustic ore
#

so i still store session id in database?

onyx lantern
#

It is your choice what to store in your own database. I can't help with that choice unfortunately, I can just provide context on what those IDs are like I did above

acoustic ore
#

i am really confused what you said

#

i am planning to store session id in database and

#

const checkoutSession = await stripe.checkout.sessions.retrieve(SESSIONID THAT WAS STORED IN DATABASE);

#

const returnUrl = YOUR_DOMAIN;

const portalSession = await stripe.billingPortal.sessions.create({
customer: checkoutSession.customer,
return_url: returnUrl,
}); and same for other lines but you saying this will not work, what's the point of storing the user id?

onyx lantern
#

So when you call await stripe.billingPortal.sessions.create, what happens if you don't pass in a customer ID?

#

And what happens if you pass in the ID of a Checkout Session?

acoustic ore
#

the thing is i have not store the session id anywhere yet so

#

if i just open the success.html itself, it will not work