M-PESA is the default way Kenyans pay online, and integrating it well is less about the first payment than about everything that happens around it. This is how the pieces fit, in plain language.

The two main patterns

1. STK push (express checkout)

Your website or app asks the M-PESA API to send a confirmation prompt to the customer's phone. The customer enters their PIN, and the API confirms the payment to your server. This is the smoothest flow, no copying of paybill numbers, and the right default for e-commerce checkouts and app payments.

2. Paybill / Till number flow

The customer pays manually to your paybill, and your system receives a notification of the transaction. You then match the payment to an order. This flow survives where STK push cannot run (feature phones, some USSD journeys), but matching is your job, reference design matters.

The part everyone underestimates: callbacks

The payment request is the easy half. The important half is the callback: the message M-PESA sends to your server when money actually moves. Production-grade integration means:

  • A public, stable callback URL that accepts the notification, verifies it, and answers quickly.
  • Idempotent processing: the same callback may arrive twice; your records must treat it as one payment.
  • A timeout path: customers who never enter the PIN must release their carts and get a clean retry.
  • A reconciliation report: payments requested versus payments confirmed, reviewed daily, with a manual-match queue for edge cases.

Security and trust details

Store API credentials outside the public web root, use a dedicated credentials user, log every request-response pair (with personal data handled carefully), and never mark an order paid on the browser's word alone, only the server-side confirmation counts. Test in the sandbox with the real failure cases: cancelled PIN, insufficient funds, network timeout.

Choosing the right shape for your business

  • Online shop: STK push at checkout, paybill as fallback, automated confirmation emails/SMS.
  • Bookings and fees: STK push with references that encode the account, so reconciliation is automatic.
  • Donations or variable amounts: paybill flow with a short unique code per intention, matched on callback.

M-PESA integration is a workflow problem as much as a code problem. If you are planning one, talk to us: we build integrations with the callback and reconciliation discipline described here, and we are happy to review an existing one for gaps.