working on new tables for payments
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user