Signed webhooks
Webhooks notify your backend when an order's payment or fulfillment changes. They complement, but do not replace, the canonical order read.
Register an endpoint
The endpoint must be an approved, publicly reachable HTTPS URL. Create a stable idempotency key before the request and store the returned secret immediately.
curl -sS -X POST https://api.lifepeaks.dk/v2/webhook-endpoints \
-H "Authorization: Bearer $LIFEPEAKS_API_KEY" \
-H "Idempotency-Key: webhook_endpoint_primary_v1" \
-H "Content-Type: application/json" \
-d '{
"url":"https://partner.example/webhooks/lifepeaks",
"events":["order.payment_authorized","order.fulfilled","order.payment_failed"]
}'
The first successful 201 response includes a whsec_… signing secret. It is shown once; list responses never return it. Store it in a managed secret store, outside source control and logs.
An idempotent replay returns 200 without the secret. If the first response was lost before you stored it, rotate the endpoint secret and store the new one-time value. Do not create duplicate endpoints to recover a missing secret.
Verify before parsing
Lifepeaks sends these headers:
| Header | Purpose |
|---|---|
Lifepeaks-Webhook-Id | Immutable evt_… event ID and deduplication key |
Lifepeaks-Webhook-Timestamp | Unix timestamp in seconds |
Lifepeaks-Webhook-Secret-Version | The current secret version. During a rotation overlap it does not name the previous one, so do not use it to choose a secret |
Lifepeaks-Webhook-Signature | One or more v1= HMAC-SHA256 hex digests. During a rotation overlap it carries comma-separated values, newest first |
The signed bytes are exactly:
timestamp + "." + event_id + "." + raw_request_body
Read the raw request body before JSON parsing or middleware changes whitespace. Reject stale timestamps, compare signatures in constant time, and only then parse the JSON.
This complete verifier uses Node/Bun's standard crypto implementation:
import { createHmac, timingSafeEqual } from 'node:crypto'
export function verifyLifepeaksWebhook(input: {
secret: string
eventId: string
timestamp: number
rawBody: string
signature: string
now?: number
}): boolean {
const now = input.now ?? Math.floor(Date.now() / 1000)
if (!input.secret || !input.eventId || input.eventId.includes('.')) return false
if (!Number.isSafeInteger(input.timestamp) || Math.abs(now - input.timestamp) > 300) return false
const signed = `${input.timestamp}.${input.eventId}.${input.rawBody}`
const expected = Buffer.from(
`v1=${createHmac('sha256', input.secret).update(signed).digest('hex')}`,
)
return input.signature.split(',').some((value) => {
const candidate = Buffer.from(value.trim())
return candidate.length === expected.length && timingSafeEqual(candidate, expected)
})
}
Acknowledge durably
Process each request in this order:
- Limit the request body size.
- Read the exact raw body and required headers.
- Reject timestamps outside a five-minute tolerance.
- Verify the signature in constant time.
- Parse JSON and validate
id,type,api_version, and the payload for that event type (data.orderfor order events;data.endpointforwebhook.ping). - Insert
Lifepeaks-Webhook-Idinto durable storage with a unique constraint. - Commit the event to your queue or inbox table.
- Return
204only after that durable commit.
Repeated event IDs are normal. A duplicate that is already durable should also receive 204, without running business side effects again. Return a non-2xx response when the event was not made durable so Lifepeaks can retry it.
Event types
| Event | Meaning |
|---|---|
order.created | An order was accepted, before payment. Retrying its creation does not emit a second event. Delivery is not guaranteed for every created order; use GET /v2/orders to reconcile missed notifications. |
order.payment_authorized | Payment was authorized. Read the order to confirm its current payment and fulfillment state. |
order.fulfilled | Order fulfillment completed. |
order.payment_failed | Payment failed. Read the order before offering another checkout attempt. |
order.partially_refunded | Part of the payment was refunded. |
order.refunded | The payment was refunded in full. |
order.refund_failed | A tracked refund could not be completed. Read data.refund.id through GET /v2/refunds/{id} for its final status and confirmed amounts. |
order.expired | An unpaid order expired. |
Refund outcomes. Subscribe to all three refund events when offering a refund action. Events for refunds created through the order refund API include data.refund alongside data.order. The refund resource contains id, status, requested_amount, amount, refunded, refundable, currency, and payment; a failure also includes failure.code and failure.message. Amounts are whole numbers in the smallest currency unit. A mixed payment can return its paying gift-card contribution even if the gateway part fails, so inspect amount before describing a failed operation as returning no money. A failure does not reactivate the cancelled cards.
A pending refund is reconciled automatically. A confirmed result emits order.refunded or order.partially_refunded; a failed result emits order.refund_failed. Poll GET /v2/refunds/{id} as a fallback for missed notifications. The same refund ID identifies the operation throughout its lifecycle. Refunds initiated outside this tracked API flow may have only data.order.
For example, a confirmed refund notification includes:
{
"id": "evt_0123456789abcdef0123456789abcdef",
"type": "order.refunded",
"api_version": "v2",
"occurred_at": "2026-10-05T12:00:00+00:00",
"data": {
"order": {
"id": "po_2f8c1d4e6a7b8c9d0e1f2a3b4c5d6e7f"
},
"refund": {
"object": "refund",
"id": "rf_0123456789abcdef0123456789abcdef",
"status": "succeeded",
"order_id": "po_2f8c1d4e6a7b8c9d0e1f2a3b4c5d6e7f",
"requested_amount": 37500,
"amount": 37500,
"refunded": 37500,
"refundable": 37500,
"currency": "DKK",
"payment": {
"status": "refunded"
}
}
}
}
Order expiry. An unpaid order expires when its checkout link expired more than one hour ago, or when no checkout session was started within 24 hours of creation. Declined payments follow the same rules because the buyer can retry checkout on the unpaid order. Paid orders are not expired. Subscribe to order.expired to update abandoned baskets in your application.
Webhook order payloads omit sender, recipient, greeting, and the postal address. They include reference, delivery.method, and delivery.send_at for reconciliation. Retrieve buyer details through an authenticated order read when needed.
Webhook payloads have this envelope:
{
"id": "evt_0123456789abcdef0123456789abcdef",
"type": "order.fulfilled",
"api_version": "v2",
"occurred_at": "2026-08-22T12:00:00+00:00",
"data": { "order": { "id": "po_0123456789abcdef0123456789abcdef" } }
}
Use the embedded id only after verifying that it matches Lifepeaks-Webhook-Id.
Test an endpoint
POST /v2/webhook-endpoints/{endpoint_id}/ping — scope webhooks:write
Queues a signed webhook.ping event to test connectivity and signature verification before processing order events.
curl -sS -X POST https://api.lifepeaks.dk/v2/webhook-endpoints/wh_8f2c/ping \
-H "Authorization: Bearer $LIFEPEAKS_API_KEY" \
-H "Idempotency-Key: $(uuidgen)"
The ping is a real delivery. It is signed with the endpoint's current secret, carries the same headers as any other event, retries on the same schedule, and appears in GET /v2/webhook-deliveries beside your order events. Use it to verify connectivity and signature handling.
Send an empty request body. Request fields return 422. The event payload identifies the endpoint:
{
"id": "evt_0123456789abcdef0123456789abcdef",
"type": "webhook.ping",
"api_version": "v2",
"occurred_at": "2026-09-03T10:14:00+00:00",
"data": { "endpoint": { "id": "wh_8f2c" } }
}
A handler that does not process webhook.ping should verify its signature and return 2xx. Ping events are delivered to the specified endpoint regardless of its subscriptions. Do not include webhook.ping in an endpoint's events list.
The response is 202 Accepted; check GET /v2/webhook-deliveries for the delivery outcome. Idempotency-Key is required. Repeating a ping with the same key returns the same event and delivery; use a new key for a separate test. Disabled and unknown endpoints return 404.
Rotate without downtime
Lifepeaks provides a 24-hour overlap between the current and previous signing secrets:
- Rotate.
POST /v2/webhook-endpoints/{endpoint_id}/rotate-secretreturns the newwhsec_…secret — once — along withprevious_secret_versionandprevious_secret_expires_at. - Read the deadline.
previous_secret_expires_atis when the old secret stops being accepted, 24 hours after the rotation. - Install the new secret before that instant. Until then every delivery is signed with both secrets, so a receiver still holding only the old one keeps verifying. A receiver that verifies against every value in the signature header — as the one above does — needs no change at all beyond the new secret value.
- Remove the old secret from your configuration after the overlap. Lifepeaks stops using it when the window closes, and deliveries go back to a single signature.
{
"id": "wh_9d41b7e0c8524fa63b1e70d5482ac9f6",
"secret_version": 2,
"previous_secret_version": 1,
"previous_secret_expires_at": "2026-08-28T04:13:05+00:00",
"secret": "whsec_Kd8pR1zW6vN3yT5bG9hJ2mQ4sX7cF0aL"
}
Both overlap fields read null when no window is open — on an endpoint that has never
been rotated, and once a window has closed.
Rotating again inside an open window retires the older secret immediately. Only two secrets are ever live, so a second rotation before you have deployed the first one will cut off a receiver still using the original. Deploy, then rotate again.
Operate and recover
GET /v2/webhook-endpointslists endpoint status, failure counts, and any open rotation overlap, without secrets.POST /v2/webhook-endpoints/{endpoint_id}/rotate-secretreturns the new secret on the first execution only. Use a stable, operation-specificIdempotency-Key.GET /v2/webhook-deliveriesshows recent attempts and terminal state.POST /v2/webhook-deliveries/{delivery_id}/replayrequeues a delivered or exhausted delivery whose endpoint is still active. A disabled endpoint returns409 delivery_not_replayablewithout changing the delivery. Its idempotency key must be independent from registration and rotation keys.DELETE /v2/webhook-endpoints/{endpoint_id}disables the endpoint and cancels pending deliveries.
The Lifepeaks storefront starter ships a working receiver with durable deduplication, timestamp checks, and tamper tests. The repository is private, so ask Lifepeaks for access first. Run bun run doctor before exposing your endpoint publicly.
Membership lifecycle events
Subscribe to membership.changed, membership_program.changed or membership_group.changed for discount memberships. These events use the same signatures, outbox, retry policy and event-ID deduplication as order events. Payloads contain the resource identifier, revision and state without member contact details. Refresh the current resource through API v2. Group changes also invalidate the eligibility of their members; individual expiry remains a time-based eligibility calculation.