hooked the plans page up to the geo ip lookup
This commit is contained in:
@@ -7,7 +7,7 @@ LimitationsManager = require("./LimitationsManager")
|
||||
RecurlyWrapper = require './RecurlyWrapper'
|
||||
Settings = require 'settings-sharelatex'
|
||||
logger = require('logger-sharelatex')
|
||||
|
||||
GeoIpLookup = require("../../infrastructure/GeoIpLookup")
|
||||
|
||||
|
||||
module.exports = SubscriptionController =
|
||||
@@ -22,11 +22,13 @@ module.exports = SubscriptionController =
|
||||
if req.query.v?
|
||||
viewName = "#{viewName}_#{req.query.v}"
|
||||
logger.log viewName:viewName, "showing plans page"
|
||||
res.render viewName,
|
||||
title: "plans_and_pricing"
|
||||
plans: plans
|
||||
baseUrl: baseUrl
|
||||
gaExperiments: Settings.gaExperiments.plansPage
|
||||
GeoIpLookup.getCurrencyCode req.headers["x-forwarded-for"], (err, recomendedCurrency)->
|
||||
res.render viewName,
|
||||
title: "plans_and_pricing"
|
||||
plans: plans
|
||||
baseUrl: baseUrl
|
||||
gaExperiments: Settings.gaExperiments.plansPage
|
||||
recomendedCurrency:recomendedCurrency
|
||||
|
||||
#get to show the recurly.js page
|
||||
paymentPage: (req, res, next) ->
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
request = require("request")
|
||||
settings = require("settings-sharelatex")
|
||||
_ = require("underscore")
|
||||
logger = require("logger-sharelatex")
|
||||
|
||||
currencyMappings = {
|
||||
"GB":"GBP"
|
||||
@@ -22,16 +23,22 @@ module.exports = GeoIpLookup =
|
||||
e = new Error("no ip passed")
|
||||
return callback(e)
|
||||
ip = ip.trim().split(" ")[0]
|
||||
|
||||
opts =
|
||||
url: "#{settings.apis.geoIpLookup.url}/#{ip}"
|
||||
timeout: 1000
|
||||
request.get opts, (err, ipDetails)->
|
||||
json:true
|
||||
logger.log ip:ip, opts:opts, "getting geo ip details"
|
||||
request.get opts, (err, res, ipDetails)->
|
||||
if err?
|
||||
logger.err err:err, ip:ip, "error getting ip details"
|
||||
callback(err, ipDetails)
|
||||
|
||||
getCurrencyCode : (ip, callback)->
|
||||
GeoIpLookup.getDetails ip, (err, ipDetails)->
|
||||
if err? or !ipDetails?
|
||||
logger.err err:err, ip:ip, "problem getting currencyCode for ip, defaulting to USD"
|
||||
return callback(null, "USD")
|
||||
currencyCode = currencyMappings[ipDetails?.country_code?.toUpperCase()]
|
||||
countryCode = ipDetails?.country_code?.toUpperCase()
|
||||
currencyCode = currencyMappings[countryCode]
|
||||
logger.log ip:ip, currencyCode:currencyCode, ipDetails:ipDetails, "got currencyCode for ip"
|
||||
callback(err, currencyCode)
|
||||
@@ -2,6 +2,7 @@ extends ../layout
|
||||
block scripts
|
||||
script(type='text/javascript').
|
||||
window.recurlyPublicToken = '#{settings.apis.recurly.publicKey}'
|
||||
window.recomendedCurrency = '#{recomendedCurrency}'
|
||||
block content
|
||||
.content-alt
|
||||
.content.plans(ng-controller="PlansController")
|
||||
@@ -9,7 +10,6 @@ block content
|
||||
.row
|
||||
.col-md-12
|
||||
.page-header.centered.plans-header.text-centered
|
||||
|
||||
h1(ng-cloak) #{translate("start_x_day_trial", {len:'{{trial_len}}'})}
|
||||
.row
|
||||
.col-md-8.col-md-offset-2
|
||||
|
||||
@@ -96,7 +96,8 @@ module.exports =
|
||||
privateKey: ""
|
||||
apiKey: ""
|
||||
subdomain: ""
|
||||
|
||||
geoIpLookup:
|
||||
url: "https://freegeoip.net/json/"
|
||||
|
||||
templates:
|
||||
user_id: process.env.TEMPLATES_USER_ID or "5395eb7aad1f29a88756c7f2"
|
||||
|
||||
@@ -5,16 +5,8 @@ define [
|
||||
|
||||
|
||||
App.factory "MultiCurrencyPricing", () ->
|
||||
recurly.configure(window.recurlyPublicToken);
|
||||
|
||||
pricing = recurly.Pricing()
|
||||
window.pricing = pricing
|
||||
|
||||
currencyCode = pricing.items.currency
|
||||
|
||||
pricing.on "set.currency", (currency)->
|
||||
currencyCode = pricing.items.currency
|
||||
|
||||
currencyCode = window.recomendedCurrency
|
||||
|
||||
currencyCode:currencyCode
|
||||
plans:
|
||||
@@ -30,34 +22,35 @@ define [
|
||||
monthly: "$30"
|
||||
annual: "$360"
|
||||
|
||||
# EUR:
|
||||
# symbol: "€"
|
||||
# student:
|
||||
# monthly: "€7"
|
||||
# annual: "€70"
|
||||
# collaborator:
|
||||
# monthly: "€12"
|
||||
# annual: "€144"
|
||||
# professional:
|
||||
# monthly: "€25"
|
||||
# annual: "€300"
|
||||
# GBP:
|
||||
# symbol: "£"
|
||||
# student:
|
||||
# monthly: "£6"
|
||||
# annual: "£60"
|
||||
# collaborator:
|
||||
# monthly: "£10"
|
||||
# annual: "£120"
|
||||
# professional:
|
||||
# monthly: "£22"
|
||||
# annual: "£264"
|
||||
EUR:
|
||||
symbol: "€"
|
||||
student:
|
||||
monthly: "€7"
|
||||
annual: "€70"
|
||||
collaborator:
|
||||
monthly: "€12"
|
||||
annual: "€144"
|
||||
professional:
|
||||
monthly: "€25"
|
||||
annual: "€300"
|
||||
|
||||
GBP:
|
||||
symbol: "£"
|
||||
student:
|
||||
monthly: "£6"
|
||||
annual: "£60"
|
||||
collaborator:
|
||||
monthly: "£10"
|
||||
annual: "£120"
|
||||
professional:
|
||||
monthly: "£22"
|
||||
annual: "£264"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
App.controller "PlansController", ($scope, $modal, event_tracking, abTestManager, MultiCurrencyPricing) ->
|
||||
App.controller "PlansController", ($scope, $modal, event_tracking, abTestManager, MultiCurrencyPricing, $http) ->
|
||||
|
||||
buckets = [
|
||||
{ bucketName:"7d", queryString: "_free_trial_7_days", trial_len:7 }
|
||||
|
||||
@@ -55,6 +55,9 @@ describe "SubscriptionController sanboxed", ->
|
||||
recurly:
|
||||
subdomain:"sl.recurly.com"
|
||||
siteUrl: "http://de.sharelatex.dev:3000"
|
||||
gaExperiments:{}
|
||||
@GeoIpLookup =
|
||||
getCurrencyCode:sinon.stub()
|
||||
|
||||
@SubscriptionController = SandboxedModule.require modulePath, requires:
|
||||
'../../managers/SecurityManager': @SecurityManager
|
||||
@@ -62,6 +65,7 @@ describe "SubscriptionController sanboxed", ->
|
||||
"./PlansLocator": @PlansLocator
|
||||
'./SubscriptionViewModelBuilder': @SubscriptionViewModelBuilder
|
||||
"./LimitationsManager": @LimitationsManager
|
||||
"../../infrastructure/GeoIpLookup":@GeoIpLookup
|
||||
'./RecurlyWrapper': @RecurlyWrapper
|
||||
"logger-sharelatex": log:->
|
||||
"settings-sharelatex": @settings
|
||||
@@ -73,6 +77,21 @@ describe "SubscriptionController sanboxed", ->
|
||||
@req.query =
|
||||
planCode:"123123"
|
||||
|
||||
@stubbedCurrencyCode = "GBP"
|
||||
|
||||
describe "plansPage", ->
|
||||
beforeEach (done) ->
|
||||
@req.headers =
|
||||
"x-forwarded-for" : "1234.3123.3131.333 313.133.445.666 653.5345.5345.534"
|
||||
@GeoIpLookup.getCurrencyCode.callsArgWith(1, null, @stubbedCurrencyCode)
|
||||
@res.callback = done
|
||||
@SubscriptionController.plansPage(@req, @res)
|
||||
|
||||
it "should set the recommended currency from the geoiplookup", (done)->
|
||||
@res.renderedVariables.recomendedCurrency.should.equal(@stubbedCurrencyCode)
|
||||
@GeoIpLookup.getCurrencyCode.calledWith(@req.headers["x-forwarded-for"]).should.equal true
|
||||
done()
|
||||
|
||||
describe "editBillingDetailsPage", ->
|
||||
describe "with a user with a subscription", ->
|
||||
beforeEach (done) ->
|
||||
|
||||
@@ -19,7 +19,9 @@ describe "GeoIpLookup", ->
|
||||
@GeoIpLookup = SandboxedModule.require modulePath, requires:
|
||||
"request": @request
|
||||
"settings-sharelatex":@settings
|
||||
"logger-sharelatex": log:->
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
@ipAddress = "123.456.789.123"
|
||||
|
||||
@stubbedResponse =
|
||||
@@ -37,11 +39,11 @@ describe "GeoIpLookup", ->
|
||||
|
||||
describe "getDetails", ->
|
||||
beforeEach ->
|
||||
@request.get.callsArgWith(1, null, @stubbedResponse)
|
||||
@request.get.callsArgWith(1, null, null, @stubbedResponse)
|
||||
|
||||
it "should request the details using the ip", (done)->
|
||||
@GeoIpLookup.getDetails @ipAddress, (err)=>
|
||||
@request.get.calledWith({url:@settings.apis.geoIpLookup.url+"/"+@ipAddress, timeout:1000}).should.equal true
|
||||
@request.get.calledWith({url:@settings.apis.geoIpLookup.url+"/"+@ipAddress, timeout:1000, json:true}).should.equal true
|
||||
done()
|
||||
|
||||
it "should return the ip details", (done)->
|
||||
@@ -51,7 +53,7 @@ describe "GeoIpLookup", ->
|
||||
|
||||
it "should take the first ip in the string", (done)->
|
||||
@GeoIpLookup.getDetails " #{@ipAddress} 456.312.452.102 432.433.888.234", (err)=>
|
||||
@request.get.calledWith({url:@settings.apis.geoIpLookup.url+"/"+@ipAddress, timeout:1000}).should.equal true
|
||||
@request.get.calledWith({url:@settings.apis.geoIpLookup.url+"/"+@ipAddress, timeout:1000, json:true}).should.equal true
|
||||
done()
|
||||
|
||||
describe "getCurrencyCode", ->
|
||||
|
||||
Reference in New Issue
Block a user