Skip to main content

Overview

The Next.js minimal boilerplate is a starter app with Dodo Payments already connected. Add your API keys and product IDs, and you get a pricing page that opens checkout, a webhook endpoint for payment events, and a link to the Customer Portal.
This boilerplate uses the Next.js 16 App Router with TypeScript, Tailwind CSS 4, and the @dodopayments/nextjs adaptor. To add the same route handlers to an existing app, see the Next.js Adaptor.

Features

The boilerplate includes:
  • Quick Setup: Go from clone to a running pricing page in about five minutes.
  • Checkout: A pre-configured checkout flow built on @dodopayments/nextjs.
  • Pricing Page: A dark-themed pricing page styled with Tailwind CSS.
  • Webhook Handler: An endpoint that verifies each webhook signature and runs your code for the event.
  • Customer Portal: A header link that opens the Customer Portal, where customers manage their subscriptions.
  • TypeScript: Typed product definitions and handlers.
  • Pre-filled Checkout: Passes the customer’s name and email to checkout, so the customer doesn’t retype them.

Prerequisites

Before you begin, you need:
  • Node.js 20.9 or later, which Next.js 16 requires.
  • A Dodo Payments account, to create an API key and a webhook signing secret in the dashboard.

Quick Start

1

Clone the Repository

2

Install Dependencies

3

Get API Credentials

Sign up at Dodo Payments, then get your credentials from the dashboard:
Create both while the Live Mode switch in the sidebar is off. A test mode key works only with DODO_PAYMENTS_ENVIRONMENT=test_mode, and test mode payments don’t move real money.
4

Configure Environment Variables

Copy the example file to create a .env file in the root directory:
Set the values to your Dodo Payments credentials:
The route handlers read these variables:
  • DODO_PAYMENTS_API_KEY authenticates the checkout and Customer Portal handlers.
  • DODO_PAYMENTS_WEBHOOK_KEY verifies webhook signatures.
  • DODO_PAYMENTS_RETURN_URL is where checkout sends the customer after payment.
  • DODO_PAYMENTS_ENVIRONMENT is test_mode or live_mode.
Don’t commit your .env file to version control. The repository’s .gitignore already excludes it.
5

Add Your Products

Replace the sample products in src/lib/products.ts with your own. Set each product_id to the ID of a product under Products in your dashboard:
The pricing page displays name, description, price, and features from this file. Checkout charges the price set on the product in Dodo Payments, so keep price in sync with it.
6

Run the Development Server

Open http://localhost:3000 to see your pricing page.

Project Structure

The checkout, Customer Portal, and webhook route handlers live under src/app/api/:

Customization

Update Product Information

Edit src/lib/products.ts to change:
  • Product IDs, from Products in your Dodo Payments dashboard
  • Prices
  • Features
  • Descriptions

Pre-fill Customer Data

src/app/components/ProductCard.tsx sends a hardcoded name and email with each checkout request. Replace them with the signed-in user’s details:

Update Customer Portal

The Customer Portal link in src/app/components/Header.tsx opens /api/customer-portal with a hardcoded customer ID. Replace it with the signed-in user’s Dodo Payments customer ID:
To get a customer ID for testing, complete a test purchase, then copy the customer’s ID from Customers in the dashboard. In production, fetch the ID from your backend.

Webhook Events

The handler in src/app/api/webhook/route.ts verifies each request with DODO_PAYMENTS_WEBHOOK_KEY, then handles two events:
  • onSubscriptionActive runs when a subscription becomes active (subscription.active).
  • onPaymentSucceeded runs when a payment succeeds (payment.succeeded).
Add your business logic inside these handlers:
To handle more events, add their handlers, such as onSubscriptionCancelled. The Next.js Adaptor lists every supported handler. Dodo Payments can’t reach localhost. For local development, use a tunnel such as ngrok to expose your local server, and use the tunnel URL as your webhook endpoint.

Deployment

Build for Production

Deploy to Vercel

Deploy with Vercel Add the four environment variables in the Vercel dashboard, and set DODO_PAYMENTS_RETURN_URL to your production URL.

Update Webhook URL

After deploying, add your production webhook URL in the Dodo Payments Dashboard, with your domain in place of example.com:
Each endpoint has its own signing secret. Copy the new endpoint’s secret into DODO_PAYMENTS_WEBHOOK_KEY in your production environment.

Troubleshooting

Delete node_modules and package-lock.json, then reinstall dependencies:
Check for these common causes:
  • The product ID doesn’t exist in your Dodo Payments dashboard.
  • The API key or DODO_PAYMENTS_ENVIRONMENT in .env is wrong. A test mode key works only with test_mode.
Look for the error in the browser console and in the terminal that runs npm run dev.
For local testing, use ngrok to expose your server:
In your Dodo dashboard, add an endpoint with the ngrok HTTPS URL followed by /api/webhook. Copy that endpoint’s signing secret into DODO_PAYMENTS_WEBHOOK_KEY in your .env file.

Learn More

Support

For help with the boilerplate:
Last modified on September 25, 2026