𝗦𝘁𝗿𝗶𝗽𝗲 𝗪𝗲𝗯𝗵𝗼𝗼𝗸 𝗧𝗲𝘀𝘁𝗶𝗻𝗴: 𝗟𝗼𝗰𝗮𝗹 𝗗𝗲𝘃𝗲𝗹𝗼𝗽𝗺𝗲𝗻𝘁 𝗚𝘂𝗶𝗱𝗲 -> 𝗣𝗿𝘂𝗲𝗯𝗮𝘀 𝗱𝗲 𝗪𝗲𝗯𝗵𝗼𝗼𝗸𝘀 𝗱𝗲 𝗦𝘁𝗿𝗶𝗽𝗲: 𝗚𝘂í𝗮 𝗱𝗲 𝗱𝗲𝘀𝗮𝗿𝗿𝗼𝗹𝗹𝗼 𝗹𝗼𝗰𝗮𝗹
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. -> Los webhooks de Stripe notifican a tu aplicación sobre pagos y suscripciones. Un webhook perdido provoca fallos en los pedidos. Antes, las pruebas eran difíciles. Ahora es fácil con la CLI de Stripe.
Install the CLI first. -> Primero, instala la CLI.
- macOS: brew install stripe/stripe-cli/stripe
- Windows: scoop install stripe
- Linux: Use the releases page. ->
- macOS: brew install stripe/stripe-cli/stripe
- Windows: scoop install stripe
- Linux: Usa la página de lanzamientos.
Link your account with this command: -> Vincula tu cuenta con este comando:
stripe login -> stripe login
Start the listener to forward events to your server: -> Inicia el listener para reenviar eventos a tu servidor:
stripe listen --forward-to localhost:3000/webhooks/stripe -> stripe listen --forward-to localhost:3000/webhooks/stripe
Save the signing secret from the output. Set it in your environment: -> Guarda el secreto de firma (signing secret) de la salida. Configúralo en tu entorno:
export STRIPE_WEBHOOK_SECRET=whsec_abc123 -> export STRIPE_WEBHOOK_SECRET=whsec_abc123
Test events without spending money. Use triggers. -> Prueba eventos sin gastar dinero. Usa triggers.
- Payment success: stripe trigger payment_intent.succeeded
- Payment fail: stripe trigger payment_intent.payment_failed
- New subscription: stripe trigger customer.subscription.created ->
- Pago exitoso: stripe trigger payment_intent.succeeded
- Fallo de pago: stripe trigger payment_intent.payment_failed
- Nueva suscripción: 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. -> Verifica las firmas para evitar solicitudes falsas. Usa el cuerpo de la solicitud en bruto (raw request body). Los analizadores JSON rompen la verificación. Usa express.raw() en Express.
Solve common errors. -> Soluciona errores comunes.
- A 400 response means the signature failed.
- Check your CLI secret. Dashboard secrets do not work here.
- Review your logs. ->
- Una respuesta 400 significa que la firma falló.
- Comprueba tu secreto de la CLI. Los secretos del Dashboard no funcionan aquí.
- Revisa tus logs.
Production checklist. -> Lista de verificación para producción.
- Use HTTPS.
- Use the production secret.
- Respond in under 30 seconds.
- Handle duplicate events. ->
- Usa HTTPS.
- Usa el secreto de producción.
- Responde en menos de 30 segundos.
- Gestiona eventos duplicados.
Source: https://dev.to/digital_trubador/stripe-webhook-testing-local-development-guide-391 -> Source: https://dev.to/digital_trubador/stripe-webhook-testing-local-development-guide-391