mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03: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
@ -1,7 +1,4 @@
|
||||
const membersService = require('../../services/members');
|
||||
const config = require('../../../shared/config');
|
||||
const urlUtils = require('../../../shared/url-utils');
|
||||
const {BadRequestError} = require('@tryghost/errors');
|
||||
|
||||
module.exports = {
|
||||
docName: 'members_stripe_connect',
|
||||
@ -18,13 +15,6 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
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
|
||||
frame.response = async function (req, res) {
|
||||
function setSessionProp(prop, val) {
|
||||
|
@ -4,6 +4,9 @@ const {Buffer} = require('buffer');
|
||||
const {randomBytes} = require('crypto');
|
||||
const {URL} = require('url');
|
||||
|
||||
const config = require('../../../shared/config');
|
||||
const urlUtils = require('../../../shared/url-utils');
|
||||
|
||||
const messages = {
|
||||
incorrectState: 'State did not match.'
|
||||
};
|
||||
@ -24,6 +27,7 @@ const redirectURI = 'https://stripe.ghost.org';
|
||||
* @returns {Promise<URL>}
|
||||
*/
|
||||
async function getStripeConnectOAuthUrl(setSessionProp, mode = 'live') {
|
||||
checkCanConnect();
|
||||
const randomState = randomBytes(16).toString('hex');
|
||||
const state = Buffer.from(JSON.stringify({
|
||||
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 = {
|
||||
getStripeConnectOAuthUrl,
|
||||
getStripeConnectTokenData,
|
||||
|
Loading…
Reference in New Issue
Block a user