mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Prevented ios and android subs from being upgrade to group plans (#8646)
* Prevented ios and android subs from being upgrade to group plans * Add admin email sender * Updated admin email * Updated get user email * Fixed grammar issue
This commit is contained in:
@@ -603,6 +603,64 @@ describe('Purchasing a subscription for group', () => {
|
|||||||
expect(updatedUser.purchased.plan.dateCreated).to.exist;
|
expect(updatedUser.purchased.plan.dateCreated).to.exist;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not modify a user with a Google subscription', async () => {
|
||||||
|
plan.customerId = 'random';
|
||||||
|
plan.paymentMethod = api.constants.GOOGLE_PAYMENT_METHOD;
|
||||||
|
|
||||||
|
let recipient = new User();
|
||||||
|
recipient.profile.name = 'recipient';
|
||||||
|
recipient.purchased.plan = plan;
|
||||||
|
recipient.guilds.push(group._id);
|
||||||
|
await recipient.save();
|
||||||
|
|
||||||
|
user.guilds.push(group._id);
|
||||||
|
await user.save();
|
||||||
|
data.groupId = group._id;
|
||||||
|
|
||||||
|
await api.createSubscription(data);
|
||||||
|
|
||||||
|
let updatedUser = await User.findById(recipient._id).exec();
|
||||||
|
|
||||||
|
expect(updatedUser.purchased.plan.planId).to.eql('basic_3mo');
|
||||||
|
expect(updatedUser.purchased.plan.customerId).to.eql('random');
|
||||||
|
expect(updatedUser.purchased.plan.dateUpdated).to.exist;
|
||||||
|
expect(updatedUser.purchased.plan.gemsBought).to.eql(0);
|
||||||
|
expect(updatedUser.purchased.plan.paymentMethod).to.eql(api.constants.GOOGLE_PAYMENT_METHOD);
|
||||||
|
expect(updatedUser.purchased.plan.extraMonths).to.eql(0);
|
||||||
|
expect(updatedUser.purchased.plan.dateTerminated).to.eql(null);
|
||||||
|
expect(updatedUser.purchased.plan.lastBillingDate).to.exist;
|
||||||
|
expect(updatedUser.purchased.plan.dateCreated).to.exist;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not modify a user with an iOS subscription', async () => {
|
||||||
|
plan.customerId = 'random';
|
||||||
|
plan.paymentMethod = api.constants.IOS_PAYMENT_METHOD;
|
||||||
|
|
||||||
|
let recipient = new User();
|
||||||
|
recipient.profile.name = 'recipient';
|
||||||
|
recipient.purchased.plan = plan;
|
||||||
|
recipient.guilds.push(group._id);
|
||||||
|
await recipient.save();
|
||||||
|
|
||||||
|
user.guilds.push(group._id);
|
||||||
|
await user.save();
|
||||||
|
data.groupId = group._id;
|
||||||
|
|
||||||
|
await api.createSubscription(data);
|
||||||
|
|
||||||
|
let updatedUser = await User.findById(recipient._id).exec();
|
||||||
|
|
||||||
|
expect(updatedUser.purchased.plan.planId).to.eql('basic_3mo');
|
||||||
|
expect(updatedUser.purchased.plan.customerId).to.eql('random');
|
||||||
|
expect(updatedUser.purchased.plan.dateUpdated).to.exist;
|
||||||
|
expect(updatedUser.purchased.plan.gemsBought).to.eql(0);
|
||||||
|
expect(updatedUser.purchased.plan.paymentMethod).to.eql(api.constants.IOS_PAYMENT_METHOD);
|
||||||
|
expect(updatedUser.purchased.plan.extraMonths).to.eql(0);
|
||||||
|
expect(updatedUser.purchased.plan.dateTerminated).to.eql(null);
|
||||||
|
expect(updatedUser.purchased.plan.lastBillingDate).to.exist;
|
||||||
|
expect(updatedUser.purchased.plan.dateCreated).to.exist;
|
||||||
|
});
|
||||||
|
|
||||||
it('updates a user with a cancelled but active group subscription', async () => {
|
it('updates a user with a cancelled but active group subscription', async () => {
|
||||||
plan.key = 'basic_earned';
|
plan.key = 'basic_earned';
|
||||||
plan.customerId = api.constants.GROUP_PLAN_CUSTOMER_ID;
|
plan.customerId = api.constants.GROUP_PLAN_CUSTOMER_ID;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import nconf from 'nconf';
|
||||||
import analytics from './analyticsService';
|
import analytics from './analyticsService';
|
||||||
import {
|
import {
|
||||||
getUserInfo,
|
getUserInfo,
|
||||||
@@ -18,12 +19,16 @@ import {
|
|||||||
} from './errors';
|
} from './errors';
|
||||||
import slack from './slack';
|
import slack from './slack';
|
||||||
|
|
||||||
|
const TECH_ASSISTANCE_EMAIL = nconf.get('EMAILS:TECH_ASSISTANCE_EMAIL');
|
||||||
|
|
||||||
let api = {};
|
let api = {};
|
||||||
|
|
||||||
api.constants = {
|
api.constants = {
|
||||||
UNLIMITED_CUSTOMER_ID: 'habitrpg', // Users with the customerId have an unlimted free subscription
|
UNLIMITED_CUSTOMER_ID: 'habitrpg', // Users with the customerId have an unlimted free subscription
|
||||||
GROUP_PLAN_CUSTOMER_ID: 'group-plan',
|
GROUP_PLAN_CUSTOMER_ID: 'group-plan',
|
||||||
GROUP_PLAN_PAYMENT_METHOD: 'Group Plan',
|
GROUP_PLAN_PAYMENT_METHOD: 'Group Plan',
|
||||||
|
GOOGLE_PAYMENT_METHOD: 'Google',
|
||||||
|
IOS_PAYMENT_METHOD: 'Apple',
|
||||||
};
|
};
|
||||||
|
|
||||||
function revealMysteryItems (user) {
|
function revealMysteryItems (user) {
|
||||||
@@ -77,6 +82,7 @@ api.addSubscriptionToGroupUsers = async function addSubscriptionToGroupUsers (gr
|
|||||||
*/
|
*/
|
||||||
api.addSubToGroupUser = async function addSubToGroupUser (member, group) {
|
api.addSubToGroupUser = async function addSubToGroupUser (member, group) {
|
||||||
let customerIdsToIgnore = [this.constants.GROUP_PLAN_CUSTOMER_ID, this.constants.UNLIMITED_CUSTOMER_ID];
|
let customerIdsToIgnore = [this.constants.GROUP_PLAN_CUSTOMER_ID, this.constants.UNLIMITED_CUSTOMER_ID];
|
||||||
|
let paymentMethodsToIgnore = [this.constants.GOOGLE_PAYMENT_METHOD, this.constants.IOS_PAYMENT_METHOD];
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
user: {},
|
user: {},
|
||||||
@@ -109,7 +115,21 @@ api.addSubToGroupUser = async function addSubToGroupUser (member, group) {
|
|||||||
if (member.isSubscribed()) {
|
if (member.isSubscribed()) {
|
||||||
let memberPlan = member.purchased.plan;
|
let memberPlan = member.purchased.plan;
|
||||||
let customerHasCancelledGroupPlan = memberPlan.customerId === this.constants.GROUP_PLAN_CUSTOMER_ID && !member.hasNotCancelled();
|
let customerHasCancelledGroupPlan = memberPlan.customerId === this.constants.GROUP_PLAN_CUSTOMER_ID && !member.hasNotCancelled();
|
||||||
if (customerIdsToIgnore.indexOf(memberPlan.customerId) !== -1 && !customerHasCancelledGroupPlan) return;
|
let ignorePaymentPlan = paymentMethodsToIgnore.indexOf(memberPlan.paymentMethod) !== -1;
|
||||||
|
let ignoreCustomerId = customerIdsToIgnore.indexOf(memberPlan.customerId) !== -1;
|
||||||
|
|
||||||
|
if (ignorePaymentPlan) {
|
||||||
|
txnEmail(TECH_ASSISTANCE_EMAIL, 'admin-user-subscription-details', [
|
||||||
|
{name: 'PROFILE_NAME', content: member.profile.name},
|
||||||
|
{name: 'UUID', content: member._id},
|
||||||
|
{name: 'EMAIL', content: getUserInfo(member, ['email']).email},
|
||||||
|
{name: 'PAYMENT_METHOD', content: memberPlan.paymentMethod},
|
||||||
|
{name: 'PURCHASED_PLAN', content: JSON.stringify(memberPlan)},
|
||||||
|
{name: 'ACTION_NEEDED', content: 'User has joined group plan. Tell them to cancel subscription then give them free sub.'},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ignorePaymentPlan || ignoreCustomerId) && !customerHasCancelledGroupPlan) return;
|
||||||
|
|
||||||
if (member.hasNotCancelled()) await member.cancelSubscription();
|
if (member.hasNotCancelled()) await member.cancelSubscription();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user