Commit d0a6e83038fb54e5e69243274914eef6ff6d193e
1 parent
c48b094899
Exists in
master
Pebaikan config amount_pattern
Showing 3 changed files with 20 additions and 5 deletions Inline Diff
lib/irs/reverse-report.js
1 | const fs = require('fs'); | 1 | const fs = require('fs'); |
2 | const http = require('http'); | 2 | const http = require('http'); |
3 | const url = require('url'); | 3 | const url = require('url'); |
4 | 4 | ||
5 | const stringify = require("json-stringify-pretty-compact"); | 5 | const stringify = require("json-stringify-pretty-compact"); |
6 | 6 | ||
7 | const config = require('komodo-sdk/config'); | 7 | const config = require('komodo-sdk/config'); |
8 | const logger = require('komodo-sdk/logger'); | 8 | const logger = require('komodo-sdk/logger'); |
9 | 9 | ||
10 | const partner = require('../partner'); | 10 | const partner = require('../partner'); |
11 | const irs = require('komodo-gw-irs-lib'); | 11 | const irs = require('komodo-gw-irs-lib'); |
12 | 12 | ||
13 | const localRc = fs.existsSync(__dirname + '/../../rc-local.json') ? require('../../rc-local.json') : null; | 13 | const localRc = fs.existsSync(__dirname + '/../../rc-local.json') ? require('../../rc-local.json') : null; |
14 | if (localRc) { | 14 | if (localRc) { |
15 | logger.info('REVERSE-REPORT: Found rc-local.json', { | 15 | logger.info('REVERSE-REPORT: Found rc-local.json', { |
16 | useRcLocalOnReverseReport: config.partner.reverse_report_using_rc_local, | 16 | useRcLocalOnReverseReport: config.partner.reverse_report_using_rc_local, |
17 | localRc, | 17 | localRc, |
18 | }); | 18 | }); |
19 | } | 19 | } |
20 | 20 | ||
21 | function processPartnerReport(qs) { | 21 | function processPartnerReport(qs) { |
22 | let rc = '68'; | 22 | let rc = '68'; |
23 | 23 | ||
24 | if (config.partner.reverse_report_using_rc_local && localRc && qs.statuscode) { | 24 | if (config.partner.reverse_report_using_rc_local && localRc && qs.statuscode) { |
25 | rc = localRc[qs.statuscode] || '40'; | 25 | rc = localRc[qs.statuscode] || '40'; |
26 | } else if (qs.statuscode === '1') { | 26 | } else if (qs.statuscode === '1') { |
27 | rc = '00'; | 27 | rc = '00'; |
28 | } else if (qs.statuscode === '2') { | 28 | } else if (qs.statuscode === '2') { |
29 | rc = '40'; | 29 | rc = '40'; |
30 | } | 30 | } |
31 | 31 | ||
32 | if (rc === '40') { | 32 | if (rc === '40') { |
33 | rc = irs.getRcFromMessage(qs.msg) || '40'; | 33 | rc = irs.getRcFromMessage(qs.msg) || '40'; |
34 | } | 34 | } |
35 | 35 | ||
36 | let amount = null; | 36 | let amount = null; |
37 | if (rc === '00') { | 37 | if (rc === '00') { |
38 | amount = Number(qs.hrg); | 38 | amount = Number(qs.hrg); |
39 | if (!amount) { | 39 | if (!amount) { |
40 | amount = irs.getPriceFromMessage(qs.msg, config.partner.price_pattern); | 40 | amount = irs.getPriceFromMessage( |
41 | qs.msg, | ||
42 | config.partner.price_pattern || config.price_pattern || | ||
43 | ); | ||
41 | } | 44 | } |
42 | } | 45 | } |
43 | 46 | ||
44 | const balance = irs.getBalanceFromMessage(qs.msg, config.partner.balance_pattern) || null; | 47 | const balance = irs.getBalanceFromMessage(qs.msg, config.partner.balance_pattern) || null; |
45 | if (balance) { | 48 | if (balance) { |
46 | logger.verbose('REVERSE-REPORT: Balance from supplier extracted', { | 49 | logger.verbose('REVERSE-REPORT: Balance from supplier extracted', { |
47 | trxId: qs.clientid, | 50 | trxId: qs.clientid, |
48 | balance, | 51 | balance, |
49 | }) | 52 | }) |
50 | } | 53 | } |
51 | 54 | ||
52 | partner.report({ | 55 | partner.report({ |
53 | trx_id: qs.clientid, | 56 | trx_id: qs.clientid, |
54 | rc: rc, | 57 | rc: rc, |
55 | message: 'REVERSE-REPORT: ' + stringify(qs), | 58 | message: 'REVERSE-REPORT: ' + stringify(qs), |
56 | raw: stringify(qs), | 59 | raw: stringify(qs), |
57 | sn: (qs.sn ? qs.sn : null) || irs.getSnFromMessage(qs.msg, config.partner.sn_pattern) || null, | 60 | sn: (qs.sn ? qs.sn : null) || irs.getSnFromMessage(qs.msg, config.partner.sn_pattern) || null, |
58 | amount: amount, | 61 | amount: amount, |
59 | balance, | 62 | balance, |
60 | misc: {} | 63 | misc: {} |
61 | }) | 64 | }) |
62 | } | 65 | } |
63 | 66 | ||
64 | function create() { | 67 | function create() { |
65 | http.createServer(function (req, res) { | 68 | http.createServer(function (req, res) { |
66 | res.writeHead(200, {'Content-Type': 'text/html'}); | 69 | res.writeHead(200, {'Content-Type': 'text/html'}); |
67 | const qs = url.parse(req.url, true).query; | 70 | const qs = url.parse(req.url, true).query; |
68 | res.end('OK'); | 71 | res.end('OK'); |
69 | 72 | ||
70 | const remote_ip = req.connection ? req.connection.remoteAddress : null; | 73 | const remote_ip = req.connection ? req.connection.remoteAddress : null; |
71 | logger.verbose('REVERSE-REPORT: got report from partner', {url: req.url, remote_ip: remote_ip}); | 74 | logger.verbose('REVERSE-REPORT: got report from partner', {url: req.url, remote_ip: remote_ip}); |
72 | 75 | ||
73 | processPartnerReport(qs); | 76 | processPartnerReport(qs); |
74 | }).listen(config.reverse_report_port); | 77 | }).listen(config.reverse_report_port); |
75 | 78 | ||
76 | logger.info('REVERSE-REPORT: listen on port ' + config.reverse_report_port); | 79 | logger.info('REVERSE-REPORT: listen on port ' + config.reverse_report_port); |
77 | } | 80 | } |
78 | 81 | ||
79 | config.reverse_report_port && create(); | 82 | config.reverse_report_port && create(); |
80 | 83 |
lib/partner.js
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | 3 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; |
4 | 4 | ||
5 | const fs = require('fs'); | 5 | const fs = require('fs'); |
6 | const url = require('url'); | 6 | const url = require('url'); |
7 | const https = require('https'); | 7 | const https = require('https'); |
8 | const xmlrpc = require('xmlrpc'); | 8 | const xmlrpc = require('xmlrpc'); |
9 | const moment = require('moment'); | 9 | const moment = require('moment'); |
10 | const stringify = require("json-stringify-pretty-compact"); | 10 | const stringify = require("json-stringify-pretty-compact"); |
11 | 11 | ||
12 | const config = require('komodo-sdk/config'); | 12 | const config = require('komodo-sdk/config'); |
13 | const logger = require('komodo-sdk/logger'); | 13 | const logger = require('komodo-sdk/logger'); |
14 | const matrix = require('komodo-sdk/matrix'); | 14 | const matrix = require('komodo-sdk/matrix'); |
15 | const pull = require('komodo-sdk/gateway/pull'); | 15 | const pull = require('komodo-sdk/gateway/pull'); |
16 | const resendDelay = require('komodo-sdk/gateway/resend-delay'); | 16 | const resendDelay = require('komodo-sdk/gateway/resend-delay'); |
17 | 17 | ||
18 | const st24 = require('./st24'); | 18 | const st24 = require('./st24'); |
19 | 19 | ||
20 | if (config.partner.use_sslv3) { | 20 | if (config.partner.use_sslv3) { |
21 | https.globalAgent.options.secureProtocol = 'SSLv3_method'; | 21 | https.globalAgent.options.secureProtocol = 'SSLv3_method'; |
22 | } | 22 | } |
23 | 23 | ||
24 | const partnerRc = fs.existsSync(__dirname + '/../rc-local.json') ? require('../rc-local.json') : require('./partner-rc.json'); | 24 | const partnerRc = fs.existsSync(__dirname + '/../rc-local.json') ? require('../rc-local.json') : require('./partner-rc.json'); |
25 | logger.verbose('Partner RC dictionary loaded', {partner_rc: partnerRc}); | 25 | logger.verbose('Partner RC dictionary loaded', {partner_rc: partnerRc}); |
26 | 26 | ||
27 | const RESPONSECODE_TAG = config.responsecode_tag ? config.responsecode_tag : 'RESPONSECODE'; | 27 | const RESPONSECODE_TAG = config.responsecode_tag ? config.responsecode_tag : 'RESPONSECODE'; |
28 | 28 | ||
29 | function komodoRc(rc) { | 29 | function komodoRc(rc) { |
30 | return (config.partner.override_rc ? config.partner.override_rc[rc] : null) || partnerRc[rc] || '40'; | 30 | return (config.partner.override_rc ? config.partner.override_rc[rc] : null) || partnerRc[rc] || '40'; |
31 | } | 31 | } |
32 | 32 | ||
33 | function createXmlRpcClient(endpoint) { | 33 | function createXmlRpcClient(endpoint) { |
34 | const partnerUrl = url.parse(endpoint); | 34 | const partnerUrl = url.parse(endpoint); |
35 | const clientOptions = { | 35 | const clientOptions = { |
36 | host: partnerUrl.hostname, | 36 | host: partnerUrl.hostname, |
37 | port: partnerUrl.port, | 37 | port: partnerUrl.port, |
38 | path: partnerUrl.pathname | 38 | path: partnerUrl.pathname |
39 | }; | 39 | }; |
40 | 40 | ||
41 | logger.verbose('Creating XML-RPC client using ' + partnerUrl.protocol, clientOptions); | 41 | logger.verbose('Creating XML-RPC client using ' + partnerUrl.protocol, clientOptions); |
42 | 42 | ||
43 | return (partnerUrl.protocol === 'https:') ? xmlrpc.createSecureClient(clientOptions) : xmlrpc.createClient(clientOptions); | 43 | return (partnerUrl.protocol === 'https:') ? xmlrpc.createSecureClient(clientOptions) : xmlrpc.createClient(clientOptions); |
44 | } | 44 | } |
45 | 45 | ||
46 | function buy(task) { | 46 | function buy(task) { |
47 | _topUpRequest(task); | 47 | _topUpRequest(task); |
48 | } | 48 | } |
49 | 49 | ||
50 | function _topUpRequest(task, isAdvice) { | 50 | function _topUpRequest(task, isAdvice) { |
51 | const params = { | 51 | const params = { |
52 | MSISDN: config.partner.msisdn || config.partner.userid, | 52 | MSISDN: config.partner.msisdn || config.partner.userid, |
53 | REQUESTID: task.trx_id.toString(), | 53 | REQUESTID: task.trx_id.toString(), |
54 | PIN: config.partner.pin || config.partner.password, | 54 | PIN: config.partner.pin || config.partner.password, |
55 | NOHP: task.destination, | 55 | NOHP: task.destination, |
56 | NOM: task.remote_product | 56 | NOM: task.remote_product |
57 | }; | 57 | }; |
58 | 58 | ||
59 | const xmlrpcMethod = 'topUpRequest'; | 59 | const xmlrpcMethod = 'topUpRequest'; |
60 | logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: config.partner.url}); | 60 | logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: config.partner.url}); |
61 | 61 | ||
62 | const client = createXmlRpcClient(config.partner.url); | 62 | const client = createXmlRpcClient(config.partner.url); |
63 | client.methodCall(xmlrpcMethod, [ params ], function (err, value) { | 63 | client.methodCall(xmlrpcMethod, [ params ], function (err, value) { |
64 | 64 | ||
65 | if (err) { | 65 | if (err) { |
66 | 66 | ||
67 | const msg = `XMLRPC Client Error: ${err}. HTTP status code: ${err && err.res && err.res.statusCode ? err.res.statusCode : '-'}. Raw response body: ${err.body}`; | 67 | const msg = `XMLRPC Client Error: ${err}. HTTP status code: ${err && err.res && err.res.statusCode ? err.res.statusCode : '-'}. Raw response body: ${err.body}`; |
68 | let rc = '68'; | 68 | let rc = '68'; |
69 | 69 | ||
70 | if ( | 70 | if ( |
71 | !isAdvice && | 71 | !isAdvice && |
72 | ( | 72 | ( |
73 | err.code === 'ECONNREFUSED' | 73 | err.code === 'ECONNREFUSED' |
74 | || err.code === 'EHOSTUNREACH' | 74 | || err.code === 'EHOSTUNREACH' |
75 | || (err.code === 'ETIMEDOUT' && err.syscall === "connect") | 75 | || (err.code === 'ETIMEDOUT' && err.syscall === "connect") |
76 | || (err.code === 'EPROTO' && err.syscall === "write") | 76 | || (err.code === 'EPROTO' && err.syscall === "write") |
77 | ) | 77 | ) |
78 | ) { | 78 | ) { |
79 | rc = '91'; | 79 | rc = '91'; |
80 | } | 80 | } |
81 | 81 | ||
82 | logger.warn(msg, {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, err: err}); | 82 | logger.warn(msg, {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, err: err}); |
83 | report({ | 83 | report({ |
84 | trx_id: task.trx_id, | 84 | trx_id: task.trx_id, |
85 | rc: rc, | 85 | rc: rc, |
86 | message: 'topUpRequest INTERNAL ERROR: ' + msg, | 86 | message: 'topUpRequest INTERNAL ERROR: ' + msg, |
87 | misc: { | 87 | misc: { |
88 | task: task | 88 | task: task |
89 | } | 89 | } |
90 | }); | 90 | }); |
91 | 91 | ||
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | 94 | ||
95 | logger.info('Got XMLRPC response from partner for', {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, response: value}); | 95 | logger.info('Got XMLRPC response from partner for', {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, response: value}); |
96 | matrix.last_topupRequest_ack = value; | 96 | matrix.last_topupRequest_ack = value; |
97 | 97 | ||
98 | const balance = st24.extractBalanceFromMsg(value.MESSAGE, config.partner.balance_pattern || config.balance_pattern) || null; | 98 | const balance = st24.extractBalanceFromMsg(value.MESSAGE, config.partner.balance_pattern || config.balance_pattern) || null; |
99 | 99 | ||
100 | if (balance) { | 100 | if (balance) { |
101 | logger.verbose('TOPUPREQUEST: Balance from supplier extracted', { | 101 | logger.verbose('TOPUPREQUEST: Balance from supplier extracted', { |
102 | trxId: task.trx_id, | 102 | trxId: task.trx_id, |
103 | balance, | 103 | balance, |
104 | }); | 104 | }); |
105 | } | 105 | } |
106 | 106 | ||
107 | report({ | 107 | report({ |
108 | trx_id: task.trx_id, | 108 | trx_id: task.trx_id, |
109 | rc: komodoRc(value[RESPONSECODE_TAG]) || '40', | 109 | rc: komodoRc(value[RESPONSECODE_TAG]) || '40', |
110 | message: 'topUpRequest: ' + stringify(value), | 110 | message: 'topUpRequest: ' + stringify(value), |
111 | sn: (value.SN || '').replace(/;$/, '') || st24.extractSnFromMessage(value.MESSAGE, config.sn_pattern), | 111 | sn: (value.SN || '').replace(/;$/, '') || st24.extractSnFromMessage(value.MESSAGE, config.sn_pattern), |
112 | amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE, config.amount_pattern), | 112 | amount: value.PRICE || st24.extractPriceFromMsg( |
113 | value.MESSAGE, | ||
114 | config.partner.price_pattern || config.partner.amount_pattern || config.amount_pattern, | ||
115 | ), | ||
113 | balance, | 116 | balance, |
114 | raw: value, | 117 | raw: value, |
115 | misc: { | 118 | misc: { |
116 | task: task | 119 | task: task |
117 | } | 120 | } |
118 | }); | 121 | }); |
119 | }); | 122 | }); |
120 | } | 123 | } |
121 | 124 | ||
122 | function _topUpInquiry(task) { | 125 | function _topUpInquiry(task) { |
123 | const params = { | 126 | const params = { |
124 | REQUESTID: task.trx_id.toString(), | 127 | REQUESTID: task.trx_id.toString(), |
125 | MSISDN: config.partner.msisdn || config.partner.userid, | 128 | MSISDN: config.partner.msisdn || config.partner.userid, |
126 | PIN: config.partner.pin || config.partner.password, | 129 | PIN: config.partner.pin || config.partner.password, |
127 | NOHP: task.destination | 130 | NOHP: task.destination |
128 | }; | 131 | }; |
129 | 132 | ||
130 | const xmlrpcMethod = 'topUpInquiry'; | 133 | const xmlrpcMethod = 'topUpInquiry'; |
131 | logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: config.partner.url}); | 134 | logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: config.partner.url}); |
132 | 135 | ||
133 | const client = createXmlRpcClient(config.partner.url); | 136 | const client = createXmlRpcClient(config.partner.url); |
134 | client.methodCall(xmlrpcMethod, [ params ], function (err, value) { | 137 | client.methodCall(xmlrpcMethod, [ params ], function (err, value) { |
135 | 138 | ||
136 | if (err) { | 139 | if (err) { |
137 | 140 | ||
138 | const msg = 'XMLRPC Client Error: ' + err; | 141 | const msg = 'XMLRPC Client Error: ' + err; |
139 | 142 | ||
140 | logger.warn(msg, {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, err: err}); | 143 | logger.warn(msg, {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, err: err}); |
141 | report({ | 144 | report({ |
142 | trx_id: task.trx_id, | 145 | trx_id: task.trx_id, |
143 | rc: '68', | 146 | rc: '68', |
144 | message: 'topUpInquiry INTERNAL ERROR: ' + msg, | 147 | message: 'topUpInquiry INTERNAL ERROR: ' + msg, |
145 | misc: { | 148 | misc: { |
146 | task: task | 149 | task: task |
147 | } | 150 | } |
148 | }); | 151 | }); |
149 | 152 | ||
150 | return; | 153 | return; |
151 | } | 154 | } |
152 | 155 | ||
153 | logger.info('Got XMLRPC response from partner for', {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, response: value}); | 156 | logger.info('Got XMLRPC response from partner for', {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, response: value}); |
154 | //matrix.last_topupRequest_ack = value; | 157 | //matrix.last_topupRequest_ack = value; |
155 | 158 | ||
156 | report({ | 159 | report({ |
157 | trx_id: task.trx_id, | 160 | trx_id: task.trx_id, |
158 | rc: (value[RESPONSECODE_TAG] && (komodoRc(value[RESPONSECODE_TAG]) || '40')) || '68', | 161 | rc: (value[RESPONSECODE_TAG] && (komodoRc(value[RESPONSECODE_TAG]) || '40')) || '68', |
159 | message: 'topUpInquiry: ' + stringify(value), | 162 | message: 'topUpInquiry: ' + stringify(value), |
160 | sn: (value.SN || '').replace(/;$/, '') || st24.extractSnFromMessage(value.MESSAGE, config.sn_pattern), | 163 | sn: (value.SN || '').replace(/;$/, '') || st24.extractSnFromMessage(value.MESSAGE, config.sn_pattern), |
161 | amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE, config.amount_pattern), | 164 | amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE, config.amount_pattern), |
162 | balance: st24.extractBalanceFromMsg(value.MESSAGE, config.balance_pattern), | 165 | balance: st24.extractBalanceFromMsg(value.MESSAGE, config.balance_pattern), |
163 | raw: value, | 166 | raw: value, |
164 | misc: { | 167 | misc: { |
165 | task: task | 168 | task: task |
166 | } | 169 | } |
167 | }); | 170 | }); |
168 | }); | 171 | }); |
169 | } | 172 | } |
170 | 173 | ||
171 | function advice(task) { | 174 | function advice(task) { |
172 | if (config && config.advice_is_not_allowed) { | 175 | if (config && config.advice_is_not_allowed) { |
173 | return; | 176 | return; |
174 | } | 177 | } |
175 | 178 | ||
176 | if (config && config.advice_max_age_ms) { | 179 | if (config && config.advice_max_age_ms) { |
177 | if (moment() - moment(task.created) > config.advice_max_age_ms) { | 180 | if (moment() - moment(task.created) > config.advice_max_age_ms) { |
178 | logger.verbose('Ignoring advice request because of expired task', {trx_id: task.trx_id, destination: task.destination, product: task.product, created: task.created, max_age: config.advice_max_age_ms}); | 181 | logger.verbose('Ignoring advice request because of expired task', {trx_id: task.trx_id, destination: task.destination, product: task.product, created: task.created, max_age: config.advice_max_age_ms}); |
179 | return; | 182 | return; |
180 | } | 183 | } |
181 | } | 184 | } |
182 | 185 | ||
183 | if (config && config.advice_is_topuprequest) { | 186 | if (config && config.advice_is_topuprequest) { |
184 | _topUpRequest(task, true); | 187 | _topUpRequest(task, true); |
185 | } | 188 | } |
186 | else { | 189 | else { |
187 | _topUpInquiry(task); | 190 | _topUpInquiry(task); |
188 | } | 191 | } |
189 | } | 192 | } |
190 | 193 | ||
191 | function report(data) { | 194 | function report(data) { |
192 | if (!data) { | 195 | if (!data) { |
193 | return; | 196 | return; |
194 | } | 197 | } |
195 | 198 | ||
196 | if (config && config.force_all_to_pending) { | 199 | if (config && config.force_all_to_pending) { |
197 | data.rc = '68'; | 200 | data.rc = '68'; |
198 | } | 201 | } |
199 | 202 | ||
200 | matrix.last_report_to_core = data; | 203 | matrix.last_report_to_core = data; |
201 | pull.report(data); | 204 | pull.report(data); |
202 | 205 | ||
203 | if (!resendDelay.isEnabled()) { | 206 | if (!resendDelay.isEnabled()) { |
204 | //logger.verbose('Skipping resend delay because resend delay has not configured yet', {trx_id: task.trx_id, destination: task.destination, product: task.product}); | 207 | //logger.verbose('Skipping resend delay because resend delay has not configured yet', {trx_id: task.trx_id, destination: task.destination, product: task.product}); |
205 | return; | 208 | return; |
206 | } | 209 | } |
207 | 210 | ||
208 | if (data.rc !== '68') { | 211 | if (data.rc !== '68') { |
209 | logger.verbose('Canceling resend delay', {trx_id: data.trx_id}) | 212 | logger.verbose('Canceling resend delay', {trx_id: data.trx_id}) |
210 | resendDelay.cancel(data.trx_id); | 213 | resendDelay.cancel(data.trx_id); |
211 | return; | 214 | return; |
212 | } | 215 | } |
213 | 216 | ||
214 | 217 | ||
215 | if (!data.misc || !data.misc.task || typeof data.misc.task !== 'object') { | 218 | if (!data.misc || !data.misc.task || typeof data.misc.task !== 'object') { |
216 | return; | 219 | return; |
217 | } | 220 | } |
218 | 221 | ||
219 | const task = data.misc.task; | 222 | const task = data.misc.task; |
220 | logger.verbose('Registering resend delay', {trx_id: task.trx_id, destination: task.destination, product: task.product}) | 223 | logger.verbose('Registering resend delay', {trx_id: task.trx_id, destination: task.destination, product: task.product}) |
221 | resendDelay.register(task, advice); | 224 | resendDelay.register(task, advice); |
222 | 225 | ||
223 | } | 226 | } |
224 | 227 | ||
225 | exports.buy = buy; | 228 | exports.buy = buy; |
226 | exports.advice = advice; | 229 | exports.advice = advice; |
227 | exports.report = report; | 230 | exports.report = report; |
228 | exports.komodoRc = komodoRc; | 231 | exports.komodoRc = komodoRc; |
229 | exports.RESPONSECODE_TAG = RESPONSECODE_TAG; | 232 | exports.RESPONSECODE_TAG = RESPONSECODE_TAG; |
lib/reverse-report.js
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | const xmlrpc = require('xmlrpc'); | 3 | const xmlrpc = require('xmlrpc'); |
4 | const stringify = require("json-stringify-pretty-compact"); | 4 | const stringify = require("json-stringify-pretty-compact"); |
5 | 5 | ||
6 | const config = require('komodo-sdk/config'); | 6 | const config = require('komodo-sdk/config'); |
7 | const logger = require('komodo-sdk/logger'); | 7 | const logger = require('komodo-sdk/logger'); |
8 | const matrix = require('komodo-sdk/matrix'); | 8 | const matrix = require('komodo-sdk/matrix'); |
9 | 9 | ||
10 | const st24 = require('./st24'); | 10 | const st24 = require('./st24'); |
11 | const partner = require('./partner'); | 11 | const partner = require('./partner'); |
12 | // const partnerRc = require('./partner-rc.json'); | 12 | // const partnerRc = require('./partner-rc.json'); |
13 | 13 | ||
14 | function create() { | 14 | function create() { |
15 | if (!config || !config.reverse_report_port) { | 15 | if (!config || !config.reverse_report_port) { |
16 | logger.info('Not creating reverse report server because of undefined config.reverse_report_port'); | 16 | logger.info('Not creating reverse report server because of undefined config.reverse_report_port'); |
17 | return; | 17 | return; |
18 | } | 18 | } |
19 | 19 | ||
20 | const server = xmlrpc.createServer({ port: config.reverse_report_port }); | 20 | const server = xmlrpc.createServer({ port: config.reverse_report_port }); |
21 | 21 | ||
22 | logger.info('Reverse report server listen on port ' + config.reverse_report_port); | 22 | logger.info('Reverse report server listen on port ' + config.reverse_report_port); |
23 | 23 | ||
24 | server.on('NotFound', function (method, params) { | 24 | server.on('NotFound', function (method, params) { |
25 | logger.warn('REVERSEREPORT: Unknown method recevied on XMLRPC server', {method: method, params: params}); | 25 | logger.warn('REVERSEREPORT: Unknown method recevied on XMLRPC server', {method: method, params: params}); |
26 | }); | 26 | }); |
27 | 27 | ||
28 | server.on('topUpReport', function (err, params, callback) { | 28 | server.on('topUpReport', function (err, params, callback) { |
29 | 29 | ||
30 | logger.info('REVERSEREPORT: Got XMLRPC topUpReport request from partner', {method: 'topUpReport', params: params}); | 30 | logger.info('REVERSEREPORT: Got XMLRPC topUpReport request from partner', {method: 'topUpReport', params: params}); |
31 | matrix.last_topupReport_params = params; | 31 | matrix.last_topupReport_params = params; |
32 | 32 | ||
33 | const paramsCount = params.length; | 33 | const paramsCount = params.length; |
34 | for (let i = 0; i < paramsCount; i++) { | 34 | for (let i = 0; i < paramsCount; i++) { |
35 | let value = params[i]; | 35 | let value = params[i]; |
36 | 36 | ||
37 | partner.report({ | 37 | partner.report({ |
38 | trx_id: value.REQUESTID, | 38 | trx_id: value.REQUESTID, |
39 | // rc: partnerRc[value.RESPONSECODE] || '40', | 39 | // rc: partnerRc[value.RESPONSECODE] || '40', |
40 | rc: partner.komodoRc(value[partner.RESPONSECODE_TAG]) || '40', | 40 | rc: partner.komodoRc(value[partner.RESPONSECODE_TAG]) || '40', |
41 | //message: value.MESSAGE, | 41 | //message: value.MESSAGE, |
42 | message: 'topUpReport: ' + stringify(value), | 42 | message: 'topUpReport: ' + stringify(value), |
43 | sn: (value.SN || '').replace(/;+$/, '').replace(/#+$/, '') || st24.extractSnFromMessage(value.MESSAGE, config.sn_pattern), | 43 | sn: (value.SN || '').replace(/;+$/, '').replace(/#+$/, '') || st24.extractSnFromMessage( |
44 | amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE, config.amount_pattern), | 44 | value.MESSAGE, |
45 | balance: st24.extractBalanceFromMsg(value.MESSAGE, config.balance_pattern), | 45 | config.partner.sn_pattern || config.sn_pattern, |
46 | ), | ||
47 | amount: value.PRICE || st24.extractPriceFromMsg( | ||
48 | value.MESSAGE, | ||
49 | config.partner.price_pattern || config.partner.amount_pattern || config.amount_pattern, | ||
50 | ), | ||
51 | balance: st24.extractBalanceFromMsg( | ||
52 | value.MESSAGE, | ||
53 | config.partner.balance_pattern || config.balance_pattern, | ||
54 | ), | ||
46 | raw: value, | 55 | raw: value, |
47 | misc: { | 56 | misc: { |
48 | } | 57 | } |
49 | }); | 58 | }); |
50 | } | 59 | } |
51 | 60 | ||
52 | callback(null, 'ACK REPORT OK'); | 61 | callback(null, 'ACK REPORT OK'); |
53 | }) | 62 | }) |
54 | } | 63 | } |
55 | 64 | ||
56 | create(); | 65 | create(); |
57 | 66 |