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