Skip to main content

GitHub Repository

Complete source code and setup guide

Quick Setup

1. Prerequisites

You need:

2. Install Dependencies

3. Database Setup

  1. Sign up for Neon and create a project.
  2. Open the SQL Editor.
  3. Copy the entire contents of schema.sql and run it.
  4. Copy your connection string from Connection Details.

4. Configure Initial Secrets

You’ll set DODO_PAYMENTS_WEBHOOK_KEY after deployment, once you have your webhook URL.

5. Update wrangler.toml

Edit wrangler.toml and set your worker name:

6. Deploy

7. Get Your Webhook URL

Your webhook URL is:

8. Register Webhook in DodoPayments Dashboard

  1. Go to Developer → Webhooks in the Dodo Payments dashboard.
  2. Click Add endpoint.
  3. Enter your webhook URL.
  4. Select these events: subscription.active, subscription.cancelled, subscription.renewed.
  5. Click Create endpoint and copy the signing secret.

9. 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 records
  • subscription.cancelled — Marks the subscription as cancelled
  • subscription.renewed — Updates the next billing date

Key Features

  • Signature verification — Uses the Dodo Payments SDK to verify webhook authenticity
  • Idempotency — Uses the webhook-id header to prevent duplicate processing
  • Event logging — Stores all events in the webhook_events table 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

Tables created:
  • customers — Email, name, and Dodo Payments 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. Verifies the signature — Uses the Dodo Payments SDK to verify the request with HMAC-SHA256
  2. Checks for duplicates — Uses the webhook-id header to prevent processing the same event twice
  3. Logs the event — Stores the raw webhook in the webhook_events table for audit trails
  4. Processes the event — Creates or updates customers and subscriptions in the database
  5. Handles errors — Logs failures and marks events as unprocessed for retry

Testing

Local development:
Configure in the Dodo Payments dashboard:
  1. Go to Developer → Webhooks.
  2. Add an endpoint with your Worker URL.
  3. Select subscription.active, subscription.cancelled, and subscription.renewed.

Common Issues

Resources

Last modified on September 25, 2026