Docs FNB FNB Gateway v1 API reference
FNB Gateway webhooks v1
The events FNB Gateway pushes to internal services, their flags, how delivery and retries work, and how to verify the HMAC-SHA256 signature.
How delivery works#
- Each subscribing internal service has one HTTPS webhook URL, set in the gateway's configuration by the gateway owner.
- Webhooks are live (sandbox) for a consumer once it has shown that it verifies signatures correctly: good signatures accepted; tampered, stale, replayed and wrongly keyed deliveries refused. Until then its deliveries are signed and recorded but not sent.
- One event per POST, JSON body, at most 256 KB.
- Every delivery is signed with a secret shared only between the gateway and that service.
- Any
2xxresponse counts as delivered. Anything else, or a timeout, is retried with capped exponential backoff (starting at about 30 seconds, growing to at most an hour) for 24 hours. After that the delivery is set aside and the gateway owner is alerted. - A retry sends the same body and the same
eventId. Delivery is at least once, so make your handler idempotent: if you have already processed aneventId, return200and do nothing. - Deliveries can arrive out of order. If order matters, use
occurredAt, or readGET /v1/events, which is ordered. - Missed something?
GET /v1/events?after=<cursor>returns the same envelopes, in order, at any time. - Respond quickly (do heavy work after replying), and return
2xxonly after you have safely stored the event.
Headers#
| Header | Value |
|---|---|
X-Gateway-Timestamp |
Unix time in seconds when this attempt was signed. |
X-Gateway-Key-Id |
Which signing key was used, so keys can be rotated without downtime. |
X-Gateway-Signature |
v1= followed by the lowercase hex HMAC-SHA256 of "<timestamp>.<raw body>". |
X-Gateway-Event-Id |
The same value as eventId in the body. |
The envelope#
Every event shares these fields. Type-specific fields sit beside them at the top level.
| Field | Meaning |
|---|---|
eventId |
Unique and stable across retries (ev_...). Use it to deduplicate. |
type |
One of the event types below. |
occurredAt |
When the gateway recorded the event, RFC 3339 UTC. |
accountId |
The account it concerns. |
simulated |
true for sandbox data. |
apiVersion |
v1. |
Event types#
transaction.created#
A transaction the gateway had not seen before. Sent for both credits and debits.
{
"eventId": "ev_01EXAMPLEEVENT0000000000001",
"type": "transaction.created",
"occurredAt": "2026-11-27T08:05:12Z",
"accountId": "acc_01EXAMPLEACCOUNT00000000AA",
"simulated": true,
"apiVersion": "v1",
"transaction": {
"id": "gt_01EXAMPLETRANSACTION00001",
"bookingDate": "2026-11-27",
"valueDate": "2026-11-27",
"amount": { "cents": 25000, "currency": "ZAR" },
"creditDebit": "CREDIT",
"remittanceUnstructured": "EXAMPLE REF 0001",
"futureDated": false,
"backfill": false,
"lateArrival": false
},
"backfill": false,
"lateArrival": false
}
transaction is the full transaction object, shortened here. Flags, repeated at the top level for convenience:
| Flag | Meaning | Suggested handling |
|---|---|---|
backfill |
Found during the first catch-up of an account's history, not new activity. | Apply idempotently. Consider holding user-facing notifications for older items. |
lateArrival |
Booked on a date the gateway had already fully read, so it appeared late. | Process normally; worth logging. |
futureDated (on transaction) |
valueDate is after today, so the money is not available yet. |
Record it, but act on it from valueDate. |
transaction.observed_changed#
A re-read of a transaction the gateway already holds returned something different, or a fully read window no longer returned it. The stored transaction is not changed; the difference is recorded.
{
"eventId": "ev_01EXAMPLEEVENT0000000000002",
"type": "transaction.observed_changed",
"occurredAt": "2026-11-28T06:00:41Z",
"accountId": "acc_01EXAMPLEACCOUNT00000000AA",
"simulated": true,
"apiVersion": "v1",
"transaction": { "id": "gt_01EXAMPLETRANSACTION00001" },
"observation": {
"kind": "field_changed",
"field": "availability",
"before": { "cents": 1025000, "creditDebit": "CREDIT" },
"after": { "cents": 1030000, "creditDebit": "CREDIT" },
"observedAt": "2026-11-28T06:00:41Z",
"pollId": "poll_EXAMPLE"
}
}
kind is field_changed or not_returned. The exact shape of before and after depends on the field; treat them as informational and review the transaction.
transaction.reversed_suspected#
A new DEBIT looks like it undoes an earlier CREDIT. This is a heuristic, because the bank's API has no reversal marker. It is a prompt for review, never an automatic change.
{
"eventId": "ev_01EXAMPLEEVENT0000000000003",
"type": "transaction.reversed_suspected",
"occurredAt": "2026-11-28T09:00:03Z",
"accountId": "acc_01EXAMPLEACCOUNT00000000AA",
"simulated": true,
"apiVersion": "v1",
"transaction": { "id": "gt_01EXAMPLETRANSACTION00002", "creditDebit": "DEBIT" },
"originalTransactionId": "gt_01EXAMPLETRANSACTION00001",
"originalTransaction": { "id": "gt_01EXAMPLETRANSACTION00001", "creditDebit": "CREDIT" },
"matchBasis": ["amount+reference"],
"confidence": "high",
"candidates": [
{ "transactionId": "gt_01EXAMPLETRANSACTION00001", "matchBasis": ["amount+reference"], "confidence": "high" }
]
}
originalTransactionId and originalTransaction are null when several candidates tie; then look at candidates[]. A transaction.created event for the same debit is sent as well.
sync.status#
The gateway's sync health for an account changed, for example it recovered, stalled, or the bank login expired.
{
"eventId": "ev_01EXAMPLEEVENT0000000000004",
"type": "sync.status",
"occurredAt": "2026-11-29T20:10:02Z",
"accountId": "acc_01EXAMPLEACCOUNT00000000AA",
"simulated": true,
"apiVersion": "v1",
"reason": "recovered",
"lastSuccessfulPollAt": "2026-11-29T20:10:02Z",
"sync": { "accountId": "acc_01EXAMPLEACCOUNT00000000AA", "state": "ok", "ok": true, "coveredThrough": "2026-11-29" }
}
reason is recovered, state_changed or catch_up_finished. sync has the same fields as in /v1/sync-status.
New event types may be added within v1. Return 2xx for types you do not handle.
Verifying the signature#
- Read the raw request body bytes before any JSON parsing. Re-encoding parsed JSON changes the bytes and breaks the signature.
- Build the message
<X-Gateway-Timestamp>+.+ raw body. - Compute HMAC-SHA256 with your shared secret for the
X-Gateway-Key-Idgiven, as lowercase hex. - Compare with the part after
v1=inX-Gateway-Signature, using a constant-time comparison. - Reject the request if the timestamp is more than 300 seconds from your clock. Each retry is signed afresh, so a genuine retry always has a recent timestamp.
If verification fails, return 401 and do not process the body.
Python#
import hashlib, hmac, time
def verify_fnb_gateway_webhook(secret: bytes, headers: dict, raw_body: bytes, tolerance: int = 300) -> bool:
"""True if the delivery is genuine and fresh. Use the raw request bytes, not re-encoded JSON."""
ts = headers.get("X-Gateway-Timestamp", "")
sig = headers.get("X-Gateway-Signature", "")
if not ts.isdigit() or not sig.startswith("v1="):
return False
if abs(time.time() - int(ts)) > tolerance:
return False
expected = hmac.new(secret, ts.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, sig[3:])
Node.js#
const crypto = require("node:crypto");
// rawBody must be the exact bytes received (a Buffer), not JSON.stringify of a parsed object.
function verifyFnbGatewayWebhook(secret, headers, rawBody, toleranceSec = 300) {
const ts = headers["x-gateway-timestamp"] || "";
const sig = headers["x-gateway-signature"] || "";
if (!/^\d+$/.test(ts) || !sig.startsWith("v1=")) return false;
if (Math.abs(Date.now() / 1000 - Number(ts)) > toleranceSec) return false;
const expected = crypto.createHmac("sha256", secret)
.update(ts + ".").update(rawBody).digest();
const given = Buffer.from(sig.slice(3), "hex");
return given.length === expected.length && crypto.timingSafeEqual(given, expected);
}
module.exports = { verifyFnbGatewayWebhook };
With Express, read the raw body using express.raw({ type: "application/json" }) on the webhook route.
Rust#
Uses the hmac, sha2 and hex crates.
use hmac::{Hmac, Mac};
use sha2::Sha256;
/// True if an FNB Gateway webhook is genuine and fresh. `raw_body` is the exact bytes received.
pub fn verify_fnb_gateway_webhook(
secret: &[u8],
timestamp: &str, // X-Gateway-Timestamp
signature: &str, // X-Gateway-Signature
raw_body: &[u8],
now_unix: i64,
tolerance_secs: i64,
) -> bool {
let Ok(ts) = timestamp.parse::<i64>() else { return false };
if (now_unix - ts).abs() > tolerance_secs {
return false;
}
let Some(Ok(given)) = signature.strip_prefix("v1=").map(hex::decode) else { return false };
let mut mac = Hmac::<Sha256>::new_from_slice(secret).expect("any key length");
mac.update(timestamp.as_bytes());
mac.update(b".");
mac.update(raw_body);
mac.verify_slice(&given).is_ok() // constant time
}
These three examples were tested against signatures produced the same way as the gateway does: a genuine body passes, a changed body or a stale timestamp fails.
Keys#
- The shared secret is never sent in chat, email or code. The receiving service reads its own copy from the gateway's secret store, with read access granted to that service's own role for that one secret.
- During a rotation, accept both the old and new secret, chosen by
X-Gateway-Key-Id, until the gateway confirms the switch.
Changelog#
- 2026-12-01: Addresses now have no trailing slash.
- 2026-11-30: Updated for release v0.1.3: live in sandbox at fnb.thought.bz, webhooks live for verified consumers.
- 2026-11-29: First version.
Updated 2026-12-01