Webhooks
When something happens to a payment, BillPay sends a POST request to a URL
on your server. This is how you learn a payment's result. It works even if the
customer closes their browser and never returns to your site.
A customer landing on your returnUrl doesn't prove they paid. Mark an order
as paid only after a verified PaymentCaptured webhook, or a
status check that returns CAPTURED.
Events
| Event | Sent when |
|---|---|
PaymentCaptured | A payment is paid. |
PaymentFailed | A payment fails for good. |
PaymentRefunded | A refund is completed. |
SettlementPaid | A payout reaches your bank account. |
SettlementReturned | Your bank sent a payout back. |
TestEvent | You sent a test from the portal or the API. |
Cancelled and expired payments don't send a webhook yet. See Payment Statuses.
Set up an endpoint
- Add a route on your server that accepts
POST, such ashttps://shop.example.com/webhooks/billpay. It must usehttps. - Register the URL in the portal under Developers → Webhooks, or with the API.
- Save the signing secret. It starts with
whsec_and is shown only once. Store the whole value, prefix included, on your server asBILLPAY_WEBHOOK_SECRET. - Send a test event and confirm it in the delivery log.
Each endpoint has its own secret. Sandbox and production are separate, so register your endpoint in each one.
What BillPay sends
A webhook isn't instant. In the sandbox, deliveries arrive about 20 seconds after the event. Your return page should be ready to wait for it. See Handle the return.
If you have more than one endpoint, each one receives its own copy of every event.
Headers
POST /webhooks/billpay HTTP/1.1
content-type: application/json
x-billpay-event: PaymentCaptured
x-billpay-event-id: 39267d3d-5fc7-4d42-ac1d-28b92d8df414
x-billpay-signature: t=1793546671,v1=a1195d9c4c97452f15b7fbf76a5bd6d29d7a62a123a46caff6f91476b6fdb469
| Header | Value |
|---|---|
x-billpay-signature | t=<unix seconds>,v1=<signature>. See Verify the signature. |
x-billpay-event | The event type, the same as eventType in the body. |
x-billpay-event-id | The event ID, the same as eventId in the body. |
content-type | application/json |
Body
Every event has the same four top-level fields. The details are in data.
This is a PaymentCaptured event from a sandbox payment:
{
"eventId": "39267d3d-5fc7-4d42-ac1d-28b92d8df414",
"eventType": "PaymentCaptured",
"occurredAt": "2026-11-01T15:24:15.028546546Z",
"data": {
"paymentId": "39267d3d-5fc7-4d42-ac1d-28b92d8df414",
"merchantId": "7d3e9b14-2c5a-4f8e-b6d1-0a9c4e2f7b35",
"merchantReference": "order-10231",
"amount": 1000.0000,
"chargedAmount": 1000.0000,
"fee": 0.0000,
"vat": 0.0000,
"netAmount": 1000.0000,
"currency": "ETB",
"provider": "SANDBOX_WALLET",
"instrument": "TEST_WALLET",
"capturedAt": "2026-11-01T15:24:15.007523085Z",
"attemptStartedAt": "2026-11-01T15:21:37.728087Z"
}
}
PaymentCaptured.In webhook data, amounts are plain numbers, such as "amount": 1000.0000,
with the currency in its own currency field. In API responses, amounts are
objects, such as {"amount": 1000.0000, "currency": "ETB"}.
Use data.paymentId to find the payment. Don't rely on eventId being the
same as the payment ID.
ETBSANDBOX_WALLET for the sandbox test wallet.TEST_WALLET for the sandbox test wallet.Fields in data for other events
ETBSANDBOX_WALLET.TEST_WALLET.CUSTOMER_DECLINED.ETBETBETBACCOUNT_CLOSED.Handle events
Your endpoint should do four things, in this order:
- Check the signature on the raw body, before parsing the JSON. See Verify the signature.
- Skip events you've already handled. The same event can arrive more than once, so store each
eventIdyou process. - Update the order. Use
data.merchantReferenceordata.paymentIdto find it. - Answer
2xxquickly. BillPay waits 10 seconds. Send emails or SMS in the background, after you've answered.
import express from 'express';
import {verifySignature} from './billpay-signature.js'; // see "Verify the signature"
const app = express();
// express.raw keeps the body as bytes, which the signature check needs.
// Register this route before any app.use(express.json()).
app.post('/webhooks/billpay', express.raw({type: 'application/json'}), async (req, res) => {
if (!verifySignature(req.body, req.get('x-billpay-signature'))) {
return res.status(400).send('Invalid signature');
}
const event = JSON.parse(req.body);
try {
if (!(await db.webhookEvents.exists(event.eventId))) {
await handleEvent(event);
await db.webhookEvents.save(event.eventId);
}
res.sendStatus(200);
} catch (err) {
console.error(err);
res.sendStatus(500); // not 2xx, so BillPay will try again
}
});
async function handleEvent(event) {
const {data} = event;
switch (event.eventType) {
case 'PaymentCaptured':
await db.orders.markPaid(data.merchantReference, data.paymentId);
break;
case 'PaymentFailed':
await db.orders.markFailed(data.merchantReference, data.reason);
break;
// TestEvent and events you don't use: change nothing, but still answer 200
}
}
Verify the signature
Anyone can send a request to your webhook URL. The x-billpay-signature
header proves it came from BillPay. It has two parts:
x-billpay-signature: t=1793546671,v1=a1195d9c4c97452f15b7fbf76a5bd6d29d7a62a123a46caff6f91476b6fdb469
| Part | Meaning |
|---|---|
t | When BillPay signed the request, in Unix seconds. |
v1 | The signature, made with your endpoint's signing secret. |
Two checks belong in your code, whatever the signing method:
- Reject old requests. If
tis far from the current time, someone may be replaying a captured request. - Compare signatures in constant time, so attackers can't guess the signature byte by byte.
v1 is an HMAC-SHA256, in lowercase hex, of t, a dot, and the raw body.
The key is your endpoint's signing secret exactly as BillPay gave it,
including the whsec_ prefix. Reject the request if t is more than
5 minutes from the current time.
- Node.js
- Python
- PHP
import crypto from 'node:crypto';
const SECRET = process.env.BILLPAY_WEBHOOK_SECRET;
const TOLERANCE_SECONDS = 5 * 60;
export function verifySignature(rawBody, header) {
if (!header) return false;
const parts = Object.fromEntries(
header.split(',').map((part) => part.trim().split('=')),
);
if (!parts.t || !parts.v1) return false;
const age = Math.abs(Date.now() / 1000 - Number(parts.t));
if (!(age <= TOLERANCE_SECONDS)) return false;
const expected = crypto
.createHmac('sha256', SECRET)
.update(`${parts.t}.`)
.update(rawBody)
.digest();
const received = Buffer.from(parts.v1, 'hex');
return received.length === expected.length &&
crypto.timingSafeEqual(received, expected);
}
import hashlib
import hmac
import os
import time
SECRET = os.environ["BILLPAY_WEBHOOK_SECRET"].encode()
TOLERANCE_SECONDS = 5 * 60
def verify_signature(raw_body: bytes, header: str) -> bool:
try:
parts = dict(part.strip().split("=", 1) for part in header.split(","))
timestamp, received = parts["t"], parts["v1"]
if abs(time.time() - int(timestamp)) > TOLERANCE_SECONDS:
return False
except (ValueError, KeyError):
return False
expected = hmac.new(
SECRET, timestamp.encode() + b"." + raw_body, hashlib.sha256
).hexdigest()
return hmac.compare_digest(expected, received)
<?php
function verifySignature(string $rawBody, string $header, string $secret): bool
{
$parts = [];
foreach (explode(',', $header) as $part) {
[$key, $value] = array_pad(explode('=', trim($part), 2), 2, '');
$parts[$key] = $value;
}
$timestamp = $parts['t'] ?? '';
$received = $parts['v1'] ?? '';
if (!ctype_digit($timestamp) || abs(time() - (int) $timestamp) > 300) {
return false;
}
$expected = hash_hmac('sha256', $timestamp . '.' . $rawBody, $secret);
return hash_equals($expected, $received);
}
Test your endpoint
Send a TestEvent to check your endpoint without making a payment.
curl -X POST https://sandbox.api.billpay.et/api/v1/checkout/webhooks/{webhookId}/test \
-H "x-api-key: $BILLPAY_API_KEY"
{
"statusCode": 202,
"message": "Test delivery queued",
"body": {
"eventId": "1aba9526-bfb9-417a-afda-8b9136b01fbb"
},
"timestamp": "2026-11-01T14:05:12.291+00:00"
}
202 means the test is queued, not delivered yet. Your server receives a
signed TestEvent like the example above a few seconds later.
Confirm it arrived in the delivery log.
Your handler should answer 200 to a TestEvent without changing any order.
You can also send a test from the portal: Developers → Webhooks → Send test.
Check deliveries
The delivery log shows every webhook BillPay sent to your endpoints, newest first, and what your server answered. Check it first when you think a webhook is missing.
curl https://sandbox.api.billpay.et/api/v1/checkout/webhooks/deliveries \
-H "x-api-key: $BILLPAY_API_KEY"
{
"statusCode": 200,
"message": "Deliveries fetched successfully",
"body": {
"total": 1,
"page": 0,
"size": 20,
"items": [
{
"id": "18d4716d-2176-45ca-892f-e9d63e309896",
"webhookId": "4a17a76e-162c-4a17-a867-e62291b5ab27",
"eventType": "PaymentCaptured",
"status": "DELIVERED",
"attempts": 1,
"lastStatusCode": 200,
"lastError": null,
"nextAttemptAt": null,
"createdAt": "2026-10-31T17:27:15.030585Z",
"deliveredAt": "2026-10-31T17:27:32.629600Z",
"tries": []
}
]
},
"timestamp": "2026-11-01T13:51:15.483+00:00"
}
PaymentCaptured.DELIVERED when your server answered 2xx. PENDING while BillPay is still retrying. EXHAUSTED when every attempt failed.The endpoint answered 404. null if it worked.null when there's nothing left to retry.The response includes total, page and size, like other lists.
DELIVERED only means your server answered with a 2xx. If an order didn't
update, the problem is in your handler. Check your server logs for that
eventId.
If you have more than one endpoint, the same event appears once per endpoint,
each with its own delivery id.
To see one delivery:
A single delivery also includes tries, one entry for each attempt. Use it
to see exactly when BillPay called your server and what it got back.
1.null if it worked.Retries
If your server doesn't answer with a 2xx, BillPay tries again, up to
8 attempts in total, waiting longer before each one. Retries can go on
for many hours. nextAttemptAt in the delivery log shows when the next
attempt is due.
BillPay waits 3 seconds to connect and 10 seconds for an answer. It doesn't
follow redirects, so register the final URL. Production only calls public
https addresses.
After the last attempt, the delivery is marked EXHAUSTED. If you missed
events, use the change feed to catch
up, or contact support to replay them.
Manage endpoints with the API
You can do everything from the portal. If you'd rather automate it, use these endpoints.
Register an endpoint
https only, up to 2,048 characters.curl https://sandbox.api.billpay.et/api/v1/checkout/webhooks \
-H "x-api-key: $BILLPAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://shop.example.com/webhooks/billpay",
"description": "Shop backend"
}'
{
"statusCode": 201,
"message": "Webhook registered successfully",
"body": {
"id": "1556a00e-165c-4198-a43b-b66d59eef8b8",
"url": "https://shop.example.com/webhooks/billpay",
"events": [],
"active": true,
"description": "Shop backend",
"secret": "whsec_<your signing secret>",
"createdAt": "2026-11-01T14:02:17.540812323Z",
"updatedAt": "2026-11-01T14:02:17.540812323Z"
},
"timestamp": "2026-11-01T14:02:17.548+00:00"
}
Save secret now. It's never shown again. Save the id too, because you
need it to send a test, change the endpoint, or rotate the secret.
An empty events list means the endpoint receives every event.
Other endpoints
| Method | Path | What it does |
|---|---|---|
GET | /api/v1/checkout/webhooks | List your endpoints and their current settings. |
PATCH | /api/v1/checkout/webhooks/{webhookId} | Change the events, or switch the endpoint off with active. |
POST | /api/v1/checkout/webhooks/{webhookId}/rotate-secret | Get a new signing secret. |
POST | /api/v1/checkout/webhooks/{webhookId}/test | Send a TestEvent. |
GET | /api/v1/checkout/webhooks/deliveries | The delivery log. |
GET | /api/v1/checkout/webhooks/deliveries/{deliveryId} | One delivery. |
There's no endpoint for reading a single webhook. To check an endpoint's
current settings, list your endpoints and find it by id.
The list doesn't include signing secrets. A secret is shown only when you register an endpoint or rotate its secret.
Endpoints can't be deleted. To stop deliveries, switch the endpoint off with
PATCH and {"active": false}.
Rotate the signing secret
Rotate the secret if it may have leaked, for example if it ended up in a log or a screenshot.
{
"statusCode": 200,
"message": "Webhook secret rotated successfully",
"body": {
"id": "1556a00e-165c-4198-a43b-b66d59eef8b8",
"url": "https://shop.example.com/webhooks/billpay",
"events": [],
"active": true,
"description": "Shop backend",
"secret": "<your new signing secret>",
"createdAt": "2026-11-01T14:02:17.540812Z",
"updatedAt": "2026-11-01T15:39:37.210893122Z"
},
"timestamp": "2026-11-01T15:39:37.215+00:00"
}
The new secret is shown only in this response. Update
BILLPAY_WEBHOOK_SECRET on your server right away, and treat the old secret
as no longer valid.