nevar/mpesa
Composer 安装命令:
composer require nevar/mpesa
包简介
A laravel-php library
README 文档
README
Introduction
This package is still under developement. A full and descriptive documentation is coming soon. Work with the functionality under the table of contents for now
Contents
Installation
-
Run the following command to install:
composer require nevar/mpesa -
If you are using older versions of Laravel 5 be sure to include the following provivers in your app/config.php
<?php return [ 'providers' => [ /* * Package Service Providers... */ MPESA\Providers\AuthServiceProvider::class, MPESA\Providers\ConfigurationServiceProvider::class, MPESA\Providers\OnlinePaymentServiceProvider::class, ] ];
-
Then run
php artisan vendor:publish --tag=mpesa-config -
Add the following values to you .env file
MPESA_DEVELOPEMENT_MODE=true MPESA_USERNAME=m&yu$ern@ame MPESA_PASSWORD=password MPESA_PAYBILLNO=0000 MPESA_STK_PASSKEY=000c2daf998f92aa5a925350031f2471f873bff7877879b45cc364f2cb9a9907ef1245 MPESA_CALLBACK_URL= http://5c3f4b1d.ngrok.io/api/mpesa/callback
-
MPESA_DEVELOPEMENT_MODEshould be false if in production otherwise leave it as true -
If you're developing login and get test credentials from here so as to populate your environment variables.
STK-Push
- Below is a use case on how to request for payment via STK-Push.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use MPESA\Services\OnlinePaymentService; class PaymentController extends Controller { public function requestPayment(Request $request,OnlinePaymentService $stk) { // phone number $user_phone_number = "254712345678"; # insert user phone number $amount = 50; # insert amount payable // this is optional if you want to overide the IPN on your .env $stk->callBackURL = "http://8bbea5f4.ngrok.io/api/mpesa/response-callback"; // request for payment $stk->initiateSTKCheckout($amount,$user_phone_number); } }
-
Set up your call back incase of successfull or cancelled payments . Your callback url should match the .env variable
MPESA_CALLBACK_URLor$stk->callBackURLoverride. For more information on the json response from MPESA visit here -
Otherwise here is a sample of the IPN callback
// A cancelled request { "Body":{ "stkCallback":{ "MerchantRequestID":"8555-67195-1", "CheckoutRequestID":"ws_CO_27072017151044001", "ResultCode":1032, "ResultDesc":"[STK_CB - ]Request cancelled by user" } } } // An accepted request { "Body":{ "stkCallback":{ "MerchantRequestID":"19465-780693-1", "CheckoutRequestID":"ws_CO_27072017154747416", "ResultCode":0, "ResultDesc":"The service request is processed successfully.", "CallbackMetadata":{ "Item":[ { "Name":"Amount", "Value":1 }, { "Name":"MpesaReceiptNumber", "Value":"LGR7OWQX0R" }, { "Name":"Balance" }, { "Name":"TransactionDate", "Value":20170727154800 }, { "Name":"PhoneNumber", "Value":254721566839 } ] } } } }
NB Create an issue incase of any problems.
nevar/mpesa 适用场景与选型建议
nevar/mpesa 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 555 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 08 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nevar/mpesa 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nevar/mpesa 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 555
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-05