定制 wanzoou/momoapicollection 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wanzoou/momoapicollection

最新稳定版本:v0.0.1

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.0 or higher
  • cURL extension 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.

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-19