diff --git a/ghost/core/core/server/services/settings/SettingsBREADService.js b/ghost/core/core/server/services/settings/SettingsBREADService.js index 413886dd68..28ff6fb6f5 100644 --- a/ghost/core/core/server/services/settings/SettingsBREADService.js +++ b/ghost/core/core/server/services/settings/SettingsBREADService.js @@ -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); });