2020-06-23 04:45:38 -04:00
|
|
|
import _ from 'lodash'
|
2020-05-12 10:23:53 -04:00
|
|
|
/* global recurly */
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// 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
|
|
|
|
* DS104: Avoid inline assignments
|
|
|
|
* DS204: Change includes calls to have a more natural evaluation order
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../base'
|
2021-04-15 10:23:12 -04:00
|
|
|
import getMeta from '../utils/meta'
|
2020-05-19 05:02:56 -04:00
|
|
|
const SUBSCRIPTION_URL = '/user/subscription/update'
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2022-01-11 09:57:03 -05:00
|
|
|
const GROUP_PLAN_MODAL_OPTIONS = getMeta('ol-groupPlanModalOptions')
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const ensureRecurlyIsSetup = _.once(() => {
|
|
|
|
if (typeof recurly === 'undefined' || !recurly) {
|
|
|
|
return false
|
|
|
|
}
|
2021-04-15 10:23:12 -04:00
|
|
|
recurly.configure(getMeta('ol-recurlyApiKey'))
|
2020-05-19 05:02:56 -04:00
|
|
|
return true
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2022-01-11 10:08:57 -05:00
|
|
|
function getPricePerUser(price, currencySymbol, size) {
|
|
|
|
let perUserPrice = price / size
|
|
|
|
if (perUserPrice % 1 !== 0) {
|
|
|
|
perUserPrice = perUserPrice.toFixed(2)
|
|
|
|
}
|
|
|
|
return `${currencySymbol}${perUserPrice}`
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller('MetricsEmailController', function ($scope, $http) {
|
|
|
|
$scope.institutionEmailSubscription = function (institutionId) {
|
2021-10-26 04:08:56 -04:00
|
|
|
const inst = _.find(window.managedInstitutions, function (institution) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return institution.v1Id === parseInt(institutionId)
|
|
|
|
})
|
|
|
|
if (inst.metricsEmail.optedOutUserIds.includes(window.user_id)) {
|
|
|
|
return 'Subscribe'
|
|
|
|
} else {
|
|
|
|
return 'Unsubscribe'
|
2019-03-01 09:44:00 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2019-03-01 09:44:00 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.changeInstitutionalEmailSubscription = function (institutionId) {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.subscriptionChanging = true
|
|
|
|
return $http({
|
|
|
|
method: 'POST',
|
|
|
|
url: `/institutions/${institutionId}/emailSubscription`,
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-CSRF-Token': window.csrfToken,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}).then(function successCallback(response) {
|
2021-04-14 09:17:21 -04:00
|
|
|
window.managedInstitutions = _.map(
|
|
|
|
window.managedInstitutions,
|
|
|
|
function (institution) {
|
|
|
|
if (institution.v1Id === parseInt(institutionId)) {
|
|
|
|
institution.metricsEmail.optedOutUserIds = response.data
|
|
|
|
}
|
|
|
|
return institution
|
2019-03-01 09:44:00 -05:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
)
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.subscriptionChanging = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2019-03-01 09:44:00 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.factory('RecurlyPricing', function ($q, MultiCurrencyPricing) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return {
|
2021-04-14 09:17:21 -04:00
|
|
|
loadDisplayPriceWithTax: function (planCode, currency, taxRate) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (!ensureRecurlyIsSetup()) return
|
|
|
|
const currencySymbol = MultiCurrencyPricing.plans[currency].symbol
|
|
|
|
const pricing = recurly.Pricing()
|
2021-04-14 09:17:21 -04:00
|
|
|
return $q(function (resolve, reject) {
|
2020-05-19 05:02:56 -04:00
|
|
|
pricing
|
|
|
|
.plan(planCode, { quantity: 1 })
|
|
|
|
.currency(currency)
|
2021-04-14 09:17:21 -04:00
|
|
|
.done(function (price) {
|
2020-05-19 05:02:56 -04:00
|
|
|
const totalPriceExTax = parseFloat(price.next.total)
|
2021-10-28 09:00:22 -04:00
|
|
|
let taxAmount = totalPriceExTax * taxRate
|
|
|
|
if (isNaN(taxAmount)) {
|
|
|
|
taxAmount = 0
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2021-10-28 09:00:22 -04:00
|
|
|
let total = totalPriceExTax + taxAmount
|
2020-05-19 05:02:56 -04:00
|
|
|
if (total % 1 !== 0) {
|
|
|
|
total = total.toFixed(2)
|
|
|
|
}
|
2021-10-28 09:00:22 -04:00
|
|
|
resolve({
|
|
|
|
total: `${currencySymbol}${total}`,
|
2022-01-11 10:08:57 -05:00
|
|
|
totalValue: total,
|
2021-10-28 09:00:22 -04:00
|
|
|
subtotal: `${currencySymbol}${totalPriceExTax.toFixed(2)}`,
|
|
|
|
tax: `${currencySymbol}${taxAmount.toFixed(2)}`,
|
|
|
|
includesTax: taxAmount !== 0,
|
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
})
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-09-14 08:18:37 -04:00
|
|
|
App.controller('ChangePlanToGroupFormController', function ($scope, $modal) {
|
|
|
|
if (!ensureRecurlyIsSetup()) return
|
|
|
|
|
|
|
|
const subscription = getMeta('ol-subscription')
|
|
|
|
const currency = subscription.recurly.currency
|
|
|
|
|
2022-01-11 09:57:03 -05:00
|
|
|
const validCurrencies = GROUP_PLAN_MODAL_OPTIONS.currencies.map(
|
|
|
|
item => item.code
|
|
|
|
)
|
|
|
|
|
|
|
|
if (validCurrencies.includes(currency)) {
|
2021-09-14 08:18:37 -04:00
|
|
|
$scope.isValidCurrencyForUpgrade = true
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.openGroupPlanModal = function () {
|
|
|
|
const planCode = subscription.plan.planCode
|
|
|
|
$scope.defaultGroupPlan = planCode.includes('professional')
|
|
|
|
? 'professional'
|
|
|
|
: 'collaborator'
|
|
|
|
$scope.currentPlanCurrency = currency
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: 'groupPlanModalUpgradeTemplate',
|
|
|
|
controller: 'GroupPlansModalUpgradeController',
|
|
|
|
scope: $scope,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
App.controller(
|
|
|
|
'GroupPlansModalUpgradeController',
|
2021-10-28 09:00:22 -04:00
|
|
|
function ($scope, $modal, $location, $http, RecurlyPricing) {
|
2022-01-11 09:57:03 -05:00
|
|
|
$scope.options = GROUP_PLAN_MODAL_OPTIONS
|
2021-09-14 08:18:37 -04:00
|
|
|
|
2022-01-12 04:48:02 -05:00
|
|
|
$scope.groupPlans = getMeta('ol-groupPlans')
|
2021-09-14 08:18:37 -04:00
|
|
|
|
|
|
|
const currency = $scope.currentPlanCurrency
|
|
|
|
|
|
|
|
// default selected
|
|
|
|
$scope.selected = {
|
|
|
|
plan_code: $scope.defaultGroupPlan || 'collaborator',
|
|
|
|
currency,
|
|
|
|
size: '10',
|
|
|
|
usage: 'enterprise',
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.recalculatePrice = function () {
|
2021-10-28 09:00:22 -04:00
|
|
|
const subscription = getMeta('ol-subscription')
|
|
|
|
const { taxRate } = subscription.recurly
|
2021-09-14 08:18:37 -04:00
|
|
|
const { usage, plan_code, currency, size } = $scope.selected
|
2022-01-11 10:08:57 -05:00
|
|
|
$scope.discountEligible = size >= 10
|
2022-01-12 04:41:39 -05:00
|
|
|
const recurlyPricePlaceholder = { total: '...' }
|
|
|
|
let perUserDisplayPricePlaceholder = '...'
|
2022-01-11 10:08:57 -05:00
|
|
|
const currencySymbol = $scope.options.currencySymbols[currency]
|
2021-10-28 09:00:22 -04:00
|
|
|
if (taxRate === 0) {
|
2022-01-12 04:48:02 -05:00
|
|
|
const basePrice = $scope.groupPlans[usage][plan_code][currency][size]
|
2022-01-12 04:41:39 -05:00
|
|
|
recurlyPricePlaceholder.total = `${currencySymbol}${basePrice}`
|
|
|
|
perUserDisplayPricePlaceholder = getPricePerUser(
|
2022-01-11 10:08:57 -05:00
|
|
|
basePrice,
|
|
|
|
currencySymbol,
|
|
|
|
size
|
|
|
|
)
|
2021-10-28 09:00:22 -04:00
|
|
|
}
|
2022-01-12 04:41:39 -05:00
|
|
|
$scope.recurlyPrice = recurlyPricePlaceholder // Placeholder while we talk to recurly
|
|
|
|
$scope.perUserDisplayPrice = perUserDisplayPricePlaceholder // Placeholder while we talk to recurly
|
2021-10-28 09:00:22 -04:00
|
|
|
const recurlyPlanCode = `group_${plan_code}_${size}_${usage}`
|
|
|
|
RecurlyPricing.loadDisplayPriceWithTax(
|
|
|
|
recurlyPlanCode,
|
|
|
|
currency,
|
|
|
|
taxRate
|
|
|
|
).then(price => {
|
2022-01-12 04:41:39 -05:00
|
|
|
$scope.recurlyPrice = price
|
|
|
|
$scope.perUserDisplayPrice = getPricePerUser(
|
2022-01-11 10:08:57 -05:00
|
|
|
price.totalValue,
|
|
|
|
currencySymbol,
|
|
|
|
size
|
|
|
|
)
|
2021-10-28 09:00:22 -04:00
|
|
|
})
|
2021-09-14 08:18:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.$watch('selected', $scope.recalculatePrice, true)
|
|
|
|
$scope.recalculatePrice()
|
|
|
|
|
|
|
|
$scope.upgrade = function () {
|
|
|
|
const { plan_code, size, usage } = $scope.selected
|
|
|
|
const body = {
|
|
|
|
_csrf: window.csrfToken,
|
|
|
|
plan_code: `group_${plan_code}_${size}_${usage}`,
|
|
|
|
}
|
|
|
|
$scope.inflight = true
|
|
|
|
$http
|
|
|
|
.post(`/user/subscription/update`, body)
|
|
|
|
.then(() => location.reload())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller(
|
|
|
|
'ChangePlanFormController',
|
|
|
|
function ($scope, $modal, RecurlyPricing) {
|
|
|
|
if (!ensureRecurlyIsSetup()) return
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.changePlan = () =>
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: 'confirmChangePlanModalTemplate',
|
|
|
|
controller: 'ConfirmChangePlanController',
|
2021-04-27 03:52:58 -04:00
|
|
|
scope: $scope,
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
|
|
|
|
2021-04-27 10:17:39 -04:00
|
|
|
$scope.cancelPendingPlanChange = () =>
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: 'cancelPendingPlanChangeModalTemplate',
|
|
|
|
controller: 'CancelPendingPlanChangeController',
|
|
|
|
scope: $scope,
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.$watch('plan', function (plan) {
|
|
|
|
if (!plan) return
|
2021-04-27 10:17:39 -04:00
|
|
|
const planCodesChangingAtTermEnd = getMeta(
|
|
|
|
'ol-planCodesChangingAtTermEnd'
|
|
|
|
)
|
|
|
|
$scope.planChangesAtTermEnd = false
|
|
|
|
if (
|
|
|
|
planCodesChangingAtTermEnd &&
|
|
|
|
planCodesChangingAtTermEnd.indexOf(plan.planCode) > -1
|
|
|
|
) {
|
|
|
|
$scope.planChangesAtTermEnd = true
|
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
const planCode = plan.planCode
|
2021-04-15 10:23:12 -04:00
|
|
|
const subscription = getMeta('ol-subscription')
|
|
|
|
const { currency, taxRate } = subscription.recurly
|
2022-01-12 04:41:39 -05:00
|
|
|
$scope.displayPrice = '...' // Placeholder while we talk to recurly
|
2021-04-14 09:17:21 -04:00
|
|
|
RecurlyPricing.loadDisplayPriceWithTax(planCode, currency, taxRate).then(
|
2022-01-12 04:41:39 -05:00
|
|
|
recurlyPrice => {
|
|
|
|
$scope.displayPrice = recurlyPrice.total
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller(
|
|
|
|
'ConfirmChangePlanController',
|
|
|
|
function ($scope, $modalInstance, $http) {
|
|
|
|
$scope.confirmChangePlan = function () {
|
|
|
|
const body = {
|
|
|
|
plan_code: $scope.plan.planCode,
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-05-17 10:19:48 -04:00
|
|
|
$scope.genericError = false
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.inflight = true
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
return $http
|
|
|
|
.post(`${SUBSCRIPTION_URL}?origin=confirmChangePlan`, body)
|
|
|
|
.then(() => location.reload())
|
2021-05-17 10:19:48 -04:00
|
|
|
.catch(() => {
|
|
|
|
$scope.genericError = true
|
|
|
|
$scope.inflight = false
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-27 10:17:39 -04:00
|
|
|
return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
App.controller(
|
|
|
|
'CancelPendingPlanChangeController',
|
|
|
|
function ($scope, $modalInstance, $http) {
|
|
|
|
$scope.confirmCancelPendingPlanChange = function () {
|
|
|
|
const body = {
|
|
|
|
_csrf: window.csrfToken,
|
|
|
|
}
|
|
|
|
|
2021-05-17 10:19:48 -04:00
|
|
|
$scope.genericError = false
|
2021-04-27 10:17:39 -04:00
|
|
|
$scope.inflight = true
|
|
|
|
|
|
|
|
return $http
|
|
|
|
.post('/user/subscription/cancel-pending', body)
|
|
|
|
.then(() => location.reload())
|
2021-05-17 10:19:48 -04:00
|
|
|
.catch(() => {
|
|
|
|
$scope.genericError = true
|
|
|
|
$scope.inflight = false
|
|
|
|
})
|
2021-04-27 10:17:39 -04:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller(
|
|
|
|
'LeaveGroupModalController',
|
|
|
|
function ($scope, $modalInstance, $http) {
|
|
|
|
$scope.confirmLeaveGroup = function () {
|
|
|
|
$scope.inflight = true
|
|
|
|
return $http({
|
|
|
|
url: '/subscription/group/user',
|
|
|
|
method: 'DELETE',
|
|
|
|
params: {
|
|
|
|
subscriptionId: $scope.subscriptionId,
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
|
|
|
},
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
|
|
|
.then(() => location.reload())
|
|
|
|
.catch(() => console.log('something went wrong changing plan'))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller('GroupMembershipController', function ($scope, $modal) {
|
|
|
|
$scope.removeSelfFromGroup = function (subscriptionId) {
|
2020-08-12 10:17:15 -04:00
|
|
|
$scope.subscriptionId = subscriptionId
|
2020-05-19 05:02:56 -04:00
|
|
|
return $modal.open({
|
|
|
|
templateUrl: 'LeaveGroupModalTemplate',
|
|
|
|
controller: 'LeaveGroupModalController',
|
2021-04-27 03:52:58 -04:00
|
|
|
scope: $scope,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2018-11-19 10:44:51 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller('RecurlySubscriptionController', function ($scope) {
|
2020-05-19 05:02:56 -04:00
|
|
|
const recurlyIsSetup = ensureRecurlyIsSetup()
|
2021-04-15 10:23:12 -04:00
|
|
|
const subscription = getMeta('ol-subscription')
|
|
|
|
$scope.showChangePlanButton = recurlyIsSetup && !subscription.groupPlan
|
2021-03-30 11:40:00 -04:00
|
|
|
if (
|
2021-04-08 14:48:16 -04:00
|
|
|
window.subscription.recurly.account.has_past_due_invoice &&
|
|
|
|
window.subscription.recurly.account.has_past_due_invoice._ === 'true'
|
2021-03-30 11:40:00 -04:00
|
|
|
) {
|
|
|
|
$scope.showChangePlanButton = false
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.recurlyLoadError = !recurlyIsSetup
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.switchToDefaultView = () => {
|
|
|
|
$scope.showCancellation = false
|
|
|
|
$scope.showChangePlan = false
|
|
|
|
}
|
|
|
|
$scope.switchToDefaultView()
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.switchToCancellationView = () => {
|
|
|
|
$scope.showCancellation = true
|
|
|
|
$scope.showChangePlan = false
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.switchToChangePlanView = () => {
|
|
|
|
$scope.showCancellation = false
|
|
|
|
$scope.showChangePlan = true
|
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller(
|
|
|
|
'RecurlyCancellationController',
|
|
|
|
function ($scope, RecurlyPricing, $http) {
|
|
|
|
if (!ensureRecurlyIsSetup()) return
|
2021-04-15 10:23:12 -04:00
|
|
|
const subscription = getMeta('ol-subscription')
|
2021-04-14 09:17:21 -04:00
|
|
|
const sevenDaysTime = new Date()
|
|
|
|
sevenDaysTime.setDate(sevenDaysTime.getDate() + 7)
|
|
|
|
const freeTrialEndDate = new Date(subscription.recurly.trial_ends_at)
|
|
|
|
const freeTrialInFuture = freeTrialEndDate > new Date()
|
|
|
|
const freeTrialExpiresUnderSevenDays = freeTrialEndDate < sevenDaysTime
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const isMonthlyCollab =
|
|
|
|
subscription.plan.planCode.indexOf('collaborator') !== -1 &&
|
|
|
|
subscription.plan.planCode.indexOf('ann') === -1 &&
|
|
|
|
!subscription.groupPlan
|
|
|
|
const stillInFreeTrial = freeTrialInFuture && freeTrialExpiresUnderSevenDays
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
if (isMonthlyCollab && stillInFreeTrial) {
|
|
|
|
$scope.showExtendFreeTrial = true
|
|
|
|
} else if (isMonthlyCollab && !stillInFreeTrial) {
|
|
|
|
$scope.showDowngradeToStudent = true
|
|
|
|
} else {
|
|
|
|
$scope.showBasicCancel = true
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-15 10:23:12 -04:00
|
|
|
const { currency, taxRate } = subscription.recurly
|
2022-01-12 04:41:39 -05:00
|
|
|
$scope.studentDisplayPrice = '...' // Placeholder while we talk to recurly
|
2021-04-14 09:17:21 -04:00
|
|
|
RecurlyPricing.loadDisplayPriceWithTax('student', currency, taxRate).then(
|
|
|
|
price => {
|
2022-01-12 04:41:39 -05:00
|
|
|
$scope.studentDisplayPrice = price.total
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.downgradeToStudent = function () {
|
|
|
|
const body = {
|
|
|
|
plan_code: 'student',
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
2021-04-14 09:17:21 -04:00
|
|
|
}
|
|
|
|
$scope.inflight = true
|
|
|
|
return $http
|
|
|
|
.post(`${SUBSCRIPTION_URL}?origin=downgradeToStudent`, body)
|
|
|
|
.then(() => location.reload())
|
|
|
|
.catch(() => console.log('something went wrong changing plan'))
|
2018-11-19 10:44:51 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.cancelSubscription = function () {
|
|
|
|
const body = { _csrf: window.csrfToken }
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.inflight = true
|
|
|
|
return $http
|
|
|
|
.post('/user/subscription/cancel', body)
|
|
|
|
.then(() => (location.href = '/user/subscription/canceled'))
|
|
|
|
.catch(() => console.log('something went wrong changing plan'))
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.extendTrial = function () {
|
|
|
|
const body = { _csrf: window.csrfToken }
|
|
|
|
$scope.inflight = true
|
|
|
|
return $http
|
|
|
|
.put('/user/subscription/extend', body)
|
|
|
|
.then(() => location.reload())
|
|
|
|
.catch(() => console.log('something went wrong changing plan'))
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
)
|