mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Extend terminal sub with year sub purchase
This commit is contained in:
parent
2ad285093a
commit
5faeb82d17
6 changed files with 114 additions and 4 deletions
|
@ -444,6 +444,7 @@
|
|||
sale_button_title: "Save 35% when you purchase a 1 year subscription"
|
||||
sale_click_here: "Click Here"
|
||||
sale_ends: "Ends"
|
||||
sale_extended: "*Existing subscriptions will be extended by 1 year."
|
||||
sale_feature_here: "Here's what you'll get:"
|
||||
sale_feature4: "<strong>42,000 bonus gems</strong> awarded immediately!"
|
||||
sale_continue: "Ready to continue adventuring?"
|
||||
|
|
|
@ -24,5 +24,7 @@
|
|||
-moz-transform: rotate(330deg) /* Firefox */
|
||||
-webkit-transform: rotate(330deg) /* Safari and Chrome */
|
||||
-o-transform: rotate(330deg) /* Opera */
|
||||
.sub-extended
|
||||
font-size: 12px
|
||||
#pay-button
|
||||
font-size: 18px
|
||||
|
|
|
@ -12,7 +12,7 @@ block content
|
|||
a(href="/account/subscription", data-i18n="account.subscription")
|
||||
li.active(data-i18n="account.sale") Sale
|
||||
|
||||
if me.hasSubscription()
|
||||
if hasSubscription
|
||||
h1(data-i18n="subscribe.sale_already_subscribed")
|
||||
span.spr(data-i18n="subscribe.sale_continue")
|
||||
a(href="/play", data-i18n="subscribe.sale_click_here")
|
||||
|
@ -43,6 +43,7 @@ block content
|
|||
li.feature-description(data-i18n="[html]subscribe.sale_feature4")
|
||||
li.feature-description(data-i18n="subscribe.feature5")
|
||||
li.feature-description(data-i18n="[html]subscribe.feature7")
|
||||
div.sub-extended(data-i18n="subscribe.sale_extended")
|
||||
br
|
||||
p.center
|
||||
button.btn.btn-success#pay-button #{payButtonText}
|
||||
|
|
|
@ -33,6 +33,7 @@ module.exports = class SubscriptionSaleView extends RootView
|
|||
|
||||
getRenderData: ->
|
||||
c = super()
|
||||
c.hasSubscription = me.get('stripe')?.sponsorID or me.get('stripe')?.subscriptionID
|
||||
c.heroes = @heroes.models
|
||||
c.payButtonText = @payButtonText
|
||||
c.saleEndDate = @saleEndDate
|
||||
|
|
|
@ -119,7 +119,8 @@ class SubscriptionHandler extends Handler
|
|||
|
||||
purchaseYearSale: (req, res) ->
|
||||
return @sendForbiddenError(res) unless req.user?
|
||||
return @sendForbiddenError(res) if req.user?.hasSubscription()
|
||||
return @sendForbiddenError(res) if req.user?.get('stripe')?.sponsorID
|
||||
return @sendForbiddenError(res) if req.user?.get('stripe')?.subscriptionID
|
||||
|
||||
StripeUtils.getCustomer req.user, req.body.stripe?.token, (err, customer) =>
|
||||
if err
|
||||
|
@ -143,9 +144,12 @@ class SubscriptionHandler extends Handler
|
|||
return @sendDatabaseError(res, err)
|
||||
|
||||
# Add terminal subscription to User
|
||||
endDate = new Date()
|
||||
endDate.setUTCFullYear(endDate.getUTCFullYear() + 1)
|
||||
stripeInfo = _.cloneDeep(req.user.get('stripe') ? {})
|
||||
endDate = new Date()
|
||||
if _.isString(stripeInfo.free) and new Date() < new Date(stripeInfo.free)
|
||||
# Extend end date by remaining terminal subscription
|
||||
endDate = new Date(stripeInfo.free)
|
||||
endDate.setUTCFullYear(endDate.getUTCFullYear() + 1)
|
||||
stripeInfo.free = endDate.toISOString().substring(0, 10)
|
||||
req.user.set('stripe', stripeInfo)
|
||||
|
||||
|
|
|
@ -1400,3 +1400,104 @@ describe 'Subscriptions', ->
|
|||
expect(payment).toBeDefined()
|
||||
expect(payment.get('gems')).toEqual(3500*12)
|
||||
done()
|
||||
|
||||
it 'year_sale when stripe.free === true', (done) ->
|
||||
stripe.tokens.create {
|
||||
card: { number: '4242424242424242', exp_month: 12, exp_year: 2020, cvc: '123' }
|
||||
}, (err, token) ->
|
||||
loginNewUser (user1) ->
|
||||
user1.set('stripe', {free: true})
|
||||
user1.save (err, user1) ->
|
||||
expect(err).toBeNull()
|
||||
expect(user1.get('stripe')?.free).toEqual(true)
|
||||
requestBody =
|
||||
stripe:
|
||||
token: token.id
|
||||
timestamp: new Date()
|
||||
request.put {uri: "#{subscriptionURL}/-/year_sale", json: requestBody, headers: headers }, (err, res) ->
|
||||
expect(err).toBeNull()
|
||||
expect(res.statusCode).toBe(200)
|
||||
User.findById user1.id, (err, user1) ->
|
||||
expect(err).toBeNull()
|
||||
stripeInfo = user1.get('stripe')
|
||||
expect(stripeInfo).toBeDefined()
|
||||
return done() unless stripeInfo
|
||||
endDate = new Date()
|
||||
endDate.setUTCFullYear(endDate.getUTCFullYear() + 1)
|
||||
expect(stripeInfo.free).toEqual(endDate.toISOString().substring(0, 10))
|
||||
expect(stripeInfo.customerID).toBeDefined()
|
||||
expect(user1.get('purchased')?.gems).toEqual(3500*12)
|
||||
Payment.findOne 'stripe.customerID': stripeInfo.customerID, (err, payment) ->
|
||||
expect(err).toBeNull()
|
||||
expect(payment).toBeDefined()
|
||||
expect(payment.get('gems')).toEqual(3500*12)
|
||||
done()
|
||||
|
||||
it 'year_sale when stripe.free < today', (done) ->
|
||||
stripe.tokens.create {
|
||||
card: { number: '4242424242424242', exp_month: 12, exp_year: 2020, cvc: '123' }
|
||||
}, (err, token) ->
|
||||
loginNewUser (user1) ->
|
||||
endDate = new Date()
|
||||
endDate.setUTCFullYear(endDate.getUTCFullYear() - 1)
|
||||
user1.set('stripe', {free: endDate.toISOString().substring(0, 10)})
|
||||
user1.save (err, user1) ->
|
||||
expect(err).toBeNull()
|
||||
expect(user1.get('stripe')?.free).toEqual(endDate.toISOString().substring(0, 10))
|
||||
requestBody =
|
||||
stripe:
|
||||
token: token.id
|
||||
timestamp: new Date()
|
||||
request.put {uri: "#{subscriptionURL}/-/year_sale", json: requestBody, headers: headers }, (err, res) ->
|
||||
expect(err).toBeNull()
|
||||
expect(res.statusCode).toBe(200)
|
||||
User.findById user1.id, (err, user1) ->
|
||||
expect(err).toBeNull()
|
||||
stripeInfo = user1.get('stripe')
|
||||
expect(stripeInfo).toBeDefined()
|
||||
return done() unless stripeInfo
|
||||
endDate = new Date()
|
||||
endDate.setUTCFullYear(endDate.getUTCFullYear() + 1)
|
||||
expect(stripeInfo.free).toEqual(endDate.toISOString().substring(0, 10))
|
||||
expect(stripeInfo.customerID).toBeDefined()
|
||||
expect(user1.get('purchased')?.gems).toEqual(3500*12)
|
||||
Payment.findOne 'stripe.customerID': stripeInfo.customerID, (err, payment) ->
|
||||
expect(err).toBeNull()
|
||||
expect(payment).toBeDefined()
|
||||
expect(payment.get('gems')).toEqual(3500*12)
|
||||
done()
|
||||
|
||||
it 'year_sale when stripe.free > today', (done) ->
|
||||
stripe.tokens.create {
|
||||
card: { number: '4242424242424242', exp_month: 12, exp_year: 2020, cvc: '123' }
|
||||
}, (err, token) ->
|
||||
loginNewUser (user1) ->
|
||||
endDate = new Date()
|
||||
endDate.setUTCDate(endDate.getUTCDate() + 5)
|
||||
user1.set('stripe', {free: endDate.toISOString().substring(0, 10)})
|
||||
user1.save (err, user1) ->
|
||||
expect(err).toBeNull()
|
||||
expect(user1.get('stripe')?.free).toEqual(endDate.toISOString().substring(0, 10))
|
||||
requestBody =
|
||||
stripe:
|
||||
token: token.id
|
||||
timestamp: new Date()
|
||||
request.put {uri: "#{subscriptionURL}/-/year_sale", json: requestBody, headers: headers }, (err, res) ->
|
||||
expect(err).toBeNull()
|
||||
expect(res.statusCode).toBe(200)
|
||||
User.findById user1.id, (err, user1) ->
|
||||
expect(err).toBeNull()
|
||||
stripeInfo = user1.get('stripe')
|
||||
expect(stripeInfo).toBeDefined()
|
||||
return done() unless stripeInfo
|
||||
endDate = new Date()
|
||||
endDate.setUTCFullYear(endDate.getUTCFullYear() + 1)
|
||||
endDate.setUTCDate(endDate.getUTCDate() + 5)
|
||||
expect(stripeInfo.free).toEqual(endDate.toISOString().substring(0, 10))
|
||||
expect(stripeInfo.customerID).toBeDefined()
|
||||
expect(user1.get('purchased')?.gems).toEqual(3500*12)
|
||||
Payment.findOne 'stripe.customerID': stripeInfo.customerID, (err, payment) ->
|
||||
expect(err).toBeNull()
|
||||
expect(payment).toBeDefined()
|
||||
expect(payment.get('gems')).toEqual(3500*12)
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue