mpesa php api
v2.0.0
该项目旨在为M-Pesa Mozambique API提供易于使用和最新的PHP包装器。
M-PESA API的目标版本: V1X
使用作曲家安装:
composer require abdulmueid/mpesa
从文件加载配置。
$ config = abdulmueid mpesa Config:: loadFromFile ( ' /path/to/config.php ' );请参阅示例文件夹中的示例配置文件。
使用配置创建交易。
$ transaction = new abdulmueid mpesa Transaction ( $ config );执行API操作并传递适当的参数。
启动C2B付款收集。
$ c2b = $ transaction -> c2b (
float $ amount ,
string $ msisdn ,
string $ reference ,
string $ third_party_reference
);启动B2C付款。
$ b2c = $ transaction -> b2c (
float $ amount ,
string $ msisdn ,
string $ reference ,
string $ third_party_reference
);启动B2B付款。
$ b2b = $ transaction -> b2b (
float $ amount ,
string $ receiver_party_code ,
string $ reference ,
string $ third_party_reference
);启动逆转。
$ reversal = $ transaction -> reversal (
float $ amount ,
string $ transaction_id ,
string $ third_party_reference
);查询交易。
$ query = $ transaction -> query (
string $ query_reference ,
string $ third_party_reference
);检查响应
所有交易返回TransactionResponse对象。该对象具有以下公共方法:
getCode() - 返回响应代码IE INS-0
getDescription() - 返回描述。
getTransactionID() - 返回事务ID。
getConversationID() - 返回对话ID。
getTransactionStatus() - 返回事务状态。仅在调用query()事务时填充。
getResponse() - 返回从M -PESA服务器接收到的完整响应JSON对象。非常适合调试M-PESA API的任何问题或无证件行为。
在典型的情况下,检查成功交易的代码应如下:
$ c2b = $ transaction -> c2b (...);
if ( $ c2b -> getCode () === ' INS-0 ' ) {
// Transaction Successful, Do something here
}该回购提供了单位测试,以验证对象及其与M-PESA的相互作用。
要运行测试,
phpunit.xml文件,并添加M-PESA提供的要求凭据/参数。phpunit所有测试使用1MT作为测试量。
该库是根据麻省理工学院许可证发布的。有关详细信息,请参见许可证文件。