Webhook Endpoint
The webhook handler is deployed as a Supabase Edge Function at:~/workspace/source/supabase/functions/dodo-webhook/index.ts
Security & Verification
All webhook requests are verified using the standardwebhooks library to ensure authenticity.Verification Process
The webhook handler validates every incoming request by:-
Extracting required headers from the request:
webhook-id: Unique identifier for the webhook eventwebhook-signature: HMAC signature for verificationwebhook-timestamp: Timestamp of the event
-
Verifying the signature using the
DODO_WEBHOOK_SECRET:
- Rejecting requests with invalid signatures (returns 400 status)
Required Environment Variables
Secret key provided by Dodo Payments for webhook verification
Your Supabase project URL
Service role key for database access
Event Processing
The webhook handler processes two categories of events:Payment Events
These events update thepayments table:
payment.succeededpayment.failedpayment.processingpayment.cancelled
managePayment() function at line 120
Subscription Events
These events update thesubscriptions table and may also update user subscription status:
Active/Upgrade Events (updates user tier):
subscription.activesubscription.plan_changed
subscription.renewedsubscription.on_hold
subscription.cancelledsubscription.expiredsubscription.failed
manageSubscription() function at line 164
Response Codes
Event processed successfully or event type not handled
Invalid webhook signature - verification failed
Non-POST request received
Missing configuration or error processing webhook
CORS Support
The webhook endpoint includes CORS headers for cross-origin requests:Database Operations
The webhook handler uses upsert operations to handle both new events and updates:- Payments: Upserted by
payment_id - Subscriptions: Upserted by
subscription_id - Users: Updated by
dodo_customer_id
Next Steps
Webhook Events
View all webhook event types and payloads
Database Schema
Explore the database structure
