Skip to main content

GitHub Repository

Complete source code and setup guide
Check out the Dodo Payments Supabase Subscription Starter β€” a complete Next.js, Supabase, and Dodo Payments boilerplate with authentication, payments, and webhooks.

Quick Setup

1. Prerequisites

You need:
  • A Supabase account with a project created
  • A Dodo Payments API key from Developer β†’ API Keys in the dashboard
Find your project ref in Project Settings on the Supabase dashboard.

3. Database Setup

  1. Go to the Supabase dashboard.
  2. Open the SQL Editor.
  3. Copy the entire contents of schema.sql and run it.

4. Set Initial Secrets

Supabase automatically provides SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY at runtime.
You’ll set DODO_PAYMENTS_WEBHOOK_KEY after deployment, once you have your webhook URL.

5. Deploy

The function is already set up in functions/webhook/index.ts.

6. Get Your Webhook URL

Your webhook URL is:

7. 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.

8. Set Webhook Key & Redeploy

What It Does

The webhook handler processes subscription events and stores them in Supabase 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 Deno-based Edge Function:
  1. Verifies the signature β€” Uses the Dodo Payments SDK for HMAC-SHA256 verification
  2. Checks for duplicates β€” Uses the webhook-id header to prevent duplicate processing
  3. Logs the event β€” Stores the raw webhook data in the webhook_events table
  4. Processes updates β€” Creates or updates customers and subscriptions via the Supabase client
  5. Handles errors β€” Logs failures and marks events 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.
View logs:
Or in the Supabase dashboard under Edge Functions β†’ webhook β†’ Logs. Configure in the Dodo Payments dashboard:
  1. Go to Developer β†’ Webhooks.
  2. Add an endpoint with your Supabase URL.
  3. Select subscription.active, subscription.cancelled, and subscription.renewed.

Common Issues

Resources

Last modified on September 25, 2026