Commit 73342a88531f8825a7f611869eb8d85485908930
1 parent
65d6174d3c
Exists in
master
penanganan ssl
Showing 1 changed file with 2 additions and 0 deletions Inline Diff
partner-bayarkilat.js
1 | var request = require('request'); | 1 | var request = require('request'); |
2 | var url = require('url'); | 2 | var url = require('url'); |
3 | var winston = require('winston'); | 3 | var winston = require('winston'); |
4 | 4 | ||
5 | var config; | 5 | var config; |
6 | var aaa; | 6 | var aaa; |
7 | var callbackReport; | 7 | var callbackReport; |
8 | var logger; | 8 | var logger; |
9 | 9 | ||
10 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | ||
11 | |||
10 | function start(_config, _callbackReport, options) { | 12 | function start(_config, _callbackReport, options) { |
11 | config = _config; | 13 | config = _config; |
12 | callbackReport = _callbackReport; | 14 | callbackReport = _callbackReport; |
13 | 15 | ||
14 | if (options && options.aaa) { | 16 | if (options && options.aaa) { |
15 | aaa = options.aaa; | 17 | aaa = options.aaa; |
16 | } | 18 | } |
17 | 19 | ||
18 | if (options && options.logger) { | 20 | if (options && options.logger) { |
19 | logger = options.logger; | 21 | logger = options.logger; |
20 | } else { | 22 | } else { |
21 | logger = new winston.Logger({ | 23 | logger = new winston.Logger({ |
22 | transports: [ | 24 | transports: [ |
23 | new (winston.transports.Console)() | 25 | new (winston.transports.Console)() |
24 | ] | 26 | ] |
25 | }); | 27 | }); |
26 | } | 28 | } |
27 | } | 29 | } |
28 | 30 | ||
29 | 31 | ||
30 | function topupRequest(task, retry) { | 32 | function topupRequest(task, retry) { |
31 | aaa.insertTaskToMongoDb(task); | 33 | aaa.insertTaskToMongoDb(task); |
32 | 34 | ||
33 | var partnerUrl = url.parse(config.h2h_out.partner); | 35 | var partnerUrl = url.parse(config.h2h_out.partner); |
34 | var product = prepareRemoteProductCode(task.remoteProduct); | 36 | var product = prepareRemoteProductCode(task.remoteProduct); |
35 | 37 | ||
36 | var options = { | 38 | var options = { |
37 | url: config.h2h_out.partner, | 39 | url: config.h2h_out.partner, |
38 | qs: { | 40 | qs: { |
39 | request: 'PURCHASE*' | 41 | request: 'PURCHASE*' |
40 | + task.requestId + '*' | 42 | + task.requestId + '*' |
41 | + product.product + '*' | 43 | + product.product + '*' |
42 | + product.productDetail + '*' | 44 | + product.productDetail + '*' |
43 | + task.destination + '*' | 45 | + task.destination + '*' |
44 | + task.nominal + '*' | 46 | + task.nominal + '*' |
45 | + '0*' | 47 | + '0*' |
46 | + config.h2h_out.noid + '*' | 48 | + config.h2h_out.noid + '*' |
47 | + config.h2h_out.userid + '*' | 49 | + config.h2h_out.userid + '*' |
48 | + config.h2h_out.password | 50 | + config.h2h_out.password |
49 | } | 51 | } |
50 | }; | 52 | }; |
51 | 53 | ||
52 | logger.verbose('Requesting to partner', {requestOption: options}); | 54 | logger.verbose('Requesting to partner', {requestOption: options}); |
53 | request(options, function(error, response, body) { | 55 | request(options, function(error, response, body) { |
54 | if (error) { | 56 | if (error) { |
55 | logger.warn('Error requesting to partner', {error: error}); | 57 | logger.warn('Error requesting to partner', {error: error}); |
56 | callbackReport(task.requestId, '68', 'Error requesting to partner. ' + error); | 58 | callbackReport(task.requestId, '68', 'Error requesting to partner. ' + error); |
57 | return; | 59 | return; |
58 | } | 60 | } |
59 | 61 | ||
60 | if (response.statusCode != 200) { | 62 | if (response.statusCode != 200) { |
61 | var message = 'Partner response with http status code other that 200 (' + response.statusCode +')'; | 63 | var message = 'Partner response with http status code other that 200 (' + response.statusCode +')'; |
62 | 64 | ||
63 | logger.warn(message); | 65 | logger.warn(message); |
64 | callbackReport(task.requestId, '68', message); | 66 | callbackReport(task.requestId, '68', message); |
65 | return; | 67 | return; |
66 | } | 68 | } |
67 | 69 | ||
68 | logger.verbose('Got response', {requestId: task.requestId, responseBody: body}); | 70 | logger.verbose('Got response', {requestId: task.requestId, responseBody: body}); |
69 | callbackReport(task.requestId, '68', body); | 71 | callbackReport(task.requestId, '68', body); |
70 | }); | 72 | }); |
71 | } | 73 | } |
72 | 74 | ||
73 | function prepareRemoteProductCode(remoteProduct) { | 75 | function prepareRemoteProductCode(remoteProduct) { |
74 | var product = remoteProduct.split(','); | 76 | var product = remoteProduct.split(','); |
75 | 77 | ||
76 | if (product.length != 3) { | 78 | if (product.length != 3) { |
77 | return; | 79 | return; |
78 | } | 80 | } |
79 | 81 | ||
80 | return { | 82 | return { |
81 | product: product[0], | 83 | product: product[0], |
82 | productDetail: product[1], | 84 | productDetail: product[1], |
83 | nominal: product[2] | 85 | nominal: product[2] |
84 | } | 86 | } |
85 | } | 87 | } |
86 | 88 | ||
87 | exports.start = start; | 89 | exports.start = start; |
88 | exports.topupRequest = topupRequest; | 90 | exports.topupRequest = topupRequest; |
89 | exports.prepareRemoteProductCode = prepareRemoteProductCode; | 91 | exports.prepareRemoteProductCode = prepareRemoteProductCode; |
90 | 92 |