Skip to content

Commit

Permalink
BuyGemsModal handles if there is no monthly subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
sderickson committed Mar 2, 2017
1 parent df606b7 commit 31984dd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app/locale/en.coffee
Expand Up @@ -607,6 +607,9 @@
prompt_button: "Enter Shop"
recovered: "Previous gems purchase recovered. Please refresh the page."
price: "x{{gems}} / mo"
buy_premium: "Buy Premium"
purchase: "Purchase"
purchased: "Purchased"

subscribe:
subscribe_modal_title: "CodeCombat Premium"
Expand Down
3 changes: 3 additions & 0 deletions app/models/User.coffee
Expand Up @@ -220,6 +220,9 @@ module.exports = class User extends CocoModel
return true if me.isAdmin()
return true if me.hasSubscription()
return false

isForeverPremium: ->
return @get('stripe')?.free is true

isOnPremiumServer: ->
return true if me.get('country') in ['brazil']
Expand Down
33 changes: 23 additions & 10 deletions app/templates/play/modal/buy-gems-modal.jade
Expand Up @@ -33,16 +33,29 @@
a(href="http://www.codecombat.nl/kopen", target="_blank")
button.btn.btn-ideal.btn-illustrated.btn-lg.btn-succes PREPAID CODES

.product
h4.subscription-gem-amount x{{gems}} / mo
h3(data-i18n="account.subscription")
if me.hasSubscription()
button.disabled.start-subscription-button.btn.btn-lg.btn-illustrated.btn-success
| ✓
span(data-i18n="account.subscribed")
else
button.start-subscription-button.btn.btn-lg.btn-illustrated.btn-success(data-i18n="subscribe.subscribe_title") Subscribe

if view.basicProduct
.product
h4.subscription-gem-amount x{{gems}} / mo
h3(data-i18n="account.subscription")
if me.hasSubscription()
button.disabled.start-subscription-button.btn.btn-lg.btn-illustrated.btn-success
| ✓
span(data-i18n="account.subscribed")
else
button.start-subscription-button.btn.btn-lg.btn-illustrated.btn-success(data-i18n="subscribe.subscribe_title")

else if view.lifetimeProduct
.product
h4.subscription-gem-amount x#{view.lifetimeProduct.get('gems')}
h3(data-i18n="buy_gems.buy_premium")
if me.isForeverPremium()
button.disabled.start-subscription-button.btn.btn-lg.btn-illustrated.btn-success
| ✓
span(data-i18n="buy_gems.purchased")
else
button.start-subscription-button.btn.btn-lg.btn-illustrated.btn-success(data-i18n="buy_gems.purchase")


if view.state === 'declined'
#declined-alert.alert.alert-danger.alert-dismissible
span(data-i18n="buy_gems.declined")
Expand Down
1 change: 1 addition & 0 deletions app/views/play/modal/BuyGemsModal.coffee
Expand Up @@ -45,6 +45,7 @@ module.exports = class BuyGemsModal extends ModalView
@basicProduct = @products.findWhere { name: 'basic_subscription' }
if countrySpecificProduct = @products.findWhere { name: "#{me.get('country')}_basic_subscription" }
@basicProduct = countrySpecificProduct
@lifetimeProduct = @products.findWhere { name: 'lifetime_subscription' }
@products.reset @products.filter (product) -> _.string.startsWith(product.get('name'), 'gems_')
super()

Expand Down
4 changes: 4 additions & 0 deletions server/middleware/products.coffee
Expand Up @@ -102,6 +102,10 @@ productStubs = [
}
]

# For Backbone collection in dev environment, otherwise models merge
for productStub in productStubs
productStub._id = _.uniqueId()

module.exports = {
get
productStubs
Expand Down

0 comments on commit 31984dd

Please sign in to comment.