Search by

masterlink / mpesa-dependency

Moniz

online payment manager using mpesa gateway

Package info

github.com/Moniz10/mpesa-dependency

pkg:composer/masterlink/mpesa-dependency

Statistics

Installs: 13

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-10-04 16:22 UTC

This package is auto-updated.

Last update: 2026-10-04 16:41:40 UTC


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.