Skip to main content
Back to API Reference
WEBHOOKX-Signature (HMAC-SHA256)

Webhook Signature Verification & Idempotency (HMAC-SHA256)

ENDPOINT OVERVIEW

SF PayGate delivers and retries webhooks until your server answers HTTP 200. Because X-Signature is computed over the exact raw request body, re-serialising parsed JSON will not match — always verify raw bytes with timingSafeEqual, check X-Timestamp freshness, and deduplicate by transaction id.

Protocol Rules

  • Never re-serialize parsed JSON before signature verification — read the unparsed raw body buffer.
  • For outbound API requests you send to us, strip the leading /api prefix from the signed path.
  • Enforce idempotent ledger writes keyed on id / merchant_ref_id before returning HTTP 200.

Request Examples

# Webhook headers delivered to your callback endpoint:
# X-Timestamp: 1796365500
# X-Signature: 8b21c4e9a7...
# Content-Type: application/json

Sample JSON Response

{
  "event": "payin.succeeded",
  "id": "0198cbff-db9b-7b6a-9f82-6a55fdfb6575",
  "merchant_ref_id": "unique-order-ref-id-2025001",
  "currency_code": "THB",
  "request_amount": 1000,
  "settled_at": "2026-12-04T13:18:22+07:00"
}