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作為測試量。
該庫是根據麻省理工學院許可證發布的。有關詳細信息,請參見許可證文件。