diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee index cc3013a42d..d37e8e02fe 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee @@ -127,24 +127,32 @@ module.exports = SubscriptionController = editBillingDetailsPage: (req, res, next) -> user = AuthenticationController.getSessionUser(req) - LimitationsManager.userHasSubscription user, (err, hasSubscription)-> + LimitationsManager.userHasSubscription user, (err, hasSubscription, subscription)-> 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 + RecurlyWrapper.getSubscription subscription.recurlySubscription_id, + includeAccount: true, + (err, usersSubscription)-> + account = usersSubscription.account + hostedLoginToken = account.hosted_login_token + if !hostedLoginToken + err = new Error('no hosted_login_token on recurly account') + return next(err) + subdomain = Settings?.apis?.recurly?.subdomain + if !subdomain + err = new Error('recurly subdomain not configured') + return next(err) + link = "https://" + + subdomain + + ".recurly.com/account/billing_info/edit?ht=" + + hostedLoginToken + res.render "subscriptions/edit-billing-details", + title: "update_billing_details" + hostedBillingDetailsPageLink: link + user: + id: user._id updateBillingDetails: (req, res, next) -> res.redirect "/user/subscription?saved_billing_details=true" diff --git a/services/web/app/views/subscriptions/edit-billing-details.pug b/services/web/app/views/subscriptions/edit-billing-details.pug index cc41e0a4b9..0b40be7eb7 100644 --- a/services/web/app/views/subscriptions/edit-billing-details.pug +++ b/services/web/app/views/subscriptions/edit-billing-details.pug @@ -1,7 +1,5 @@ extends ../layout -block scripts - script(src=buildJsPath('libs/recurly.min.js', {fingerprint:false})) block content .content.content-alt @@ -11,17 +9,8 @@ block content .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}" - }); - - - + div.text-center + a.btn.btn-primary.btn-lg( + href=hostedBillingDetailsPageLink + target="_blank" + ) #{translate('open_your_billing_details_page')} diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee index b95fba1cdd..428ed58f7a 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee @@ -55,7 +55,7 @@ describe "SubscriptionController", -> collaborator:"COLLABORATORCODEHERE" apis: recurly: - subdomain:"sl.recurly.com" + subdomain:"sl" siteUrl: "http://de.sharelatex.dev:3000" gaExperiments:{} @GeoIpLookup = @@ -122,7 +122,12 @@ describe "SubscriptionController", -> describe "editBillingDetailsPage", -> describe "with a user with a subscription", -> beforeEach (done) -> - @LimitationsManager.userHasSubscription.callsArgWith(1, null, true) + @settings.apis.recurly.subdomain = 'test' + @userSub = {account: {hosted_login_token: 'abcd'}} + @LimitationsManager.userHasSubscription + .callsArgWith(1, null, true, @activeRecurlySubscription) + @RecurlyWrapper.getSubscription = sinon.stub() + .callsArgWith(2, null, @userSub) @user._id = @activeRecurlySubscription.account.account_code @res.callback = done @SubscriptionController.editBillingDetailsPage(@req, @res) @@ -132,8 +137,10 @@ describe "SubscriptionController", -> @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" + should.exist @res.renderedVariables.hostedBillingDetailsPageLink + @res.renderedVariables.hostedBillingDetailsPageLink.should.equal( + "https://test.recurly.com/account/billing_info/edit?ht=abcd" + ) @res.renderedVariables.user.id.should.equal @user._id describe "with a user without subscription", ->