Download the PHP package botnetdobbs/laravel-mpesa-sdk without Composer
On this page you can find all versions of the php package botnetdobbs/laravel-mpesa-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download botnetdobbs/laravel-mpesa-sdk
More information about botnetdobbs/laravel-mpesa-sdk
Files in botnetdobbs/laravel-mpesa-sdk
Package laravel-mpesa-sdk
Short Description Laravel M-Pesa Integration Package
License MIT
Informations about the package laravel-mpesa-sdk
Laravel M-Pesa Integration Package
Laravel package for integrating with Safaricom"s M-Pesa payment gateway. Supports STK Push, B2C, B2B, balance queries, transaction status checks, and payment reversals.
For the most current API documentation and updates, always refer to the Safaricom Developer Portal.
Requirements
- PHP 8.2+
Laravel Version |
---|
Laravel 10.x |
Laravel 11.x |
Installation
Install the package via Composer:
Publish the configuration file:
Configuration
Add the following variables to your .env
file:
More can be added as per the config file below.
Configuration Options
The published config file (config/mpesa.php
) contains the following options:
For the cerfiticate, Download under M-Pesa API Certificates.
Usage
STK Push (Lipa Na M-Pesa Online)
STK Push (check the status of a Lipa Na M-Pesa Online Payment.)
B2C Payment (Business to Customer)
B2B Payment (Business to Business)
B2B parameter naming convention is camelCase instead of PascalCase like the other endpoints on the Safaricom Developer Portal. Retained as is
C2B Register (Customer to Business)
C2B Simulate Payment (Sandbox Environment Only)
Account Balance Query
Transaction Status Query
Transaction Reversal
Response Handling
All methods return a standard Response with the following methods:
Example Usage
Error Handling
The package throws MpesaException
for various error scenarios:
Callback Handling
The package provides callback handling system for processing M-Pesa payment notifications.
Setup Callback Routes
Register the callback routes in your routes/api.php
:
Create Callback Controller
Create a controller to handle M-Pesa callbacks:
You can use the provided CallbackProcessor
which wraps the callback data in a TransactionResult object as shown below, or you can handle the raw data directly.
Available Callback Methods
Each callback type provides specific methods to access the payment data:
Common Methods Available in All Callbacks
The CallbackResponder
provides two methods:
success(string $message = 'Payment processed'): Responsable
- Returns a success response with ResultCode 0failed(string $message = 'Internal server error', int $statusCode = 500): Responsable
- Returns a failure response with ResultCode 1
Response Format: All responses are returned as JSON with the appropriate Content-Type header.
Success Response:
Failed Response:
For Contributors
This package includes comprehensive testing capabilities:
Running Tests
Run all tests
Coverage Reports
Generate HTML coverage report:
Then open coverage/index.html
in your browser.
Code Quality
Credits
- Lazarus Odhiambo
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-mpesa-sdk with dependencies
illuminate/http Version ^10.0|^11.0
illuminate/support Version ^10.0|^11.0