-
Notifications
You must be signed in to change notification settings - Fork 0
/
paymentService.js
51 lines (44 loc) · 1.33 KB
/
paymentService.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
const dotenv = require("dotenv");
const payOS = require("./utils/payos");
dotenv.config();
const YOUR_DOMAIN = process.env.SERVER_URL || "http://localhost:3000";
const createPaymentLink = async (body) => {
body.returnUrl = `${YOUR_DOMAIN}/success.html`;
body.cancelUrl = `${YOUR_DOMAIN}/cancel.html`;
console.log("Creating payment link with body:", body);
try {
const paymentLinkResponse = await payOS.createPaymentLink(body);
return paymentLinkResponse.checkoutUrl;
} catch (error) {
console.error("Error creating payment link:", error);
throw new Error("Something went wrong while creating payment link");
}
};
const getPaymentLinkInformation = async (orderCode) => {
try {
const order = await payOS.getPaymentLinkInformation(orderCode);
if (!order) {
return {
error: -1,
message: "failed",
data: null,
};
}
return {
error: 0,
message: "ok",
data: order,
};
} catch (error) {
console.error("Error getting payment link information:", error);
return {
error: -1,
message: "failed",
data: null,
};
}
};
module.exports = {
createPaymentLink,
getPaymentLinkInformation,
};