skip to Main Content

I haven’t found a solution for integrating Stripe into my Next.js 13 application in order to integrate Pre-build checkout form.

I have attempted to integrate Stripe into my Next.js 13 application, but unfortunately, I haven’t been able to find a solution thus far. If anyone has successfully achieved this integration and can provide guidance or a solution, I would greatly appreciate it. Please feel free to share any insights or instructions you may have. Thank you.

2

Answers


  1. Use node stripe and create a stripe object with your secret key.

    const stripe = require('stripe')('sk_test_...');
    

    In a server component or API route create a Session object

    const session = await stripe.checkout.sessions.create({
      success_url: 'https://example.com/success', // return URL
      line_items: [
        {price: 'price_H5ggYwtDq4fbrJ', quantity: 2}, // what you sold
      ],
      mode: 'payment',
    });
    

    This is obviously an example, you need to update the call with your needs. See https://stripe.com/docs/api/checkout/sessions/create?lang=node for details.

    Now you can use session.url to redirect your user to the built-in checkout in whichever way you want.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search