Docs/Webhooks

Webhooks

Receive real-time notifications when events happen in your account.

How webhooks work

When an event occurs—like a successful payment or a failed subscription charge—we send an HTTP POST request to your configured endpoint with all the relevant data.

payment.succeeded
payment.failed
subscription.created
subscription.cancelled
invoice.paid
payout.completed

Example webhook payload

{ "id": "evt_1234567890", "type": "payment.succeeded", "created_at": "2024-01-15T10:30:00Z", "data": { "payment": { "id": "pay_abc123", "amount": 1000, "currency": "KES", "status": "succeeded" } } }

Verifying webhook signatures

Always verify that webhooks came from Sunny by checking the signature.

const sunny = require('@sunny/payments'); const event = sunny.webhooks.verify( request.body, request.headers['sunny-signature'], process.env.WEBHOOK_SECRET );