M-Pesa & Payments Integration for Kenyan Applications
Production M-Pesa Daraja integration — STK Push, B2C, C2B, USSD, callback handling, and reconciliation — built on Laravel, React/Next.js, and Flutter.
Most M-Pesa integration guides show you how to fire an STK Push and get a callback. Production is harder than that. What happens when the callback never arrives? What happens when a user pays but your system missed the confirmation? What do you do when Safaricom's API returns a timeout and you don't know if the transaction went through? I integrate M-Pesa Daraja into web and mobile applications — built on Laravel, React/Next.js, and Flutter — and build the reconciliation, retry, and logging infrastructure that keeps payments reliable, not just working in a demo.
STK Push — Lipa Na M-Pesa Online
STK Push lets your application initiate a payment request directly to a customer's phone. The user sees a prompt, enters their PIN, and the money moves. I implement the complete STK Push flow: initiating the request, storing the pending transaction with a reference, handling the callback Safaricom sends to confirm or reject, and giving users immediate feedback without polling.
Callbacks can arrive delayed, duplicated, or not at all. I implement idempotent handlers that process each transaction exactly once regardless of how many times the same callback arrives. Timeout checks flag transactions needing reconciliation when a callback has not arrived within a defined window. An admin dashboard lets your operations team see every transaction's current state and trigger the Safaricom Transaction Status API query for anything ambiguous.
B2C — Bulk Disbursements
B2C sends money from your M-Pesa business account to individual phone numbers. Common uses include paying suppliers, disbursing loans, sending agent commissions, and issuing refunds. I implement B2C with queue management for batches of hundreds or thousands of payments, per-transaction result tracking, and settlement reports your finance team can export directly.
B2C has its own failure taxonomy: insufficient balance, invalid phone numbers, per-transaction limits, and B2C API-specific error codes all need distinct handling. I build the notification layer so your operations team knows exactly which payments settled, which failed definitively, and which need manual investigation.
C2B — Paybill and Buy Goods Collection
C2B lets customers pay your Paybill or Till number through the standard M-Pesa menu and your system receives a notification. I register your confirmation and validation URLs with Safaricom, implement the validation logic that accepts or rejects incoming payments against your business rules, handle the confirmation webhook, and reconcile confirmed payments against your orders or invoices automatically.
USSD Integration
USSD gives feature-phone users access to services without internet — multi-level menu flows that work on any handset over a basic voice connection. I build USSD applications using Africa's Talking or Safaricom's direct USSD gateway, with the session state management that makes multi-level menus reliable: handling timeouts, invalid input, and dropped sessions so users are never left in an inconsistent state. Common use cases include e.g. loan applications, bill payment, account inquiries, and service confirmations.
Other Payment Gateways
Beyond M-Pesa, I integrate Stripe for international card payments and Paystack for broader African coverage. The same reconciliation-first approach applies regardless of the payment method.
What Good Payments Infrastructure Looks Like
Every payment event is logged with the full payload before it is processed. Webhooks are idempotent — processing the same event twice does nothing. Failed payments can be retried with exponential backoff where appropriate. Every transaction has an audit trail from initiation to settlement. A finance export to Excel or CSV can be built in. Alerts can be configured to fire when error rates exceed thresholds you set. None of this is optional — it is how production payments infrastructure needs to be built from day one.
How I Deliver This
Scope and sandbox setup
We define which payment flows you need and configure sandbox credentials to begin development immediately.
Core integration
Payment flows built and tested in sandbox with full callback handling, logging, and error taxonomy.
Reconciliation layer
Timeout handling, retry logic, Transaction Status API queries, and the admin dashboard for operations.
Go-live checklist
Production shortcode registration, IP whitelisting, callback URL verification, and Safaricom UAT sign-off.
Soft launch monitoring
First production transactions monitored closely. Operations team trained on the transaction dashboard.
Handover
Operations runbook, alert thresholds configured, and a support window agreed before I hand over.
Frequently Asked Questions
What I Can Build
- M-Pesa STK Push (Lipa Na M-Pesa Online)
- B2C bulk disbursements with batch management
- C2B Paybill and Buy Goods collection
- USSD menu application development
- Transaction reconciliation dashboard
- Idempotent callback and webhook handlers
- Stripe and Paystack integration
- Payment retry and timeout management
- Settlement reporting and CSV/Excel export
- Full transaction audit trail and logging
Tech Stack
Ready to start?
Tell me about your project and I'll outline a realistic scope and approach.
Get a QuoteRelated Work
Farmbid Africa Marketplace
Agricultural marketplace platform connecting farmers with buyers. Features include product listings, bidding system, and...
Completed
Vibo Africa Platform
Multi-vendor e-commerce platform with advanced filtering, cart management, and payment processing.
Completed: Sep 2024