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 …