Custom WooCommerce payment gateway for KCB M-Pesa STK Push API.
# π³ KCB M-Pesa Express WooCommerce Gateway
> A production WordPress plugin enabling KCB M-Pesa STK Push payments in WooCommerce stores across Kenya and East Africa. Free core + Pro tier with extended features.
**Why this exists:** KCB's M-Pesa Express API is widely used in Kenya but has no official WooCommerce integration. This plugin fills that gap with a clean, extensible implementation.
---
## Features
### Free
- β
Full STK Push payment flow at WooCommerce checkout
- β
Secure OAuth2 token generation with KCB API
- β
Real-time callback handling β automatic order status updates
- β
Admin callback log dashboard (view, download, clear)
- β
Email alerts on payment failures
### Pro
- π License key activation system
- π CSV export of payment logs
- π£ Slack / Telegram payment notifications (planned)
- π¨ Advanced checkout UI customisation
---
## Architecture
```
kcb-mpesa-gateway/
βββ admin/
β βββ logs-ui.php # Admin log dashboard
βββ includes/
β βββ class-gateway-base.php # Abstract base β extensible for other M-Pesa providers
β βββ class-gateway-free.php # Free tier implementation
β βββ class-gateway-pro.php # Pro tier with licence check
βββ pro/
β βββ class-license-manager.php
βββ kcb-mpesa-gateway.php # Plugin entry point
βββ init_kcb-mpesa-gateway.php # Gateway registration + callback endpoint
```
**Design decisions:**
- Abstract base class (`class-gateway-base.php`) makes it straightforward to extend for other KCB payment products or M-Pesa providers
- Callbacks are logged to a flat file (`wp-content/mpesa-callback-log.txt`) β avoids DB write overhead during high-volume payment events
- Token generation is handled per-request with short TTL β avoids stale token issues that plague many community implementations
---
## Installation
1. Upload to `/wp-content/plugins/kcb-mpesa-gateway`
2. Activate via **Plugins** in WordPress admin
3. Go to **WooCommerce β Settings β Payments** β enable **KCB M-Pesa**
4. Enter you β¦