diff --git a/app/locale/en.coffee b/app/locale/en.coffee index 3a010d364..0c09e5ea2 100644 --- a/app/locale/en.coffee +++ b/app/locale/en.coffee @@ -334,6 +334,13 @@ subscribe: subscribe_title: "Subscribe" + levels: "25 more levels, with 5 new levels every week!" + heroes: "Unlock more heroes, including wizards and rangers!" + gems: "Subscribers get 3500 bonus gems per month!" + items: "Unlock the coding power of 275 new items!" + parents: "Parents" + parents_title: "Your child should learn to code." + parents_blurb: "Invest in your child's education by teaching her to program with CodeCombat. It's just $9.99/mo, and that comes with personal email support, cancellation with a click, and a 100% money-back guarantee." subscribe_button: "$9.99/mo - Subscribe" stripe_description: "Monthly Subscription" diff --git a/app/styles/play/modal/subscribe-modal.sass b/app/styles/play/modal/subscribe-modal.sass index 43c6f83de..ef3a94898 100644 --- a/app/styles/play/modal/subscribe-modal.sass +++ b/app/styles/play/modal/subscribe-modal.sass @@ -57,31 +57,37 @@ #selling-points position: absolute - left: 55px - top: 142px - width: 681px - height: 140px + left: 65px + top: 335px + width: 650px + font-weight: bold + line-height: 18px + color: black + font-family: 'Open Sans Condensed' + font-size: 18px .point width: 150px - height: 256px overflow: none float: left - text-align: center + text-align: left margin-right: 10px - background-color: rgba(156, 204, 10, 0.2) - - h4 - font-size: 20px - color: rgb(22,16,5) - - h3 - margin-top: 10px - text-transform: uppercase - color: rgb(22,16,5) - - button - width: 80% + + #parents-info + position: absolute + right: 7px + top: 56px + text-decoration: underline + cursor: pointer + + .popover + z-index: 1050 + + h3 + background: transparent + border: 0 + font-size: 30px + color: black //- Purchase button diff --git a/app/templates/play/modal/subscribe-modal.jade b/app/templates/play/modal/subscribe-modal.jade index ec7667223..37681e8a1 100644 --- a/app/templates/play/modal/subscribe-modal.jade +++ b/app/templates/play/modal/subscribe-modal.jade @@ -16,13 +16,15 @@ #selling-points #point-levels.point - .blurb 25 more levels. 5 new levels every week. + .blurb(data-i18n="subscribe.levels") 25 more levels, with 5 new levels every week! #point-heroes.point - .blurb 13 more heroes to unleash on the ogre hordes. - #point-items.point - .blurb 275 items to unlock and explore. + .blurb(data-i18n="subscribe.heroes") Unlock more heroes, including wizards and rangers! #point-gems.point - .blurb Subscribers get 3500 bonus gems per month. + .blurb(data-i18n="subscribe.gems") Subscribers get 3500 bonus gems per month! + #point-items.point + .blurb(data-i18n="subscribe.items") Unlock the coding power of 275 new items! + + #parents-info(data-i18n="subscribe.parents") button.btn.btn-lg.btn-illustrated.purchase-button(data-i18n="subscribe.subscribe_button") span $9.99/mo - Subscribe diff --git a/app/views/play/modal/SubscribeModal.coffee b/app/views/play/modal/SubscribeModal.coffee index a2494ecc1..b9fee5df3 100644 --- a/app/views/play/modal/SubscribeModal.coffee +++ b/app/views/play/modal/SubscribeModal.coffee @@ -29,11 +29,26 @@ module.exports = class SubscribeModal extends ModalView c.stateMessage = @stateMessage return c + afterRender: -> + super() + popoverTitle = $.i18n.t 'subscribe.parents_title' + popoverContent = $.i18n.t 'subscribe.parents_blurb' + @$el.find('#parents-info').popover( + animation: true + html: true + placement: 'top' + trigger: 'hover' + title: popoverTitle + content: popoverContent + container: @$el + ).on 'shown.bs.popover', => + application.tracker?.trackEvent 'Subscription parent hover', {} + onClickPurchaseButton: (e) -> @playSound 'menu-button-click' application.tracker?.trackEvent 'Started subscription purchase', {} stripeHandler.open({ - description: $.t 'subscribe.stripe_description' + description: $.i18n.t 'subscribe.stripe_description' amount: @product.amount }) @@ -46,31 +61,24 @@ module.exports = class SubscribeModal extends ModalView stripe.token = e.token.id me.set 'stripe', stripe - me.save() @listenToOnce me, 'sync', @onSubscriptionSuccess @listenToOnce me, 'error', @onSubscriptionError + me.save() - onSubmissionSuccess: -> - console.log 'we done it!' - # PLAY A OSUND TOITJOTIJOITJDODONNN + onSubscriptionSuccess: -> + application.tracker?.trackEvent 'Finished subscription purchase', {} + @playSound 'victory' @hide() - onSubscriptionError: (e) -> - console.log 'we got an error subscribing', e + onSubscriptionError: (user, response, options) -> + console.error 'We got an error subscribing with Stripe from our server:', response stripe = me.get('stripe') ? {} delete stripe.token delete stripe.planID - - # - # if jqxhr.status is 402 - # @state = 'declined' - # @stateMessage = arguments[2] - # else if jqxhr.status is 500 - # @state = 'retrying' - # f = _.bind @onStripeReceivedToken, @, e - # _.delay f, 2000 - # else - # @state = 'unknown_error' - # @stateMessage = "#{jqxhr.status}: #{jqxhr.responseText}" - # @render() - #) + xhr = options.xhr + if xhr.status is 402 + @state = 'declined' + else + @state = 'unknown_error' + @stateMessage = "#{xhr.status}: #{xhr.responseText}" + @render() diff --git a/server/payments/subscription_handler.coffee b/server/payments/subscription_handler.coffee index e8cabd8a1..5659949e7 100644 --- a/server/payments/subscription_handler.coffee +++ b/server/payments/subscription_handler.coffee @@ -65,10 +65,10 @@ class SubscriptionHandler extends Handler @checkForExistingSubscription(req, user, customer, done) ) - + checkForExistingSubscription: (req, user, customer, done) -> if subscription = customer.subscriptions?.data?[0] - + if subscription.cancel_at_period_end # Things are a little tricky here. Can't re-enable a cancelled subscription, # so it needs to be deleted, but also don't want to charge for the new subscription immediately. @@ -84,22 +84,22 @@ class SubscriptionHandler extends Handler if err @logSubscriptionError(req, 'Stripe customer plan setting error. '+err) return done({res: 'Database error.', code: 500}) - + @updateUser(req, user, customer.subscriptions.data[0], false, done) else # can skip creating the subscription return @updateUser(req, user, customer.subscriptions.data[0], false, done) - + else stripe.customers.update req.user.get('stripe').customerID, { plan: 'basic' }, (err, customer) => if err @logSubscriptionError(req, 'Stripe customer plan setting error. '+err) return done({res: 'Database error.', code: 500}) - + @updateUser(req, user, customer.subscriptions.data[0], true, done) - - + + updateUser: (req, user, subscription, increment, done) -> stripeInfo = _.cloneDeep(user.get('stripe') ? {}) stripeInfo.planID = 'basic' @@ -120,8 +120,8 @@ class SubscriptionHandler extends Handler @logSubscriptionError(req, 'Stripe user plan saving error. '+err) return done({res: 'Database error.', code: 500}) return done() - - + + unsubscribeUser: (req, user, done) -> stripeInfo = _.cloneDeep(user.get('stripe')) stripe.customers.cancelSubscription stripeInfo.customerID, stripeInfo.subscriptionID, { at_period_end: true }, (err) => @@ -136,6 +136,6 @@ class SubscriptionHandler extends Handler @logSubscriptionError(req, 'User save unsubscribe error. '+err) return done({res: 'Database error.', code: 500}) return done() - -module.exports = new SubscriptionHandler() \ No newline at end of file + +module.exports = new SubscriptionHandler()