keenops / laravel-mpesa
Laravel wrapper for the Vodacom M-Pesa API, providing a seamless integration experience for Laravel applications
Requires
- php: ^7.4|^8.0
- phpseclib/phpseclib: ~3.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-10-16 22:23:39 UTC
README
Engineered for seamless integration with the Vodacom M-Pesa OpenApi, it offers Laravel developers a streamlined pathway to execute customer-to-business transactions with ease and efficiency.
Installation
You can install the package via composer:
composer require keenops/laravel-mpesa:v0.0.1-beta.1
Runing the above command should also publish in a config directory a file named laravel-mpesa.php. If so didnt happen, publish the configuration files by running the command:
php artisan vendor:publish --tag=laravel-mpesa
Usage
Add Vodacom M-Pesa API credentials to a .env file. The credentials can be obtained here
MPESA_API_KEY= // get this from your mpesa developer/bussiness account MPESA_PUBLIC_KEY= // get this from your mpesa developer/bussiness account MPESA_ENVIROMENT= // options are: sandbox, openapi MPESA_MARKET_COUNTRY= // options are: TZN, GHA, LES, DRC MPESA_MARKET_CURRENCY= // options are: TZS, GHS, SLS, USD
Customer to Business Transaction
In your controller use like this
namespace App\Http\Controllers; use Keenops\Mpesa\Mpesa; class CheckoutController extends Controller { public function checkout() { return Mpesa::c2b( amount: '1000', customerNumber:'255746277553', serviceCode: '000000', reference: 'T12344Z', description: 'Three items', conversationId: '1e9b774d1da34af78412a498cbc28f43e' ); //this returns json response from M-Pesa API. Refer the link https://openapiportal.m-pesa.com/ for error and success codes } }
Errors
Specific error codes may be displayed within parenthesis when send or receive operations fail. The most common of these error codes are specified in API documetation found on openapiportal.m-pesa.com
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 git@kimwalu.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.