@togtokh.dev/monpay
Version:
monpay is a library for payment gateway.
85 lines (84 loc) • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.reward = void 0;
const axios_master_1 = require("axios-master");
const _1 = require(".");
const BranchLogin = async () => {
try {
const result = await (0, axios_master_1.axiosMasterMain)({
method: "POST",
url: `${_1.default.host}/rest/branch/login`,
headers: {
"Content-Type": "application/json",
},
data: {
username: _1.default.config.username,
password: _1.default.config.password,
},
}, {
name: "login",
timeout: 20000,
shouldRetry: false,
shouldRetryStatus: [],
logger(data) {
console.log("Login Log:", data);
},
});
if (result.code === 0) {
_1.default.BranchToken = result.result.token;
return result.result.token;
}
console.error("BranchLogin Error:", result);
return "";
}
catch (error) {
const axiosError = error;
console.error("BranchLogin Error =>?:", axiosError.data);
return "";
}
};
const reward = async (data) => {
try {
const result = await (0, axios_master_1.axiosMasterMain)({
method: "POST",
url: `${_1.default.host}/rest/branch/candy/reward`,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${_1.default.BranchToken}`,
},
data: data,
}, {
name: "reward",
timeout: 20000,
shouldRetry: true,
shouldRetryStatus: [401],
retryFunction: BranchLogin,
logger(data) {
console.log("Reward Log:", data);
},
});
if (result.code === 0) {
return {
success: true,
message: "Амжилттай",
data: { id: result.result.journals[0].transactionId },
};
}
return {
success: false,
message: result.info,
};
}
catch (error) {
const axiosError = error;
return {
success: false,
message: axiosError.data || "Reward request failed",
};
}
};
exports.reward = reward;
exports.default = {
reward: exports.reward,
BranchLogin,
};