Replit Stripe integration broken — fix webhooks and payment state
Replit Stripe integration broken — fix webhooks and payment state
Scope of this page:Replit-specific Stripe issues — Replit URL rotation, Python/Flask raw-body handling, Replit deploy target. For the tool-agnostic error-signature fix see Stripe webhook not firing. Shopping for a paid engagement? Add payments to AI app.
Replit apps can integrate Stripe but Replit’s URL structure creates webhook configuration issues. The preview URL changes; the production Replit URL is not the same as your webhook endpoint. Additionally, Stripe webhook signature verification requires the raw request body— something that breaks when request parsing middleware runs first.
Quick fix for Replit Stripe integration broken — fix
Fix 1 — Configure production webhook URL in Stripe
In Stripe Dashboard → Developers → Webhooks → Add endpoint: enter your Replit production URL (not the preview URL):
https://yourapp.replit.app/api/webhook
Subscribe to: checkout.session.completed, invoice.paid, customer.subscription.updated, customer.subscription.deleted.
Deeper fixes when the quick fix fails
- 02
Fix 2 — Preserve raw body for signature verification
Express apps: add
express.rawbeforeexpress.jsonon the webhook route.// Before express.json middleware for this route only: app.post( '/api/webhook', express.raw({ type: 'application/json' }), async (req, res) => { const sig = req.headers['stripe-signature']; const event = stripe.webhooks.constructEvent( req.body, sig, process.env.STRIPE_WEBHOOK_SECRET ); // handle event } ); // All other routes still get JSON parsing: app.use(express.json());The webhook signature verification will fail if the body is parsed before it reaches the Stripe verification call.
- 03
Fix 3 — Handle all subscription lifecycle events
Most Replit Stripe integrations only handle
checkout.session.completed. Add handlers for:invoice.paid(monthly renewal),customer.subscription.updated(plan change, trial end),customer.subscription.deleted(cancellation). Each one should update your database so paywalled routes know whether the user has an active subscription. - 04
Fix 4 — Add webhook secret to Replit Secrets
In Replit Secrets tab: add
STRIPE_WEBHOOK_SECRETwith the signing secret from your Stripe webhook configuration (starts withwhsec_). This is different from your Stripe API key (sk_live_/sk_test_). Redeploy after adding.
Verify end-to-end
Stripe Dashboard → Developers → Webhooks → your endpoint → Send test webhook. Pick checkout.session.completed and send. The response should be 200 within 2 seconds. Then run a full test purchase (Stripe test card 4242 4242 4242 4242) and verify: (1) checkout opens, (2) payment succeeds, (3) webhook fires, (4) your database reflects the paid status, (5) the user gets access to paid routes.
Why AI-built apps hit Replit Stripe integration broken — fix
Replit Agent adds Stripe checkout but usually skips: (1) webhook endpoint configuration with Stripe, (2) raw body preservation for signature verification, (3) subscription state management in the database.
The most common failure mode: checkout works, payment succeeds in Stripe dashboard, but the app never activates the user’s subscription because the webhook is either never reaching your app or is rejected by signature verification.
“Stripe payments go through but my app never activates the subscription.”
Diagnose Replit Stripe integration broken — fix by failure mode
Match your symptom to the failing layer. Most of these show up in Stripe’s own webhook dashboard.
| Symptom | Cause | Fix |
|---|---|---|
| Webhook shows 'Failed' in Stripe Dashboard | Webhook URL wrong or app unreachable | Fix 1 |
| Webhook URL returns 400 'Invalid signature' | Request body parsed before signature verification | Fix 2 |
| First payment works, renewals don't activate | Only checkout.session.completed handled | Fix 3 |
| Webhook endpoint returns 500 'undefined secret' | STRIPE_WEBHOOK_SECRET missing from Secrets | Fix 4 |
Related errors we fix
Still stuck with Replit Stripe integration broken — fix?
Payments failing in production is a revenue emergency. We fix Stripe end-to-end with a verified test purchase:
- →Stripe Dashboard shows failed webhooks
- →Payments succeed but users don't get access
- →Subscription renewals don't extend access
- →You don't know the difference between test and live webhook secrets
Replit Stripe integration broken — fix questions
Why does my Stripe webhook say 'Invalid signature'?+
What webhook events do I need to handle for subscriptions?+
How do I test Stripe webhooks locally in Replit?+
My webhook works with test keys but fails with live keys. What's wrong?+
Can I use Stripe Checkout instead of Payment Elements?+
How much does a Stripe integration fix cost?+
Ship the fix. Keep the fix.
Emergency Triage restores service in 48 hours. Break the Fix Loop rebuilds CI so this error cannot ship again.
Hyder Shah leads Afterbuild Labs, shipping production rescues for apps built in Lovable, Bolt.new, Cursor, Replit, v0, and Base44. our rescue methodology.
Replit Stripe integration broken — fix experts
If this problem keeps coming back, you probably need ongoing expertise in the underlying stack.