npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dohone-sdk

v1.0.13

Published

A JS SDK for easily use Dohone payment API

Downloads

21

Readme

DohoneSDK

Latest Version on Packagist Total Downloads
A NodeJS SDK for easily use Dohone payment API.

Note

This module 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

There is no specific requirements for this package.

2. Installation

$ npm install dohone-sdk

3. Payin requests (collect payments)

3.1. Create a DohoneSDK object

You can find DohoneSDK class here.

var dohone = require('dohone-sdk');

// constants
var merchantKey = '...'; // your dohone merchant key (required)
var appName = '...'; // the name by which your application is recognized at Dohone
var hashCode = '...'; // your dohone hash code (only if you handle dohone notifications in your system)
var notifyUrl = '...'; // default notification URL for incoming payments

var dohoneSdk = dohone.payin(merchantKey, appName, hashCode, notifyUrl);

// ...

3.2. Make a « COTATION » command

// ...

/**
 * transaction is a JSON object with following properties
 *   - amount: number
 *   - currency: 'XAF', 'EUR' or 'USD'
 *   
 * params is a JSON object with following properties
 *   - mode: 0, 1, 2, 3 or 4 (exact as levelFeeds in Dohone docs)
 */
var transaction = {
    amount: 1000,
    currency: 'XAF'
};
var params = {
    mode: 0
};
dohoneSdk.quote(transaction, params, function (err, dohoneRes) {
    if (err) {
        // handle request error here
    }
    else if (dohoneRes.isSuccess) {
        // use dohoneRes.message here
    }
    else {
        // Dohone error, check dohoneRes.message
    }
});

// ...

3.3. Make a « START » command

// ...

/**
 * transaction is a JSON object with following properties
 *   - ref: string (unique transaction reference in your system)
 *   - amount: number
 *   - currency: 'XAF', 'EUR' or 'USD'
 *   - operator: 'DOHONE_OM', 'DOHONE_MOMO', 'DOHONE_EU', 'DOHONE_TRANSFER'
 *   - customerPhoneNumber: string
 *   - customerName: string
 *   - customerEmail: string
 *   - reason: string
 *   - notifyUrl: string (notification URL for this transaction)
 *   
 * params is a JSON object with following properties
 *   - OTP: number (payment code in case of Orange Money)
 */
var transaction = {
    ref: '146eb9e4-fad1-4214-a8ed-9e5316ef2fad',
    amount: 1000,
    currency: 'XAF',
    operator: 'DOHONE_OM', // Orange Money
    customerPhoneNumber: '699999999'
};
var params = {
    OTP: '452132' // provided by user
};
dohoneSdk.start(transaction, params, function (err, dohoneRes) {
    if (err) {
        // handle request error here
    }
    else if (dohoneRes.isSuccess) {
        if (dohoneRes.needCFRMSMS) {
            // must make a CFRMSMS command
        }
        else if (dohoneRes.hasREF) {
            // successful transaction
            // dohoneRes.REF is transaction reference
        }
        else {
            // unknown response, check dohoneRes.message
        }
    }
    else {
        // Dohone error, check dohoneRes.message
    }
});

// ...

3.4. Make a « CFRMSMS » command

// ...

/**
 * transaction is a JSON object with following properties
 *   - customerPhoneNumber: string
 *   
 * params is a JSON object with following properties
 *   - code: string (Dohone authorization code)
 */
var transaction = {
    customerPhoneNumber: '699999999'
};
var params = {
    code: 'A123' // provided by user
};
dohoneSdk.confirmSMS(transaction, params, function (err, dohoneRes) {
    if (err) {
        // handle request error here
    }
    else if (dohoneRes.isSuccess) {
        if (dohoneRes.needCFRMSMS) {
            // invalid code, make a CFRMSMS command again
        }
        else if (dohoneRes.hasREF) {
            // successful transaction
            // dohoneRes.REF is transaction reference
        }
        else {
            // error, check dohoneRes.message
        }
    }
    else {
        // Dohone error, check dohoneRes.message
    }
});

// ...

Bonus tip

We have noticed that the CFRMSMS command often returns an empty answer, it is sometimes necessary to make several attempts before getting a good answer. For this, we have provided a fourth optional parameter to the confirmSMS() method that defines the maximum number of attempts to be made, its default value is 1.

// for example, if you want to allow five attempts
dohoneSdk.confirmSMS(transaction, params, callback, 5);

3.5. Make a « VERIFY » command

// ...

/**
 * transaction is a JSON object with following properties
 *   - ref: string (unique transaction reference in your system)
 *   - dohoneRef: string (Dohone transaction reference)
 *   - amount: number
 *   - currency: 'XAF', 'EUR' or 'USD'
 */
var transaction = {
    ref: '146eb9e4-fad1-4214-a8ed-9e5316ef2fad',
    dohoneRef: '123456789',
    amount: 1000,
    currency: 'XAF'
};
dohoneSdk.verify(transaction, function (err, dohoneRes) {
    if (err) {
        // handle request error here
    }
    else if (dohoneRes.isSuccess) {
        // recognized transaction
    }
    else {
        // unknown transaction
    }
});

// ...

3.6. Handle Dohone's notifications

// ...

/**
 * data must contain request parameters sent by Dohone
 */
// For example, if you are using Express framework, then
var data = request.query;

// After that, map data using
data = dohoneSdk.mapNotificationData(data);

// Check request integrity using your hashCode
if (dohoneSdk.checkHash(data)) {
    dohoneSdk.verify(data, function (err, dohoneRes) {
        if (err){
            // handle request error here
        }
        if (dohoneRes.isSuccess) {
            // everything is OK, do what you want with data
        }
        else {
            // unrecognized transaction, you can ignore the request or do something else
        }
    });
}
else {
    // bad signature, you can ignore the request or do something else
}

// ...

4. Payout requests (refund customer or withdraw money)

Need this ? Contact me, I will fill this content for FREE.

4.1. Create a DohonePayoutSDK object

You can find DohonePayoutSDK class here.



// ...

4.2. Make a « COTATION » command

// ...



// ...

4.3. Make a transfer

// ...



// ...

4.4. Handle Dohone's payout notifications

// ...



// ...

Credits