mathermann/dohone-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mathermann/dohone-sdk

Composer 安装命令:

composer require mathermann/dohone-sdk

包简介

A PHP 5.4+ SDK for easily use Dohone payment API

README 文档

README

Latest Version on Packagist Total Downloads
A PHP 5.4+ SDK for easily use Dohone payment API.

Note

This PHP package let you easily integrate Dohone payment API to your application or your web site for every Cameroon mobile payments operators (MTN Mobile Money, Orange Money and Express Union Mobile Money).

Before you start using this package, it's highly recommended to read documents below.

Table of contents

1. Requirements

This package requires: Required PHP version

2. Installation

2.1. Install Composer package

First of all, install the Composer package from your CMD or your Terminal.

$ composer require mathermann/dohone-sdk

2.2. Implement TransactionInterface

Then you need a class that implements TransactionInterface interface.
For example:

<?php

namespace Your\Name\Space; // Replace with your namespace

use Mathermann\DohoneSDK\TransactionInterface;

class Transaction implements TransactionInterface
{
    /**
     * Transaction reference (or id) in your system
     */
    private $transactionRef;
    
    /**
     * Transaction operator, must be one of the following values:
     * ['DOHONE_MOMO', 'DOHONE_OM', 'DOHONE_EU', 'DOHONE_TRANSFER']
     */
    private $transactionOperator;
    
    private $transactionAmount;
    
    /**
     * Transaction currency, must be one of the following values:
     * ['XAF', 'EUR', 'USD']
     */
    private $transactionCurrency;
    
    private $transactionReason;
    
    /**
     * Transaction reference in Dohone's system
     */
    private $dohoneTransactionRef;
    
    private $customerName;
    
    private $customerPhoneNumber;
    
    private $customerEmail;
    
    private $customerCountry;
    
    private $customerCity;
    
    /**
     * Notification URL for this transaction
     */
    private $notifyUrl;
    
    // You can add some additional properties...
    
    
    public function getTransactionRef()
    {
        return $this->transactionRef;
    }

    public function getTransactionOperator()
    {
        return $this->transactionOperator;
    }

    public function getTransactionAmount()
    {
        return $this->transactionAmount;
    }

    public function getTransactionCurrency()
    {
        return $this->transactionCurrency;
    }

    public function getTransactionReason()
    {
        return $this->transactionReason;
    }

    public function getDohoneTransactionRef()
    {
        return $this->dohoneTransactionRef;
    }

    public function getCustomerName()
    {
        return $this->customerName;
    }

    public function getCustomerPhoneNumber()
    {
        return $this->customerPhoneNumber;
    }

    public function getCustomerEmail()
    {
        return $this->customerEmail;
    }

    public function getCustomerCountry()
    {
        return $this->customerCountry;
    }

    public function getCustomerCity()
    {
        return $this->customerCity;
    }

    public function getNotifyUrl()
    {
        return $this->notifyUrl;
    }
    
    // add setters...
    
    // you can add some additional methods...
}

3. Payin requests (collect payments)

3.1. Create a DohoneSDK object

You can find DohoneSDK class here.

<?php

use Mathermann\DohoneSDK\DohoneSDK;

// constants
define('MERCHANT_KEY', '...'); // your dohone merchant key (required)
define('APP_NAME', '...'); // the name by which your application is recognized at Dohone
define('HASH_CODE', '...'); // your dohone hash code (only if you handle dohone notifications in your system)
define('NOTIFY_URL', '...'); // default notification URL for incoming payments

$dohoneSdk = new DohoneSDK(MERCHANT_KEY, APP_NAME, HASH_CODE, NOTIFY_URL);

// ...

3.2. Make a « COTATION » command

<?php

// ...

use Mathermann\DohoneSDK\InvalidDohoneResponseException;

try 
{
    /**
     * $transaction is an object of type Transaction defined above,
     * $mode is exactly the same as "levelFeeds" in Dohone's documentation
     */
    $response = $dohoneSdk->quote($transaction, ['mode' => $mode]);
    
    if ($response->isSuccess())
    {
        echo $response->getMessage(); // display result
    }
    else
    {
        echo $response->getMessage(); // display error message
    }                
}
catch (InvalidDohoneResponseException $e)
{
    echo $e->getMessage(); // display error message
}

// ...

3.3. Make a « START » command

<?php

// ...

use Mathermann\DohoneSDK\InvalidDohoneResponseException;

try
{
    /**
     * $transaction is an object of type Transaction defined above,
     * $OTP is exactly the same as "rOTP" in Dohone's documentation, required only for Orange Money payment
     */
    $response = $dohoneSdk->start($transaction, ['OTP' => $OTP]);
    
    if ($response->isSuccess())
    {
        if ($response->hasREF()) {
            // ToDo: handle success
        }
        else if ($response->needCFRMSMS()) {
            // ToDo: request SMS confirmation code to user
        }
    }
    else
    {
        echo $response->getMessage(); // display error message
    }                
}
catch (InvalidDohoneResponseException $e)
{
    echo $e->getMessage(); // display error message
}

// ...

3.4. Make a « CRFMSMS » command

<?php

// ...

use Mathermann\DohoneSDK\InvalidDohoneResponseException;

try
{
    /**
     * $transaction is an object of type Transaction defined above,
     * $code is exactly the same as "rCS" in Dohone's documentation
     */
    $response = $dohoneSdk->confirmSMS($transaction, ['code' => $code]);
    
    if ($response->isSuccess())
    {
        if ($response->hasREF()) {
            // ToDo: handle success
        }
        else if ($response->needCFRMSMS()) {
            // ToDo: request SMS confirmation code to user
        }
    }
    else
    {
        echo $response->getMessage(); // display error message
    }                
}
catch (InvalidDohoneResponseException $e)
{
    echo $e->getMessage(); // display error message
}

// ...

3.5. Make a « VERIFY » command

<?php

// ...

use Mathermann\DohoneSDK\InvalidDohoneResponseException;

try
{
    /**
     * $transaction is an object of type Transaction defined above
     */
    $response = $dohoneSdk->verify($transaction);
    
    if ($response->isSuccess()) {
        // ToDo: handle OK
    }
    else {
        // ToDo: handle NO
    }                
} 
catch (InvalidDohoneResponseException $e)
{
    echo $e->getMessage(); // display error message
}

// ...

3.6. Handle Dohone's notifications

<?php

// ...

use Mathermann\DohoneSDK\InvalidDohoneResponseException;

// convert data into more readable format
/**
 * $notificationData is data received from the request, it can be
 * $_GET if you use vanilla PHP,
 * $request->query->all() if you use Symfony or
 * Input::all() if you use Laravel
 */
$data = $dohoneSdk->mapNotificationData($notificationData);

// check for request integrity
if ($dohoneSdk->checkHash($data))
{
    // fill new Transaction() with data and check if Dohone recognizes the transaction
    try
    {
        /**
         * $transaction is an object of type Transaction defined above
         */
        $response = $dohoneSdk->verify($transaction);
        
        if ($response->isSuccess()) {
            // ToDo: handle OK
        }
        else {
            // ToDo: handle NO (or just ignore the request)
        }                
    } 
    catch (InvalidDohoneResponseException $e)
    {
        echo $e->getMessage(); // display error message
    }
}

// ...

4. Payout requests (refund customer or withdraw money)

4.1. Create a DohonePayoutSDK object

You can find DohonePayoutSDK class here.

<?php

use Mathermann\DohoneSDK\DohonePayoutSDK;

// constants
define('ACCOUNT', '...'); // the phone number of your Dohone account (required)
define('HASH_CODE', '...'); // your dohone hash code (required)
define('NOTIFY_URL', '...'); // default notification URL for payouts

$dohonePayoutSdk = new DohonePayoutSDK(ACCOUNT, HASH_CODE, NOTIFY_URL);

// ...

4.2. Make a « COTATION » command

<?php

// ...

use Mathermann\DohoneSDK\InvalidDohoneResponseException;

try 
{
    /**
     * $transaction is an object of type Transaction defined above
     */
    $response = $dohonePayoutSdk->quote($transaction);
    
    if ($response->isSuccess())
    {
        echo $response->getMessage(); // display result
    }
    else
    {
        echo $response->getMessage(); // display error message
    }                
}
catch (InvalidDohoneResponseException $e)
{
    echo $e->getMessage(); // display error message
}

// ...

4.3. Make a transfer

<?php

// ...

use Mathermann\DohoneSDK\InvalidDohoneResponseException;

try
{
    /**
     * $transaction is an object of type Transaction defined above
     */
    $response = $dohonePayoutSdk->transfer($transaction);
    
    if ($response->isSuccess() && $response->hasREF()) {
        // ToDo: handle success
    }
    else {
        echo $response->getMessage(); // display error message
    }
}
catch (InvalidDohoneResponseException $e)
{
    echo $e->getMessage(); // display error message
}

// ...

4.4. Handle Dohone's payout notifications

<?php

// ...

// convert data into more readable format
/**
 * $notificationData is data received from the request, it can be
 * $_GET if you use vanilla PHP,
 * $request->query->all() if you use Symfony or
 * Input::all() if you use Laravel
 */
$data = $dohonePayoutSdk->mapNotificationData($notificationData);

// ToDo: handle notification

// ...

Credits

mathermann/dohone-sdk 适用场景与选型建议

mathermann/dohone-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 114 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「sdk」 「payment-integration」 「Dohone」 「Cameroon」 「mobile-payments」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mathermann/dohone-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mathermann/dohone-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 mathermann/dohone-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-08