next-stripe
A convenience library for server side Stripe workflows with Next.js
Getting Started
yarn add next-stripe@beta
Add the API route
Create a [...nextstripe.js]
catch-all route in your project's pages/api/stripe
directory.
import NextStripe from 'next-stripe'
const options = {
secret_key: process.env.STRIPE_SECRET_KEY
}
export default (req, res) => NextStripe(req, res, options)
Usage
next-stripe/client
exports a selection helper functions to call the Next.js API routes.
Checkout Sessions
Create
import { createCheckoutSession } from 'next-stripe/client'
const session = await createCheckoutSession({
success_url: window.location.href,
cancel_url: window.location.href,
line_items: [{ price: 'price_id', quantity: 1 }],
payment_method_types: ['card'],
mode: 'payment'
})
PaymentIntents
Create
import { createPaymentIntent } from 'next-stripe/client'
const session = await createPaymentIntent({
amount: 1000,
currency: 'usd'
})