Accept payments with Stripe
Stripe is a fully integrated suite of financial and payments products powering online payment processing and commerce solutions for internet businesses of all sizes. Reduce costs, grow revenue, and run your business more efficiently on a fully integrated, AI-powered platform. Use Stripe to handle all of your payments-related needs, manage revenue operations, and launch (or invent) new business models.
By integrating Stripe with Vercel, you can get started with the products you need to accept payments in a matter of minutes. Instantly create a Stripe integration and sandbox to begin testing payments functionality. Claim your sandbox and all your work once you’re ready to launch your business.
Start by connecting to your existing project and then run vercel link in the CLI to link to the project locally.
npm install --save stripeimport 'server-only'
import Stripe from 'stripe'
export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY)'use server'
import { headers } from 'next/headers'import { stripe } from '@/lib/stripe'
export async function startCheckoutSession(productId: string) { // Implement your product catalog lookup. const product = await getProduct(productId)
// Create Checkout Sessions from body params. const session = await stripe.checkout.sessions.create({ ui_mode: 'embedded', redirect_on_completion: 'never', line_items: [ { price_data: { currency: 'usd', product_data: { name: product.name, description: product.description, }, unit_amount: product.priceInCents, }, quantity: 1, }, ], mode: 'payment', })
return session.client_secret}'use client'
import { useCallback } from 'react'import { EmbeddedCheckout, EmbeddedCheckoutProvider} from '@stripe/react-stripe-js'import { loadStripe } from '@stripe/stripe-js'import { startCheckoutSession } from '@/app/actions/stripe'
const stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY)
export default function Checkout({ productId }: { productId: string }) { const startCheckoutSessionForProduct = useCallback( () => startCheckoutSession(productId), [productId] )
return ( <div id="checkout"> <EmbeddedCheckoutProvider stripe={stripePromise} options={{ clientSecret: startCheckoutSessionForProduct }} > <EmbeddedCheckout /> </EmbeddedCheckoutProvider> </div> )}Install the Stripe integration to create a new sandbox to test your payments functionality. Create products and test transactions directly from Vercel. When ready, claim the sandbox and either create a new Stripe account or bring your work to an existing Stripe account.
Learn more about Stripe with the following resources: