-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (43 loc) · 1.25 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept, Authorization'
);
res.setHeader(
'Access-Control-Allow-Methods',
'GET, POST, PATCH, PUT, DELETE, OPTIONS'
);
next();
});
app.use(bodyParser.json());
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
app.post("/createPayment", (req, res) => {
console.log('i\'m trying to create a paymentIntent');
(async () => {
paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
currency: 'eur',
payment_method_types: ['card'],
}).then(paymentIntentResponse => {
console.log("paymentIntent created");
res.send(paymentIntentResponse)
});
})();
});
app.post("/confirmPayment", (req, res) => {
console.log(req.body);
(async () => {
paymentIntent = await stripe.paymentIntents.confirm(req.body.id, { payment_method: 'pm_card_visa' })
.then(paymentIntentResponse => {
console.log("paymentIntent confirmed");
res.send(paymentIntentResponse)
});
})();
});
app.listen(process.env.PORT || 8080, () => {
console.log('online');
});