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.

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
- Customer clicks Place order; the store creates a pending order.
- Your server requests an OAuth token, then posts an STK Push with the amount and phone number.
- Safaricom prompts the customer's handset for a PIN.
- A callback hits your
CallBackURLwith the result code and receipt number. - 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.
