Commit 369116684bc6ad11c218989a039305427ed67b3b

Authored by Adhidarma Hadiwinoto
1 parent d14ff80178
Exists in master

Pembuatan tiket deposit

Showing 4 changed files with 42 additions and 2 deletions Inline Diff

lib/command-handler/depositticket.js
File was created 1 "use strict";
2
3 const commandError = require('./error');
4 const coreapi = require('../coreapi');
5
6 const coreEndpoint = '/deposit-tickets/create';
7
8 function help(keyword) {
9 return `Untuk membuat tiket depoist, ketik perintah dengan format: ${ keyword.toUpperCase() }.<JUMLAH>.<PIN>`;
10 }
11
12 function execute(tokens, params, cb) {
13
14 if (!tokens || tokens.length < 3) {
15 const responseParams = {
16 body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }`
17 }
18
19 cb(null, null, responseParams);
20 return;
21 }
22
23 const coreParams = {
24 origin: params.origin,
25 report_ip: params.report_ip,
26 report_port: params.report_port,
27
28 asker_terminal_name: params.from,
29 amount: tokens[1],
30 asker_terminal_password: tokens[2],
31 };
32
33 coreapi(coreEndpoint, coreParams, 'GET', cb);
34 }
35
36 module.exports = execute;
lib/command-handler/index.js
1 "use strict"; 1 "use strict";
2 2
3 const logger = require('komodo-sdk/logger'); 3 const logger = require('komodo-sdk/logger');
4 4
5 const commandParser = require('../command-parser'); 5 const commandParser = require('../command-parser');
6 6
7 const commandError = require('./error'); 7 const commandError = require('./error');
8 8
9 const handlerAddBalance = require('./addbalance'); 9 const handlerAddBalance = require('./addbalance');
10 const handlerAddDownline = require('./adddownline'); 10 const handlerAddDownline = require('./adddownline');
11 const handlerAddTerminal = require('./addterminal'); 11 const handlerAddTerminal = require('./addterminal');
12 const handlerBalance = require('./balance'); 12 const handlerBalance = require('./balance');
13 const handlerBuy = require('./buy'); 13 const handlerBuy = require('./buy');
14 const handlerChangePin = require('./changepin'); 14 const handlerChangePin = require('./changepin');
15 const handlerDaySummary = require('./daysummary'); 15 const handlerDaySummary = require('./daysummary');
16 const handlerDepositTicket = require('./depositticket');
16 const handlerDisableDownline = require('./disabledownline'); 17 const handlerDisableDownline = require('./disabledownline');
17 const handlerDownlineInfo = require('./downlineinfo'); 18 const handlerDownlineInfo = require('./downlineinfo');
18 const handlerEnableDownline = require('./enabledownline'); 19 const handlerEnableDownline = require('./enabledownline');
19 const handlerHelp = require('./help'); 20 const handlerHelp = require('./help');
20 const handlerListDownline = require('./listdownline'); 21 const handlerListDownline = require('./listdownline');
21 const handlerListTerminal = require('./listterminal'); 22 const handlerListTerminal = require('./listterminal');
22 const handlerPrice = require('./price'); 23 const handlerPrice = require('./price');
23 const handlerTransferBalance = require('./transferbalance'); 24 const handlerTransferBalance = require('./transferbalance');
24 25
25 function execute(msg, params, cb) { 26 function execute(msg, params, cb) {
26 27
27 if ( typeof msg !== 'string' || !msg.trim() ) { 28 if ( typeof msg !== 'string' || !msg.trim() ) {
28 cb(commandError.ERR_EMPTY_MESSAGE); 29 cb(commandError.ERR_EMPTY_MESSAGE);
29 return; 30 return;
30 } 31 }
31 32
32 const tokens = commandParser.splitToken(msg); 33 const tokens = commandParser.splitToken(msg);
33 const commandGroup = commandParser.extractCommandGroup(tokens); 34 const commandGroup = commandParser.extractCommandGroup(tokens);
34 logger.verbose('Got new message from partner', {msg: msg, params: params, tokens: tokens, commandGroup: commandGroup}); 35 logger.verbose('Got new message from partner', {msg: msg, params: params, tokens: tokens, commandGroup: commandGroup});
35 36
36 if (!commandGroup || commandGroup === 'buy') { 37 if (!commandGroup || commandGroup === 'buy') {
37 handlerBuy(tokens, params, cb); 38 handlerBuy(tokens, params, cb);
38 } 39 }
39 else if (commandGroup === 'balance') { 40 else if (commandGroup === 'balance') {
40 handlerBalance(tokens, params, cb); 41 handlerBalance(tokens, params, cb);
41 } 42 }
42 else if (commandGroup === 'addbalance') { 43 else if (commandGroup === 'addbalance') {
43 handlerAddBalance(tokens, params, cb); 44 handlerAddBalance(tokens, params, cb);
44 } 45 }
45 else if (commandGroup === 'transferbalance') { 46 else if (commandGroup === 'transferbalance') {
46 handlerTransferBalance(tokens, params, cb); 47 handlerTransferBalance(tokens, params, cb);
47 } 48 }
48 else if (commandGroup === 'price') { 49 else if (commandGroup === 'price') {
49 handlerPrice(tokens, params, cb); 50 handlerPrice(tokens, params, cb);
50 } 51 }
51 else if (commandGroup === 'listdownline') { 52 else if (commandGroup === 'listdownline') {
52 handlerListDownline(tokens, params, cb); 53 handlerListDownline(tokens, params, cb);
53 } 54 }
54 else if (commandGroup === 'downlineinfo') { 55 else if (commandGroup === 'downlineinfo') {
55 handlerDownlineInfo(tokens, params, cb); 56 handlerDownlineInfo(tokens, params, cb);
56 } 57 }
57 else if (commandGroup === 'adddownline') { 58 else if (commandGroup === 'adddownline') {
58 handlerAddDownline(tokens, params, cb); 59 handlerAddDownline(tokens, params, cb);
59 } 60 }
60 else if (commandGroup === 'listterminal') { 61 else if (commandGroup === 'listterminal') {
61 handlerListTerminal(tokens, params, cb); 62 handlerListTerminal(tokens, params, cb);
62 } 63 }
63 else if (commandGroup === 'addterminal') { 64 else if (commandGroup === 'addterminal') {
64 handlerAddTerminal(tokens, params, cb); 65 handlerAddTerminal(tokens, params, cb);
65 } 66 }
66 else if (commandGroup === 'changepin') { 67 else if (commandGroup === 'changepin') {
67 handlerChangePin(tokens, params, cb); 68 handlerChangePin(tokens, params, cb);
68 } 69 }
69 else if (commandGroup === 'enabledownline') { 70 else if (commandGroup === 'enabledownline') {
70 handlerEnableDownline(tokens, params, cb); 71 handlerEnableDownline(tokens, params, cb);
71 } 72 }
72 else if (commandGroup === 'daysummary') { 73 else if (commandGroup === 'daysummary') {
73 handlerDaySummary(tokens, params, cb); 74 handlerDaySummary(tokens, params, cb);
74 } 75 }
76 else if (commandGroup === 'depositticket') {
77 handlerDepositTicket(tokens, params, cb);
78 }
75 else if (commandGroup === 'disabledownline') { 79 else if (commandGroup === 'disabledownline') {
76 handlerDisableDownline(tokens, params, cb); 80 handlerDisableDownline(tokens, params, cb);
77 } 81 }
78 else if (commandGroup === 'help') { 82 else if (commandGroup === 'help') {
79 handlerHelp(cb) 83 handlerHelp(cb)
80 } 84 }
81 else { 85 else {
82 cb(commandError.ERR_NOT_IMPLEMENTED); 86 cb(commandError.ERR_NOT_IMPLEMENTED);
83 } 87 }
84 } 88 }
85 89
86 module.exports = execute; 90 module.exports = execute;
lib/coreapi/core-version.js
1 "use strict"; 1 "use strict";
2 2
3 const MINIMUM_VERSION = 'v1.33.1-32'; 3 const MINIMUM_VERSION = 'v1.34.0';
4 4
5 const util = require('util'); 5 const util = require('util');
6 const naturalCompare = require('natural-compare-lite'); 6 const naturalCompare = require('natural-compare-lite');
7 7
8 const logger = require('komodo-sdk/logger'); 8 const logger = require('komodo-sdk/logger');
9 const matrix = require('komodo-sdk/matrix'); 9 const matrix = require('komodo-sdk/matrix');
10 10
11 const coreMatrixRequest = util.promisify(require('./matrix')); 11 const coreMatrixRequest = util.promisify(require('./matrix'));
12 12
13 let _isSufficient = false; 13 let _isSufficient = false;
14 matrix.core_version_is_sufficient = false; 14 matrix.core_version_is_sufficient = false;
15 matrix.core_version_requirement = MINIMUM_VERSION; 15 matrix.core_version_requirement = MINIMUM_VERSION;
16 16
17 function logIfDev(...args) { 17 function logIfDev(...args) {
18 matrix.NODE_ENV !== 'production' && logger.verbose(...args); 18 matrix.NODE_ENV !== 'production' && logger.verbose(...args);
19 } 19 }
20 20
21 async function getCoreVersion() { 21 async function getCoreVersion() {
22 22
23 logIfDev('CORE-VERSION: checking core version'); 23 logIfDev('CORE-VERSION: checking core version');
24 24
25 try { 25 try {
26 var coreMatrix = await coreMatrixRequest(); 26 var coreMatrix = await coreMatrixRequest();
27 } 27 }
28 catch(e) { 28 catch(e) {
29 logger.verbose('Error requsting CORE version. ' + e.toString()) 29 logger.verbose('Error requsting CORE version. ' + e.toString())
30 } 30 }
31 31
32 if (!coreMatrix || !coreMatrix.version_active) { 32 if (!coreMatrix || !coreMatrix.version_active) {
33 setTimeout( 33 setTimeout(
34 function() { 34 function() {
35 getCoreVersion(); 35 getCoreVersion();
36 }, 36 },
37 5000 37 5000
38 ) 38 )
39 return; 39 return;
40 } 40 }
41 41
42 _isSufficient = naturalCompare(MINIMUM_VERSION, coreMatrix.version_active) <= 0; 42 _isSufficient = naturalCompare(MINIMUM_VERSION, coreMatrix.version_active) <= 0;
43 matrix.core_version_is_sufficient = _isSufficient; 43 matrix.core_version_is_sufficient = _isSufficient;
44 logger.info('CORE-VERSION', {version_active: coreMatrix.version_active, minimum_version: MINIMUM_VERSION, sufficient: _isSufficient}); 44 logger.info('CORE-VERSION', {version_active: coreMatrix.version_active, minimum_version: MINIMUM_VERSION, sufficient: _isSufficient});
45 45
46 if (!_isSufficient) { 46 if (!_isSufficient) {
47 setTimeout( 47 setTimeout(
48 function() { 48 function() {
49 getCoreVersion(); 49 getCoreVersion();
50 }, 50 },
51 5000 51 5000
52 ) 52 )
53 } 53 }
54 } 54 }
55 getCoreVersion(); 55 getCoreVersion();
56 56
57 function isSufficient() { 57 function isSufficient() {
58 return _isSufficient; 58 return _isSufficient;
59 } 59 }
60 60
61 module.exports = isSufficient(); 61 module.exports = isSufficient();
lib/default-command.js
1 module.exports = { 1 module.exports = {
2 help: [ 2 help: [
3 "bantu", 3 "bantu",
4 "bantuan", 4 "bantuan",
5 "format", 5 "format",
6 "help", 6 "help",
7 "tolong", 7 "tolong",
8 ], 8 ],
9 buy: [ 9 buy: [
10 "beli", 10 "beli",
11 "buy", 11 "buy",
12 "i", 12 "i",
13 "isi", 13 "isi",
14 ], 14 ],
15 _statuscheck: [ 15 _statuscheck: [
16 "cekstatus", 16 "cekstatus",
17 "checkstatus", 17 "checkstatus",
18 "status", 18 "status",
19 ], 19 ],
20 balance: [ 20 balance: [
21 "bal", 21 "bal",
22 "balance", 22 "balance",
23 "ceksaldo", 23 "ceksaldo",
24 "checksaldo", 24 "checksaldo",
25 "s", 25 "s",
26 "sal", 26 "sal",
27 "saldo", 27 "saldo",
28 ], 28 ],
29 transferbalance: [ 29 transferbalance: [
30 "transfer", 30 "transfer",
31 "trf", 31 "trf",
32 ], 32 ],
33 addbalance: [ 33 addbalance: [
34 "addbalance", 34 "addbalance",
35 "addbal", 35 "addbal",
36 "tambahsaldo", 36 "tambahsaldo",
37 ], 37 ],
38 listdownline: [ 38 listdownline: [
39 "dllist", 39 "dllist",
40 "downlinelist", 40 "downlinelist",
41 "ldl", 41 "ldl",
42 "listdl", 42 "listdl",
43 "listdownline", 43 "listdownline",
44 "listmitra", 44 "listmitra",
45 "lsdl", 45 "lsdl",
46 "lsdownline", 46 "lsdownline",
47 "lsmitra", 47 "lsmitra",
48 ], 48 ],
49 adddownline: [ 49 adddownline: [
50 "adddl", 50 "adddl",
51 "adddownline", 51 "adddownline",
52 "addmitra", 52 "addmitra",
53 "buatdl", 53 "buatdl",
54 "buatdownline", 54 "buatdownline",
55 "createdl", 55 "createdl",
56 "createdownlne", 56 "createdownlne",
57 "createmitra", 57 "createmitra",
58 "regdl", 58 "regdl",
59 "regdownline", 59 "regdownline",
60 "registerdl", 60 "registerdl",
61 "registerdownline", 61 "registerdownline",
62 "registermitra", 62 "registermitra",
63 "regmitra", 63 "regmitra",
64 "tambahdl", 64 "tambahdl",
65 "tambahdownline", 65 "tambahdownline",
66 "tambahmitra", 66 "tambahmitra",
67 ], 67 ],
68 downlineinfo: [ 68 downlineinfo: [
69 "dl", 69 "dl",
70 "downline", 70 "downline",
71 "mitra", 71 "mitra",
72 "saldodownline", 72 "saldodownline",
73 "saldomitra", 73 "saldomitra",
74 "sd", 74 "sd",
75 "sdl", 75 "sdl",
76 ], 76 ],
77 disabledownline: [ 77 disabledownline: [
78 "disabledl", 78 "disabledl",
79 "disabledownline", 79 "disabledownline",
80 "disablemitra", 80 "disablemitra",
81 "nonaktifdl", 81 "nonaktifdl",
82 "nonaktifdownline", 82 "nonaktifdownline",
83 "nonaktifkandl", 83 "nonaktifkandl",
84 "nonaktifkandownline", 84 "nonaktifkandownline",
85 "nonaktifkanmitra", 85 "nonaktifkanmitra",
86 "nonaktifmitra", 86 "nonaktifmitra",
87 ], 87 ],
88 enabledownline: [ 88 enabledownline: [
89 "aktifkandl", 89 "aktifkandl",
90 "aktifkandownline", 90 "aktifkandownline",
91 "aktifkanmitra", 91 "aktifkanmitra",
92 "aktivasidl", 92 "aktivasidl",
93 "aktivasidownline", 93 "aktivasidownline",
94 "aktivasimitra", 94 "aktivasimitra",
95 "enabledl", 95 "enabledl",
96 "enabledownline", 96 "enabledownline",
97 "enablemitra", 97 "enablemitra",
98 ], 98 ],
99 daysummary: [ 99 daysummary: [
100 "lap", 100 "lap",
101 "laporan", 101 "laporan",
102 "rekap", 102 "rekap",
103 ], 103 ],
104 price: [ 104 price: [
105 "cekharga", 105 "cekharga",
106 "ch", 106 "ch",
107 "checkharga", 107 "checkharga",
108 "h", 108 "h",
109 "harga", 109 "harga",
110 "hargaproduct", 110 "hargaproduct",
111 "hargaproduk", 111 "hargaproduk",
112 "price", 112 "price",
113 ], 113 ],
114 changepin: [ 114 changepin: [
115 "changepin", 115 "changepin",
116 "gantipin", 116 "gantipin",
117 "pin", 117 "pin",
118 "setpin", 118 "setpin",
119 "ubahpin", 119 "ubahpin",
120 ], 120 ],
121 _depositticket: [ 121 depositticket: [
122 'depo', 122 'depo',
123 'depositticket', 123 'depositticket',
124 'depoticket', 124 'depoticket',
125 'tiket', 125 'tiket',
126 'tiketdeposit', 126 'tiketdeposit',
127 ], 127 ],
128 listterminal: [ 128 listterminal: [
129 'listmsisdn', 129 'listmsisdn',
130 'listterminal', 130 'listterminal',
131 'lsmsisdn', 131 'lsmsisdn',
132 'lsterminal', 132 'lsterminal',
133 'msisdn', 133 'msisdn',
134 'msisdnlist', 134 'msisdnlist',
135 'msisdnls', 135 'msisdnls',
136 'terminal', 136 'terminal',
137 'terminallist', 137 'terminallist',
138 'terminalls', 138 'terminalls',
139 'terminalterdaftar', 139 'terminalterdaftar',
140 ], 140 ],
141 addterminal: [ 141 addterminal: [
142 'addmsisdn', 142 'addmsisdn',
143 'addterminal', 143 'addterminal',
144 'createmsisdn', 144 'createmsisdn',
145 'createterminal', 145 'createterminal',
146 'msisdnadd', 146 'msisdnadd',
147 'newmsisdn', 147 'newmsisdn',
148 'newterminal', 148 'newterminal',
149 'registerterminal', 149 'registerterminal',
150 'regmsisdn', 150 'regmsisdn',
151 'regterminal', 151 'regterminal',
152 'tambahmsisdn', 152 'tambahmsisdn',
153 'tambahterminal', 153 'tambahterminal',
154 'terminaladd', 154 'terminaladd',
155 ], 155 ],
156 _setmarkup: [ 156 _setmarkup: [
157 'markup' 157 'markup'
158 ] 158 ]
159 } 159 }
160 160