#_kevinx

1 messages · Page 1 of 1 (latest)

gentle zodiacBOT
gloomy gazelle
#

Hello! Can you provide more details? What Stripe product(s) are you using? What specific thing do you want to confirm?

jaunty valve
#

hello, just using the payment checkout session

#
// This is a public sample test API key.
// Don’t submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
const express = require('express');
const app = express();
app.use(express.static('public'));

const YOUR_DOMAIN = 'http://localhost:4242';

app.post('/create-checkout-session', async (req, res) => {
  const session = await stripe.checkout.sessions.create({
    line_items: [
      {
        // Provide the exact Price ID (for example, pr_1234) of the product you want to sell
        price: '{{PRICE_ID}}',
        quantity: 1,
      },
    ],
    mode: 'payment',
    success_url: `${YOUR_DOMAIN}/success.html`,
    cancel_url: `${YOUR_DOMAIN}/cancel.html`,
  });

  res.redirect(303, session.url);
});

app.listen(4242, () => console.log('Running on port 4242'));
#

I want to confirm on the front end once the payment is successful

#

but search the keyword 'success' in URL seems not secure enough

#

anyone can put it there

gloomy gazelle
#

Ah, okay. With Checkout the best way to do this is to add the {CHECKOUT_SESSION_ID} placeholder to the success_url. That placeholder will be replaced with the Checkout Session's ID which you can then retrieve on your success page to determine what the current state of the Checkout Session is. There are more details here: https://stripe.com/docs/payments/checkout/custom-success-page

jaunty valve
#

Thanks, in this line

 const session = await stripe.checkout.sessions.retrieve(req.query.session_id);

only need to pass session_id ?

gloomy gazelle
#

Yep.

#

That will retrieve the Checkout Session by it's ID, and then you can check the status or any other property you wish.

jaunty valve
#

do I need to pass session_id in the req body?

#

or req.query.session_id would do

#

I guess req,query would do from the URL directly

#

thanks

#

but this is still from the backend

#

is there anyway to check it from the front end directly

#

I have to make another api call to check it

gloomy gazelle
#

Yeah, your success page gets the session ID in the URL, passes it to your server, your server retrieves the Checkout Session, then you can render the success page however you want.

#

You can't retrieve it from the frontend directly, no.

jaunty valve
#

ok, got you, thank you man

#

Is there any example of this using Next JS btw

gloomy gazelle
#

Not that I know of, at least not something made by Stripe.