Download the PHP package ongudidan/mpesa-sdk without Composer
On this page you can find all versions of the php package ongudidan/mpesa-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ongudidan/mpesa-sdk
More information about ongudidan/mpesa-sdk
Files in ongudidan/mpesa-sdk
Package mpesa-sdk
Short Description This package seeks to help php developers implement the various Mpesa APIs without much hustle. It is based on the REST API whose documentation is available on http://developer.safaricom.co.ke.
License
Informations about the package mpesa-sdk
M-Pesa SDK for PHP
Overview
mpesa-sdk
is a lightweight PHP SDK that simplifies integration with Safaricom's M-Pesa Daraja API. It supports B2C, B2B, C2B, STK Push, reversals, transaction status, account balance, and more.
This SDK is framework-agnostic, meaning you can use it with Laravel, Symfony, Yii, CodeIgniter, or even plain/vanilla PHP.
π¦ Installation
Install via Composer:
βοΈ Configuration
You'll need:
- Consumer Key & Consumer Secret β from Safaricom Developer Portal
- An M-Pesa API User (Initiator) created from your Safaricom Business account
- Password for that Initiator
You can pass credentials directly in the data array or load them using environment variables/configuration.
π Usage Examples
β B2C (Business to Customer)
Send funds from your shortcode to a customer's phone.
πΌ Account Balance
Check your Paybill/Till balance.
π Transaction Status
Check the status of a transaction.
π’ B2B (Business to Business)
Send money from your organization to another.
π₯ C2B (Customer to Business Simulation)
Simulate a customer payment to your shortcode.
π² STK Push (Lipa Na M-Pesa)
Trigger a payment prompt on a customer's phone.
π‘ STK Push Query
Query the status of an STK Push request.
π Reversal
Reverse a transaction.
π Register Validation & Confirmation URLs
Register endpoints to handle C2B payments.
π₯ Handle Callback Data
Get Data from Callback:
Send Callback Response:
π₯ Handling M-PESA Daraja Callback Responses
To log the response from any M-PESA Daraja callback (e.g., C2B Confirmation
, C2B Validation
, STK Push
, etc.), you can use the following snippet in your callback.php
(or any relevant endpoint). This helps with debugging and record-keeping.
β Best Practices:
- Always log the full callback for reference during development and support.
- Use different log files per endpoint if needed, like
STKCallback.json
,C2BValidation.json
, etc. - Avoid exposing these logs publiclyβstore them securely or behind server-level access control.
π More Info
- Safaricom API docs: https://developer.safaricom.co.ke/
- Ensure your callback URLs are publicly accessible and accept POST data.
π Contributing
Pull requests and suggestions welcome! Letβs improve mobile money in PHP together.