fixing charges input into db
This commit is contained in:
@@ -6,6 +6,7 @@ const sendgrid = require("./sendgrid.controller");
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
Grant,
|
Grant,
|
||||||
|
Charge,
|
||||||
Cause,
|
Cause,
|
||||||
Region,
|
Region,
|
||||||
Organization,
|
Organization,
|
||||||
@@ -62,7 +63,7 @@ exports.createGrant = async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// one time charge
|
// one time charge
|
||||||
await stripe.grantCharge({
|
const charge = await stripe.grantCharge({
|
||||||
grant,
|
grant,
|
||||||
stripeToken,
|
stripeToken,
|
||||||
stripeToken,
|
stripeToken,
|
||||||
@@ -72,6 +73,16 @@ exports.createGrant = async (req, res, next) => {
|
|||||||
user
|
user
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await Charge.create(
|
||||||
|
{
|
||||||
|
id: charge.id,
|
||||||
|
amount,
|
||||||
|
description: "One time payment for grant",
|
||||||
|
grant_id: grant.id
|
||||||
|
},
|
||||||
|
{ transaction }
|
||||||
|
);
|
||||||
|
|
||||||
// send email
|
// send email
|
||||||
await sendgrid.paymentReceipt({
|
await sendgrid.paymentReceipt({
|
||||||
organizations,
|
organizations,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const db = require('../../models'),
|
const db = require("../../models"),
|
||||||
errorMaker = require('../helpers/error.maker'),
|
errorMaker = require("../helpers/error.maker"),
|
||||||
requestPromise = require('request-promise');
|
requestPromise = require("request-promise");
|
||||||
|
|
||||||
const stripe = require('stripe')(process.env.STRIPE_KEY);
|
const stripe = require("stripe")(process.env.STRIPE_KEY);
|
||||||
|
|
||||||
const { Donor, Organization, Charge, PaymentPlan } = db;
|
const { Donor, Organization, Charge, PaymentPlan } = db;
|
||||||
|
|
||||||
@@ -20,18 +20,16 @@ exports.grantCharge = async ({
|
|||||||
try {
|
try {
|
||||||
const donors = await Donor.findAll({ where: { id: user.id } });
|
const donors = await Donor.findAll({ where: { id: user.id } });
|
||||||
|
|
||||||
var result;
|
|
||||||
|
|
||||||
const stripeAmount = amount * 100;
|
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: stripeAmount,
|
amount: stripeAmount,
|
||||||
currency: 'usd',
|
currency: "usd",
|
||||||
source: 'tok_visa',
|
source: "tok_visa",
|
||||||
description: `Charity Bundle Payment`,
|
description: `Charity Bundle Payment`,
|
||||||
statement_descriptor: `charity bundle ${grant.id}`,
|
statement_descriptor: `charity bundle ${grant.id}`,
|
||||||
receipt_email: '[email protected]'
|
receipt_email: "[email protected]"
|
||||||
});
|
});
|
||||||
|
|
||||||
let transfers = await organizations.map(async org => {
|
let transfers = await organizations.map(async org => {
|
||||||
@@ -40,22 +38,14 @@ exports.grantCharge = async ({
|
|||||||
|
|
||||||
let t = await stripe.transfers.create({
|
let t = await stripe.transfers.create({
|
||||||
amount: stripeOrgAmount - applicationStripeFee,
|
amount: stripeOrgAmount - applicationStripeFee,
|
||||||
currency: 'usd',
|
currency: "usd",
|
||||||
source_transaction: charge.id,
|
source_transaction: charge.id,
|
||||||
destination: 'acct_1EAxzUIVW1uo07uH'
|
destination: "acct_1EAxzUIVW1uo07uH"
|
||||||
});
|
});
|
||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
|
|
||||||
await Charge.create({
|
return charge;
|
||||||
id: charge.id,
|
|
||||||
amount,
|
|
||||||
description: 'One time payment for grant'
|
|
||||||
});
|
|
||||||
|
|
||||||
result = charge;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -71,7 +61,7 @@ exports.deleteGrant = async (req, res, next) => {
|
|||||||
// check if there are plans for that grant
|
// check if there are plans for that grant
|
||||||
if (!paymentPlans.length) {
|
if (!paymentPlans.length) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
message: 'Not a valid grant'
|
message: "Not a valid grant"
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const plan = paymentPlans[0];
|
const plan = paymentPlans[0];
|
||||||
@@ -125,12 +115,12 @@ exports.activateStripeAccount = async (req, res, next) => {
|
|||||||
}&code=${code}&grant_type=authorization_code`;
|
}&code=${code}&grant_type=authorization_code`;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
uri: 'https://connect.stripe.com/oauth/token',
|
uri: "https://connect.stripe.com/oauth/token",
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
body: {
|
body: {
|
||||||
client_secret: process.env.STRIPE_KEY,
|
client_secret: process.env.STRIPE_KEY,
|
||||||
code,
|
code,
|
||||||
grant_type: 'authorization_code'
|
grant_type: "authorization_code"
|
||||||
},
|
},
|
||||||
json: true
|
json: true
|
||||||
};
|
};
|
||||||
@@ -140,11 +130,11 @@ exports.activateStripeAccount = async (req, res, next) => {
|
|||||||
const { stripe_user_id } = stripeAccRes;
|
const { stripe_user_id } = stripeAccRes;
|
||||||
|
|
||||||
const updateRes = await db.sequelize.query(
|
const updateRes = await db.sequelize.query(
|
||||||
'UPDATE organizations SET stripe_account_id = :stripe_user_id WHERE id = :org_id',
|
"UPDATE organizations SET stripe_account_id = :stripe_user_id WHERE id = :org_id",
|
||||||
{ replacements: { stripe_user_id, org_id } }
|
{ replacements: { stripe_user_id, org_id } }
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(302).redirect('http://localhost:8081/org/main/banking');
|
return res.status(302).redirect("http://localhost:8081/org/main/banking");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
const express = require('express'),
|
const express = require("express"),
|
||||||
router = express.Router(),
|
router = express.Router(),
|
||||||
checkAuth = require('../middleware/check-auth'),
|
checkAuth = require("../middleware/check-auth"),
|
||||||
roles = require('../helpers/roles');
|
roles = require("../helpers/roles");
|
||||||
|
|
||||||
const { organization, cause, region, stripe } = require('../controllers');
|
const { organization, cause, region, stripe } = require("../controllers");
|
||||||
|
|
||||||
// Charity signup route
|
// Charity signup route
|
||||||
router.post('/', organization.createOrganization);
|
router.post("/", organization.createOrganization);
|
||||||
|
|
||||||
// GET Activate org with stripe
|
// GET Activate org's stripe connected account
|
||||||
router.get('/stripe/connect', stripe.activateStripeAccount);
|
router.get("/stripe/connect", stripe.activateStripeAccount);
|
||||||
|
|
||||||
// GET express ui account link
|
// GET stripe express ui account link
|
||||||
router.get(
|
router.get(
|
||||||
'/stripe/link',
|
"/stripe/link",
|
||||||
checkAuth(roles.ORGANIZATION),
|
checkAuth(roles.ORGANIZATION),
|
||||||
stripe.getExpressUILink
|
stripe.getExpressUILink
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user