Payments

M-PESA STK Push explained: how Lipa na M-PESA Online works

How the M-PESA Express (STK Push) payment flow works through the Safaricom Daraja API, what developers need, callbacks, and common pitfalls.

By Oxflare Engineering2 min read

Updated

Mobile payment illustration

STK Push, also called M-PESA Express or Lipa na M-PESA Online, lets a website or app send a payment prompt directly to a customer's phone. The customer enters their M-PESA PIN, and the business is notified when the payment succeeds. It is the smoothest way to accept M-PESA online because the customer does not need to type a Paybill number or account reference.

The flow

  1. The customer enters their phone number at checkout.
  2. Your server requests an access token from Safaricom's Daraja API using your app's consumer key and secret.
  3. Your server sends an STK Push request containing your shortcode, a password built from the shortcode, passkey and timestamp, the amount, the customer's number, an account reference and a callback URL.
  4. Safaricom acknowledges the request with a CheckoutRequestID.
  5. The customer sees a prompt on their phone and enters their PIN.
  6. Safaricom sends the result to your callback URL. A result code of 0 means success and includes the M-PESA receipt number.
  7. Your system marks the order as paid and shows confirmation to the customer.

What you need

  • A Paybill or Till number with M-PESA Express enabled.
  • A Daraja developer account and an app approved for production.
  • A publicly reachable HTTPS callback URL.
  • Secure storage for your credentials and passkey.

Common pitfalls

  • Callbacks not arriving: the URL must be HTTPS, publicly reachable and respond quickly. Log every request.
  • Customer does not complete: prompts time out. Use the transaction status query to check, and let the customer retry.
  • Duplicate payments: make order updates idempotent so a repeated callback does not double-credit.
  • Reconciliation: match receipts to orders automatically and review exceptions daily.

Oxflare builds and hosts M-PESA integrations, including C2B, B2C and reconciliation. See our M-PESA integration service.

Related questions

Not answered here? Our team replies within one working day.

Ask a question
Can I test STK Push without real money?

Yes. Safaricom provides a sandbox environment with test credentials on the Daraja portal.

Put it into practice

Our team can set this up for you, or answer any questions.