karson/mpesa-php-sdk

Fund package maintenance!
karson

1.5.0 2022-06-15 05:39 UTC

This package is auto-updated.

Last update: 2024-05-15 09:39:28 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads

This package seeks to help php developers implement the various Mpesa APIs without much hustle. It is based on the REST API whose documentation is available on https://developer.mpesa.vm.co.mz/.

Installation

You can install the package via composer:

composer require karson/mpesa-php-sdk

Usage

// Set the api and public key as follows . Copy it from Mpesa Developer Console (https://developer.mpesa.vm.co.mz/) .
$mpesa = new \Karson\MpesaPhpSdk\Mpesa();
$mpesa->setApiKey('your api key');
$mpesa->setPublicKey('your public key');
$mpesa->setServiceProviderCode('your public key');
$mpesa->setEnv('test');// 'live' production environment 

//This creates transaction between an M-Pesa service provider code to a phone number registered on M-Pesa.
$invoice_id = "FT0001"; // Eg: Invoice number
$phone_number = "258841234567"; // Prefixed with country code (258)
$amount = "10"; // Payment amount
$reference_id = "XBRAND001"; // Should be unique for each transaction

$result = $mpesa->c2b($invoice_id, $phone_number, $amount, $reference_id);

var_dump($result);

Instalation in Laravel

// Set the api, public key, provider and environment secret as follows in your .env file

MPESA_API_KEY ="Your API Key";
MPESA_PUBLIC_KEY='You Public Key'
MPESA_ENV='test' // 'live' production environment
MPESA_SERVICE_PROVIDER_CODE=171717

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email karson@turbohost.co instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate.