wip - downgrade options it all works, need unit tests & translations

This commit is contained in:
Henry Oswald 2015-12-08 18:23:28 +00:00
parent 8fb1f9e00b
commit aafdeb031e
7 changed files with 92 additions and 13 deletions

View file

@ -247,6 +247,18 @@ module.exports = RecurlyWrapper =
callback(error)
)
extendTrial: (subscriptionId, daysUntilExpire = 7, callback)->
next_renewal_date = new Date()
next_renewal_date.setDate(next_renewal_date.getDate() + daysUntilExpire)
logger.log subscriptionId:subscriptionId, daysUntilExpire:daysUntilExpire, "Exending Free trial for user"
@apiRequest({
url : "/subscriptions/#{subscriptionId}/postpone?next_renewal_date=#{next_renewal_date}&bulk=false"
method : "put"
}, (error, response, responseBody) =>
if error?
logger.err err:error, subscriptionId:subscriptionId, daysUntilExpire:daysUntilExpire, "error exending trial"
callback(error)
)
_parseSubscriptionXml: (xml, callback) ->
@_parseXml xml, (error, data) ->

View file

@ -226,6 +226,14 @@ module.exports = SubscriptionController =
else
res.sendStatus 200
extendTrial: (req, res)->
SecurityManager.getCurrentUser req, (error, user) ->
LimitationsManager.userHasSubscription user, (err, hasSubscription, subscription)->
SubscriptionHandler.extendTrial subscription, 14, (err)->
if err?
res.send 500
else
res.send 200
recurlyNotificationParser: (req, res, next) ->
xml = ""

View file

@ -74,5 +74,5 @@ module.exports =
return callback("no user found")
SubscriptionUpdater.syncSubscription recurlySubscription, user?._id, callback
extendTrial: (subscription, daysToExend, callback)->
RecurlyWrapper.extendTrial subscription.recurlySubscription_id, daysToExend, callback

View file

@ -39,6 +39,7 @@ module.exports =
webRouter.post '/user/subscription/cancel', AuthenticationController.requireLogin(), SubscriptionController.cancelSubscription
webRouter.post '/user/subscription/reactivate', AuthenticationController.requireLogin(), SubscriptionController.reactivateSubscription
webRouter.put '/user/subscription/extend', AuthenticationController.requireLogin(), SubscriptionController.extendTrial
webRouter.get "/user/subscription/upgrade-annual", AuthenticationController.requireLogin(), SubscriptionController.renderUpgradeToAnnualPlanPage
webRouter.post "/user/subscription/upgrade-annual", AuthenticationController.requireLogin(), SubscriptionController.processUpgradeToAnnualPlan

View file

@ -27,6 +27,7 @@ module.exports =
currency:recurlySubscription?.currency
taxRate:parseFloat(recurlySubscription?.tax_rate?._)
groupPlan: subscription.groupPlan
trial_ends_at:recurlySubscription?.trial_ends_at
}, memberSubscriptions
else
callback null, null, memberSubscriptions

View file

@ -39,7 +39,7 @@ block content
.content.content-alt(ng-cloak)
.container(ng-controller="UserSubscriptionController")
.row
.col-md-8.col-md-offset-2 {{view}}
.col-md-8.col-md-offset-2
.card(ng-if="view == 'overview'")
.page-header
h1 #{translate("your_subscription")}
@ -58,8 +58,8 @@ block content
p.pull-right
p
a(href="/user/subscription/billing-details/edit").btn.btn-info #{translate("update_your_billing_details")}
p
a(href, ng-click="switchToCancelationView()").btn.btn-success !{translate("cancel_your_subscription")}
|  
a(href, ng-click="switchToCancelationView()").btn.btn-primary !{translate("cancel_your_subscription")}
when "canceled"
p !{translate("currently_subscribed_to_plan", {planName:"<strong>" + subscription.name + "</strong>"})}
p !{translate("subscription_canceled_and_terminate_on_x", {terminateDate:"<strong>" + subscription.nextPaymentDueAt + "</strong>"})}
@ -108,14 +108,36 @@ block content
.card(ng-if="view == 'cancelation'")
.page-header
h1 #{translate("Cancel Subscription")}
div(ng-show="isMonthlyCollab")
span(ng-controller="ChangePlanFormController") downgrade to student for {{studentPrice}}
button(type="submit", ng-click="downgradeToStudent()", ng-disabled='inflight').btn.btn-success #{translate("change_to_this_plan")}
div(ng-show="isMonthlyCollab && stillInFreeTrial", style="text-align: center")
p Have another
strong 14 days
| on your Trial!
button(type="submit", ng-click="exendTrial()", ng-disabled='inflight').btn.btn-success #{translate("ill_take_it!")}
p
| &nbsp;
p
a(href, ng-click="cancelSubscription()", ng-disabled='inflight') No thanks - I still want to Cancel Now
div(ng-show="isMonthlyCollab && !stillInFreeTrial", style="text-align: center")
span(ng-controller="ChangePlanFormController")
p Would you be interested in the cheaper
strong {{studentPrice}}
| student plan?
button(type="submit", ng-click="downgradeToStudent()", ng-disabled='inflight').btn.btn-success #{translate("yes_please!")}
p
| &nbsp;
p
a(href, ng-click="cancelSubscription()", ng-disabled='inflight') No thanks - I still want to Cancel Now
div(ng-show="!isMonthlyCollab && !stillInFreeTrial")
p Are you sure you want to cancel?
a(href="/project").btn.btn-info I want to stay
| &nbsp;
a(ng-click="cancelSubscription()", ng-disabled='inflight').btn.btn-primary Cancel my account
div(ng-if="!isMonthlyCollab")
form(action="/user/subscription/cancel",method="post")
input(type="hidden", name="_csrf", value=csrfToken)
input(type="submit", value="Cancel your subscription").btn.btn-primary#cancelSubscription
script(type="text/javascript").
$('#cancelSubscription').on("click", function() {
ga('send', 'event', 'subscription-funnel', 'cancelation')

View file

@ -76,8 +76,18 @@ define [
App.controller "UserSubscriptionController", ($scope, MultiCurrencyPricing, $http) ->
freeTrialEndDate = new Date(subscription.trial_ends_at)
sevenDaysTime = new Date()
sevenDaysTime.setDate(sevenDaysTime.getDate() + 7)
freeTrialInFuture = freeTrialEndDate > new Date()
freeTrialExpiresUnderSevenDays = freeTrialEndDate < sevenDaysTime
$scope.view = 'overview'
$scope.isMonthlyCollab = subscription?.planCode?.indexOf("collaborator") != -1 and subscription?.planCode?.indexOf("ann") == -1
$scope.stillInFreeTrial = freeTrialInFuture and freeTrialExpiresUnderSevenDays
setupReturly()
recurly.Pricing().plan('student', { quantity: 1 }).currency(MultiCurrencyPricing.currencyCode).done (price)->
@ -100,6 +110,31 @@ define [
.error ->
console.log "something went wrong changing plan"
$scope.cancelSubscription = ->
body =
_csrf : window.csrfToken
$scope.inflight = true
$http.post("/user/subscription/cancel", body)
.success ->
location.reload()
.error ->
console.log "something went wrong changing plan"
$scope.switchToCancelationView = ->
$scope.view = "cancelation"
$scope.view = "cancelation"
$scope.exendTrial = ->
body =
_csrf : window.csrfToken
$scope.inflight = true
$http.put("/user/subscription/extend", body)
.success ->
location.reload()
.error ->
console.log "something went wrong changing plan"