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:
- API Key: Create a key under Dashboard → Developer → API Keys.
- Webhook Key: Add an endpoint under Dashboard → Developer → Webhooks, then copy its signing secret. The endpoint URL must be public and use HTTPS. To receive events on your machine, see Webhook Events.
4
Configure Environment Variables
Copy the example file to create a Set the values to your Dodo Payments credentials:The route handlers read these variables:
.env file in the root directory:DODO_PAYMENTS_API_KEYauthenticates the checkout and Customer Portal handlers.DODO_PAYMENTS_WEBHOOK_KEYverifies webhook signatures.DODO_PAYMENTS_RETURN_URLis where checkout sends the customer after payment.DODO_PAYMENTS_ENVIRONMENTistest_modeorlive_mode.
5
Add Your Products
Replace the sample products in The pricing page displays
src/lib/products.ts with your own. Set each product_id to the ID of a product under Products in your dashboard: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
Project Structure
The checkout, Customer Portal, and webhook route handlers live undersrc/app/api/:
Customization
Update Product Information
Editsrc/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 insrc/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:
Webhook Events
The handler insrc/app/api/webhook/route.ts verifies each request with DODO_PAYMENTS_WEBHOOK_KEY, then handles two events:
onSubscriptionActiveruns when a subscription becomes active (subscription.active).onPaymentSucceededruns when a payment succeeds (payment.succeeded).
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
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 ofexample.com:
DODO_PAYMENTS_WEBHOOK_KEY in your production environment.
Troubleshooting
Module not found or build errors
Module not found or build errors
Delete
node_modules and package-lock.json, then reinstall dependencies:Checkout redirect fails
Checkout redirect fails
Check for these common causes:
- The product ID doesn’t exist in your Dodo Payments dashboard.
- The API key or
DODO_PAYMENTS_ENVIRONMENTin.envis wrong. A test mode key works only withtest_mode.
npm run dev.Webhooks not receiving events
Webhooks not receiving events
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.Customer portal link doesn't work
Customer portal link doesn't work
Replace the hardcoded
CUSTOMER_ID in src/app/components/Header.tsx with the ID of a customer in your Dodo Payments dashboard.In production, get the customer ID from your authentication system and database instead.Learn More
- Dodo Payments Documentation
- Checkout Sessions Documentation
- Webhooks Documentation
- Next.js Adaptor: options for the
Checkout,CustomerPortal, andWebhookshandlers
Support
For help with the boilerplate:- Ask questions in the Discord community.
- Report issues and follow updates in the GitHub repository.
- Email the support team.