99.9% Live Uptime Free .co.ke Domain on Business Plans →

M-Pesa Integration Problems and Fixes: STK Push, Callbacks and Go-Live Issues

M-Pesa integrations, like any payment system, run into predictable problems. Most of them fall into a handful of categories, and most can be diagnosed in minutes if you know where to look. This guide lists the problems we see most often, how to recognise them, and what actually resolves them.

First: where in the flow does it break?

An STK Push payment has four stages. Identifying the failing stage saves hours.

  1. Authentication: your server gets an access token from Daraja.
  2. Request: your server asks Daraja to send the prompt.
  3. Customer action: the prompt reaches the phone and the customer approves.
  4. Callback: Daraja posts the result to your server and your system updates the order.

Log the request and response at every stage, with timestamps. Most "mystery" problems become obvious once you can see them. For background, see Daraja and STK Push explained.

Problem 1: The customer paid, but the order is not marked paid

Almost always the callback. Safaricom sent the result, but your system did not receive or process it.

  • Check that the callback URL is publicly reachable over HTTPS and returns a 200 response quickly.
  • Check it is not blocked by a firewall, a security plugin or a "maintenance mode" page.
  • Check that the URL is not behind a login or a redirect.
  • Look in your server logs for the incoming POST. If it is absent, it is a reachability issue; if present, your script failed.
  • Make the handler robust: validate the payload, match the request ID, update the order and respond.
  • Use the transaction status query as a safety net for callbacks that never arrive.

Problem 2: The STK Push prompt never arrives

  • Phone number format: use 254XXXXXXXXX with no plus sign or spaces. Normalise 07XX and 01XX numbers before sending.
  • Credentials: expired, wrong or mismatched consumer key, secret, shortcode or passkey.
  • Wrong environment: sandbox credentials against the production URL, or the reverse.
  • Timestamp or password errors: the password is generated from the shortcode, passkey and timestamp; a wrong timestamp format breaks it.
  • Customer side: phone off, no network, SIM Toolkit issues or an older SIM that needs updating. Ask them to retry or to dial the manual paybill option.
  • Rate limiting: sending many requests in a short time.

Problem 3: Duplicate charges or duplicate orders

Customers click "Pay" repeatedly while waiting, or the callback is delivered twice.

  • Disable the button after the first click and show a waiting state.
  • Generate a unique reference per attempt and reject a second attempt while one is pending.
  • Make the callback handler idempotent: processing the same result twice must not credit twice.
  • Check the M-Pesa receipt number is unique before creating a payment record.

Problem 4: It works in the sandbox, but not live

This is the classic go-live mistake. Check:

  • Production consumer key and secret, not sandbox ones.
  • Production base URL and endpoints.
  • The live shortcode and the live passkey for that shortcode.
  • The callback URL has been updated to a public HTTPS address and not a local or test URL.
  • Your shortcode has been enabled for the API you are calling.

Problem 5: Amount or currency errors

  • M-Pesa only processes Kenyan shillings. Make sure the invoice is in KES before sending the request.
  • Send whole numbers. Round decimals according to your policy and keep the total consistent with the order.
  • Reject zero or negative amounts at your end.

Problem 6: Access token errors

  • Tokens expire after a short time, so request a new token when the old one is rejected rather than hard-coding one.
  • Check the authorisation header encoding: base64 of key:secret.
  • Check your server's clock and that outgoing HTTPS requests are allowed by your host.

Result codes you will often see

MeaningWhat to do
SuccessMark paid, store receipt
Request cancelled by the userOffer a retry
Insufficient balanceOffer another method or top-up guidance
Wrong PIN or too many attemptsLet the customer retry later
Timeout, phone unreachableRetry or fallback to manual payment

Use the current Daraja documentation for the exact codes, because they can be extended.

A quick debugging checklist

  1. Can you get an access token?
  2. Does the request return an accepted response with a checkout request ID?
  3. Did the phone receive the prompt?
  4. Did the callback arrive in your logs?
  5. Did your handler match it and update the order?
  6. Did the customer get a confirmation?

Preventing problems

  • Test the full journey, including failed, cancelled and delayed payments, before launch.
  • Monitor callback failures and alert on payments pending for more than a few minutes.
  • Keep a runbook for support: how to look up a transaction code and apply it to an invoice.
  • Reconcile daily; see reconciling M-Pesa payments with invoices.

Frequently asked questions

A customer says they paid but the order is pending. What now?

Ask for the M-Pesa transaction code, verify it on your statement, then apply it to the order manually or query the transaction status. Do not ask the customer to pay again until you have checked.

Can a host block Safaricom's callbacks?

Security tools and firewalls sometimes do. If callbacks never reach you, check with your host and security plugin. Contact us and we will check on our side.

Is it better to use a plugin or write custom code?

Use a maintained plugin where it covers your needs; custom code makes sense for bespoke flows. See PesaPal vs direct Daraja.