<!-- Public page: https://payeast.app/developers/docs/#webhooks · version 2026-12-05 -->

# Webhooks

PayEast calls your server when something changes, so you do not have to poll. Register one HTTPS address per app. For a test app you set it in the developer sandbox; for a live app, ask PayEast to change it. The address must use a public domain name on port 443: no IP address, and no PayEast address.

## Events

| `type` | When | `data` |
|---|---|---|
| `payment.succeeded` | Payment completed and money moved, including a permitted merchant autopay | `{ "object": <payment> }` |
| `payment.declined` | The customer declined | `{ "object": <payment> }` |
| `payment.cancelled` | You cancelled it via the API | `{ "object": <payment> }` |
| `payment.expired` | Nobody approved before `approval_expires_at` | `{ "object": <payment> }` |
| `dispute.created` | A customer raised a dispute about a merchant payment | `{ "object": <dispute> }` |
| `dispute.updated` | A reply, a status change, a withdrawal or an outcome | `{ "object": <dispute> }` |
| `mandate.accepted` | A merchant app: the customer accepted charges from you (after `POST /v1/mandates`) | `{ "object": { "id": "mnd_…", "status": "active", "customer_number", "reason", "reference" } }` |
| `mandate.declined` | The customer declined | same object, status `declined` |
| `mandate.revoked` | The customer removed your app in Settings (open charges are cancelled) | same object, status `revoked` |

While an app is **suspended** nothing is delivered to it: events wait and keep their retries (1 min, 5 min, 30 min, 2 h, 6 h, 24 h), and are marked failed if the app is still not active after the last one. A webhook address that does not resolve to a public server follows the same retry ladder instead of being retried for ever.

The payment object describes the merchant charge. Verify its amount, currency and reference against your order.

## The request

`POST` to your address, `Content-Type: application/json`:

```
{
  "id": "5b3f2c1e-…",
  "object": "event",
  "type": "payment.succeeded",
  "created": 1790000000,
  "data": { "object": { "id": "pay_…", "kind": "charge", "status": "succeeded", "amount": 25000, "currency": "UGX",
                         "reference": "ord_1001", "transaction_id": "TXN-…", "payer_customer_number": "PE-…", "payee_customer_number": "PE-…" } }
}

```

Headers:

| Header |  |
|---|---|
| `PayEast-Signature` | `t=<unix seconds>,v1=<hex>` — see below |
| `PayEast-Event-Id` | The event `id`. The same on every retry. |
| `User-Agent` | `PayEast-Webhooks/1.0` |

## Verifying the signature

`v1` is the hex **HMAC-SHA256** of the string `"<t>.<raw request body>"` using your **webhook secret** (`whsec_…`, given to you with your credentials). Verify against the **raw bytes** you received, not a re-serialised object, compare in constant time, and reject timestamps more than 5 minutes old.

```
// Node / Express — use express.raw({ type: 'application/json' }) for this route
import crypto from 'node:crypto';

export function verifyPayEast(rawBody, header, secret, toleranceSeconds = 300) {
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
  const t = Number(parts.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false;
  const expected = crypto.createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex');
  const a = Buffer.from(expected), b = Buffer.from(parts.v1 || '');
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

```

```
# Python
import hmac, hashlib, time

def verify_payeast(raw_body: bytes, header: str, secret: str, tolerance=300) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    t = int(parts.get("t", "0"))
    if not t or abs(time.time() - t) > tolerance:
        return False
    expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))

```

## Responding and retries

* Answer **any 2xx within 10 seconds** to acknowledge. Do your real work after answering.
* Anything else (or a timeout) is retried after **1 min, 5 min, 30 min, 2 h, 6 h, 24 h**; after that the event is marked failed. Contact support if delivery remains unsuccessful.
* Delivery is **at least once** and not guaranteed to be in order. **De-duplicate on `PayEast-Event-Id`**, and make your handler idempotent: a second `payment.succeeded` for a payment you already marked paid must change nothing.
* Redirects are not followed. The address must be public `https` — private, loopback and local addresses are refused.

## Do not trust the webhook alone for money decisions

The signature proves the message came from PayEast. For a high-value order, you can also `GET /v1/charges/{id}` with your merchant credentials and check `status === "succeeded"` and that `amount`, `currency` and `reference` match what you expect before you deliver goods.

## Identifiers in the payload

The payment object in `data.object` carries three different IDs: `payeast_ref` (= `id`, PayEast's `pay_...` reference), `partner_reference` (= `reference`, **your** own transaction ID, returned unchanged) and `audit_id` (= `transaction_id`, the `TXN-...` entry in PayEast's books, for support and audit only, `null` until money moved). The envelope `id` / `PayEast-Event-Id` identifies the delivery. Contact support@payeast.app for integration-specific guidance.
