working on new tables for payments

This commit is contained in:
Arjun Patel
2019-01-29 19:55:32 -08:00
parent ad26f7b6fd
commit d6643c32f9
8 changed files with 154 additions and 13 deletions
+32 -3
View File
@@ -6,16 +6,45 @@ const stripe = require('stripe')('sk_test_n8NCvCFjD1xFhGiEq6SI8CXj');
const { Donor, Organization } = db;
// Subscribe user to plan or one time charge
exports.grantCharge = async (req, res, next) => {
exports.grantCharge = (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({});
return stripe.customers
.create({
source: stripeToken,
email: user.email
})
.then(customer => {
Donor.update(
{ stripe_id: customer.id },
{ where: { id: user.id } }
);
return customer.id;
});
}
return stripeId;
})
.then(stripeId => {
// return stripe.charges.create({
// amount,
// currency: 'usd',
// customer: stripeId
// });s
stripe.plans
.create({
product: 'prod_CbvTFuXWh7BPJH',
currency: 'usd',
interval: 'month',
amount: 10000
})
.then();
})
.then(chargeResponse => {
res.status(200).json(chargeResponse);
})
.catch(error => next(error));
// if (!monthly) {