Accept a Payment
Your server creates a payment, and your customer pays on BillPay's hosted checkout page. You never handle wallet, bank, or card details.
- Create the payment from your server.
- Redirect the customer to the
checkoutUrlin the response. - Handle the return when the customer comes back to your site.
- Confirm the result with a webhook, not the redirect.
1. Create the payment
Headers
application/jsonBody
409.0.01, with up to 4 decimal places.ETB is the only currency today.+. For example, +251911234567.https, up to 2,048 characters.https.Example
- cURL
- Node.js
- Python
- PHP
curl https://sandbox.api.billpay.et/api/v1/checkout/payments \
-H "x-api-key: $BILLPAY_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-10231" \
-d '{
"merchantReference": "order-10231",
"amount": 1000.00,
"currency": "ETB",
"description": "Invoice 10231",
"customer": {
"name": "Abebe Kebede",
"phone": "+251911234567"
"email": "abebe@example.com"
},
"returnUrl": "https://shop.example.com/orders/10231",
"cancelUrl": "https://shop.example.com/cart"
}'
const res = await fetch(`${process.env.BILLPAY_BASE_URL}/api/v1/checkout/payments`, {
method: 'POST',
headers: {
'x-api-key': process.env.BILLPAY_API_KEY,
'Content-Type': 'application/json',
'Idempotency-Key': order.id,
},
body: JSON.stringify({
merchantReference: order.id,
amount: order.total,
description: `Order ${order.id}`,
customer: {name: order.customerName, phone: order.customerPhone},
returnUrl: `https://shop.example.com/orders/${order.id}`,
cancelUrl: 'https://shop.example.com/cart',
}),
});
const result = await res.json();
if (!res.ok) {
throw new Error(`BillPay ${result.statusCode}: ${result.message}`);
}
const payment = result.body;
// checkoutUrl is only returned now, so save it with the order
await db.orders.update(order.id, {
paymentId: payment.id,
checkoutUrl: payment.checkoutUrl,
});
import os
import requests
res = requests.post(
f"{os.environ['BILLPAY_BASE_URL']}/api/v1/checkout/payments",
headers={
"x-api-key": os.environ["BILLPAY_API_KEY"],
"Idempotency-Key": order.id,
},
json={
"merchantReference": order.id,
"amount": float(order.total),
"description": f"Order {order.id}",
"customer": {"name": order.customer_name, "phone": order.customer_phone},
"returnUrl": f"https://shop.example.com/orders/{order.id}",
"cancelUrl": "https://shop.example.com/cart",
},
timeout=15,
)
result = res.json()
if not res.ok:
raise Exception(f"BillPay {result['statusCode']}: {result['message']}")
payment = result["body"]
# checkoutUrl is only returned now, so save it with the order
order.payment_id = payment["id"]
order.checkout_url = payment["checkoutUrl"]
order.save()
<?php
$ch = curl_init(getenv('BILLPAY_BASE_URL') . '/api/v1/checkout/payments');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'x-api-key: ' . getenv('BILLPAY_API_KEY'),
'Content-Type: application/json',
'Idempotency-Key: ' . $order['id'],
],
CURLOPT_POSTFIELDS => json_encode([
'merchantReference' => $order['id'],
'amount' => $order['total'],
'description' => 'Order ' . $order['id'],
'customer' => [
'name' => $order['customer_name'],
'phone' => $order['customer_phone'],
],
'returnUrl' => 'https://shop.example.com/orders/' . $order['id'],
'cancelUrl' => 'https://shop.example.com/cart',
]),
]);
$result = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status >= 400) {
throw new Exception("BillPay {$result['statusCode']}: {$result['message']}");
}
$payment = $result['body'];
// checkoutUrl is only returned now, so save it with the order
saveOrder($order['id'], $payment['id'], $payment['checkoutUrl']);
Response
201 Created, with the new payment in body.
If you send the same Idempotency-Key with the same body again, BillPay
doesn't create a second payment. It returns the original one, with the
message Payment already created. Treat a repeat like a new response: the
payment is in body, and its id is the same.
{
"statusCode": 201,
"message": "Payment created successfully",
"body": {
"id": "cae54780-b884-4253-829c-1069e1d41e3c",
"merchantId": "7d3e9b14-2c5a-4f8e-b6d1-0a9c4e2f7b35",
"merchantReference": "order-10231",
"status": "CREATED",
"amount": {"amount": 1000.0000, "currency": "ETB"},
"charged": {"amount": 1000.0000, "currency": "ETB"},
"fee": {"amount": 0.0000, "currency": "ETB"},
"vat": {"amount": 0.0000, "currency": "ETB"},
"net": {"amount": 1000.0000, "currency": "ETB"},
"refunded": {"amount": 0.0000, "currency": "ETB"},
"feePayer": null,
"description": "Invoice 10231",
"customer": {
"name": "Abebe Kebede",
"phone": "****4567",
"email": "a***e@example.com"
},
"checkoutUrl": "https://sandbox.checkout.billpay.et/...",
"returnUrl": "https://shop.example.com/orders/10231",
"cancelUrl": "https://shop.example.com/cart",
"createdAt": "2026-10-31T17:04:11.988768131Z",
"expiresAt": "2026-10-31T17:34:11.988768131Z",
"completedAt": null,
"attempts": []
},
"timestamp": "2026-10-31T17:04:12.010+00:00"
}
0, for example for some charities, and in the sandbox.MERCHANT, CUSTOMER, or SPLIT. Set in your agreement with BillPay. Can be null in the sandbox.null.null until then.1.SANDBOX_WALLET.TEST_WALLET.SUCCEEDED or TIMEOUT.PROVIDER_TIMEOUT. null if it succeeded.Fees
Who pays BillPay's fee is agreed with BillPay when you sign up. You don't
choose it per payment. The payment's feePayer tells you which applies:
feePayer | Who pays the fee | Effect |
|---|---|---|
MERCHANT | You. This is the most common. | The customer pays amount. You receive amount minus the fee and VAT. |
CUSTOMER | The customer | The customer pays more than amount. You receive the full amount. |
SPLIT | Both | The fee is shared between you and the customer. |
Some merchants have no fee at all, so fee is 0.
Always read charged for what the customer paid, and net for what reaches
your balance. Don't calculate them yourself.
Errors
| Status | Reason |
|---|---|
400 | A field failed validation, or Idempotency-Key is missing. body names each invalid field. |
401 | The key is missing or wrong, or it's from the other environment. |
409 | merchantReference is already used, or the same Idempotency-Key was sent with a different body. |
422 | Your account can't take live payments yet (production only). |
See Errors for the full list.
2. Redirect the customer
Redirect the customer's browser to checkoutUrl. For example, in Express:
res.redirect(303, payment.checkoutUrl);
The link works until expiresAt, which is 30 minutes after the payment is
created. Read expiresAt instead of hard-coding 30 minutes. The customer gets
3 tries. If a try fails, for example because of a wrong PIN, the payment
stays open and the customer can try again on the same page.
The checkout page is available in English, French, Arabic, Amharic, Afaan Oromoo, Tigrinya, and Chinese., and the customer gets 3 tries. If a try fails, for example because of a wrong PIN, the payment stays open and the customer can try again on the same page.
BillPay returns checkoutUrl only when the payment is created. If you want to
send the link again later, for example by SMS, save it with the order.
3. Handle the return
After paying, the customer's browser goes to your returnUrl. If they give up
on the checkout page, it goes to your cancelUrl.
- Put your order ID in the URL, like
https://shop.example.com/orders/10231. BillPay sends the customer to yourreturnUrlexactly as you set it, without adding a payment ID or status. The URL is the only way your page knows which order to show. - Show the status from your database, not from the URL. The webhook updates your database.
- The webhook can arrive a few seconds after the customer. If the order isn't updated yet, show "Confirming your payment…" and refresh the status after a few seconds.
4. Confirm the result
BillPay sends one of these webhooks to your server:
| Event | Meaning | What to do |
|---|---|---|
PaymentCaptured | The customer paid. | Mark the order paid and deliver it. |
PaymentFailed | The payment failed for good. | Mark the order failed and offer another try. |
Cancelled and expired payments don't send a webhook yet. For orders still unpaid after 30 minutes, check the payment. It will be CANCELLED or EXPIRED.
Letting the customer try again
A merchantReference belongs to one payment forever. If a payment ends
FAILED, CANCELLED, or EXPIRED,
create a new payment with a new reference, such as order-10231-2, and a new
Idempotency-Key.