Accept a payment.

const stripe = require('stripe')(process.env.STRIPE_API_KEY);

export default async (req, res) => {
  const session = await stripe.checkout.sessions.create({
    payment_method_types: ['card'],
    line_items: [
        name: 'Serverless Functions – The Complete Guide',
        description: '100 page e-book on serverless functions.',
        images: [''],
        amount: '5000', // Cents
        currency: 'usd',
        quantity: 1
    success_url: '{CHECKOUT_SESSION_ID}',
    cancel_url: ''

  return res.status(200).json(session);


  1. Create Checkout Session

Using the function above, create a checkout session returning CHECKOUT_SESSION_ID. Upon success, it will redirect to your success_url.

  1. Redirect to Checkout

Follow Stripe's documentation to complete the client-side.

  1. Add Environment Variables

To securely access the API, we need to include the secret with each request. We also do not want to commit secrets to git. Thus, we should use an environment variable. Learn how to add environment variables in Vercel.