mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-02 04:00:36 +00:00
feat(plans): consectuive-month subscription perks (gifting)
This commit is contained in:
parent
5b01fff700
commit
5fd805db88
3 changed files with 25 additions and 5 deletions
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -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'")
|
||||
|
|
|
|||
Loading…
Reference in a new issue