adding integration with payment sources table and within stripe controller

This commit is contained in:
Arjun Patel
2019-05-11 03:27:30 -07:00
parent f865781c07
commit 3c55717dda
6 changed files with 187 additions and 7 deletions
+5 -3
View File
@@ -34,6 +34,7 @@ exports.createGrant = async (req, res, next) => {
// get transaction
transaction = await sequelize.transaction();
// creating grant in table
const grant = await Grant.create(
{
donor_id: user.id,
@@ -48,6 +49,7 @@ exports.createGrant = async (req, res, next) => {
}
);
// getting data for later use throughout
await Promise.all(
await organizations.map(async org => {
let dbOrgs = await sequelize.query(
@@ -70,7 +72,7 @@ exports.createGrant = async (req, res, next) => {
})
);
// one time charge
// one time charge with stripe helper
const charge = await stripe.grantCharge({
grant,
stripeToken,
@@ -81,6 +83,7 @@ exports.createGrant = async (req, res, next) => {
transaction
});
// mapping between bundle and orgs
const grantsOrgs = organizations.map(org => {
return {
grant_id: grant.id,
@@ -88,12 +91,11 @@ exports.createGrant = async (req, res, next) => {
amount: org.finalAmountToOrg
};
});
// mapping between bundle and orgs
await GrantOrganization.bulkCreate(grantsOrgs, {
transaction
});
// creating in charge table for reference
await Charge.create(
{
id: charge.id,