HomeBlogMobile App Development
Mobile App Development

M-Pesa API Integration in Kenya for Mobile Apps: 2026 Guide

Learn how M-Pesa API integration in Kenya works, from Daraja 3.0 flow selection and callbacks to idempotency, reconciliation, security and go-live.

Z
Zuxxis Team
•9 min read
M-Pesa API Integration in Kenya for Mobile Apps: 2026 Guide

M-Pesa API integration in Kenya can fail after the customer approves a prompt. The order says “pending”—or worse, “paid”—because the team treated the initial response as settlement. This is not a payment button; it is a state machine connecting your app, backend and M-PESA.

Safaricom's FY26 results reported 41 million active M-PESA customers, 46.41 billion transactions worth KSh 41.68 trillion and a 3.1 million merchant base. This guide covers flow selection, callbacks, duplicate prevention, reconciliation and a safe Daraja launch.

Why M-Pesa API integration in Kenya starts with payment reality

Kenyan customers see a phone prompt, an M-PESA confirmation and whether the business reflects it promptly. Safaricom's Business Till supports collections, withdrawals and reports through app and USSD; a Business Paybill is customer-initiated and can use an account number to identify a payer. Their identifiers are not interchangeable.

DataReportal counted 85.5 million cellular connections in late 2026 but 23.9 million internet users, while StatCounter placed Android at 94.91% of Kenyan mobile traffic in October 2026. The request belongs on your server, but confirmation must work on an ordinary Android handset and a constrained connection.

Daraja 3.0 expands the integration surface

Safaricom's Daraja 3.0 portal connects M-PESA APIs to web and mobile products. Its January 2026 update describes a cloud-native architecture, enhanced security and new Security APIs for fraud detection, prevention and identity verification. It also enables services inside the M-PESA Super App.

A newer platform does not remove the fundamentals: the team still needs a correct merchant setup, server-side credentials, a stateful ledger and a support process.

Choose the right M-Pesa payment flow

Start with the direction of money and the customer action, not with the SDK a developer finds first. Confirm the product, identifier and settlement treatment with Safaricom for the specific business model.

OptionWho initiates it?Typical useIntegration decision
STK Push / ExpressYour backend requests; the customer approvesCheckout, booking or orderWait for a validated outcome before fulfilment
C2BThe customer initiatesInvoice or account paymentMatch the Till or Paybill identifier, reference and expected amount
B2CThe business initiatesApproved payoutsApply validation, limits, approval and reconciliation
Till / PaybillThe merchant's receiving account defines the collectionPoint of sale or identified billsKeep the shortcode and account reference distinct
Native app or PWAYou control distributionDevice features, branded or web journeysUse a secure backend
M-PESA Mini AppThe customer opens it in the Super AppTask-focused serviceConfirm supported APIs during discovery

Choose the delivery surface separately

A native app, progressive web app and M-PESA Mini App are client surfaces, not payment rails. They can share the same backend, order model and reconciliation pipeline.

Choose native Android for deep device integration, offline behaviour or complex work. Choose a PWA for a lightweight, browser-first journey. Consider an M-PESA Mini App when distribution inside the M-PESA Super App is important and the required APIs are supported. Confirm needs such as notifications, location, camera, storage, offline behaviour or an external channel first.

Build a reliable transaction lifecycle

Separate the order from the payment attempt. The order knows what was sold and whether fulfilment is allowed; the attempt tracks the flow, references, provider ID, timestamps and state changes.

Make every request traceable

Give every logical payment attempt a unique internal reference and send the relevant account or merchant reference with the request. A network retry may reuse that attempt; a deliberate second payment needs a new reference. Never derive one only from amount or timestamp: two customers can pay the same amount together.

A sound request flow is:

  1. 1Lock the order and expected amount on your server.
  2. 2Create or retrieve the payment attempt with a unique reference.
  3. 3Request a provider token and submit the payment through the selected flow.
  4. 4Store the provider identifiers and show a neutral “payment requested” state.
  5. 5Update the order only after a validated provider outcome arrives.

The initial STK response or CheckoutRequestID confirms acceptance, not approval or settlement.

Validate callbacks and make processing idempotent

Providers may repeat a callback, and a retrying customer may create a second attempt. Either can duplicate an order, receipt or fulfilment without an idempotency rule.

For every callback, authenticate it using the current Daraja method, then compare the provider ID, merchant reference, expected amount and state with the payment attempt. Do not trust values merely because the body contains them. Enforce unique constraints on the provider transaction ID and merchant reference.

Record the event before changing the order, and make the transition safe to replay. A repeated valid callback must create only one receipt, entitlement or delivery. If the amount differs, quarantine the event for review instead of marking the order “paid.”

Recover missing callbacks and reconcile the ledger

A missing callback is not proof of failure. Safaricom describes the Transaction Status API as an asynchronous secondary reconciliation mechanism. Query it from the backend with sensible backoff, not from the app in a tight loop, and show the last confirmed state while the check continues.

Compare the provider report with your ledger by provider ID, merchant reference, amount, state, fees where provided and timestamp. Queue unmatched entries, duplicate references, amount differences, reversals and refunds separately. Customer reversals, provider timeouts and business-approved refunds are different events and need distinct states, owners and communication rules.

Secure the integration and go from sandbox to production

The app should never ask for, receive or store an M-PESA PIN. Keep Daraja credentials, tokens and production secrets on the server, inject them through a secrets manager, rotate them and keep them out of source code, crash reports and logs. Redact phone numbers, account identifiers and sensitive callback fields.

Use least-privilege access. Give staff refund or reversal permissions only when needed, require second approval for high-value actions and record who acted. Authenticate every status, export and administrative endpoint. Do not expose a payment checker that reveals whether another customer's reference exists.

Meet Kenya data-protection obligations

An integration may process phone numbers, account identifiers, orders, location, support messages and device metadata. The Data Protection Act 2019 and ODPC's 2025 MSME guidance therefore affect the architecture, not only the privacy policy. Document each lawful basis and purpose, minimise collection and separate optional analytics or marketing consent from payment processing.

Complete a Data Protection Impact Assessment for high-risk processing. ODPC's guidance says a controller must notify the Commissioner of a notifiable breach without delay and within 72 hours; a processor must notify the controller within 48 hours. Prepare an incident owner, evidence log and customer-communication runbook. If a cloud, analytics or support provider receives data outside Kenya, document the transfer and safeguards under ODPC's 2026 cross-border guidance.

Tax is transaction-specific. KRA's Digital Marketplace Supply guidance applies 16% VAT to covered supplies; do not hard-code it across every goods transaction, marketplace service or local service. Agree the model with a Kenyan adviser, then make receipts, invoices and exports follow it.

Use a staged go-live checklist

Before production traffic, test the complete lifecycle in Daraja's sandbox and a controlled production cohort:

  • Credentials and merchant setup: the environment, shortcode or Paybill, passkey, callback URL and token flow are correct.
  • State handling: approval, decline, timeout, unknown outcome, duplicate callback, amount mismatch and reversal behave safely.
  • Recovery: an asynchronous status query finds a transaction when the callback is delayed or missing.
  • Ledger integrity: retries cannot duplicate fulfilment, receipts or refunds, and daily reconciliation has an owner.
  • Security: no PIN is collected, secrets stay server-side, logs are redacted and refund permissions are controlled.
  • Compliance: the data map, lawful bases, retention rules, DPIA decision, transfer safeguards and breach process are approved.
  • Support: staff can explain pending, completed, failed, reversed and unknown states using the same transaction timeline shown to the customer.

Monitor acceptance, completion, callback latency, unmatched transactions, duplicate processing, reversals and support contacts. Release the next flow only when the current one is understood and reconciled.

How Zuxxis Helps Kenya Businesses

Zuxxis builds mobile products and the operational systems behind them. Our mobile app development team can deliver native Android and iOS apps or cross-platform experiences, with server-side M-Pesa integration, clear payment states and an operator-facing transaction timeline. Our UI/UX design team makes STK approval, pending states and receipts understandable on low-cost devices and can support English and Swahili journeys where the audience needs them.

For reconciliation, refunds and business reporting, our custom software and ERP service builds the order, payment-attempt and audit model. Our cloud and DevOps service secures deployment, secrets, monitoring and handover, while ecommerce can connect products, checkout and fulfilment when the business sells online.

We work as a senior-only, high-velocity partner with transparent and affordable pricing, flexible engagement models and measurable business outcomes. We begin with the transaction and compliance model, then ship the smallest release that proves it. Documentation, test evidence, ownership transfer and a maintenance plan are part of delivery, not an afterthought. Handover includes lifecycle diagrams, test cases and operating runbooks so your team can manage the integration confidently from launch. Book a free strategy call at https://zuxxis.in.

FAQ

How much does M-Pesa API integration cost?

Cost depends on the number of flows, merchant accounts, customer journeys, backend and ledger work, security, compliance, staff tooling and reconciliation. One checkout is not the same scope as a multi-tenant platform with B2C payouts and refunds. Ask for a scope stating code ownership, testing, handover and maintenance rather than an unsupported headline price.

Why is my M-Pesa API integration failing?

Check the environment and merchant credentials, then compare the request with the current Daraja documentation. Failure points include sandbox credentials in production, the wrong Till or Paybill identifier, an invalid reference or amount, an expired token, an unreachable callback URL and a timeout recorded as failure. Check the provider ID and final status before retrying. Never ask for a PIN, and make callbacks safe to replay.

Should we build a native app, PWA or M-PESA Mini App?

Choose native for deep device features, offline work or complex workflows; choose a PWA for a lightweight browser-first journey; and consider an M-PESA Mini App when Super App distribution is important. Confirm supported payment and Mini App capabilities first. All three can use the same secure backend and ledger.

Conclusion

M-Pesa API integration in Kenya succeeds when every payment is a traceable, replayable transaction rather than a successful button press. Select the correct flow, keep Till and Paybill identities distinct, validate callbacks, make updates idempotent, query asynchronous status when callbacks disappear and reconcile daily. Protect credentials and data, prove the lifecycle in sandbox, then release gradually. It is production-ready only when support, finance and engineering trust the same ledger. Book a free strategy call at https://zuxxis.in.

Z
Written By

Zuxxis Team

Principal Architect & Growth Director at Zuxxis, pioneering deterministic performance marketing and edge digital products.

Implement These Systems For Your Brand

Our embedded sprint team turns theoretical models into high-yielding acquisition campaigns and sub-second apps.