API reference · v1
FamPay API
Request mobile money payments from customers, send money to mobile wallets and Tanzanian bank accounts, and read your wallet and its statement. Every endpoint takes and returns JSON over HTTPS.
Requests are processed for real; there is no sandbox. Test with small amounts. Add your API key at the top of this page to call any endpoint from your browser.
- Base URL
- Shown once a valid API key is added
- Authentication
X-API-Keyheader- Currency
- TZS, whole shillings
- Format
- JSON, UTF-8, UTC timestamps
Quick start
Check your wallet, then ask a customer to pay you. Set FAMPAY_BASE_URL and FAMPAY_API_KEY in your shell first.
# 1. Wallet balance
curl "$FAMPAY_BASE_URL/account/balance" \
-H "X-API-Key: $FAMPAY_API_KEY"
# 2. Send a payment prompt to a customer's phone
curl -X POST "$FAMPAY_BASE_URL/collections" \
-H "X-API-Key: $FAMPAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"msisdn":"255712345678","amount":1000,"transactionRef":"order-1001"}'
Endpoints
| POST | /collections | Request a payment from a customer |
| POST | /collections/status | Status of a collection |
| GET | /account/balance | Wallet balance |
| GET | /account/statement | Balance movements over a date range |
| POST | /payouts/mobile/preview | Fee and receiver name for a mobile payout |
| POST | /payouts/mobile | Send a mobile payout |
| POST | /payouts/mobile/status | Status of a mobile payout |
| GET | /payouts/bank/banks | Banks you can pay to |
| POST | /payouts/bank/preview | Fee and account name for a bank payout |
| POST | /payouts/bank | Send a bank payout |
| POST | /payouts/bank/status | Status of a bank payout |
How a payment moves
- You create a transaction with your own
transactionRef. FamPay answers at once with atransactionIdand the current status. - FamPay hands it to the network. Collections go out straight away as a USSD prompt on the customer's phone. Payouts wait their turn in the payout queue.
- You learn the outcome through a signed webhook to your
callbackUrl, or from the status endpoint.SUCCESSandFAILEDare final.
01Start here
Authentication
Send your API key in the X-API-Key header on every request, to the base URL below. FamPay issues the key when your account is set up. It is shown once, so store it in a secrets manager.
X-API-Key: fpk_A1b2C3d4E5f6.40-character secret
- Keep the key on your server. Never ship it in a mobile app, a browser bundle, or a public repository. If it leaks, ask FamPay to revoke it and issue a new one.
- If your account has an IP allowlist, requests from any other address get
403. That includes this page, because it calls the API from your browser's IP address. - Each key may make a limited number of requests per minute (60 unless agreed otherwise). Past the limit you get
429. Wait a few seconds, then retry.
| Status | Code | Meaning |
|---|---|---|
| 401 | UNAUTHORIZED | The key is missing, malformed, wrong, or revoked. |
| 403 | FORBIDDEN | The account is deactivated, or the request came from an IP address that is not allowed. |
| 429 | RATE_LIMITED | Too many requests this minute. |
On this page your key is kept in this tab's session storage. It is sent only to this server and disappears when you close the tab. It is never written into the code samples.
02Start here
Requests & fields
Request bodies are JSON and need Content-Type: application/json, up to 16 KB. Unknown fields are rejected with 422, so a misspelled field fails loudly instead of being silently ignored.
| Field | Rules |
|---|---|
msisdn | Tanzanian mobile number in international format without +: 2557XXXXXXXX or 2556XXXXXXXX. |
amount | Integer, in TZS. Must be within your account's limits (by default 1,000 to 5,000,000). |
transactionRef | Your own reference, 1–64 characters: letters, digits and . _ - : /. It must be unique within your account. |
transactionId | FamPay's identifier for a transaction: 16 letters and digits. It starts with C for a collection, M for a mobile payout, or B for a bank payout. |
narration | Optional, up to 140 characters, no control characters. |
callbackUrl | Optional https:// URL on a public host. FamPay sends this transaction's final status there. If you leave it out, no webhook is sent. |
Retrying safely
A transactionRef can be used only once. If a create request times out and you don't know whether it arrived, send it again with the same reference. If the first request did arrive, you get 409 CONFLICT with the existing transaction's ID in error.details.transactionId, and nothing is charged twice.
Request IDs
Every response carries an X-Request-Id header. Log it. When you contact support about a request, include its ID. For a request that created a transaction, it is also the ID of that transaction's full trace.
03Start here
Fees & your wallet
Your account has a FamPay wallet in TZS. Collections add money to it, and payouts are paid from it. The fees are the rates agreed when your account was opened. Each response shows the fee it charged and netAmount, the amount that actually moves in your wallet.
SUCCESS
Before sending a payout, use the preview endpoints to see the exact fee, the total debit, and the receiver's registered name.
04Start here
Transaction lifecycle
- QUEUEDpayouts only
- PENDINGsubmitting
- PROCESSINGat the network
- SUCCESSFAILED
| Status | Meaning |
|---|---|
QUEUED | The payout is accepted, its funds are held, and it is waiting for its dispatch slot. |
PENDING | Being submitted to the mobile network or bank. |
PROCESSING | The network or bank has it. FamPay is waiting for the customer to approve, or for the transfer to settle. |
SUCCESS | Done. For a collection, the wallet has been credited. |
FAILED | Did not go through. For a payout, the held funds are back in your wallet. failure says why. |
A payout can, rarely, change from SUCCESS to FAILED after the network or bank reverses or refunds it. The money returns to your wallet, and you receive a transaction.failed webhook whose failure.stage is PROVIDER_REVERSAL.
Where it failed
Every failed transaction has failure.stage, which says where the failure happened, so you know whose move it is.
| Stage | What happened | What to do |
|---|---|---|
VALIDATION | The request was invalid. | Fix the request. |
LEDGER | Your wallet could not cover amount + fee. | Top up, or send less. |
PROVIDER_REJECTED | The network refused the request, for example an unsupported number or account. | Check the details, then retry with a new reference. |
PROVIDER_PROCESSING | The network or bank failed it: declined, no PIN entered, insufficient funds, wallet limits. | Ask the customer to retry, using a new reference. |
PROVIDER_REVERSAL | Reversed or refunded after it had succeeded. | Funds are back in your wallet. |
PROVIDER_CONNECTIVITY | FamPay could not reach the network. Nothing was sent. | Retry later with a new reference. |
TIMEOUT | The network never confirmed the transaction within 15 minutes. | Treat it as failed. Nothing was charged. |
PROVIDER_AUTH, SCHEDULER, INTERNAL | A problem on FamPay's side. | Contact support with the X-Request-Id. |
05Start here
Payout queue
The payment network accepts only one payout from FamPay per cooldown window (60 seconds). Rather than make you retry, FamPay holds the funds the moment you create a payout and puts it in a fair, first-come queue. A background scheduler then sends each payout as soon as its slot opens.
The create response includes a queue object. The status endpoint returns it too while the payout is still queued:
"queue": {
"position": 3,
"estimatedDispatchAt": "2026-12-04T09:18:00Z",
"cooldownSeconds": 60
}
Mobile and bank payouts have separate queues. Rely on webhooks for the final result rather than tight polling.
06Start here
Errors
Errors come back with a non-2xx status and the same envelope every time:
{
"error": {
"code": "INSUFFICIENT_BALANCE",
"message": "insufficient balance: available 4000, required 5500",
"failureStage": "LEDGER",
"details": { "available": 4000, "required": 5500 }
}
}
| Status | Code | When |
|---|---|---|
| 422 | VALIDATION_ERROR | A field is missing or invalid, a field is unknown, or the JSON is malformed. |
| 401 | UNAUTHORIZED | The API key is missing or invalid. |
| 403 | FORBIDDEN | The account is deactivated, or the request came from an IP address that is not allowed. |
| 404 | NOT_FOUND | No such transaction in your account. |
| 409 | CONFLICT | The transactionRef was already used. details names the transaction. |
| 402 | INSUFFICIENT_BALANCE | Your wallet cannot cover amount + fee. |
| 400 / 502 | PROVIDER_ERROR | The network rejected a preview or lookup (400), or could not be reached (502). |
| 429 | RATE_LIMITED | Too many requests. |
| 500 | INTERNAL_ERROR | Something broke on FamPay's side. Contact support with the request ID. |
Sometimes a collection fails while the request is still in progress, for example when the network rejects the phone number. You then get 400 or 502 with the error envelope, plus a transaction object recording the failed attempt.
07Start here
The transaction object
Every create, status and webhook response carries the same object.
transactionIdstringFamPay's ID, 16 characters.
transactionRefstringYour reference.
typestringCOLLECTION, MOBILE_PAYOUT or BANK_PAYOUT.
statusstringSee lifecycle.
amountintegerThe amount requested, in TZS.
feeintegerYour FamPay fee for this transaction.
netAmountintegerCollections: amount − fee, credited to your wallet. Payouts: amount + fee, debited from your wallet.
currencystringAlways TZS.
msisdnstringCollections and mobile payouts only.
accountNumberaccountNamebictransferTypestringBank payouts only.
narrationstring | nullAs sent.
channelchannelProviderstring | nullThe network or bank that handled it, for example M-PESA.
providerReferencestring | nullThe network's own reference. Useful when talking to the customer's operator.
messagestring | nullThe latest message from the network.
failureobject | null{ stage, code, reason } when FAILED.
scheduledAttimestampPresent only while QUEUED.
createdAtupdatedAtcompletedAttimestampcompletedAt is null until the status is final.
Endpoints
Collections
Ask a customer to pay you. FamPay sends a USSD prompt to their phone, and the customer approves it with their mobile money PIN. Once they do, the money (minus your fee) lands in your wallet.
Endpoints
Account
Read your FamPay wallet and the movements that changed it.
Endpoints
Mobile payouts
Send money from your wallet to a mobile money account: M-Pesa, Tigo Pesa / Mixx by Yas, Airtel Money or HaloPesa. FamPay works out the network from the number.
Endpoints
Bank payouts
Send money from your wallet to an account at a Tanzanian bank. Take the bank's bic from the supported-banks list, and preview the payout first to check the account holder's name.
W1Webhooks
Events & delivery
When a transaction reaches a final status, FamPay sends an HTTPS POST to that transaction's callbackUrl.
| Event | Sent when |
|---|---|
transaction.success | The status becomes SUCCESS. |
transaction.failed | The status becomes FAILED, including when a payout is reversed or refunded after success. |
The body is the event name plus the transaction object:
{
"event": "transaction.success",
"data": {
"transactionId": "C8hJ2kLm9PqRs4Tv",
"transactionRef": "order-2025-001",
"type": "COLLECTION",
"status": "SUCCESS",
"amount": 1000,
"fee": 20,
"netAmount": 980,
…
}
}
| Header | Value |
|---|---|
X-FamPay-Event | transaction.success or transaction.failed |
X-FamPay-Delivery-Id | Unique per delivery. Use it to ignore duplicate deliveries. |
X-FamPay-Timestamp | Unix seconds at signing. |
X-FamPay-Signature | v1= followed by a hex HMAC-SHA256 (see below). |
Responding
Return any 2xx within 10 seconds, and do slow work after you respond. Any other answer, or no answer, is retried 10 times over about two days:
A delivery can therefore arrive more than once, so handle it idempotently using transactionId and event.
W2Webhooks
Verifying signatures
Every delivery is signed with the webhook secret (whsec_…) you received when your account was set up. Before you trust a delivery:
- Read the raw request body exactly as received, before any JSON parsing.
- Compute
HMAC-SHA256(secret, timestamp + "." + rawBody)and hex-encode it. - Compare it with the value after
v1=, using a constant-time comparison. - Reject the delivery if the timestamp is more than 5 minutes from your clock.
import crypto from "node:crypto";
import express from "express";
const app = express();
const SECRET = process.env.FAMPAY_WEBHOOK_SECRET;
app.post("/webhooks/fampay", express.raw({ type: "application/json" }), (req, res) => {
const ts = req.get("X-FamPay-Timestamp") ?? "";
const sig = (req.get("X-FamPay-Signature") ?? "").replace(/^v1=/, "");
const expected = crypto.createHmac("sha256", SECRET)
.update(`${ts}.${req.body}`)
.digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(ts)) < 300;
const valid = sig.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
if (!fresh || !valid) return res.sendStatus(400);
const { event, data } = JSON.parse(req.body);
// queue the work, then answer quickly
res.sendStatus(200);
});
import hashlib, hmac, json, os, time
from flask import Flask, request, abort
app = Flask(__name__)
SECRET = os.environ["FAMPAY_WEBHOOK_SECRET"].encode()
@app.post("/webhooks/fampay")
def fampay_webhook():
raw = request.get_data() # raw bytes, not request.json
ts = request.headers.get("X-FamPay-Timestamp", "")
sig = request.headers.get("X-FamPay-Signature", "").removeprefix("v1=")
expected = hmac.new(SECRET, ts.encode() + b"." + raw, hashlib.sha256).hexdigest()
if not ts.isdigit() or abs(time.time() - int(ts)) > 300:
abort(400)
if not hmac.compare_digest(sig, expected):
abort(400)
payload = json.loads(raw)
# queue the work, then answer quickly
return "", 200
<?php
$secret = getenv('FAMPAY_WEBHOOK_SECRET');
$raw = file_get_contents('php://input');
$ts = $_SERVER['HTTP_X_FAMPAY_TIMESTAMP'] ?? '';
$sig = preg_replace('/^v1=/', '', $_SERVER['HTTP_X_FAMPAY_SIGNATURE'] ?? '');
$expected = hash_hmac('sha256', $ts . '.' . $raw, $secret);
if (!ctype_digit($ts) || abs(time() - (int) $ts) > 300 || !hash_equals($expected, $sig)) {
http_response_code(400);
exit;
}
$payload = json_decode($raw, true);
// queue the work, then answer quickly
http_response_code(200);
W3Webhooks
Signature checker
Paste a delivery you received to check your secret and your verification code. The check runs entirely in this browser. Nothing you paste here is sent anywhere.