Skip to main content

GitHub Repository

Complete source code and setup guide

Quick Setup

1. Prerequisites

2. Install Dependencies

3. Database Setup

  1. Sign up for Neon
  2. Create a new project
  3. Open the SQL Editor
  4. Copy and paste the contents of schema.sql
  5. Run the query
  6. Get your connection string from Neon โ†’ Connection Details

4. Set Initial Environment Variables

Via Vercel CLI:
Note: Weโ€™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

  1. Go to DodoPayments Dashboard โ†’ Developer โ†’ Webhooks
  2. Create a new webhook endpoint
  3. Configure your webhook URL as the endpoint
  4. Enable these subscription events:
    • subscription.active
    • subscription.cancelled
    • subscription.renewed
  5. Copy the Signing Secret

8. Set Webhook Key & Redeploy

What It Does

Processes subscription events and stores them in PostgreSQL:
  • subscription.active - Creates/updates customer and subscription records
  • subscription.cancelled - Marks subscription as cancelled
  • subscription.renewed - Updates next billing date

Key Features

โœ… Signature verification - Using the dodopayments library
โœ… Idempotency - Prevents duplicate processing with webhook IDs
โœ… Event logging - Complete audit trail in webhook_events table
โœ… Error handling - Logged and retryable
Note: This implementation demonstrates handling three core subscription events (subscription.active, subscription.cancelled, subscription.renewed) with minimal fields. You can easily extend it to support additional event types and fields based on your requirements.

Configuration Files

Database Schema

Tables created:
  • customers - Email, name, dodo_customer_id
  • subscriptions - Status, amount, next_billing_date, linked to customers
  • webhook_events - Event log with webhook_id for idempotency

Implementation Code

How It Works

The webhook handler:
  1. Disables body parsing - To access raw body for signature verification
  2. Verifies the signature - Ensures the request is from DodoPayments using HMAC-SHA256
  3. Checks for duplicates - Uses webhook ID to prevent processing the same event twice
  4. Logs the event - Stores raw webhook in webhook_events table for audit trail
  5. Processes the event - Creates or updates customers and subscriptions in Neon
  6. Handles errors - Logs failures and marks event as unprocessed for retry

Testing

Local development:
View logs in Vercel Dashboard:
  1. Select your project
  2. Go to Deployments โ†’ latest deployment
  3. Click Functions โ†’ Logs
Configure in DodoPayments Dashboard:
  1. Go to Developers โ†’ Webhooks
  2. Add endpoint with your Vercel Functions URL
  3. Enable: subscription.active, subscription.cancelled, subscription.renewed

Common Issues

IssueSolution
Verification failedCheck webhook key is correct from DodoPayments dashboard
Database connection errorVerify Neon connection string and use pooled connection
Function timeoutOptimize queries; Pro plan has longer timeout (60s)
Env vars not availableSet in dashboard or CLI, ensure all environments selected, redeploy

Resources

Last modified on May 19, 2026