M-Pesa Daraja API Integration: A Practical Guide for Kenyan Businesses
A practical guide to integrating the M-Pesa Daraja API into business software: the flows that matter, the failure cases that break weak integrations, and why automatic reconciliation is the real prize.
In this article
M-Pesa is not a payment option in Kenya. It is the payment layer. If your software cannot accept and reconcile M-Pesa cleanly, it cannot serve a Kenyan business properly. The Daraja API is how you connect to it, and getting the integration right is the difference between money that reconciles itself and a finance team chasing receipts.
This is a plain guide to what a solid Daraja integration involves.
The pieces that matter
Daraja covers several flows. Most businesses need a subset:
- STK Push prompts a customer to approve a payment on their phone. This is the smooth checkout experience.
- C2B handles customers paying a Paybill or Till directly.
- B2C sends money out, for refunds, payouts, or salary disbursements.
- Transaction Status and Reversal let you confirm or undo when something goes wrong.
Where integrations break
The happy path is easy. The failures are where weak integrations fall apart:
- IF an STK push times out with no callback, THEN the system must query transaction status before assuming failure, never charge twice.
- IF a callback arrives late or twice, THEN the system must treat it idempotently, recording the payment once no matter how many times the notice arrives.
- IF the Daraja token expires mid-flow, THEN the system refreshes it automatically rather than failing the transaction.
A payment integration that ignores these cases works in the demo and fails in production.
Reconciliation is the real prize
Accepting a payment is half the job. The other half is matching every shilling received to the right invoice automatically, so nobody reconciles by hand at month end. That means each transaction carries an account reference that links it straight to its source. When that link is solid, your books close themselves.
Security basics
Your Daraja credentials are keys to your money. They belong in server-side configuration, never in front-end code, and callbacks must be validated so a forged request cannot mark an unpaid invoice as settled.
Vapor Technologies builds M-Pesa Daraja integrations into Laravel platforms with the failure cases and reconciliation handled from the start, so payments land, match, and balance without manual chasing. If your current setup needs a person to reconcile M-Pesa by hand, there is a better way.
Steve Nyanumba
Building software for Kenyan and African businesses at Vapor Technologies.
Building something for your business?
We help Kenyan and African businesses ship software that performs.