johnes-ke/mpesa-php-api
Composer 安装命令:
composer require johnes-ke/mpesa-php-api
包简介
Safaricom Daraja M-pesa API for laravel framework
README 文档
README
This package provides you with a simple tool to make requests to Safaricom Mpesa APIs so that you can focus on the development of your awesome application.
Installation
Install via composer
composer require johnes-ke/mpesa-php-api
Publish Configuration File
php artisan vendor:publish --tag=mpesa-php-api-config
Publish Database Migration File
php artisan vendor:publish --tag=mpesa-php-api-migrations
IF YOU WANT TO GO LIVE/PRODUCTION READY
Copy the variables in the .env.example. to the .env environment file .
For the MPESA_ENVIRONMENT use live as the value for the production environment.
Usage
If you have not created your Safaricom Daraja Mpesa API application yet you can create one at Safaricom Developer
Example code to try
<?php use JohnesKe\MpesaPhpApi\MpesaPhpApi; $mpesa = new MpesaPhpApi( config('mpesa-php-api.mpesa_environment'), config('mpesa-php-api.consumer_key'), config('mpesa-php-api.consumer_secret') ); $accessToken = $mpesa->getToken(); $amount = '1'; $phoneNumber = '2547********'; $callBackUrl = 'https:://example.com'; $accountReference = 'Test001'; $transactionRef = 'test'; // Stk Push Example $result = $mpesa->stkPushRequest( $accessToken, config('mpesa-php-api.c2b_stk_short_code'), config('mpesa-php-api.lipa_na_mpesa_pass_key'), $amount, $phoneNumber, $callBackUrl, $accountReference, $transactionRef, ); $ResponseCode = $result->ResponseCode; $ResponseDescription = $result->ResponseDescription; $merchantRequestID = $result->MerchantRequestID; $checkoutRequestID = $result->CheckoutRequestID; $CustomerMessage = $result->CustomerMessage; //Response echo "<br/>Response Code --> ".$ResponseCode; echo "<br/>Response Desc --> ".$ResponseDescription; echo "<br/>Merchant Request ID --> ".$merchantRequestID; echo "<br/>Checkout Request ID--> ".$checkoutRequestID; echo "<br/>Customer Message --> ".$CustomerMessage;
Security
If you discover any security related issues, please send an email to jmecha09@gmail.com
instead of using the issue tracker.
统计信息
- 总下载量: 61
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-22