How to Integrate M-Pesa Into Your Website: STK Push, Daraja and WordPress Explained
Integrating M-Pesa means connecting your till or paybill to your website through Safaricom's Daraja API, so customers pay from a prompt on their phone and orders confirm themselves. Here's how it works, what it costs and the mistake that loses money.
When people ask how to put M-Pesa on a website, they usually mean STK Push: the customer types their phone number at checkout, an M-Pesa prompt pops up on their phone, they enter their PIN, and the order is marked paid. That's built with Safaricom's Daraja API, connected to your own till or paybill.
What you need first
- An active Lipa na M-Pesa till or paybill in your business's name
- A Daraja account on Safaricom's developer portal, with an app created for your integration
- A website or system that can receive payment confirmations on a secure (HTTPS) callback address
- Your production credentials (consumer key, consumer secret and passkey), which Safaricom issues after go-live approval
How M-Pesa integration works, step by step
- Build and test in the Daraja sandbox using Safaricom's test shortcode
- Apply to go live and link your real till or paybill
- Your site sends an STK Push request with the amount and the customer's phone number
- The customer approves on their phone
- Safaricom sends a confirmation to your callback URL
- Your system checks the confirmation, then marks the order or invoice as paid and sends a receipt
The mistake that loses money
Never treat the STK Push request as proof of payment. The customer can cancel, have insufficient funds or close the prompt. Only the confirmation callback, checked against Safaricom's transaction status, proves the money arrived. Every 'paid but not paid' dispute we've been asked to fix came from a shortcut here.
M-Pesa on WordPress and Shopify
WooCommerce and Shopify have M-Pesa plugins and apps. They work for simple shops, but check who maintains the plugin, where your credentials are stored and whether it handles failed and duplicate callbacks. For bookings, school fees, rent or anything that needs payments matched to accounts, a custom integration is usually more reliable.
Mpesa integration cost
Safaricom doesn't charge for Daraja access. You pay the normal transaction tariffs on money received. The cost is in the build: the checkout, callback handling, reconciliation and receipts. Our M-Pesa payment automation starts from KSh 60,000, and online shops with M-Pesa checkout built in start from KSh 75,000.
Can I use STK Push with a till number?
Yes. STK Push works with both Buy Goods tills and paybills. The till or paybill must be linked to your Daraja app at go-live.
How long does M-Pesa integration take?
The code can be done in days. Safaricom's go-live approval and your shortcode setup usually add a few working days, so plan for one to two weeks end to end.
Why is my STK Push not working?
The usual culprits are wrong production credentials, a callback URL that isn't public HTTPS, an expired access token or a shortcode not linked to the app. Check the Daraja response codes first, because they tell you which.
Antony Mungai
Founder, Steff Cloud — building websites, systems and automation for Kenyan businesses from Nakuru.