Commit 93ea90c3e74bcad946be24858cc194a50a136809

Authored by Adhidarma Hadiwinoto
1 parent af040c0dd0
Exists in master and in 1 other branch dev

CALLBACK-SENDER: data for postpaid trx

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

lib/core-callback/sender.js
1   -const MODULE_NAME = 'CORE-CALLBACK-SENDER';
2   -const MAX_RETRY = 10;
3   -const SLEEP_BEFORE_RETRY_MS = 60 * 1000;
  1 +const MODULE_NAME = 'CORE-CALLBACK.SENDER';
4 2  
5 3 const axios = require('axios').default;
  4 +const config = require('komodo-sdk/config');
6 5 const logger = require('komodo-sdk/logger');
7 6  
  7 +const HTTP_TIMEOUT = Number(
  8 + config.callback_sender && config.callback_sender.http_timeout_ms,
  9 +) || 30 * 1000;
  10 +
  11 +const SLEEP_BEFORE_RETRY_MS = Number(
  12 + config.callback_sender && config.callback_sender.sleep_before_retry_ms,
  13 +) || 10 * 1000;
  14 +
  15 +const MAX_RETRY = Number(
  16 + config.callback_sender && config.callback_sender.max_retry,
  17 +) || 10;
  18 +
  19 +logger.verbose(`${MODULE_NAME} 848B9104: Initialized`, {
  20 + HTTP_TIMEOUT,
  21 + SLEEP_BEFORE_RETRY_MS,
  22 + MAX_RETRY,
  23 +});
  24 +
8 25 const sleep = require('../sleep');
9 26 const urlConcatQs = require('../url-concat-qs');
10 27  
11 28 const sender = async (data, xid, retry) => {
12   - if (!data.reverse_url) return;
  29 + if (!data.reverse_url) {
  30 + logger.verbose(`${MODULE_NAME} C4FF18FB: Ignoring missing reverse url`, {
  31 + xid,
  32 + dataFromCore: data,
  33 + });
  34 +
  35 + return;
  36 + }
13 37  
14 38 const params = {
15 39 httpgetx_xid: xid,
... ... @@ -21,33 +45,47 @@ const sender = async (data, xid, retry) => {
21 45 terminal_name: data.terminal_name,
22 46 product_name: data.product_name,
23 47 destination: data.destination,
  48 +
24 49 rc: data.rc,
25 50 sn: data.sn || undefined,
26 51 amount: Number(data.amount) || undefined,
27 52 ending_balance: Number(data.ending_balance) || undefined,
  53 +
28 54 message: data.message,
  55 +
  56 + bill_count: Number(data.bill_count) || undefined,
  57 + bill_amount: Number(data.bill_amount) || undefined,
  58 + fee_per_bill: Number(data.fee) || undefined,
  59 + fee_total: Number(data.fee_total) || undefined,
  60 +
  61 + bill_detail: data.bill_detail || undefined,
29 62 };
30 63  
31   - if (data.command === 'INQUIRY' && Number(data.amount_to_charge)) {
32   - params.amount_to_charge = Number(data.amount_to_charge);
  64 + if (data.command === 'INQUIRY' && data.amount_to_charge) {
  65 + params.amount_to_charge = data.amount_to_charge;
33 66 }
34 67  
35 68 const fullUrl = urlConcatQs(data.reverse_url, params);
36   - logger.info(`${MODULE_NAME} 8B6A4CEC: Sending CORE-CALLBACK to PARTNER`, {
37   - xid, retry, params, fullUrl,
  69 + logger.info(`${MODULE_NAME} 8B6A4CEC: Sending to PARTNER`, {
  70 + xid,
  71 + retry,
  72 + fullUrl,
38 73 });
39 74  
40 75 try {
41   - const result = await axios.get(data.reverse_url, {
  76 + const response = await axios.get(data.reverse_url, {
42 77 params,
43   - timeout: 60 * 1000,
  78 + timeout: HTTP_TIMEOUT,
44 79 });
45 80  
46   - logger.info(`${MODULE_NAME} 3641FBD7: CORE-CALLBACK has been sent to PARTNER successfully`, {
47   - xid, retry, fullUrl, body: result && result.data,
  81 + logger.info(`${MODULE_NAME} 3641FBD7: Has been sent to PARTNER successfully`, {
  82 + xid,
  83 + retry,
  84 + httpStatus: response.status,
  85 + responseBody: response && response.data,
48 86 });
49 87 } catch (e) {
50   - logger.warn(`${MODULE_NAME} A1EC9E70: Failed on sending CORE-CALLBACK to PARTNER`, {
  88 + logger.warn(`${MODULE_NAME} A1EC9E70: Failed on sending to PARTNER`, {
51 89 xid,
52 90 retry,
53 91 maxRetry: MAX_RETRY,
... ... @@ -56,7 +94,7 @@ const sender = async (data, xid, retry) => {
56 94 reverseUrl: data.reverse_url,
57 95 fullUrl,
58 96 httpStatus: e.response && e.response.status,
59   - body: e.response && e.response.data,
  97 + responseBody: e.response && e.response.data,
60 98 });
61 99  
62 100 if ((retry || 0) < MAX_RETRY) {