Integrations8 April 2025· 11 min read· Enet Integrations Team9 views0 found this helpful

Integrating M-Pesa with WooCommerce: A Developer's Field Guide

Daraja STK Push, callbacks, reconciliation and the security mistakes that get merchants in trouble — written from real deployments.

Connected commerce and payment integration technology

M-Pesa is not an optional payment method in Kenya — it is the payment method. If your WooCommerce checkout does not support STK Push, you are asking customers to do extra work.

Choose the right product

Paybill, Till (Buy Goods) and C2B/B2C each behave differently in reconciliation. Register for credentials on the Safaricom Daraja portal and keep sandbox and production keys strictly separate.

The STK Push flow

  1. Customer clicks Place order; the store creates a pending order.
  2. Your server requests an OAuth token, then posts an STK Push with the amount and phone number.
  3. Safaricom prompts the customer's handset for a PIN.
  4. A callback hits your CallBackURL with the result code and receipt number.
  5. Only the callback — never the browser — marks the order paid.

Security essentials

  • Serve the callback over HTTPS with a valid certificate (SSL certificates).
  • Validate the amount and account reference server-side before completing the order.
  • Make the handler idempotent — duplicate callbacks are normal.
  • Log every raw payload for 90 days; disputes happen.

Reconciliation

Match by MpesaReceiptNumber, not phone number. Run a nightly job against the transaction status API to close orders whose callback was lost to a timeout.

Hosting matters

Callbacks fail on cheap oversold hosting. Run the store on managed WordPress hosting or a VPS with a static IP you can whitelist.

We ship ready-made plugins for WooCommerce, PrestaShop, OpenCart and WHMCS — see Enet integrations, or read the official WooCommerce gateway API docs if you are building your own.

Share this article

Was this article helpful?

Your vote helps us write better guides.

Need a hand implementing this?

Enet engineers in Nairobi handle migrations, SSL installs, M-Pesa and eTIMS integrations for you.

Launch today

Powering Your Online Success!

Domain, hosting, email and SSL from one local team — set up in minutes and backed by people you can call.

  • Free SSL
  • Free migration
  • 99.9% uptime
  • 24/7 expert support

Start with your domain

Check availability, then add hosting in the same order.

Prefer to talk? Call +254 726 872 512