Overview
The Astro 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 Astro 5 with TypeScript, Tailwind CSS 4, and the
@dodopayments/astro adaptor. To add the same API routes to an existing app, see the Astro 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/astro. - 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:- A Node.js LTS version, which Astro 5 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:
.env file in the root directory:.env.example sets DODO_PAYMENTS_RETURN_URL to port 3000. Change it to 4321, the port the Astro dev server uses, so that checkout returns the customer to your app.The API routes read these variables:DODO_PAYMENTS_API_KEYauthenticates the checkout and Customer Portal routes.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 API routes live undersrc/pages/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
The checkout script insrc/components/ProductCard.astro 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/components/Header.astro opens /api/customer-portal with a hardcoded customer ID. Replace it with the customer ID from your authentication system or database:
Webhook Events
The handler insrc/pages/api/webhook.ts verifies each request with DODO_PAYMENTS_WEBHOOK_KEY, then handles two events:
onSubscriptionActiveruns when a subscription becomes active (subscription.active).onSubscriptionCancelledruns when a subscription is cancelled (subscription.cancelled).
onPaymentSucceeded. The Astro 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
Astro builds the pages as static output, and each API route setsexport const prerender = false so that it renders on demand. On-demand routes need an Astro adapter for your deployment platform:
For other platforms, see Astro’s deployment guides. In your hosting platform, add the four environment variables 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:DODO_PAYMENTS_WEBHOOK_KEY in your production environment to the signing secret of this endpoint.
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/components/Header.astro with the ID of a customer in your Dodo Payments dashboard.In production, get the customer ID from your authentication system and database instead.Build fails with adapter error
Build fails with adapter error
The API routes render on demand, and the repository doesn’t include a deployment adapter. Install the Astro adapter for your platform before you build for production.See Astro’s deployment guides for details.
Learn More
- Dodo Payments Documentation
- Checkout Sessions Documentation
- Webhooks Documentation
- Astro Adaptor: options for the
Checkout,CustomerPortal, andWebhookshandlers - Astro Documentation
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.