From ad26f7b6fd20faa27a80043fcbe985729d9089a4 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Tue, 29 Jan 2019 15:53:49 -0800 Subject: [PATCH] working on stripe controller --- app/controllers/stripe.controller.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/controllers/stripe.controller.js b/app/controllers/stripe.controller.js index 60273ef..2eee659 100644 --- a/app/controllers/stripe.controller.js +++ b/app/controllers/stripe.controller.js @@ -9,7 +9,15 @@ const { Donor, Organization } = db; exports.grantCharge = async (req, res, next) => { const { stripeToken, amount, monthly } = req.body; console.log(req.body); + const user = req.user; + findStripeId(user.id) + .then(stripeId => { + if (!stripeId) { + stripe.customers.create({}); + } + }) + .catch(error => next(error)); // if (!monthly) { // const charge = stripe.charges.create({ // amount, @@ -20,3 +28,17 @@ exports.grantCharge = async (req, res, next) => { // }); // } }; + +const findStripeId = userId => { + return new Promise((resolve, reject) => { + Donor.findAll({ where: { id: userId } }) + .then(donors => { + // add stripe id for + // if (donors[0]) { + // return next(errorMaker(409, `Email Exists: ${req.body.email}`)); + // } + resolve(donors[0].stripe_id); + }) + .catch(error => reject(error)); + }); +};