diff --git a/lib/command-handler/index.js b/lib/command-handler/index.js index d6f4fb3..1a7ea7e 100644 --- a/lib/command-handler/index.js +++ b/lib/command-handler/index.js @@ -19,10 +19,12 @@ const handlerDisableDownline = require('./disabledownline'); const handlerDownlineInfo = require('./downlineinfo'); const handlerEnableDownline = require('./enabledownline'); const handlerHelp = require('./help'); +const handlerInquiry = require('./inquiry'); const handlerListDeposit = require('./listdeposit'); const handlerListDownline = require('./listdownline'); const handlerListTerminal = require('./listterminal'); const handlerListTrx = require('./listtrx'); +const handlerPay = require('./pay'); const handlerPrice = require('./price'); const handlerSupplierBalances = require('./supplierbalances'); const handlerTemporaryBonus = require('./temporarybonus'); @@ -100,6 +102,12 @@ function execute(msg, params, cb) { else if (commandGroup === 'temporarybonus') { handlerTemporaryBonus(tokens, params, cb); } + else if (commandGroup === 'inquiry') { + handlerInquiry(tokens, params, cb); + } + else if (commandGroup === 'pay') { + handlerPay(tokens, params, cb); + } else if (commandGroup === 'help') { handlerHelp(tokens, params, cb) } diff --git a/lib/command-handler/inquiry.js b/lib/command-handler/inquiry.js new file mode 100644 index 0000000..4caa400 --- /dev/null +++ b/lib/command-handler/inquiry.js @@ -0,0 +1,40 @@ +const moment = require('moment'); + +const commandError = require('./error'); +const coreapi = require('../coreapi'); + +const coreEndpoint = '/postpaid2/inquiry'; + +function generateRequestId(product, destination) { + return `AUTO_INQUIRY_${ product.toUpperCase() }_${ destination }_${ moment().format('YYYYMMDD') }`; +} + +function help(keyword) { + return `Untuk mengecek 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; \ No newline at end of file diff --git a/lib/command-handler/pay.js b/lib/command-handler/pay.js new file mode 100644 index 0000000..f67cd4f --- /dev/null +++ b/lib/command-handler/pay.js @@ -0,0 +1,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; \ No newline at end of file diff --git a/lib/default-command.js b/lib/default-command.js index 2bedd99..07be4b0 100644 --- a/lib/default-command.js +++ b/lib/default-command.js @@ -232,6 +232,18 @@ module.exports = { 'tarikbonus', 'tarikrebate', ], + inquiry: [ + 'cektagihan', + 'infotagihan', + 'inq', + 'inquiry', + 'tagihan', + ], + pay: [ + 'bayar', + 'bayartagihan', + 'pay', + ], _setmarkup: [ 'markup' ],