-
Notifications
You must be signed in to change notification settings - Fork 0
/
DohonePayoutSDK.js
97 lines (80 loc) · 2.94 KB
/
DohonePayoutSDK.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var AbstractDohoneSDK = require('./AbstractDohoneSDK')
var md5 = require('md5')
function DohonePayoutSDK(dohoneAccount, hashCode, notifyUrl) {
AbstractDohoneSDK.call(this, hashCode, notifyUrl)
this.dohoneAccount = dohoneAccount
this.BASE_URL = 'https://www.my-dohone.com/dohone/transfert'
this.OPERATORS = {
'DOHONE_MOMO': 5, // MTN Mobile Money
'DOHONE_OM': 6, // Orange Money
'DOHONE_EU': 3, // Express Union Mobile Money
'DOHONE_TRANSFER': 1 // Dohone Account Transfer
}
}
DohonePayoutSDK.prototype = Object.create(AbstractDohoneSDK.prototype)
DohonePayoutSDK.prototype.constructor = DohonePayoutSDK
DohonePayoutSDK.prototype.parseDohoneResponse = function (res) {
// If response is a float number, add 'OK / ' before
if (res.match(/^[+-]?[0-9]*.?[0-9]+$/))
res = 'OK / ' + res
var response = Object.getPrototypeOf(DohonePayoutSDK.prototype).parseDohoneResponse(res)
var message = res.substr(res.indexOf('/') + 2)
response.message = message
if (response.status === 'OK')
response.REF = message
return response
}
DohonePayoutSDK.prototype.quote = function (transaction, callback) {
var params = {
cmd: 'cotation',
amount: transaction.amount,
devise: transaction.currency || 'XAF',
mode: this.getOperatorCodeFromSlug(transaction.operator || 'DOHONE_OM')
}
this.request(params, callback)
}
DohonePayoutSDK.prototype.transfer = function (transaction, callback) {
var account = this.dohoneAccount
var mode = this.getOperatorCodeFromSlug(transaction.operator || 'DOHONE_OM')
var amount = transaction.amount
var devise = transaction.currency || 'XAF'
var transID = transaction.ref
var hash = md5(account + mode + amount + devise + transID + this.hashCode)
var notifyUrl = this.notifyUrl
if (transaction.notifyUrl)
notifyUrl = transaction.notifyUrl
var params = {
account: account,
destination: transaction.customerPhoneNumber,
mode: mode,
amount: amount,
devise: devise,
nameDest: transaction.customerName,
ville: transaction.customerCity,
pays: transaction.customerCountry,
transID: transID,
hash: hash,
notifyUrl: notifyUrl
}
this.request(params, callback)
}
DohonePayoutSDK.prototype.mapNotificationData = function (data) {
var map = {
transID: 'ref',
amount: 'amount',
devise: 'currency',
mode: 'operator',
status: 'status',
refTrans: 'dohoneRef',
nameDest: 'customerName',
destination: 'customerPhoneNumber',
withdrawal_mode: 'withdrawalMode'
}
for(var key in map)
if (map.hasOwnProperty(key) && data.hasOwnProperty(key))
data[map[key]] = data[key]
return data;
}
module.exports = function (dohoneAccount, hashCode, notifyUrl) {
return new DohonePayoutSDK(dohoneAccount, hashCode, notifyUrl)
}