Skip to main content

Charged but Not Confirmed: Fixing M-Pesa STK Push Payment Gaps on Your Website

Charged but Not Confirmed: Fixing M-Pesa STK Push Payment Gaps on Your Website

A customer taps Pay on your website, gets the M-Pesa prompt, enters their PIN and receives a confirmation SMS from Safaricom. Your website, meanwhile, shows Payment failed or spins forever. The customer calls, frustrated and sure they have been cheated. Your team searches the M-Pesa statement, finds the money, and marks the order as paid by hand.

If this sounds familiar, the problem is rarely M-Pesa. It is almost always how the payment integration was built. This post explains why these gaps happen and what a well-built integration does differently, whether you run an online store, a school fee portal, a SACCO app or a county revenue system.

How an STK Push payment actually works

When your system uses Safaricom's Daraja API to send a payment prompt (often called STK Push or Lipa Na M-Pesa Online), the flow looks roughly like this:

  1. Your server asks Safaricom to send a prompt to the customer's phone.
  2. Safaricom immediately replies saying the request was accepted. This does not mean the customer has paid.
  3. The customer enters their PIN, cancels, ignores the prompt, or lets it time out.
  4. Safaricom sends the final result to a callback URL on your server.
  5. Your system updates the order based on that callback.

The weak point is step four. Many integrations assume the callback will always arrive, arrive quickly, and arrive exactly once. In the real world, none of those is guaranteed.

Why payments go missing between M-Pesa and your system

The callback never reaches you

If your server is down for a moment, your SSL certificate has expired, a firewall blocks the request, or the callback URL was mistyped during setup, Safaricom's result has nowhere to land. The customer has paid; your database never hears about it.

The callback arrives, but your code chokes on it

Callbacks for successful and failed payments are structured differently. Code that expects a receipt number on every callback can crash on a cancellation, or worse, crash on a success because of an unexpected field. The error gets logged somewhere nobody reads.

The page gives up too early

Some checkouts wait a fixed number of seconds and then declare failure. A customer who takes a little longer to find their phone or enter their PIN pays successfully after the website has already told them it failed. Many then try again, and you end up with a double payment and a refund to process.

Duplicate callbacks create duplicate orders

Occasionally the same result is delivered more than once. Without a check, your system may record two payments, issue two receipts or release stock twice.

Payments made outside the prompt

When the prompt fails, customers often fall back to paying your Paybill or Till directly. Those payments come through a different channel (C2B confirmation) and frequently carry a wrong or missing account reference. If your system only listens for STK Push results, these payments sit unmatched.

What a reliable M-Pesa integration does differently

1. Treats "pending" as a real state

An order should move from awaiting payment to pending confirmation to paid or failed. While pending, the customer sees an honest message such as We're confirming your payment, this can take a moment, not a premature failure. The page keeps checking quietly in the background.

2. Asks M-Pesa directly when the callback is late

Daraja provides a way to query the status of a transaction. A good integration does not just wait for the callback; if nothing arrives within a reasonable window, a background job queries the status and updates the order. The callback becomes one route to the truth, not the only one.

3. Handles every outcome, not just success

Cancelled by user, wrong PIN, insufficient balance, timeout, system busy: each has its own result code. Mapping them properly lets you show the customer a useful message (You cancelled the prompt, would you like to try again?) instead of a generic error, and lets your team see patterns in why payments fail.

4. Is idempotent

That is a technical word for a simple idea: processing the same callback twice should have exactly the same effect as processing it once. The system checks whether a receipt number has already been recorded before doing anything with it. No duplicate orders, no double stock deductions.

5. Listens to Paybill and Till payments too

By registering for C2B confirmations, your system also captures customers who pay manually. Smart matching then links them to the right order using the account reference, phone number, amount and timing, and flags anything uncertain for a person to review rather than guessing.

6. Reconciles against the statement every day

Even with all of the above, a daily reconciliation job comparing your records with the M-Pesa transaction data catches anything that slipped through. Exceptions appear on a short list for your finance team, instead of being discovered weeks later when a customer complains.

7. Logs everything, readably

Every request, callback and status query should be stored with timestamps. When a customer disputes a payment, your support team can see exactly what happened in seconds, without calling a developer.

Signs your current integration needs attention

  • Your team regularly marks orders as paid by hand after checking the M-Pesa statement.
  • Customers report being charged twice after a "failed" payment.
  • Month-end reconciliation always leaves a pile of unexplained M-Pesa receipts.
  • Nobody on your team knows where the callback URL points or who maintains it.
  • Payment problems spike after server changes, domain renewals or hosting moves.
  • You cannot easily tell how many payment attempts fail, or why.

Beyond M-Pesa: the same principles apply everywhere

Card payments, bank integrations and other mobile money services all share the same basic shape: request, asynchronous result, possible delays and duplicates. If you accept several payment methods, the same discipline of pending states, status checks, idempotency and daily reconciliation should apply to all of them, ideally through a single payments layer so your orders, invoices and receipts work the same way regardless of how the customer paid.

Fix it once, properly

Payment gaps are rarely dramatic. They show up as a few awkward phone calls a week, a bit of manual reconciliation, and a slow erosion of customer trust. But every customer who is told their payment failed when it succeeded is a customer wondering whether to buy from you again.

Let's look at your payment flow

At Glomex Technologies we build and repair payment gateway integrations for online stores, schools, SACCOs, hospitals, county systems and growing businesses, with M-Pesa handled properly from prompt to reconciliation. Whether you need a new integration or want us to review one that keeps misbehaving, talk to us about what you are seeing. We will help you work out where payments are slipping through and what it takes to close the gap for good.

Share this post

Know someone who'd enjoy reading Charged but Not Confirmed: Fixing M-Pesa STK Push Payment Gaps on Your Website?

Leave a Comment