Paybill & till payments (C2B)
Customers pay your paybill or till from their own phone: M-PESA menu or app, Lipa na M-PESA, your number and an account number. No prompt, no API call from you; you just receive the webhook.
Turning it on
- Add the paybill or till with its Daraja keys in Dashboard → Accounts.
- On the account page, press Register C2B URLs. We register our confirmation and validation URLs with Safaricom for that shortcode;
c2b_registered_aton the account records when. - Add a webhook endpoint.
One set of URLs per shortcode
What you receive
Once Safaricom confirms the payment, a payment.settled webhook with kind: "c2b":
{
"event": "payment.settled",
"transaction": {
"uuid": "edef32d8-5dac-4139-aff7-7b3a17279bf9",
"account_uuid": "5e2989df-905b-40e9-a056-8251c2e34a37",
"provider": "mpesa",
"direction": "collection",
"kind": "c2b",
"amount": "50.00",
"reported_amount": "50.00",
"amount_mismatch": false,
"currency": "KES",
"phone_sha256": "7132104d6aae9c3fac82095a42c2817952bca48e09d98d5bf4ac08218982fb90",
"payer_names": "JANE",
"reference": "HS-0042",
"provider_receipt": "TL3BD4QX7M",
"status": "settled",
"verified": true,
"settled_at": "2026-12-03T17:58:41.206893Z",
"created_at": "2026-12-03T17:58:41.206893Z",
"source": "provider",
"account_number": "HS-0042",
"external_ref": "router-42"
}
}referenceis the account number the customer typed (BillRef), uppercased with spaces removed. A till has none, so it falls back to the receipt.account_numberandexternal_refappear when the reference is a number you issued.amountis what was paid, or the number'sexpected_amountwhen it has one; compare withreported_amountandamount_mismatch.- A C2B payment has no
tracking_id: identify it by account number orexternal_ref.
Who paid
Safaricom usually hides C2B payers' numbers. What we get, we pass on: payer_names, a masked_phone, and phone_sha256, the SHA-256 of the number as 2547XXXXXXXX. To match a payment to a customer whose number you know, hash it the same way:
import { createHash } from "node:crypto";
// Hash the number in our (and Safaricom's) format: "254712345678", no "+".
// "0712345678" and "+254712345678" are converted first.
function phoneSha256(phone) {
const digits = phone.replace(/\D/g, "").replace(/^0/, "254");
return createHash("sha256").update(digits).digest("hex");
}
phoneSha256("254712345678") === tx.phone_sha256;Webhook endpoints can filter by payer number the same way, so a VIP line can go to its own system.
Accepting or declining before the money moves
If Safaricom has switched on external validation for your shortcode (ask them; it is off by default), they ask us before taking the money and we answer for you:
- An account number you issued that is closed, used up (single-use) or expired: declined.
- A number with an
expected_amountand a different amount: declined. - Any other account number on your own paybill: accepted, so customers can still pay with free-form references.
- A disabled account: declined.
Without validation every payment goes through, and you receive it with whatever reference the customer typed. Money is never dropped.
Shared Mypayments paybills
On a paybill Mypayments shares with you (ownership: "platform"), a payment is yours only when its account number is one issued to you. Issue a number for each customer, invoice or device before you ask them to pay. A payment that names no issued number is held for our team, not credited to anyone.
Testing
On a sandbox account, Simulate C2B on the account page asks Daraja to send a test payment. See testing in the sandbox.