added refund and sms feature

This commit is contained in:
swtmply
2023-03-17 01:05:51 +08:00
parent cf017fb80b
commit fa05d0b401
10 changed files with 231 additions and 71 deletions

View File

@@ -11,9 +11,7 @@ require("dotenv").config({
),
});
const url = process.env.NODE_ENV
? "https://secure.cpteller.com/api/custapi.cfc?method=autoterminal"
: "https://test.cpteller.com/api/custapi.cfc?method=autoterminal";
const domain = process.env.NODE_ENV ? "secure" : "test";
const getShopCredentials = () => {
// add parametes for the request
@@ -44,7 +42,58 @@ exports.lightbox_credentials = async (req, res) => {
? process.env.NODE_ENV
: "businessattended",
}),
url,
url: `https://${domain}.cpteller.com/api/custapi.cfc?method=autoterminal`,
};
const response = await axios(options);
res.send(response.data);
} catch (error) {
console.log(error);
res.json({ error });
}
};
exports.payment_refund = async (req, res) => {
const shopCredentials = getShopCredentials();
try {
const options = {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
data: qs.stringify({
method: "payment_refund",
...shopCredentials,
paymentid: req.body.paymentid,
amount: req.body.amount,
}),
url: `https://${domain}.cpteller.com/api/26/webapi.cfc?method=payment_refund`,
};
const response = await axios(options);
res.send(response.data);
} catch (error) {
console.log(error);
res.json({ error });
}
};
exports.generate_payment_url = async (req, res) => {
const shopCredentials = getShopCredentials();
try {
const options = {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
//TODO: Move these to environment variables/database.
data: qs.stringify({
...shopCredentials,
...req.body,
createshorturl: true,
}),
url: `https://${domain}.cpteller.com/api/custapi.cfc?method=generate_lightbox_url`,
};
const response = await axios(options);