allowing charities to add ribbons for
This commit is contained in:
@@ -12,7 +12,9 @@ exports.getStatusUpdatesByOrg = async (req, res, next) => {
|
|||||||
const posts = await sequelize.query(
|
const posts = await sequelize.query(
|
||||||
`
|
`
|
||||||
SELECT * FROM posts
|
SELECT * FROM posts
|
||||||
WHERE organization_id = :organization_id`,
|
WHERE organization_id = :organization_id
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT 6`,
|
||||||
{
|
{
|
||||||
type: db.Sequelize.QueryTypes.SELECT,
|
type: db.Sequelize.QueryTypes.SELECT,
|
||||||
replacements: { organization_id }
|
replacements: { organization_id }
|
||||||
@@ -70,6 +72,7 @@ exports.addRibbon = async (req, res, next) => {
|
|||||||
message: 'Successfully added ribbon to post!'
|
message: 'Successfully added ribbon to post!'
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const db = require("../../models"),
|
const db = require('../../models'),
|
||||||
errorMaker = require("../helpers/error.maker"),
|
errorMaker = require('../helpers/error.maker'),
|
||||||
requestPromise = require("request-promise");
|
requestPromise = require('request-promise');
|
||||||
|
|
||||||
const stripe = require("stripe")(process.env.STRIPE_KEY);
|
const stripe = require('stripe')(process.env.STRIPE_KEY);
|
||||||
|
|
||||||
const { Donor, Organization, Charge, PaymentPlan } = db;
|
const { Donor, Organization, Charge, PaymentPlan } = db;
|
||||||
|
|
||||||
@@ -25,11 +25,11 @@ exports.grantCharge = async ({
|
|||||||
// charge if yes or no monthly
|
// charge if yes or no monthly
|
||||||
let charge = await stripe.charges.create({
|
let charge = await stripe.charges.create({
|
||||||
amount: stripeAmount,
|
amount: stripeAmount,
|
||||||
currency: "usd",
|
currency: 'usd',
|
||||||
source: "tok_visa",
|
source: 'tok_visa',
|
||||||
description: `Charity Bundle Payment`,
|
description: `Charity Bundle Payment`,
|
||||||
statement_descriptor: `charity bundle ${grant.id}`,
|
statement_descriptor: `charity bundle ${grant.id}`,
|
||||||
receipt_email: "[email protected]"
|
receipt_email: '[email protected]'
|
||||||
});
|
});
|
||||||
|
|
||||||
let transfers = await organizations.map(async org => {
|
let transfers = await organizations.map(async org => {
|
||||||
@@ -38,9 +38,9 @@ exports.grantCharge = async ({
|
|||||||
|
|
||||||
let t = await stripe.transfers.create({
|
let t = await stripe.transfers.create({
|
||||||
amount: stripeOrgAmount - applicationStripeFee,
|
amount: stripeOrgAmount - applicationStripeFee,
|
||||||
currency: "usd",
|
currency: 'usd',
|
||||||
source_transaction: charge.id,
|
source_transaction: charge.id,
|
||||||
destination: "acct_1EAxzUIVW1uo07uH"
|
destination: 'acct_1EAxzUIVW1uo07uH'
|
||||||
});
|
});
|
||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
@@ -61,7 +61,7 @@ exports.deleteGrant = async (req, res, next) => {
|
|||||||
// check if there are plans for that grant
|
// check if there are plans for that grant
|
||||||
if (!paymentPlans.length) {
|
if (!paymentPlans.length) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
message: "Not a valid grant"
|
message: 'Not a valid grant'
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const plan = paymentPlans[0];
|
const plan = paymentPlans[0];
|
||||||
@@ -115,12 +115,12 @@ exports.activateStripeAccount = async (req, res, next) => {
|
|||||||
}&code=${code}&grant_type=authorization_code`;
|
}&code=${code}&grant_type=authorization_code`;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
uri: "https://connect.stripe.com/oauth/token",
|
uri: 'https://connect.stripe.com/oauth/token',
|
||||||
method: "POST",
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
client_secret: process.env.STRIPE_KEY,
|
client_secret: process.env.STRIPE_KEY,
|
||||||
code,
|
code,
|
||||||
grant_type: "authorization_code"
|
grant_type: 'authorization_code'
|
||||||
},
|
},
|
||||||
json: true
|
json: true
|
||||||
};
|
};
|
||||||
@@ -130,11 +130,11 @@ exports.activateStripeAccount = async (req, res, next) => {
|
|||||||
const { stripe_user_id } = stripeAccRes;
|
const { stripe_user_id } = stripeAccRes;
|
||||||
|
|
||||||
const updateRes = await db.sequelize.query(
|
const updateRes = await db.sequelize.query(
|
||||||
"UPDATE organizations SET stripe_account_id = :stripe_user_id WHERE id = :org_id",
|
'UPDATE organizations SET stripe_account_id = :stripe_user_id WHERE id = :org_id',
|
||||||
{ replacements: { stripe_user_id, org_id } }
|
{ replacements: { stripe_user_id, org_id } }
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(302).redirect("http://localhost:8081/org/main/banking");
|
return res.status(302).redirect('http://localhost:8081/org/main/');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,11 +55,8 @@ router.get('/dashboard', checkAuth(roles.DONOR), donor.getDashboardData);
|
|||||||
|
|
||||||
router.get('/charges', checkAuth(roles.DONOR), charge.getAllChargesbyDonor);
|
router.get('/charges', checkAuth(roles.DONOR), charge.getAllChargesbyDonor);
|
||||||
|
|
||||||
router.put(
|
//TODO: checkAuth so only donors can add ribbons
|
||||||
'/statusupdate/ribbon/:update_id',
|
router.put('/statusupdate/ribbon/:update_id', post.addRibbon);
|
||||||
checkAuth(roles.DONOR),
|
|
||||||
post.addRibbon
|
|
||||||
);
|
|
||||||
|
|
||||||
// // Retrieve a single Donor by Id
|
// // Retrieve a single Donor by Id
|
||||||
// router.get('/:donor_id', donor.findById);
|
// router.get('/:donor_id', donor.findById);
|
||||||
|
|||||||
Reference in New Issue
Block a user