From c996c7b576dbd45b5ad959daeb9a603df8539cef Mon Sep 17 00:00:00 2001 From: Rishabh Garg Date: Tue, 27 Oct 2020 15:15:23 +0530 Subject: [PATCH] Added `unpaid` and `past_due` subscription status as paid member (#211) refs https://github.com/TryGhost/Ghost/issues/12256 , https://github.com/TryGhost/Ghost/issues/12255 Currently when listing subscriptions for Members, we were only showing the subscriptions which have a status of trialing or active. Based on discussion, the `unpaid` and `past_due` states on Stripe also represent owner's intention of considering a subscription as active instead of `cancelled`, so we allow any subscriptions under these 2 states to be also listed for a member and consider them as `paid`. - Subscriptions will go into a past_due state if the payment is missed, this should be considered a grace period where the member still has access. - After this the subscriptions will either go to the unpaid or the cancelled state - this can be configured on an account by account basis in the Stripe dashboard. `unpaid` is considered as an intention to keep the subscription to allow for re-activation later. --- ghost/members-api/index.js | 16 ++++++++++++++++ ghost/members-api/lib/stripe/index.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ghost/members-api/index.js b/ghost/members-api/index.js index a7e7b115b6..750f7b9587 100644 --- a/ghost/members-api/index.js +++ b/ghost/members-api/index.js @@ -64,6 +64,22 @@ module.exports = function MembersApi({ return true; } + const firstUnpaidSubscription = await StripeCustomerSubscription.findOne({ + status: 'unpaid' + }); + + if (firstUnpaidSubscription) { + return true; + } + + const firstPastDueSubscription = await StripeCustomerSubscription.findOne({ + status: 'past_due' + }); + + if (firstPastDueSubscription) { + return true; + } + return false; } diff --git a/ghost/members-api/lib/stripe/index.js b/ghost/members-api/lib/stripe/index.js index 7f45e57798..48c4ec27b0 100644 --- a/ghost/members-api/lib/stripe/index.js +++ b/ghost/members-api/lib/stripe/index.js @@ -341,7 +341,7 @@ module.exports = class StripePaymentProcessor { const subscriptions = await this.getSubscriptions(member); return subscriptions.filter((subscription) => { - return subscription.status === 'active' || subscription.status === 'trialing'; + return ['active', 'trialing', 'unpaid', 'past_due'].includes(subscription.status); }); }