forked from kigu502yaju-post-wordpress-com/docs-examples-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (28 loc) · 863 Bytes
/
server.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
import "dotenv/config"; // loads variables from .env file
import express from "express";
import * as paypal from "./paypal-api.js";
const {PORT = 8888} = process.env;
const app = express();
app.use(express.static("public"));
// parse post params sent in body in json format
app.use(express.json());
app.post("/my-server/create-paypal-order", async (req, res) => {
try {
const order = await paypal.createOrder();
res.json(order);
} catch (err) {
res.status(500).send(err.message);
}
});
app.post("/my-server/capture-paypal-order", async (req, res) => {
const { orderID } = req.body;
try {
const captureData = await paypal.capturePayment(orderID);
res.json(captureData);
} catch (err) {
res.status(500).send(err.message);
}
});
app.listen(PORT, () => {
console.log(`Server listening at http://localhost:${PORT}/`);
});