fixes for rounding
This commit is contained in:
@@ -10,7 +10,7 @@ const { Grant, Cause, Region, Organization, sequelize } = db;
|
||||
exports.create = (req, res, next) => {
|
||||
const user = req.user;
|
||||
|
||||
const {
|
||||
var {
|
||||
name,
|
||||
monthly,
|
||||
causes,
|
||||
@@ -20,6 +20,8 @@ exports.create = (req, res, next) => {
|
||||
stripeToken
|
||||
} = req.body;
|
||||
|
||||
amount = Math.round(amount * 100) / 100;
|
||||
|
||||
if (!stripeToken) {
|
||||
throw errorMaker(400, 'No stripe token given');
|
||||
}
|
||||
@@ -56,7 +58,6 @@ exports.create = (req, res, next) => {
|
||||
stripe.grantCharge({
|
||||
grant: grants.dataValues,
|
||||
stripeToken,
|
||||
grant,
|
||||
stripeToken,
|
||||
organizations,
|
||||
monthly,
|
||||
@@ -66,13 +67,13 @@ exports.create = (req, res, next) => {
|
||||
|
||||
sendgrid.paymentReceipt({
|
||||
organizations,
|
||||
total_amount,
|
||||
total_amount: amount,
|
||||
receiver: user.email
|
||||
});
|
||||
|
||||
return res.status(200).json({
|
||||
message: 'Successfully charged or subscribed',
|
||||
grant
|
||||
grant: grants.dataValues
|
||||
});
|
||||
})
|
||||
.catch(function(error) {
|
||||
|
||||
@@ -21,9 +21,11 @@ exports.grantCharge = async ({
|
||||
|
||||
var result;
|
||||
|
||||
const stripeAmount = amount * 100;
|
||||
|
||||
// charge if yes or no monthly
|
||||
let charge = await stripe.charges.create({
|
||||
amount,
|
||||
amount: stripeAmount,
|
||||
currency: 'usd',
|
||||
source: 'tok_visa',
|
||||
description: `Charity Bundle Payment`,
|
||||
@@ -32,11 +34,11 @@ exports.grantCharge = async ({
|
||||
});
|
||||
|
||||
let transfers = await organizations.map(async org => {
|
||||
org.amount = org.amount * 100;
|
||||
const applicationStripeFee = org.amount * 0.05;
|
||||
let stripeOrgAmount = Math.round(org.amount * 100 * 100) / 100;
|
||||
const applicationStripeFee = stripeOrgAmount * 0.05;
|
||||
|
||||
let t = await stripe.transfers.create({
|
||||
amount: org.amount - applicationStripeFee,
|
||||
amount: stripeOrgAmount - applicationStripeFee,
|
||||
currency: 'usd',
|
||||
source_transaction: charge.id,
|
||||
destination: 'acct_1EAxzUIVW1uo07uH'
|
||||
|
||||
@@ -36,10 +36,6 @@ exports.paymentReceipt = async ({ organizations, total_amount, receiver }) => {
|
||||
}
|
||||
};
|
||||
const sentRes = await sgMail.send(msg);
|
||||
|
||||
return res.status(200).json({
|
||||
message: 'Email sent'
|
||||
});
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user