Commit 2429c04c16a0de083ea86e247cc4be41888013ca
1 parent
04e7f9e6a9
Exists in
master
INQUIRY and PAY
Showing 4 changed files with 100 additions and 0 deletions Side-by-side Diff
lib/command-handler/index.js
... | ... | @@ -19,10 +19,12 @@ const handlerDisableDownline = require('./disabledownline'); |
19 | 19 | const handlerDownlineInfo = require('./downlineinfo'); |
20 | 20 | const handlerEnableDownline = require('./enabledownline'); |
21 | 21 | const handlerHelp = require('./help'); |
22 | +const handlerInquiry = require('./inquiry'); | |
22 | 23 | const handlerListDeposit = require('./listdeposit'); |
23 | 24 | const handlerListDownline = require('./listdownline'); |
24 | 25 | const handlerListTerminal = require('./listterminal'); |
25 | 26 | const handlerListTrx = require('./listtrx'); |
27 | +const handlerPay = require('./pay'); | |
26 | 28 | const handlerPrice = require('./price'); |
27 | 29 | const handlerSupplierBalances = require('./supplierbalances'); |
28 | 30 | const handlerTemporaryBonus = require('./temporarybonus'); |
... | ... | @@ -100,6 +102,12 @@ function execute(msg, params, cb) { |
100 | 102 | else if (commandGroup === 'temporarybonus') { |
101 | 103 | handlerTemporaryBonus(tokens, params, cb); |
102 | 104 | } |
105 | + else if (commandGroup === 'inquiry') { | |
106 | + handlerInquiry(tokens, params, cb); | |
107 | + } | |
108 | + else if (commandGroup === 'pay') { | |
109 | + handlerPay(tokens, params, cb); | |
110 | + } | |
103 | 111 | else if (commandGroup === 'help') { |
104 | 112 | handlerHelp(tokens, params, cb) |
105 | 113 | } |
lib/command-handler/inquiry.js
... | ... | @@ -0,0 +1,40 @@ |
1 | +const moment = require('moment'); | |
2 | + | |
3 | +const commandError = require('./error'); | |
4 | +const coreapi = require('../coreapi'); | |
5 | + | |
6 | +const coreEndpoint = '/postpaid2/inquiry'; | |
7 | + | |
8 | +function generateRequestId(product, destination) { | |
9 | + return `AUTO_INQUIRY_${ product.toUpperCase() }_${ destination }_${ moment().format('YYYYMMDD') }`; | |
10 | +} | |
11 | + | |
12 | +function help(keyword) { | |
13 | + return `Untuk mengecek tagihan, ketik perintah dengan format: ${(keyword || '').trim().toUpperCase()}.<KODEPRODUK>.<IDPELANGGAN>.<PIN>`; | |
14 | +} | |
15 | + | |
16 | +function execute(tokens, params, cb) { | |
17 | + if (!tokens || tokens.length < 3) { | |
18 | + const responseParams = { | |
19 | + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }`, | |
20 | + } | |
21 | + | |
22 | + cb(null, null, responseParams); | |
23 | + return; | |
24 | + } | |
25 | + | |
26 | + const coreParams = { | |
27 | + origin: params.origin, | |
28 | + report_ip: params.report_ip, | |
29 | + report_port: params.report_port, | |
30 | + terminal_name: params.from, | |
31 | + product_name: tokens[1].trim().toUpperCase(), | |
32 | + destination: tokens[2].trim().replace(/^\+62/, '0'), | |
33 | + terminal_password: tokens[3], | |
34 | + request_id: `${generateRequestId(tokens[1], tokens[2])}${Number(tokens[4]) ? '_req' + Number(tokens[4]) : ''}`, | |
35 | + }; | |
36 | + | |
37 | + coreapi(coreEndpoint, coreParams, 'GET', cb); | |
38 | +} | |
39 | + | |
40 | +module.exports = execute; | |
0 | 41 | \ No newline at end of file |
lib/command-handler/pay.js
... | ... | @@ -0,0 +1,40 @@ |
1 | +const moment = require('moment'); | |
2 | + | |
3 | +const commandError = require('./error'); | |
4 | +const coreapi = require('../coreapi'); | |
5 | + | |
6 | +const coreEndpoint = '/postpaid2/pay'; | |
7 | + | |
8 | +function generateRequestId(product, destination) { | |
9 | + return `AUTO_PAY_${ product.toUpperCase() }_${ destination }_${ moment().format('YYYYMMDD') }`; | |
10 | +} | |
11 | + | |
12 | +function help(keyword) { | |
13 | + return `Untuk membayar tagihan, ketik perintah dengan format: ${(keyword || '').trim().toUpperCase()}.<KODEPRODUK>.<IDPELANGGAN>.<PIN>`; | |
14 | +} | |
15 | + | |
16 | +function execute(tokens, params, cb) { | |
17 | + if (!tokens || tokens.length < 3) { | |
18 | + const responseParams = { | |
19 | + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }`, | |
20 | + } | |
21 | + | |
22 | + cb(null, null, responseParams); | |
23 | + return; | |
24 | + } | |
25 | + | |
26 | + const coreParams = { | |
27 | + origin: params.origin, | |
28 | + report_ip: params.report_ip, | |
29 | + report_port: params.report_port, | |
30 | + terminal_name: params.from, | |
31 | + product_name: tokens[1].trim().toUpperCase(), | |
32 | + destination: tokens[2].trim().replace(/^\+62/, '0'), | |
33 | + terminal_password: tokens[3], | |
34 | + request_id: `${generateRequestId(tokens[1], tokens[2])}${Number(tokens[4]) ? '_req' + Number(tokens[4]) : ''}`, | |
35 | + }; | |
36 | + | |
37 | + coreapi(coreEndpoint, coreParams, 'GET', cb); | |
38 | +} | |
39 | + | |
40 | +module.exports = execute; | |
0 | 41 | \ No newline at end of file |
lib/default-command.js
... | ... | @@ -232,6 +232,18 @@ module.exports = { |
232 | 232 | 'tarikbonus', |
233 | 233 | 'tarikrebate', |
234 | 234 | ], |
235 | + inquiry: [ | |
236 | + 'cektagihan', | |
237 | + 'infotagihan', | |
238 | + 'inq', | |
239 | + 'inquiry', | |
240 | + 'tagihan', | |
241 | + ], | |
242 | + pay: [ | |
243 | + 'bayar', | |
244 | + 'bayartagihan', | |
245 | + 'pay', | |
246 | + ], | |
235 | 247 | _setmarkup: [ |
236 | 248 | 'markup' |
237 | 249 | ], |