0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Fixed Complimentary subscriptions being created twice

refs https://github.com/TryGhost/Team/issues/1030

The usage of `setComplimentarySubscription` is for pre-Tiers enabled
sites only. We didn't see this issue before because the `comped` flag
was incorrectly being set to `false` by default. Since it was fixed in
https://github.com/TryGhost/Ghost/commit/ae844db60 the `comped` flag was
then getting sent up, and creating the subscription.

We've moved the usage of `setComplimentarySubscription` to behind the
feature flag so that we do not use old behaviour when Tiers are enabled
This commit is contained in:
Fabien O'Carroll 2021-09-10 13:40:54 +02:00 committed by Fabien 'egg' O'Carroll
parent 864e4583d4
commit c9325aa2cc
2 changed files with 15 additions and 11 deletions

View file

@ -124,9 +124,11 @@ module.exports = {
}, frame.options);
}
if (!labsService.isSet('multipleProducts')) {
if (frame.data.members[0].comped) {
await membersService.api.members.setComplimentarySubscription(member);
}
}
if (frame.options.send_email) {
await membersService.api.sendEmailWithMagicLink({email: member.get('email'), requestedType: frame.options.email_type});
@ -188,6 +190,7 @@ module.exports = {
const hasCompedSubscription = !!member.related('stripeSubscriptions').find(sub => sub.get('plan_nickname') === 'Complimentary' && sub.get('status') === 'active');
if (!labsService.isSet('multipleProducts')) {
if (typeof frame.data.members[0].comped === 'boolean') {
if (frame.data.members[0].comped && !hasCompedSubscription) {
await membersService.api.members.setComplimentarySubscription(member);
@ -197,6 +200,7 @@ module.exports = {
await member.load(['stripeSubscriptions', 'products', 'stripeSubscriptions.stripePrice', 'stripeSubscriptions.stripePrice.stripeProduct']);
}
}
await member.load(['stripeSubscriptions.customer', 'stripeSubscriptions.stripePrice', 'stripeSubscriptions.stripePrice.stripeProduct']);