Skip to main content

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.

Don't rely on the redirect

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​

EventSent when
PaymentCapturedA payment is paid.
PaymentFailedA payment fails for good.
PaymentRefundedA refund is completed.
SettlementPaidA payout reaches your bank account.
SettlementReturnedYour bank sent a payout back.
TestEventYou 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​

  1. Add a route on your server that accepts POST, such as https://shop.example.com/webhooks/billpay. It must use https.
  2. Register the URL in the portal under Developers → Webhooks, or with the API.
  3. Save the signing secret. It starts with whsec_ and is shown only once. Store the whole value, prefix included, on your server as BILLPAY_WEBHOOK_SECRET.
  4. 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.

Testing on your own computer

BillPay can't reach localhost. Use a tunnel such as ngrok or Cloudflare Tunnel to get a public https URL that forwards to your machine. To just look at what BillPay sends, a request inspector like Beeceptor works too, but use it only in the sandbox.

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
HeaderValue
x-billpay-signaturet=<unix seconds>,v1=<signature>. See Verify the signature.
x-billpay-eventThe event type, the same as eventType in the body.
x-billpay-event-idThe event ID, the same as eventId in the body.
content-typeapplication/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"
}
}
eventIdstring
A unique ID for the event. Use it to skip events you've already handled.
eventTypestring
The event, such as PaymentCaptured.
occurredAtstring
When the event happened, in UTC.
dataobject
The event details. The fields depend on the event.
Amounts are numbers here

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.

PaymentCaptured data
paymentIdstring
BillPay's payment ID.
merchantIdstring
Your merchant account ID.
merchantReferencestring
Your order ID.
amountnumber
The amount you asked for.
chargedAmountnumber
What the customer paid.
feenumber
BillPay's fee.
vatnumber
VAT on the fee.
netAmountnumber
What was credited to your balance.
currencystring
ETB
providerstring
The provider used. SANDBOX_WALLET for the sandbox test wallet.
instrumentstring
The instrument used. TEST_WALLET for the sandbox test wallet.
capturedAtstring
When the payment was captured.
attemptStartedAtstring
When the customer started the successful try.
Fields in data for other events
PaymentFailed
paymentIdstring
BillPay's payment ID.
merchantIdstring
Your merchant account ID.
merchantReferencestring
Your order ID.
amountnumber
The amount you asked for.
currencystring
ETB
providerstring
The provider of the last try, for example SANDBOX_WALLET.
instrumentstring
The instrument of the last try, for example TEST_WALLET.
failureCodestring
Why it failed, for example CUSTOMER_DECLINED.
reasonstring
A readable explanation, such as "The customer declined the payment".
failedAtstring
When the payment failed.
attemptStartedAtstring
When the customer started the last try.
PaymentRefunded
refundIdstring
BillPay's refund ID.
paymentIdstring
The refunded payment.
merchantReferencestring
Your order ID.
amount
The amount of this refund.
feeReturned
The fee returned to you.
vatReturned
The VAT returned to you.
paymentRefundedTotal
Everything refunded on this payment so far.
currencystring
ETB
refundedAtstring
When the refund completed.
SettlementPaid
settlementIdstring
BillPay's settlement ID.
gross
Captured payments in this payout.
refunded
Refunds taken out.
holdback
Amount held back.
fee
Fees.
vat
VAT on fees.
netPayable
What was paid to you.
currencystring
ETB
itemCountinteger
Number of payments included.
payoutRailstring
How the payout was sent.
accountNumberMaskedstring
The receiving account, masked.
paidAtstring
When it was paid.
SettlementReturned
settlementIdstring
BillPay's settlement ID.
netPayable
The amount sent back.
currencystring
ETB
payoutAccountIdstring
The payout account.
failureCodestring
Why it came back, for example ACCOUNT_CLOSED.
reasonstring
A readable explanation.
returnedAtstring
When it came back.
TestEvent
messagestring
A note saying this is a test. No payment is affected.

Handle events​

Your endpoint should do four things, in this order:

  1. Check the signature on the raw body, before parsing the JSON. See Verify the signature.
  2. Skip events you've already handled. The same event can arrive more than once, so store each eventId you process.
  3. Update the order. Use data.merchantReference or data.paymentId to find it.
  4. Answer 2xx quickly. BillPay waits 10 seconds. Send emails or SMS in the background, after you've answered.
Node.js
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
PartMeaning
tWhen BillPay signed the request, in Unix seconds.
v1The signature, made with your endpoint's signing secret.

Two checks belong in your code, whatever the signing method:

  • Reject old requests. If t is 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.

billpay-signature.js
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);
}

Test your endpoint​

Send a TestEvent to check your endpoint without making a payment.

POST/api/v1/checkout/webhooks/{webhookId}/test
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​

GET/api/v1/checkout/webhooks/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"
}
Each delivery
idstring
The delivery ID.
webhookIdstring
The endpoint it was sent to.
eventTypestring
The event, such as PaymentCaptured.
statusstring
DELIVERED when your server answered 2xx. PENDING while BillPay is still retrying. EXHAUSTED when every attempt failed.
attemptsinteger
How many times BillPay has tried.
lastStatusCodeinteger
The HTTP status your server last answered with.
lastErrorstring
What went wrong on the last attempt, such as The endpoint answered 404. null if it worked.
nextAttemptAtstring
When BillPay will try again. null when there's nothing left to retry.
createdAtstring
When the event was queued.
deliveredAtstring
When your server accepted it.

The response includes total, page and size, like other lists.

DELIVERED means your server answered, not that it worked

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:

GET/api/v1/checkout/webhooks/deliveries/{deliveryId}

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.

Each try
attemptNointeger
The attempt number, starting at 1.
statusCodeinteger
The HTTP status your server answered with.
errorstring
What went wrong, such as a timeout. null if it worked.
latencyMsinteger
How long your server took to answer, in milliseconds.
attemptedAtstring
When BillPay made the attempt.

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​

POST/api/v1/checkout/webhooks
Body
urlstringRequired
Your endpoint. https only, up to 2,048 characters.
eventsstring[]
The events to send. Leave it out to receive every event.
descriptionstring
A note for yourself, such as "Shop backend".
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​

MethodPathWhat it does
GET/api/v1/checkout/webhooksList 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-secretGet a new signing secret.
POST/api/v1/checkout/webhooks/{webhookId}/testSend a TestEvent.
GET/api/v1/checkout/webhooks/deliveriesThe 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.

POST/api/v1/checkout/webhooks/{webhookId}/rotate-secret
{
"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.