-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
44 lines (34 loc) · 1.05 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
var express = require('express');
var app = express();
var dotenv = require('dotenv');
var bodyParser = require('body-parser');
dotenv.load(); //get cofiguration file from .env
app.use(bodyParser.json());
var stripe = require("stripe")(process.env.TEST_STRIPE_SECRET_KEY);
app.get('/', function(req,res){
res.sendFile(__dirname +'/index.html');
})
app.post('/process_payment', function(req,res){
var token_id = req.body.token_id;
var purchase_price = req.body.price;
//console.log(token.id +"\n"+purchase_price);
var charge = stripe.charges.create({
amount: purchase_price, // Amount in cents
currency: "usd",
source: token_id,
description: "Example charge"
}, function(err, charge) {
if (err && err.type === 'StripeCardError') {
// The card has been declined
res.json({"status":"failure", "reason":"card was declined"});
}
else{
console.log(charge);
res.json({"status":"success"});
}
});
})
var appPort=9002;
app.listen(appPort, function () {
console.log("Magic on port %d",appPort);
});