-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.js
37 lines (35 loc) · 945 Bytes
/
routes.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
const express = require('express');
const router = express.Router();
const stripe = require('stripe')('sk_test_qqZDHIAgBZFr8pIlFLFQAOna');
const knex = require('./knex')
router.post('/api', (req, res, next) => {
var token = req.body.id;
var body = req.body;
knex('donations')
.insert({
card_token: body.id,
amount: body.amount
})
.returning('*')
.then((donation) => {
console.log('logging inside knex:', donation, body)
knex('donors')
.insert({
firstName: req.body.firstName,
lastName: req.body.lastName,
email: req.body.email,
donation_id: donation[0].id
})
.then(() => res.send('Donation Posted'));
});
var charge = stripe.charges.create({
amount: req.body.amount * 100,
currency: "usd",
description: "Example charge",
receipt_email: req.body.email,
source: token,
}, function(err, charge) {
res.send(charge);
});
});
module.exports = router;