From 98cefaa5bd8af9351b6fbcf3bf8ebbda225dfe03 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Tue, 23 Apr 2024 09:30:29 +0100 Subject: [PATCH] Remove "upgrade to annual" page (#18014) GitOrigin-RevId: b9f92ad038adab7fc7eb5e2a7175461bfefee379 --- .../Subscription/SubscriptionController.js | 60 ------------ .../Subscription/SubscriptionRouter.js | 13 --- .../views/subscriptions/upgradeToAnnual.pug | 24 ----- services/web/frontend/js/main.js | 1 - .../web/frontend/js/main/annual-upgrade.js | 48 ---------- services/web/locales/en.json | 3 - .../SubscriptionControllerTests.js | 96 ------------------- 7 files changed, 245 deletions(-) delete mode 100644 services/web/app/views/subscriptions/upgradeToAnnual.pug delete mode 100644 services/web/frontend/js/main/annual-upgrade.js diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index 3b6405cff1..955a96effe 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionController.js @@ -488,64 +488,6 @@ function recurlyCallback(req, res, next) { } } -function renderUpgradeToAnnualPlanPage(req, res, next) { - const user = SessionManager.getSessionUser(req.session) - LimitationsManager.userHasV2Subscription( - user, - function (err, hasSubscription, subscription) { - let planName - if (err) { - return next(err) - } - const planCode = subscription - ? subscription.planCode.toLowerCase() - : undefined - if ((planCode ? planCode.indexOf('annual') : undefined) !== -1) { - planName = 'annual' - } else if ((planCode ? planCode.indexOf('student') : undefined) !== -1) { - planName = 'student' - } else if ( - (planCode ? planCode.indexOf('collaborator') : undefined) !== -1 - ) { - planName = 'collaborator' - } - if (hasSubscription) { - res.render('subscriptions/upgradeToAnnual', { - title: 'Upgrade to annual', - planName, - }) - } else { - res.redirect('/user/subscription/plans') - } - } - ) -} - -function processUpgradeToAnnualPlan(req, res, next) { - const user = SessionManager.getSessionUser(req.session) - const { planName } = req.body - const couponCode = Settings.coupon_codes.upgradeToAnnualPromo[planName] - const annualPlanName = `${planName}-annual` - logger.debug( - { userId: user._id, planName: annualPlanName }, - 'user is upgrading to annual billing with discount' - ) - return SubscriptionHandler.updateSubscription( - user, - annualPlanName, - couponCode, - function (err) { - if (err) { - OError.tag(err, 'error updating subscription', { - user_id: user._id, - }) - return next(err) - } - res.sendStatus(200) - } - ) -} - async function extendTrial(req, res) { const user = SessionManager.getSessionUser(req.session) const { subscription } = @@ -684,8 +626,6 @@ module.exports = { updateAccountEmailAddress, reactivateSubscription, recurlyCallback, - renderUpgradeToAnnualPlanPage, - processUpgradeToAnnualPlan, extendTrial: expressify(extendTrial), recurlyNotificationParser, refreshUserFeatures: expressify(refreshUserFeatures), diff --git a/services/web/app/src/Features/Subscription/SubscriptionRouter.js b/services/web/app/src/Features/Subscription/SubscriptionRouter.js index b0cd52a9e8..a6bd5459f2 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionRouter.js +++ b/services/web/app/src/Features/Subscription/SubscriptionRouter.js @@ -147,19 +147,6 @@ module.exports = { SubscriptionController.extendTrial ) - webRouter.get( - '/user/subscription/upgrade-annual', - AuthenticationController.requireLogin(), - RateLimiterMiddleware.rateLimit(subscriptionRateLimiter), - SubscriptionController.renderUpgradeToAnnualPlanPage - ) - webRouter.post( - '/user/subscription/upgrade-annual', - AuthenticationController.requireLogin(), - RateLimiterMiddleware.rateLimit(subscriptionRateLimiter), - SubscriptionController.processUpgradeToAnnualPlan - ) - webRouter.post( '/user/subscription/account/email', AuthenticationController.requireLogin(), diff --git a/services/web/app/views/subscriptions/upgradeToAnnual.pug b/services/web/app/views/subscriptions/upgradeToAnnual.pug deleted file mode 100644 index 55d6fb1934..0000000000 --- a/services/web/app/views/subscriptions/upgradeToAnnual.pug +++ /dev/null @@ -1,24 +0,0 @@ -extends ../layout - -block content - - main.content.content-alt#main-content - .container(ng-controller="AnnualUpgradeController") - .row(ng-cloak) - .col-md-6.col-md-offset-3 - .card(ng-init="planName = "+JSON.stringify(planName)) - .page-header - h1.text-centered #{translate("move_to_annual_billing")} - div(ng-hide="upgradeComplete") - .row - div.col-md-12 !{translate("change_to_annual_billing_and_save", {percentage:'20%', yearlySaving:'${{yearlySaving}}'}, ['strong', 'strong'])} - .row   - .row - div.col-md-12 - center - button.btn.btn-primary(ng-click="completeAnnualUpgrade()", ng-disabled="inflight") - span(ng-show="inflight") #{translate("processing")} - span(ng-hide="inflight") #{translate("move_to_annual_billing")} now - - div(ng-show="upgradeComplete") - h3 #{translate("annual_billing_enabled")}, #{translate("thank_you")}. diff --git a/services/web/frontend/js/main.js b/services/web/frontend/js/main.js index f2e3ae2233..7c2c587a97 100644 --- a/services/web/frontend/js/main.js +++ b/services/web/frontend/js/main.js @@ -11,7 +11,6 @@ import './main/token-access' // used in project/token/access import './main/event' // used in various controllers import './main/system-messages' // used in project/editor -import './main/annual-upgrade' // used in subscriptions/upgradeToAnnual import './main/subscription/team-invite-controller' // used in subscriptions/team/invite import './directives/eventTracking' // used in lots of places import './features/cookie-banner' diff --git a/services/web/frontend/js/main/annual-upgrade.js b/services/web/frontend/js/main/annual-upgrade.js deleted file mode 100644 index bac294e779..0000000000 --- a/services/web/frontend/js/main/annual-upgrade.js +++ /dev/null @@ -1,48 +0,0 @@ -/* eslint-disable - max-len, - no-return-assign, -*/ -// TODO: This file was created by bulk-decaffeinate. -// Fix any style issues and re-enable lint. -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ -import App from '../base' -import { debugConsole } from '@/utils/debugging' - -export default App.controller('AnnualUpgradeController', [ - '$scope', - '$http', - function ($scope, $http) { - const MESSAGES_URL = '/user/subscription/upgrade-annual' - - $scope.upgradeComplete = false - const savings = { - student: '19.2', - collaborator: '36', - } - $scope.$watch($scope.planName, function () { - $scope.yearlySaving = savings[$scope.planName] - if ($scope.planName === 'annual') { - return ($scope.upgradeComplete = true) - } - }) - return ($scope.completeAnnualUpgrade = function () { - const body = { - planName: $scope.planName, - _csrf: window.csrfToken, - } - - $scope.inflight = true - - return $http - .post(MESSAGES_URL, body) - .then(() => ($scope.upgradeComplete = true)) - .catch(err => - debugConsole.error('something went wrong changing plan', err) - ) - }) - }, -]) diff --git a/services/web/locales/en.json b/services/web/locales/en.json index 722a1dc0c8..1a1b9e63b2 100644 --- a/services/web/locales/en.json +++ b/services/web/locales/en.json @@ -107,7 +107,6 @@ "an_error_occurred_when_verifying_the_coupon_code": "An error occurred when verifying the coupon code", "and": "and", "annual": "Annual", - "annual_billing_enabled": "Annual billing enabled", "anonymous": "Anonymous", "anyone_with_link_can_edit": "Anyone with this link can edit this project", "anyone_with_link_can_view": "Anyone with this link can view this project", @@ -218,7 +217,6 @@ "change_primary_email_address_instructions": "To change your primary email, please add your new primary email address first (by clicking <0>Add another email) and confirm it. Then click the <0>Make Primary button. <1>Learn more about managing your __appName__ emails.", "change_project_owner": "Change Project Owner", "change_the_ownership_of_your_personal_projects": "Change the ownership of your personal projects to the new account. <0>Find out how to change project owner.", - "change_to_annual_billing_and_save": "Get <0>__percentage__ off with annual billing. If you switch now you’ll save <1>__yearlySaving__ per year.", "change_to_group_plan": "Change to a group plan", "change_to_this_plan": "Change to this plan", "changing_the_position_of_your_figure": "Changing the position of your figure", @@ -1120,7 +1118,6 @@ "more_project_collaborators": "<0>More project <0>collaborators", "more_than_one_kind_of_snippet_was_requested": "The link to open this content on Overleaf included some invalid parameters. If this keeps happening for links on a particular site, please report this to them.", "most_popular": "most popular", - "move_to_annual_billing": "Move to Annual Billing", "must_be_email_address": "Must be an email address", "my_library": "My Library", "n_items": "__count__ item", diff --git a/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js b/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js index df2e184538..6bb124b0d3 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js @@ -695,100 +695,4 @@ describe('SubscriptionController', function () { }) }) }) - - describe('renderUpgradeToAnnualPlanPage', function () { - it('should redirect to the plans page if the user does not have a subscription', function (done) { - this.LimitationsManager.userHasV2Subscription.callsArgWith(1, null, false) - this.res.redirect = function (url) { - url.should.equal('/user/subscription/plans') - done() - } - this.SubscriptionController.renderUpgradeToAnnualPlanPage( - this.req, - this.res - ) - }) - - it('should pass the plan code to the view - student', function (done) { - this.LimitationsManager.userHasV2Subscription.callsArgWith( - 1, - null, - true, - { planCode: 'Student free trial 14 days' } - ) - this.res.render = function (view, opts) { - view.should.equal('subscriptions/upgradeToAnnual') - opts.planName.should.equal('student') - done() - } - this.SubscriptionController.renderUpgradeToAnnualPlanPage( - this.req, - this.res - ) - }) - - it('should pass the plan code to the view - collaborator', function (done) { - this.LimitationsManager.userHasV2Subscription.callsArgWith( - 1, - null, - true, - { planCode: 'free trial for Collaborator free trial 14 days' } - ) - this.res.render = function (view, opts) { - opts.planName.should.equal('collaborator') - done() - } - this.SubscriptionController.renderUpgradeToAnnualPlanPage( - this.req, - this.res - ) - }) - - it('should pass annual as the plan name if the user is already on an annual plan', function (done) { - this.LimitationsManager.userHasV2Subscription.callsArgWith( - 1, - null, - true, - { planCode: 'student annual with free trial' } - ) - this.res.render = function (view, opts) { - opts.planName.should.equal('annual') - done() - } - this.SubscriptionController.renderUpgradeToAnnualPlanPage( - this.req, - this.res - ) - }) - }) - - describe('processUpgradeToAnnualPlan', function () { - beforeEach(function () {}) - - it('should tell the subscription handler to update the subscription with the annual plan and apply a coupon code', function (done) { - this.req.body = { planName: 'student' } - - this.res.sendStatus = () => { - this.SubscriptionHandler.updateSubscription - .calledWith(this.user, 'student-annual', 'STUDENTCODEHERE') - .should.equal(true) - done() - } - - this.SubscriptionController.processUpgradeToAnnualPlan(this.req, this.res) - }) - - it('should get the collaborator coupon code', function (done) { - this.req.body = { planName: 'collaborator' } - - this.res.sendStatus = url => { - this.SubscriptionHandler.updateSubscription - .calledWith(this.user, 'collaborator-annual', 'COLLABORATORCODEHERE') - .should.equal(true) - done() - } - - this.SubscriptionController.processUpgradeToAnnualPlan(this.req, this.res) - }) - }) })