From 6fe46a79f34dc3fa1741f89222df7fae245e70db Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Wed, 2 Oct 2019 14:40:00 +0700 Subject: [PATCH] Added cancelAllSubscriptions method no-issue This gets all subscriptions, filters out ones which have already been cancelled and cancels the rest --- ghost/members-api/lib/stripe/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ghost/members-api/lib/stripe/index.js b/ghost/members-api/lib/stripe/index.js index f63014b5bf..58fe464197 100644 --- a/ghost/members-api/lib/stripe/index.js +++ b/ghost/members-api/lib/stripe/index.js @@ -108,6 +108,20 @@ module.exports = class StripePaymentProcessor { }; } + async cancelAllSubscriptions(member) { + const subscriptions = await this.getSubscriptions(member); + + const activeSubscriptions = subscriptions.filter((subscription) => { + return subscription.status !== 'cancelled'; + }); + + await Promise.all(activeSubscriptions.map((subscription) => { + return del(this._stripe, 'subscriptions', subscription.subscription); + })); + + return true; + } + async getSubscriptions(member) { const metadata = await this.storage.get(member);