-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (35 loc) · 932 Bytes
/
index.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
const express = require("express");
const cors = require("cors");
const dotenv = require("dotenv");
// const { Message } = require("firebase-functions/v1/pubsub");
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: "sucess !",
})
});
app.post("/payment/create", async(req, res)=>{
const total = parseInt(req.query.total);
if(total>0){
const paymentIntent = await stripe.paymentIntents.create({
amount:total,
currency: "usd"
})
console.log(paymentIntent)
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("Amzon server running on port: 5000, http://localhost:5000")
})