-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstripeRoutes.js
More file actions
29 lines (26 loc) · 838 Bytes
/
stripeRoutes.js
File metadata and controls
29 lines (26 loc) · 838 Bytes
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 stripe = require("stripe")(process.env.STRIPE_SECRET_KEY || require('./conf.js').STRIPE_SECRET_KEY);
const stripeChargeCallback = res => (stripeErr, stripeRes) => {
if (stripeErr) {
res.status(500).send({ error: stripeErr });
} else {
res.status(200).send({ success: stripeRes });
}
};
const paymentApi = app => {
app.get("/api/payment", (req, res) => {
res.send({
message: "Hello Stripe checkout server!",
timestamp: new Date().toISOString()
});
});
app.post("/api/payment", (req, res) => {
const body = {
source: req.body.token.id,
amount: req.body.amount,
currency: "usd"
};
stripe.charges.create(body, stripeChargeCallback(res));
});
return app;
};
module.exports = paymentApi;