GitHub Repository
Complete source code and setup guide
Quick Setup
1. Prerequisites
You need:- A Cloudflare 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. Configure Initial Secrets
Youâll set
DODO_PAYMENTS_WEBHOOK_KEY after deployment, once you have your webhook URL.5. Update wrangler.toml
Editwrangler.toml and set your worker name:
6. Deploy
7. Get Your Webhook URL
Your webhook URL is:8. 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.
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 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:- 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 the database
- Handles errors â Logs failures and marks events as unprocessed for retry
Testing
Local development:- Go to Developer â Webhooks.
- Add an endpoint with your Worker URL.
- Select
subscription.active,subscription.cancelled, andsubscription.renewed.