Commit 05d016dd09546d33ca52b7befb3153ed032ba152
1 parent
93ea90c3e7
Exists in
master
and in
1 other branch
CALLBACK-SENDER: using POST on postpaid callback
Showing 1 changed file with 27 additions and 7 deletions Side-by-side Diff
lib/core-callback/sender.js
... | ... | @@ -22,6 +22,11 @@ logger.verbose(`${MODULE_NAME} 848B9104: Initialized`, { |
22 | 22 | MAX_RETRY, |
23 | 23 | }); |
24 | 24 | |
25 | +const axiosHeaders = { | |
26 | + 'Content-Type': 'application/json', | |
27 | + 'User-Agent': 'KOMODO-HTTPGETX callback sender', | |
28 | +}; | |
29 | + | |
25 | 30 | const sleep = require('../sleep'); |
26 | 31 | const urlConcatQs = require('../url-concat-qs'); |
27 | 32 | |
... | ... | @@ -38,11 +43,14 @@ const sender = async (data, xid, retry) => { |
38 | 43 | const params = { |
39 | 44 | httpgetx_xid: xid, |
40 | 45 | command: data.command, |
46 | + | |
41 | 47 | request_id: data.request_id && data.request_id.toString(), |
42 | 48 | transaction_id: data.transaction_id && data.transaction_id.toString(), |
43 | 49 | transaction_date: data.transaction_date, |
50 | + | |
44 | 51 | store_name: data.store_name, |
45 | 52 | terminal_name: data.terminal_name, |
53 | + | |
46 | 54 | product_name: data.product_name, |
47 | 55 | destination: data.destination, |
48 | 56 | |
... | ... | @@ -65,18 +73,30 @@ const sender = async (data, xid, retry) => { |
65 | 73 | params.amount_to_charge = data.amount_to_charge; |
66 | 74 | } |
67 | 75 | |
68 | - const fullUrl = urlConcatQs(data.reverse_url, params); | |
76 | + const isPostpaid = ['INQUIRY', 'PAY'].indexOf(data.command) >= 0; | |
77 | + const isHttpPost = isPostpaid; | |
78 | + | |
79 | + const endpointUrl = isHttpPost ? data.reverse_url : urlConcatQs(data.reverse_url, params); | |
80 | + | |
69 | 81 | logger.info(`${MODULE_NAME} 8B6A4CEC: Sending to PARTNER`, { |
70 | 82 | xid, |
71 | 83 | retry, |
72 | - fullUrl, | |
84 | + isPostpaid, | |
85 | + isHttpPost, | |
86 | + endpointUrl, | |
73 | 87 | }); |
74 | 88 | |
75 | 89 | try { |
76 | - const response = await axios.get(data.reverse_url, { | |
77 | - params, | |
78 | - timeout: HTTP_TIMEOUT, | |
79 | - }); | |
90 | + const response = isHttpPost | |
91 | + ? await axios.post(data.reverse_url, params, { | |
92 | + timeout: HTTP_TIMEOUT, | |
93 | + headers: axiosHeaders, | |
94 | + }) | |
95 | + : await axios.get(data.reverse_url, { | |
96 | + params, | |
97 | + timeout: HTTP_TIMEOUT, | |
98 | + headers: axiosHeaders, | |
99 | + }); | |
80 | 100 | |
81 | 101 | logger.info(`${MODULE_NAME} 3641FBD7: Has been sent to PARTNER successfully`, { |
82 | 102 | xid, |
... | ... | @@ -92,7 +112,7 @@ const sender = async (data, xid, retry) => { |
92 | 112 | errCode: e.code, |
93 | 113 | errMessage: e.message, |
94 | 114 | reverseUrl: data.reverse_url, |
95 | - fullUrl, | |
115 | + endpointUrl, | |
96 | 116 | httpStatus: e.response && e.response.status, |
97 | 117 | responseBody: e.response && e.response.data, |
98 | 118 | }); |