Commit 0cda3b29fd1f18b8c032e5b82da8c6c4cb594927

Authored by Adhidarma Hadiwinoto
1 parent 636896a548
Exists in master

PIN bisa dapat dari database

Showing 1 changed file with 20 additions and 3 deletions Side-by-side Diff

lib/partner-mkios.js
... ... @@ -20,10 +20,12 @@ if (config && config.debug_modem) {
20 20 process.env.KOMODO_DEBUG_MODEM=1;
21 21 }
22 22  
  23 +/*
23 24 if (!config || !config.partner || !config.partner.pin) {
24 25 logger.warn('Undefined PIN');
25 26 process.exit(1);
26 27 }
  28 +*/
27 29  
28 30 matrix.modem = {};
29 31  
... ... @@ -45,10 +47,14 @@ const resumeHandlers = {};
45 47  
46 48 let last_trx_id = null;
47 49  
  50 +function getPin() {
  51 + return ( config && config.partner && config.partner.pin ) || ( matrix && matrix.modem && matrix.modem.pin_trx );
  52 +}
  53 +
48 54 modem.on('open', function() {
49 55 logger.info('Modem opened');
50 56  
51   - const ussd_command = '*776*' + config.partner.pin + '#';
  57 + const ussd_command = '*776*' + getPin() + '#';
52 58 db.run("INSERT INTO ussd VALUES (?, ?, 'OUT', ?, ?)", moment().format('YYYY-MM-DD HH:mm:ss'), moment().format('YYYY-MM-DD'), matrix.modem.imsi, 'AT+CUSD=1,"' + ussd_command + '",15', function(err) {
53 59 if (err) {
54 60 logger.warn('Error inserting ussd command (stock check) to local database', {err: err});
... ... @@ -62,6 +68,7 @@ modem.on('imsi', function(imsi) {
62 68 logger.verbose('IMSI: ' + imsi);
63 69 matrix.modem.imsi = imsi;
64 70 matrix.modem.msisdn = chips && chips.by_imsi && chips.by_imsi[imsi] && chips.by_imsi[imsi].msisdn ? chips.by_imsi[imsi].msisdn : config.partner.msisdn;
  71 + matrix.modem.pin_trx = chips && chips.by_imsi && chips.by_imsi[imsi] && chips.by_imsi[imsi].pin ? chips.by_imsi[imsi].pin : null;
65 72 })
66 73  
67 74  
... ... @@ -286,11 +293,21 @@ function onTrxFinish(trx_id) {
286 293 }
287 294  
288 295 function buy(task) {
  296 +
  297 + if (!getPin()) {
  298 + report({
  299 + trx_id: task.trx_id,
  300 + rc: '40',
  301 + message: 'INTERNAL: Tidak dapat melakukan transaksi. PIN transaksi tidak terdefinisi.'
  302 + });
  303 + return;
  304 + }
  305 +
289 306 if (task.product === task.remote_product) {
290 307 report({
291 308 trx_id: task.trx_id,
292 309 rc: '40',
293   - message: 'INTERNAL: Gagal melakukan transaksi. Kode USSD belum terdefinisi.'
  310 + message: 'INTERNAL: Tidak dapat melakukan transaksi. Kode USSD belum terdefinisi.'
294 311 });
295 312 return;
296 313 }
... ... @@ -311,7 +328,7 @@ function buy(task) {
311 328 return;
312 329 }
313 330  
314   - const ussd_command = task.remote_product.split(',')[0].replace("<DESTINATION>", task.destination).replace("<PIN>", config.partner.pin);
  331 + const ussd_command = task.remote_product.split(',')[0].replace("<DESTINATION>", task.destination).replace("<PIN>", getPin());
315 332 logger.verbose('Going to execute USSD', {trx_id: task.trx_id, destination: task.destination, product: task.product, ussd: ussd_command});
316 333  
317 334 db.run("INSERT INTO ussd VALUES (?, ?, 'OUT', ?, ?)", moment().format('YYYY-MM-DD HH:mm:ss'), moment().format('YYYY-MM-DD'), matrix.modem.imsi, 'AT+CUSD=1,"' + ussd_command + '",15', function(err) {