Download the PHP package apelimpesa/mpesa-php without Composer
On this page you can find all versions of the php package apelimpesa/mpesa-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download apelimpesa/mpesa-php
More information about apelimpesa/mpesa-php
Files in apelimpesa/mpesa-php
Package mpesa-php
Short Description A comprehensive PHP library for integrating with the M-Pesa API
License MIT
Informations about the package mpesa-php
M-Pesa PHP Library
This library provides a simple and flexible way to integrate M-Pesa API services into your PHP application. It supports STK Push, C2B, B2C, transaction status queries, and reversals.
Features
- STK Push: Initiate Lipa Na M-Pesa Online payments.
- C2B: Handle customer-to-business transactions.
- B2C: Process business-to-customer payments.
- Transaction Status: Query the status of transactions.
- Reversal: Reverse transactions.
Installation
Install the library via Composer:
Configuration
Step 1: Copy the Example Environment File
The library includes an .env.example
file with all required configuration variables. Copy this file to your project root as .env
:
Step 2: Configure Your Environment Variables
Edit the .env
file with your M-Pesa API credentials and settings:
Step 3: Required Variables
Variable | Description | Required For |
---|---|---|
APP_ENV |
Application environment (development /production ) |
All operations |
MPESA_CONSUMER_KEY |
Your M-Pesa API consumer key | All operations |
MPESA_CONSUMER_SECRET |
Your M-Pesa API consumer secret | All operations |
MPESA_SHORTCODE |
Your business shortcode | All operations |
MPESA_PASSKEY |
Your Lipa Na M-Pesa Online passkey | STK Push |
MPESA_INITIATOR_NAME |
B2C/B2B transaction initiator name | B2C/B2B |
MPESA_INITIATOR_PASSWORD |
Encrypted initiator password | B2C/B2B |
MPESA_CERTIFICATE_PATH |
Path to your M-Pesa certificate (if required) | Optional for security |
Usage
Step 1: Load Environment Variables
Ensure your application loads the .env
file. For non-Laravel projects, use vlucas/phpdotenv
:
Step 2: Initialize the Library
Create an instance of the M-Pesa service:
Step 3: Perform Transactions
1. STK Push (Lipa Na M-Pesa Online)
2. Query Transaction Status
3. Reverse a Transaction
Testing with Sandbox
When APP_ENV=development
, the library uses M-Pesa's sandbox environment. No real money is transferred during testing.
For production, set:
Security Notes
- Use different credentials for development and production environments.
- Keep your
.env
file secure and avoid committing it to version control.
Requirements
- PHP 7.4 or higher
- Composer
- cURL extension enabled
License
This library is open-source and available under the MIT License.
All versions of mpesa-php with dependencies
guzzlehttp/guzzle Version ^7.0
monolog/monolog Version ^2.9
nesbot/carbon Version ^2.0
vlucas/phpdotenv Version ^5.3