PixelBilling
M-Pesa & payments

How M-Pesa STK Push Works for ISP Payments

By The PixelBilling team · · 3 min read

STK push is the "enter your PIN" prompt that appears on a customer's phone. For an ISP it replaces typing paybill numbers and account numbers, which is where most payment mistakes happen.

The basic flow

  • Your system sends a payment request to Safaricom with the amount, the customer's phone number and your shortcode
  • The customer sees a prompt and enters their M-Pesa PIN
  • Safaricom processes the payment and sends the result to your callback address
  • Your system checks the result and activates the subscription

Why it helps

The amount and the destination are filled in for the customer, so there are no wrong account numbers and no typing errors. The payment is tied to a specific request, which makes matching it to the right customer and invoice straightforward.

What you need

You need your own paybill or till, a Daraja app with its consumer key, consumer secret and passkey, and a public https address that Safaricom can reach for the callback. Going live requires following Safaricom's process, which can change, so check the Daraja portal.

Good practice

Never mark a payment as paid because a customer says so. Confirm from the provider, compare the amount with what you asked for, and ignore repeated callbacks for the same receipt.

Behind the scenes, step by step

When your system asks for a payment, it first obtains a short-lived access token from Safaricom using your consumer key and secret. It then sends the request containing your shortcode, a password built from your shortcode, passkey and a timestamp, the amount, the customer's phone number and the address Safaricom should call back.

Safaricom answers immediately with an acknowledgement and a unique request identifier. That identifier is the key: when the final result arrives later, it carries the same identifier so your system can match it to the exact customer and invoice you created it for.

Phone numbers and amounts

M-Pesa expects phone numbers in international format, such as 2547XXXXXXXX. A good system converts the formats customers type, such as 07XX or +254 7XX, into the one Safaricom needs, and refuses numbers that cannot be right.

STK push amounts are whole shillings. If a plan price has cents, the prompt cannot be sent for the exact amount, so price plans in whole shillings or record such payments manually.

What can go wrong

  • The customer is out of coverage or their phone is off, so the prompt never appears
  • The customer cancels the prompt
  • The customer has insufficient funds
  • Your callback address is unreachable, so the result is never delivered
  • The shortcode or passkey is wrong, so the request is rejected

Designing for the failures

A reliable system treats an unanswered prompt as unknown, not as failed. It marks the request pending, lets staff check its status and times it out after a sensible period. It never activates a plan before the provider confirms success.

It also limits how often a customer can request prompts, so a mistake or a bad actor cannot flood a phone with requests.

Testing before you go live

Use the Daraja sandbox first with the test shortcode and credentials, and simulate full flows: success, cancellation and a timeout. Then test with a small real amount on your own phone in production before announcing it to customers.

What the customer sees

  • A prompt on their phone showing your business name and the amount
  • A PIN request
  • A confirmation message from M-Pesa
  • An updated plan in the portal moments later

How PixelBilling helps

PixelBilling sends the STK push from the portal or from staff, limits repeated prompts, and confirms the result through a secret callback address after verifying the amount.

Common questions

Does STK push work on every phone?

It works for Safaricom M-Pesa customers whose line and SIM support it. Offer vouchers or manual payment as an alternative.

What if the customer ignores the prompt?

The request ends without a payment. They can try again, and you can see the request status.

Can I use STK push without writing code?

Yes, if your billing software integrates Daraja. You supply your credentials and it handles the rest.

See PixelBilling with your own data

Start a free trial, import your customers and watch a payment turn into a connection. Or send us your questions.

Get Started Contact us