working on stripe controller

This commit is contained in:
Arjun Patel
2019-01-29 15:53:49 -08:00
parent e3b7a1699e
commit ad26f7b6fd
+22
View File
@@ -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));
});
};