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.
Updated
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
- The customer enters their phone number at checkout.
- Your server requests an access token from Safaricom's Daraja API using your app's consumer key and secret.
- 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.
- Safaricom acknowledges the request with a CheckoutRequestID.
- The customer sees a prompt on their phone and enters their PIN.
- Safaricom sends the result to your callback URL. A result code of 0 means success and includes the M-PESA receipt number.
- 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.
