Commit 3b9df1cc7ccfb3a769600037e89f8cde3a5e2c96

Authored by Adhidarma Hadiwinoto
1 parent 89288b1ed6
Exists in master

Update kamus rc, tambahkan rc40

Showing 1 changed file with 176 additions and 175 deletions Side-by-side Diff

1   -"use strict";
2   -
3   -process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
4   -
5   -const http = require('http');
6   -const url = require('url');
7   -const request = require('request');
8   -const resendDelay = require('sate24/resend-delay')
9   -
10   -const komodoRc = {
11   - '00': '00',
12   - '03': '40',
13   - '13': '13',
14   - '14': '14',
15   - '30': '40',
16   - '68': '68',
17   - '55': '55',
18   - '91': '91',
19   - '92': '40',
20   - '96': '68'
21   -}
22   -
23   -var config;
24   -var aaa;
25   -var logger;
26   -
27   -function start(options) {
28   - if (!options) {
29   - console.log('Undefined options, terminating....');
30   - process.exit(1);
31   - }
32   -
33   - if (options.config) {
34   - config = options.config;
35   - } else {
36   - console.log('Undefined options.config, terminating....')
37   - process.exit(1);
38   - }
39   -
40   - if (options.aaa) {
41   - aaa = options.aaa;
42   - } else {
43   - console.log('Undefined options.aaa, terminating....')
44   - process.exit(1);
45   - }
46   -
47   - if (options && options.logger) {
48   - logger = options.logger;
49   - } else {
50   - console.log('Undefined options.logger, terminating....')
51   - process.exit(1);
52   - }
53   -
54   - resendDelay.init({config: config, logger: logger, topupRequest: topupAdvice});
55   -
56   - createReverseHttpServer();
57   -
58   -}
59   -
60   -function callbackReport(requestId, rc, message, options) {
61   - aaa.callbackReportWithPushToMongoDb(requestId, rc, message);
62   -
63   - if (!options || !options.task) {
64   - return;
65   - }
66   -
67   - if (rc == '68') {
68   - resendDelay.register(options.task);
69   - } else {
70   - resendDelay.cancel(options.task)
71   - }
72   -}
73   -
74   -function topupRequest(task, pendingOnConnectError) {
75   - aaa.insertTaskToMongoDb(task);
76   -
77   - const requestOptions = {
78   - url: config.h2h_out.partner,
79   - qs: {
80   - terminal_name: config.h2h_out.terminal_name,
81   - password: config.h2h_out.password,
82   - product_name: task.remoteProduct,
83   - destination: task.destination,
84   - request_id: task.requestId,
85   - reverse_url: config.h2h_out.reverse_url
86   - }
87   - }
88   -
89   - logger.verbose('Requesting to partner', {request_options: requestOptions});
90   -
91   - request(requestOptions, function(err, response, body) {
92   - if (err) {
93   - logger.warn('Error requesting to partner', {err: err});
94   -
95   - let rc = '68';
96   -
97   - if (err.syscall == 'connect' && !pendingOnConnectError) {
98   - rc = '91';
99   - }
100   - callbackReport(task.requestId, rc, 'Error requesting to partner: ' + err, {task: task});
101   - return;
102   - }
103   -
104   - if (response.statusCode != 200) {
105   - let rc = '68';
106   -
107   - callbackReport(task.requestId, rc, 'Partner returning HTTP status code ' + response.statusCode + ', not 200', {task: task});
108   - return;
109   - }
110   -
111   - let result = parsePartnerMessage(body);
112   -
113   - if (!result) {
114   - callbackReport(task.requestId, '40', 'Error parsing response from partner. Partner response: ' + body, {task: task});
115   - return;
116   - }
117   -
118   - processPartnerResponse(result, task);
119   -
120   - })
121   -}
122   -
123   -function topupAdvice(task) {
124   - topupRequest(task, true);
125   -}
126   -
127   -function processPartnerResponse(resObj, task) {
128   - let st24Rc = '68';
129   -
130   - if (komodoRc[resObj.rc]) {
131   - st24Rc = komodoRc[resObj.rc];
132   - }
133   -
134   - let st24Message = resObj.message;
135   - if (resObj.sn) {
136   - st24Message = 'SN=' + resObj.sn + '; ' + st24Message;
137   - }
138   -
139   - callbackReport(resObj.request_id, st24Rc, st24Message, {task: task});
140   -}
141   -
142   -function parsePartnerMessage(partner_message) {
143   - let result;
144   - try {
145   - result = JSON.parse(partner_message);
146   -
147   - }
148   - catch(e) {
149   - logger.verbose('Exception on parsing partner message: ' + partner_message);
150   - result = null;
151   - }
152   -
153   - return result;
154   -}
155   -
156   -function createReverseHttpServer() {
157   - let listenPort = config.h2h_out.listen_port;
158   -
159   - http.createServer(onReverseReport).listen(listenPort, function() {
160   - logger.info('HTTP Reverse/Report server listen on port ' + listenPort);
161   - });
162   -}
163   -
164   -function onReverseReport(request, response) {
165   - response.end('OK');
166   -
167   - const qs = url.parse(request.url, true).query;
168   - logger.verbose('Got reverse report from partner', {qs: qs});
169   - processPartnerResponse(qs);
170   -}
171   -
172   -
173   -exports.start = start;
174   -exports.topupRequest = topupRequest;
175   -exports.topupAdvice = topupAdvice;
  1 +"use strict";
  2 +
  3 +process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
  4 +
  5 +const http = require('http');
  6 +const url = require('url');
  7 +const request = require('request');
  8 +const resendDelay = require('sate24/resend-delay')
  9 +
  10 +const komodoRc = {
  11 + '00': '00',
  12 + '03': '40',
  13 + '13': '13',
  14 + '14': '14',
  15 + '30': '40',
  16 + '40': '40',
  17 + '68': '68',
  18 + '55': '55',
  19 + '91': '91',
  20 + '92': '40',
  21 + '96': '68'
  22 +}
  23 +
  24 +var config;
  25 +var aaa;
  26 +var logger;
  27 +
  28 +function start(options) {
  29 + if (!options) {
  30 + console.log('Undefined options, terminating....');
  31 + process.exit(1);
  32 + }
  33 +
  34 + if (options.config) {
  35 + config = options.config;
  36 + } else {
  37 + console.log('Undefined options.config, terminating....')
  38 + process.exit(1);
  39 + }
  40 +
  41 + if (options.aaa) {
  42 + aaa = options.aaa;
  43 + } else {
  44 + console.log('Undefined options.aaa, terminating....')
  45 + process.exit(1);
  46 + }
  47 +
  48 + if (options && options.logger) {
  49 + logger = options.logger;
  50 + } else {
  51 + console.log('Undefined options.logger, terminating....')
  52 + process.exit(1);
  53 + }
  54 +
  55 + resendDelay.init({config: config, logger: logger, topupRequest: topupAdvice});
  56 +
  57 + createReverseHttpServer();
  58 +
  59 +}
  60 +
  61 +function callbackReport(requestId, rc, message, options) {
  62 + aaa.callbackReportWithPushToMongoDb(requestId, rc, message);
  63 +
  64 + if (!options || !options.task) {
  65 + return;
  66 + }
  67 +
  68 + if (rc == '68') {
  69 + resendDelay.register(options.task);
  70 + } else {
  71 + resendDelay.cancel(options.task)
  72 + }
  73 +}
  74 +
  75 +function topupRequest(task, pendingOnConnectError) {
  76 + aaa.insertTaskToMongoDb(task);
  77 +
  78 + const requestOptions = {
  79 + url: config.h2h_out.partner,
  80 + qs: {
  81 + terminal_name: config.h2h_out.terminal_name,
  82 + password: config.h2h_out.password,
  83 + product_name: task.remoteProduct,
  84 + destination: task.destination,
  85 + request_id: task.requestId,
  86 + reverse_url: config.h2h_out.reverse_url
  87 + }
  88 + }
  89 +
  90 + logger.verbose('Requesting to partner', {request_options: requestOptions});
  91 +
  92 + request(requestOptions, function(err, response, body) {
  93 + if (err) {
  94 + logger.warn('Error requesting to partner', {err: err});
  95 +
  96 + let rc = '68';
  97 +
  98 + if (err.syscall == 'connect' && !pendingOnConnectError) {
  99 + rc = '91';
  100 + }
  101 + callbackReport(task.requestId, rc, 'Error requesting to partner: ' + err, {task: task});
  102 + return;
  103 + }
  104 +
  105 + if (response.statusCode != 200) {
  106 + let rc = '68';
  107 +
  108 + callbackReport(task.requestId, rc, 'Partner returning HTTP status code ' + response.statusCode + ', not 200', {task: task});
  109 + return;
  110 + }
  111 +
  112 + let result = parsePartnerMessage(body);
  113 +
  114 + if (!result) {
  115 + callbackReport(task.requestId, '40', 'Error parsing response from partner. Partner response: ' + body, {task: task});
  116 + return;
  117 + }
  118 +
  119 + processPartnerResponse(result, task);
  120 +
  121 + })
  122 +}
  123 +
  124 +function topupAdvice(task) {
  125 + topupRequest(task, true);
  126 +}
  127 +
  128 +function processPartnerResponse(resObj, task) {
  129 + let st24Rc = '68';
  130 +
  131 + if (komodoRc[resObj.rc]) {
  132 + st24Rc = komodoRc[resObj.rc];
  133 + }
  134 +
  135 + let st24Message = resObj.message;
  136 + if (resObj.sn) {
  137 + st24Message = 'SN=' + resObj.sn + '; ' + st24Message;
  138 + }
  139 +
  140 + callbackReport(resObj.request_id, st24Rc, st24Message, {task: task});
  141 +}
  142 +
  143 +function parsePartnerMessage(partner_message) {
  144 + let result;
  145 + try {
  146 + result = JSON.parse(partner_message);
  147 +
  148 + }
  149 + catch(e) {
  150 + logger.verbose('Exception on parsing partner message: ' + partner_message);
  151 + result = null;
  152 + }
  153 +
  154 + return result;
  155 +}
  156 +
  157 +function createReverseHttpServer() {
  158 + let listenPort = config.h2h_out.listen_port;
  159 +
  160 + http.createServer(onReverseReport).listen(listenPort, function() {
  161 + logger.info('HTTP Reverse/Report server listen on port ' + listenPort);
  162 + });
  163 +}
  164 +
  165 +function onReverseReport(request, response) {
  166 + response.end('OK');
  167 +
  168 + const qs = url.parse(request.url, true).query;
  169 + logger.verbose('Got reverse report from partner', {qs: qs});
  170 + processPartnerResponse(qs);
  171 +}
  172 +
  173 +
  174 +exports.start = start;
  175 +exports.topupRequest = topupRequest;
  176 +exports.topupAdvice = topupAdvice;
176 177 \ No newline at end of file