M-PESA API Package

Comprehensive PHP package for integrating with Safaricom's M-Pesa DARAJA API

Features

Complete API Coverage

All M-Pesa endpoints including B2Pochi and STK Status

Hierarchical Configuration

Intelligent fallbacks for nested settings

Universal Callbacks

Centralized logic for STK, C2B, and result notifications

Smart Defaults

Pre-configured Safaricom command IDs and response types

Robust Validation

Command-aware field pruning and detailed error reporting

Framework Agnostic

Works with any PHP project, sandbox and production ready

API Methods

STK Push

Initiate payment requests directly to customer phones

STK Status Query

Check the status of STK Push requests

B2C Payments

Send money from business to customer accounts

B2B Transfers

Transfer funds between business accounts

B2Pochi

Send money to customer Pochi savings accounts

C2B Register & Simulate

Register URLs and simulate customer payments

Transaction Status

Query status of any M-Pesa transaction

Account Balance & Reversal

Check balance and reverse erroneous transactions

Installation

# Install via Composer
composer require yourdudeken/mpesa

Quick Start Example

<?php
require "vendor/autoload.php";

use Yourdudeken\Mpesa\Init as Mpesa;

$mpesa = new Mpesa();

$response = $mpesa->STKPush([
  'amount' => 100,
  'phoneNumber' => '254722000000',
  'accountReference' => 'ORDER-123'
]);

Documentation

Ready to Integrate M-Pesa?

Start accepting mobile payments in minutes