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

How to Accept M-Pesa Payments on Your Website: A Step-by-Step Guide

If you sell to Kenyan customers online, M-Pesa is not a nice-to-have; for most shoppers it is the payment method they will actually use. The good news is that accepting M-Pesa on a website is more achievable than most owners expect. This guide gives you the realistic path from "we take payments by phone" to a working Pay with M-Pesa button, with the decisions you will face along the way.

What customers experience

At checkout the customer enters their phone number, receives an M-Pesa prompt on their handset, enters their PIN and the order confirms in seconds. There are no card details to type and no redirect to an unfamiliar third-party site. The mechanics are explained in Safaricom Daraja and STK Push explained.

Step 1: Have a website or store to take payments on

You need somewhere for the payment to happen. That might be a WooCommerce store, a custom shop, a booking form or just a simple payment page for invoices. A basic site on shared hosting is enough to begin; a store is better on eCommerce hosting. If you are starting from scratch, read how to start an online shop in Kenya.

Step 2: Register a paybill or till number

Customer payments land in a Safaricom paybill or till number registered to your business. Using a business shortcode rather than a personal number keeps payments organised, trackable and credible, and it is required to use the official API. Start this early because registration takes time and documents. Choose:

  • Till (Buy Goods): common for shops and retail.
  • Paybill: better when customers need to quote an account number, such as an invoice or student ID.

Step 3: Decide how you will integrate

RouteBest forTrade-off
Direct Daraja integrationStores with development support and meaningful volumeMore setup and maintenance; most control
Aggregator (such as PesaPal)Getting started fast, wanting cards and M-Pesa through one connectionAggregator fees; less control over checkout
Ready-made integration through your hosting or store builderMost small businessesLimited to what the provider supports

We compare the first two in PesaPal vs direct Daraja.

Step 4: Set up the checkout flow

  1. Show M-Pesa as the default option, with cards as a backup for customers who prefer them.
  2. Ask for the phone number in a field that accepts 07XX, 01XX, +254 and 254 formats and normalises them.
  3. Show a clear waiting message: "Check your phone and enter your M-Pesa PIN".
  4. Disable the pay button after the first click to prevent duplicate requests.
  5. Wait for the payment confirmation callback before marking the order complete.
  6. Offer a retry, and clear manual-payment instructions as a fallback.

Step 5: Test properly

Test the full flow, not just the happy path:

  • Successful payment.
  • Customer cancels the prompt.
  • Wrong PIN and insufficient funds.
  • Phone off or out of coverage.
  • Customer pays and closes the browser before the page updates.
  • Duplicate clicks and duplicate callbacks.

Most bugs hide in these edge cases. See common M-Pesa integration problems and fixes.

Step 6: Go live

Switch from the sandbox to production credentials and endpoints, confirm the callback URL is reachable over HTTPS, and make a small real payment to verify end-to-end. Check that the M-Pesa receipt number is stored against the order and that your accounts team can find it.

Step 7: Reconcile and report

Every payment should match an order automatically. Do not rely on someone scrolling through an M-Pesa statement. See how to reconcile M-Pesa payments with invoices.

Start small if you are just beginning

You do not need a full online store to accept your first online payment. A simple invoice or payment link with an M-Pesa prompt is already a big improvement over manual cash collection, and you can grow into a store afterwards. The start is mostly a shortcode and a simple page, not a big project.

Security and trust

  • Serve the whole site over HTTPS; see what an SSL certificate is.
  • Never ask customers to send their PIN anywhere. Legitimate checkouts only ask for the phone number.
  • Keep consumer keys and passkeys out of public code and version control.
  • Show clear contact details, refund terms and business information to build trust.

What does it cost?

Costs include your shortcode registration and Safaricom's per-transaction charges, any aggregator fees if you use one, and development time if you build it. Hosting for a small store is modest; see what hosting costs in Kenya. Many businesses find that the time saved on manual reconciliation pays for the integration quickly.

Frequently asked questions

Can I accept M-Pesa without a paybill or till?

You can ask customers to send money to a personal number, but it does not scale, is hard to reconcile and looks less professional. Use a business shortcode.

Can I accept M-Pesa and cards together?

Yes, and it is common. Make M-Pesa the default and add cards for international customers.

Will it work with WooCommerce?

Yes. WooCommerce has gateways that support STK Push, including aggregator plugins and Daraja-based plugins.

Can you set it up for me?

Yes. Our online shop design service and eCommerce hosting include working M-Pesa checkout from day one, or talk to us about the simplest route for your business.