A PHP sdk for the new Vodacom Mpesa RESTful APIs :mozambique:
# Mpesa Mozambique PHP SDK
A comprehensive PHP SDK for integrating with M-Pesa Mozambique APIs. This package provides a clean, modern interface for all M-Pesa operations with robust error handling, callback processing, and extensive validation.
## Features
- **π Modern PHP 8.1+ Support**: Built with modern PHP features including typed properties, named arguments, and enums
- **π¦ Unified Response Architecture**: Streamlined response classes with eliminated code duplication (~90% reduction)
- **π Callback Handler System**: Complete callback processing with event-driven architecture (TODO)
- **β
Type Safety**: Strongly typed responses with specific methods for each operation
- **ποΈ Clean Architecture**: Organized structure with dedicated response classes and clear inheritance
- **π Security First**: Built-in signature validation, parameter sanitization, and secure token management
- **π Transaction Operations**: Full support for C2B, B2C, B2B transactions with sync/async modes
- **π Query Operations**: Transaction status queries and customer name lookups
- **π° Refund/Reversal**: Complete transaction reversal support with partial refund capabilities
- **π― Smart Validation**: Comprehensive parameter validation with detailed error messages
- **π± Laravel Integration**: Native Laravel service provider with configuration publishing
- **π§ Developer Experience**: Extensive examples, comprehensive documentation, and debugging tools
## Installation
You can install the package via composer:
```bash
composer require karson/mpesa-php-sdk
```
## Usage
### Basic Setup
```php
use Karson\MpesaPhpSdk\Mpesa;
// Initialize with your credentials from M-Pesa Developer Console (
developer.mpesa.vm.co.mz)
$mpesa = new Mpesa(
publicKey: 'your_public_key',
apiKey: 'your_api_key',
isTest: true, // false for production
serviceProviderCode: '171717' // Your service provider code
);
```
### Customer to Business (C2B) Transactions
```php
// C2B Transaction (Unified API)
$res β¦