Learn how Kenyan businesses can accept M-Pesa payments on their website using STK Push and the Daraja API, from setup and security to common pitfalls.

Most Kenyan customers would rather pay with M-Pesa than enter a card number online. If your business website only accepts cards or bank transfers, you are asking customers to take an extra step, and many will leave before they finish. Adding M-Pesa checkout to your website is one of the most practical upgrades a Kenyan business can make.
This guide explains how M-Pesa payments work on a website, what you need before you start, and how to avoid the mistakes that cause failed or unconfirmed payments.
The most common method for online M-Pesa payments is STK Push, also called Lipa Na M-Pesa Online. Here is the basic flow:
1. The customer enters their phone number on your checkout page and confirms the order. 2. Your server sends a request through the Safaricom Daraja API asking M-Pesa to send a payment prompt to that phone. 3. The customer receives a pop-up on their phone and enters their M-Pesa PIN to approve the payment. 4. Safaricom sends the result of the transaction to a callback URL on your server. 5. Your website marks the order as paid, or as failed, based on that result.
The key point is that the customer never sends money to a number they have to type in manually. The prompt does the work, which reduces errors such as wrong amounts or missing account references.
Before writing any code, gather the following:
Start in the Daraja sandbox. It lets you test the full flow with test credentials and simulated phone numbers before real money is involved. Moving to production requires Safaricom's go-live process, so plan for that time in your launch schedule.
A typical integration has three backend pieces.
1. Get an access token. Daraja uses OAuth. Your server sends your consumer key and secret to the authentication endpoint and receives a temporary access token. Cache the token and refresh it when it expires rather than requesting a new one for every payment.
2. Send the STK Push request. Your server builds a request containing the business shortcode, the transaction type, the amount, the customer's phone number in the international format (254 followed by nine digits), an account reference such as the order number, a short transaction description, and your callback URL. The password field is built by combining the shortcode, the passkey, and a timestamp, then encoding the result in Base64. Daraja's documentation includes the exact format, and following it carefully prevents most authentication errors.
3. Handle the callback. When the customer completes or cancels the payment, Safaricom posts the result to your callback URL. Your endpoint should:
It is also wise to build a query endpoint that checks the status of a transaction. Callbacks can occasionally be delayed or missed, so a scheduled check on orders stuck in a pending state keeps your records accurate.
The technical integration is only half the job. The customer experience determines whether people complete their payment.
A few errors cause most problems with M-Pesa website payments:
You can build an M-Pesa integration in-house if you have a developer comfortable with server-side APIs. However, payment flows touch money and customer trust, so mistakes are costly. At Mycrea, we typically handle the Daraja setup, callback reliability, order reconciliation, and testing as part of a broader e-commerce or web application build. That includes connecting M-Pesa to your inventory, invoicing, and customer notifications so the payment is not a standalone feature.
If your business already runs on a website, adding M-Pesa checkout is usually faster and cheaper than most owners expect, especially when the integration is planned from the start.
Before you go live, confirm that:
M-Pesa can make your website feel local and trustworthy to Kenyan buyers. With a careful setup, it can also reduce abandoned checkouts and give your team reliable payment records from day one.
Tell us about your project. We'll show you what's possible.