Skip to content

Commit

Permalink
Add donationAmount and emailAddress to charge route
Browse files Browse the repository at this point in the history
Relates #25 #68 #85
  • Loading branch information
joeylouise committed May 11, 2017
1 parent 662806b commit a9d43fb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/routes/charge.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ module.exports = {
method: 'POST',
path: '/charge',
handler: (req, reply) => {
console.log('>>>>>>>>>>>>>>>>>>', req.payload);
// we get a req.payload which has a token
const stripeToken = req.payload.stripeToken;
const userCredentials = req.auth.credentials;
const emailAddress = req.payload.email;
const donationAmount = req.auth.credentials.data.amount;

doesCustomerExistInDB(userCredentials, (err, result) => {
if (err) {
console.log(err);
reply('Broken');
} else if (result === false) {
// create customer id and charge user
createNewCustomer(stripeToken, (err, result) => {
createNewCustomer(emailAddress, stripeToken, (err, result) => {
const stripe_id = result;
if (err) {
console.log(err);
Expand All @@ -28,7 +29,7 @@ module.exports = {
if (err) {
reply('unable to save stripe id to db');
} else {
chargeRepeatCustomer(stripe_id, (err, result) => {
chargeRepeatCustomer(donationAmount, stripe_id, (err, result) => {
if (err) {
console.log(err);
reply('unable to charge user');
Expand All @@ -42,11 +43,11 @@ module.exports = {
});
} else {
const stripe_id = result.stripe_id;
chargeRepeatCustomer(stripe_id, (err, result) => {
chargeRepeatCustomer(donationAmount, stripe_id, (err, result) => {
if (err) {
reply('error, charge not gone through, they dont have any money.')
} else {
console.log(result);
// console.log(result);
reply('success!!!!')
}
});
Expand Down

0 comments on commit a9d43fb

Please sign in to comment.