-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
29 lines (24 loc) · 814 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
const express = require('express');
const stripe = require('stripe')('sk_test_51MlaZ8HNqasSknnsYvvIm7MgbGNLePEHsSz5K1ptdZKqgnYgz3CUpRvWaeFjjIjw0MonD8t5o89nsnAXFI1CCgL800rzkyAu7V');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.post('/create-payment-intent', async (req, res) => {
let { amount } = req.body;
try {
const paymentIntent = await stripe.paymentIntents.create({
amount,
currency: 'usd',
});
res.send({
clientSecret: paymentIntent.client_secret,
});
} catch (error) {
res.status(400).send({
error: {
message: error.message,
},
});
}
});
app.listen(3000, () => console.log('Server is running on port 3000'));