A customer is ready to pay. They tap the button on your website, and what happens next decides whether you have the money today, tomorrow, or never.

On a lot of Kenyan sites, what happens next is a line of text: "Send to Paybill 123456 and WhatsApp us the code." It works, right up to the evening you are matching forty M-Pesa messages against forty orders, and one of them does not match anything.

There are three ways to take money online in Kenya. Most businesses need one or two of them, not all three. This guide shows which is which, how to set each one up, and the mistakes that leave paid orders sitting in your dashboard marked unpaid.

The short answer. If nearly all your customers are in Kenya, M-Pesa direct is the core of your checkout. Add a card gateway such as Pesapal when you also sell to the diaspora, to visitors, or to companies paying on a card. You can run both side by side at one checkout.

The Three Routes, Compared

RouteCustomers pay withMoney goes toBest for
M-Pesa direct, through Safaricom's Daraja APIM-Pesa, by a prompt on their phone (STK Push) or by paying your Paybill or TillYour own Paybill or TillBusinesses selling mostly to customers in Kenya
Pesapal, a payment gatewayM-Pesa, Visa and Mastercard, chosen on Pesapal's payment pageYour Pesapal merchant accountOne integration that covers mobile money and cards
A card gateway, such as Pesapal, Flutterwave or PayPalVisa, Mastercard and international cardsYour account with that gatewayDiaspora customers, tourists, and companies paying on a card

The difference that matters most is who sits in the middle. With M-Pesa direct, the money goes from the customer's M-Pesa to your Paybill or Till, and Safaricom is the only party taking a fee. With a gateway, the gateway takes the payment and passes it on to you, and it charges for doing so. You are paying for convenience: one integration, one dashboard, and cards included.

Which One You Need

Before You Start

Setting Up M-Pesa Direct

This is the route we recommend as the base of almost every Kenyan checkout. The customer taps Pay, a prompt appears on their phone, they enter their PIN, and your site marks the order paid on its own. No SMS forwarding, no reconciliation.

1. Get your Paybill or Till

The money needs somewhere to land. If you already take M-Pesa in a shop, you probably have one. Use the number that should receive website payments.

2. Create a Daraja account and an app

Daraja is Safaricom's API for developers, at developer.safaricom.co.ke. You create an account, then an app, which gives you the consumer key and secret your website uses to talk to M-Pesa.

3. Build it in the sandbox

The sandbox is Safaricom's test environment. Your site sends an STK Push request, a test prompt goes out, and Safaricom calls your callback URL with the result: paid, cancelled, wrong PIN, or timed out. Your site has to handle every one of those, not only the happy path.

4. Request go-live

Once it works in the sandbox, you apply to move to production, which links your real Paybill or Till to the app and issues live credentials.

5. Test with real money

Run real KES 1 transactions through your live Paybill before you tell a single customer. The sandbox does not behave exactly like live, and the only way to know money flows correctly is to watch it flow.

6. Let the callback do the reconciliation

Every successful payment triggers your own logic: mark the order paid, send the receipt, alert the team. That is the step that ends the evening of matching codes by hand.

For the technical detail, with a working code example, read how to add M-Pesa payments to your website. On WooCommerce specifically, the WooCommerce M-Pesa guide covers STK Push, Paybill and Till end to end.

Setting Up Pesapal

Pesapal is a Kenyan payment gateway. Your site sends the customer to Pesapal's payment page, the customer chooses M-Pesa or a card there, and Pesapal tells your site the result. Its current API is version 3.0, documented at developer.pesapal.com.

Pesapal, step by step

  1. Open a merchant account with Pesapal and complete its business verification. Pesapal tells you which documents it needs.
  2. Get your API credentials, the consumer key and consumer secret your website authenticates with.
  3. Build against the sandbox first, using Pesapal's test credentials.
  4. Register your IPN URL. IPN is the instant payment notification: the address on your site Pesapal calls whenever a payment's status changes. The API call is RegisterIPNURL.
  5. Submit the order. Your checkout sends the amount and order reference with SubmitOrderRequest, and the customer is taken to Pesapal to pay.
  6. Confirm before you mark it paid. When the notification arrives, ask Pesapal for the real status with GetTransactionStatus, then update the order.
  7. Switch to live credentials and run a real payment of your own, by M-Pesa and by card, before launch.

Pesapal also publishes official plugins for e-commerce platforms, listed on its developer site. A plugin saves building the API calls yourself. It does not save you the testing.

Adding Card Payments

Do not build card processing yourself. Let the gateway collect the card details on its own secure payment page. The card number never touches your server, which keeps most of the security burden with the gateway, where it belongs.

In practice that means one of three things:

At checkout the customer sees two or three clear options, M-Pesa first, and picks the one they have. Put M-Pesa first because that is what most Kenyan customers will use. A checkout that opens on a card form tells a local customer the shop was not built for them.

The Mistakes That Leave Orders Unpaid

Almost every broken payment we are asked to fix is one of these.

Marking the order paid on the redirect

The customer lands back on your "thank you" page, so the site marks the order paid. But a page load proves nothing. People close the tab, the phone loses signal, somebody types the URL. The only trustworthy signal is the callback from Safaricom or the gateway, confirmed against the provider's own record.

A callback the provider cannot reach

The payment succeeds and M-Pesa shows the money, but the order stays unpaid. Usually a security plugin, a firewall rule or a maintenance mode is blocking the provider's request to your callback URL, or the URL is plain HTTP. Test it from outside your own network.

Caching the checkout

Speed plugins that cache every page will cache the checkout and callback pages too. Exclude them. A cached callback answers every payment with the same stale response.

Testing only in the sandbox

The sandbox passes, launch day fails. Always run real transactions on the live account before customers do.

No plan for the customer who ignores the prompt

People miss the STK prompt, enter the wrong PIN, or are on a call when it arrives. Show a clear "did not get the prompt? Try again" button, and offer Paybill as a fallback, instead of leaving them staring at a spinner.

Keep your credentials out of your theme. A consumer secret pasted into a theme file, or committed to a public code repository, lets someone else call the payment API as you. Store keys in configuration outside the web root, and rotate them if they have ever been exposed.

What It Costs

ItemWho charges itAmount
M-Pesa integration, fully done for youWPfossKES 1,000 per year, all-inclusive
Transaction charges on your Paybill or TillSafaricomSafaricom's current business tariff
Gateway charges on Pesapal or card paymentsThe gatewaySet by the gateway. Pesapal does not publish its merchant rates on its homepage, so ask when you sign up
A new online shop with payments built inWPfossFrom KES 50,000 (up to 30 products)

The KES 1,000 a year covers STK Push, Paybill and Till confirmations, B2C payouts, reconciliation and reporting, Daraja registration with Safaricom, live test transactions, and ongoing support for the year. It is a flat fee, not a cut of every transaction. Most integrations go live within 5 to 10 working days, and more complex setups take 2 to 4 weeks.

Adding Pesapal or a card gateway to an existing site is quoted for the job, because it depends on the platform you run. If you are building a new shop, see what an e-commerce website costs in Kenya.

Frequently Asked Questions

What is the best payment gateway in Kenya?

It depends on who pays you. If nearly all your customers are in Kenya, M-Pesa direct through Safaricom's Daraja API is the core of the checkout. If you also sell to people abroad or to companies paying by card, add a card gateway such as Pesapal or Flutterwave. Many stores run M-Pesa direct and a card gateway side by side.

Can I accept M-Pesa and card payments on the same checkout?

Yes. Either run M-Pesa direct and a card gateway as two payment options at one checkout, or use one gateway such as Pesapal that takes both M-Pesa and cards on its own payment page.

Do I need a Paybill or Till number to accept M-Pesa on my website?

For M-Pesa direct, yes. You need a Paybill, a Till Number, or a Daraja API merchant account from Safaricom. We can register the Daraja account on your behalf or work with what you already have.

How long does M-Pesa integration take?

Most of our integrations go live within 5 to 10 working days. More complex setups with custom reconciliation, B2C payouts or multi-account routing take 2 to 4 weeks.

How much does Pesapal charge per transaction?

Pesapal does not publish its merchant rates on its homepage, so ask Pesapal for current pricing when you open a merchant account. Compare that against Safaricom's own tariff on your Paybill or Till before deciding which payments go through which route.

Is it safe to take card payments on my website?

Yes, when the gateway collects the card details on its own secure payment page. The card number never touches your server, which keeps most of the security burden with the gateway rather than with you.

What does M-Pesa integration cost with WPfoss?

KES 1,000 per year, all-inclusive. That covers STK Push, Paybill and Till confirmations, B2C payouts, reconciliation, Daraja registration, live test transactions and ongoing support. It is a flat annual fee, not a cut of every transaction.

Stop matching M-Pesa codes by hand

Tell us what your site runs on and how your customers pay. We will wire M-Pesa into it properly, add cards if you need them, and test with real money before a single customer sees it. Talk to us on WhatsApp at +254 722 334 188, email hello@wpfoss.ke, or call +254 709 384 200.

Add M-Pesa for KES 1,000 a Year

Related: E-commerce Websites · Safaricom Daraja · Pesapal · Pesapal API · Flutterwave · PayPal · WooCommerce