Skip to main content

Webhook Handlers

The SDK includes ready-made webhook handlers for Express and Next.js that handle signature verification, JSON parsing, deduplication, and event routing automatically.

processWebhook

The low-level webhook processor. Framework handlers build on top of this.

WebhookResult


Express Handler

Import from @zendfi/sdk/express:
You must use express.raw({ type: 'application/json' }) before the webhook handler. The handler needs the raw body string for signature verification. If you use express.json() instead, the signature check will fail.

Next.js Handler

Import from @zendfi/sdk/nextjs. Works with the App Router:

Handler Config

Both framework handlers accept a shared configuration:
The handlers map is passed alongside the config when creating framework-specific handlers (see Express/Next.js examples above).

Handler Callback Signature

Each handler receives two arguments — the event-specific data object and the full webhook payload:

Available Event Handlers

You only need to register handlers for events you care about. Unhandled events return a 200 response automatically.

Deduplication

The SDK includes built-in deduplication to handle webhook retries. By default, it uses an in-memory set (auto-pruned at 10,000 entries). For production, provide your own storage:

Error Handling

Register a global error handler: