-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
62 lines (45 loc) · 1.42 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const express=require('express');
const bodyParser=require('body-parser');
const path=require('path');
const app=express();
const PUBLISHABLE_KEY="pk_test_51LyX6LSBN8d4cdyd9yWCVJIDoO7ASp7ScwMAQNhjScOs0vm5FRHs4O45KMXQ1FfjCtZnpyhtK78fAfBJsughvq5J00SNSIx9EI"
const SECRET_KEY="sk_test_51LyX6LSBN8d4cdydk1hfD6FCsvQxcKRmPwCtb8SDQTDT36vMU68ful2yEo5JN9J3h4stE8SwLTCr1umMfMEtuiUh00Fh0C0Xmo"
const stripe=require("stripe")(SECRET_KEY);
const PORT=process.env.PORT||3000;
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json())
app.set('view engine',"ejs");
app.get('/',(req,res)=>{
res.render('Home',{
key:PUBLISHABLE_KEY
})
});
app.post('/payment',(req,res)=>{
stripe.customers.create({
email:req.body.stripeEmail,
source:req.body.stripeToken,
name:'Ayush Anand',
address:{
line1:'btm layout bangalore',
postal_code:'560076',
city:'Bangalore',
state:'Karnataka',
country:'India'
}
}).then((customer)=>{
return stripe.charges.create({
amount:10000,
description:'testing developments',
currency:'USD',
customer:customer.id
})
}).then((charge)=>{
console.log(charge)
res.send("success")
}).catch((error)=>{
res.send(error)
})
})
app.listen(PORT,()=>{
console.log(`port is up and running on ${PORT}`);
})