Move the recurly-billing-details link up to main subscription page

This commit is contained in:
Shane Kilkelly 2017-11-28 11:40:48 +00:00
parent c121653dc4
commit 22c163c60a
3 changed files with 46 additions and 18 deletions

View file

@ -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)

View file

@ -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")}
| &nbsp;
a(href, ng-click="switchToCancelationView()").btn.btn-primary !{translate("cancel_your_subscription")}
when "canceled"

View file

@ -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)
@ -262,7 +263,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
@ -273,7 +279,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)->
@ -288,7 +294,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", ->