@togtokh.dev/monpay
Version:
monpay is a library for payment gateway.
156 lines (155 loc) • 5.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = require("axios");
const _1 = require(".");
const CREATE_DEEP_LINK = async (body) => {
var _a, _b, _c;
try {
const res = await axios_1.default.post(`${_1.default.host}/v2/api/oauth/invoice`, JSON.stringify({
amount: body.amount,
redirectUri: body.redirectUri,
clientServiceUrl: body.callback,
receiver: body.branch,
invoiceType: "P2B",
description: body.description,
}), {
headers: {
Authorization: `Bearer ${_1.default.token}`,
"Content-Type": "application/json",
},
});
if (res.data.code == "OK") {
return {
success: true,
message: "success",
data: res.data.result,
};
}
else {
return {
success: false,
message: res.data.info || "",
};
}
}
catch (error) {
console.log("FAILED", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data);
return {
success: false,
message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "error",
};
}
};
const CREATE_QR_CODE = async (body) => {
var _a, _b, _c;
try {
const res = await axios_1.default.post(`${_1.default.host}/rest/branch/qrpurchase/generate`, JSON.stringify({
amount: body.amount,
generateUuid: true,
displayName: body.displayName,
callbackUrl: body.callback,
}), {
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${Buffer.from(_1.default.config.username + ":" + _1.default.config.id).toString("base64")}`,
},
});
if (res.data.code == 0) {
return {
success: true,
message: "success",
data: res.data.result,
};
}
else {
return {
success: false,
message: res.data.info || "",
};
}
}
catch (error) {
console.log("FAILED", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data);
return {
success: false,
message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "error",
};
}
};
const CHECKER_QR_CODE = async (uuid) => {
var _a, _b, _c;
try {
const res = await axios_1.default.get(`${_1.default.host}/rest/branch/qrpurchase/check?uuid=${uuid}`, {
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${Buffer.from(_1.default.config.username + ":" + _1.default.config.password).toString("base64")}`,
},
});
if (res.data.code == 0) {
return {
success: true,
message: "success",
data: res.data.result,
};
}
else {
return {
success: false,
message: res.data.info || "",
};
}
}
catch (error) {
console.log("FAILED", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data);
return {
success: false,
message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "error",
};
}
};
const CHECKER_DEEP_LINK = async (id) => {
var _a, _b, _c;
try {
const res = await axios_1.default.get(`${_1.default.host}/v2/api/oauth/invoice/${id}`, {
headers: {
Authorization: `Bearer ${_1.default.token}`,
"Content-Type": "application/json",
},
});
if (res.data.code == "OK") {
if (res.data.result.status == "PAID") {
return Promise.resolve({
success: true,
data: res.data.result,
message: res.data.result.statusInfo,
});
}
else {
return Promise.resolve({
success: false,
data: null,
// data: null || response.result,
message: "Төлбөр төлөлт хийгдээгүй байна",
});
}
}
else {
return Promise.resolve({
success: false,
data: null,
message: res.data.info,
});
}
}
catch (error) {
console.log("FAILED", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data);
return {
success: false,
message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "error",
};
}
};
exports.default = {
CREATE: { QR: CREATE_QR_CODE, DEEP_LINK: CREATE_DEEP_LINK },
CHECKER: { QR: CHECKER_QR_CODE, DEEP_LINK: CHECKER_DEEP_LINK },
};