diff --git a/test/api/unit/libs/payments/payments.test.js b/test/api/unit/libs/payments/payments.test.js
index 697a13fe1b..438b8def23 100644
--- a/test/api/unit/libs/payments/payments.test.js
+++ b/test/api/unit/libs/payments/payments.test.js
@@ -748,9 +748,19 @@ describe('payments/index', () => {
});
it('does not add to plans.consecutive.offset if 1 month subscription', async () => {
+ data.sub.key = 'basic_earned';
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 () => {
diff --git a/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue b/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue
index 9e7ffff117..5c5e3e8a43 100644
--- a/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue
+++ b/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue
@@ -17,10 +17,18 @@
Payment schedule ("basic-earned" is monthly):
{{ hero.purchased.plan.planId }}
+
+ Group plan ID:
+ {{ hero.purchased.plan.owner }}
+
Creation date:
{{ dateFormat(hero.purchased.plan.dateCreated) }}
+
+ Start date for current subscription type:
+ {{ dateFormat(hero.purchased.plan.dateCurrentTypeCreated) }}
+
Termination date:
{{ hero.purchased.plan.consecutive.offset }}
-
+
Perk month count:
- {{ hero.purchased.plan.perkMonthCount }}
+
Next Mystic Hourglass:
diff --git a/website/server/libs/payments/groupPayments.js b/website/server/libs/payments/groupPayments.js
index b59566c2fb..dfd7f7eea5 100644
--- a/website/server/libs/payments/groupPayments.js
+++ b/website/server/libs/payments/groupPayments.js
@@ -180,6 +180,7 @@ async function addSubToGroupUser (member, group) {
}
// save unused hourglass and mystery items
+ plan.perkMonthCount = memberPlan.perkMonthCount;
plan.consecutive.trinkets = memberPlan.consecutive.trinkets;
plan.mysteryItems = memberPlan.mysteryItems;
diff --git a/website/server/libs/payments/subscriptions.js b/website/server/libs/payments/subscriptions.js
index ce609e022d..41e2d1ff26 100644
--- a/website/server/libs/payments/subscriptions.js
+++ b/website/server/libs/payments/subscriptions.js
@@ -253,13 +253,18 @@ async function createSubscription (data) {
} = await prepareSubscriptionValues(data);
// Block sub perks
- if (months > 0 && (!data.gift || !isNewSubscription)) {
+ if (months > 1 && (!data.gift || !isNewSubscription)) {
if (!data.gift && !groupId) {
plan.consecutive.offset = block.months;
}
+ } else if (months === 1) {
+ plan.consecutive.offset = 0;
}
if (months > 1 || data.gift) {
await plan.incrementPerkCounterAndReward(recipient._id, months);
+ } else {
+ // Make sure the perkMonthCount field is initialized.
+ await plan.incrementPerkCounterAndReward(recipient._id, 0);
}
if (recipient !== group) {
diff --git a/website/server/models/subscriptionPlan.js b/website/server/models/subscriptionPlan.js
index 31849ceb94..8bc7daa587 100644
--- a/website/server/models/subscriptionPlan.js
+++ b/website/server/models/subscriptionPlan.js
@@ -56,13 +56,20 @@ schema.methods.incrementPerkCounterAndReward = async function incrementPerkCount
if (typeof adding === 'string' || adding instanceof String) {
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 (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;
} else {
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;