mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Fixed max-complexity-warnings for stripe_connect API
no-issue This removes the logic to check if stripe connect is allowed into the stripe connect service, which makes the feature easier to maintain, as well as fixes the v3 API - which previously did not have this check.
This commit is contained in:
parent
a68b96001c
commit
bccc8790f0
2 changed files with 14 additions and 10 deletions
|
@ -1,7 +1,4 @@
|
||||||
const membersService = require('../../services/members');
|
const membersService = require('../../services/members');
|
||||||
const config = require('../../../shared/config');
|
|
||||||
const urlUtils = require('../../../shared/url-utils');
|
|
||||||
const {BadRequestError} = require('@tryghost/errors');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
docName: 'members_stripe_connect',
|
docName: 'members_stripe_connect',
|
||||||
|
@ -18,13 +15,6 @@ module.exports = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
query(frame) {
|
query(frame) {
|
||||||
const siteUrl = urlUtils.getSiteUrl();
|
|
||||||
const productionMode = config.get('env') === 'production';
|
|
||||||
const siteUrlUsingSSL = /^https/.test(siteUrl);
|
|
||||||
const cannotConnectToStripe = productionMode && !siteUrlUsingSSL;
|
|
||||||
if (cannotConnectToStripe) {
|
|
||||||
throw new BadRequestError('Cannot connect to stripe unless site is using https://');
|
|
||||||
}
|
|
||||||
// This is something you have to do if you want to use the "framework" with access to the raw req/res
|
// This is something you have to do if you want to use the "framework" with access to the raw req/res
|
||||||
frame.response = async function (req, res) {
|
frame.response = async function (req, res) {
|
||||||
function setSessionProp(prop, val) {
|
function setSessionProp(prop, val) {
|
||||||
|
|
|
@ -4,6 +4,9 @@ const {Buffer} = require('buffer');
|
||||||
const {randomBytes} = require('crypto');
|
const {randomBytes} = require('crypto');
|
||||||
const {URL} = require('url');
|
const {URL} = require('url');
|
||||||
|
|
||||||
|
const config = require('../../../shared/config');
|
||||||
|
const urlUtils = require('../../../shared/url-utils');
|
||||||
|
|
||||||
const messages = {
|
const messages = {
|
||||||
incorrectState: 'State did not match.'
|
incorrectState: 'State did not match.'
|
||||||
};
|
};
|
||||||
|
@ -24,6 +27,7 @@ const redirectURI = 'https://stripe.ghost.org';
|
||||||
* @returns {Promise<URL>}
|
* @returns {Promise<URL>}
|
||||||
*/
|
*/
|
||||||
async function getStripeConnectOAuthUrl(setSessionProp, mode = 'live') {
|
async function getStripeConnectOAuthUrl(setSessionProp, mode = 'live') {
|
||||||
|
checkCanConnect();
|
||||||
const randomState = randomBytes(16).toString('hex');
|
const randomState = randomBytes(16).toString('hex');
|
||||||
const state = Buffer.from(JSON.stringify({
|
const state = Buffer.from(JSON.stringify({
|
||||||
mode,
|
mode,
|
||||||
|
@ -71,6 +75,16 @@ async function getStripeConnectTokenData(encodedData, getSessionProp) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkCanConnect() {
|
||||||
|
const siteUrl = urlUtils.getSiteUrl();
|
||||||
|
const productionMode = config.get('env') === 'production';
|
||||||
|
const siteUrlUsingSSL = /^https/.test(siteUrl);
|
||||||
|
const cannotConnectToStripe = productionMode && !siteUrlUsingSSL;
|
||||||
|
if (cannotConnectToStripe) {
|
||||||
|
throw new errors.BadRequestError('Cannot connect to stripe unless site is using https://');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getStripeConnectOAuthUrl,
|
getStripeConnectOAuthUrl,
|
||||||
getStripeConnectTokenData,
|
getStripeConnectTokenData,
|
||||||
|
|
Loading…
Reference in a new issue