From 9e5ff94708752350082eaa68139aba98915147c3 Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <me@adhisimon.org> Date: Mon, 15 Jul 2024 18:11:57 +0700 Subject: [PATCH] Experimental POST-JSON --- lib/hit/dump-req-res.js | 6 +++++- lib/hit/prepaid-topup.js | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/hit/dump-req-res.js b/lib/hit/dump-req-res.js index 5f149c8..bed4c22 100644 --- a/lib/hit/dump-req-res.js +++ b/lib/hit/dump-req-res.js @@ -53,7 +53,11 @@ ${ ) } -${httpMethod === 'GET' ? `FULL URL: ${endpointUrl}?${querystring.stringify(params)}` : `FORM DATA: ${new URLSearchParams(params).toString()}`} +${ + (httpMethod === 'GET' && `FULL URL: ${endpointUrl}?${querystring.stringify(params)}`) + || (httpMethod === 'POST' && `FORM DATA: ${new URLSearchParams(params).toString()}`) + || '' +} RESPONSE-STATUS: ${responseStatus} RESPONSE-BODY: diff --git a/lib/hit/prepaid-topup.js b/lib/hit/prepaid-topup.js index 32d4434..17be4de 100644 --- a/lib/hit/prepaid-topup.js +++ b/lib/hit/prepaid-topup.js @@ -59,20 +59,30 @@ module.exports = async (xid, task) => { }, }); - const response = config.partner.method === 'POST' - ? await axios.post(endpointUrl, new URLSearchParams(params), { + let response; + if (config.partner.method === 'POST') { + response = await axios.post(endpointUrl, new URLSearchParams(params), { headers: { 'User-Agent': 'KOMODO-GW-HTTPGETX', }, timeout: config.partner.hit_timeout_ms || 60 * 1000, - }) - : await axios.get(endpointUrl, { + }); + } else if (config.partner.method === 'POST-JSON') { + response = await axios.post(endpointUrl, params, { + headers: { + 'User-Agent': 'KOMODO-GW-HTTPGETX', + }, + timeout: config.partner.hit_timeout_ms || 60 * 1000, + }); + } else { + response = await axios.get(endpointUrl, { headers: { 'User-Agent': 'KOMODO-GW-HTTPGETX', }, timeout: config.partner.hit_timeout_ms || 60 * 1000, params, }); + } if (!response) { const e = new Error(`${MODULE_NAME} 8CF4E04D: Empty response`); -- 1.9.0