diff --git a/app/controllers/stripe.controller.js b/app/controllers/stripe.controller.js index 753e1b5..0aa45a0 100644 --- a/app/controllers/stripe.controller.js +++ b/app/controllers/stripe.controller.js @@ -93,6 +93,25 @@ exports.getExpressUILink = async (req, res, next) => { // get connected stripe account id from db // createLoginLink with stripe function // return to frontend + const org_id = req.user.id; + + try { + const orgs = await db.sequelize.query( + `SELECT stripe_account_id + FROM organizations + WHERE id = :org_id + LIMIT 1`, + { replacements: { org_id }, type: db.sequelize.QueryTypes.SELECT } + ); + + const stripeAccessRes = await stripe.accounts.createLoginLink( + orgs[0].stripe_account_id + ); + + return res.status(200).json({ url: stripeAccessRes.url }); + } catch (error) { + next(error); + } }; // verify the charity after they filled out basic info for express ui diff --git a/app/routes/organization.route.js b/app/routes/organization.route.js index 235b2ea..26556b5 100644 --- a/app/routes/organization.route.js +++ b/app/routes/organization.route.js @@ -8,9 +8,16 @@ const { organization, cause, region, stripe } = require('../controllers'); // Charity signup route router.post('/', organization.createOrganization); -// Activate org with stripe +// GET Activate org with stripe router.get('/stripe/connect', stripe.activateStripeAccount); +// GET express ui account link +router.get( + '/stripe/link', + checkAuth(roles.ORGANIZATION), + stripe.getExpressUILink +); + // // Add cause // router.post('/cause', checkAuth(roles.ORGANIZATION), cause.createCause);