taking out charify credit and application fee per donation

This commit is contained in:
Arjun Patel
2019-05-01 00:56:25 -07:00
parent db960ee554
commit fa2343822b
2 changed files with 39 additions and 36 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ 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;">$${charity.amountWithStripeFees.toFixed( <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.finalAmountToOrg.toFixed(
2 2
)}</td> )}</td>
</tr>`; </tr>`;
+38 -35
View File
@@ -25,21 +25,21 @@ exports.grantCharge = async ({
let charge = await stripe.charges.create({ let charge = await stripe.charges.create({
amount: stripeAmount, amount: stripeAmount,
currency: 'usd', currency: 'usd',
source: 'tok_visa', source: stripeToken,
description: `Charity Bundle Payment`, description: `Charify Bundle ${grant.id}`,
statement_descriptor: `charity bundle ${grant.id}`, statement_descriptor: `Charify Bundle ${grant.id}`,
receipt_email: donors[0].email receipt_email: donors[0].email
}); });
let updatedOrgs = await Promise.all( let updatedOrgs = await Promise.all(
organizations.map(async (org, index) => { organizations.map(async org => {
const selectedOrgAmount = org.amount; const selectedOrgAmount = org.amount;
// this determines how much payment processing is covered // 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;
// this determines how much Charify takes from each donation // this determines how much Charify takes from each donation
const applicationFee = const applicationFee = 0;
Math.round(selectedOrgAmount * 0.025 * 1e2) / 1e2; //const applicationFee = Math.round(selectedOrgAmount * 0.025 * 1e2) / 1e2;
const applicationAndStripeFee = applicationFee + stripeFee; const applicationAndStripeFee = applicationFee + stripeFee;
@@ -55,40 +55,43 @@ exports.grantCharge = async ({
} }
); );
if (currOrg[0].charify_credit) { // IMPLEMENTATION FOR CHARIFY CREDIT
let updated_amt = currOrg[0].charify_credit; // if (currOrg[0].charify_credit) {
// let updated_amt = currOrg[0].charify_credit;
if (currOrg[0].charify_credit < applicationAndStripeFee) { // if (currOrg[0].charify_credit < applicationAndStripeFee) {
updated_amt = 0; // updated_amt = 0;
// use up credit and take remaining as middle man // // use up credit and take remaining as middle man
finalAmountToOrg = // finalAmountToOrg =
selectedOrgAmount - // selectedOrgAmount -
applicationAndStripeFee + // applicationAndStripeFee +
currOrg[0].charify_credit; // currOrg[0].charify_credit;
} else { // } else {
updated_amt = currOrg[0].charify_credit - applicationAndStripeFee; // updated_amt = currOrg[0].charify_credit - applicationAndStripeFee;
// take nothing as the middle man // // take nothing as the middle man
finalAmountToOrg = selectedOrgAmount; // finalAmountToOrg = selectedOrgAmount;
} // }
await sequelize.query( // await sequelize.query(
` // `
UPDATE organizations // UPDATE organizations
SET charify_credit = :updated_amt // SET charify_credit = :updated_amt
WHERE id = :org_id`, // WHERE id = :org_id`,
{ // {
type: db.Sequelize.QueryTypes.UPDATE, // type: db.Sequelize.QueryTypes.UPDATE,
replacements: { // replacements: {
org_id: org.id, // org_id: org.id,
updated_amt // updated_amt
} // }
} // }
); // );
} else finalAmountToOrg = selectedOrgAmount - applicationAndStripeFee; // } else finalAmountToOrg = selectedOrgAmount - applicationAndStripeFee;
finalAmountToOrg = selectedOrgAmount - applicationAndStripeFee;
// for record in grant org table // for record in grant org table
org.finalAmountToOrg = finalAmountToOrg; org.finalAmountToOrg = finalAmountToOrg;
org.amountWithStripeFees = selectedOrgAmount - stripeFee; // 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({