Commit f23920e222feb6c11b9485a7766b98bdfca8c648

Authored by Adhidarma Hadiwinoto
1 parent f10cd202f2
Exists in master

insert dan push response

Showing 1 changed file with 38 additions and 1 deletions Side-by-side Diff

... ... @@ -32,7 +32,6 @@ function calculateBalanceSignature(userid, password, timestamp) {
32 32 return xor.encode(a,b);
33 33 }
34 34  
35   -
36 35 function createPayload(task) {
37 36 var timestamp = strftime('%H%M%S');
38 37  
... ... @@ -55,6 +54,8 @@ function createPayload(task) {
55 54 function topupRequest(task, retry) {
56 55 //balanceCheck();
57 56  
  57 + aaa.insertTaskToMongoDb(task);
  58 +
58 59 var payload_xml = createPayload(task);
59 60 //console.log(payload_xml);
60 61  
... ... @@ -86,6 +87,15 @@ function topupRequest(task, retry) {
86 87  
87 88 req.on('error', function(e) {
88 89 logger.warn('problem with request: ' + e.message);
  90 +
  91 + var response = {
  92 + raw: e.message,
  93 + parsed: {
  94 + MESSAGE: e.message,
  95 + }
  96 + }
  97 +
  98 + aaa.pushResponseToMongoDb(task, response, '40');
89 99 callbackReport(task['requestId'], '40', e.message);
90 100 });
91 101  
... ... @@ -99,6 +109,14 @@ function topupResponseHandler(body, request_id) {
99 109 if (!body) {
100 110 logger.info('Partner send empty response', {request_id: request_id});
101 111 if (request_id) {
  112 +
  113 + var response = {
  114 + raw: '',
  115 + parsed: {
  116 + MESSAGE: 'Got empty response from partner';
  117 + }
  118 + }
  119 + aaa.pushResponseToMongoDb(request_id, response, '68');
102 120 callbackReport(request_id, '68', 'partner send empty response');
103 121 }
104 122 return;
... ... @@ -107,6 +125,15 @@ function topupResponseHandler(body, request_id) {
107 125 xml2js(body, function (err, result) {
108 126 if (err) {
109 127 logger.warn('topupResponseHandler', {body: body});
  128 +
  129 + var response = {
  130 + raw: body,
  131 + parsed: {
  132 + MESSAGE: 'Error parsing partner message: ' + err;
  133 + }
  134 + }
  135 +
  136 + aaa.pushResponseToMongoDb(request_id, response, '40');
110 137 callbackReport(request_id, '40', buffer);
111 138 return;
112 139 }
... ... @@ -201,6 +228,16 @@ function topupResponseHandler(body, request_id) {
201 228  
202 229 if (response_code != '68') {
203 230 callbackReport(request_id, response_code, message);
  231 +
  232 + var response = {
  233 + raw: body,
  234 + parsed: {
  235 + MESSAGE: message,
  236 + }
  237 + }
  238 +
  239 + aaa.pushResponseToMongoDb(request_id, response, response_code);
  240 +
204 241 }
205 242 });
206 243 }