Commit bb3e05947bedeefec5551c0fd0141af35b9f3097

Authored by Adhidarma Hadiwinoto
1 parent cd12c75614
Exists in master

siap dicoba

Showing 3 changed files with 179 additions and 0 deletions Inline Diff

File was created 1 {
2 "name": "sate24-to-irs",
3 "version": "1.0.0",
4 "description": "ST25 to IRS",
5 "main": "index.js",
6 "scripts": {
7 "test": "mocha"
8 },
9 "repository": {
10 "type": "git",
11 "url": "git@gitlab.kodesumber.com:reload97/sate24-to-irs.git"
12 },
13 "keywords": [
14 "st24",
15 "ppob",
16 "irs",
17 "reload97",
18 "r97"
19 ],
20 "author": "Adhidarma Hadiwinoto <me@adhisimon.org>",
21 "license": "ISC",
22 "dependencies": {
23 "ini": "^1.3.4",
24 "request": "^2.72.0",
25 "sate24": "git+http://gitlab.kodesumber.com/reload97/node-sate24.git",
26 "sate24-expresso": "git+http://gitlab.kodesumber.com/reload97/sate24-expresso.git",
27 "url": "^0.11.0",
28 "winston": "^2.2.0",
29 "xmlrpc": "^1.3.1"
30 }
31 }
32
File was created 1 var winston = require('winston');
2 var request = require('request');
3 var xmlrpc = require('xmlrpc');
4 var url = require('url');
5
6 var max_retry = 3;
7 var sleep_before_retry = 2000;
8
9 process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
10
11 var config;
12 var callbackReport;
13 var aaa;
14 var logger;
15 var options;
16
17 function start(_config, _callbackReport, options) {
18 config = _config;
19 callbackReport = _callbackReport
20
21 if (options && options.aaa) {
22 aaa = options.aaa;
23 }
24
25 if (options && options.logger) {
26 logger = options.logger;
27 } else {
28 logger = new winston.Logger({
29 transports: [
30 new (winston.transports.Console)()
31 ]
32 });
33 }
34
35 createHttpReportServer();
36 }
37
38 function createHttpReportServer() {
39 var httpServer = http.createServer(function(request, response) {
40 var qs = url.parse(request.url, true).query;
41 var path = url.parse(request.url).pathname;
42
43 logger.info('Got reverse report from partner', {path: path, qs: qs});
44 response.end('OK');
45
46 /*
47 var trxid;
48 try {
49 trxid = qs.transid;
50 }
51 catch(err) {
52 }
53
54 if (trxid) {
55 logger.info('Requesting advice from webreport', {trxid: trxid})
56 cekstatus.advice({trxid: trxid}, callbackFromWebReport);
57 }
58 */
59
60 });
61
62 httpServer.listen(config.h2h_out.listen_port, function() {
63 logger.info('HTTP Reverse/Report server listen on port ' + config.h2h_out.listen_port);
64 });
65 }
66
67 function topupRequestHttpGet(task, retry) {
68
69 var options = {
70 method: 'GET',
71 url: config.h2h_out.partner,
72 qs: {
73 id: config.h2h_out.userid,
74 pin: config.h2h_out.pin,
75 user: config.h2h_out.user,
76 pass: config.h2h_put.password,
77 kodeproduk: task.remoteProduct,
78 tujuan: task.destination,
79 idtrx: task.requestId
80 }
81 }
82
83 request(options, function(err, res, body) {
84 });
85 }
86
87 function topupRequestXMLRPC(task, retry) {
88 var partnerUrl = url.parse(config.h2h_out.partner);
89 var clientOptions = {
90 host: partnerUrl.hostname
91 , port: partnerUrl.port
92 , path: partnerUrl.pathname
93 };
94 logger.info('Preparing XMLRPC client options', {options: clientOptions});
95
96 var client;
97 if (partnerUrl.protocol == 'https:') {
98 client = xmlrpc.createSecureClient(clientOptions);
99 } else {
100 client = xmlrpc.createClient(clientOptions);
101 }
102
103 var params = {
104 MSISDN: config.h2h_out.userid,
105 REQUESTID: task.requestId,
106 PIN: config.h2h_out.password,
107 NOHP: task.destination,
108 NOM: task.remoteProduct
109 };
110
111 var methodName = 'topUpRequest';
112 logger.info('Preparing XMLRPC client method', {methodname: methodName, params: params});
113
114 client.methodCall(methodName, [ params ], function (error, value) {
115 // Results of the method response
116 if (error) {
117
118 logger.warn('XMLRPC Client Error', {requestId: task['requestId'], errorMessage: error});
119
120 if (retry) {
121
122 logger.info('Retrying topUpRequest (' + retry + ')');
123 setTimeout(function() {
124 topupRequest(task, retry - 1);
125 }, sleep_before_retry);
126
127 } else {
128 callbackReport(task['requestId'], '91', 'Gangguan koneksi ke suplier: ' + error);
129 }
130 return;
131 }
132
133 logger.info('Got XMLRPC response from partner for', {response_method: methodName, response_message: value});
134
135 if (value['RESPONSECODE'] == '00' && config.h2h_out.parse_sn == 'YES') {
136 value['MESSAGE'] = 'SN=' + parseSN(value['MESSAGE']) + '; ' + value['MESSAGE'];
137 }
138
139 callbackReport(value['REQUESTID'], value['RESPONSECODE'], value['MESSAGE']);
140 });
141 }
142
143 function topupRequest(task, retry) {
144 topupRequestXMLRPC(task, retry);
145 }
146
147 exports.start = start;
148 exports.topupRequest = topupRequest;
149