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,33 +39,37 @@ module.exports = SubscriptionController =
|
||||||
if hasSubscription or !plan?
|
if hasSubscription or !plan?
|
||||||
res.redirect "/user/subscription"
|
res.redirect "/user/subscription"
|
||||||
else
|
else
|
||||||
currency = req.query.currency || "USD"
|
currency = req.query.currency?.toUpperCase()
|
||||||
RecurlyWrapper.sign {
|
GeoIpLookup.getCurrencyCode req.headers["x-forwarded-for"], (err, recomendedCurrency)->
|
||||||
subscription:
|
if recomendedCurrency? and !currency?
|
||||||
plan_code : req.query.planCode
|
currency = recomendedCurrency
|
||||||
currency: currency
|
RecurlyWrapper.sign {
|
||||||
account_code: user.id
|
subscription:
|
||||||
}, (error, signature) ->
|
plan_code : req.query.planCode
|
||||||
return next(error) if error?
|
|
||||||
res.render "subscriptions/new",
|
|
||||||
title : "subscribe"
|
|
||||||
plan_code: req.query.planCode
|
|
||||||
recurlyConfig: JSON.stringify
|
|
||||||
currency: currency
|
currency: currency
|
||||||
subdomain: Settings.apis.recurly.subdomain
|
account_code: user.id
|
||||||
subscriptionFormOptions: JSON.stringify
|
}, (error, signature) ->
|
||||||
acceptedCards: ['discover', 'mastercard', 'visa']
|
return next(error) if error?
|
||||||
target : "#subscribeForm"
|
res.render "subscriptions/new",
|
||||||
signature : signature
|
title : "subscribe"
|
||||||
planCode : req.query.planCode
|
plan_code: req.query.planCode
|
||||||
successURL : "#{Settings.siteUrl}/user/subscription/create?_csrf=#{req.session._csrf}"
|
currency: currency
|
||||||
accountCode : user.id
|
recurlyConfig: JSON.stringify
|
||||||
enableCoupons: true
|
currency: currency
|
||||||
acceptPaypal: true
|
subdomain: Settings.apis.recurly.subdomain
|
||||||
account :
|
subscriptionFormOptions: JSON.stringify
|
||||||
firstName : user.first_name
|
acceptedCards: ['discover', 'mastercard', 'visa']
|
||||||
lastName : user.last_name
|
target : "#subscribeForm"
|
||||||
email : user.email
|
signature : signature
|
||||||
|
planCode : req.query.planCode
|
||||||
|
successURL : "#{Settings.siteUrl}/user/subscription/create?_csrf=#{req.session._csrf}"
|
||||||
|
accountCode : user.id
|
||||||
|
enableCoupons: true
|
||||||
|
acceptPaypal: true
|
||||||
|
account :
|
||||||
|
firstName : user.first_name
|
||||||
|
lastName : user.last_name
|
||||||
|
email : user.email
|
||||||
|
|
||||||
|
|
||||||
userSubscriptionPage: (req, res, next) ->
|
userSubscriptionPage: (req, res, next) ->
|
||||||
|
|
|
@ -18,7 +18,7 @@ block content
|
||||||
.page-header
|
.page-header
|
||||||
h1.text-centered #{translate("new_subscription")}
|
h1.text-centered #{translate("new_subscription")}
|
||||||
#subscribeForm #{translate("loading_billing_form")}...
|
#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()
|
span.dropdown.col-md-1.changePlanButton()
|
||||||
a.btn.btn-primary.dropdown-toggle(
|
a.btn.btn-primary.dropdown-toggle(
|
||||||
href="#",
|
href="#",
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
extends ../layout
|
extends ../layout
|
||||||
block scripts
|
block scripts
|
||||||
script(type='text/javascript').
|
script(type='text/javascript').
|
||||||
window.recurlyPublicToken = '#{settings.apis.recurly.publicKey}'
|
|
||||||
window.recomendedCurrency = '#{recomendedCurrency}'
|
window.recomendedCurrency = '#{recomendedCurrency}'
|
||||||
block content
|
block content
|
||||||
.content-alt
|
.content-alt
|
||||||
|
@ -34,7 +33,7 @@ block content
|
||||||
ng-click="switchToStudent()"
|
ng-click="switchToStudent()"
|
||||||
) #{translate("half_price_student")}
|
) #{translate("half_price_student")}
|
||||||
.col-md-2
|
.col-md-2
|
||||||
.dropdown(style="display:none;")
|
.dropdown()
|
||||||
a.btn.btn-primary.dropdown-toggle#currenyDropdown(
|
a.btn.btn-primary.dropdown-toggle#currenyDropdown(
|
||||||
href="#",
|
href="#",
|
||||||
data-toggle="dropdown"
|
data-toggle="dropdown"
|
||||||
|
|
|
@ -120,6 +120,10 @@ describe "SubscriptionController sanboxed", ->
|
||||||
@res.redirectedTo.should.equal "/user/subscription"
|
@res.redirectedTo.should.equal "/user/subscription"
|
||||||
|
|
||||||
describe "paymentPage", ->
|
describe "paymentPage", ->
|
||||||
|
beforeEach ->
|
||||||
|
@req.headers = {}
|
||||||
|
@GeoIpLookup.getCurrencyCode.callsArgWith(1, null, @stubbedCurrencyCode)
|
||||||
|
|
||||||
describe "with a user without a subscription", ->
|
describe "with a user without a subscription", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@LimitationsManager.userHasSubscription.callsArgWith(1, null, false)
|
@LimitationsManager.userHasSubscription.callsArgWith(1, null, false)
|
||||||
|
@ -158,6 +162,34 @@ describe "SubscriptionController sanboxed", ->
|
||||||
done()
|
done()
|
||||||
@SubscriptionController.paymentPage(@req, @res)
|
@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", ->
|
describe "successful_subscription", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel.callsArgWith(1, null, {})
|
@SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel.callsArgWith(1, null, {})
|
||||||
|
|
Loading…
Reference in a new issue