promise request attempt
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
'config': path.resolve('./app/config', 'migrations.config.js'),
|
||||
'config': path.resolve('./app/config', 'db.config.js'),
|
||||
'models-path': path.resolve('./', 'models'),
|
||||
'seeders-path': path.resolve('./', 'seeders'),
|
||||
'migrations-path': path.resolve('./', 'migrations')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const db = require('../../models'),
|
||||
errorMaker = require('../helpers/error.maker');
|
||||
errorMaker = require('../helpers/error.maker'),
|
||||
https = require('https');
|
||||
|
||||
const stripe = require('stripe')(process.env.STRIPE_KEY);
|
||||
|
||||
@@ -86,3 +87,62 @@ exports.deleteGrant = async (req, res, next) => {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
// allows the org to see their stripe account with their balance and payout to their bank
|
||||
exports.getExpressUILink = async (req, res, next) => {
|
||||
// get connected stripe account id from db
|
||||
// createLoginLink with stripe function
|
||||
// return to frontend
|
||||
};
|
||||
|
||||
// verify the charity after they filled out basic info for express ui
|
||||
exports.activateStripeAccount = async (req, res, next) => {
|
||||
const { code } = req.query;
|
||||
console.log(req.query);
|
||||
|
||||
try {
|
||||
var dataString = `client_secret=${
|
||||
process.env.STRIPE_KEY
|
||||
}&code=${code}&grant_type=authorization_code`;
|
||||
|
||||
var options = {
|
||||
host: 'connect.stripe.com',
|
||||
path: '/oauth/token',
|
||||
method: 'POST',
|
||||
body: {
|
||||
client_secret: process.env.STRIPE_KEY,
|
||||
code,
|
||||
grant_type: 'authorization_code'
|
||||
}
|
||||
};
|
||||
|
||||
// Set up the request
|
||||
const postRequest = new Promise((resolve, reject) => {
|
||||
https
|
||||
.request(options, function(res) {
|
||||
res.setEncoding('utf8');
|
||||
let body = '';
|
||||
res.on('data', data => {
|
||||
body += data;
|
||||
});
|
||||
res.on('end', () => {
|
||||
body = JSON.parse(body);
|
||||
});
|
||||
|
||||
resolve(body);
|
||||
})
|
||||
.on('error', err => {
|
||||
console.log('Error: ' + err.message);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
// store for current user, get user_id from the state param maybe?
|
||||
const stripeAccRes = await Promise.resolve(postRequest);
|
||||
console.log(stripeAccRes);
|
||||
|
||||
return res.status(302).redirect('http://localhost:8081/org/main/banking');
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,11 +3,14 @@ const express = require('express'),
|
||||
checkAuth = require('../middleware/check-auth'),
|
||||
roles = require('../helpers/roles');
|
||||
|
||||
const { organization, cause, region } = require('../controllers');
|
||||
const { organization, cause, region, stripe } = require('../controllers');
|
||||
|
||||
// Charity signup route
|
||||
router.post('/', organization.createOrganization);
|
||||
|
||||
// Activate org with stripe
|
||||
router.get('/stripe/connect', stripe.activateStripeAccount);
|
||||
|
||||
// // Add cause
|
||||
// router.post('/cause', checkAuth(roles.ORGANIZATION), cause.createCause);
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ module.exports = (sequelize, DataTypes) => {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0
|
||||
},
|
||||
stripe_account_id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: null
|
||||
},
|
||||
|
||||
primary_contact_email: {
|
||||
type: DataTypes.STRING,
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
"jsonwebtoken": "^8.4.0",
|
||||
"morgan": "^1.9.1",
|
||||
"mysql2": "^1.6.4",
|
||||
"request": "^2.88.0",
|
||||
"sequelize": "^4.42.0",
|
||||
"sequelize-cli": "^5.4.0",
|
||||
"stripe": "^6.22.0",
|
||||
|
||||
Reference in New Issue
Block a user