Commit 0a7aef7834de3cd3e1e733cdaed3cc267819ba99

Authored by Adhidarma Hadiwinoto
1 parent b0323ac2e3
Exists in master

cekstatus jadi module

Showing 1 changed file with 25 additions and 24 deletions Side-by-side Diff

... ... @@ -7,7 +7,7 @@ var xml2js = require('xml2js').parseString;
7 7 var argv = require('minimist')(process.argv.slice(2), {string: ['requestid', 'destination']});
8 8 var strftime = require('strftime');
9 9  
10   -var config = {
  10 +var _config = {
11 11 webreport: {
12 12 login_url: 'http://103.11.75.142:9009/dealer/index.php/admin/login',
13 13 username: 'reload97',
... ... @@ -15,6 +15,10 @@ var config = {
15 15 }
16 16 };
17 17  
  18 +function getTrxStatusFromWebReport(data, callback) {
  19 + login(data, callback);
  20 +};
  21 +
18 22 function login(data, callback) {
19 23 var jar = request.jar();
20 24  
... ... @@ -41,12 +45,12 @@ function login(data, callback) {
41 45 return;
42 46 }
43 47  
44   - callback(data, jar);
  48 + getTrxStatusPage(data, jar, callback);
45 49  
46 50 });
47 51 }
48 52  
49   -function getTrxStatusPage(data, jar) {
  53 +function getTrxStatusPage(data, jar, callback) {
50 54 var options = {
51 55 url: 'http://103.11.75.142:9009/dealer/index.php/transaction/index',
52 56 jar: jar,
... ... @@ -112,34 +116,31 @@ function getTrxStatusPage(data, jar) {
112 116  
113 117 status.response = result.result;
114 118  
115   -
116   - console.log(status);
  119 + if (!callback) {
  120 + console.log(status);
  121 + } else {
  122 + callback(status);
  123 + }
117 124 });
118   -
119   -
120   -
121 125 });
122 126  
123 127 }
124 128  
125   -/*
126   -if (!argv.destination || argv.destination === true) {
127   - console.log('Missing "destination" parameter');
128   - process.exit(1);
129   -}
130   -*/
  129 +if (require.main === module) {
  130 + var data = {
  131 + trxid: argv.trxid,
  132 + destination: argv.destination,
  133 + }
131 134  
132   -data = {
133   - trxid: argv.trxid,
134   - destination: argv.destination,
135   -}
  135 + if (argv.trxid) {
  136 + data.trxid = argv.trxid;
  137 + }
136 138  
137   -if (argv.trxid) {
138   - data.trxid = argv.trxid;
139   -}
  139 + if (argv.destination) {
  140 + data.destinaton = argv.destination;
  141 + }
140 142  
141   -if (argv.destination) {
142   - data.destinaton = argv.destination;
  143 + getTrxStatusFromWebReport(data);
143 144 }
144 145  
145   -login(data, getTrxStatusPage);
  146 +exports.getTrxStatusFromWebReport = getTrxStatusFromWebReport;