BillingWebhookKit

Payment webhook dead letter queue in Next.js

A billing webhook can fail after the provider already considers the event delivered. Store failed events, prove replay safety, and keep entitlement writes idempotent before the buy link goes public.

Generate replay cURL Build a test plan

What to record

Verified event identity

Record provider, event ID, event type, object ID, raw body hash, and signature result after the raw-body gate passes.

Failure reason

Separate signature failure, unknown event, missing customer mapping, database write failure, email failure, and fulfillment failure.

Replay command

Store a sanitized cURL command or fixture reference so the team can reproduce the event without exposing webhook secrets.

Idempotency key

Persist the same key used by the handler so manual replay cannot grant access, revoke access, or send delivery twice.

Next.js table shape

The dead letter table can be small. The important rule is that it records enough evidence to replay safely without storing production API keys or private checkout links.

create table payment_webhook_dead_letters (
  id text primary key,
  provider text not null,
  event_type text not null,
  object_id text not null,
  idempotency_key text not null,
  raw_body_sha256 text not null,
  signature_verified boolean not null,
  failure_reason text not null,
  replay_status text not null default 'pending',
  created_at timestamptz not null default now()
);

CI gates

FAQ

Should a payment webhook return 500 to force provider retries?

Only when the event is safe to retry and the handler failed before durable recording. If the event is recorded in a dead letter queue, return the status your runbook expects and replay from storage.

What should a webhook dead letter queue store?

Store provider, event ID, event type, object ID, signature verification result, raw body hash, failure reason, idempotency key, replay command, and operator notes without storing private API keys.

Turn failed webhook handling into release evidence

The free replay and test plan tools help design the recovery path. The CNY 69 Pro Kit is for teams that want fixtures, idempotency tests, entitlement matrices, and review templates already packaged.