properly showing transaction fees with stripe in email and deductions
This commit is contained in:
@@ -100,6 +100,7 @@ exports.createGrant = async (req, res, next) => {
|
|||||||
grant,
|
grant,
|
||||||
organizations,
|
organizations,
|
||||||
total_amount: actual_total,
|
total_amount: actual_total,
|
||||||
|
transaction_fees: charge.transaction_fees,
|
||||||
receiver: donors[0]
|
receiver: donors[0]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ exports.paymentReceipt = async ({
|
|||||||
grant,
|
grant,
|
||||||
organizations,
|
organizations,
|
||||||
total_amount,
|
total_amount,
|
||||||
|
transaction_fees,
|
||||||
receiver
|
receiver
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
@@ -40,6 +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,
|
||||||
date: currDate,
|
date: currDate,
|
||||||
subject: 'Your Charify Bundle Payment - Charify'
|
subject: 'Your Charify Bundle Payment - Charify'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,17 @@ exports.grantCharge = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
let transfers = await organizations.map(async (org, index) => {
|
let transfers = await organizations.map(async (org, index) => {
|
||||||
let selectedOrgAmount = org.amount;
|
const selectedOrgAmount = org.amount;
|
||||||
// this determines how much Charify takes from each donation
|
// this determines how much Charify takes from each donation
|
||||||
const applicationStripeFee = selectedOrgAmount * 0.05;
|
const stripeFee =
|
||||||
|
Math.round((selectedOrgAmount * 0.029 + 0.3) * 1e2) / 1e2;
|
||||||
|
org.amount = org.amount - stripeFee;
|
||||||
|
|
||||||
|
const applicationFee =
|
||||||
|
Math.round(selectedOrgAmount * 0.025 * 1e2) / 1e2;
|
||||||
|
|
||||||
|
const applicationAndStripeFee = applicationFee + stripeFee;
|
||||||
|
console.log(applicationAndStripeFee);
|
||||||
let finalAmountToOrg = 0;
|
let finalAmountToOrg = 0;
|
||||||
|
|
||||||
let currOrg = await sequelize.query(
|
let currOrg = await sequelize.query(
|
||||||
@@ -53,15 +60,15 @@ exports.grantCharge = async ({
|
|||||||
if (currOrg[0].charify_credit) {
|
if (currOrg[0].charify_credit) {
|
||||||
let updated_amt = currOrg[0].charify_credit;
|
let updated_amt = currOrg[0].charify_credit;
|
||||||
|
|
||||||
if (currOrg[0].charify_credit < applicationStripeFee) {
|
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 -
|
||||||
applicationStripeFee +
|
applicationAndStripeFee +
|
||||||
currOrg[0].charify_credit;
|
currOrg[0].charify_credit;
|
||||||
} else {
|
} else {
|
||||||
updated_amt = currOrg[0].charify_credit - applicationStripeFee;
|
updated_amt = currOrg[0].charify_credit - applicationAndStripeFee;
|
||||||
// take nothing as the middle man
|
// take nothing as the middle man
|
||||||
finalAmountToOrg = selectedOrgAmount;
|
finalAmountToOrg = selectedOrgAmount;
|
||||||
}
|
}
|
||||||
@@ -79,7 +86,7 @@ exports.grantCharge = async ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else finalAmountToOrg = selectedOrgAmount - applicationStripeFee;
|
} else finalAmountToOrg = selectedOrgAmount - applicationAndStripeFee;
|
||||||
|
|
||||||
// now scale to match stripe standards
|
// now scale to match stripe standards
|
||||||
let t = await stripe.transfers.create({
|
let t = await stripe.transfers.create({
|
||||||
@@ -92,6 +99,9 @@ exports.grantCharge = async ({
|
|||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// to show the transaction fees in email to giver
|
||||||
|
charge.transaction_fees = Math.round((amount * 0.029 + 0.3) * 1e2) / 1e2;
|
||||||
|
|
||||||
resolve(charge);
|
resolve(charge);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
charify_credit: {
|
charify_credit: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.DOUBLE,
|
||||||
defaultValue: 0
|
defaultValue: 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user