diff --git a/ghost/members-api/index.js b/ghost/members-api/index.js index ae050b670b..b22cd88419 100644 --- a/ghost/members-api/index.js +++ b/ghost/members-api/index.js @@ -39,6 +39,26 @@ module.exports = function MembersApi({ const {encodeIdentityToken, decodeToken} = Tokens({privateKey, publicKey, issuer}); const metadata = Metadata({memberStripeCustomerModel, stripeCustomerSubscriptionModel}); + async function hasActiveStripeSubscriptions() { + const firstActiveSubscription = await stripeCustomerSubscriptionModel.findOne({ + status: 'active' + }); + + if (firstActiveSubscription) { + return true; + } + + const firstTrialingSubscription = await stripeCustomerSubscriptionModel.findOne({ + status: 'trialing' + }); + + if (firstTrialingSubscription) { + return true; + } + + return false; + } + const stripeStorage = { async get(member) { return metadata.getMetadata('stripe', member); @@ -450,6 +470,7 @@ module.exports = function MembersApi({ bus, sendEmailWithMagicLink, getMagicLink, + hasActiveStripeSubscriptions, members: users }; };