changes to flow of payments for different fees shown

This commit is contained in:
Arjun Patel
2019-04-30 03:29:03 -07:00
parent 98d165eab1
commit db960ee554
6 changed files with 79 additions and 74 deletions
+13 -13
View File
@@ -48,19 +48,6 @@ exports.createGrant = async (req, res, next) => {
} }
); );
const grantsOrgs = organizations.map(org => {
return {
grant_id: grant.id,
organization_id: org.id,
amount: org.amount
};
});
// mapping between bundle and orgs
await GrantOrganization.bulkCreate(grantsOrgs, {
transaction
});
// one time charge // one time charge
const charge = await stripe.grantCharge({ const charge = await stripe.grantCharge({
grant, grant,
@@ -72,6 +59,19 @@ exports.createGrant = async (req, res, next) => {
user user
}); });
const grantsOrgs = organizations.map(org => {
return {
grant_id: grant.id,
organization_id: org.id,
amount: org.finalAmountToOrg
};
});
// mapping between bundle and orgs
await GrantOrganization.bulkCreate(grantsOrgs, {
transaction
});
await Charge.create( await Charge.create(
{ {
id: charge.id, id: charge.id,
+4 -4
View File
@@ -22,9 +22,9 @@ exports.paymentReceipt = async ({
<td align="left" width="75%" style="padding: 6px 12px;font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;">${ <td align="left" width="75%" style="padding: 6px 12px;font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;">${
charity.name charity.name
}</td> }</td>
<td align="left" width="25%" style="padding: 6px 12px;font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;">$${ <td align="left" width="25%" style="padding: 6px 12px;font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px;">$${charity.amountWithStripeFees.toFixed(
charity.amount 2
}</td> )}</td>
</tr>`; </tr>`;
}); });
@@ -41,7 +41,7 @@ exports.paymentReceipt = async ({
bundle_id: grant.id, bundle_id: grant.id,
charities_list: charitiesHtml, charities_list: charitiesHtml,
total_amount, total_amount,
transaction_fees, transaction_fees: transaction_fees.toFixed(2),
date: currDate, date: currDate,
subject: 'Your Charify Bundle Payment - Charify' subject: 'Your Charify Bundle Payment - Charify'
} }
+15 -10
View File
@@ -15,9 +15,7 @@ exports.grantCharge = async ({
amount, amount,
user user
}) => { }) => {
return new Promise(async (resolve, reject) => { return await new Promise(async (resolve, reject) => {
const grant_id = await grant.id;
try { try {
const donors = await Donor.findAll({ where: { id: user.id } }); const donors = await Donor.findAll({ where: { id: user.id } });
@@ -33,18 +31,18 @@ exports.grantCharge = async ({
receipt_email: donors[0].email receipt_email: donors[0].email
}); });
let transfers = await organizations.map(async (org, index) => { let updatedOrgs = await Promise.all(
organizations.map(async (org, index) => {
const selectedOrgAmount = org.amount; const selectedOrgAmount = org.amount;
// this determines how much Charify takes from each donation // this determines how much payment processing is covered
const stripeFee = const stripeFee =
Math.round((selectedOrgAmount * 0.029 + 0.3) * 1e2) / 1e2; Math.round((selectedOrgAmount * 0.029 + 0.3) * 1e2) / 1e2;
org.amount = org.amount - stripeFee; // this determines how much Charify takes from each donation
const applicationFee = const applicationFee =
Math.round(selectedOrgAmount * 0.025 * 1e2) / 1e2; Math.round(selectedOrgAmount * 0.025 * 1e2) / 1e2;
const applicationAndStripeFee = applicationFee + stripeFee; const applicationAndStripeFee = applicationFee + stripeFee;
console.log(applicationAndStripeFee);
let finalAmountToOrg = 0; let finalAmountToOrg = 0;
let currOrg = await sequelize.query( let currOrg = await sequelize.query(
@@ -88,6 +86,10 @@ exports.grantCharge = async ({
); );
} else finalAmountToOrg = selectedOrgAmount - applicationAndStripeFee; } else finalAmountToOrg = selectedOrgAmount - applicationAndStripeFee;
// for record in grant org table
org.finalAmountToOrg = finalAmountToOrg;
org.amountWithStripeFees = selectedOrgAmount - stripeFee;
// now scale to match stripe standards // now scale to match stripe standards
let t = await stripe.transfers.create({ let t = await stripe.transfers.create({
amount: finalAmountToOrg * 100, amount: finalAmountToOrg * 100,
@@ -96,11 +98,14 @@ exports.grantCharge = async ({
destination: currOrg[0].stripe_account_id destination: currOrg[0].stripe_account_id
}); });
return t; return org;
}); })
);
// to show the transaction fees in email to giver // to show the transaction fees in email to giver
charge.transaction_fees = Math.round((amount * 0.029 + 0.3) * 1e2) / 1e2; charge.transaction_fees = Math.round((amount * 0.029 + 0.3) * 1e2) / 1e2;
// orgs with updated amounts after fees
charge.updatedOrgs = updatedOrgs;
resolve(charge); resolve(charge);
} catch (error) { } catch (error) {
+1 -1
View File
@@ -7,7 +7,7 @@ module.exports = (sequelize, DataTypes) => {
{ {
id: { type: DataTypes.UUID, primaryKey: true, allowNull: false }, id: { type: DataTypes.UUID, primaryKey: true, allowNull: false },
description: DataTypes.STRING, description: DataTypes.STRING,
amount: DataTypes.INTEGER, amount: DataTypes.DOUBLE,
payment_status: { payment_status: {
type: DataTypes.STRING, type: DataTypes.STRING,
+1 -1
View File
@@ -14,7 +14,7 @@ module.exports = (sequelize, DataTypes) => {
allowNull: false allowNull: false
}, },
amount: { amount: {
type: DataTypes.INTEGER, type: DataTypes.DOUBLE,
allowNull: false allowNull: false
}, },
monthly: { monthly: {
+1 -1
View File
@@ -27,7 +27,7 @@ module.exports = (sequelize, DataTypes) => {
} }
}, },
amount: { amount: {
type: DataTypes.INTEGER, type: DataTypes.DOUBLE,
allowNull: false allowNull: false
} }
}, },