
Testing Stripe Webhooks Locally: The 2-Minute No-Dashboard Setup
Ditch the domain and dashboard hassle! Set up 100% working, local Stripe testing in under 2 minutes using the Stripe CLI.
🚀 Testing Stripe Webhooks Locally: The 2-Minute No-Dashboard Setup
No domain. No dashboard. No stress.
Testing Stripe webhooks can be a pain. You usually need to deploy a public URL or constantly update a webhook URL in the Stripe dashboard. Not anymore!
We're going to set up 100% working, local testing in under two minutes using the Stripe CLI to forward events directly to your localhost.
🎯 Goal: Test Stripe Locally (No Webhook in Stripe Dashboard)
We’ll use the Stripe CLI to forward Stripe events directly to your localhost — so you’ll never need to touch the Stripe dashboard for webhook setup again.
🧩 Step 1: Install Stripe CLI (Windows — Fixed)
For Windows users, installing via PowerShell is the cleanest way.
Note: Run your PowerShell terminal as Administrator.
Run this one command:
iwr https://github.com/stripe/stripe-cli/releases/download/v1.21.5/stripe_1.21.5_windows_x86_64.zip -OutFile stripe.zip; Expand-Archive stripe.zip .; .\stripe\stripe.exe --version\This command will:
Download the zip file
Unzip the contents into a new stripe folder
Run stripe --version to confirm installation
Expected output:
stripe/1.21.5 windows-x86_64🔑 Step 2: Login (One-Time Setup) Link your CLI to your Stripe account:
.\stripe\stripe.exe loginThis will automatically open your browser — click Continue to complete the login process.
⚡ Step 3: Start Webhook Forwarding (Your Local “Webhook”) This is the magic step. The CLI connects to Stripe and forwards events to your local endpoint.
.\stripe\stripe.exe listen --forward-to localhost:3000/api/webhook/stripe🚨 Important: Copy the secret it prints — this is your new local webhook secret.
Ready! Your webhook signing secret is whsec_test_abc123xyz... 🔐 Step 4: Update Your .env.local Add your Stripe keys and webhook secret:
STRIPE_SECRET_KEY=sk_test_XXXXXXXXXXXXXXXXXXXXXXXX
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_XXXXXXXXXXXXXXXXXXXXXXXX
STRIPE_WEBHOOK_SECRET=whsec_test_abc123xyz... # ← Paste your secret here
NEXT_PUBLIC_URL=http://localhost:3000Get your test keys from 👉 https://dashboard.stripe.com/test/apikeys
🧠 Step 5: Verify Your Webhook Handler File Ensure you have a serverless function that handles and verifies incoming webhook events. Example using Next.js API route:
import Stripe from "stripe";
import Order from "@/models/Order";
import { buffer } from "micro"; // for raw body access in serverless environments
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET;
export const config = { api: { bodyParser: false } };
export async function POST(req) {
const buf = await buffer(req);
const sig = req.headers["stripe-signature"];
let event;
try {
event = stripe.webhooks.constructEvent(buf, sig, endpointSecret);
} catch (err) {
console.log("Webhook error:", err.message);
return new Response("Webhook Error", { status: 400 });
}
if (event.type === "checkout.session.completed") {
const session = event.data.object;
const orderId = session.metadata.orderId;
console.log("Payment SUCCESS for order:", orderId);
await Order.findByIdAndUpdate(orderId, {
status: "paid",
stripeSessionId: session.id,
});
}
return new Response("OK", { status: 200 });
}🧭 Step 6: Run Your Application Start your local development server:
npm run dev💳 Step 7: Test Stripe Checkout Go to your shopping cart
Choose Stripe as the payment method
Click Place Order
Use the test card:
4242 4242 4242 4242Any future expiration date and any CVC will work.
✅ Verification:
In your PowerShell (where stripe listen is running), you’ll see:
--> checkout.session.completed
<-- [200] POST /api/webhook/stripe
Payment SUCCESS for order: 67f1a2b3...In your database:
status: "paid" 💰 Step 8: Test Cash on Delivery (COD) To confirm your non-Stripe payment flow is unaffected:
Choose COD
Place Order
Order status should remain pending

