-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
80 lines (73 loc) · 1.84 KB
/
index.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
const crypto = require("crypto")
const rp = require("request-promise-native");
const md5 = require("md5");
class Tokopay {
/**
* @param {string} merchant - Merchant ID
* @param {string} secret - Secret Key
**/
constructor(merchant, secret) {
this._merchant = merchant;
this._secret = secret;
this._endpoint = "https://api.tokopay.id"
}
info() {
const options = {
method: 'GET',
uri: `${this._endpoint}/v1/merchant/balance?merchant=${this._merchant}&secret=${this._secret}`,
json: true,
};
return rp(options)
.then(function (resp) {
if (resp.data) {
return resp.data;
}
})
.catch(function (err) {
throw Error(err);
});
}
/**
* @param {string} nominal - Nominal
* @param {string} refId - Ref ID Unik Anda
* @param {string} metode - Kode Metode Pembayaran
**/
simpleOrder(refId, metode, nominal) {
const options = {
method: 'GET',
uri: `${this._endpoint}/v1/order?merchant=${this._merchant}&secret=${this._secret}&ref_id=${refId}&nominal=${nominal}&metode${metode}`,
json: true,
};
return rp(options)
.then(function (resp) {
if (resp.data) {
return resp.data;
}
})
.catch(function (err) {
throw Error(err);
});
}
tarikSaldo(nominal) {
const options = {
method: 'POST',
uri: `${this._endpoint}/v1/merchant/tarik-saldo`,
json: true,
body: {
nominal:nominal,
merchant_id: this._merchant,
signature: md5(this._merchant+':'+this._secret)
}
};
return rp(options)
.then(function (resp) {
if (resp.data) {
return resp.data;
}
})
.catch(function (err) {
throw Error(err);
});
}
}
module.exports = Tokopay;