The berrapay API
Get paid in Ghana from your own code.
Mobile Money and cards, invoices, payment links, subscriptions and phone charges. Don't read about it first. Press Run below and pay yourself some pretend cedis.
- Three lines to get paidSend an amount, get a link, send your customer there.
- A sandbox where no money movesEvery example on this page runs for real, against pretend money.
- Errors that tell you the fixPlain words, the field that's wrong and what to do next.
Try it right here
Pick what you want to do, change anything you like, and press Run. No sign-up, no key.
Take a payment on your website. Send an amount and get back a link. Send your customer to it, and they pay by Mobile Money or card.
The same request from your code
curl -X POST https://berrapay.com/api/v1/checkouts \
-H "Authorization: Bearer bp_test_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"amount": 25.5,
"description": "Jollof for two",
"customer": {
"name": "Ama Mensah",
"phone": "0241234567"
},
"return_url": "https://yourshop.com/thanks"
}'Your customer's phone
Press Run. What you make shows up here, ready to be paid.
Webhooks berrapay sends you
Nothing yet. Pay something on the phone and watch this fill up.
Quick start
Four steps to your first payment
- 1
Get a test key
In berrapay, open Settings, then Connections, then berrapay API, and create a key. It starts with
bp_test_. - 2
Create a checkout
POST an amount to
/v1/checkouts. The answer has aurl. - 3
Send your customer there
They pay by Mobile Money or card, then land back on your
return_url. - 4
Hear that it's paid
berrapay calls your server with
checkout.paid. Or ask any time with a GET.
The basics
Everything works the same way
- Where
https://berrapay.com/api/v1- Who you are
- A header on every request:
Authorization: Bearer bp_test_... - Format
- JSON in and JSON out. Reading is
GET. Creating and changing arePOST. - Money
- Numbers in cedis.
25.5is GHS 25.50. Not text, and not pesewas. - Ids
- They say what they are:
chk_checkout,inv_invoice,lnk_link,pln_plan,chg_charge,pay_payment. - Lists
- 20 at a time. Add
?limit=50for more, and?after=with thenextvalue for the page after. - Safe retries
- Send an
Idempotency-Keyheader when you create something. The same key always returns the same object, never a second one. - Limits
- 3,000 requests an hour with a live key and 1,000 with a test key.
- History
- Events are kept for 90 days, and an
Idempotency-Keyis remembered for 7.
Test mode
Break things. It's free.
Test keys bp_test_
A sandbox of your own. Everything works, and nothing is real: no customer is charged and no wallet changes. Links lead to a pretend pay page where you choose whether the payment succeeds or fails.
Live keys bp_live_
Real customers and real money, into your berrapay wallet. Available once berrapay has approved your account. The requests and answers are exactly the same as in test mode.
Testing from code instead of clicking? POST to /v1/sandbox/pay with the id of a test checkout, invoice, link, plan or charge and an outcome of success or fail. Your test webhooks fire exactly as the live ones will.
Reference
Everything you can make
One payment of one amount, paid once. The quickest way to get paid from your own website or app.
Status: unpaid, paid, cancelled, expired, refunded
- POST/v1/checkoutsCreate a checkout
- GET/v1/checkoutsList your checkouts
- GET/v1/checkouts/:idGet one
- POST/v1/checkouts/:id/cancelCancel one that hasn't been paid
What you send to create one
| amountneeded | number | How much, in cedis. 25.5 means GHS 25.50. |
| description | text | What it is for. Your customer sees this. |
| reference | text | Your own order number. |
| customer.name | text | Who is paying. |
| customer.email | text | Where the receipt goes. |
| customer.phone | text | A Ghana number, like 0241234567. |
| return_url | text | Where to send the customer after paying. |
| expires_in_minutes | number | Stop taking payment after this long. |
Webhooks
Let berrapay tell you
Add an address under Settings, Connections, berrapay API, and berrapay calls it the moment something happens. Answer with any 2xx inside 10 seconds. If your server is down, berrapay tries again after 5 minutes, 30 minutes, 2 hours, 12 hours and a day, and you can resend any of them yourself.
- payment.succeededA customer paid you. Sent for every payment, whatever it was for.
- checkout.paidA checkout has been paid.
- invoice.paidAn invoice has been paid in full.
- subscription.createdA customer signed up to a plan.
- subscription.cancelledA subscription ended, by you, the customer or after failed renewals.
- charge.failedA phone charge wasn't approved.
- payment.refundedberrapay refunded a payment.
{
"id": "evt_k3m9x2p7q4w8n5",
"object": "event",
"type": "checkout.paid",
"mode": "live",
"created": "2027-01-15T10:24:11.000Z",
"data": {
"object": {
"id": "chk_6a1f0c9e2b7d4a53",
"object": "checkout",
"status": "paid",
"amount": 25.5,
"currency": "GHS",
"amount_paid": 25.5,
"balance": 0,
"description": "Jollof for two",
"reference": "ORDER-1001"
}
}
}Check every one is really from berrapay. Each call carries a Berrapay-Signature header: t= the time and v1= an HMAC-SHA256 of t.body made with your address's signing secret. Work it out yourself and compare. If they differ, ignore the call.
import crypto from "node:crypto";
// `raw` is the request body exactly as it arrived, before any JSON parsing.
function fromBerrapay(raw, header, secret) {
const { t, v1 } = Object.fromEntries(header.split(",").map((p) => p.split("=")));
if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false; // older than 5 minutes
const expected = crypto.createHmac("sha256", secret).update(t + "." + raw).digest("hex");
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(v1));
}
app.post("/berrapay", express.raw({ type: "application/json" }), (req, res) => {
if (!fromBerrapay(req.body.toString(), req.get("Berrapay-Signature"), process.env.BERRAPAY_WEBHOOK_SECRET)) return res.sendStatus(400);
const event = JSON.parse(req.body);
if (event.type === "checkout.paid") markOrderPaid(event.data.object.reference);
res.sendStatus(200);
});Errors
Errors that tell you the fix
When something is wrong, berrapay says what, and what to do about it. Every error has the same four parts, so you can show message to yourself and act on code in your program.
{
"error": {
"code": "invalid_request",
"message": "`amount` should be a number in cedis, like 25.5 (not text, and not pesewas).",
"fix": "Fix that field and send the request again.",
"docs": "https://berrapay.com/developers#errors"
}
}| 400 | invalid_request | Something in the request is missing or the wrong kind. The message names the field. |
| 400 | invalid_json | The body couldn't be read as JSON. |
| 400 | amount_out_of_range | The amount is below or above what berrapay takes. |
| 401 | missing_key / invalid_key | No key was sent, or it isn't valid. |
| 403 | account_not_ready | A live key on an account berrapay hasn't approved yet. |
| 403 | test_only | A pretend payment was tried with a live key. |
| 404 | not_found / no_such_route | No such object on this account, or no such address. |
| 409 | already_paid / already_exists / not_payable | It can't be done to this object as it stands. |
| 429 | rate_limited / busy / sandbox_full | Too many requests, or a full sandbox. Wait, or clear your test data. |
| 500 | server_error | berrapay's fault. Nothing was changed. |
Going live
Ready for real money?
- Your account is approved by berrapay, so a live key can be made.
- Your server uses the live key from a secret store, never from your website's pages or your app's code.
- You added a live webhook address, sent it a test, and your server checks the signature.
- You mark an order as paid from the webhook or a GET, not only because the customer came back to your site.
- You send an Idempotency-Key when creating, so a retry never charges twice.
- You tried a failed payment in test mode and your site handles it kindly.
Get your keys
A test key takes ten seconds. No approval needed to start building.