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

  1. Add the paybill or till with its Daraja keys in Dashboard → Accounts.
  2. On the account page, press Register C2B URLs. We register our confirmation and validation URLs with Safaricom for that shortcode; c2b_registered_at on the account records when.
  3. Add a webhook endpoint.

One set of URLs per shortcode

Safaricom keeps one confirmation URL per shortcode. Registering ours replaces whatever another system registered. If another system must keep receiving these payments, leave its URLs in place and forward its callbacks to us instead, or route our webhooks to it by filters.

What you receive

Once Safaricom confirms the payment, a payment.settled webhook with kind: "c2b":

json
{
  "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"
  }
}
  • reference is the account number the customer typed (BillRef), uppercased with spaces removed. A till has none, so it falls back to the receipt.
  • account_number and external_ref appear when the reference is a number you issued.
  • amount is what was paid, or the number's expected_amount when it has one; compare with reported_amount and amount_mismatch.
  • A C2B payment has no tracking_id: identify it by account number or external_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:

javascript
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_amount and 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.