mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-18 02:21:47 -05:00
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:
parent
aa0b02b75e
commit
ae9870993a
1 changed files with 21 additions and 0 deletions
|
@ -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
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue