buy-to-sds.js
1.52 KB
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
const MODULE_NAME = 'ACTIONS.BUY-TO-SDS';
const logger = require('tektrans-logger');
const axios = require('axios').default;
const config = require('../config');
const client = axios.create({
baseURL: config.sds.url,
timeout: config.sds.request_timeout_ms,
});
/**
* request buy to sds
*
* @param {string} xid
* @param {string} requestId
* @param {string} destination
* @param {string} productName
* @param {number} quantity
*/
module.exports = async (
xid,
requestId,
destination,
productName,
quantity,
) => {
logger.verbose(`${MODULE_NAME} 4AD4DF41: buy to sds`, {
requestId, destination, productName, quantity, xid,
});
const params = {
trxid: requestId,
username: config.sds.username,
password: config.sds.password,
number: destination,
product: productName,
amount: quantity,
payment: config.sds.payment,
};
try {
const response = await client.get('/request', {
params,
});
if (!response) {
throw new Error(`${MODULE_NAME} 6CE3E06E: Empty response sds`);
}
if (!response.data) {
throw new Error(`${MODULE_NAME} F236476F: Empty response sds`);
}
return response.data;
} catch (err) {
logger.warn(`${MODULE_NAME} 48BAA6B7: Exception`, {
xid,
requestId,
destination,
productName,
quantity,
message: err.message,
});
throw err;
}
};