Developer tools
Webhooks
Get notified when a payment or payout changes, and check each delivery came from us.
We POST a signed event to a URL you own each time a charge, payout or refund
changes. Return 2xx quickly; we retry anything else.
Key requirements
- A key with
webhooks:manage, to register and manage endpoints. - An
httpsURL on a public address. Private, loopback and plainhttpURLs are refused. - One URL per endpoint. Your business can register a URL once, so give test
and live different URLs (
…/hooks/inversepay?mode=test, say).
How it works
- You register an endpoint and store the secret it returns.
- When something changes, we queue one delivery per event for each endpoint that wants it, and send it within about a minute.
- You verify the signature, return
2xx, and do the work afterwards. - Anything else is retried for about nine hours, then dead-lettered for you to replay.
A test key's endpoints receive test events only, and a live key's live events only.
Step 1 — Register an endpoint
curl -X POST https://api.inversepay.app/api/b/v1/webhooks \
-H "Authorization: Bearer $INVERSEPAY_TEST_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/hooks/inversepay?mode=test",
"description": "Sandbox receiver",
"event_types": ["charge.succeeded", "charge.failed", "payout.completed", "payout.failed"]
}'{
"endpoint": {
"id": "5b0e…",
"url": "https://example.com/hooks/inversepay?mode=test",
"description": "Sandbox receiver",
"event_types": ["charge.succeeded", "charge.failed", "payout.completed", "payout.failed"],
"is_active": true,
"failure_streak": 0,
"last_delivered_at": null,
"created_at": "2026-11-25T09:00:00Z"
},
"secret": "q3V9…",
"signature_header": "X-InversePay-Signature",
"verification_hint": "Sign the raw request body, not a re-serialised copy: two JSON documents can mean the same thing and differ byte for byte."
}The secret is shown once. Store it now; nothing can read it back.
Leave event_types out to receive every event. An unknown value is accepted
and never matches, so check the spelling against the list
below if an endpoint stays quiet.
Step 2 — Verify each delivery
POST /hooks/inversepay?mode=test HTTP/1.1
Content-Type: application/json
X-InversePay-Signature: t=1764061200,v1=<hex>
X-InversePay-Event: charge.succeeded
X-InversePay-Delivery: 8f14e45f-ceea-467a-9c4b-1f0bd4f1a2c3The signature is HMAC-SHA256, keyed with your secret, over the timestamp, a
., and the raw body: f"{t}.".encode() + body.
import hashlib
import hmac
import time
TOLERANCE_SECONDS = 300
def verify(header: str, body: bytes, secrets: list[str]) -> bool:
"""`body` must be the raw bytes of the request, not a re-serialised object."""
parts = [piece.split("=", 1) for piece in header.split(",") if "=" in piece]
timestamps = [value for key, value in parts if key == "t"]
if not timestamps:
return False
timestamp = int(timestamps[0])
# Reject anything too old, or a captured delivery can be replayed forever.
if abs(time.time() - timestamp) > TOLERANCE_SECONDS:
return False
# A header may carry MORE THAN ONE v1 (see rotation below). Check them all.
signatures = [value for key, value in parts if key == "v1"]
signed = f"{timestamp}.".encode() + body
for secret in secrets:
expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
for candidate in signatures:
# Constant time: a compare that returns early leaks the answer.
if hmac.compare_digest(expected, candidate):
return True
return FalseFour rules:
- Sign the raw body. A re-serialised body differs byte for byte. In
Express use
express.raw({ type: 'application/json' }); in FastAPI,await request.body()before anything parses it. - Check the timestamp. It is inside the signed material. Reject anything older than five minutes.
- Accept any matching
v1=. During a secret rotation the header carries two, one per secret. A verifier that reads only the first rejects about half of all deliveries for the whole overlap. - Compare in constant time:
hmac.compare_digest, not==.
Step 3 — Return 2xx, then do the work
Only a 2xx counts as delivered, and an attempt that has not answered within 10 seconds has failed. A redirect is not followed
and counts as a failure. Do the slow work after you answer: a handler that
times out is retried, and you receive the same delivery again.
Events
Every body has the same envelope:
| Field | |
|---|---|
id | The delivery's id, the same as X-InversePay-Delivery. It does not change between retries. |
type | The event type, as in X-InversePay-Event. |
created_at | When the event was queued. |
data | What changed. Depends on the type, below. |
Charges
data is the charge as it is now, the object GET /charges/{id} returns,
plus your metadata and the payer's phone_number, network and
country_code. Beside it, event is what the event recorded when it happened:
event.id, event.created_at and event.payload.
| Event | When | event.payload, besides charge_id, reference and status |
|---|---|---|
charge.created | A charge exists. | — |
charge.succeeded | The payer paid. | amount_minor, fee_minor, net_minor, currency, reconciled_late |
charge.failed | It did not happen. | reason |
charge.partially_refunded | The first refund that leaves part of it. | refunded_minor, amount_minor |
charge.refunded | Refunded in full. | refunded_minor, amount_minor |
There is no event for pending, and none for a dispute: disputes are not
reported by webhook. Until the next API release the reference's event_types
list still names charge.disputed; it is never sent, so do not wait on it. A
full body is in Mobile money collections.
Payouts
data is what the event recorded: payout_id, reference, status (when it
happened), transaction_type, and the fields below. actor says who caused
it: kind is member, api_key or system, and id is the member's or the
key's id.
| Event | When | Also in data |
|---|---|---|
payout.created | Raised, and the money reserved. | conversion, on a payout that converts currency |
payout.parked | Held for a compliance review. | reason |
payout.released | A review cleared it. It rejoins its normal path. | — |
payout.approved | An approver signed it. | — |
payout.processing | Handed to the network or the bank. | — |
payout.completed | Paid. | amount_minor, currency |
payout.failed | Failed. The money is back in your balance. | reason, amount_minor, currency, funds_released |
payout.returned | After payout.failed: the network or bank confirmed the money came back. | — |
payout.rerouted | Sent another way after the first could not take it. Slower, not broken. | reason |
payout.reconciling | We do not yet know whether the money moved. Not a failure: treat it as unknown. | reason |
data also carries rail, and a reroute from_rail and to_rail. They are
for our support team: never branch on them.
Refunds
Refunds are issued in the dashboard. data carries refund_id, charge_id,
amount_minor, send_fee_minor, total_minor, currency, method,
payout_id and status.
| Event | When | Also in data |
|---|---|---|
refund.created | A refund was issued. | — |
refund.requires_approval | It waits for an approver. | — |
refund.succeeded | The money reached the payer. | — |
refund.failed | It did not. | reason |
Subscribe to them by name in event_types, or list no event_types to get
every event. The reference's event_types list names them from the next API
release; they are delivered either way.
Checkout sessions
data is the session as it is now, the object
GET /checkout/sessions/{id} returns, with the charge it created under
data.charge (or null). event.payload carries session_id, reference,
status and charge_id.
| Event | When | Also in event.payload |
|---|---|---|
checkout.session.completed | The customer paid. | — |
checkout.session.failed | The payment failed. It can still be followed by completed if the network confirms late. | reason |
checkout.session.expired | Nobody started paying before expires_at, or you expired the session. | — |
A full body is in Checkout.
Exports
| Event | When | data |
|---|---|---|
export.ready | A report you asked for in the dashboard is ready to download. Live endpoints only. | export_id, kind, format, row_count, byte_size, filename, expires_at, params |
Retries
We send what is due once a minute (test events about five seconds after they
happen). Each delivery gets 8 attempts. After a failed attempt the next waits
30s × 3ⁿ⁻¹, capped at six hours, with jitter: somewhere between half and all
of that interval.
| After attempt | Next attempt in |
|---|---|
| 1 | 15–30 seconds |
| 2 | 45 seconds – 1.5 minutes |
| 3 | 2¼–4½ minutes |
| 4 | 6¾–13½ minutes |
| 5 | 20–40 minutes |
| 6 | 1–2 hours |
| 7 | 3–6 hours |
| 8 | Dead-lettered |
Allow up to a minute more on each, for the sweep. Each attempt times out after 10 seconds (5 to connect). After the eighth failure, roughly 4½ to 9 hours after the first, the delivery is abandoned and moves to the dead-letter queue:
curl https://api.inversepay.app/api/b/v1/webhooks/deliveries/dead-letter \
-H "Authorization: Bearer $INVERSEPAY_TEST_KEY"An endpoint that fails 20 attempts in a row is disabled. While it is
disabled, new events are not queued for it, and they are not sent later. Fix
it, then POST /webhooks/{id}/enable, which resets the count.
GET /webhooks/deliveries lists every delivery with status (pending,
delivered, failed or abandoned), attempts, attempt_ceiling,
response_status and error.
Replaying a delivery
curl -X POST https://api.inversepay.app/api/b/v1/webhooks/deliveries/$DELIVERY_ID/replay \
-H "Authorization: Bearer $INVERSEPAY_TEST_KEY"Only an abandoned delivery can be replayed, and only to an enabled endpoint.
It is sent at the next sweep with 8 more attempts. attempts keeps counting
and attempt_ceiling grows, so the record still shows every try.
Ordering and duplicates
- Each event type fires at most once per charge, payout and refund. A
charge has at most one
charge.failedand onecharge.succeeded, so a late success arrives ascharge.failedthencharge.succeededwithreconciled_late: true. Let the later one win. - Each event is queued once per endpoint, as one delivery with one
id. - The same delivery can still arrive twice: a retry after a timeout you
had in fact handled, or a send we could not record. Handle duplicates by
id. - Order is not guaranteed. A retried delivery can arrive after a later
event. For a charge, read
data.status, which is the charge now; for a payout,GET /payouts/{id}when the order matters.
Rotating a secret
curl -X POST "https://api.inversepay.app/api/b/v1/webhooks/$ENDPOINT_ID/rotate-secret?overlap_hours=24" \
-H "Authorization: Bearer $INVERSEPAY_TEST_KEY"The response carries the new secret, once. For overlap_hours (24 by default,
0 to 168) the old secret keeps signing too, so every delivery carries two
v1=. Deploy the new secret, then let the window close. Pass 0 to retire the
old secret at once, if it leaked. Rotating again inside the window retires the
older secret immediately.
Errors
| Status | code | |
|---|---|---|
400 | INVALID_ENDPOINT | Not https, not a public address, or a URL your business already uses. |
404 | ENDPOINT_NOT_FOUND | No such endpoint, or it belongs to the other mode. |
404 | DELIVERY_NOT_FOUND | No such delivery. |
409 | NOT_REPLAYABLE | The delivery is not abandoned, or its endpoint is disabled. |
403 | INSUFFICIENT_AUTHORITY | The key lacks webhooks:manage. |
All codes are on Errors.
Testing
Register an endpoint with a sk_test_ key, then create a test charge: you
receive charge.created and charge.succeeded within seconds. A tunnel such
as ngrok gives a local server a public https URL. To see a failed delivery,
return 500 and watch GET /webhooks/deliveries.
Developer notes
- The body is compact JSON with sorted keys. Verify the bytes you received; never re-serialise them.
data.statusandevent.payload.statuscan differ on a charge: the first is the charge now, the second what it was when the event happened.- Disabling is yours to undo.
POST /webhooks/{id}/disableand/enableturn an endpoint off and on.