Commit 249d4d6a28829d6942e5de7e88d7a85d22b91ee8

Authored by Adhidarma Hadiwinoto
1 parent 6b1de0867f
Exists in master

Experimental POST on prepaid

Showing 2 changed files with 20 additions and 9 deletions Side-by-side Diff

... ... @@ -6,6 +6,7 @@
6 6 "terminal_name": "PLEASE_CHANGE_ME",
7 7 "password": "PLEASE_CHANGE_ME",
8 8 "dump_request": true,
  9 + "method": "GET",
9 10 "callback": {
10 11 "port": 14000,
11 12 "url": "http://PLEASE_CHANGE_ME:14000",
lib/hit/prepaid-topup.js
... ... @@ -43,7 +43,9 @@ module.exports = async (xid, task) => {
43 43 xid,
44 44 endpointUrl,
45 45 params,
46   - fullEndpointUrl,
  46 + fullEndpointUrl: (!config.partner.method || config.partner.method === 'GET')
  47 + ? fullEndpointUrl
  48 + : endpointUrl,
47 49 });
48 50  
49 51 report(xid, {
... ... @@ -52,17 +54,25 @@ module.exports = async (xid, task) => {
52 54 message: {
53 55 xid,
54 56 msg: 'Sending request to partner',
  57 + method: config.partner.method || 'GET',
55 58 endpointUrl,
56 59 },
57 60 });
58 61  
59   - const response = await axios.get(endpointUrl, {
60   - headers: {
61   - 'User-Agent': 'KOMODO-GW-HTTPGETX',
62   - },
63   - timeout: config.partner.hit_timeout_ms || 60 * 1000,
64   - params,
65   - });
  62 + const response = config.partner.method === 'POST'
  63 + ? await axios.post(endpointUrl, new URLSearchParams(params), {
  64 + headers: {
  65 + 'User-Agent': 'KOMODO-GW-HTTPGETX',
  66 + },
  67 + timeout: config.partner.hit_timeout_ms || 60 * 1000,
  68 + })
  69 + : await axios.get(endpointUrl, {
  70 + headers: {
  71 + 'User-Agent': 'KOMODO-GW-HTTPGETX',
  72 + },
  73 + timeout: config.partner.hit_timeout_ms || 60 * 1000,
  74 + params,
  75 + });
66 76  
67 77 if (!response) {
68 78 const e = new Error(`${MODULE_NAME} 8CF4E04D: Empty response`);
... ... @@ -138,7 +148,7 @@ module.exports = async (xid, task) => {
138 148 dumpReqRes(
139 149 xid,
140 150 task,
141   - 'GET',
  151 + config.partner.method || 'GET',
142 152 endpointUrl,
143 153 params,
144 154 lastResponse && lastResponse.data,