Receives and processes Stripe webhook events with signature verification
constructEvent method to verify that incoming webhooks are authentic. This process:
stripe-signature header containing the signature and timestampSTRIPE_WEBHOOK_SECRET to verify the signature matches the payloadSTRIPE_WEBHOOK_SECRETYou must configure this secret in your environment. The webhook secret is provided in your Stripe Dashboard when you create a webhook endpoint. It typically starts with whsec_.https://yourdomain.com/api/webhooks/stripeSTRIPE_WEBHOOK_SECRETapplication/jsonpayment_intent.succeeded
event.data.object contains the complete PaymentIntent object.Use cases:payment_intent.payment_failed
event.data.object contains the PaymentIntent with error details.Use cases:refund.created
event.data.object contains the Refund object.Use cases:charge.refunded
event.data.object contains the Charge object with refund details.Use cases:true for valid webhooks.event.id to ensure you only process each event once.
| Error Condition | HTTP Status | Response Message |
|---|---|---|
Missing STRIPE_WEBHOOK_SECRET | 500 | ”Missing STRIPE_WEBHOOK_SECRET in environment variables” |
Missing stripe-signature header | 400 | ”Missing stripe-signature header” |
| Invalid signature | 400 | ”Webhook signature verification failed: [error details]“ |
| Valid webhook received | 200 | ”Webhook recibido correctamente” |