Compare View
Commits (2)
Changes
Showing 3 changed files Inline Diff
index.js
1 | "use strict"; | 1 | "use strict"; |
2 | process.chdir(__dirname); | 2 | process.chdir(__dirname); |
3 | 3 | ||
4 | const pullgw = require('komodo-sdk/gateway/pull'); | 4 | const pullgw = require('komodo-sdk/gateway/pull'); |
5 | const partner = require('./lib/partner'); | 5 | const partner = require('./lib/partner'); |
6 | const reverseReport = require('./lib/reverse-report'); | 6 | const reverseReport = require('./lib/reverse-report'); |
7 | const adviceServer = require('komodo-sdk/gateway/advice-push-server'); | ||
7 | const adviceServer = require('komodo-sdk/gateway/advice-push-server'); | 8 | |
8 | 9 | pullgw.setPartner(partner); | |
10 | adviceServer.setPartner(partner); | ||
9 | pullgw.setPartner(partner); | 11 |
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 url = require('url'); | 5 | const url = require('url'); |
6 | const https = require('https'); | 6 | const https = require('https'); |
7 | const xmlrpc = require('xmlrpc'); | 7 | const xmlrpc = require('xmlrpc'); |
8 | 8 | ||
9 | const config = require('komodo-sdk/config'); | 9 | const config = require('komodo-sdk/config'); |
10 | const logger = require('komodo-sdk/logger'); | 10 | const logger = require('komodo-sdk/logger'); |
11 | const matrix = require('komodo-sdk/matrix'); | 11 | const matrix = require('komodo-sdk/matrix'); |
12 | const pull = require('komodo-sdk/gateway/pull'); | 12 | const pull = require('komodo-sdk/gateway/pull'); |
13 | 13 | ||
14 | const st24 = require('./st24'); | 14 | const st24 = require('./st24'); |
15 | const partnerRc = require('./partner-rc.json'); | 15 | const partnerRc = require('./partner-rc.json'); |
16 | 16 | ||
17 | if (config.partner.use_sslv3) { | 17 | if (config.partner.use_sslv3) { |
18 | https.globalAgent.options.secureProtocol = 'SSLv3_method'; | 18 | https.globalAgent.options.secureProtocol = 'SSLv3_method'; |
19 | } | 19 | } |
20 | 20 | ||
21 | function buy(task) { | 21 | function buy(task) { |
22 | const partnerUrl = url.parse(config.partner.url); | 22 | const partnerUrl = url.parse(config.partner.url); |
23 | const clientOptions = { | 23 | const clientOptions = { |
24 | host: partnerUrl.hostname, | 24 | host: partnerUrl.hostname, |
25 | port: partnerUrl.port, | 25 | port: partnerUrl.port, |
26 | path: partnerUrl.pathname | 26 | path: partnerUrl.pathname |
27 | }; | 27 | }; |
28 | 28 | ||
29 | let client; | 29 | let client; |
30 | if (partnerUrl.protocol == 'https:') { | 30 | if (partnerUrl.protocol == 'https:') { |
31 | client = xmlrpc.createSecureClient(clientOptions); | 31 | client = xmlrpc.createSecureClient(clientOptions); |
32 | } else { | 32 | } else { |
33 | client = xmlrpc.createClient(clientOptions); | 33 | client = xmlrpc.createClient(clientOptions); |
34 | } | 34 | } |
35 | 35 | ||
36 | const params = { | 36 | const params = { |
37 | MSISDN: config.partner.msisdn || config.partner.userid, | 37 | MSISDN: config.partner.msisdn || config.partner.userid, |
38 | REQUESTID: task.trx_id, | 38 | REQUESTID: task.trx_id, |
39 | PIN: config.partner.pin || config.partner.password, | 39 | PIN: config.partner.pin || config.partner.password, |
40 | NOHP: task.destination, | 40 | NOHP: task.destination, |
41 | NOM: task.remote_product | 41 | NOM: task.remote_product |
42 | }; | 42 | }; |
43 | 43 | ||
44 | const xmlrpcMethod = 'topUpRequest'; | 44 | const xmlrpcMethod = 'topUpRequest'; |
45 | logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: partnerUrl.href}); | 45 | logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: partnerUrl.href}); |
46 | 46 | ||
47 | client.methodCall(xmlrpcMethod, [ params ], function (err, value) { | 47 | client.methodCall(xmlrpcMethod, [ params ], function (err, value) { |
48 | 48 | ||
49 | if (err) { | 49 | if (err) { |
50 | 50 | ||
51 | let msg = 'XMLRPC Client Error: ' + err; | 51 | let msg = 'XMLRPC Client Error: ' + err; |
52 | let rc = '68'; | 52 | let rc = '68'; |
53 | 53 | ||
54 | if ( | 54 | if ( |
55 | err.code === 'ECONNREFUSED' | 55 | err.code === 'ECONNREFUSED' |
56 | || err.code === 'EHOSTUNREACH' | 56 | || err.code === 'EHOSTUNREACH' |
57 | || (err.code === 'ETIMEDOUT' && err.syscall === "connect") | 57 | || (err.code === 'ETIMEDOUT' && err.syscall === "connect") |
58 | || (err.code === 'EPROTO' && err.syscall === "write") | 58 | || (err.code === 'EPROTO' && err.syscall === "write") |
59 | ) { | 59 | ) { |
60 | rc = '91'; | 60 | rc = '91'; |
61 | } | 61 | } |
62 | 62 | ||
63 | logger.warn(msg, {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, err: err}); | 63 | logger.warn(msg, {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, err: err}); |
64 | report({ | 64 | report({ |
65 | trx_id: task.trx_id, | 65 | trx_id: task.trx_id, |
66 | rc: rc, | 66 | rc: rc, |
67 | message: 'INTERNAL: ' + msg, | 67 | message: 'INTERNAL: ' + msg, |
68 | misc: { | 68 | misc: { |
69 | task: task | 69 | task: task |
70 | } | 70 | } |
71 | }); | 71 | }); |
72 | 72 | ||
73 | return; | 73 | return; |
74 | } | 74 | } |
75 | 75 | ||
76 | logger.info('Got XMLRPC response from partner for', {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, response: value}); | 76 | logger.info('Got XMLRPC response from partner for', {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, response: value}); |
77 | matrix.last_topupRequest_ack = value; | 77 | matrix.last_topupRequest_ack = value; |
78 | 78 | ||
79 | report({ | 79 | report({ |
80 | trx_id: task.trx_id, | 80 | trx_id: task.trx_id, |
81 | rc: partnerRc[value.RESPONSECODE] || '40', | 81 | rc: partnerRc[value.RESPONSECODE] || '40', |
82 | message: value.MESSAGE, | 82 | message: value.MESSAGE, |
83 | sn: (value.SN || '').replace(/;$/, '') || st24.extractSnFromMessage(value.MESSAGE), | 83 | sn: (value.SN || '').replace(/;$/, '') || st24.extractSnFromMessage(value.MESSAGE), |
84 | amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE), | 84 | amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE), |
85 | raw: value, | 85 | raw: value, |
86 | misc: { | 86 | misc: { |
87 | task: task | 87 | task: task |
88 | } | 88 | } |
89 | }); | 89 | }); |
90 | }); | 90 | }); |
91 | } | 91 | } |
92 | 92 | ||
93 | function advice(task) { | 93 | function advice(task) { |
94 | const partnerUrl = url.parse(config.partner.url); | ||
95 | const clientOptions = { | ||
96 | host: partnerUrl.hostname, | ||
97 | port: partnerUrl.port, | ||
98 | path: partnerUrl.pathname | ||
99 | }; | ||
100 | |||
101 | let client; | ||
102 | if (partnerUrl.protocol == 'https:') { | ||
103 | client = xmlrpc.createSecureClient(clientOptions); | ||
104 | } else { | ||
105 | client = xmlrpc.createClient(clientOptions); | ||
106 | } | ||
107 | |||
108 | const params = { | ||
109 | REQUESTID: task.trx_id, | ||
110 | MSISDN: config.partner.msisdn || config.partner.userid, | ||
111 | PIN: config.partner.pin || config.partner.password, | ||
112 | NOHP: task.destination | ||
113 | }; | ||
114 | |||
115 | const xmlrpcMethod = 'topUpInquiry'; | ||
116 | logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: partnerUrl.href}); | ||
117 | |||
118 | client.methodCall(xmlrpcMethod, [ params ], function (err, value) { | ||
119 | |||
120 | if (err) { | ||
121 | |||
122 | const msg = 'XMLRPC Client Error: ' + err; | ||
123 | |||
124 | logger.warn(msg, {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, err: err}); | ||
125 | report({ | ||
126 | trx_id: task.trx_id, | ||
127 | rc: '68', | ||
128 | message: 'INTERNAL: ' + msg, | ||
129 | misc: { | ||
130 | task: task | ||
131 | } | ||
132 | }); | ||
133 | |||
134 | return; | ||
135 | } | ||
136 | |||
137 | logger.info('Got XMLRPC response from partner for', {method: xmlrpcMethod, trx_id: task.trx_id, destination: task.destination, response: value}); | ||
138 | //matrix.last_topupRequest_ack = value; | ||
139 | |||
140 | report({ | ||
141 | trx_id: task.trx_id, | ||
142 | rc: partnerRc[value.RESPONSECODE] || '40', | ||
143 | message: value.MESSAGE, | ||
144 | sn: (value.SN || '').replace(/;$/, '') || st24.extractSnFromMessage(value.MESSAGE), | ||
145 | amount: value.PRICE || st24.extractPriceFromMsg(value.MESSAGE), | ||
146 | raw: value, | ||
147 | misc: { | ||
148 | task: task | ||
149 | } | ||
150 | }); | ||
151 | }); | ||
94 | const partnerUrl = url.parse(config.partner.url); | 152 | } |
95 | const clientOptions = { | 153 | |
96 | host: partnerUrl.hostname, | 154 | function report(data) { |
97 | port: partnerUrl.port, | 155 | matrix.last_report_to_core = data; |
98 | path: partnerUrl.pathname | 156 | pull.report(data); |
99 | }; | 157 | } |
100 | 158 | ||
101 | let client; | 159 | exports.buy = buy; |
102 | if (partnerUrl.protocol == 'https:') { | 160 | exports.advice = advice; |
103 | client = xmlrpc.createSecureClient(clientOptions); | 161 | exports.report = report; |
104 | } else { | 162 |
package.json
1 | { | 1 | { |
2 | "name": "komodo-gw-st24", | 2 | "name": "komodo-gw-st24", |
3 | "version": "1.0.2", | 3 | "version": "1.1.0", |
4 | "description": "Komodo Gateway to ST24 XML-RPC", | 4 | "description": "Komodo Gateway to ST24 XML-RPC", |
5 | "main": "index.js", | 5 | "main": "index.js", |
6 | "scripts": { | 6 | "scripts": { |
7 | "test": "mocha", | 7 | "test": "mocha", |
8 | "postversion": "git push && git push --tags" | 8 | "postversion": "git push && git push --tags" |
9 | }, | 9 | }, |
10 | "repository": { | 10 | "repository": { |
11 | "type": "git", | 11 | "type": "git", |
12 | "url": "git@gitlab.kodesumber.com:komodo/komodo-gw-st24.git" | 12 | "url": "git@gitlab.kodesumber.com:komodo/komodo-gw-st24.git" |
13 | }, | 13 | }, |
14 | "keywords": [ | 14 | "keywords": [ |
15 | "komodo", | 15 | "komodo", |
16 | "tektrans", | 16 | "tektrans", |
17 | "ppob", | 17 | "ppob", |
18 | "st24", | 18 | "st24", |
19 | "xmlrpc", | 19 | "xmlrpc", |
20 | "xml-rpc" | 20 | "xml-rpc" |
21 | ], | 21 | ], |
22 | "author": "Adhidarma Hadiwinoto <me@adhisimon.org>", | 22 | "author": "Adhidarma Hadiwinoto <me@adhisimon.org>", |
23 | "license": "ISC", | 23 | "license": "ISC", |
24 | "dependencies": { | 24 | "dependencies": { |
25 | "komodo-sdk": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git", | 25 | "komodo-sdk": "git+http://gitlab.kodesumber.com/komodo/komodo-sdk.git", |
26 | "xmlrpc": "^1.3.2" | 26 | "xmlrpc": "^1.3.2" |
27 | } | 27 | } |
28 | } | 28 | } |
29 | 29 |