Compare View
Commits (4)
Changes
Showing 3 changed files Side-by-side Diff
center/messaging/trx-center.js
... | ... | @@ -26,12 +26,18 @@ function onIncomingMessage(paramsFromTransport, cb) { |
26 | 26 | |
27 | 27 | const command = paramsFromTransport.msg.split(/[\., ]+/)[0].toUpperCase(); |
28 | 28 | |
29 | - if (config.commands && config.commands.balance.indexOf(command) >= 0) { | |
29 | + if (config.commands && config.commands.balance && config.commands.balance.indexOf(command) >= 0) { | |
30 | 30 | executeBalanceCheck(paramsFromTransport, cb); |
31 | 31 | } |
32 | - else if (config.commands && config.commands.price.indexOf(command) >= 0) { | |
32 | + else if (config.commands && config.commands.price && config.commands.price.indexOf(command) >= 0) { | |
33 | 33 | executePriceCheck(paramsFromTransport, cb); |
34 | 34 | } |
35 | + else if (config.commands && config.commands.postpaid_inquiry && config.commands.postpaid_inquiry.indexOf(command) >= 0) { | |
36 | + | |
37 | + } | |
38 | + else if (config.commands && config.commands.postpaid_pay && config.commands.postpaid_pay.indexOf(command) >= 0) { | |
39 | + | |
40 | + } | |
35 | 41 | else { |
36 | 42 | executePrepaidBuy(paramsFromTransport, cb); |
37 | 43 | } |
... | ... | @@ -114,6 +120,70 @@ function executePrepaidBuy(paramsFromTransport, cb) { |
114 | 120 | requestToCore(requestOptions, cb); |
115 | 121 | } |
116 | 122 | |
123 | +function executePostpaidInquiry(paramsFromTransport, cb) { | |
124 | + // PAY.PLN.1234567890.PIN | |
125 | + | |
126 | + let tokens = paramsFromTransport.msg.trim().split(/[\., ]+/); | |
127 | + | |
128 | + let qs = { | |
129 | + request_id: tokens[4], | |
130 | + terminal_name: paramsFromTransport.partner.toLowerCase(), | |
131 | + product_name: tokens[1].toUpperCase(), | |
132 | + destination: tokens[2].toUpperCase(), | |
133 | + password: tokens[3], | |
134 | + origin: config.origin || config.username, | |
135 | + report_port: config.listen_port || '80', | |
136 | + msg: paramsFromTransport.msg, | |
137 | + reverse_url: paramsFromTransport.reverse_url | |
138 | + } | |
139 | + | |
140 | + if (!config.do_not_prefix_request_id) { | |
141 | + qs.request_id = generateRequestId(qs); | |
142 | + if (tokens[3]) { | |
143 | + qs.request_id += '_' + tokens[3]; | |
144 | + } | |
145 | + } | |
146 | + | |
147 | + let requestOptions = { | |
148 | + url: config.core_url + '/postpaid/pay', | |
149 | + qs: qs | |
150 | + } | |
151 | + | |
152 | + requestToCore(requestOptions, cb); | |
153 | +} | |
154 | + | |
155 | +function executePostpaidPay(paramsFromTransport, cb) { | |
156 | + // INQUIRY.PLN.1234567890.PIN | |
157 | + | |
158 | + let tokens = paramsFromTransport.msg.trim().split(/[\., ]+/); | |
159 | + | |
160 | + let qs = { | |
161 | + request_id: tokens[4], | |
162 | + terminal_name: paramsFromTransport.partner.toLowerCase(), | |
163 | + product_name: tokens[1].toUpperCase(), | |
164 | + destination: tokens[2].toUpperCase(), | |
165 | + password: tokens[3], | |
166 | + origin: config.origin || config.username, | |
167 | + report_port: config.listen_port || '80', | |
168 | + msg: paramsFromTransport.msg, | |
169 | + reverse_url: paramsFromTransport.reverse_url | |
170 | + } | |
171 | + | |
172 | + if (!config.do_not_prefix_request_id) { | |
173 | + qs.request_id = generateRequestId(qs); | |
174 | + if (tokens[3]) { | |
175 | + qs.request_id += '_' + tokens[3]; | |
176 | + } | |
177 | + } | |
178 | + | |
179 | + let requestOptions = { | |
180 | + url: config.core_url + '/postpaid/inquiry', | |
181 | + qs: qs | |
182 | + } | |
183 | + | |
184 | + requestToCore(requestOptions, cb); | |
185 | +} | |
186 | + | |
117 | 187 | function requestToCore(requestOptions, cb) { |
118 | 188 | logger.verbose('Requesting service to CORE', requestOptions); |
119 | 189 |
gateway/pull.js
... | ... | @@ -88,10 +88,6 @@ function forwardCoreTaskToPartner(coreMessage) { |
88 | 88 | } |
89 | 89 | |
90 | 90 | function report(data) { |
91 | - reportUsingHttpPost(data); | |
92 | -} | |
93 | - | |
94 | -function reportUsingHttpPost(data) { | |
95 | 91 | |
96 | 92 | let core_pull_report_url; |
97 | 93 | |
... | ... | @@ -116,9 +112,7 @@ function reportUsingHttpPost(data) { |
116 | 112 | sn: data.sn, |
117 | 113 | amount: data.amount, |
118 | 114 | raw: data.raw, |
119 | - combined: { | |
120 | - raw: data.raw | |
121 | - } | |
115 | + misc: data.misc | |
122 | 116 | } |
123 | 117 | } |
124 | 118 | |
... | ... | @@ -136,46 +130,6 @@ function reportUsingHttpPost(data) { |
136 | 130 | }); |
137 | 131 | } |
138 | 132 | |
139 | -function reportUsingHttpGet(data) { | |
140 | - let core_pull_report_url; | |
141 | - | |
142 | - if (config.core_url) { | |
143 | - core_pull_report_url = config.core_url + '/pull/report'; | |
144 | - } else if (config.pull_url.report) { | |
145 | - core_pull_report_url = config.pull_url.report.replace('<CORE_APIKEY>', config.core_apikey); | |
146 | - } | |
147 | - | |
148 | - if (!core_pull_report_url) { | |
149 | - logger.warn('Unknown CORE report url'); | |
150 | - return; | |
151 | - } | |
152 | - | |
153 | - let options = { | |
154 | - url: core_pull_report_url, | |
155 | - qs: { | |
156 | - trx_id: data.trx_id, | |
157 | - rc: data.rc, | |
158 | - message: data.message, | |
159 | - handler: config.handler_name, | |
160 | - sn: data.sn, | |
161 | - amount: data.amount | |
162 | - } | |
163 | - } | |
164 | - | |
165 | - logger.verbose('Report to CORE using HTTP GET'); | |
166 | - request(options, function(error, response, body) { | |
167 | - if (error) { | |
168 | - logger.warn('Error reporting to CORE', {error: error}); | |
169 | - } | |
170 | - else if (response.statusCode != 200) { | |
171 | - logger.warn('CORE http response status is not 200', {requestOptions: options, http_response_status: response.statusCode}); | |
172 | - } | |
173 | - else { | |
174 | - logger.verbose('Report has been sent to CORE', {requestOptions: options}); | |
175 | - } | |
176 | - }); | |
177 | -} | |
178 | - | |
179 | 133 | function resendReport(data) { |
180 | 134 | let sleepBeforeResend = 1000; |
181 | 135 | logger.verbose('Resend report to CORE in ' + sleepBeforeResend + 'ms') |