Download the PHP package mesasdk/php-mpesa without Composer
On this page you can find all versions of the php package mesasdk/php-mpesa. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-mpesa
PHP M-Pesa SDK
A comprehensive PHP SDK for integrating with the M-Pesa API in Ethiopia. This SDK provides a simple and elegant way to interact with M-Pesa's payment services, featuring a modern fluent interface design and robust error handling.
Features
- ๐ Modern Fluent Interface Design
- ๐ณ Complete M-Pesa API Integration
- STK Push (USSD Push)
- Business to Customer (B2C) Payments
- Customer to Business (C2B) Payments and Simulation
- URL Registration and Management
- Transaction Status Queries
- ๐ Type-Safe Response Models
- ๐ก๏ธ Robust Error Handling and Validation
- ๐ Comprehensive Logging
- ๐ Secure by Default
- โจ PSR-4 Compliant
- ๐ Extensive Documentation
- ๐งช Unit Tests
Requirements
- PHP 7.4 or higher
- Composer
- Valid M-Pesa API credentials
- HTTPS enabled server for callbacks
Installation
Install the package via composer:
Quick Start
Configuration
Environment Variables
We recommend using environment variables for sensitive configuration:
Available Configuration Options
Option | Description | Required | Notes |
---|---|---|---|
baseUrl | API base URL | Yes | Use sandbox URL for testing |
environment | 'sandbox' or 'production' | Yes | Start with sandbox |
consumerKey | Your M-Pesa API consumer key | Yes | Keep secure |
consumerSecret | Your M-Pesa API consumer secret | Yes | Keep secure |
shortCode | Your M-Pesa shortcode | Yes | - |
passKey | Your M-Pesa passkey | For STK Push | - |
verifySSL | Whether to verify SSL certificates | Optional | Always true in production |
Features Documentation
STK Push
B2C Payment
C2B Simulation
Account Balance Query
C2B Validation and Confirmation
First, register your validation and confirmation URLs:
Validation Endpoint
Confirmation Endpoint
Response Models
The SDK provides type-safe response models for all API responses:
Security Best Practices
-
Environment Variables:
- Store all sensitive credentials in environment variables
- Never commit credentials to version control
- Use .env files for local development
-
SSL/TLS:
- Always use HTTPS for callback URLs
- Set verifySSL to true in production
- Keep SSL certificates up to date
-
Error Handling:
- Implement comprehensive error logging
- Never expose sensitive error details to users
- Monitor failed transactions
- Data Validation:
- Validate all incoming callback data
- Implement request signing where possible
- Use type-safe response models
Handling Callbacks
Create a callback handler for your endpoint:
Error Handling
The SDK provides comprehensive error handling through custom exceptions:
Logging
The SDK includes comprehensive logging capabilities:
Log File Example
json { "OriginatorConversationID": "2c22-4733-b801-a1eaa3f9763c", "ConversationID": "AG_20240211_70101d5c7e1c4fbf514f", "ResponseCode": "0", "ResponseDescription": "Accept the service request successfully." } json { "Result": { "ResultType": 0, "ResultCode": 0, "ResultDesc": "The service request is processed successfully.", "OriginatorConversationID": "cd88-49b1-80c9-172990525931", "ConversationID": "AG_20230116_7010211995599455bcb1", "TransactionID": "RAG0000000", "ResultParameters": { "ResultParameter": [ { "Key": "AccountBalance", "Value": "Working Account|ETB|0.00|0.00|0.00|0.00&Utility Account|ETB|101090.00|101090.00|0.00|0.00" } ] } } } `
Testing
Run the test suite:
`
The SDK includes comprehensive tests:
- Unit tests for all core functionality
- Integration tests for API endpoints
- Mock responses for offline testing
- Test coverage reports
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch
- Write your changes
- Write tests for your changes
- Run the tests
- Submit a pull request
Please read our Contributing Guide for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support and questions:
- Open an issue on GitHub
- Check our documentation
- Join our community forum
Changelog
See CHANGELOG.md for release history.
Response Models
The SDK provides type-safe response models for all API responses. These models make it easier to work with API responses and provide better IDE support.
All versions of php-mpesa with dependencies
ext-curl Version *
ext-json Version *
guzzlehttp/guzzle Version ^7.0
vlucas/phpdotenv Version ^5.6