Skip to content
HisarPay

Money and events

Webhooks

Webhooks are signed HTTP requests that HisarPay sends to your server when something happens in your account. Listen for events instead of polling: it is faster and does not use your rate limit.

Adding an endpoint

Add endpoints in the dashboard under Developers → Webhooks, or through the API with a live key. Leave events empty to receive every event. The signing secret (whsec_…) is returned once, in the create response.

curl -X POST https://hisarpay.com/v1/webhook-endpoints \
  -H "Authorization: Bearer $HISARPAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://shop.example/webhooks/hisarpay",
    "events": [
      "invoice.paid",
      "invoice.overpaid",
      "invoice.partial",
      "invoice.expired"
    ]
  }'

curl -X POST https://hisarpay.com/v1/webhook-endpoints/3c9d…/rotate-secret \
  -H "Authorization: Bearer $HISARPAY_API_KEY"
  • Endpoints receive both live and test events; check the livemode field of the event.
  • If you pass a callback_url on an invoice, that invoice’s events are sent there too. These deliveries are signed with your default endpoint’s secret; without any endpoint they are not sent.
  • For safety, events only go to public addresses: localhost, private networks and link-local addresses are refused. Use HTTPS.

Event types

EventWhen
invoice.paidAn invoice was paid in full or within tolerance.
invoice.overpaidAn invoice was paid more than due.
invoice.partialPart of an invoice was paid; the rest is due.
invoice.expiredAn invoice expired before it was paid.
invoice.cancelledAn invoice was cancelled.
invoice.payment_receivedA payment that does not count towards the invoice arrived (other coin or cancelled invoice); it was credited.
withdrawal.completedA withdrawal was confirmed on chain.
withdrawal.failedA withdrawal could not be sent; it was refunded.
withdrawal.rejectedA withdrawal was rejected in review.
test.pingSent by the “Send test” button in the dashboard.

Request and payload

Every event is a POST with a JSON body. The body always uses the same envelope: id, type, livemode, created_at and a data object that depends on the event.

Request headers
POST /webhooks/hisarpay HTTP/1.1
Content-Type: application/json
User-Agent: HisarPay-Webhook/1.0
X-HisarPay-Event-Id: 5f0c6c1e-8a51-4c7e-9d0e-2b1f4f6a9c11
X-HisarPay-Signature: t=1792746760,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
invoice.paid
{
  "id": "5f0c6c1e-8a51-4c7e-9d0e-2b1f4f6a9c11",
  "type": "invoice.paid",
  "livemode": true,
  "created_at": "2026-10-23T09:12:40.000Z",
  "data": {
    "invoice": {
      "id": "0b6a3f52-3c1d-4a7e-8f4b-1d2c3e4f5a6b",
      "object": "invoice",
      "livemode": true,
      "type": "choice",
      "status": "paid",
      "token": "USDT",
      "amount": "26",
      "paid_amount": "26",
      "remaining_amount": "0",
      "overpaid_amount": "0",
      "underpaid_amount": "0",
      "price_amount": "25.00",
      "price_currency": "USD",
      "rate_usd": "1",
      "allowed_tokens": ["TRX", "USDT"],
      "network_fee": "1",
      "fee_paid_by_customer": false,
      "commission_added": "0",
      "order_id": "order_1001",
      "description": "Order #1001",
      "metadata": { "cart": "42" },
      "address": "TQ5pRkV4n1hYp7Dn3fRzXw2Lc8uJmKb9eA",
      "payment_url": "https://hisarpay.com/pay/0b6a3f52-3c1d-4a7e-8f4b-1d2c3e4f5a6b",
      "success_url": "https://shop.example/thanks",
      "return_url": null,
      "callback_url": null,
      "payment_link_id": null,
      "customer_email": null,
      "payer": null,
      "expires_at": "2026-10-23T10:00:00.000Z",
      "paid_at": "2026-10-23T09:12:39.000Z",
      "created_at": "2026-10-23T09:00:00.000Z"
    },
    "payment": {
      "txid": "9b7c1d2e…c3d4e",
      "from": "TW8x…2nQe",
      "amount": "26",
      "token": "USDT",
      "late": false,
      "repriced": null,
      "simulated": false
    }
  }
}

Invoice events carry data.invoice and data.payment, and withdrawal events data.withdrawal. data.invoice is the same object GET /v1/invoices/{id} returns, without the payments list (the payment that triggered the event is data.payment).

Verifying signatures

The X-HisarPay-Signature header looks like t=<unix time>,v1=<signature>. The signature is the hex HMAC-SHA256 of t + "." + raw body, keyed with the endpoint’s secret. To verify:

  1. Read the body raw. If you parse the JSON and serialise it again, the bytes change and the signature no longer matches.
  2. Reject the request if t is more than 5 minutes away from the current time.
  3. Compute the expected signature and compare it, in constant time, with any of the v1 values in the header.

The SDKs do all of this in one call:

import express from 'express';
import { HisarPay, SignatureVerificationError } from '@hisarpay/node';

const app = express();
const secret = process.env.HISARPAY_WEBHOOK_SECRET!; // whsec_…
const LIVE = process.env.HISARPAY_API_KEY!.startsWith('hp_live_');

// express.raw keeps the exact bytes; register it before any express.json()
app.post('/webhooks/hisarpay', express.raw({ type: 'application/json' }), async (req, res) => {
  let event;
  try {
    event = HisarPay.webhooks.constructEvent(req.body, req.headers['x-hisarpay-signature'], secret);
  } catch (err) {
    if (err instanceof SignatureVerificationError) return res.status(400).send(err.message);
    throw err;
  }
  // test events arrive here too, and anyone can mark a test invoice as paid
  if (event.livemode !== LIVE) return res.sendStatus(200);
  if (event.type === 'invoice.paid' || event.type === 'invoice.overpaid') {
    // fulfil the order once; record the event id
    await fulfillOrder(event.data.invoice.order_id, event.id);
  }
  res.sendStatus(200);
});

Without an SDK, the same check takes a few lines:

import { createHmac, timingSafeEqual } from 'node:crypto';

export function verifyHisarPay(rawBody: string, header: string, secret: string, tolerance = 300) {
  const parts = header.split(',').map((p) => p.trim().split('='));
  const t = Number(parts.find(([k]) => k === 't')?.[1]);
  if (!Number.isFinite(t) || Math.abs(Date.now() / 1000 - t) > tolerance) return false;
  const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest();
  return parts
    .filter(([k]) => k === 'v1')
    .some(([, v]) => {
      const got = Buffer.from(v ?? '', 'hex');
      return got.length === expected.length && timingSafeEqual(got, expected);
    });
}

Responding and duplicates

  • Return a 2xx within 10 seconds. Queue heavy work and answer right away. Redirects (3xx) are not followed and count as failures.
  • The same event can arrive more than once. Store X-HisarPay-Event-Id (the id in the body) and skip events you have already handled.
  • Ordering is not guaranteed. Decide based on the status in the event, or read the current state with GET /v1/invoices/{id} to be sure.

Retry schedule

Any response other than 2xx, a timeout or a connection error counts as a failure, and the event is sent again on this schedule:

AttemptAfter the previous one
1Immediately
230 s
32 min
410 min
530 min
61 h
73 h
86 h
912 h
1024 h

The ten attempts span about two days. If the last one fails too, the delivery is marked failed. Once you have fixed the problem, resend the event from the dashboard or the API; it goes to every matching endpoint again:

curl -X POST https://hisarpay.com/v1/events/5f0c6c1e-8a51-4c7e-9d0e-2b1f4f6a9c11/resend \
  -H "Authorization: Bearer $HISARPAY_API_KEY"

Rotating the secret

POST /v1/webhook-endpoints/{id}/rotate-secret creates a new secret. The old one stays valid for 24 hours, and during that time every delivery carries two signatures:

During rotation
X-HisarPay-Signature: t=1792746760,v1=<new secret signature>,v1=<old secret signature>

Verification passes when any v1 matches, so you can switch to the new secret whenever you like within those 24 hours, without downtime.

Testing

The Send test button next to an endpoint in the dashboard sends one test.ping event to it; it is never retried. For end-to-end scenarios use payment simulation; simulated payments produce real webhooks.