mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-28 00:00:59 +00:00
Merge branch 'sk-use-recurly-hosted-details-page'
This commit is contained in:
commit
c203a8d80a
5 changed files with 47 additions and 101 deletions
|
@ -97,20 +97,39 @@ module.exports = SubscriptionController =
|
|||
logger.log user: user, "redirecting to plans"
|
||||
res.redirect "/user/subscription/plans"
|
||||
else
|
||||
SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel user, (error, subscription, groupSubscriptions) ->
|
||||
return next(error) if error?
|
||||
logger.log user: user, subscription:subscription, hasSubOrIsGroupMember:hasSubOrIsGroupMember, groupSubscriptions:groupSubscriptions, "showing subscription dashboard"
|
||||
plans = SubscriptionViewModelBuilder.buildViewModel()
|
||||
res.render "subscriptions/dashboard",
|
||||
title: "your_subscription"
|
||||
recomendedCurrency: subscription?.currency
|
||||
taxRate:subscription?.taxRate
|
||||
plans: plans
|
||||
subscription: subscription || {}
|
||||
groupSubscriptions: groupSubscriptions
|
||||
subscriptionTabActive: true
|
||||
user:user
|
||||
saved_billing_details: req.query.saved_billing_details?
|
||||
RecurlyWrapper.getSubscription subscription.recurlySubscription_id,
|
||||
includeAccount: true,
|
||||
(err, usersSubscription)->
|
||||
# always render the page, but skip the recurly link if
|
||||
# we can't get it for some reason
|
||||
if err?
|
||||
logger.err {err, userId: user._id}, "error getting billing details link from recurly, proceeding"
|
||||
hostedLoginToken = usersSubscription?.account?.hosted_login_token
|
||||
recurlySubdomain = Settings?.apis?.recurly?.subdomain
|
||||
if err? || !hostedLoginToken || !recurlySubdomain
|
||||
billingDetailsLink = null
|
||||
else
|
||||
billingDetailsLink = [
|
||||
"https://",
|
||||
recurlySubdomain,
|
||||
".recurly.com/account/billing_info/edit?ht=",
|
||||
hostedLoginToken
|
||||
].join("")
|
||||
SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel user, (error, subscription, groupSubscriptions) ->
|
||||
return next(error) if error?
|
||||
logger.log {user, subscription, hasSubOrIsGroupMember, groupSubscriptions, billingDetailsLink}, "showing subscription dashboard"
|
||||
plans = SubscriptionViewModelBuilder.buildViewModel()
|
||||
res.render "subscriptions/dashboard",
|
||||
title: "your_subscription"
|
||||
recomendedCurrency: subscription?.currency
|
||||
taxRate:subscription?.taxRate
|
||||
plans: plans
|
||||
subscription: subscription || {}
|
||||
groupSubscriptions: groupSubscriptions
|
||||
subscriptionTabActive: true
|
||||
user:user
|
||||
saved_billing_details: req.query.saved_billing_details?
|
||||
billingDetailsLink: billingDetailsLink
|
||||
|
||||
userCustomSubscriptionPage: (req, res, next)->
|
||||
user = AuthenticationController.getSessionUser(req)
|
||||
|
@ -124,31 +143,6 @@ module.exports = SubscriptionController =
|
|||
title: "your_subscription"
|
||||
subscription: subscription
|
||||
|
||||
|
||||
editBillingDetailsPage: (req, res, next) ->
|
||||
user = AuthenticationController.getSessionUser(req)
|
||||
LimitationsManager.userHasSubscription user, (err, hasSubscription)->
|
||||
return next(err) if err?
|
||||
if !hasSubscription
|
||||
res.redirect "/user/subscription"
|
||||
else
|
||||
RecurlyWrapper.sign {
|
||||
account_code: user._id
|
||||
}, (error, signature) ->
|
||||
return next(error) if error?
|
||||
res.render "subscriptions/edit-billing-details",
|
||||
title : "update_billing_details"
|
||||
recurlyConfig: JSON.stringify
|
||||
currency: "USD"
|
||||
subdomain: Settings.apis.recurly.subdomain
|
||||
signature : signature
|
||||
successURL : "#{Settings.siteUrl}/user/subscription/billing-details/update"
|
||||
user :
|
||||
id : user._id
|
||||
|
||||
updateBillingDetails: (req, res, next) ->
|
||||
res.redirect "/user/subscription?saved_billing_details=true"
|
||||
|
||||
createSubscription: (req, res, next)->
|
||||
user = AuthenticationController.getSessionUser(req)
|
||||
recurly_token_id = req.body.recurly_token_id
|
||||
|
|
|
@ -15,8 +15,6 @@ module.exports =
|
|||
|
||||
|
||||
webRouter.get '/user/subscription/new', AuthenticationController.requireLogin(), SubscriptionController.paymentPage
|
||||
webRouter.get '/user/subscription/billing-details/edit', AuthenticationController.requireLogin(), SubscriptionController.editBillingDetailsPage
|
||||
webRouter.post '/user/subscription/billing-details/update', AuthenticationController.requireLogin(), SubscriptionController.updateBillingDetails
|
||||
|
||||
webRouter.get '/user/subscription/thank-you', AuthenticationController.requireLogin(), SubscriptionController.successful_subscription
|
||||
|
||||
|
|
|
@ -61,7 +61,10 @@ block content
|
|||
p !{translate("next_payment_of_x_collectected_on_y", {paymentAmmount:"<strong>" + subscription.price + "</strong>", collectionDate:"<strong>" + subscription.nextPaymentDueAt + "</strong>"})}
|
||||
p.pull-right
|
||||
p
|
||||
a(href="/user/subscription/billing-details/edit").btn.btn-info #{translate("update_your_billing_details")}
|
||||
if billingDetailsLink
|
||||
a(href=billingDetailsLink, target="_blank").btn.btn-info #{translate("update_your_billing_details")}
|
||||
else
|
||||
a(href=billingDetailsLink, disabled).btn.btn-info.btn-disabled #{translate("update_your_billing_details")}
|
||||
|
|
||||
a(href, ng-click="switchToCancelationView()").btn.btn-primary !{translate("cancel_your_subscription")}
|
||||
when "canceled"
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
extends ../layout
|
||||
|
||||
block scripts
|
||||
script(src=buildJsPath('libs/recurly.min.js', {fingerprint:false}))
|
||||
|
||||
block content
|
||||
.content.content-alt
|
||||
.container
|
||||
.row
|
||||
.col-md-6.col-md-offset-3
|
||||
.card
|
||||
.page-header
|
||||
h1.text-centered #{translate("update_your_billing_details")}
|
||||
#billingDetailsForm #{translate("loading_billing_form")}...
|
||||
|
||||
|
||||
script(type="text/javascript").
|
||||
Recurly.config(!{recurlyConfig})
|
||||
Recurly.buildBillingInfoUpdateForm({
|
||||
target : "#billingDetailsForm",
|
||||
successURL : "#{successURL}?_csrf=#{csrfToken}&origin=editBillingDetails",
|
||||
signature : "!{signature}",
|
||||
accountCode : "#{user.id}"
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -44,6 +44,7 @@ describe "SubscriptionController", ->
|
|||
|
||||
@RecurlyWrapper =
|
||||
sign: sinon.stub().callsArgWith(1, null, "somthing")
|
||||
getSubscription: sinon.stub().callsArgWith(2, null, {})
|
||||
|
||||
@SubscriptionViewModelBuilder =
|
||||
buildUsersSubscriptionViewModel:sinon.stub().callsArgWith(1, null, @activeRecurlySubscription)
|
||||
|
@ -55,7 +56,7 @@ describe "SubscriptionController", ->
|
|||
collaborator:"COLLABORATORCODEHERE"
|
||||
apis:
|
||||
recurly:
|
||||
subdomain:"sl.recurly.com"
|
||||
subdomain:"sl"
|
||||
siteUrl: "http://de.sharelatex.dev:3000"
|
||||
gaExperiments:{}
|
||||
@GeoIpLookup =
|
||||
|
@ -118,34 +119,6 @@ describe "SubscriptionController", ->
|
|||
@UserGetter.getUser.callCount.should.equal 0
|
||||
done()
|
||||
|
||||
|
||||
describe "editBillingDetailsPage", ->
|
||||
describe "with a user with a subscription", ->
|
||||
beforeEach (done) ->
|
||||
@LimitationsManager.userHasSubscription.callsArgWith(1, null, true)
|
||||
@user._id = @activeRecurlySubscription.account.account_code
|
||||
@res.callback = done
|
||||
@SubscriptionController.editBillingDetailsPage(@req, @res)
|
||||
|
||||
it "should render the edit billing details page", ->
|
||||
@res.rendered.should.equal true
|
||||
@res.renderedTemplate.should.equal "subscriptions/edit-billing-details"
|
||||
|
||||
it "should set the correct variables for the template", ->
|
||||
should.exist @res.renderedVariables.signature
|
||||
@res.renderedVariables.successURL.should.equal "#{@settings.siteUrl}/user/subscription/billing-details/update"
|
||||
@res.renderedVariables.user.id.should.equal @user._id
|
||||
|
||||
describe "with a user without subscription", ->
|
||||
beforeEach (done) ->
|
||||
@res.callback = done
|
||||
@LimitationsManager.userHasSubscription.callsArgWith(1, null, false)
|
||||
@SubscriptionController.reactivateSubscription @req, @res
|
||||
|
||||
it "should redirect to the subscription dashboard", ->
|
||||
@res.redirected.should.equal true
|
||||
@res.redirectedTo.should.equal "/user/subscription"
|
||||
|
||||
describe "paymentPage", ->
|
||||
beforeEach ->
|
||||
@req.headers = {}
|
||||
|
@ -255,7 +228,12 @@ describe "SubscriptionController", ->
|
|||
describe "with an existing subscription", ->
|
||||
beforeEach (done)->
|
||||
@res.callback = done
|
||||
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, true)
|
||||
@settings.apis.recurly.subdomain = 'test'
|
||||
@userSub = {account: {hosted_login_token: 'abcd'}}
|
||||
@RecurlyWrapper.getSubscription = sinon.stub()
|
||||
.callsArgWith(2, null, @userSub)
|
||||
@LimitationsManager.userHasSubscriptionOrIsGroupMember
|
||||
.callsArgWith(1, null, true, {})
|
||||
@SubscriptionController.userSubscriptionPage @req, @res
|
||||
|
||||
|
||||
|
@ -266,7 +244,7 @@ describe "SubscriptionController", ->
|
|||
beforeEach (done) ->
|
||||
@res.callback = done
|
||||
@SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel.callsArgWith(1, null, @activeRecurlySubscription)
|
||||
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, true)
|
||||
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, true, {})
|
||||
@SubscriptionController.userSubscriptionPage @req, @res
|
||||
|
||||
it "should render the dashboard", (done)->
|
||||
|
@ -281,7 +259,7 @@ describe "SubscriptionController", ->
|
|||
beforeEach (done) ->
|
||||
@res.callback = done
|
||||
@SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel.callsArgWith(1, null, @activeRecurlySubscription)
|
||||
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, true)
|
||||
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, true, {})
|
||||
@SubscriptionController.userSubscriptionPage @req, @res
|
||||
|
||||
it "should render the dashboard", ->
|
||||
|
|
Loading…
Reference in a new issue