Skip to main content

Source: ocean/docs/TESTING_STRIPE_WEBHOOK.md | ✏️ Edit on GitHub

Testing Stripe Webhook Integration

This guide covers how to test the Cloudflare Worker webhook integration at different levels.

1. Test GitHub Actions Deployment

First, let's verify the CI/CD pipeline works:

# Make a small change to trigger deployment
cd cloudflare/worker
echo "// Test deployment" >> src/index.ts

# Commit and push
git add .
git commit -m "test: trigger webhook deployment"
git push origin main

Monitor the deployment:

  • Go to GitHub Actions tab in your repo
  • Watch the "Deploy Stripe Webhook Worker" workflow
  • Should auto-deploy to staging

2. Test Worker Directly (Unit Test)

Use the provided test script:

cd cloudflare/worker
./test-webhook.sh

This will:

  • Send a mock webhook payload to your worker
  • Verify it creates a Stripe customer
  • Return the customer ID for verification

3. Test End-to-End Flow

Step 1: Deploy and Configure

cd cloudflare/worker
./deploy-staging.sh

Save the webhook secret that's generated!

Step 2: Configure Supabase Webhook

  1. Go to Supabase Dashboard
  2. Create new webhook:
    • Name: new-user-stripe-sync

    • Table: auth.users

    • Events: INSERT

    • URL: https://ocean-stripe-webhook.staging.goldfish.io

    • Headers:

      Authorization: Bearer {webhook-secret-from-deploy-script}
      Content-Type: application/json
    • Enable: Yes

Step 3: Monitor Logs

Open a terminal and watch the worker logs:

wrangler tail --env staging

Step 4: Create Test User

Sign up through your app with test data:

  • Email: test@example.com
  • Name: Test User
  • Organization: Test Company
  • Industry: Business
  • Region: United States

Step 5: Verify Results

  1. Check Worker Logs: Should show webhook received and processed

  2. Check Stripe Dashboard:

  3. Check Supabase:

    SELECT o.*, u.email
    FROM organizations o
    JOIN organization_members om ON o.id = om.organization_id
    JOIN auth.users u ON om.user_id = u.id
    WHERE u.email = 'test@example.com';

    Should show stripe_customer_id populated

4. Debug Common Issues

Webhook Not Firing

  • Check Supabase webhook is enabled
  • Verify webhook URL is correct
  • Check webhook logs in Supabase dashboard

401 Unauthorized

  • Webhook secret doesn't match
  • Re-run deploy script and update Supabase webhook

Stripe Customer Not Created

  • Check Stripe API key is valid
  • Verify it's using test key (sktest...)
  • Check worker logs for specific error

Organization Not Updated

  • Verify Supabase service role key has proper permissions
  • Check if organization was created by trigger
  • Look for errors in worker logs

5. Load Testing

For production readiness, test with multiple concurrent signups:

# Create 10 test users concurrently
for i in {1..10}; do
./test-webhook.sh &
done
wait

6. Monitoring Production

Once deployed to production:

  1. Set up alerts:

    • Cloudflare Worker errors
    • Stripe API failures
    • Webhook delivery failures
  2. Monitor metrics:

    • Worker execution time
    • Success/failure rates
    • Stripe API latency
  3. Regular checks:

    • Verify new users have Stripe customers
    • Check for orphaned records
    • Monitor billing sync accuracy

Test Checklist

  • GitHub Actions deploys successfully
  • Test script creates Stripe customer
  • Real signup creates Stripe customer
  • Metadata is correctly synced
  • Organization has stripe_customer_id
  • Logs show successful processing
  • Error handling works correctly
  • Webhook retries on failure