Deleted webhooks when disconnecting from Stripe

refs https://github.com/TryGhost/Team/issues/1006

When disconnecting from Stripe, we currently do not remove the webhooks,
this will result in the webhooks from Stripe failing, and tending toward
a 100% error rate, which will ultimately result in emails from Stripe
about the failing webhook.

In order to stop all of that from happening, we should make sure that we
actively remove the webhook from Stripe when disconnecting.
This commit is contained in:
Fabien O'Carroll 2021-09-07 17:18:23 +02:00
parent 2d394b3a2e
commit 67d2104190
2 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -100,6 +100,20 @@ module.exports = class StripeWebhookService {
this._webhookSecret = webhook.secret;
}
/**
* @param {string} id - WebhookEndpoint Stripe ID
*
* @returns {Promise<boolean>}
*/
async removeWebhook(id) {
try {
await this._stripeAPIService.deleteWebhookEndpoint(id);
return true;
} catch (err) {
return false;
}
}
/**
* @param {string} body
* @param {string} signature