pay.js
1.24 KB
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
const moment = require('moment');
const commandError = require('./error');
const coreapi = require('../coreapi');
const coreEndpoint = '/postpaid2/pay';
function generateRequestId(product, destination) {
return `AUTO_PAY_${ product.toUpperCase() }_${ destination }_${ moment().format('YYYYMMDD') }`;
}
function help(keyword) {
return `Untuk membayar tagihan, ketik perintah dengan format: ${(keyword || '').trim().toUpperCase()}.<KODEPRODUK>.<IDPELANGGAN>.<PIN>`;
}
function execute(tokens, params, cb) {
if (!tokens || tokens.length < 3) {
const responseParams = {
body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }`,
}
cb(null, null, responseParams);
return;
}
const coreParams = {
origin: params.origin,
report_ip: params.report_ip,
report_port: params.report_port,
terminal_name: params.from,
product_name: tokens[1].trim().toUpperCase(),
destination: tokens[2].trim().replace(/^\+62/, '0'),
terminal_password: tokens[3],
request_id: `${generateRequestId(tokens[1], tokens[2])}${Number(tokens[4]) ? '_req' + Number(tokens[4]) : ''}`,
};
coreapi(coreEndpoint, coreParams, 'GET', cb);
}
module.exports = execute;