mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Updated subscription flow to only attach single tier to member
refs https://github.com/TryGhost/Team/issues/1728 - previously, we allowed a member to be mapped to multiple tiers simultaneously as an edge case, in case they managed to signup via another subscription - since this was always an edge case and not supported, to simplify the flows going forward now that complimentary members can also upgrade, in case of an active subscription we'll always just attach the associated tier to member and remove all other tiers mapped to it
This commit is contained in:
parent
6f2066517b
commit
c19d2d8712
1 changed files with 37 additions and 30 deletions
|
@ -941,39 +941,46 @@ module.exports = class MemberRepository {
|
||||||
} else {
|
} else {
|
||||||
status = 'paid';
|
status = 'paid';
|
||||||
}
|
}
|
||||||
// This is an active subscription! Add the product
|
if (this._labsService.isSet('compExpiring')) {
|
||||||
if (ghostProduct) {
|
// This is an active subscription! Update member to have only this product
|
||||||
memberProducts.push(ghostProduct.toJSON());
|
if (ghostProduct) {
|
||||||
}
|
memberProducts = [ghostProduct.toJSON()];
|
||||||
if (model) {
|
}
|
||||||
if (model.get('stripe_price_id') !== subscriptionData.stripe_price_id) {
|
} else {
|
||||||
// The subscription has changed plan - we may need to update the products
|
// This is an active subscription! Add the product
|
||||||
|
if (ghostProduct) {
|
||||||
|
memberProducts.push(ghostProduct.toJSON());
|
||||||
|
}
|
||||||
|
if (model) {
|
||||||
|
if (model.get('stripe_price_id') !== subscriptionData.stripe_price_id) {
|
||||||
|
// The subscription has changed plan - we may need to update the products
|
||||||
|
|
||||||
const subscriptions = await member.related('stripeSubscriptions').fetch(options);
|
const subscriptions = await member.related('stripeSubscriptions').fetch(options);
|
||||||
const changedProduct = await this._productRepository.get({
|
const changedProduct = await this._productRepository.get({
|
||||||
stripe_price_id: model.get('stripe_price_id')
|
stripe_price_id: model.get('stripe_price_id')
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
let activeSubscriptionForChangedProduct = false;
|
let activeSubscriptionForChangedProduct = false;
|
||||||
|
|
||||||
for (const subscription of subscriptions.models) {
|
for (const subscription of subscriptions.models) {
|
||||||
if (this.isActiveSubscriptionStatus(subscription.get('status'))) {
|
if (this.isActiveSubscriptionStatus(subscription.get('status'))) {
|
||||||
try {
|
try {
|
||||||
const subscriptionProduct = await this._productRepository.get({stripe_price_id: subscription.get('stripe_price_id')}, options);
|
const subscriptionProduct = await this._productRepository.get({stripe_price_id: subscription.get('stripe_price_id')}, options);
|
||||||
if (subscriptionProduct && changedProduct && subscriptionProduct.id === changedProduct.id) {
|
if (subscriptionProduct && changedProduct && subscriptionProduct.id === changedProduct.id) {
|
||||||
activeSubscriptionForChangedProduct = true;
|
activeSubscriptionForChangedProduct = true;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logging.error(`Failed to attach products to member - ${data.id}`);
|
||||||
|
logging.error(e);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
logging.error(`Failed to attach products to member - ${data.id}`);
|
|
||||||
logging.error(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!activeSubscriptionForChangedProduct) {
|
if (!activeSubscriptionForChangedProduct) {
|
||||||
memberProducts = memberProducts.filter((product) => {
|
memberProducts = memberProducts.filter((product) => {
|
||||||
return product.id !== changedProduct.id;
|
return product.id !== changedProduct.id;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue