-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseMethod.js
72 lines (64 loc) · 2.44 KB
/
BaseMethod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const getEnvironment = require('./EnvironmentConfig');
const error = require('./ErrorHandler');
const fetch = require('node-fetch');
let response;
async function baseGetMethod(credential, payload, url, getBillingEnv) {
var getTimeOut = getEnvironment.getTimeOut(credential);
try {
response = await fetch(url, {
method: 'get',
timeout: getTimeOut.get('READ_TIMEOUT'),
connectionTimeout: getTimeOut.get('CONNECTION_TIMEOUT'),
headers: {
transactionId: payload.requestId,
publicKey: getBillingEnv.get('PUBLIC_KEY'),
'Content-Type': 'application/json', },
})
.then(res => res.json());
}catch (err) {
response = error.handleError(err);
}
return response;
}
async function basePostMethod(credential, payload, url, getBillingEnv) {
var getTimeOut = getEnvironment.getTimeOut(credential);
try {
response = await fetch(url, {
method: 'post',
timeout: getTimeOut.get('READ_TIMEOUT'),
connectionTimeout: getTimeOut.get('CONNECTION_TIMEOUT'),
body: JSON.stringify(payload),
headers: {
transactionId: payload.requestId,
publicKey: getBillingEnv.get('PUBLIC_KEY'),
'Content-Type': 'application/json', },
})
.then(res => res.json());
} catch (err) {
response = error.handleError(err);
}
return response
}
async function basePostMethodWithHash(credential, url, payload, getBillingEnv, hash) {
var getTimeOut = getEnvironment.getTimeOut(credential);
try {
response = await fetch(url, {
method: 'post',
timeout: getTimeOut.get('READ_TIMEOUT'),
connectionTimeout: getTimeOut.get('CONNECTION_TIMEOUT'),
body: JSON.stringify(payload),
headers: {
transactionId: payload.requestId,
publicKey: getBillingEnv.get('PUBLIC_KEY'),
'TXN_HASH': hash,
'Content-Type': 'application/json', },
})
.then(res => res.json());
} catch (err) {
response = error.handleError(err);
}
return response
}
module.exports.baseGetMethod = baseGetMethod;
module.exports.basePostMethod = basePostMethod;
module.exports.basePostMethodWithHash = basePostMethodWithHash;