-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (24 loc) · 868 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
30
const express = require('express');
const bodyParser = require('body-parser');
const Stripe = require('stripe');
const app = express();
const stripe = Stripe('YOUR_SECRET_KEY'); // Replace with your Stripe secret key
app.use(bodyParser.json());
app.post('/pay', async (req, res) => {
const { paymentMethodId } = req.body;
try {
// Create a PaymentIntent
const paymentIntent = await stripe.paymentIntents.create({
amount: 1000, // Replace with actual amount in cents
currency: 'usd',
payment_method: paymentMethodId,
confirm: true,
});
res.send({ success: true });
} catch (error) {
console.error(error);
res.send({ success: false });
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));