mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -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?
|
||||
res.redirect "/user/subscription"
|
||||
else
|
||||
currency = req.query.currency || "USD"
|
||||
RecurlyWrapper.sign {
|
||||
subscription:
|
||||
plan_code : req.query.planCode
|
||||
currency: currency
|
||||
account_code: user.id
|
||||
}, (error, signature) ->
|
||||
return next(error) if error?
|
||||
res.render "subscriptions/new",
|
||||
title : "subscribe"
|
||||
plan_code: req.query.planCode
|
||||
recurlyConfig: JSON.stringify
|
||||
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
|
||||
currency: currency
|
||||
subdomain: Settings.apis.recurly.subdomain
|
||||
subscriptionFormOptions: JSON.stringify
|
||||
acceptedCards: ['discover', 'mastercard', 'visa']
|
||||
target : "#subscribeForm"
|
||||
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
|
||||
account_code: user.id
|
||||
}, (error, signature) ->
|
||||
return next(error) if error?
|
||||
res.render "subscriptions/new",
|
||||
title : "subscribe"
|
||||
plan_code: req.query.planCode
|
||||
currency: currency
|
||||
recurlyConfig: JSON.stringify
|
||||
currency: currency
|
||||
subdomain: Settings.apis.recurly.subdomain
|
||||
subscriptionFormOptions: JSON.stringify
|
||||
acceptedCards: ['discover', 'mastercard', 'visa']
|
||||
target : "#subscribeForm"
|
||||
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) ->
|
||||
|
|
|
@ -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