# ChainPesa developer docs Accept stablecoins, settle in local currency and pay out across Africa with one REST API. - [Quickstart](/docs/quickstart): Take your first test payment in about five minutes. - [Accept payments](/docs/payments): Hosted checkout for USDT and USDC, priced in dollars or local currency. - [Send payouts](/docs/payouts): Pay bank and mobile-money accounts from your balance, or let your customer fund it. - [Webhooks](/docs/webhooks): Signed events, so your system hears about money the moment it moves. ## How money moves 1. Your customer pays: USDT or USDC, to an address created for that one payment. 2. ChainPesa records it: Every movement is a double-entry ledger line you can export. 3. You keep it or convert it: Hold a USD balance, or settle to your bank or mobile-money account. 4. You pay out: Send local currency to anyone, with a status you can follow. ## Base URL ``` https://dev.chainpesa.com/api/v1 ``` Requests and responses are JSON. Amounts are strings in major units, such as `"250.000000"` or `"50000.00"`, so no precision is lost. Timestamps are ISO 8601 in UTC. > Note: This environment runs in **test mode**: no real funds move. Use test keys, which start with `cp_test_`. ## Machine-readable - [OpenAPI 3.1 specification](/api/v1/openapi.json), to generate a client or import into Postman. - [llms.txt](/llms.txt) and [llms-full.txt](/llms-full.txt), for coding assistants. - Every page has a **Copy page** button that gives you clean Markdown. --- # Quickstart From a new account to a completed test payment and a verified webhook. ## 1. Create your account [Sign up](/signup) and set up two-factor sign-in. You get a test environment straight away. ## 2. Create a test key In the dashboard, open **API keys** and create a key with the `payments:read` and `payments:write` scopes. Copy it when it is shown: only a fingerprint is stored, so it cannot be shown again. ```bash export CHAINPESA_KEY=cp_test_your_key_here ``` ## 3. Create a payment cURL: ```bash curl -X POST https://dev.chainpesa.com/api/v1/payments \ -H "Authorization: Bearer $CHAINPESA_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{ "amount": "250.00", "currency": "USDT", "network": "TRON", "reference": "order_1042" }' ``` Node.js: ```javascript const res = await fetch("https://dev.chainpesa.com/api/v1/payments", { method: "POST", headers: { Authorization: `Bearer ${process.env.CHAINPESA_KEY}`, "Content-Type": "application/json", "Idempotency-Key": crypto.randomUUID(), }, body: JSON.stringify({ "amount": "250.00", "currency": "USDT", "network": "TRON", "reference": "order_1042" }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error.message); console.log(data); ``` Python: ```python import os, uuid import requests res = requests.post( "https://dev.chainpesa.com/api/v1/payments", headers={ "Authorization": f"Bearer {os.environ['CHAINPESA_KEY']}", "Idempotency-Key": str(uuid.uuid4()), }, json={ "amount": "250.00", "currency": "USDT", "network": "TRON", "reference": "order_1042" }, timeout=30, ) res.raise_for_status() print(res.json()) ``` PHP: ```php true, CURLOPT_TIMEOUT => 30, CURLOPT_POST => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('CHAINPESA_KEY'), 'Content-Type: application/json', 'Idempotency-Key: ' . bin2hex(random_bytes(16)), ], CURLOPT_POSTFIELDS => json_encode([ 'amount' => '250.00', 'currency' => 'USDT', 'network' => 'TRON', 'reference' => 'order_1042', ]), ]); $body = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); $data = json_decode($body, true); ``` The response has a `checkout_url`. That is the page your customer pays on. ## 4. Pay it, in test mode Open the `checkout_url` and press **Test mode: simulate this payment**. The payment becomes `completed` and your balance goes up. ## 5. Hear about it Add an endpoint under **Webhooks** in the dashboard. You will receive `payment.completed`. [Verify the signature](/docs/webhooks#verify-the-signature) before you trust it. > Note: Fulfil orders from the webhook, or by fetching the payment from your server. Never from the customer's browser returning to your site. --- # Authentication Bearer keys, scopes and IP allow-lists. Send your secret key as a bearer token on every request. ``` Authorization: Bearer cp_test_xxxxxxxxxxxxxxxx ``` ## Scopes Give each key only what it needs. A request outside its scopes returns `403 forbidden`. | Scope | Allows | | --- | --- | | `wallet:read` | Read balances | | `payments:read` | List and read payments | | `payments:write` | Create payments | | `payouts:write` | Create and read payouts, list banks, verify accounts | ## IP allow-list A key can be limited to the addresses of your servers. A request from anywhere else is refused as `401 unauthorized`. ## Keeping keys safe - Use keys from your server only. Never put one in a web page or a mobile app. - Use one key per system, so you can revoke one without stopping the rest. - Revoke a key from the dashboard the moment you suspect it has leaked. It stops working immediately. > Warning: Live keys are not accepted yet: they return `403 live_disabled`. See [Going live](/docs/going-live). --- # Errors One error shape, with a stable code and a message you can show. A failed request returns a non-2xx status and an `error` object. Branch on `code`; the `message` is written for people and may change. ```json { "error": { "code": "invalid_request", "message": "Insufficient USD balance. Add funds, or use Stable Connector so your customer funds this payout." } } ``` | Status | Code | Meaning | | --- | --- | --- | | 400 | `invalid_request` | A field is missing or wrong, or the request cannot be done. The message says which. | | 400 | `invalid_json` | The body is not a JSON object. | | 401 | `unauthorized` | The key is missing, wrong, revoked, or used from an address it does not allow. | | 403 | `forbidden` | The key lacks the scope this endpoint needs. | | 403 | `live_disabled` | A live key was used. Live mode is not open yet. | | 403 | `account_suspended` | The business account is suspended. Contact support. | | 404 | `not_found` | No such object on your account. | | 413 | `too_large` | The request body is larger than 20 kB. | | 429 | `rate_limited` | Too many requests. Wait for the `Retry-After` seconds. | | 502 | `provider_error` | Our payment partner could not answer. Safe to try again. | ## Retrying Retry `429` and `5xx` with a growing delay. Do not retry other `4xx` errors without changing the request. For anything that creates money movement, retry with the same [idempotency key](/docs/idempotency). --- # Idempotent requests Retry safely: the same key never creates a second payment or payout. Send an `Idempotency-Key` header, up to 120 characters, when you create a payment or payout. If a request with that key already succeeded, you get the original object back and nothing new is created. cURL: ```bash curl -X POST https://dev.chainpesa.com/api/v1/payouts \ -H "Authorization: Bearer $CHAINPESA_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{ "amount": "50000", "currency": "NGN", "beneficiary": { "name": "Ada Obi", "account_number": "0123456789", "bank_code": "058" }, "funding": "float", "reference": "payout_77" }' ``` Node.js: ```javascript const res = await fetch("https://dev.chainpesa.com/api/v1/payouts", { method: "POST", headers: { Authorization: `Bearer ${process.env.CHAINPESA_KEY}`, "Content-Type": "application/json", "Idempotency-Key": crypto.randomUUID(), }, body: JSON.stringify({ "amount": "50000", "currency": "NGN", "beneficiary": { "name": "Ada Obi", "account_number": "0123456789", "bank_code": "058" }, "funding": "float", "reference": "payout_77" }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error.message); console.log(data); ``` Python: ```python import os, uuid import requests res = requests.post( "https://dev.chainpesa.com/api/v1/payouts", headers={ "Authorization": f"Bearer {os.environ['CHAINPESA_KEY']}", "Idempotency-Key": str(uuid.uuid4()), }, json={ "amount": "50000", "currency": "NGN", "beneficiary": { "name": "Ada Obi", "account_number": "0123456789", "bank_code": "058" }, "funding": "float", "reference": "payout_77" }, timeout=30, ) res.raise_for_status() print(res.json()) ``` PHP: ```php true, CURLOPT_TIMEOUT => 30, CURLOPT_POST => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('CHAINPESA_KEY'), 'Content-Type: application/json', 'Idempotency-Key: ' . bin2hex(random_bytes(16)), ], CURLOPT_POSTFIELDS => json_encode([ 'amount' => '50000', 'currency' => 'NGN', 'beneficiary' => [ 'name' => 'Ada Obi', 'account_number' => '0123456789', 'bank_code' => '058', ], 'funding' => 'float', 'reference' => 'payout_77', ]), ]); $body = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); $data = json_decode($body, true); ``` - Use a fresh random value, such as a UUID, for each new operation. - Store it with your order before you send the request, so a retry after a crash uses the same one. - A reused key returns the first object even if you send a different body. Never reuse a key for a different operation. > Warning: A network timeout does not mean the request failed. Retry with the same key to find out. --- # Rate limits 120 requests a minute per key. Each key may make **120 requests a minute**. [Account verification](/docs/api/accounts-verify) also has its own limit of 30 a minute, because each check reaches the bank. Over the limit you receive `429 rate_limited` with a `Retry-After` header giving the seconds to wait. --- # Money and currencies Stablecoins, local currencies, networks and how amounts are written. | | Supported | Decimals | | --- | --- | --- | | Stablecoins | `USDT`, `USDC` | 6 | | Networks | `TRON`, `BSC`, `ETHEREUM` | | | Local currencies | `NGN`, `KES`, `GHS`, `UGX`, `TZS`, `XOF`, `XAF`, `CNY` | 2 | Amounts are strings in major units. Do your own arithmetic with a decimal type, not floating point. ## Exchange rates `rate` is units of local currency for 1 US dollar, locked when the object is created. A payment priced in local currency holds its rate for 30 minutes; a stablecoin payment expires after 60 minutes. ## Test data - Rates in test mode are illustrative, not market rates. - A payout to an account number ending in `000` is rejected, so you can test a failure. --- # Accept payments Hosted checkout, local-currency pricing and what each status means. ## Price in stablecoins Send `amount`. You are credited in the stablecoin, less the checkout fee, or converted to a linked local currency if you set `settle_to`. cURL: ```bash curl -X POST https://dev.chainpesa.com/api/v1/payments \ -H "Authorization: Bearer $CHAINPESA_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{ "amount": "250.00", "currency": "USDT", "network": "TRON", "reference": "order_1042" }' ``` Node.js: ```javascript const res = await fetch("https://dev.chainpesa.com/api/v1/payments", { method: "POST", headers: { Authorization: `Bearer ${process.env.CHAINPESA_KEY}`, "Content-Type": "application/json", "Idempotency-Key": crypto.randomUUID(), }, body: JSON.stringify({ "amount": "250.00", "currency": "USDT", "network": "TRON", "reference": "order_1042" }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error.message); console.log(data); ``` Python: ```python import os, uuid import requests res = requests.post( "https://dev.chainpesa.com/api/v1/payments", headers={ "Authorization": f"Bearer {os.environ['CHAINPESA_KEY']}", "Idempotency-Key": str(uuid.uuid4()), }, json={ "amount": "250.00", "currency": "USDT", "network": "TRON", "reference": "order_1042" }, timeout=30, ) res.raise_for_status() print(res.json()) ``` PHP: ```php true, CURLOPT_TIMEOUT => 30, CURLOPT_POST => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('CHAINPESA_KEY'), 'Content-Type: application/json', 'Idempotency-Key: ' . bin2hex(random_bytes(16)), ], CURLOPT_POSTFIELDS => json_encode([ 'amount' => '250.00', 'currency' => 'USDT', 'network' => 'TRON', 'reference' => 'order_1042', ]), ]); $body = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); $data = json_decode($body, true); ``` ## Price in local currency Send `price` instead. The customer pays the stablecoin equivalent at a rate locked for 30 minutes, fees included, and you receive the full price in that currency. You must first link a bank or mobile-money account for it under **Settlements**. ```json { "price": { "amount": "150000", "currency": "NGN" }, "currency": "USDT", "network": "TRON", "reference": "order_1044" } ``` ## Statuses | Status | Meaning | What to do | | --- | --- | --- | | `pending` | Waiting for the customer | Nothing yet | | `underpaid` | Some arrived, not all | Ask the customer to send the rest to the same address | | `completed` | Paid in full and credited | Fulfil the order | | `expired` | Not paid in time | Create a new payment | > Warning: Customers must send on the network you chose. Funds sent on another network can be lost. Reference: [Create a payment](/docs/api/payments-create), [Retrieve a payment](/docs/api/payments-get). --- # Send payouts From your balance or funded by your customer, to banks and mobile money. ## Find the destination [List banks](/docs/api/banks) for the currency, then, for NGN, GHS and XOF (Benin), [verify the account](/docs/api/accounts-verify) and show the name to your user before paying. cURL: ```bash curl -X POST https://dev.chainpesa.com/api/v1/accounts/verify \ -H "Authorization: Bearer $CHAINPESA_KEY" \ -H "Content-Type: application/json" \ -d '{ "currency": "NGN", "bank_id": 1, "account_number": "0123456789" }' ``` Node.js: ```javascript const res = await fetch("https://dev.chainpesa.com/api/v1/accounts/verify", { method: "POST", headers: { Authorization: `Bearer ${process.env.CHAINPESA_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ "currency": "NGN", "bank_id": 1, "account_number": "0123456789" }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error.message); console.log(data); ``` Python: ```python import os import requests res = requests.post( "https://dev.chainpesa.com/api/v1/accounts/verify", headers={ "Authorization": f"Bearer {os.environ['CHAINPESA_KEY']}", }, json={ "currency": "NGN", "bank_id": 1, "account_number": "0123456789" }, timeout=30, ) res.raise_for_status() print(res.json()) ``` PHP: ```php true, CURLOPT_TIMEOUT => 30, CURLOPT_POST => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('CHAINPESA_KEY'), 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => json_encode([ 'currency' => 'NGN', 'bank_id' => 1, 'account_number' => '0123456789', ]), ]); $body = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); $data = json_decode($body, true); ``` ## Send it cURL: ```bash curl -X POST https://dev.chainpesa.com/api/v1/payouts \ -H "Authorization: Bearer $CHAINPESA_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{ "amount": "50000", "currency": "NGN", "beneficiary": { "name": "Ada Obi", "account_number": "0123456789", "bank_code": "058" }, "funding": "float", "reference": "payout_77" }' ``` Node.js: ```javascript const res = await fetch("https://dev.chainpesa.com/api/v1/payouts", { method: "POST", headers: { Authorization: `Bearer ${process.env.CHAINPESA_KEY}`, "Content-Type": "application/json", "Idempotency-Key": crypto.randomUUID(), }, body: JSON.stringify({ "amount": "50000", "currency": "NGN", "beneficiary": { "name": "Ada Obi", "account_number": "0123456789", "bank_code": "058" }, "funding": "float", "reference": "payout_77" }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error.message); console.log(data); ``` Python: ```python import os, uuid import requests res = requests.post( "https://dev.chainpesa.com/api/v1/payouts", headers={ "Authorization": f"Bearer {os.environ['CHAINPESA_KEY']}", "Idempotency-Key": str(uuid.uuid4()), }, json={ "amount": "50000", "currency": "NGN", "beneficiary": { "name": "Ada Obi", "account_number": "0123456789", "bank_code": "058" }, "funding": "float", "reference": "payout_77" }, timeout=30, ) res.raise_for_status() print(res.json()) ``` PHP: ```php true, CURLOPT_TIMEOUT => 30, CURLOPT_POST => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('CHAINPESA_KEY'), 'Content-Type: application/json', 'Idempotency-Key: ' . bin2hex(random_bytes(16)), ], CURLOPT_POSTFIELDS => json_encode([ 'amount' => '50000', 'currency' => 'NGN', 'beneficiary' => [ 'name' => 'Ada Obi', 'account_number' => '0123456789', 'bank_code' => '058', ], 'funding' => 'float', 'reference' => 'payout_77', ]), ]); $body = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); $data = json_decode($body, true); ``` ## Who pays | `funding` | How it works | | --- | --- | | `float` | Taken from your USD balance at once. | | `connector` | Stable Connector: nothing is taken from you. The response includes `funding_payment`; send its `checkout_url` to your customer. The payout is released once it is paid. | ## A payout is not instant The provider confirms payouts. Treat `processing` as **not finished**: your money is held, and the payout becomes `completed` or `failed`. Wait for the webhook, or [fetch the payout](/docs/api/payouts-get). Do not send it again because it looks slow. | Status | Meaning | | --- | --- | | `pending_funding` | Waiting for your customer (Stable Connector) | | `pending_approval` | $1,000 or more: waiting for a second person in your dashboard | | `processing` | Sent, waiting for confirmation | | `completed` | Delivered | | `failed` | Not delivered; `failure` says why and your money is returned | | `cancelled` | Cancelled before sending | ## Country and amount rules - `XOF` payouts need `beneficiary.country`: `CI`, `SN` or `BJ`. - Some routes take whole amounts only. A payout with cents is refused before anything is reserved. --- # Settlements and wallet Getting your money out, in local currency or stablecoins. Settlements and withdrawals are managed in the dashboard. There is no API for moving your own money out, so a leaked API key cannot do it. ## Local currency Link a bank or mobile-money account under **Settlements**, then choose how each currency settles: | Mode | When money is sent | | --- | --- | | Instant | As soon as each payment completes | | Scheduled | Daily or weekly, at the hour you pick (UTC) | | Manual | When you press withdraw | Changing a destination account pauses settlements to it for 24 hours. Where the local network charges for a transfer, the charge is taken from the balance and the rest is sent. Settlement history and the `settlement.completed` event show it as `transfer_fee`. ## Stablecoins Under **Wallet**, withdraw USDT or USDC to a saved address. New addresses wait 24 hours before use, your team is emailed, and $1,000 or more needs a second approver. You receive `settlement.*` and `withdrawal.*` [events](/docs/events) for both. --- # Webhooks Signed HTTPS events with automatic retries. Add an `https` endpoint in the dashboard under **Webhooks**. You are shown a signing secret that starts with `whsec_`, once. ## What we send ```json { "id": "evt_Yz81kQm4NbTs", "type": "payment.completed", "created": 1831715100, "data": { "id": "pay_Qm3x9Tq1LbZa", "amount": "250.000000", "paid": "250.000000", "currency": "USDT", "settle_to": null, "reference": "order_1042" } } ``` ## Verify the signature Every delivery has a `ChainPesa-Signature` header: `t=,v1=`. The signature is an HMAC-SHA256, in hex, of the time, a dot, and the raw request body, using your endpoint secret. Node.js: ```javascript const crypto = require("node:crypto"); // rawBody must be the exact bytes we sent, as a string. Parse the JSON only after the check passes. function verifyChainPesa(rawBody, header, secret, toleranceSeconds = 300) { const match = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(header || ""); if (!match) return false; const [, timestamp, signature] = match; if (Math.abs(Date.now() / 1000 - Number(timestamp)) > toleranceSeconds) return false; const expected = crypto.createHmac("sha256", secret).update(timestamp + "." + rawBody).digest("hex"); return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature)); } // Express app.post("/webhooks/chainpesa", express.raw({ type: "application/json" }), (req, res) => { const raw = req.body.toString("utf8"); if (!verifyChainPesa(raw, req.get("ChainPesa-Signature"), process.env.CHAINPESA_WEBHOOK_SECRET)) { return res.sendStatus(400); } const event = JSON.parse(raw); res.sendStatus(200); // answer first, then do the work }); ``` Python: ```python import hashlib, hmac, time, re def verify_chainpesa(raw_body: bytes, header: str, secret: str, tolerance: int = 300) -> bool: match = re.fullmatch(r"t=(\d+),v1=([a-f0-9]{64})", header or "") if not match: return False timestamp, signature = match.groups() if abs(time.time() - int(timestamp)) > tolerance: return False expected = hmac.new(secret.encode(), timestamp.encode() + b"." + raw_body, hashlib.sha256).hexdigest() return hmac.compare_digest(expected, signature) ``` PHP: ```php $tolerance) { return false; } return hash_equals(hash_hmac('sha256', $m[1] . '.' . $rawBody, $secret), $m[2]); } $raw = file_get_contents('php://input'); $ok = verify_chainpesa($raw, $_SERVER['HTTP_CHAINPESA_SIGNATURE'] ?? null, getenv('CHAINPESA_WEBHOOK_SECRET')); http_response_code($ok ? 200 : 400); ``` - Use the **raw** body. Parsing and re-serialising it changes the bytes and the check fails. - Reject timestamps older than 5 minutes, so a captured request cannot be replayed. - Compare signatures with a constant-time function. ## Respond and retry Answer with any `2xx` within 8 seconds, then do your work. Redirects are not followed. Otherwise we try again after 30 seconds, 2 minutes, 10 minutes, 1 hour and 6 hours: six attempts in all. Deliveries and their responses are listed in the dashboard. > Warning: The same event can arrive more than once, and events can arrive out of order. Remember the event `id` and ignore repeats, and fetch the object if you need its current state. --- # Event types Every event, when it is sent and what it carries. The `data` object for each event. Amounts are strings in major units, the same as the API. ### payment.completed A payment received the full amount. ```json { "id": "pay_Qm3x9Tq1LbZa", "amount": "250.000000", "paid": "250.000000", "currency": "USDT", "settle_to": null, "reference": "order_1042" } ``` ### payment.underpaid The customer sent less than the amount due. ```json { "id": "pay_Qm3x9Tq1LbZa", "expected": "250.000000", "received": "200.000000", "currency": "USDT" } ``` ### payment.expired A payment was not paid in time. ```json { "id": "pay_Qm3x9Tq1LbZa" } ``` ### payout.awaiting_funding A Stable Connector payout is waiting for your customer to fund it. ```json { "id": "po_7Hc2kLm9PqRs", "payment_id": "pay_Qm3x9Tq1LbZa" } ``` ### payout.pending_approval A large payout is waiting for a second person. ```json { "id": "po_7Hc2kLm9PqRs" } ``` ### payout.completed The money was sent. ```json { "id": "po_7Hc2kLm9PqRs", "psp_ref": "10238", "currency": "NGN", "amount": "50000.00", "reference": "payout_77" } ``` ### payout.failed The payout did not go through. Your money has been returned. ```json { "id": "po_7Hc2kLm9PqRs", "reason": "Beneficiary account rejected by bank" } ``` ### payout.cancelled A waiting payout was cancelled. ```json { "id": "po_7Hc2kLm9PqRs" } ``` ### settlement.completed Money reached your bank or mobile-money account. ```json { "id": "stl_4Kd8mNp2QrSt", "currency": "NGN", "amount": "125000.00", "transfer_fee": "0.00", "trigger": "scheduled" } ``` ### settlement.failed A settlement did not go through. The balance is restored. ```json { "id": "stl_4Kd8mNp2QrSt", "currency": "NGN", "reason": "Beneficiary account rejected by bank" } ``` ### withdrawal.pending_approval A large wallet withdrawal is waiting for a second person. ```json { "id": "wd_9Lm3pQr5StUv" } ``` ### withdrawal.completed Stablecoins left your wallet. ```json { "id": "wd_9Lm3pQr5StUv", "amount": "100.000000", "currency": "USDT", "network": "TRON", "tx_hash": "0x5f1c9a" } ``` ### withdrawal.failed A withdrawal did not go through. Your balance is restored. ```json { "id": "wd_9Lm3pQr5StUv", "reason": "chain unavailable" } ``` --- # Going live What to have in place before real money. > Warning: Live mode is not open yet. Everything here runs on test money, and live keys are refused. ## Your integration checklist - Keys are only on your servers, one per system, limited by IP address. - Every create request sends an idempotency key that you store first. - Webhook signatures are verified on the raw body, and repeated events are ignored. - `processing`, `pending_approval` and `underpaid` are handled as unfinished, not as success or failure. - You reconcile daily against the list endpoints or the dashboard's CSV exports. - At least two people can approve large payouts, and each has their recovery codes. --- # Retrieve your balance The wallet balance for each stablecoin you hold. Amounts are strings in major units with 6 decimals. A currency you have never held is not listed. `GET /api/v1/balance` Scope: `wallet:read` ## Request ```bash curl https://dev.chainpesa.com/api/v1/balance \ -H "Authorization: Bearer $CHAINPESA_KEY" ``` ## Response ```json { "object": "balance", "mode": "test", "available": [ { "currency": "USDT", "amount": "1250.000000" } ] } ``` --- # Create a payment Creates a hosted checkout with its own deposit address. Send either `amount` (a fixed stablecoin amount) or `price` (a local-currency price). With `price`, the customer pays the stablecoin equivalent at a rate locked for 30 minutes, fees are included so you receive the full price, and you are settled in that currency. `POST /api/v1/payments` Scope: `payments:write` ## Parameters | Name | In | Type | Required | Description | | --- | --- | --- | --- | --- | | `amount` | body | string | see description | Stablecoin amount to collect, between 1 and 1,000,000. Send this or `price`, never both. | | `price` | body | object | see description | A local-currency price. Send this or `amount`. | | `price.amount` | body | string | see description | The price in major units, for example `"1500.00"`. | | `price.currency` | body | string | see description | A local currency you have linked in Settlements, for example `NGN`. | | `currency` | body | string | yes | The stablecoin the customer pays with: `USDT` or `USDC`. | | `network` | body | string | yes | `TRON`, `BSC` or `ETHEREUM`. | | `settle_to` | body | string | no | With `amount`, convert what you receive into this linked local currency. Leave out to keep it in USD. | | `reference` | body | string | no | Your own order reference, up to 100 characters. It is returned on the payment and its webhooks. | ## Request ```bash curl -X POST https://dev.chainpesa.com/api/v1/payments \ -H "Authorization: Bearer $CHAINPESA_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{ "amount": "250.00", "currency": "USDT", "network": "TRON", "reference": "order_1042" }' ``` ## Response ```json { "id": "pay_Qm3x9Tq1LbZa", "object": "payment", "status": "pending", "mode": "test", "amount": "250.000000", "paid_amount": "0.000000", "currency": "USDT", "network": "TRON", "address": "TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE", "settle_to": null, "reference": "order_1042", "price": null, "checkout_url": "https://dev.chainpesa.com/pay/pay_Qm3x9Tq1LbZa", "expires_at": "2027-01-12T10:45:00.000Z", "created_at": "2027-01-12T09:45:00.000Z" } ``` --- # List payments Your 50 most recent payments, newest first. `GET /api/v1/payments` Scope: `payments:read` ## Request ```bash curl https://dev.chainpesa.com/api/v1/payments \ -H "Authorization: Bearer $CHAINPESA_KEY" ``` ## Response ```json { "object": "list", "data": [ { "id": "pay_Qm3x9Tq1LbZa", "object": "payment", "status": "pending", "mode": "test", "amount": "250.000000", "paid_amount": "0.000000", "currency": "USDT", "network": "TRON", "address": "TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE", "settle_to": null, "reference": "order_1042", "price": null, "checkout_url": "https://dev.chainpesa.com/pay/pay_Qm3x9Tq1LbZa", "expires_at": "2027-01-12T10:45:00.000Z", "created_at": "2027-01-12T09:45:00.000Z" } ] } ``` --- # Retrieve a payment Fetch one payment. `status` is `pending`, `underpaid`, `completed` or `expired`. `GET /api/v1/payments/{id}` Scope: `payments:read` ## Parameters | Name | In | Type | Required | Description | | --- | --- | --- | --- | --- | | `id` | path | string | yes | The payment id. | ## Request ```bash curl https://dev.chainpesa.com/api/v1/payments/pay_Qm3x9Tq1LbZa \ -H "Authorization: Bearer $CHAINPESA_KEY" ``` ## Response ```json { "id": "pay_Qm3x9Tq1LbZa", "object": "payment", "status": "pending", "mode": "test", "amount": "250.000000", "paid_amount": "0.000000", "currency": "USDT", "network": "TRON", "address": "TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE", "settle_to": null, "reference": "order_1042", "price": null, "checkout_url": "https://dev.chainpesa.com/pay/pay_Qm3x9Tq1LbZa", "expires_at": "2027-01-12T10:45:00.000Z", "created_at": "2027-01-12T09:45:00.000Z" } ``` --- # Create a payout Sends local currency to a bank or mobile-money account. With `funding: "float"` it is paid from your USD balance. With `funding: "connector"` (Stable Connector) no balance is used: the response includes a `funding_payment` your customer pays, and the payout is released once it is covered. Payouts of $1,000 or more wait for a second approver in the dashboard. Payouts through our payment partners are confirmed by the provider: the payout can stay `processing`, with your money held, until it becomes `completed` or `failed` (and your money is returned). Some routes take whole amounts only, with no cents. `transfer_fee` is what the local network charges for the transfer, in the payout currency: the recipient still receives `amount`, and `usd_debit` includes the fee. `POST /api/v1/payouts` Scope: `payouts:write` ## Parameters | Name | In | Type | Required | Description | | --- | --- | --- | --- | --- | | `amount` | body | string | yes | Amount in local currency, major units, for example `"50000"`. | | `currency` | body | string | yes | `NGN`, `KES`, `GHS`, `UGX`, `TZS`, `XOF`, `XAF` or `CNY`. | | `beneficiary` | body | object | yes | Who is being paid. | | `beneficiary.name` | body | string | yes | Account holder name, 2 to 100 characters. | | `beneficiary.account_number` | body | string | yes | Bank account or mobile-money number. | | `beneficiary.bank_id` | body | integer | no | The bank or network id from [List banks](/docs/api/banks). The most reliable way to name a destination. | | `beneficiary.bank_code` | body | string | no | Bank code, used when there is no `bank_id`. | | `beneficiary.bank_name` | body | string | no | Bank or network name, used when it matches exactly one option. | | `beneficiary.country` | body | string | see description | Required for `XOF`: `CI`, `SN` or `BJ`. | | `beneficiary.network` | body | string | no | With Stable Connector, the chain your customer funds on: `TRON` (default), `BSC` or `ETHEREUM`. | | `funding` | body | string | no | `float` (default) or `connector`. | | `reference` | body | string | no | Your own reference, up to 100 characters. | ## Request ```bash curl -X POST https://dev.chainpesa.com/api/v1/payouts \ -H "Authorization: Bearer $CHAINPESA_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{ "amount": "50000", "currency": "NGN", "beneficiary": { "name": "Ada Obi", "account_number": "0123456789", "bank_code": "058" }, "funding": "float", "reference": "payout_77" }' ``` ## Response ```json { "id": "po_7Hc2kLm9PqRs", "object": "payout", "status": "completed", "mode": "test", "funding": "float", "route": "psp", "currency": "NGN", "amount": "50000.00", "transfer_fee": "0.00", "usd_debit": "32.594734", "rate": "1557", "reference": "payout_77", "failure": null, "confirmation_url": null, "created_at": "2027-01-12T09:45:00.000Z" } ``` --- # List payouts Your 50 most recent payouts, newest first. `GET /api/v1/payouts` Scope: `payouts:write` ## Request ```bash curl https://dev.chainpesa.com/api/v1/payouts \ -H "Authorization: Bearer $CHAINPESA_KEY" ``` ## Response ```json { "object": "list", "data": [ { "id": "po_7Hc2kLm9PqRs", "object": "payout", "status": "completed", "mode": "test", "funding": "float", "route": "psp", "currency": "NGN", "amount": "50000.00", "transfer_fee": "0.00", "usd_debit": "32.594734", "rate": "1557", "reference": "payout_77", "failure": null, "confirmation_url": null, "created_at": "2027-01-12T09:45:00.000Z" } ] } ``` --- # Retrieve a payout `status` is `pending_funding`, `pending_approval`, `processing`, `completed`, `failed` or `cancelled`. When it is `failed`, `failure` says why. `GET /api/v1/payouts/{id}` Scope: `payouts:write` ## Parameters | Name | In | Type | Required | Description | | --- | --- | --- | --- | --- | | `id` | path | string | yes | The payout id. | ## Request ```bash curl https://dev.chainpesa.com/api/v1/payouts/po_7Hc2kLm9PqRs \ -H "Authorization: Bearer $CHAINPESA_KEY" ``` ## Response ```json { "id": "po_7Hc2kLm9PqRs", "object": "payout", "status": "completed", "mode": "test", "funding": "float", "route": "psp", "currency": "NGN", "amount": "50000.00", "transfer_fee": "0.00", "usd_debit": "32.594734", "rate": "1557", "reference": "payout_77", "failure": null, "confirmation_url": null, "created_at": "2027-01-12T09:45:00.000Z" } ``` --- # List banks The banks and mobile-money networks a payout in this currency can go to. Use an `id` as `beneficiary.bank_id`. `GET /api/v1/banks/{currency}` Scope: `payouts:write` ## Parameters | Name | In | Type | Required | Description | | --- | --- | --- | --- | --- | | `currency` | path | string | yes | A local currency, for example `GHS`. | ## Request ```bash curl https://dev.chainpesa.com/api/v1/banks/GHS \ -H "Authorization: Bearer $CHAINPESA_KEY" ``` ## Response ```json { "object": "list", "currency": "GHS", "data": [ { "id": 277, "name": "MTN Ghana" } ] } ``` --- # Verify an account Check an account before paying it and get back the name the bank holds. Available for NGN, GHS and XOF (Benin). Limited to 30 checks a minute. `POST /api/v1/accounts/verify` Scope: `payouts:write` ## Parameters | Name | In | Type | Required | Description | | --- | --- | --- | --- | --- | | `currency` | body | string | yes | The account's currency. | | `bank_id` | body | integer | yes | From [List banks](/docs/api/banks). | | `account_number` | body | string | yes | The account to check. | ## Request ```bash curl -X POST https://dev.chainpesa.com/api/v1/accounts/verify \ -H "Authorization: Bearer $CHAINPESA_KEY" \ -H "Content-Type: application/json" \ -d '{ "currency": "NGN", "bank_id": 1, "account_number": "0123456789" }' ``` ## Response ```json { "object": "account_verification", "currency": "NGN", "account_number": "0123456789", "account_name": "Ada Obi" } ```