Follow these steps to test the Stripe payment flow locally:
- Open Stripe dashboard in test mode: https://dashboard.stripe.com/test/apikeys
- Copy your Secret key (starts with
sk_test_...) - Paste it into
backend/.env.localreplacingSTRIPE_SECRET_KEY=sk_test_YOUR_TEST_KEY_HERE
- Go to: https://dashboard.stripe.com/test/products
- Click "+ Add product"
- Create these products:
- Name:
Agent Pro Monthly - Price:
$19.00 USD - Billing period:
Monthly - Copy the Price ID (starts with
price_...) - Paste into
.env.localasSTRIPE_PRICE_AGENT_PRO_MONTHLY
- Name:
Agent Pro Yearly - Price:
$192.00 USD(16/mo × 12) - Billing period:
Yearly - Copy the Price ID
- Paste into
.env.localasSTRIPE_PRICE_AGENT_PRO_YEARLY
- Name:
Business Monthly - Price:
$49.00 USD - Billing period:
Monthly - Copy the Price ID
- Paste into
.env.localasSTRIPE_PRICE_BUSINESS_MONTHLY
- Name:
Business Yearly - Price:
$492.00 USD(41/mo × 12) - Billing period:
Yearly - Copy the Price ID
- Paste into
.env.localasSTRIPE_PRICE_BUSINESS_YEARLY
Open a new terminal and run:
cd backend
./setup-stripe-local.shThis will:
- Start Stripe CLI webhook forwarding
- Forward webhooks from Stripe to
http://localhost:8000/api/webhooks/stripe - Display a webhook signing secret (starts with
whsec_...)
Copy the webhook secret and paste it into .env.local:
STRIPE_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxKeep this terminal open while testing!
Open another terminal:
cd backend
npm run devBackend will start on http://localhost:8000
Open another terminal:
cd frontend
npm run devFrontend will start on http://localhost:3001
- Go to: http://localhost:3001
- Login with your test account
- Navigate to Billing page
- Click "upgrade" on Agent Pro plan
- Use Stripe test card:
4242 4242 4242 4242- Expiry: Any future date (e.g.,
12/34) - CVC: Any 3 digits (e.g.,
123) - ZIP: Any 5 digits (e.g.,
12345)
- Expiry: Any future date (e.g.,
- Complete payment
- You should be redirected back with
?payment=success - After 2 seconds, plan should update to "Agent Pro"
Check backend terminal for:
✅ Stripe webhook received
✅ Organization upgraded via checkout
- Make sure you're logged in to the dashboard first
- Go to website pricing page
- Click upgrade button
- Should redirect to Stripe checkout
- Complete payment with test card
- Return to dashboard
- Verify plan updated
- On billing page, click "manage billing"
- Should redirect to Stripe billing portal
- Try changing plan (upgrade/downgrade)
- Try canceling subscription
- Verify webhooks process correctly in backend logs
Stripe provides test cards for different scenarios:
- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002 - 3D Secure:
4000 0027 6000 3184 - Insufficient funds:
4000 0000 0000 9995
More test cards: https://stripe.com/docs/testing
Watch backend logs for these events:
[INFO] Stripe webhook received { type: 'checkout.session.completed' }
[INFO] Organization upgraded via checkout { orgId: '...', plan: 'agent_pro' }
[INFO] Stripe webhook received { type: 'customer.subscription.updated' }
[INFO] Subscription updated { orgId: '...', oldTier: 'agent_pro', newTier: 'business' }
[INFO] Stripe webhook received { type: 'customer.subscription.deleted' }
[INFO] Subscription deleted, org downgraded to free
[WARN] Checkout session missing metadata — CRITICAL BUG (should never happen after fix)
[ERROR] Database unavailable during checkout webhook — Infrastructure issue
[WARN] No org found for Stripe customer — Data inconsistency
Check:
- Is
stripe listenstill running? - Is backend server running on port 8000?
- Check backend logs for webhook signature errors
Fix: Restart stripe listen and update STRIPE_WEBHOOK_SECRET in .env.local
Check:
- Backend logs for:
"Checkout session missing metadata" - Check if
orgIdis in Stripe session metadata
Fix: This was the bug we fixed. Make sure you're using the updated code.
Check:
- Wait 2-3 seconds for auto-refetch
- Check browser console for API errors
Fix: Manually refresh the page. The auto-refetch should work after our fix.
Make sure these are set in backend/.env.local:
-
STRIPE_SECRET_KEY(starts withsk_test_) -
STRIPE_WEBHOOK_SECRET(starts withwhsec_) -
STRIPE_PRICE_AGENT_PRO_MONTHLY(starts withprice_) -
STRIPE_PRICE_AGENT_PRO_YEARLY(starts withprice_) -
STRIPE_PRICE_BUSINESS_MONTHLY(starts withprice_) -
STRIPE_PRICE_BUSINESS_YEARLY(starts withprice_) -
FRONTEND_URL=http://localhost:3001
After testing, you can:
- Stop all terminals (Ctrl+C)
- Delete test subscriptions from Stripe dashboard
- Keep
.env.localfor future testing
When ready to deploy:
- DO NOT commit
.env.localto git - Use production Stripe keys on Railway
- Set webhook endpoint in Stripe dashboard to:
https://api.commune.email/api/webhooks/stripe - Use live price IDs in production environment variables