Back to projects
Live Store

Smart World Kenya Tech Store

M-Pesa-Integrated Electronics E-Commerce Platform

PHPLaravelM-Pesa APIE-CommerceMySQLREST API
Products Listed
2K+SKUs
M-Pesa Transactions
15K+processed
Payment Success
98.5%
Avg Checkout Time
<90sec

E-commerce platform for electronics and smart devices tailored for Kenya, featuring M-Pesa mobile payment integration, product filtering, and dispatch tracking. Handles the operational realities of mobile-money callback delivery being unreliable.

Architecture & System Design

Checkout initiates an M-Pesa Daraja STK push, with an idempotent callback handler and a scheduled reconciliation job covering any callbacks that never arrive. Dispatch status is surfaced to customers through webhook-driven order updates.

Request Flow
Product Browse
Cart
Checkout
M-Pesa STK Push
Idempotent Callback Verification
Order Confirmation
Dispatch Tracking
  • M-Pesa Daraja STK Push integration with idempotent, verified callback handling
  • Scheduled reconciliation job for transactions with missing or delayed callbacks
  • Faceted product filtering across category, brand, and price attributes
  • Webhook-driven dispatch tracking surfaced directly on the order page

Engineering Challenges

Unreliable M-Pesa Callback Delivery

Problem

M-Pesa callback delivery is not guaranteed, occasionally leaving payments in an unconfirmed state despite the customer being charged.

Solution

Built a polling fallback alongside the idempotent callback handler, plus a scheduled reconciliation job that queries transaction status directly when callbacks don't arrive.

Result

Payment confirmation reliability improved to 98.5% of transactions.

STK Push Timeout & Cancellation UX

Problem

Customers frequently missed or cancelled the STK push prompt on their phone, leaving checkout stuck with no clear feedback.

Solution

Implemented real-time status polling on the checkout page with timeout detection and a one-tap retry prompt.

Result

Checkout abandonment at the payment step was noticeably reduced.

Order Visibility for Customers

Problem

Customers had no visibility into dispatch status after payment, generating a high volume of support inquiries.

Solution

Wired dispatch status webhooks directly into the order detail page with real-time status updates.

Result

"Where is my order" support tickets dropped by roughly 50%.

Core Features

M-Pesa STK Push Checkout

Mobile-money checkout with idempotent callback verification and status reconciliation.

Clean Code

MpesaStkService — Daraja STK Push Integration
1<?php
2
3namespace App\Services;
4
5use Illuminate\Support\Facades\Http;
6
7class MpesaStkService
8{
9 public function push(string $phone, float $amount, string $orderRef): array
10 {
11 $timestamp = now()->format('YmdHis');
12 $password = base64_encode(
13 config('mpesa.shortcode') . config('mpesa.passkey') . $timestamp
14 );
15
16 return Http::withToken($this->accessToken())
17 ->post(config('mpesa.stk_url'), [
18 'BusinessShortCode' => config('mpesa.shortcode'),
19 'Password' => $password,
20 'Timestamp' => $timestamp,
21 'TransactionType' => 'CustomerPayBillOnline',
22 'Amount' => $amount,
23 'PartyA' => $phone,
24 'PartyB' => config('mpesa.shortcode'),
25 'PhoneNumber' => $phone,
26 'CallBackURL' => route('mpesa.callback'),
27 'AccountReference' => $orderRef,
28 ])->json();
29 }
30}