Commit 9c5411fccdbdd70605ead96fff021f6540714f2b

Authored by Adhidarma Hadiwinoto
1 parent aef705f99f
Exists in master

reportUsingHttpPost

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

... ... @@ -70,8 +70,37 @@ function forwardCoreTaskToPartner(coreMessage) {
70 70 partner.buy(task);
71 71 }
72 72  
73   -//function report(trx_id, rc, message, sn) {
74 73 function report(data) {
  74 + reportUsingHttpPost(data);
  75 +}
  76 +
  77 +function reportUsingHttpPost(data) {
  78 + let options = {
  79 + url: config.pull_url.report.replace('<CORE_APIKEY>', config.core_apikey),
  80 + form: {
  81 + trx_id: data.trx_id,
  82 + rc: data.rc,
  83 + message: data.message,
  84 + handler: config.handler_name,
  85 + sn: data.sn,
  86 + amount: data.amount
  87 + }
  88 + }
  89 +
  90 + request.post(options, function(error, response, body) {
  91 + if (error) {
  92 + logger.warn('Error reporting to CORE', {error: error});
  93 + }
  94 + else if (response.statusCode != 200) {
  95 + logger.warn('CORE http response status is not 200', {requestOptions: options, http_response_status: response.statusCode});
  96 + }
  97 + else {
  98 + logger.verbose('Report has been sent to CORE', {requestOptions: options});
  99 + }
  100 + });
  101 +}
  102 +
  103 +function reportUsingHttpGet(data) {
75 104 let options = {
76 105 url: config.pull_url.report.replace('<CORE_APIKEY>', config.core_apikey),
77 106 qs: {