{
  "id": 23861886,
  "title": "How to Verify Bank-Transfer VietQR Webhooks (HMAC-SHA256 + D1 Idempotency) on $0/mo Cloudflare Workers",
  "url": "https://urgent.news/2026/12/06/how-to-verify-bank-transfer-vietqr-webhooks-hmac-sha256-d1",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-12-06T16:37:10.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/bi_phcminhtm_173b617/how-to-verify-bank-transfer-vietqr-webhooks-hmac-sha256-d1-idempotency-on-0mo-cloudflare-2b2j"
  },
  "original_language": null,
  "account": "To verify Bank-Transfer VietQR Webhooks using HMAC-SHA256 and D1 Idempotency on Cloudflare Workers and D1, follow these steps:\n\n1. Read the request body as raw text using await c.req.text() before parsing as JSON. This prevents HMAC verification from failing due to whitespace or key-order changes in the JSON.\n\n2. Fail closed by checking if the SEPAY_WEBHOOK_SECRET is empty or unset. If so, return HTTP 503 status to avoid accepting unsigned callbacks from a broken deployment.\n\n3. Validate the X-SePay-Timestamp header, ensuring it matches the format of 9-12 digits and falls within a 300-second window of the server's time. If not valid, return HTTP 401 status.\n\n4. Parse the X-SePay-Signature header, which should be formatted as \"sha256=<64-character-hex-string>\". If not in this format, return HTTP 401 status.\n\n5. Sign the concatenated string of timestamp.rawBody using the Web Crypto API's SHA-256 digest algorithm with the secret key. Compare the resulting signature in constant time to the received signature. If they match, the webhook is verified successfully.",
  "summary": "If you sell digital products from Vietnam, international PayPal checkout alone leaves local buyers blocked. PayPal rejects domestic Vietnam-to-Vietnam PayPal transfers, and local cards often fail on cross-border merchant accounts. Bank transfers over VietQR solve that directly: buyers scan a QR code in their banking app, funds settle instantly in VND with zero card fees, and SePay forwards…",
  "summary_source": "publisher",
  "key_points": [
    "Read request body as raw text before JSON parsing",
    "Fail closed if SEPAYWEBHOOKSECRET is empty",
    "Validate X-SePay-Timestamp within 300-second window"
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "outlets_capped": false,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}