masterlink / mpesa-dependency
online payment manager using mpesa gateway
v1.0.0
2026-10-04 16:22 UTC
Requires
- php: >=8.0
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Dependency for consumption of the M-Pesa API.
Installation
To install this dependency, just run the command below:
composer require masterlink/mpesa-dependency
Usage
To use this manager, just follow the example below:
C2B
<?php require __DIR__.'/../../vendor/autoload.php'; use \Bluteki\MpesaGateway\Mpesa; // configuring api access credentials Mpesa::config( 'enter you api key', 'enter your public key', 'host', 'origin', 'port', 'service_provider_code' ); $transactionReference = bin2hex(random_bytes(6)); $thirdPartyReference = bin2hex(random_bytes(6)); $response = Mpesa::c2b(1, '258844224168', $transactionReference, $thirdPartyReference); echo '<pre>'; print_r($response->toArray());
B2C
<?php require __DIR__.'/../../vendor/autoload.php'; use \Bluteki\MpesaGateway\Mpesa; // configuring api access credentials Mpesa::config( 'enter you api key', 'enter your public key', 'host', 'origin', 'port', 'service_provider_code' ); $transactionReference = bin2hex(random_bytes(6)); $thirdPartyReference = bin2hex(random_bytes(6)); $response = Mpesa::b2c(1, '258844224168', $transactionReference, $thirdPartyReference); echo '<pre>'; print_r($response->toArray());
Laravel
In Laravel, do not use require .../vendor/autoload.php (it is already loaded).
Configure once in app/Providers/AppServiceProvider.php:
use Bluteki\MpesaGateway\Mpesa; public function boot(): void { Mpesa::config( config('mpesa.api_key'), config('mpesa.public_key'), config('mpesa.host'), config('mpesa.origin'), config('mpesa.port'), config('mpesa.service_provider_code') ); }
Then call it anywhere:
$response = Mpesa::c2b($amount, $phone, bin2hex(random_bytes(6)), bin2hex(random_bytes(6)));
Requirements
- PHP 8.0 or higher required
- guzzlehttp/guzzle ^7.0
License
GPL-3.0-or-later. See the LICENSE file.