mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-25 02:31:59 -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 {encodeIdentityToken, decodeToken} = Tokens({privateKey, publicKey, issuer});
|
||||||
const metadata = Metadata({memberStripeCustomerModel, stripeCustomerSubscriptionModel});
|
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 = {
|
const stripeStorage = {
|
||||||
async get(member) {
|
async get(member) {
|
||||||
return metadata.getMetadata('stripe', member);
|
return metadata.getMetadata('stripe', member);
|
||||||
|
@ -450,6 +470,7 @@ module.exports = function MembersApi({
|
||||||
bus,
|
bus,
|
||||||
sendEmailWithMagicLink,
|
sendEmailWithMagicLink,
|
||||||
getMagicLink,
|
getMagicLink,
|
||||||
|
hasActiveStripeSubscriptions,
|
||||||
members: users
|
members: users
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue