Get a public URL for Stripe webhooks#
Stripe can't deliver to localhost. An OtterKit webhook endpoint gives you a public HTTPS URL that answers Stripe around the clock and keeps every request, so nothing is lost while your laptop is closed or your handler is half written:
npx otterkit login
npx otterkit webhook --daemon --subdomain stripe-dev
# https://stripe-dev.otterkit.appThe name is reserved to your account, so the URL stays the same every time you start it. An endpoint costs $0.01 per hour while it is live and never more than $3 in any 30 days, and new accounts get 10 free credits. To look at a payload before you sign up, the try page gives you a live URL in the browser with no account.
Register the URL in Stripe#
- In the Stripe Dashboard, open Developers, then Webhooks, and add an endpoint. Newer dashboards call it an event destination.
- Paste the endpoint URL and choose the events to send. Start with the few you handle.
- Save, then reveal the signing secret. It starts with
whsec_.
Use https://stripe-dev.otterkit.app as the URL. Add a path if your handler expects one, such as https://stripe-dev.otterkit.app/webhooks/stripe: the endpoint accepts any path and records it.
The Stripe webhook secret and signature#
Every endpoint has its own signing secret, and test mode and live mode have different ones. A secret from the Stripe CLI is different again: it only signs events the CLI forwards.
Stripe sends a Stripe-Signature header with a timestamp (t=) and one or more signatures (v1=). Each signature is an HMAC-SHA256 of the timestamp, a dot and the raw request body, keyed with the secret. Verify against the raw bytes: a body that was parsed and serialized again will not match. Stripe's libraries also reject timestamps more than five minutes old by default, which stops old requests being replayed by someone else.
OtterKit can run the same check on every request as it arrives. Start the endpoint again with the secret, and each capture is marked valid, invalid or missing:
npx otterkit stop stripe-dev
npx otterkit webhook --daemon --subdomain stripe-dev --verify stripe:whsec_…A failed check comes with its reason, such as signature_mismatch, so a wrong secret and a changed body look different. See signature verification for all 16 presets and the generic HMAC mode.
Send a test event#
Trigger a real event by doing the thing in test mode, such as completing a Checkout session with a test card, or run stripe trigger payment_intent.succeeded if you have the Stripe CLI.
Then watch it land, or wait for it in a script:
# Follow requests as they arrive, with headers and bodies
npx otterkit inspect stripe-dev --follow
# Or block until the next POST, then print it as JSON
npx otterkit await stripe-dev --method POST --count 1 --timeout 120s --jsonYou can also skip Stripe entirely. otterkit send builds a sample event, signs it with your secret the way Stripe does and posts it straight to your local handler:
npx otterkit send stripe:payment_intent.succeeded 127.0.0.1:3000/webhooks/stripe \
--secret whsec_…Replay Stripe events into your local handler#
Once an event is captured you can send it to your handler as often as you like, with the original headers and body, without asking Stripe to fire it again:
# Send the latest captured event to a server on port 3000
npx otterkit replay stripe-dev --target 127.0.0.1:3000
# Or a specific one (1 is the oldest, -1 the latest)
npx otterkit replay stripe-dev --index 3 --target 127.0.0.1:3000Replays cost nothing and are added to the capture log with your handler's response next to them. If you would rather have events delivered live while you work, expose the handler with a tunnel instead and register the tunnel URL.
Retries, timeouts and duplicates#
- Stripe treats any
2xxas delivered and retries everything else with growing gaps, for up to three days in live mode. Answer quickly and do slow work afterwards. - Events can arrive more than once and out of order. Store the event
idand skip ones you have already handled.
To see how your code copes when a delivery fails, the HTTP status codes guide has URLs that return any status on demand.
Questions about Stripe webhooks#
Where do I find the Stripe webhook secret?#
On the endpoint's page under Developers, Webhooks. Click to reveal the signing secret. It starts with whsec_ and is not the same as your API key.
Do I need the Stripe CLI to test webhooks locally?#
No. An always-on endpoint receives the events Stripe sends to a registered URL, and you replay them into localhost. It also keeps receiving while your laptop is closed.
Why does signature verification fail with the right secret?#
Almost always because the handler verified a parsed body. Read the raw request bytes before any JSON middleware touches them.