Skip to content

Commit ce6d110

Browse files
committed
Fixed Stripe Service coming up if billing portal manager errors
ref ONC-1656 Prevents the whole Stripe Service from erroring if the billing portal manager encounters an error while trying to update the billing portal configuration. This can happen if the billing portal configuration that Ghost has created has been made the default one by the Stripe Account owner.
1 parent f6edd55 commit ce6d110

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

ghost/core/core/server/services/stripe/billing-portal-manager.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const logging = require('@tryghost/logging');
2+
13
const CONFIGURATION_ID_SETTING = 'stripe_billing_portal_configuration_id';
24

35
const DEFAULT_FEATURES = {
@@ -91,7 +93,13 @@ class BillingPortalManager {
9193
const configuration = await this.api.createBillingPortalConfiguration(this.getConfigurationOptions());
9294
return configuration.id;
9395
}
94-
throw err;
96+
97+
logging.error('Failed to update the billing portal configuration', {
98+
err
99+
});
100+
101+
// Couldn't modify configuration, means it's likely the default config
102+
return id;
95103
}
96104
}
97105

ghost/core/test/unit/server/services/stripe/billing-portal-manager.test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe('BillingPortalManager', function () {
173173
sinon.assert.calledOnce(mockApi.createBillingPortalConfiguration);
174174
});
175175

176-
it('throws error when update fails with non-resource_missing error', async function () {
176+
it('returns the passed id when failing with a non-resource based error', async function () {
177177
mockSettingsCache.get.withArgs('title').returns('Test Site');
178178
const genericError = new Error('Stripe API error');
179179
mockApi.updateBillingPortalConfiguration.rejects(genericError);
@@ -185,10 +185,8 @@ describe('BillingPortalManager', function () {
185185
});
186186
manager.configure({siteUrl: 'https://example.com'});
187187

188-
await assert.rejects(
189-
() => manager.createOrUpdateConfiguration('bpc_existing'),
190-
{message: 'Stripe API error'}
191-
);
188+
const result = await manager.createOrUpdateConfiguration('bpc_existing');
189+
assert.equal(result, 'bpc_existing');
192190
});
193191
});
194192

0 commit comments

Comments
 (0)