Added hasActiveStripeSubscriptions method (#169)

no-issue

This can be used by Ghost to determine if the Stripe keys can be deleted
This commit is contained in:
Fabien 'egg' O'Carroll 2020-06-18 18:01:04 +02:00 committed by GitHub
parent aa0b02b75e
commit ae9870993a

View File

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