Guide
Stripe test mode: test cards and checking checkout end to end
A checkout page that opens isn't a checkout that works. The money only counts once Stripe's webhook reaches your server, your code verifies it, and the customer gets what they paid for. Here's how to test that whole path in Stripe's test environment, failures included, without spending anything.
Updated 5 min read
Test mode, sandboxes and live mode
Stripe keeps test and live data completely apart: objects created in one aren't visible in the other, and test keys can't move real money. Test keys start with sk_test_ (secret), pk_test_ (publishable) and rk_test_ (restricted); live keys use _live_.
Stripe now calls these test environments sandboxes. Every account has the original test mode, which shares settings with live mode, and Stripe recommends separate sandboxes for new integrations, for example one for local development and one for CI. Either works for everything below.
The test cards worth knowing
Use any future expiry date (like 12/34), any three-digit CVC, and any postal code. Each card number triggers a specific result:
| Card number | What happens | Use it to test |
|---|---|---|
4242 4242 4242 4242 | Succeeds (Visa) | The happy path |
4000 0000 0000 0002 | Declined: generic decline | Your error message and that no access is granted |
4000 0000 0000 9995 | Declined: insufficient funds | A specific decline reason |
4000 0000 0000 0069 | Declined: expired card | Expiry handling |
4000 0000 0000 0127 | Declined: incorrect CVC | CVC errors |
4000 0000 0000 3220 | Requires 3D Secure authentication to succeed | The authentication pop-up |
4000 0025 0000 3155 | Always asks for authentication on-session; off-session only if the card wasn't set up | Saving a card for subscriptions |
4000 0000 0000 0341 | Attaching to a customer works, charging fails | A renewal that fails after a successful sign-up |
Stripe suggests a different test card for each independent scenario, and notes that its rate limits are stricter in test environments, so don't hammer it with hundreds of automated payments.
Run one checkout by hand, start to finish
Before automating anything, do one full run against your preview or local app with test keys, and tick each step:
The button opens Checkout
Click Upgrade (or Buy). Stripe Checkout opens with the right product, price and currency.
Pay with 4242
Complete the payment with
4242 4242 4242 4242.The success page loads
You land on your
success_url, not an error or a blank page.The webhook arrived and passed
In the Dashboard, open your test webhook endpoint and check that the
checkout.session.completeddelivery got a 2xx response from your server.Your database changed
The user's plan, credits or order record is updated.
The customer got what they paid for
Paid features unlock, the receipt or welcome email arrives.
Then the failures
Repeat with the generic decline card (you should see a clear error, and nothing unlocks), the 3D Secure card, and pressing back on Checkout (you return to your
cancel_url).
Stripe's own fulfillment guide warns you can't rely on the success page alone to fulfil an order: people close the tab, and some payment methods confirm later. The webhook is the source of truth.
Test webhooks on your machine with the Stripe CLI
Stripe can't reach localhost, so the Stripe CLI forwards events to it:
# once
stripe login
# forward test-mode events to your local route (match your route's path)
stripe listen --forward-to localhost:3000/api/webhooks/stripe
# > Ready! Your webhook signing secret is 'whsec_...'
# in another terminal: send a test event
stripe trigger checkout.session.completedwhsec_... the CLI prints into STRIPE_WEBHOOK_SECRET in .env.local. It's different from the secret of any endpoint in the Dashboard.stripe trigger creates real test objects to produce the event, but they won't belong to one of your users, so your handler may correctly find nothing to fulfil. For the full loop, keep stripe listen running and do a real test checkout in your local app with the 4242 card.
Verify the signature, and why "No signatures found" happens
Anyone can send a POST to your webhook URL. Verifying the Stripe-Signature header is what stops a fake "payment succeeded" event from unlocking your product for free. Stripe needs the raw request body to check it; any parsing or reformatting first makes verification fail with errors like "No signatures found matching the expected signature for payload". In the Next.js App Router, read the body with request.text():
// app/api/webhooks/stripe/route.ts
import Stripe from "stripe";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function POST(request: Request) {
const body = await request.text(); // the raw body, untouched
const signature = request.headers.get("stripe-signature") ?? "";
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(body, signature, process.env.STRIPE_WEBHOOK_SECRET!);
} catch {
return new Response("Invalid signature", { status: 400 });
}
switch (event.type) {
case "checkout.session.completed":
case "checkout.session.async_payment_succeeded": {
const session = event.data.object;
// Stripe may send an event more than once: fulfil() must be safe to run twice.
if (session.payment_status !== "unpaid") await fulfil(session.id);
break;
}
case "checkout.session.async_payment_failed":
// tell the customer the payment didn't go through
break;
}
return new Response(null, { status: 200 });
}fulfil() is your own function: look the session up, update the user, send the email. Stripe's guide says it may be called more than once, even at the same time.If verification fails only in one environment, the usual cause is the wrong secret: the CLI's whsec_ locally, each Dashboard endpoint's own whsec_ in test and live, and an environment variable edited without a redeploy.
Subscriptions: test renewals without waiting a month
Renewals, failed renewals and trial endings happen in the future, so Stripe has test clocks: create a customer on a test clock, subscribe them, then advance the clock to see the renewal invoice and its webhooks today. Limits from Stripe's docs: three customers per clock, three subscriptions per customer, advancing at most two billing intervals at a time, and clocks are deleted 30 days after you create them. They only work in test environments.
Combine a test clock with card 4000 0000 0000 0341 to see exactly what your app does when a renewal fails: does the user lose access, get an email, see a banner?
If you use the Stripe customer portal, note that its configuration is separate for live mode and each test environment. Set it up again in live mode before launch.
Before you switch to live keys
- Register your live webhook endpoint in the Dashboard and put its own
whsec_in your Production environment variables. A webhook that works in test and silently fails in live is almost always a missing live endpoint or a test secret in production. - Live keys go in the Production environment only; previews keep test keys (here's why).
- Redeploy after changing environment variables.
- Make sure nothing in code still points at test objects (test price ids won't exist in live mode).
- Do one small real purchase yourself, then refund it.
Where Corvis fits
Corvis tests your upgrade journey in a real browser on every Vercel preview, in Stripe test mode, and puts a pass or fail on the pull request with a screenshot of where it broke. Its free repo scan also flags Stripe webhook handlers that act on events without verifying the signature. Once you're live, it watches failed payments, notices when payments stop or fall far below your normal for that hour, and tells you in plain English which deploy it started after.
Sources
Checked against these pages on 24 October 2026. Providers change their dashboards; if a step looks different, the source has the current version.
- Stripe Docs: Testing (test cards) (opens in a new tab)
- Stripe Docs: Sandboxes (opens in a new tab)
- Stripe Docs: API keys (opens in a new tab)
- Stripe Docs: Webhooks (opens in a new tab)
- Stripe Docs: stripe trigger (opens in a new tab)
- Stripe Docs: Fulfill orders (Checkout) (opens in a new tab)
- Stripe Docs: Test clocks (opens in a new tab)
- Stripe Docs: Customer portal (opens in a new tab)
- Stripe Docs: Decline codes (testmode_decline) (opens in a new tab)
- Next.js Docs: Route handlers (webhooks) (opens in a new tab)