-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (36 loc) · 950 Bytes
/
index.js
File metadata and controls
43 lines (36 loc) · 950 Bytes
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
const express = require("express");
const cors = require("cors");
const dotenv = require("dotenv");
// const { messaging } = require("firebase-admin");
dotenv.config();
const stripe = require("stripe")(process.env.STRIPE_KEY);
const app = express();
app.use(cors({ origin: true }));
app.use(express.json());
app.get("/", (req, res) => {
res.status(200).json({
message: "Success!",
});
});
app.post("/payment/create", async (req, res) => {
const total = req.query.total;
if (total > 0) {
const paymentIntent = await stripe.paymentIntents.create({
amount: total,
currency: "usd",
});
res.status(201).json({
clientSecret: paymentIntent.client_secret,
});
} else {
res.status(403).json({
message: "total must be greater than 0",
});
}
});
app.listen(5000, (err) => {
if (err) {
// throw err;
}
console.log("Amazon server running on port: 5000, http://localhost:5000");
});