Free 15-minute strategy call with Victor Book a call
Systems

M-Pesa Daraja API Integration in Kenya: Automating STK Push, Paybill Reconciliation & Invoicing

M-Pesa Daraja API integration connects a business’s website or software directly to Safaricom’s M-Pesa platform, so payments are requested by STK Push, confirmed automatically and matched to invoices without manual checking. In Kenya, a professional Daraja integration typically costs KES 80,000 to 400,000 and takes 2 to 6 weeks including Safaricom go-live approval.

In many Kenyan businesses, someone spends hours every day doing the same thing: scrolling through M-Pesa messages, matching payments to customers, updating a spreadsheet and chasing people who "already paid". It is slow, error-prone and an open door for fraud with fake payment SMS screenshots.

Safaricom’s Daraja API removes that work. This guide explains how M-Pesa integration works, what it costs and how to plan a project that actually reconciles payments end to end.

What is the M-Pesa Daraja API?

Daraja is Safaricom’s developer platform that lets software communicate with M-Pesa. Instead of a human reading SMS confirmations, your system receives structured payment data the moment a transaction happens. The most commonly used services are:

  • M-Pesa Express (STK Push): your system sends a payment prompt to the customer’s phone; they enter their PIN; your system receives the result.
  • C2B (Customer to Business): when customers pay your Paybill or Till directly, M-Pesa notifies your system through registered confirmation and validation URLs.
  • B2C (Business to Customer): automated payouts such as refunds, commissions, loan disbursements or salaries.
  • Transaction Status and Account Balance: query results and balances programmatically.
  • Reversals: initiate reversals for erroneous transactions.

Manual verification vs automated reconciliation

Process stepManual Paybill or Till verificationAutomated STK Push and webhook reconciliation
Requesting paymentCustomer told to pay Paybill with an account number they often mistypeSTK Push prompt sent with the exact amount and reference
Confirming paymentStaff check SMS or the M-Pesa portal; customers send screenshotsCallback confirms instantly with the receipt number
Matching to invoice or orderManual matching in Excel; errors with wrong account numbersMatched automatically by reference, phone number and amount
Fraud riskFake SMS and edited screenshots acceptedOnly Safaricom-confirmed transactions are recorded
Partial and over-paymentsTracked in notebooks or memoryBalances updated automatically; customers notified
Receipts and invoicesTyped and sent manuallyGenerated and sent by SMS, email or WhatsApp automatically
ReportingEnd-of-month reconciliation takes daysReal-time dashboard of collections and outstanding balances
Staff timeHours per day in busy businessesExceptions only

How does STK Push integration work, step by step?

  1. The customer clicks pay on your website, app or portal, or staff trigger a request from your system.
  2. Your server authenticates with Daraja and sends the STK Push request with the amount, phone number, reference and a callback URL.
  3. The customer sees the M-Pesa prompt and enters their PIN.
  4. Safaricom sends the result to your callback URL: success with receipt number, or failure with a reason such as cancelled or insufficient funds.
  5. Your system updates the order or invoice, issues a receipt and triggers next steps such as delivery or access.

A robust integration also handles timeouts, duplicate callbacks and customers who pay directly to the Paybill instead of using the prompt.

What does automated Paybill reconciliation involve?

Many customers will always pay the Paybill directly: tenants, school parents, SACCO members, wholesale buyers. With C2B URLs registered, every payment is pushed to your system with the payer’s details, amount and account reference. Matching rules then allocate it to the right invoice or customer, handling common problems such as:

  • Misspelled or missing account numbers, matched by phone number or amount.
  • One payment covering several invoices.
  • Instalments and part payments.
  • Payments for unknown accounts, flagged for review.

This is the difference between "we accept M-Pesa" and "our finance team never reconciles by hand again". For e-commerce checkout specifically, see our e-commerce and M-Pesa checkout guide.

How do you go live with Daraja?

  • Register on the Daraja portal and build against the sandbox.
  • Have an active Paybill or Till number with the right account permissions.
  • Complete Safaricom’s go-live process for production credentials.
  • Host callback URLs on secure HTTPS endpoints that are always available.
  • Store credentials securely, never inside front-end code or shared documents.

How much does M-Pesa integration cost in Kenya?

  • STK Push on an existing website or store: KES 80,000 to 150,000.
  • STK Push plus C2B reconciliation and automatic receipts: KES 150,000 to 300,000.
  • Full billing system with invoicing, statements, B2C payouts and dashboards: KES 300,000 to 1,000,000+.

Safaricom transaction charges apply separately according to your tariff. Payment gateways that bundle M-Pesa are faster to set up but charge a percentage per transaction.

Which Kenyan businesses benefit most from M-Pesa automation?

  • Schools and colleges: fee collection by admission number, with balances visible to parents.
  • Property managers: rent by unit number, automatic receipts and arrears tracking.
  • SACCOs and microfinance: contributions, loan repayments and disbursements.
  • E-commerce and delivery: instant order confirmation.
  • Clinics and service businesses: deposits for bookings.

Payments are usually one part of a bigger system. Our cornerstone article, your spreadsheets are leaking money, shows how disconnected tools cost Kenyan businesses, and our custom CRM guide explains how payments connect to sales tracking.

How Nimus builds M-Pesa payment automation

Nimus (nimus.co.ke), a Nairobi software and growth agency, builds Daraja integrations as part of complete business systems. Through its custom business systems and software service, Nimus implements STK Push, C2B reconciliation, automated receipts and B2C payouts, and connects payment data to CRM, invoicing and reporting dashboards within the Nimus sales engine. It also covers inventory and stock; see our guide to custom ERP and inventory systems.

Frequently Asked Questions

Is the M-Pesa Daraja API free to use?

Access to the Daraja developer portal and APIs is free, but normal M-Pesa transaction charges apply to payments according to your Paybill or Till tariff. Development, hosting and maintenance of the integration are separate costs paid to your developer or provider.

Can I integrate M-Pesa with a Till number instead of a Paybill?

Yes. STK Push and C2B confirmations work with both Buy Goods Till numbers and Paybill numbers, though configuration differs. Paybill is often better for reconciliation because customers enter an account reference, such as an invoice, unit or admission number.

How long does Safaricom go-live approval take?

Once development and testing are complete, Safaricom’s go-live process typically takes from a few days to two weeks, depending on documentation, account setup and the APIs requested. Starting the paperwork early avoids delays at launch.

Is M-Pesa API integration secure?

Yes, when built properly. Credentials must be stored securely on the server, callbacks served over HTTPS and validated, and access to payment data restricted. Every transaction should be verifiable with Safaricom using the receipt number before goods or services are released.

Your Next Step

Want This Built For Your Business?

This is exactly the kind of thing we build. Book a free call and I'll tell you where to start.

Done For You

Stop Reading. Start Building.

Book a free 15-minute call and let's figure out what your sales engine needs.

Book a call
14+ Brandstrust Nimus with their Growth
Chat on WhatsAppMessage Victor directly Free 15-Min Call

Fifteen minutes with me. I'll look at where your leads come from and tell you honestly what I'd fix first. No pushy sales.

Book my free call