mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
Fix one-off issue for monthly subs (#14643)
* Fix initial plan.consecutive.offset for 1 month subs * fix initial values for group plan subs * Make perkMonthCount editable in admin panel * Add aditional info to admin panel * Implement automatic fix for affected users * fix(lint): exclusive test, code style * fixes * fix issue with initialization --------- Co-authored-by: SabreCat <sabe@habitica.com>
This commit is contained in:
@@ -748,9 +748,19 @@ describe('payments/index', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not add to plans.consecutive.offset if 1 month subscription', async () => {
|
it('does not add to plans.consecutive.offset if 1 month subscription', async () => {
|
||||||
|
data.sub.key = 'basic_earned';
|
||||||
await api.createSubscription(data);
|
await api.createSubscription(data);
|
||||||
|
|
||||||
expect(user.purchased.plan.extraMonths).to.eql(0);
|
expect(user.purchased.plan.consecutive.offset).to.eql(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resets plans.consecutive.offset if 1 month subscription', async () => {
|
||||||
|
user.purchased.plan.consecutive.offset = 1;
|
||||||
|
await user.save();
|
||||||
|
data.sub.key = 'basic_earned';
|
||||||
|
await api.createSubscription(data);
|
||||||
|
|
||||||
|
expect(user.purchased.plan.consecutive.offset).to.eql(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds 5 to plan.consecutive.gemCapExtra for 3 month block', async () => {
|
it('adds 5 to plan.consecutive.gemCapExtra for 3 month block', async () => {
|
||||||
|
|||||||
@@ -17,10 +17,18 @@
|
|||||||
Payment schedule ("basic-earned" is monthly):
|
Payment schedule ("basic-earned" is monthly):
|
||||||
<strong>{{ hero.purchased.plan.planId }}</strong>
|
<strong>{{ hero.purchased.plan.planId }}</strong>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="hero.purchased.plan.planId == 'group_plan_auto'">
|
||||||
|
Group plan ID:
|
||||||
|
<strong>{{ hero.purchased.plan.owner }}</strong>
|
||||||
|
</div>
|
||||||
<div v-if="hero.purchased.plan.dateCreated">
|
<div v-if="hero.purchased.plan.dateCreated">
|
||||||
Creation date:
|
Creation date:
|
||||||
<strong>{{ dateFormat(hero.purchased.plan.dateCreated) }}</strong>
|
<strong>{{ dateFormat(hero.purchased.plan.dateCreated) }}</strong>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="hero.purchased.plan.dateCurrentTypeCreated">
|
||||||
|
Start date for current subscription type:
|
||||||
|
<strong>{{ dateFormat(hero.purchased.plan.dateCurrentTypeCreated) }}</strong>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
Termination date:
|
Termination date:
|
||||||
<strong
|
<strong
|
||||||
@@ -46,9 +54,16 @@
|
|||||||
Perk offset months:
|
Perk offset months:
|
||||||
<strong>{{ hero.purchased.plan.consecutive.offset }}</strong>
|
<strong>{{ hero.purchased.plan.consecutive.offset }}</strong>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="form-inline">
|
||||||
Perk month count:
|
Perk month count:
|
||||||
<strong>{{ hero.purchased.plan.perkMonthCount }}</strong>
|
<input
|
||||||
|
v-model="hero.purchased.plan.perkMonthCount"
|
||||||
|
class="form-control"
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
max="2"
|
||||||
|
step="1"
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
Next Mystic Hourglass:
|
Next Mystic Hourglass:
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ async function addSubToGroupUser (member, group) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save unused hourglass and mystery items
|
// save unused hourglass and mystery items
|
||||||
|
plan.perkMonthCount = memberPlan.perkMonthCount;
|
||||||
plan.consecutive.trinkets = memberPlan.consecutive.trinkets;
|
plan.consecutive.trinkets = memberPlan.consecutive.trinkets;
|
||||||
plan.mysteryItems = memberPlan.mysteryItems;
|
plan.mysteryItems = memberPlan.mysteryItems;
|
||||||
|
|
||||||
|
|||||||
@@ -253,13 +253,18 @@ async function createSubscription (data) {
|
|||||||
} = await prepareSubscriptionValues(data);
|
} = await prepareSubscriptionValues(data);
|
||||||
|
|
||||||
// Block sub perks
|
// Block sub perks
|
||||||
if (months > 0 && (!data.gift || !isNewSubscription)) {
|
if (months > 1 && (!data.gift || !isNewSubscription)) {
|
||||||
if (!data.gift && !groupId) {
|
if (!data.gift && !groupId) {
|
||||||
plan.consecutive.offset = block.months;
|
plan.consecutive.offset = block.months;
|
||||||
}
|
}
|
||||||
|
} else if (months === 1) {
|
||||||
|
plan.consecutive.offset = 0;
|
||||||
}
|
}
|
||||||
if (months > 1 || data.gift) {
|
if (months > 1 || data.gift) {
|
||||||
await plan.incrementPerkCounterAndReward(recipient._id, months);
|
await plan.incrementPerkCounterAndReward(recipient._id, months);
|
||||||
|
} else {
|
||||||
|
// Make sure the perkMonthCount field is initialized.
|
||||||
|
await plan.incrementPerkCounterAndReward(recipient._id, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipient !== group) {
|
if (recipient !== group) {
|
||||||
|
|||||||
@@ -56,13 +56,20 @@ schema.methods.incrementPerkCounterAndReward = async function incrementPerkCount
|
|||||||
if (typeof adding === 'string' || adding instanceof String) {
|
if (typeof adding === 'string' || adding instanceof String) {
|
||||||
addingNumber = parseInt(adding, 10);
|
addingNumber = parseInt(adding, 10);
|
||||||
}
|
}
|
||||||
|
const isSingleMonthPlan = this.planId === 'basic_earned' || this.planId === 'group_plan_auto' || this.planId === 'group_monthly';
|
||||||
// if perkMonthCount wasn't used before, initialize it.
|
// if perkMonthCount wasn't used before, initialize it.
|
||||||
if (this.perkMonthCount === undefined || this.perkMonthCount === -1) {
|
if (this.perkMonthCount === undefined || this.perkMonthCount === -1) {
|
||||||
if (this.planId === 'basic_earned') {
|
if (isSingleMonthPlan && this.consecutive.count > 0) {
|
||||||
this.perkMonthCount = (this.consecutive.count - 1) % SUBSCRIPTION_BASIC_BLOCK_LENGTH;
|
this.perkMonthCount = (this.consecutive.count - 1) % SUBSCRIPTION_BASIC_BLOCK_LENGTH;
|
||||||
} else {
|
} else {
|
||||||
this.perkMonthCount = 0;
|
this.perkMonthCount = 0;
|
||||||
}
|
}
|
||||||
|
} else if (isSingleMonthPlan) {
|
||||||
|
const expectedPerkMonthCount = (this.consecutive.count - 1) % SUBSCRIPTION_BASIC_BLOCK_LENGTH;
|
||||||
|
if (this.perkMonthCount === (expectedPerkMonthCount - 1)) {
|
||||||
|
// User was affected by a bug that makes their perkMonthCount off by one
|
||||||
|
this.perkMonthCount += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.perkMonthCount += addingNumber;
|
this.perkMonthCount += addingNumber;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user