Compare View
Commits (4)
Changes
Showing 3 changed files Side-by-side Diff
config.sample.json
... | ... | @@ -11,6 +11,13 @@ |
11 | 11 | "pin": "PLEASE_CHANGE_ME", |
12 | 12 | "use_sslv3": false |
13 | 13 | }, |
14 | + "push_server": { | |
15 | + "apikey": "PLEASE_CHANGE_ME", | |
16 | + "advice": { | |
17 | + "port": 14283, | |
18 | + "url": "http://PLEASE_CHANGE_ME:14283/apikey/PLEASE_CHANGE_ME/advice" | |
19 | + } | |
20 | + }, | |
14 | 21 | "remote_products": { |
15 | 22 | "PLEASE_CHANGE_ME": "PLEASE_CHANGE_ME" |
16 | 23 | }, |
lib/partner.js
... | ... | @@ -18,21 +18,18 @@ if (config.partner.use_sslv3) { |
18 | 18 | https.globalAgent.options.secureProtocol = 'SSLv3_method'; |
19 | 19 | } |
20 | 20 | |
21 | -function buy(task) { | |
22 | - const partnerUrl = url.parse(config.partner.url); | |
21 | +function createXmlRpcClient(endpoint) { | |
22 | + const partnerUrl = url.parse(endpoint); | |
23 | 23 | const clientOptions = { |
24 | 24 | host: partnerUrl.hostname, |
25 | 25 | port: partnerUrl.port, |
26 | 26 | path: partnerUrl.pathname |
27 | 27 | }; |
28 | 28 | |
29 | - let client; | |
30 | - if (partnerUrl.protocol == 'https:') { | |
31 | - client = xmlrpc.createSecureClient(clientOptions); | |
32 | - } else { | |
33 | - client = xmlrpc.createClient(clientOptions); | |
34 | - } | |
29 | + return partnerUrl.protocol === 'https' ? xmlrpc.createSecureClient(clientOptions) : xmlrpc.createClient(clientOptions); | |
30 | +} | |
35 | 31 | |
32 | +function buy(task) { | |
36 | 33 | const params = { |
37 | 34 | MSISDN: config.partner.msisdn || config.partner.userid, |
38 | 35 | REQUESTID: task.trx_id, |
... | ... | @@ -42,8 +39,9 @@ function buy(task) { |
42 | 39 | }; |
43 | 40 | |
44 | 41 | const xmlrpcMethod = 'topUpRequest'; |
45 | - logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: partnerUrl.href}); | |
42 | + logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: config.partner.url}); | |
46 | 43 | |
44 | + const client = createXmlRpcClient(config.partner.url); | |
47 | 45 | client.methodCall(xmlrpcMethod, [ params ], function (err, value) { |
48 | 46 | |
49 | 47 | if (err) { |
... | ... | @@ -70,6 +68,13 @@ function buy(task) { |
70 | 68 | } |
71 | 69 | }); |
72 | 70 | |
71 | + if (rc === '68') { | |
72 | + setTimeout( | |
73 | + function() { advice(task); }, | |
74 | + 5 * 60 * 1000 | |
75 | + ); | |
76 | + } | |
77 | + | |
73 | 78 | return; |
74 | 79 | } |
75 | 80 | |
... | ... | @@ -91,20 +96,6 @@ function buy(task) { |
91 | 96 | } |
92 | 97 | |
93 | 98 | 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 | 99 | const params = { |
109 | 100 | REQUESTID: task.trx_id, |
110 | 101 | MSISDN: config.partner.msisdn || config.partner.userid, |
... | ... | @@ -113,8 +104,9 @@ function advice(task) { |
113 | 104 | }; |
114 | 105 | |
115 | 106 | const xmlrpcMethod = 'topUpInquiry'; |
116 | - logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: partnerUrl.href}); | |
107 | + logger.info('Preparing XMLRPC request', {method: xmlrpcMethod, params: params, partnerUrl: config.partner.url}); | |
117 | 108 | |
109 | + const client = createXmlRpcClient(config.partner.url); | |
118 | 110 | client.methodCall(xmlrpcMethod, [ params ], function (err, value) { |
119 | 111 | |
120 | 112 | if (err) { |
... | ... | @@ -131,6 +123,11 @@ function advice(task) { |
131 | 123 | } |
132 | 124 | }); |
133 | 125 | |
126 | + setTimeout( | |
127 | + function() { advice(task); }, | |
128 | + 60 * 1000 | |
129 | + ); | |
130 | + | |
134 | 131 | return; |
135 | 132 | } |
136 | 133 | |
... | ... | @@ -152,6 +149,10 @@ function advice(task) { |
152 | 149 | } |
153 | 150 | |
154 | 151 | function report(data) { |
152 | + if (!data) { | |
153 | + return; | |
154 | + } | |
155 | + | |
155 | 156 | matrix.last_report_to_core = data; |
156 | 157 | pull.report(data); |
157 | 158 | } |