GitHub Repository
Complete source code and setup guide
Quick Setup
1. Prerequisites
- Supabase account
- A Supabase project created
- DodoPayments API key from dashboard
2. Authenticate & Link
3. Database Setup
- Go to your Supabase Dashboard
- Open the SQL Editor
- Create a new query
- Copy and paste the entire contents of
schema.sql - Run the query
4. Set Initial Secrets
Supabase automatically providesSUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY at runtime.
Note: Weโll set DODO_PAYMENTS_WEBHOOK_KEY after deployment once you have your webhook URL.
5. Deploy
The function is already set up infunctions/webhook/index.ts - just deploy it:
6. Get Your Webhook URL
Your webhook URL is:7. Register Webhook in DodoPayments Dashboard
- Go to DodoPayments Dashboard โ Developer โ Webhooks
- Create a new webhook endpoint
- Configure your webhook URL as the endpoint
- Enable these subscription events:
subscription.activesubscription.cancelledsubscription.renewed
- Copy the Signing Secret
8. Set Webhook Key & Redeploy
What It Does
Processes subscription events and stores them in Supabase 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
- 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 Deno-based Edge Function:- Verifies signature - Uses dodopayments library for HMAC-SHA256 verification
- Checks idempotency - Looks up webhook ID to prevent duplicate processing
- Logs the event - Stores raw webhook data in
webhook_eventstable - Processes updates - Creates or updates customers and subscriptions via Supabase client
- Handles errors - Logs failures and marks event for retry
Testing
Local development:The
--no-verify-jwt flag is required because webhooks donโt include JWT tokens. Security is provided by webhook signature verification.- Go to Developers โ Webhooks
- Add endpoint with your Supabase URL
- Enable: subscription.active, subscription.cancelled, subscription.renewed