0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Simplify logic when to call stripeService.connect()

This commit is contained in:
Aileen Booker 2023-06-12 14:03:51 -04:00 committed by Aileen Booker
parent 10859b9b01
commit 00131de0b6

View file

@ -208,12 +208,19 @@ class SettingsBREADService {
key: 'stripe_connect_account_id',
value: stripeConnectData.account_id
});
if (stripeConnectData.public_key.match(/pk_live/)) {
// Require the Stripe service here as it breaks existing tests otherwise
const stripeService = require('../stripe');
// This method currently only triggers a DomainEvent
await stripeService.connect();
}
}
// remove any email properties that are not allowed to be set without verification
const {filteredSettings: refilteredSettings, emailsToVerify} = await this.prepSettingsForEmailVerification(filteredSettings, getSetting);
const modelArray = await this.SettingsModel.edit(refilteredSettings, options).then(async (result) => {
const modelArray = await this.SettingsModel.edit(refilteredSettings, options).then((result) => {
// TODO: temporary fix for starting/stopping lexicalMultiplayer service when labs flag is changed
// this should be removed along with the flag, or set up in a more generic way
const labsSetting = result.find(setting => setting.get('key') === 'labs');
@ -229,20 +236,6 @@ class SettingsBREADService {
}
}
// Detect if Stripe is now connected in live mode
const stripePublicKeySetting = result.find(setting => setting.get('key') === 'stripe_connect_publishable_key');
if (stripePublicKeySetting) {
const previous = stripePublicKeySetting.previousAttributes().value;
const current = stripePublicKeySetting.get('value');
if (current?.match(/pk_live/) && (!previous?.match(/pk_live/) || !previous)) {
// Require the Stripe service here as it breaks existing tests otherwise
const stripeService = require('../stripe');
// This method currently only triggers a DomainEvent
await stripeService.connect();
}
}
return this._formatBrowse(_.keyBy(_.invokeMap(result, 'toJSON'), 'key'), options.context);
});