nelson-flores/mpesa
Composer 安装命令:
composer require nelson-flores/mpesa
包简介
PHP SDK for M-Pesa Mozambique API
README 文档
README
This project aims to provide an easy-to-use and up-to-date PHP wrapper for the M-Pesa Mozambique API.
Target version of M-Pesa API: v1x
Installation
Install using composer:
composer require nelson-flores/mpesa
Usage
-
Load the configuration from file.
$config = \Flores\mpesa\Config::loadFromFile('/path/to/config.php');
See sample configuration file in examples folder.
-
Create a Transaction using the configuration.
$transaction = new \Flores\mpesa\Transaction($config);
-
Execute API operations and pass appropriate parameters.
-
Initiate a C2B payment collection.
$c2b = $transaction->c2b( float $amount, string $msisdn, string $reference, string $third_party_reference );
-
Initiate a B2C payment.
$b2c = $transaction->b2c( float $amount, string $msisdn, string $reference, string $third_party_reference );
-
Initiate a B2B payment.
$b2b = $transaction->b2b( float $amount, string $receiver_party_code, string $reference, string $third_party_reference );
-
Initiate a reversal.
$reversal = $transaction->reversal( float $amount, string $transaction_id, string $third_party_reference );
-
Query a transaction.
$query = $transaction->query( string $query_reference, string $third_party_reference );
-
-
Check Response
All transactions return the
TransactionResponseobject. The object has the following public methods:-
getCode()- Returns the response code i.e.INS-0 -
getDescription()- Returns the description. -
getTransactionID()- Returns the transaction ID. -
getConversationID()- Returns the conversation ID. -
getTransactionStatus()- Returns the transaction status. Only populated when calling thequery()transaction. -
getResponse()- Returns the full response JSON object as received from M-Pesa servers. Good for debugging any issues or undocumented behaviors of the M-Pesa API.
-
In a typical scenario, code to check for successful transactions should be as follows:
$c2b = $transaction->c2b(...); if($c2b->getCode() === 'INS-0') { // Transaction Successful, Do something here }
Testing
This repo provides Unit Tests to validate the objects and their interaction with M-Pesa.
To run tests,
- Open the
phpunit.xmlfile and add the require credentials/parameters as supplied by M-Pesa. - Run
phpunit - Check the handset for USSD prompts to approve test transactions.
All tests use 1MT as the test amount.
License
This library is release under the MIT License. See LICENSE file for details.
nelson-flores/mpesa 适用场景与选型建议
nelson-flores/mpesa 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 72 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nelson-flores/mpesa 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nelson-flores/mpesa 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 72
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-06