Skip to content
MCM TECH HUBSoftware · Web · Mobile · Cloud

M-Pesa Integration for Kenyan Businesses: A Practical Guide

By Daniel Muasa ·

Short answer: An M-Pesa integration lets a website, app or business system request and record mobile-money payments automatically. A reliable implementation must verify payment status on the server, handle delayed callbacks safely and reconcile transactions against the business record.

How an M-Pesa payment flow works

A typical online payment flow starts when a customer chooses a product or service and enters a phone number. The business system creates a payment request through an authorized integration, records a unique reference and waits for the provider's result. The customer completes the prompt on their phone, and the system updates the order only after it verifies the transaction result.

For Kenyan businesses using Safaricom's Daraja platform, credentials and access depend on the relevant account and product setup. Keep test and live credentials separate, and confirm the current onboarding and API requirements with Safaricom before implementation.

What a robust integration should handle

  • Server-side verification: Do not treat a browser redirect or screenshot as proof of payment.
  • Callbacks and delays: A customer may approve a prompt after the page is closed. Process provider callbacks and allow payment status to be checked again.
  • Duplicate notifications: Use unique transaction references and idempotent processing so a repeated callback cannot fulfill an order twice.
  • Clear statuses: Distinguish pending, successful, failed, cancelled and expired payments.
  • Reconciliation: Store transaction references and compare application records with provider statements and business accounts.
  • Secure credentials: Keep API secrets on the server in environment configuration, never in browser JavaScript or a public repository.

Test before taking live payments

Test successful, cancelled, timed-out and repeated payment scenarios. Confirm that the customer receives a clear result, staff can find the transaction, and a delayed response does not create an incorrect order status. Also test network failures and the procedure for investigating a payment that appears in one system but not another.

Common integration mistakes

Common problems include marking an order as paid before checking the provider response, losing the reference that links a payment to an order, storing credentials in source code, and failing to reconcile callbacks. Plan for these cases during design rather than relying on staff to correct every discrepancy manually.

Frequently asked questions

Can M-Pesa be added to an existing website?

Often, yes. First check the website's backend, checkout flow, hosting and the payment product requirements. The integration should be tested in a separate test environment before going live.

Should the website store a customer's M-Pesa PIN?

No. The customer authorizes payment through the provider's flow. A business website should not ask for or store the customer's M-Pesa PIN.

Why can a payment show as pending?

The customer may not have completed the prompt, a callback may be delayed, or a network issue may prevent an immediate update. Provide a safe status-check and reconciliation process.

See how we approach M-Pesa and payment integrations, or talk to our team about your checkout workflow.

Software developers collaborating in an office

Have a project in mind?

Tell us what you need and we will send a plan and a fixed quote within one business day.