wanzoou/momoapicollection
Composer 安装命令:
composer require wanzoou/momoapicollection
包简介
This repository provides a PHP class, MomoAPI, to facilitate integration with the MTN Mobile Money (MoMo) API for collection services. This class allows you to create API users, generate API keys, obtain access tokens, and make payment requests to the MTN MoMo platform.
README 文档
README
Introduction
This repository provides a PHP class, MomoAPI, to facilitate integration with the MTN Mobile Money (MoMo) API for collection services. This class allows you to create API users, generate API keys, obtain access tokens, and make payment requests to the MTN MoMo platform.
Features
- Create API User: Automatically create an API user for MTN MoMo integration.
- Generate API Key: Securely generate an API key for the created API user.
- Obtain Access Token: Generate an access token for authorization.
- Request to Pay: Initiate payment requests to the MoMo API.
- Check Transaction Status: Retrieve the status of a payment request.
Requirements
PHP 7.0or highercURLextension for PHP
Installation
You can install the library via Composer. Run the following command:
composer require wanzoou/momoapicollection
Include the MomoAPI class in your project:
require_once 'vendor/autoload.php'; use Wanzoou\Momoapicollection\MomoAPI;
Usage
Initialization
Instantiate the MomoAPI class:
$momo = new MomoAPI();
Configuration
Set the required parameters:
$momo->setMomoPayHost('sandbox.momodeveloper.mtn.com'); // Set MoMo API host $momo->setPrimaryKey('your_primary_key'); // Set your primary key $momo->setProviderCallbackHost('your_callback_host'); // Set your provider callback host $momo->setTargetEnvironment('sandbox'); // Set the target environment (sandbox or live)
Request to Pay
Initiate a payment request:
$phone = '237679465319'; // Payer's phone number $amount = 100; // Amount to be paid $currency = 'EUR'; // Currency $responseCode = $momo->requestToPay($phone, $amount, $currency); if ($responseCode == 202) { echo "Payment request initiated successfully."; } else { echo "Failed to initiate payment request."; }
Check Transaction Status
Retrieve the status of a payment request:
$status = $momo->requestToPayTransactionStatus(); echo "Transaction Status: " . json_encode($status);
Methods
setMomoPayHost($momo_pay_host)
Set the MoMo API host.
setProviderCallbackHost($providerCallbackHost)
Set the provider callback host.
setPrimaryKey($primary_key)
Set the primary key.
setTargetEnvironment($targetEnvironment)
Set the target environment (sandbox or live).
requestToPay($phone, $amount, $currency)
Initiate a payment request.
requestToPayTransactionStatus()
Retrieve the status of a payment request.
Example
Here is an example of using the MomoAPI class in a PHP script:
<?php require_once 'vendor/autoload.php'; use Wanzoou\Momoapicollection\MomoAPI; $momo = new MomoAPI(); $momo->setMomoPayHost('sandbox.momodeveloper.mtn.com'); $momo->setPrimaryKey('your_primary_key'); $momo->setProviderCallbackHost('your_callback_host'); $momo->setTargetEnvironment('sandbox'); $phone = '237679465319'; $amount = 100; $currency = 'EUR'; $responseCode = $momo->requestToPay($phone, $amount, $currency); if ($responseCode == 202) { echo "Payment request initiated successfully.\n"; $status = $momo->requestToPayTransactionStatus(); echo "Transaction Status: " . json_encode($status); } else { echo "Failed to initiate payment request.\n"; } ?>
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any changes.
Contact
For any inquiries, please contact wanzoou@gmail.com.
wanzoou/momoapicollection 适用场景与选型建议
wanzoou/momoapicollection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wanzoou/momoapicollection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wanzoou/momoapicollection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-19