Skip to content Skip to content

How to Add M-Pesa Payments to Your Website: 2027 Guide for Kenyan Businesses

A step-by-step guide to adding M-Pesa to your website: Paybill vs Till, Daraja API vs payment gateways, STK Push, going live, security and the mistakes that lose sales.

TTTechhoodlabs Team 7 min read
How to Add M-Pesa Payments to Your Website: 2027 Guide for Kenyan Businesses
In this article
  1. 1What does M-Pesa integration mean?
  2. 2Your three options for accepting M-Pesa online
  3. 3Paybill or Till number: which one do you need?
  4. 4What you need before you start
  5. 5How M-Pesa STK Push works
  6. 6Step-by-step: how to add M-Pesa with Daraja
  7. 7Security practices you should not skip
  8. 8Checkout design that increases paid orders
  9. 9Common M-Pesa integration mistakes
  10. 10How long does M-Pesa integration take and what does it cost?
  11. 11Planning for 2027
  12. 12Frequently asked questions
  13. 13Get M-Pesa working on your website

If you sell online in Kenya, customers expect to pay with M-Pesa. A website that only accepts cards or bank transfers loses sales at the last step. The good news is that adding M-Pesa is very doable. This guide explains your options, the steps for each, how to go live, and the mistakes to avoid, so you can plan your integration with confidence in 2027.

What does M-Pesa integration mean?

M-Pesa integration means your website asks the customer to pay and then automatically learns whether the payment succeeded. Instead of the customer sending money and then WhatsApping a screenshot, the site triggers a payment prompt on their phone, confirms the result and marks the order as paid. This saves you time, removes fraud and manual reconciliation, and makes checkout feel smooth.

Your three options for accepting M-Pesa online

  1. Direct Safaricom Daraja API. You connect your own Paybill or Till number to Safaricom through the Daraja developer portal. You have full control and the lowest per-transaction overhead, but it needs a developer and an approval process.

  2. A payment gateway or aggregator. Providers such as Pesapal, Flutterwave, IntaSend and Paystack offer M-Pesa together with cards and other methods. Setup is faster and support is included, but they charge their own fees. Check each provider’s current rates.

  3. A ready-made plugin. If you use WooCommerce or a similar shop platform, a plugin can connect your Daraja credentials or a gateway. It is quick, but you still need correct setup, testing and updates.

For a simple shop with low volume, a gateway or plugin is often the fastest start. For custom systems, high volume or special workflows such as bookings, subscriptions and invoices, a direct Daraja integration usually pays off. We build both on our eCommerce website service.

Paybill or Till number: which one do you need?

  • Till number (Buy Goods): suited to shops and businesses selling goods and services directly to customers.

  • Paybill: suited to businesses that need an account reference, such as school fees, rent, utilities, subscriptions and invoices.

Both can work with online payments. The choice affects what the customer types and how you match payments to orders. Safaricom’s charges differ between the two, so confirm the current tariff before you decide.

What you need before you start

  • A registered business with its documents, and a live Paybill or Till number that Safaricom has approved.

  • A website with HTTPS, because Safaricom sends payment results to public secure addresses.

  • An account on the Safaricom Daraja developer portal.

  • A developer or provider who can build and test the integration.

  • A clear list of how orders, stock and receipts should react to a successful or failed payment.

How M-Pesa STK Push works

Most websites use M-Pesa Express, often called STK Push. This is the flow:

  1. The customer fills in the cart and enters their phone number at checkout.

  2. Your server requests an access token from Daraja using your consumer key and secret.

  3. Your server sends the payment request with your shortcode, a timestamp, a password generated from your shortcode, passkey and timestamp, the amount, the customer’s phone number in the 2547XXXXXXXX format, an account reference and your callback address.

  4. The customer receives a prompt on their phone and enters their M-Pesa PIN.

  5. Safaricom sends the result to your callback address, including a result code. A result code of 0 means the payment succeeded.

  6. Your site confirms the payment, marks the order as paid, sends a receipt and updates stock.

Step-by-step: how to add M-Pesa with Daraja

Step 1: Create your Daraja account and sandbox app

Register on the Daraja portal, create an app and enable M-Pesa Express. The sandbox gives you test credentials and a test shortcode, so you can build safely without real money.

Step 2: Build and test in the sandbox

Build the payment request, the callback handler and an order status check. Test success, cancellation, wrong PIN, insufficient funds and no response. Log every request and callback.

Step 3: Prepare your production setup

Make sure your live site runs on HTTPS with a valid certificate, that your callback addresses are publicly reachable, and that your credentials are stored securely on the server and never in public code.

Step 4: Request to go live

On the Daraja portal, use the Go Live option and provide your live shortcode and business details. Safaricom reviews your request and may ask you to complete test cases or confirm details. When approved, you receive production credentials and your passkey, usually by email.

Step 5: Switch from sandbox to production

  • Change the base address from the sandbox to the production Daraja address.

  • Replace the test shortcode with your real Paybill or Till number.

  • Replace the sandbox consumer key, secret and passkey with your production ones.

  • Regenerate any security credential using the production certificate.

  • Run a small real payment end to end before announcing it.

Security practices you should not skip

  • Never trust the browser. Mark an order as paid only after your server receives and checks the callback or confirms the status with Safaricom.

  • Match the amount and reference. Check that the paid amount equals the order total and that the account reference matches the right order.

  • Make callbacks safe to repeat. The same callback can arrive twice. Use the transaction identifier so one payment never creates two receipts.

  • Keep secrets on the server. Store keys and passkeys in environment variables, restrict access and rotate them if staff leave.

  • Add a status check. If a callback does not arrive, query the transaction status so no paid order is left pending.

  • Log and reconcile. Keep payment logs and compare them with your M-Pesa statement every day.

Checkout design that increases paid orders

  • Accept phone numbers as 07XX, 01XX or 2547XX and convert them for the customer.

  • Show a clear waiting message such as “Check your phone and enter your M-Pesa PIN”.

  • Offer a retry button and a manual Paybill or Till fallback if the prompt fails.

  • Show the total in KES, including delivery, before the customer pays.

  • Send an SMS or email receipt immediately after payment.

  • Keep the checkout fast on mobile data, because slow pages lose customers before they pay. Our guide to website cost in Kenya explains why performance is part of a good build.

Common M-Pesa integration mistakes

  • Using a callback address that is not public or does not have valid HTTPS.

  • Marking orders as paid from the checkout page instead of the confirmed callback.

  • Forgetting to handle cancelled or timed-out prompts.

  • Leaving sandbox settings in the live site.

  • Not logging callbacks, so disputes cannot be traced.

  • Skipping a real low-value test payment before launch.

How long does M-Pesa integration take and what does it cost?

A gateway or plugin can be live in a few days once your accounts are ready. A custom Daraja integration usually takes one to three weeks including testing, plus Safaricom’s approval time, which depends on your documents and test results. Cost depends on scope, so a simple payment button is much cheaper than a full system with invoices and reconciliation. For ranges, see our guide to website costs in Kenya or request a quote.

Planning for 2027

  • Choose a developer who builds with the current Daraja portal, not outdated tutorials.

  • Plan for more than one payment method, so you can add cards or other wallets later.

  • Treat payment data under Kenya’s Data Protection Act: collect only what you need and publish a clear privacy policy.

  • Budget for monitoring and updates, as APIs and credentials change over time. Our website maintenance plans cover this.

Frequently asked questions

Can I add M-Pesa to my website without a developer?

Yes, if you use a payment gateway or a ready-made plugin for your platform. You still need to set up and test it carefully. A custom setup or special workflows need a developer.

Do I need a Paybill or a Till number?

Use a Till number for simple shop sales and a Paybill when you need an account reference, such as invoices, fees or subscriptions. Both can work online.

Is STK Push safe for customers?

Yes. The customer sees the amount and business name on their phone and approves with their own M-Pesa PIN. Your website never sees the PIN.

Why did the customer pay but the order stayed unpaid?

Usually the callback did not reach your site or was not processed. Use a status check and a daily reconciliation to catch these, and make sure your callback address is public and secure.

Can I test M-Pesa payments before going live?

Yes. The Daraja sandbox lets you test without real money. Before launch, also run a small real payment to confirm everything works in production.

Can I accept cards and M-Pesa together?

Yes. Payment gateways offer both in one checkout. A custom site can also add a card provider next to M-Pesa.

Get M-Pesa working on your website

We build online shops and business systems with M-Pesa, order emails and a fast mobile checkout. See our eCommerce service, compare packages on the pricing page, or contact us and we will advise whether a gateway or a direct Daraja integration suits your business.

Share this article
TT

Written by

Techhoodlabs Team

Practical advice on web design, SEO and business software for companies in Kenya, from the team at Techhoodlabs.

Get tips in your inbox

Short, practical updates for Kenyan business owners. No spam.

Keep reading

All articles

Trusted by