Stripe Checkout Not Redirecting After Payment
Quick Answer
Missing or wrong success_url and cancel_url in the checkout session. The URL must include your production domain. Start with "Add correct redirect URLs" before making broader code changes.
You're in the right place if...
- !Payment succeeds but user stays on Stripe page
- !Redirect goes to wrong URL
- !Success page returns 404
Why this happens
Missing or wrong success_url and cancel_url in the checkout session. The URL must include your production domain.
Fix
Add correct redirect URLs
Set success and cancel URLs in your checkout session:
const session = await stripe.checkout.sessions.create({
// ... other options
success_url: `${process.env.NEXT_PUBLIC_URL}/success?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${process.env.NEXT_PUBLIC_URL}/cancelled`,
})
// Add to Vercel env vars:
// NEXT_PUBLIC_URL=https://your-domain.comPrevent this next time
Always use an environment variable for the base URL. This way the redirect works in both development and production.
Frequently Asked Questions
Stripe replaces {CHECKOUT_SESSION_ID} with the actual session ID in the redirect URL. Use it to verify the payment on your success page.
localhost:3000 in development, your-domain.com in production. One codebase, both environments work.
Related fixes
Weekly Newsletter
Get next week's fix before you need it.
Join developers getting weekly vibe coding tips, error fixes, and tool updates.
Subscribe on Substack →