Stripe Local Development Setup
Explains how to test Stripe webhooks locally while keeping the production webhook pointing to Cloud Run.
What this file does
Explains how to test Stripe webhooks locally while keeping the production webhook pointing to Cloud Run.
When to use it
- You need to test Stripe webhooks without affecting production
- You use Stripe CLI for local webhook forwarding
- You deploy a Stripe-integrated app to Cloud Run
- You want a repeatable local-to-production Stripe workflow
Assumes this stack
Stripe Local Development Setup
Overview
This guide explains how to test Stripe webhooks locally while your production webhook points to your Cloud Run backend.
Current Setup
Production (Cloud Run)
- Webhook URL:
https://capitolscope-api-1074255918859.us-west1.run.app/api/v1/stripe/webhook - Success URL:
https://capitolscope.chrislawrence.ca/dashboard?payment=success - Cancel URL:
https://capitolscope.chrislawrence.ca/premium?payment=cancelled
Local Development
- Webhook URL:
localhost:8000/api/v1/stripe/webhook(forwarded via Stripe CLI) - Success URL:
http://localhost:3000/dashboard?payment=success - Cancel URL:
http://localhost:3000/premium?payment=cancelled
Local Development Workflow
1. Start Local Development
# Start your local Docker containers
capitol-build
# In a separate terminal, start Stripe webhook forwarding
capitol-stripe-webhook
2. What the Stripe CLI Does
The capitol-stripe-webhook command:
- Listens for webhook events from your Stripe sandbox
- Forwards them to
localhost:8000/api/v1/stripe/webhook - Provides a webhook signing secret for local testing
- Shows real-time webhook events in the terminal
3. Environment Variables for Local Dev
Make sure your local .env file has:
# Local development URLs
STRIPE_SUCCESS_URL=http://localhost:3000/dashboard?payment=success
STRIPE_CANCEL_URL=http://localhost:3000/premium?payment=cancelled
STRIPE_WEBHOOK_ENDPOINT=http://localhost:8000/api/v1/stripe/webhook
Switching Between Local and Production
For Local Testing
- Start local containers:
capitol-build - Start webhook forwarding:
capitol-stripe-webhook - Use local URLs in your frontend
For Production Testing
- Deploy to Cloud Run:
capitol-deploy-backend - Update environment variables:
capitol-update-env - Use production URLs in your frontend
Stripe Dashboard Configuration
Current Setup (Production)
- Webhook Endpoint:
https://capitolscope-api-1074255918859.us-west1.run.app/api/v1/stripe/webhook - Events: All subscription and payment events
For Local Testing
- Webhook Endpoint:
http://localhost:8000/api/v1/stripe/webhook(via Stripe CLI) - Events: Same events, but forwarded locally
Commands Reference
# Local development
capitol-build # Start local containers
capitol-stripe-webhook # Forward Stripe webhooks locally
capitol-logs # View container logs
# Production deployment
capitol-deploy-backend # Deploy backend to Cloud Run
capitol-update-env # Update environment variables
capitol-deploy-frontend # Deploy frontend to Cloud Run
Troubleshooting
Webhook Not Receiving Events
- Check if Stripe CLI is running:
capitol-stripe-webhook - Verify local containers are running:
capitol-logs - Check webhook endpoint is accessible:
curl http://localhost:8000/api/v1/stripe/webhook
Production Webhook Errors
- Check Cloud Run logs in Google Cloud Console
- Verify environment variables are set:
capitol-update-env - Test webhook endpoint:
curl https://capitolscope-api-1074255918859.us-west1.run.app/api/v1/stripe/webhook
Migration to Production
When you're ready to go live:
- Update Stripe dashboard webhook URL to production
- Update environment variables to production URLs
- Deploy both frontend and backend
- Test with real payments (small amounts first)
Notes
- Stripe CLI automatically handles webhook signing for local development
- You don't need to change the webhook URL in Stripe dashboard for local testing
- The CLI creates a temporary webhook endpoint that forwards to your local server
- All webhook events are logged in the CLI terminal for debugging
What's inside
7 sections, 4 code blocks, 2 environment variable lists, 1 command reference table
Change this for your project
- Replace
capitolscopewith your project name in URLs likehttps://capitolscope-api-1074255918859.us-west1.run.app - Replace
capitol-build,capitol-stripe-webhook,capitol-logs,capitol-deploy-backend,capitol-update-env,capitol-deploy-frontendwith your own custom commands - Replace
chrislawrence.cawith your own domain in success/cancel URLs
Where it goes
Save as AGENTS.md in your repository root. Read by Codex, Cursor and other agents that follow the AGENTS.md convention.
Worth borrowing
- Using Stripe CLI to forward webhooks locally without changing the Stripe dashboard endpoint
- Separating local and production environment variables for success and cancel URLs
Related Documents
Browser-only development
Guides AI assistants on an Electron + React + TypeScript desktop app for browsing and organizing AI-generated images locally.
Claude Agents — Reference & Recommendations
Catalogues 40+ Claude agents and marketing skills for building a cat adoption charity landing page, with a ready-to-paste prompt and backend API reference.
Golden DKG Prototype -- Master Plan
Defines an 8-phase implementation plan for a Rust prototype of the Golden non-interactive DKG protocol using BLS12-381 and tokio.
Swarms Examples Index
Lists 60+ example scripts for building single and multi-agent systems with the Swarms framework, organized by category and use case.