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 https URL on a public address. Private, loopback and plain http URLs 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

  1. You register an endpoint and store the secret it returns.
  2. When something changes, we queue one delivery per event for each endpoint that wants it, and send it within about a minute.
  3. You verify the signature, return 2xx, and do the work afterwards.
  4. 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"]
  }'
201 Created
{
  "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-1f0bd4f1a2c3

The 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 False

Four rules:

  1. 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.
  2. Check the timestamp. It is inside the signed material. Reject anything older than five minutes.
  3. 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.
  4. 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
idThe delivery's id, the same as X-InversePay-Delivery. It does not change between retries.
typeThe event type, as in X-InversePay-Event.
created_atWhen the event was queued.
dataWhat 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.

EventWhenevent.payload, besides charge_id, reference and status
charge.createdA charge exists.—
charge.succeededThe payer paid.amount_minor, fee_minor, net_minor, currency, reconciled_late
charge.failedIt did not happen.reason
charge.partially_refundedThe first refund that leaves part of it.refunded_minor, amount_minor
charge.refundedRefunded 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.

EventWhenAlso in data
payout.createdRaised, and the money reserved.conversion, on a payout that converts currency
payout.parkedHeld for a compliance review.reason
payout.releasedA review cleared it. It rejoins its normal path.—
payout.approvedAn approver signed it.—
payout.processingHanded to the network or the bank.—
payout.completedPaid.amount_minor, currency
payout.failedFailed. The money is back in your balance.reason, amount_minor, currency, funds_released
payout.returnedAfter payout.failed: the network or bank confirmed the money came back.—
payout.reroutedSent another way after the first could not take it. Slower, not broken.reason
payout.reconcilingWe 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.

EventWhenAlso in data
refund.createdA refund was issued.—
refund.requires_approvalIt waits for an approver.—
refund.succeededThe money reached the payer.—
refund.failedIt 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.

EventWhenAlso in event.payload
checkout.session.completedThe customer paid.—
checkout.session.failedThe payment failed. It can still be followed by completed if the network confirms late.reason
checkout.session.expiredNobody started paying before expires_at, or you expired the session.—

A full body is in Checkout.

Exports

EventWhendata
export.readyA 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 attemptNext attempt in
115–30 seconds
245 seconds – 1.5 minutes
32¼–4½ minutes
46¾–13½ minutes
520–40 minutes
61–2 hours
73–6 hours
8Dead-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.failed and one charge.succeeded, so a late success arrives as charge.failed then charge.succeeded with reconciled_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

Statuscode
400INVALID_ENDPOINTNot https, not a public address, or a URL your business already uses.
404ENDPOINT_NOT_FOUNDNo such endpoint, or it belongs to the other mode.
404DELIVERY_NOT_FOUNDNo such delivery.
409NOT_REPLAYABLEThe delivery is not abandoned, or its endpoint is disabled.
403INSUFFICIENT_AUTHORITYThe 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.status and event.payload.status can 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}/disable and /enable turn an endpoint off and on.

What's next

On this page