FamPay API
Your key stays in this browser tab and is sent only to this server.

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-Key header
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/collectionsRequest a payment from a customer
POST/collections/statusStatus of a collection
GET/account/balanceWallet balance
GET/account/statementBalance movements over a date range
POST/payouts/mobile/previewFee and receiver name for a mobile payout
POST/payouts/mobileSend a mobile payout
POST/payouts/mobile/statusStatus of a mobile payout
GET/payouts/bank/banksBanks you can pay to
POST/payouts/bank/previewFee and account name for a bank payout
POST/payouts/bankSend a bank payout
POST/payouts/bank/statusStatus of a bank payout

How a payment moves

  1. You create a transaction with your own transactionRef. FamPay answers at once with a transactionId and the current status.
  2. 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.
  3. You learn the outcome through a signed webhook to your callbackUrl, or from the status endpoint. SUCCESS and FAILED are 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.

Base URL Add a valid API key at the top of the page to reveal it
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.
StatusCodeMeaning
401UNAUTHORIZEDThe key is missing, malformed, wrong, or revoked.
403FORBIDDENThe account is deactivated, or the request came from an IP address that is not allowed.
429RATE_LIMITEDToo 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.

FieldRules
msisdnTanzanian mobile number in international format without +: 2557XXXXXXXX or 2556XXXXXXXX.
amountInteger, in TZS. Must be within your account's limits (by default 1,000 to 5,000,000).
transactionRefYour own reference, 1–64 characters: letters, digits and . _ - : /. It must be unique within your account.
transactionIdFamPay'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.
narrationOptional, up to 140 characters, no control characters.
callbackUrlOptional 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.

Collection + (amount − fee) credited to your wallet on SUCCESS
Payout − (amount + fee) held at creation, given back if the payout fails

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

  1. QUEUEDpayouts only
  2. PENDINGsubmitting
  3. PROCESSINGat the network
  4. SUCCESSFAILED
StatusMeaning
QUEUEDThe payout is accepted, its funds are held, and it is waiting for its dispatch slot.
PENDINGBeing submitted to the mobile network or bank.
PROCESSINGThe network or bank has it. FamPay is waiting for the customer to approve, or for the transfer to settle.
SUCCESSDone. For a collection, the wallet has been credited.
FAILEDDid 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.

StageWhat happenedWhat to do
VALIDATIONThe request was invalid.Fix the request.
LEDGERYour wallet could not cover amount + fee.Top up, or send less.
PROVIDER_REJECTEDThe network refused the request, for example an unsupported number or account.Check the details, then retry with a new reference.
PROVIDER_PROCESSINGThe network or bank failed it: declined, no PIN entered, insufficient funds, wallet limits.Ask the customer to retry, using a new reference.
PROVIDER_REVERSALReversed or refunded after it had succeeded.Funds are back in your wallet.
PROVIDER_CONNECTIVITYFamPay could not reach the network. Nothing was sent.Retry later with a new reference.
TIMEOUTThe network never confirmed the transaction within 15 minutes.Treat it as failed. Nothing was charged.
PROVIDER_AUTH, SCHEDULER, INTERNALA 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 }
  }
}
StatusCodeWhen
422VALIDATION_ERRORA field is missing or invalid, a field is unknown, or the JSON is malformed.
401UNAUTHORIZEDThe API key is missing or invalid.
403FORBIDDENThe account is deactivated, or the request came from an IP address that is not allowed.
404NOT_FOUNDNo such transaction in your account.
409CONFLICTThe transactionRef was already used. details names the transaction.
402INSUFFICIENT_BALANCEYour wallet cannot cover amount + fee.
400 / 502PROVIDER_ERRORThe network rejected a preview or lookup (400), or could not be reached (502).
429RATE_LIMITEDToo many requests.
500INTERNAL_ERRORSomething 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.

transactionIdstring

FamPay's ID, 16 characters.

transactionRefstring

Your reference.

typestring

COLLECTION, MOBILE_PAYOUT or BANK_PAYOUT.

statusstring

See lifecycle.

amountinteger

The amount requested, in TZS.

feeinteger

Your FamPay fee for this transaction.

netAmountinteger

Collections: amount − fee, credited to your wallet. Payouts: amount + fee, debited from your wallet.

currencystring

Always TZS.

msisdnstring

Collections and mobile payouts only.

accountNumberaccountNamebictransferTypestring

Bank payouts only.

narrationstring | null

As sent.

channelchannelProviderstring | null

The network or bank that handled it, for example M-PESA.

providerReferencestring | null

The network's own reference. Useful when talking to the customer's operator.

messagestring | null

The latest message from the network.

failureobject | null

{ stage, code, reason } when FAILED.

scheduledAttimestamp

Present only while QUEUED.

createdAtupdatedAtcompletedAttimestamp

completedAt 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.

EventSent when
transaction.successThe status becomes SUCCESS.
transaction.failedThe 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,
    …
  }
}
HeaderValue
X-FamPay-Eventtransaction.success or transaction.failed
X-FamPay-Delivery-IdUnique per delivery. Use it to ignore duplicate deliveries.
X-FamPay-TimestampUnix seconds at signing.
X-FamPay-Signaturev1= 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:

30s1m5m15m30m1h2h6h12h24h

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:

  1. Read the raw request body exactly as received, before any JSON parsing.
  2. Compute HMAC-SHA256(secret, timestamp + "." + rawBody) and hex-encode it.
  3. Compare it with the value after v1=, using a constant-time comparison.
  4. 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);
});

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.

Real money

Confirm

Esc
↑↓ move↵ openEsc close