mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
cda041d424
refs https://github.com/TryGhost/Team/issues/1083 The Offers service is going to need access to the StripeAPIService too, so we need to move it out of the @tryghost/members-api module and make it accessible to both.
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
const ghostVersion = require('@tryghost/version');
|
|
|
|
module.exports = {
|
|
getConfig(settings, config) {
|
|
/**
|
|
* @param {'direct' | 'connect'} type - The "type" of keys to fetch from settings
|
|
* @returns {{publicKey: string, secretKey: string} | null}
|
|
*/
|
|
function getStripeKeys(type) {
|
|
const secretKey = settings.get(`stripe_${type === 'connect' ? 'connect_' : ''}secret_key`);
|
|
const publicKey = settings.get(`stripe_${type === 'connect' ? 'connect_' : ''}publishable_key`);
|
|
|
|
if (!secretKey || !publicKey) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
secretKey,
|
|
publicKey
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @returns {{publicKey: string, secretKey: string} | null}
|
|
*/
|
|
function getActiveStripeKeys() {
|
|
const stripeDirect = config.get('stripeDirect');
|
|
|
|
if (stripeDirect) {
|
|
return getStripeKeys('direct');
|
|
}
|
|
|
|
const connectKeys = getStripeKeys('connect');
|
|
|
|
if (!connectKeys) {
|
|
return getStripeKeys('direct');
|
|
}
|
|
|
|
return connectKeys;
|
|
}
|
|
const keys = getActiveStripeKeys();
|
|
if (!keys) {
|
|
return null;
|
|
}
|
|
return {
|
|
secretKey: keys.secretKey,
|
|
publicKey: keys.publicKey,
|
|
appInfo: {
|
|
name: 'Ghost',
|
|
partner_id: 'pp_partner_DKmRVtTs4j9pwZ',
|
|
version: ghostVersion.original,
|
|
url: 'https://ghost.org/'
|
|
},
|
|
enablePromoCodes: config.get('enableStripePromoCodes')
|
|
};
|
|
}
|
|
};
|