GitHub Repository
Complete source code and setup guide
Quick Setup
1. Prerequisites
You need:- A Vercel account
- A Neon database account
- A Dodo Payments API key from Developer → API Keys in the dashboard
2. Install Dependencies
3. Database Setup
- Sign up for Neon and create a project.
- Open the SQL Editor.
- Copy the entire contents of
schema.sqland run it. - Copy your connection string from Connection Details.
4. Set Initial Environment Variables
You’ll set
DODO_PAYMENTS_WEBHOOK_KEY after deployment, once you have your webhook URL.5. Deploy
6. Get Your Webhook URL
Your webhook URL is:7. Register Webhook in DodoPayments Dashboard
- Go to Developer → Webhooks in the Dodo Payments dashboard.
- Click Add endpoint.
- Enter your webhook URL.
- Select these events:
subscription.active,subscription.cancelled,subscription.renewed. - Click Create endpoint and copy the signing secret.
8. Set Webhook Key & Redeploy
What It Does
The webhook handler processes subscription events and stores them in PostgreSQL:subscription.active— Creates or updates customer and subscription recordssubscription.cancelled— Marks the subscription as cancelledsubscription.renewed— Updates the next billing date
Key Features
- Signature verification — Uses the Dodo Payments SDK to verify webhook authenticity
- Idempotency — Uses the
webhook-idheader to prevent duplicate processing - Event logging — Stores all events in the
webhook_eventstable for audit trails - Error handling — Logs failures and marks events for retry
This example handles three core subscription events with minimal fields. You can extend it to support additional event types and fields based on your needs.
Configuration Files
Database Schema
customers— Email, name, and Dodo Payments customer IDsubscriptions— Status, amount, next billing date, linked to customerswebhook_events— Event log with webhook ID for idempotency
Implementation Code
How It Works
The webhook handler:- Disables body parsing — To access the raw body for signature verification
- Verifies the signature — Uses the Dodo Payments SDK to verify the request with HMAC-SHA256
- Checks for duplicates — Uses the
webhook-idheader to prevent processing the same event twice - Logs the event — Stores the raw webhook in the
webhook_eventstable for audit trails - Processes the event — Creates or updates customers and subscriptions in Neon
- Handles errors — Logs failures and marks events as unprocessed for retry
Testing
Local development:- Select your project.
- Go to Deployments → latest deployment.
- Click Functions → Logs.
- Go to Developer → Webhooks.
- Add an endpoint with your Vercel Functions URL.
- Select
subscription.active,subscription.cancelled, andsubscription.renewed.