M-Pesa Daraja API Integration: STK Push, Paybill and Automatic Reconciliation
M-Pesa integration means payments are recorded when they happen, not found later on a statement. Here are the main Daraja building blocks.
From statements to callbacks
Many businesses still reconcile M-Pesa by scrolling through statements. With Safaricom's Daraja APIs, your system is notified of each payment as it happens and can record it, match it and issue a receipt. That is what an M-Pesa integration delivers.
STK push
With STK push (M-Pesa Express), your system sends a payment prompt to the customer's phone. They enter their PIN and your system receives the result by callback. It suits checkout, invoices and portals because the customer does not have to type a Paybill number or account reference.
Paybill and Till payments (C2B)
For customer-initiated payments, you register validation and confirmation URLs so Safaricom notifies your server of each payment. The account reference, such as an invoice or member number, tells you what to credit. Unmatched or mistyped references need a review queue.
Payouts (B2C)
Business-to-customer payments let you send money to phones: refunds, commissions, wages or farmer payments. They need approval controls inside your system and the right permissions on your account.
Questions developers and finance teams ask
Do I need a Paybill or a Till? It depends on your business. Paybill uses account references and suits invoicing, while a Till suits retail. Safaricom can advise on eligibility.
Why did a customer's payment not appear? Common causes are delayed callbacks, wrong references and network issues. Status queries and a review queue handle these.
Can the system refund a customer? Through B2C or reversals, with approval controls.
Mistakes to avoid
Trusting callbacks without verifying them. Not handling duplicate callbacks. Ignoring partial payments and overpayments. Keeping credentials in source code. Testing only the happy path in the sandbox. Each causes real problems once money flows.
Mobile money beyond Kenya
Uganda, Tanzania, Rwanda, Ghana and other countries run mobile money through different operators and APIs, such as MTN MoMo and Airtel Money. The design of the integration, callbacks, matching and receipts, carries over, but the API details differ. If you need mobile money outside Kenya, tell us the operator and country so we can check API access.
Go-live and edge cases
Going live needs your own shortcode and Safaricom's approval. Real payments bring duplicates, delayed callbacks, partial payments and overpayments, so status queries and review queues matter. Callbacks must use HTTPS and be verified. Pair this with bank integration for a complete picture.
To integrate M-Pesa with your website, ERP or app, talk to Zinen Technologies.
Choose the right flow for the job
Use STK push when your system initiates the payment, such as at checkout. Use C2B (Paybill or Till) when customers pay from their own phone and your system must recognise it. Use B2C or B2B for payouts. Each needs separate setup and approval. See M-Pesa integration.
Callbacks and security
Daraja sends results to your callback URL. It must be HTTPS, reachable and fast. Validate the data, store the receipt number, make processing idempotent so duplicates do nothing, and log everything. Keep consumer keys and secrets out of source code.
Reconciliation
Match M-Pesa receipts to invoices daily. Handle payments with wrong references through a manual queue. Report unmatched items to finance.
Going live
Test in the sandbox, request production access, use real small amounts, and monitor the first week closely. Prepare for Safaricom outages with a fallback process.
Questions we are often asked
Why did my STK push fail? Check the number, timeout, insufficient funds and callback errors.
Can I take Paybill and Till? Both can be integrated.
How long does approval take? It varies; apply early.
Next step
If you would like to see how M-Pesa Daraja API Integration fits your system, contact Zinen Technologies for a walkthrough based on your own processes.
The systems and environments discussed in this guide
Systems related to this article
More from the blog
Car Insurance Software in Kenya: Rating, DMVIC, Claims, Renewals and IRA Compliance
Motor insurance is high volume and unforgiving of mistakes. Here is what good car insurance software does at each stage, from quote to claim, for insurers, brokers and agencies.
Security Company Software: Rostering, GPS Clock-In, Patrols, Alarms, Payroll and Billing
Guarding companies live on posts covered, guards paid correctly and invoices collected. Here is how security company software connects the roster, attendance, patrols, payroll and billing.
Garbage Collection Software in Kenya: Routes, M-Pesa Billing, NEMA Paperwork and Recycling
A waste business makes money when trucks run full routes, customers pay on time and disposal costs are controlled. Here is how garbage collection software helps.
Ready to put this into practice?
Book a free demo and we'll show you exactly how this fits your business.