-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
122 lines (108 loc) · 2.95 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const crypto = require("crypto")
const rp = require("request-promise-native");
class Apigames {
/**
* @param {string} merchant - Merchant ID
* @param {string} secret - Secret Key
**/
constructor(merchant, secret) {
this._merchant = merchant;
this._secret = secret;
this._endpoint = "https://v1.apigames.id"
}
cekSaldo() {
let signature = crypto
.createHash('md5')
.update(`${this._merchant}${this._secret}`)
.digest('hex')
const options = {
method: "GET",
uri: `${this._endpoint}/merchant/${this._merchant}?signature=${signature}`,
json: true,
};
return rp(options)
.then(function (resp) {
if (resp.data) {
if (typeof resp.data.saldo !== undefined) {
return resp.data.saldo;
} else {
throw Error(resp.data.error_msg);
}
}
})
.catch(function (err) {
throw Error(err);
});
}
/**
* @param {string} productCode - Kode Produk
* @param {string} tujuan - Tujuan Pengisian
* @param {string} refId - Ref ID Unik Anda
**/
transaksi(refId, productCode, tujuan) {
const options = {
method: 'GET',
uri: `${this._endpoint}/transaksi/http-get-v1?merchant=${this._merchant}&secret=${this._secret}&produk=${productCode}&tujuan=${tujuan}&ref=${refId}`,
json: true,
};
return rp(options)
.then(function (resp) {
if (resp.data) {
return resp.data;
}
})
.catch(function (err) {
throw Error(err);
});
}
/**
* @param {string} productCode - Kode Produk
* @param {string} tujuan - Tujuan Pengisian
* @param {string} refId - Ref ID Unik Anda
**/
transaksiv2(refId, productCode, tujuan, serverId) {
let signature = crypto
.createHash('md5')
.update(`${this._merchant}:${this._secret}:${refId}`)
.digest('hex')
const options = {
method: 'GET',
uri: `${this._endpoint}/v2/transaksi?ref_id=${refId}&merchant_id=${this._merchant}&produk=${productCode}&tujuan=${tujuan}&signature=${signature}&server_id=${serverId}`,
json: true,
};
return rp(options)
.then(function (resp) {
if (resp.data) {
return resp.data;
}
})
.catch(function (err) {
throw Error(err);
});
}
/**
* @param {string} gameCode - Kode Game
* @param {string} userId - User ID
**/
cekAkunGame(gameCode, userId) {
let signature = crypto
.createHash('md5')
.update(`${this._merchant}${this._secret}`)
.digest('hex')
const options = {
method: 'GET',
uri: `${this._endpoint}/merchant/${this._merchant}/cek-username/${gameCode}?user_id=${userId}&signature=${signature}`,
json: true,
};
return rp(options)
.then(function (resp) {
if (resp) {
return resp;
}
})
.catch(function (err) {
throw Error(err);
});
}
}
module.exports = Apigames;