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