mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 05:15:20 -05:00
plans page will auto redirect to best guess currency
This commit is contained in:
parent
52c54e7300
commit
5a0d74753f
4 changed files with 64 additions and 29 deletions
|
@ -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
|
||||
|
|
|
@ -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="#",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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, {})
|
||||
|
|
Loading…
Reference in a new issue