fixing charges input into db

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