feat(plans): consectuive-month subscription perks (gifting)

This commit is contained in:
Tyler Renelle 2014-11-28 14:44:40 -07:00
parent 5b01fff700
commit 5fd805db88
3 changed files with 25 additions and 5 deletions

View file

@ -29,6 +29,7 @@ exports.createSubscription = function(data, cb) {
var recipient = data.gift ? data.gift.member : data.user; var recipient = data.gift ? data.gift.member : data.user;
if (!recipient.purchased.plan) recipient.purchased.plan = {}; if (!recipient.purchased.plan) recipient.purchased.plan = {};
var p = recipient.purchased.plan; var p = recipient.purchased.plan;
var giftMonths = data.gift ? data.gift.subscription.months : 0
_(p).merge({ // override with these values _(p).merge({ // override with these values
planId:'basic_earned', planId:'basic_earned',
customerId: data.customerId, customerId: data.customerId,
@ -37,12 +38,21 @@ exports.createSubscription = function(data, cb) {
paymentMethod: data.paymentMethod, paymentMethod: data.paymentMethod,
extraMonths: +p.extraMonths extraMonths: +p.extraMonths
+ +(p.dateTerminated ? moment(p.dateTerminated).diff(new Date(),'months',true) : 0) + +(p.dateTerminated ? moment(p.dateTerminated).diff(new Date(),'months',true) : 0)
+ +(data.gift ? data.gift.subscription.months : 0), + +(giftMonths),
dateTerminated: null dateTerminated: null
}).defaults({ // allow non-override if a plan was previously used }).defaults({ // allow non-override if a plan was previously used
dateCreated: new Date(), dateCreated: new Date(),
mysteryItems: [] 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); revealMysteryItems(recipient);
if(isProduction) { if(isProduction) {
utils.txnEmail(data.user, 'subscription-begins'); utils.txnEmail(data.user, 'subscription-begins');

View file

@ -94,15 +94,18 @@ var UserSchema = new Schema({
planId: String, planId: String,
paymentMethod: String, //enum: ['Paypal','Stripe', 'Gift', '']} paymentMethod: String, //enum: ['Paypal','Stripe', 'Gift', '']}
customerId: String, customerId: String,
dateCreated: Date, dateCreated: Date,
dateTerminated: Date, dateTerminated: Date,
dateUpdated: Date, dateUpdated: Date,
consecutiveMonths: {type:Number, 'default':0},
extraMonths: {type:Number, 'default':0}, extraMonths: {type:Number, 'default':0},
gemsBought: {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}
}
} }
}, },

View file

@ -231,6 +231,13 @@ script(id='partials/options.settings.subscription.html',type='text/ng-template')
p.alert.alert-success(ng-if='p.extraMonths') p.alert.alert-success(ng-if='p.extraMonths')
span.glyphicon.glyphicon-credit-card span.glyphicon.glyphicon-credit-card
| You have {{p.extraMonths | number:2}} months of subscription credit. | 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') h2=env.t('individualSub')
div(ng-include="'partials/options.settings.subscription.perks.html'") div(ng-include="'partials/options.settings.subscription.perks.html'")