๐ฆ๐๐ฟ๐ถ๐ฝ๐ฒ ๐ช๐ฒ๐ฏ๐ต๐ผ๐ผ๐ธ ๐ง๐ฒ๐๐๐ถ๐ป๐ด: ๐๐ผ๐ฐ๐ฎ๐น ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐บ๐ฒ๐ป๐ ๐๐๐ถ๐ฑ๐ฒ
Stripe webhooks notify your app about payments and subscriptions. A missed webhook causes failed orders. Testing used to be hard. Now it is easy with the Stripe CLI.
Install the CLI first.
- macOS: brew install stripe/stripe-cli/stripe
- Windows: scoop install stripe
- Linux: Use the releases page.
Link your account with this command: stripe login
Start the listener to forward events to your server: stripe listen --forward-to localhost:3000/webhooks/stripe
Save the signing secret from the output. Set it in your environment: export STRIPE_WEBHOOK_SECRET=whsec_abc123
Test events without spending money. Use triggers.
- Payment success: stripe trigger payment_intent.succeeded
- Payment fail: stripe trigger payment_intent.payment_failed
- New subscription: stripe trigger customer.subscription.created
Verify signatures to stop fake requests. Use the raw request body. JSON parsers break the verification. Use express.raw() in Express.
Solve common errors.
- A 400 response means the signature failed.
- Check your CLI secret. Dashboard secrets do not work here.
- Review your logs.
Production checklist.
- Use HTTPS.
- Use the production secret.
- Respond in under 30 seconds.
- Handle duplicate events.
Source: https://dev.to/digital_trubador/stripe-webhook-testing-local-development-guide-391