-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (34 loc) · 957 Bytes
/
app.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
const express = require("express");
const stripe = require("stripe")("sk_test_vAL5prlCfC16QTrEGIAeEtp9");
const bodyParser = require("body-parser");
const app = express();
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.post("/charge", (req, res) => {
let amount = 39900;
stripe.customers.create({
email: req.body.email,
card: req.body.id
})
// stripe.orders.create({
// email: req.body.email,
// items: [
// type: 'sku',
// parent: ''
// ]
// })
.then(customer =>
stripe.charges.create({
amount,
description: "Sample Charge",
currency: "usd",
customer: customer.id
}))
.then(charge => res.send(charge))
.catch(err => {
console.log("Error:", err);
res.status(500).send({error: "Purchase Failed"});
});
});
app.listen(8100);