Blog β€Ί Operations

How to Integrate M-Pesa Into Your Website (2026): STK Push, Daraja API and Payment Gateways

Websites Updated 2026-10-20 Β· 7 min read
M-PESA and Equity agent shop front in Kenya

Photo: M-PESA mobile money and Equity agent, Nairobi, Kenya by wrcomms, CC BY-SA 2.0. Cropped.

To integrate M-Pesa into your website, you need a Safaricom Till or Paybill in your business name and one of two routes: (1) connect directly to Safaricom's Daraja API and use STK Push, so customers get a PIN prompt on their phone and your site confirms payment from Safaricom's callback; or (2) use a payment gateway such as Paystack, Pesapal or Flutterwave, which handles M-Pesa and cards through one integration. Either way, an order should only be marked paid after a verified callback from Safaricom or the gateway.

Key takeaways

Why M-Pesa on your website matters

For Kenyan customers, M-Pesa is the default way to pay. A website that only offers "send money to this number and WhatsApp us the code" loses customers at the last step and creates manual matching work for your team. An integrated checkout lets customers pay in seconds, confirms the order automatically and records the payment against the right customer, which is essential for e-commerce, bookings, deposits and invoices.

What you need before you start

  1. A registered business and KRA PIN.
  2. A Safaricom Till (Buy Goods) or Paybill in the business name. Paybill is better if customers pay invoices or need an account reference.
  3. A website on HTTPS with a server that can receive callbacks (not a static site with no backend).
  4. A developer account on Safaricom's Daraja portal, if you integrate directly.

Route 1: Direct Daraja API integration (STK Push)

STK Push ("Lipa na M-Pesa Online") is what Kenyan shoppers expect: they enter their phone number, a prompt appears on their phone, they enter their PIN, and the website confirms the payment.

How it works, step by step

  1. Create an app on the Daraja portal to get a consumer key and secret, and get your shortcode and passkey from Safaricom when you go live.
  2. Get an access token: your server requests an OAuth token from Daraja (valid for about an hour) using the key and secret.
  3. Send the STK Push request with the amount, the customer's phone number, your shortcode, a timestamp, an encoded password and a callback URL, plus an account reference such as the order number.
  4. The customer enters their PIN on their phone.
  5. Safaricom calls your callback URL with the result: success with an M-Pesa receipt number, or a failure such as a cancelled prompt or insufficient funds.
  6. Your server marks the order paid, saves the receipt number, and the page updates for the customer.

Pros and cons

Route 2: Payment gateways

Gateways such as Paystack, Pesapal, Flutterwave and DPO offer M-Pesa plus Visa/Mastercard through one integration, often with ready-made WooCommerce and Shopify plugins.

Direct DarajaPayment gateway
Setup effortHigher (developer)Lower (plugin or SDK)
Card paymentsSeparate integrationIncluded
FeesM-Pesa merchant charges onlyGateway fee per transaction on top
SettlementStraight to your till/paybillVia the gateway, on its schedule
Best forHigh M-Pesa volume, custom systemsFast launch, diaspora/card customers

Many stores use both: Daraja STK Push for M-Pesa and a gateway for cards.

M-Pesa on WordPress and WooCommerce

WooCommerce has several M-Pesa plugins (some direct Daraja, some via gateways). Before installing one, check it is actively maintained, supports STK Push with callback confirmation, handles failed and duplicate callbacks, and comes from a reputable developer. Avoid nulled (pirated) plugins entirely: payment code is the last place you want malware. On Shopify, M-Pesa usually comes through third-party payment apps or gateways.

Paybill account numbers for invoices and fees

If customers pay invoices, school fees, rent or instalments, use a Paybill with an account number (invoice number, admission number, plot number). Daraja's C2B API sends each payment to your system, which matches the account number to the customer automatically. That's what makes reconciliation automatic. See our guide to M-Pesa reconciliation.

Security essentials

Testing before launch

  1. Build and test in the Daraja sandbox with test credentials.
  2. Test failure cases: cancelled prompt, wrong PIN, timeout, duplicate callback.
  3. Apply for go-live, switch to production keys and your live shortcode.
  4. Make several small live payments (e.g. KES 10) and confirm the receipt numbers match.
  5. Check that confirmation emails or WhatsApp messages reach customers.

How much does M-Pesa website integration cost?

Costs have three parts: development (from a plugin setup to a custom Daraja integration with reconciliation), Safaricom's transaction charges (which vary by till or paybill and agreement, so confirm current tariffs with Safaricom), and any gateway fees. In our estimator, M-Pesa payments with automatic reconciliation are a $300 add-on to a website, and they're included in our e-commerce builds.

Common problems and fixes

ProblemLikely causeFix
Customer paid but order still pendingCallback not reaching your serverCheck the callback URL is public HTTPS; add status-query fallback
"Invalid access token"Expired tokenRequest a new token before each call or cache it for under an hour
STK prompt never arrivesWrong phone format or Safaricom delayUse 2547XXXXXXXX format; allow retry
Duplicate payments recordedCallback retriedDeduplicate by receipt number

Designing a checkout customers trust

The integration is only half the job; the checkout screen decides whether people complete payment. Show the total in shillings, explain that a prompt will appear on their phone, pre-fill their number if they're logged in, and show a clear "Waiting for your M-Pesa PIN…" state that updates automatically when payment confirms. Offer a fallback ("Pay to Paybill 123456, account INV-0042") if the prompt doesn't arrive. These small details noticeably reduce abandoned payments.

USD prices and M-Pesa

M-Pesa transactions are in shillings. If your prices are in dollars, as for export products or international services, convert to KES at checkout using a published rate and round up, then store the payment in both currencies for your books. Show the customer the KES amount before the PIN prompt to avoid surprises.

Beyond checkout: what integrated M-Pesa unlocks

Our own CRM uses exactly this flow: quotes accepted online become invoices with M-Pesa STK Push, and payments mark themselves paid.

Who should build your integration?

If you run WooCommerce with modest volume, a reputable plugin set up by your web developer is usually enough. If payments are central to your business (instalments, invoices, high volumes or several channels), invest in a proper Daraja integration with reconciliation and reporting, built by a developer who has shipped M-Pesa systems before and can show you live examples.

Next step

If you sell online, take deposits or send invoices, integrated M-Pesa pays for itself quickly in saved admin and fewer lost sales. See our e-commerce website design service, or talk to us about adding M-Pesa to your existing site.

Frequently asked questions

How do I integrate M-Pesa into my website?
Get a Till or Paybill in your business name, then either integrate Safaricom's Daraja API with STK Push and a server callback, or use a payment gateway such as Paystack or Pesapal that supports M-Pesa. Only mark orders paid after a verified callback.
What is the Daraja API?
Daraja is Safaricom's developer platform for M-Pesa. It provides APIs for STK Push payments, C2B and B2C transactions, transaction status and account balance queries.
Can I use M-Pesa on WordPress or WooCommerce?
Yes, through maintained M-Pesa plugins or payment gateway plugins. Choose reputable, actively updated plugins that use STK Push with callback confirmation, and never use pirated plugins.
Is Paybill or Till better for a website?
A Till works well for simple checkout. A Paybill is better when customers pay invoices, fees or instalments, because the account number lets your system match each payment automatically.
How long does M-Pesa integration take?
Development can take days, but Safaricom onboarding and go-live approval often take several business days, so start the paperwork early.
Is M-Pesa integration secure?
Yes, when built correctly: keys stored on the server, HTTPS callbacks protected by a secret, payments confirmed server-side and duplicate callbacks ignored.

Want this built for your business?

Kavenacc Digital Solutions builds custom AI dashboards, AI agents and web apps in days β€” with a free working prototype in 7 days and 100% ownership of the code.

Start My Free Prototype β†’

Written by Narkisho Nyonje β€” Founder, Kavenacc Digital Solutions. 26 years in IT & software, 50+ applications shipped, author of β€œThe Future of Work in the New AI Era” (Amazon / Barnes & Noble). Get a free 7-day working prototype of your own AI system.

Explore Kavenacc services & pricing β†’

Chat with a Real Personon WhatsApp
Get a quote WhatsApp (opens in a new tab) Call