mossey / mpesa
用于Mpesa API的PHP包
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-22 07:58:30 UTC
README
此包已被弃用,请使用 https://github.com/safaricom/mpesa-php-sdk
简介
此包旨在帮助PHP开发者轻松实现各种Mpesa API。它基于REST API,其文档可在http://developer.safaricom.co.ke找到。
使用composer安装
composer require mossey/mpesa
配置
在项目根目录下创建一个.env文件,并在其中设置消费者密钥和消费者密钥,如下所示
consumer_key= [消费者密钥]
consumer_secret=[消费者密钥]
对于Laravel用户,打开Config/App.php文件,在providers下添加\Mossey\Mpesa\MpesaServiceProvider::class
,在aliases下添加 'Mpesa'=> \Mossey\Mpesa\MpesaServiceProvider::class
。
用法
确认和验证URL
B2C付款请求
这将在M-Pesa短码和注册在M-Pesa上的手机号码之间创建交易。
$mpesa= new \Mossey\Mpesa\Mpesa();
$b2cTransaction=$mpesa->b2c( $ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );
账户余额请求
这用于查询M-Pesa BuyGoods (收银机号码)的余额。
$mpesa= new \Mossey\Mpesa\Mpesa();
$balanceInquiry=$mpesa->accountBalance($CommandID, $Initiator, $SecurityCredential, $PartyA, $IdentifierType, $Remarks, $QueueTimeOutURL, $ResultURL);
交易状态请求 这用于检查交易状态。
$mpesa= new \Mossey\Mpesa\Mpesa();
$trasactionStatus=$mpesa->transactionStatus($Initiator, $SecurityCredential, $CommandID, $TransactionID, $PartyA, $IdentifierType, $ResultURL, $QueueTimeOutURL, $Remarks, $Occasion);
B2B付款请求
这用于在两家公司之间转账。
$mpesa= new \Mossey\Mpesa\Mpesa();
$b2bTransaction=$mpesa->b2b($ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );
STK Push模拟
这用于代表客户发起在线付款。
$mpesa= new \Mossey\Mpesa\Mpesa();
$stkPushSimulation=$mpesa->STKPushSimulation($BusinessShortCode, $LipaNaMpesaPasskey, $TransactionType, $Amount, $PartyA, $PartyB, $PhoneNumber, $CallBackURL, $AccountReference, $TransactionDesc, $Remarks);
STK Push状态查询
这用于检查Lipa Na M-Pesa在线支付的状态。
$mpesa= new \Mossey\Mpesa\Mpesa();
$STKPushRequestStatus=$mpesa->STKPushQuery($checkoutRequestID,$businessShortCode,$password,$timestamp);
确认和验证
这些对于完成大多数交易是必需的。没有这些,交易将不会完成。因此,请将您的URL注册在开发者门户中,完成后,请确保您的验证URL和确认URL包含以下内容。
验证
$mpesa= new \Mossey\Mpesa\Mpesa();
$b2bTransaction=$mpesa->validate();
确认
$mpesa= new \Mossey\Mpesa\Mpesa();
$b2bTransaction=$mpesa->confirm();