#Logan - Customer Portal 404

1 messages ยท Page 1 of 1 (latest)

tawny violet
#

HI ๐Ÿ‘‹

feral axle
#

Hi Snufkin

#

How are you

tawny violet
#

Hmmm... can you share the request ID from the request where you tried to create this customer portal session?
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request

feral axle
tawny violet
#

Thanks, looking

#

Oh,

#
error: {
    message: "Invalid checkout.session id: cus_MAl6rV6WEAn0Q5",
    type: "invalid_request_error"
  }
#

You tried to use the Customer ID for the Session ID in the URL

feral axle
#

Thus I do not believe there is a session ID in the subscriptionData

#

Is there a way to create a portal without an active session?

tawny violet
#
const portalSession = await stripe.billingPortal.sessions.create({
    customer: checkoutSession.customer,
    return_url: returnUrl,
  });

You are creating the portal session here. It should return a correctly configured URL

feral axle
#

Having trouble pinpointing exactly what is going wrong here - my return URL is just localhost

tawny violet
#

You shouldn't need to

#

The portalSession.url should include it.

feral axle
#

I am trying to send the portalSession.url to my frontend, but this 404 seems to be blocking me from doing that

tawny violet
#

Can you try logging out the entire portalSession object? Make sure it matches what the API ref doc shows here?

feral axle
#

Sure, one moment

feral axle
tawny violet
#

Okay. So if you follow the link in the url property for the portalSession object you logged, do you get to an actual customer portal interface?

feral axle
#

I cannot generate a portalSession object

#

With my code

#

There is no doubt that the URL in your example would work

#

Problem is, I'm passing my own cus_id from my database, and the API is kicking back a 404

#

saying invalid ID

#

But when I plugged my ID manually into your example, it worked fine. I dont get it

tawny violet
#

I'm confused. The code you shared is clearly designed to generate a portal session.

feral axle
#

I will post a quick video

tawny violet
#

Don't, I won't view it

#

Security issues

feral axle
#

Ok. Basically, I am sending a customer ID to your API, and the API is responding with "Nah fam"

#

Trying to generate that portal URL

#

but cant

tawny violet
#

The request you sent me is not something that would work. You made a GET request to /checkout/sessions with a customer ID on the end. The only API that accepts a Customer ID is the Customer API

#

The error it returns is that there isn't a checkout session using that ID, which makes sense because it's a Customer ID

feral axle
#

That makes sense.

tawny violet
#

To create a customer portal you would be making a POST request to /v1/billing_portal/sessions with both the Customer ID and the Return URL in the body of the request

feral axle
#

WOW

#

What am I doing?!?!

#

Putting the checkout session there -___-

#

That worked LOL

tawny violet
#

Okay so the slimmed down, simplified approach got you a working customer portal?

feral axle
#

Yup!

#

app.get("/api2/create-portal-session", async (req, res) => {
  const userId = req.query.userId;
  const userData = await User.findOne({ username: userId });

  const { customer } = userData.subscriptionData.data.object

  const portalSession = await stripe.billingPortal.sessions.create({
    customer: customer,
    return_url: "http://localhost:3000/",
  });

  res.send(portalSession.url);
});
#

I have no idea what I was doing trying to make a checkout session

tawny violet
#

๐ŸŽ‰
Great, I'm glad it's working ๐Ÿ™‚

#

Hey, we are calling a lot of things "sessions" so I get it

feral axle
#

Thank you very much for your help ๐Ÿ˜„