Payments and Fintech

A practical guide to M-Pesa Daraja integration for Kenyan businesses

18 February 20266 min readBy Yagwa Tech Solutions

For any business selling online in Kenya, M-Pesa is rarely optional. Customers expect it as a payment option, and businesses that only offer card payments tend to see noticeably lower conversion at checkout. The technical path to offering it is the Daraja API, Safaricom's official integration layer for M-Pesa.

Daraja exposes several distinct products, and choosing the right one matters more than most teams expect going in. STK Push, formally Lipa Na M-Pesa Online, triggers a payment prompt directly on the customer's phone and is the standard choice for e-commerce checkouts. C2B, or customer to business, is built for scenarios where customers initiate payment themselves through a paybill or till number, common for utility style payments. B2C handles disbursements out to customers, relevant for refunds, payouts, or loan disbursements.

Getting credentials is the first practical step, requiring registration on the Safaricom developer portal and, for production access, a formal application process that includes business verification. This step alone can take longer than the development work itself, so it is worth starting early rather than leaving it until development is otherwise complete.

The integration itself involves handling asynchronous callbacks, which trips up more implementations than any other part of the process. Unlike a typical card payment flow where you get a synchronous response, STK Push requires your system to wait for a callback from Safaricom confirming success or failure, sent to a URL you provide. If that callback endpoint is not built to handle retries, timeouts, and duplicate notifications gracefully, businesses end up with orders marked as paid that were not, or paid orders never marked as complete.

Sandbox testing behaves differently from production in small but important ways, and teams that test only in sandbox sometimes encounter surprises during the production cutover. Test thoroughly in sandbox, but budget time for a careful, monitored first week in production as well.

Reconciliation is the part of M-Pesa integration most businesses underestimate before they have lived with it. Transaction references, callback timing, and partial failures all need a clear process for matching payments to orders, ideally automated rather than relying on someone manually checking statements at the end of each day.

Done properly, M-Pesa integration is a one time technical investment that removes a significant amount of friction from the buying experience for Kenyan customers. The businesses that get the most value from it are the ones that plan for the edge cases, callbacks, and reconciliation from the start, rather than treating it as a simple payment button to drop into an existing checkout flow.

Need help with something like this?

Our team is ready to talk through your specific situation.

Get a free quote
Chat with us