plans page will auto redirect to best guess currency

This commit is contained in:
Henry Oswald 2014-10-13 17:39:44 +01:00
parent 52c54e7300
commit 5a0d74753f
4 changed files with 64 additions and 29 deletions

View file

@ -39,7 +39,10 @@ module.exports = SubscriptionController =
if hasSubscription or !plan?
res.redirect "/user/subscription"
else
currency = req.query.currency || "USD"
currency = req.query.currency?.toUpperCase()
GeoIpLookup.getCurrencyCode req.headers["x-forwarded-for"], (err, recomendedCurrency)->
if recomendedCurrency? and !currency?
currency = recomendedCurrency
RecurlyWrapper.sign {
subscription:
plan_code : req.query.planCode
@ -50,6 +53,7 @@ module.exports = SubscriptionController =
res.render "subscriptions/new",
title : "subscribe"
plan_code: req.query.planCode
currency: currency
recurlyConfig: JSON.stringify
currency: currency
subdomain: Settings.apis.recurly.subdomain

View file

@ -18,7 +18,7 @@ block content
.page-header
h1.text-centered #{translate("new_subscription")}
#subscribeForm #{translate("loading_billing_form")}...
.col-md-5(ng-controller="NewSubscriptionController")
.col-md-5(ng-controller="NewSubscriptionController" ng-cloak)
span.dropdown.col-md-1.changePlanButton()
a.btn.btn-primary.dropdown-toggle(
href="#",

View file

@ -1,7 +1,6 @@
extends ../layout
block scripts
script(type='text/javascript').
window.recurlyPublicToken = '#{settings.apis.recurly.publicKey}'
window.recomendedCurrency = '#{recomendedCurrency}'
block content
.content-alt
@ -34,7 +33,7 @@ block content
ng-click="switchToStudent()"
) #{translate("half_price_student")}
.col-md-2
.dropdown(style="display:none;")
.dropdown()
a.btn.btn-primary.dropdown-toggle#currenyDropdown(
href="#",
data-toggle="dropdown"

View file

@ -120,6 +120,10 @@ describe "SubscriptionController sanboxed", ->
@res.redirectedTo.should.equal "/user/subscription"
describe "paymentPage", ->
beforeEach ->
@req.headers = {}
@GeoIpLookup.getCurrencyCode.callsArgWith(1, null, @stubbedCurrencyCode)
describe "with a user without a subscription", ->
beforeEach ->
@LimitationsManager.userHasSubscription.callsArgWith(1, null, false)
@ -158,6 +162,34 @@ describe "SubscriptionController sanboxed", ->
done()
@SubscriptionController.paymentPage(@req, @res)
describe "which currency to use", ->
beforeEach ->
@LimitationsManager.userHasSubscription.callsArgWith(1, null, false)
@PlansLocator.findLocalPlanInSettings.returns({})
it "should use the set currency from the query string", (done)->
@req.query.currency = "EUR"
@res.render = (page, opts)=>
opts.currency.should.equal "EUR"
opts.currency.should.not.equal @stubbedCurrencyCode
done()
@SubscriptionController.paymentPage @req, @res
it "should upercase the currency code", (done)->
@req.query.currency = "eur"
@res.render = (page, opts)=>
opts.currency.should.equal "EUR"
done()
@SubscriptionController.paymentPage @req, @res
it "should use the geo ip currency if non is provided", (done)->
@req.query.currency = null
@res.render = (page, opts)=>
opts.currency.should.equal @stubbedCurrencyCode
done()
@SubscriptionController.paymentPage @req, @res
describe "successful_subscription", ->
beforeEach (done) ->
@SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel.callsArgWith(1, null, {})