-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (34 loc) · 966 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
const express = require('express');
const bodyParser = require('body-parser');
const stripe = require('stripe')('sk_test_xx'); // Replace with your test secret key
const path = require('path');
const app = express();
const port = 3000;
app.use(express.static('public'))
app.use(bodyParser.json());
app.get('/', (req,res) => {
res.sendFile(path.join(__dirname, 'public/index.html'))
})
app.post('/create-payment-intent', async (req, res) => {
const { amount, currency } = req.body;
try {
const paymentIntent = await stripe.paymentIntents.create({
amount,
currency,
automatic_payment_methods: {
enabled: true,
},
});
res.send({
clientSecret: paymentIntent.client_secret,
paymentIntentId: paymentIntent.id,
});
} catch (error) {
res.status(500).send({
error: error.message,
});
}
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});