blockpay
03 · WEBHOOKS 5 MIN SETUP

Signed Settlement Webhooks Guide

Receive real-time HTTPS notifications when Ethereum finalizes a payment, verify HMAC-SHA256 signatures with replay protection, and fulfill orders safely.

Signature HeaderBlockpay-Signature: t=<ts>,v1=<hex>
Event ID HeaderBlockpay-Event-Id: evt_…
Replay Window300 seconds (5 minutes)
Retry ScheduleExponential backoff up to 24h

Registering your HTTPS webhook endpoint

Navigate to Dashboard → Developers → Webhooks and enter the HTTPS URL on your approved merchant domain that will receive POST requests from Blockpay. For SSRF protection, endpoints must resolve to public unicast IPv4 addresses over standard HTTPS (port 443) and match your approved business origin.

When you save a new URL, Blockpay generates a 64-character hex signing secret and displays it once. Store this value in your server environment as BLOCKPAY_WEBHOOK_SECRET.

Headers & event payload schema

Every delivery includes Blockpay-Signature and Blockpay-Event-Id headers along with a JSON body containing the finalized onchain settlement amounts in exact integer token units.

HTTPINCOMING WEBHOOK REQUEST
POST /webhooks/blockpay HTTP/1.1
Host: your-store.com
Content-Type: application/json
Blockpay-Event-Id: evt_settled_pay_449be60499b54b559e8d722911460dd2
Blockpay-Signature: t=1764258490,v1=9f4a81b3e17c2f0c857d3f12aa6c80e79b22d4c8e12b8e5788f01a08f11e5d3a

{
  "id": "evt_settled_pay_449be60499b54b559e8d722911460dd2",
  "type": "payment.settled",
  "createdAt": 1764258489201,
  "data": {
    "id": "pay_449be60499b54b559e8d722911460dd2",
    "order": "ORD-1043",
    "merchantId": "m_8c2a1f94...",
    "channel": "api",
    "chain": "ethereum",
    "token": "USDC",
    "transactionHash": "0x7dbfb8d8ee613df807837c360b51998e1cc93347a9c1ba9b5301ddb21e44c2ed",
    "grossUnits": "150000000",
    "feeUnits": "1035000",
    "merchantUnits": "148965000"
  }
}
Event TypeTrigger ConditionRecommended Store Action
payment.settledOnchain receipt verified full settlement and atomic 99.31% split to your walletMark order Paid / Processing, store transactionHash, trigger fulfillment
payment.reviewShort payment or late deposit released onchain for manual inspectionHold order for manual review; compare grossUnits vs. order total in Dashboard

Verifying Blockpay-Signature (HMAC-SHA256)

Blockpay signs the concatenation of the 10-digit Unix timestamp, a literal period (.), and the exact raw UTF-8 request body: `${timestamp}.${rawBody}`. Always verify over the unparsed raw request bytes before calling JSON.parse(), reject timestamps older than 300 seconds, and compare digests with constant-time equality.

JAVASCRIPTNODE.JS / EXPRESS · PRODUCTION VERIFICATION
import express from 'express';
import { createHmac, timingSafeEqual } from 'node:crypto';

const app = express();

function verifyBlockpaySignature(rawBody, header, secret) {
  const match = /^t=(\d{10}),v1=([a-f0-9]{64})$/.exec(header || '');
  if (!match) return false;

  const [, ts, sigHex] = match;
  // Reject replays outside a 5-minute clock skew tolerance
  if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;

  const expected = createHmac('sha256', secret)
    .update(`${ts}.${rawBody}`)
    .digest();
  const received = Buffer.from(sigHex, 'hex');

  return expected.length === received.length && timingSafeEqual(expected, received);
}

// IMPORTANT: use express.raw() so JSON middleware does not mutate the body
app.post('/webhooks/blockpay', express.raw({ type: 'application/json' }), async (req, res) => {
  const rawBody = req.body.toString('utf8');
  const signature = req.headers['blockpay-signature'];

  if (!verifyBlockpaySignature(rawBody, signature, process.env.BLOCKPAY_WEBHOOK_SECRET)) {
    return res.status(401).json({ error: 'Invalid signature' });
  }

  const event = JSON.parse(rawBody);

  // Deduplicate using event.id (unique constraint in your DB)
  const inserted = await db.recordWebhookEventIfNew(event.id);
  if (!inserted) return res.status(200).json({ ok: true, duplicate: true });

  if (event.type === 'payment.settled') {
    await db.markOrderPaid(event.data.order, {
      paymentId: event.data.id,
      txHash: event.data.transactionHash,
      token: event.data.token,
      merchantUnits: event.data.merchantUnits,
    });
  }

  return res.status(200).json({ ok: true });
});
PYTHONPYTHON / FLASK · HMAC VERIFICATION
import hashlib, hmac, re, time
from flask import Flask, request, abort

app = Flask(__name__)

def verify_signature(raw_body: bytes, header: str, secret: str) -> bool:
    m = re.match(r"^t=(\d{10}),v1=([a-f0-9]{64})$", header or "")
    if not m:
        return False
    ts, sig_hex = m.group(1), m.group(2)
    if abs(time.time() - int(ts)) > 300:
        return False
    signed_payload = f"{ts}.".encode("utf-8") + raw_body
    expected = hmac.new(secret.encode("utf-8"), signed_payload, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, sig_hex)

Delivery retries, timeouts & idempotency

  1. Respond with any 2xx HTTP status code within 8 seconds. Offload slow tasks (sending emails, calling shipping APIs) to a background queue.
  2. If your endpoint returns a non-2xx status or times out, Blockpay retries with exponential backoff: 15s × 2^attempt (30s, 60s, 2m, 4m … capped at 24 hours).
  3. Store Blockpay-Event-Id (e.g., evt_settled_pay_…) with a UNIQUE database index so re-delivered events never trigger double fulfillment.
  4. Inspect every emitted event and JSON payload in real time from Dashboard → Developers → Event log.