Send user to hosted recurly billing-details page.

And remove our update-billing-details form, the APIs for which will be
deprecated soon.
This commit is contained in:
Shane Kilkelly
2017-11-23 16:16:13 +00:00
parent e2b1ced267
commit caa65dddc1
3 changed files with 38 additions and 34 deletions
@@ -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"
@@ -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')}