diff --git a/ghost/members-api/lib/MembersAPI.js b/ghost/members-api/lib/MembersAPI.js index 0270503663..093e363d61 100644 --- a/ghost/members-api/lib/MembersAPI.js +++ b/ghost/members-api/lib/MembersAPI.js @@ -169,6 +169,10 @@ module.exports = function MembersAPI({ }); async function disconnectStripe() { + if (stripeConfig && stripeConfig.webhook && stripeConfig.webhook.id) { + await stripeWebhookService.removeWebhook(stripeConfig.webhook.id); + } + await Product.forge().query().update({ monthly_price_id: null, yearly_price_id: null diff --git a/ghost/members-api/lib/services/stripe-webhook.js b/ghost/members-api/lib/services/stripe-webhook.js index 7483fa418e..3224c2f6af 100644 --- a/ghost/members-api/lib/services/stripe-webhook.js +++ b/ghost/members-api/lib/services/stripe-webhook.js @@ -100,6 +100,20 @@ module.exports = class StripeWebhookService { this._webhookSecret = webhook.secret; } + /** + * @param {string} id - WebhookEndpoint Stripe ID + * + * @returns {Promise} + */ + async removeWebhook(id) { + try { + await this._stripeAPIService.deleteWebhookEndpoint(id); + return true; + } catch (err) { + return false; + } + } + /** * @param {string} body * @param {string} signature