diff --git a/src/controllers/payments/index.js b/src/controllers/payments/index.js index 332f2cdf45..c20a90a6f3 100644 --- a/src/controllers/payments/index.js +++ b/src/controllers/payments/index.js @@ -29,6 +29,7 @@ exports.createSubscription = function(data, cb) { var recipient = data.gift ? data.gift.member : data.user; if (!recipient.purchased.plan) recipient.purchased.plan = {}; var p = recipient.purchased.plan; + var giftMonths = data.gift ? data.gift.subscription.months : 0 _(p).merge({ // override with these values planId:'basic_earned', customerId: data.customerId, @@ -37,12 +38,21 @@ exports.createSubscription = function(data, cb) { paymentMethod: data.paymentMethod, extraMonths: +p.extraMonths + +(p.dateTerminated ? moment(p.dateTerminated).diff(new Date(),'months',true) : 0) - + +(data.gift ? data.gift.subscription.months : 0), + + +(giftMonths), dateTerminated: null }).defaults({ // allow non-override if a plan was previously used dateCreated: new Date(), mysteryItems: [] }); + + // Block sub perks + if (giftMonths) { + p.consecutive.offset += giftMonths; + p.consecutive.gemCapExtra += giftMonths*5; + if (p.consecutive.gemCapExtra > 25) p.consecutive.gemCapExtra = 25; + p.consecutive.trinkets += giftMonths; + } + revealMysteryItems(recipient); if(isProduction) { utils.txnEmail(data.user, 'subscription-begins'); diff --git a/src/models/user.js b/src/models/user.js index 92be197914..3dbb7f0f29 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -94,15 +94,18 @@ var UserSchema = new Schema({ planId: String, paymentMethod: String, //enum: ['Paypal','Stripe', 'Gift', '']} customerId: String, - dateCreated: Date, dateTerminated: Date, dateUpdated: Date, - consecutiveMonths: {type:Number, 'default':0}, extraMonths: {type:Number, 'default':0}, - gemsBought: {type: Number, 'default': 0}, - mysteryItems: {type: Array, 'default': []} + mysteryItems: {type: Array, 'default': []}, + consecutive: { + count: {type:Number, 'default':0}, + offset: {type:Number, 'default':0}, // when gifted subs, offset++ for each month. offset-- each new-month (cron). count doesn't ++ until offset==0 + gemCapExtra: {type:Number, 'default':0}, + trinkets: {type:Number, 'default':0} + } } }, diff --git a/views/options/settings.jade b/views/options/settings.jade index b094bb9e07..b1bee5e7ad 100644 --- a/views/options/settings.jade +++ b/views/options/settings.jade @@ -231,6 +231,13 @@ script(id='partials/options.settings.subscription.html',type='text/ng-template') p.alert.alert-success(ng-if='p.extraMonths') span.glyphicon.glyphicon-credit-card | You have {{p.extraMonths | number:2}} months of subscription credit. + ul.alert.alert-success.list-unstyled(ng-if='p.consecutive.count || p.consecutive.offset') + li: h4 + span.glyphicon.glyphicon-forward + |  Consecutive Subscription + li You've been subscribed for {{p.consecutive.count}} consecutive months, plus {{p.consecutive.offset}} extra (gift / block-subscription). + li Gem Cap Extra: {{p.consecutive.gemCapExtra}} + li Time Trinkets: {{p.consecutive.trinkets}} h2=env.t('individualSub') div(ng-include="'partials/options.settings.subscription.perks.html'")