Commit 65d6174d3cea4637d7a339e6af86af985976dbc4
1 parent
5909d674dd
Exists in
master
typo
Showing 1 changed file with 1 additions and 1 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 | url: url: config.h2h_out.partner, | 37 | url: config.h2h_out.partner, |
38 | qs: { | 38 | qs: { |
39 | request: 'PURCHASE*' | 39 | request: 'PURCHASE*' |
40 | + task.requestId + '*' | 40 | + task.requestId + '*' |
41 | + product.product + '*' | 41 | + product.product + '*' |
42 | + product.productDetail + '*' | 42 | + product.productDetail + '*' |
43 | + task.destination + '*' | 43 | + task.destination + '*' |
44 | + task.nominal + '*' | 44 | + task.nominal + '*' |
45 | + '0*' | 45 | + '0*' |
46 | + config.h2h_out.noid + '*' | 46 | + config.h2h_out.noid + '*' |
47 | + config.h2h_out.userid + '*' | 47 | + config.h2h_out.userid + '*' |
48 | + config.h2h_out.password | 48 | + config.h2h_out.password |
49 | } | 49 | } |
50 | }; | 50 | }; |
51 | 51 | ||
52 | logger.verbose('Requesting to partner', {requestOption: options}); | 52 | logger.verbose('Requesting to partner', {requestOption: options}); |
53 | request(options, function(error, response, body) { | 53 | request(options, function(error, response, body) { |
54 | if (error) { | 54 | if (error) { |
55 | logger.warn('Error requesting to partner', {error: error}); | 55 | logger.warn('Error requesting to partner', {error: error}); |
56 | callbackReport(task.requestId, '68', 'Error requesting to partner. ' + error); | 56 | callbackReport(task.requestId, '68', 'Error requesting to partner. ' + error); |
57 | return; | 57 | return; |
58 | } | 58 | } |
59 | 59 | ||
60 | if (response.statusCode != 200) { | 60 | if (response.statusCode != 200) { |
61 | var message = 'Partner response with http status code other that 200 (' + response.statusCode +')'; | 61 | var message = 'Partner response with http status code other that 200 (' + response.statusCode +')'; |
62 | 62 | ||
63 | logger.warn(message); | 63 | logger.warn(message); |
64 | callbackReport(task.requestId, '68', message); | 64 | callbackReport(task.requestId, '68', message); |
65 | return; | 65 | return; |
66 | } | 66 | } |
67 | 67 | ||
68 | logger.verbose('Got response', {requestId: task.requestId, responseBody: body}); | 68 | logger.verbose('Got response', {requestId: task.requestId, responseBody: body}); |
69 | callbackReport(task.requestId, '68', body); | 69 | callbackReport(task.requestId, '68', body); |
70 | }); | 70 | }); |
71 | } | 71 | } |
72 | 72 | ||
73 | function prepareRemoteProductCode(remoteProduct) { | 73 | function prepareRemoteProductCode(remoteProduct) { |
74 | var product = remoteProduct.split(','); | 74 | var product = remoteProduct.split(','); |
75 | 75 | ||
76 | if (product.length != 3) { | 76 | if (product.length != 3) { |
77 | return; | 77 | return; |
78 | } | 78 | } |
79 | 79 | ||
80 | return { | 80 | return { |
81 | product: product[0], | 81 | product: product[0], |
82 | productDetail: product[1], | 82 | productDetail: product[1], |
83 | nominal: product[2] | 83 | nominal: product[2] |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | exports.start = start; | 87 | exports.start = start; |
88 | exports.topupRequest = topupRequest; | 88 | exports.topupRequest = topupRequest; |
89 | exports.prepareRemoteProductCode = prepareRemoteProductCode; | 89 | exports.prepareRemoteProductCode = prepareRemoteProductCode; |
90 | 90 |