From aafdeb031e63303b6baed92c6c0c92968a3303f6 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 8 Dec 2015 18:23:28 +0000 Subject: [PATCH] wip - downgrade options it all works, need unit tests & translations --- .../Subscription/RecurlyWrapper.coffee | 12 ++++++ .../SubscriptionController.coffee | 8 ++++ .../Subscription/SubscriptionHandler.coffee | 4 +- .../Subscription/SubscriptionRouter.coffee | 1 + .../SubscriptionViewModelBuilder.coffee | 1 + .../app/views/subscriptions/dashboard.jade | 42 ++++++++++++++----- .../coffee/main/subscription-dashboard.coffee | 37 +++++++++++++++- 7 files changed, 92 insertions(+), 13 deletions(-) diff --git a/services/web/app/coffee/Features/Subscription/RecurlyWrapper.coffee b/services/web/app/coffee/Features/Subscription/RecurlyWrapper.coffee index ed7813d5c7..680905ca6c 100644 --- a/services/web/app/coffee/Features/Subscription/RecurlyWrapper.coffee +++ b/services/web/app/coffee/Features/Subscription/RecurlyWrapper.coffee @@ -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) -> diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee index 4fbd84a6ac..8133e6d565 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee @@ -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 = "" diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionHandler.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionHandler.coffee index 7fa43f4270..2396dca07b 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionHandler.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionHandler.coffee @@ -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 diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionRouter.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionRouter.coffee index 76dded3f4d..39eb53ad15 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionRouter.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionRouter.coffee @@ -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 diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionViewModelBuilder.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionViewModelBuilder.coffee index 714396b1f5..bdb9c41fde 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionViewModelBuilder.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionViewModelBuilder.coffee @@ -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 diff --git a/services/web/app/views/subscriptions/dashboard.jade b/services/web/app/views/subscriptions/dashboard.jade index d85be3f9e3..ab9f6fff6b 100644 --- a/services/web/app/views/subscriptions/dashboard.jade +++ b/services/web/app/views/subscriptions/dashboard.jade @@ -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:"" + subscription.name + ""})} p !{translate("subscription_canceled_and_terminate_on_x", {terminateDate:"" + subscription.nextPaymentDueAt + ""})} @@ -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 + |   + 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 + |   + 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 + |   + 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') diff --git a/services/web/public/coffee/main/subscription-dashboard.coffee b/services/web/public/coffee/main/subscription-dashboard.coffee index 02c2fbdf5a..83dfd6bfcd 100644 --- a/services/web/public/coffee/main/subscription-dashboard.coffee +++ b/services/web/public/coffee/main/subscription-dashboard.coffee @@ -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" \ No newline at end of file + $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" + + +