Source:
ocean/docs/STRIPE_WEBHOOK_SETUP.md| ✏️ Edit on GitHub
Stripe Webhook Setup Guide
This guide explains how to set up the Cloudflare Worker that syncs new Supabase users to Stripe.
Overview
When a new user signs up:
- Supabase creates the user and organization
- Supabase webhook triggers the Cloudflare Worker
- Worker creates a Stripe customer with all metadata
- Worker updates the organization with the Stripe customer ID
Setup Steps
1. Configure GitHub Secrets
Set these secrets in your GitHub repository for CI/CD deployment:
# Staging secrets
gh secret set STRIPE_SECRET_KEY_STAGING
gh secret set STRIPE_WEBHOOK_SECRET_STAGING
gh secret set WEBHOOK_SECRET_STAGING
gh secret set SUPABASE_SERVICE_ROLE_KEY
# Production secrets (when ready)
gh secret set STRIPE_SECRET_KEY_PRODUCTION
gh secret set STRIPE_WEBHOOK_SECRET_PRODUCTION
gh secret set WEBHOOK_SECRET_PRODUCTION
2. Deploy the Cloudflare Worker
The worker deploys automatically via GitHub Actions when:
- Changes are pushed to
cloudflare/worker/** - Manually triggered via GitHub Actions
To trigger manual deployment:
gh workflow run deploy-cloudflare-worker.yml
3. Configure Supabase Webhook
-
Run the migration to create the webhook function:
supabase db push -
Go to your Supabase Dashboard
-
Create a new webhook:
-
Name:
new-user-stripe-sync -
Table:
auth.users -
Events:
INSERT -
Type:
HTTP Request -
URL:
https://ocean-stripe-webhook-staging.{your-cf-account}.workers.dev -
HTTP Headers:
Authorization: Bearer {your-webhook-secret}
Content-Type: application/json -
Enable: Yes
-
4. Test the Integration
- Create a test user through your signup form
- Check Cloudflare Worker logs:
wrangler tail --env staging - Verify in Stripe Dashboard that customer was created
- Check Supabase organizations table for
stripe_customer_id
Environment Configuration
Staging Environment (Configured)
- Cloudflare Account:
8fa97474778c8a894925c148ca829739 - Worker URL:
https://ocean-stripe-webhook.staging.goldfish.io - Stripe Test Key: Set via environment variable or deploy script
- Stripe Webhook Secret: Set via environment variable or deploy script
- Log Level:
warn
Production Environment
- Worker URL:
https://ocean-stripe-webhook.goldfish.io - Uses Stripe live keys (
sk_live_...) - Log Level:
error
Switching Between Environments
To switch from staging to production:
-
Deploy to production:
pnpm run deploy:production -
Update Supabase webhook URL to production worker URL
-
Ensure production secrets are set (especially
STRIPE_SECRET_KEY)
Monitoring
- Cloudflare Logs:
wrangler tail --env staging - Supabase Webhook Logs: Dashboard > Database > Webhooks > View logs
- Stripe Logs: Stripe Dashboard > Developers > Logs
Data Synced to Stripe
Each Stripe customer is created with:
- Full name (from first_name + last_name)
- Metadata:
supabase_user_id: User ID from Supabaseorganization: Organization nameindustry: Selected industryhosting_region: Selected regionorganization_id: Organization ID from Supabase
Troubleshooting
- Webhook not triggering: Check Supabase webhook is enabled and URL is correct
- 401 Unauthorized: Verify
WEBHOOK_SECRETmatches in both Worker and Supabase - Stripe errors: Check Stripe API key is valid and has correct permissions
- Worker errors: Use
wrangler tailto see detailed logs