fixes to payments for the .3 to be distributed

This commit is contained in:
Arjun Patel
2019-05-09 01:35:41 -07:00
parent 98485a0da0
commit ed0cee28a2
3 changed files with 34 additions and 18 deletions
+22 -1
View File
@@ -48,11 +48,32 @@ exports.createGrant = async (req, res, next) => {
} }
); );
await Promise.all(
await organizations.map(async org => {
let dbOrgs = await sequelize.query(
`
SELECT stripe_account_id,
ein,
charify_credit
FROM organizations
WHERE id = :org_id
`,
{
type: sequelize.QueryTypes.SELECT,
replacements: { org_id: org.id }
}
);
org.stripe_account_id = dbOrgs[0].stripe_account_id;
org.ein = dbOrgs[0].ein;
org.charify_credit = dbOrgs[0].ein;
})
);
// one time charge // one time charge
const charge = await stripe.grantCharge({ const charge = await stripe.grantCharge({
grant, grant,
stripeToken, stripeToken,
stripeToken,
organizations, organizations,
monthly, monthly,
amount, amount,
+3 -3
View File
@@ -21,7 +21,7 @@ exports.paymentReceipt = async ({
charitiesHtml += `<tr> charitiesHtml += `<tr>
<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> } <i>(${charity.ein})</i></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.finalAmountToOrg.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>
@@ -32,7 +32,7 @@ exports.paymentReceipt = async ({
const msg = { const msg = {
to: receiver.email, to: receiver.email,
from: { email: 'no-reply@charify.com', name: 'Charify Payments' }, from: { email: 'no-reply@ucharify.com', name: 'UCharify Payments' },
template_id: 'd-569f804f5e7749cba66bac1994607280', template_id: 'd-569f804f5e7749cba66bac1994607280',
substitutionWrappers: ['{{', '}}'], substitutionWrappers: ['{{', '}}'],
@@ -43,7 +43,7 @@ exports.paymentReceipt = async ({
total_amount, total_amount,
transaction_fees: transaction_fees.toFixed(2), transaction_fees: transaction_fees.toFixed(2),
date: currDate, date: currDate,
subject: 'Your Charify Bundle Payment - Charify' subject: 'Your UCharify Bundle Payment'
} }
}; };
const sentRes = await sgMail.send(msg); const sentRes = await sgMail.send(msg);
+9 -14
View File
@@ -26,17 +26,22 @@ exports.grantCharge = async ({
amount: stripeAmount, amount: stripeAmount,
currency: 'usd', currency: 'usd',
source: stripeToken, source: stripeToken,
description: `Charify Bundle ${grant.id}`, description: `UCharify Bundle ${grant.id}`,
statement_descriptor: `Charify Bundle ${grant.id}`, statement_descriptor: `UCharify Bundle ${grant.id}`,
receipt_email: donors[0].email receipt_email: donors[0].email
}); });
// splitting the .30 cents per transaction to each org
let indivThirtyCentFee =
Math.round((0.3 / organizations.length) * 1e2) / 1e2;
let updatedOrgs = await Promise.all( let updatedOrgs = await Promise.all(
organizations.map(async org => { 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 + indivThirtyCentFee) * 1e2) /
1e2;
// this determines how much Charify takes from each donation // this determines how much Charify takes from each donation
const applicationFee = 0; const applicationFee = 0;
//const applicationFee = Math.round(selectedOrgAmount * 0.025 * 1e2) / 1e2; //const applicationFee = Math.round(selectedOrgAmount * 0.025 * 1e2) / 1e2;
@@ -45,16 +50,6 @@ exports.grantCharge = async ({
let finalAmountToOrg = 0; let finalAmountToOrg = 0;
let currOrg = await sequelize.query(
`
SELECT stripe_account_id, charify_credit FROM organizations
WHERE id = :org_id`,
{
type: db.Sequelize.QueryTypes.SELECT,
replacements: { org_id: org.id }
}
);
// IMPLEMENTATION FOR CHARIFY CREDIT // IMPLEMENTATION FOR CHARIFY CREDIT
// if (currOrg[0].charify_credit) { // if (currOrg[0].charify_credit) {
// let updated_amt = currOrg[0].charify_credit; // let updated_amt = currOrg[0].charify_credit;
@@ -98,7 +93,7 @@ exports.grantCharge = async ({
amount: finalAmountToOrg * 100, amount: finalAmountToOrg * 100,
currency: 'usd', currency: 'usd',
source_transaction: charge.id, source_transaction: charge.id,
destination: currOrg[0].stripe_account_id destination: org.stripe_account_id
}); });
return org; return org;