Webhooks

Events, the X-PG-Signature header, how to verify it, and the retry schedule.

Updated 22 Nov 2026 · 1 min read

When a payment reaches a final state, the server sends POST <webhook_url> with these headers:

HeaderValue
X-PG-Evente.g. payment.completed
X-PG-Timestampunix seconds
X-PG-Signaturehex HMAC_SHA256(api_secret, timestamp + "." + rawBody)

Body:

{"event":"payment.completed","id":"evt_…","created":1763280000,
 "data":{"payment":{"id":"PAY-7Q2M9XKD","status":"completed","amount":"500.00","currency":"BDT",
 "reference":"ORDER-1001","method":"bkash","trx_id":"9KD7A1B2C3","paid_amount":"500.00"}}}

Events: payment.completed, payment.failed, payment.expired, payment.cancelled, payment.refunded, invoice.paid.

Verify it (PHP)

$raw = file_get_contents('php://input');
$ts  = $_SERVER['HTTP_X_PG_TIMESTAMP'] ?? '';
$sig = $_SERVER['HTTP_X_PG_SIGNATURE'] ?? '';
$ok  = abs(time() - (int) $ts) < 300
    && hash_equals(hash_hmac('sha256', $ts . '.' . $raw, 'sk_live_…'), $sig);
if (!$ok) { http_response_code(400); exit; }
$event = json_decode($raw, true);
// compare amount, currency and reference with YOUR order, then mark it paid (only once)
echo 'ok';

Rules

  • Reject a timestamp older than 5 minutes and any wrong signature.
  • Answer with any 2xx status. Anything else is retried after 1, 5, 15, 60, 180 and 720 minutes, then marked failed — Admin → Webhooks can resend it.
  • A webhook can arrive more than once: make "mark paid" idempotent.
  • Webhooks to private network addresses are blocked.