|
|
@@ -10,47 +10,48 @@
|
|
|
/*
|
|
|
* decaffeinate suggestions:
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
- * DS103: Rewrite code to no longer use __guard__
|
|
|
* 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
|
|
|
*/
|
|
|
define(['base'], function(App) {
|
|
|
- App.controller('SuccessfulSubscriptionController', function(
|
|
|
- $scope,
|
|
|
- sixpack
|
|
|
- ) {})
|
|
|
-
|
|
|
const SUBSCRIPTION_URL = '/user/subscription/update'
|
|
|
|
|
|
- const setupReturly = _.once(
|
|
|
- () =>
|
|
|
- typeof recurly !== 'undefined' && recurly !== null
|
|
|
- ? recurly.configure(window.recurlyApiKey)
|
|
|
- : undefined
|
|
|
- )
|
|
|
- const PRICES = {}
|
|
|
-
|
|
|
- App.controller('CurrenyDropdownController', function(
|
|
|
- $scope,
|
|
|
- MultiCurrencyPricing,
|
|
|
- $q
|
|
|
- ) {
|
|
|
- // $scope.plans = MultiCurrencyPricing.plans
|
|
|
- $scope.currencyCode = MultiCurrencyPricing.currencyCode
|
|
|
+ const ensureRecurlyIsSetup = _.once(() => {
|
|
|
+ if (!recurly) return
|
|
|
+ recurly.configure(window.recurlyApiKey)
|
|
|
+ })
|
|
|
|
|
|
- return ($scope.changeCurrency = newCurrency =>
|
|
|
- (MultiCurrencyPricing.currencyCode = newCurrency))
|
|
|
+ App.factory('RecurlyPricing', function($q, MultiCurrencyPricing) {
|
|
|
+ return {
|
|
|
+ loadDisplayPriceWithTax: function(planCode, currency, taxRate) {
|
|
|
+ ensureRecurlyIsSetup()
|
|
|
+ const currencySymbol = MultiCurrencyPricing.plans[currency].symbol
|
|
|
+ const pricing = recurly.Pricing()
|
|
|
+ return $q(function(resolve, reject) {
|
|
|
+ pricing
|
|
|
+ .plan(planCode, { quantity: 1 })
|
|
|
+ .currency(currency)
|
|
|
+ .done(function(price) {
|
|
|
+ const totalPriceExTax = parseFloat(price.next.total)
|
|
|
+ let taxAmmount = totalPriceExTax * taxRate
|
|
|
+ if (isNaN(taxAmmount)) {
|
|
|
+ taxAmmount = 0
|
|
|
+ }
|
|
|
+ resolve(`${currencySymbol}${totalPriceExTax + taxAmmount}`)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
App.controller('ChangePlanFormController', function(
|
|
|
$scope,
|
|
|
$modal,
|
|
|
- MultiCurrencyPricing
|
|
|
+ RecurlyPricing
|
|
|
) {
|
|
|
- setupReturly()
|
|
|
- const { taxRate } = window
|
|
|
+ ensureRecurlyIsSetup()
|
|
|
|
|
|
$scope.changePlan = () =>
|
|
|
$modal.open({
|
|
|
@@ -59,44 +60,16 @@ define(['base'], function(App) {
|
|
|
scope: $scope
|
|
|
})
|
|
|
|
|
|
- $scope.$watch(
|
|
|
- 'pricing.currencyCode',
|
|
|
- () => ($scope.currencyCode = MultiCurrencyPricing.currencyCode)
|
|
|
- )
|
|
|
-
|
|
|
- $scope.pricing = MultiCurrencyPricing
|
|
|
- // $scope.plans = MultiCurrencyPricing.plans
|
|
|
- $scope.currencySymbol =
|
|
|
- MultiCurrencyPricing.plans[MultiCurrencyPricing.currencyCode] != null
|
|
|
- ? MultiCurrencyPricing.plans[MultiCurrencyPricing.currencyCode].symbol
|
|
|
- : undefined
|
|
|
-
|
|
|
- $scope.currencyCode = MultiCurrencyPricing.currencyCode
|
|
|
-
|
|
|
- $scope.prices = PRICES
|
|
|
- return ($scope.refreshPrice = function(planCode) {
|
|
|
- let price
|
|
|
- if ($scope.prices[planCode] != null) {
|
|
|
- return
|
|
|
- }
|
|
|
- $scope.prices[planCode] = '...'
|
|
|
- const pricing = recurly.Pricing()
|
|
|
- pricing
|
|
|
- .plan(planCode, { quantity: 1 })
|
|
|
- .currency(MultiCurrencyPricing.currencyCode)
|
|
|
- .done(function(price) {
|
|
|
- const totalPriceExTax = parseFloat(price.next.total)
|
|
|
- return $scope.$evalAsync(function() {
|
|
|
- let taxAmmount = totalPriceExTax * taxRate
|
|
|
- if (isNaN(taxAmmount)) {
|
|
|
- taxAmmount = 0
|
|
|
- }
|
|
|
- return ($scope.prices[planCode] =
|
|
|
- $scope.currencySymbol + (totalPriceExTax + taxAmmount))
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- return (price = '')
|
|
|
+ $scope.$watch('plan', function(plan) {
|
|
|
+ if (!plan) return
|
|
|
+ const planCode = plan.planCode
|
|
|
+ const { currency, taxRate } = window.subscription.recurly
|
|
|
+ $scope.price = '...' // Placeholder while we talk to recurly
|
|
|
+ RecurlyPricing.loadDisplayPriceWithTax(planCode, currency, taxRate).then(
|
|
|
+ price => {
|
|
|
+ $scope.price = price
|
|
|
+ }
|
|
|
+ )
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -141,69 +114,52 @@ define(['base'], function(App) {
|
|
|
return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
|
|
|
})
|
|
|
|
|
|
- return App.controller('UserSubscriptionController', function(
|
|
|
- $scope,
|
|
|
- MultiCurrencyPricing,
|
|
|
- $http,
|
|
|
- sixpack,
|
|
|
- $modal
|
|
|
- ) {
|
|
|
- $scope.plans = MultiCurrencyPricing.plans
|
|
|
-
|
|
|
- const freeTrialEndDate = new Date(
|
|
|
- typeof subscription !== 'undefined' && subscription !== null
|
|
|
- ? subscription.trial_ends_at
|
|
|
- : undefined
|
|
|
- )
|
|
|
+ App.controller('GroupMembershipController', function($scope, $modal) {
|
|
|
+ $scope.removeSelfFromGroup = function(admin_id) {
|
|
|
+ $scope.admin_id = admin_id
|
|
|
+ return $modal.open({
|
|
|
+ templateUrl: 'LeaveGroupModalTemplate',
|
|
|
+ controller: 'LeaveGroupModalController',
|
|
|
+ scope: $scope
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
- const sevenDaysTime = new Date()
|
|
|
- sevenDaysTime.setDate(sevenDaysTime.getDate() + 7)
|
|
|
+ App.controller('RecurlySubscriptionController', function($scope) {
|
|
|
+ $scope.showChangePlanButton = !subscription.groupPlan
|
|
|
|
|
|
- const freeTrialInFuture = freeTrialEndDate > new Date()
|
|
|
- const freeTrialExpiresUnderSevenDays = freeTrialEndDate < sevenDaysTime
|
|
|
+ $scope.switchToDefaultView = () => {
|
|
|
+ $scope.showCancellation = false
|
|
|
+ $scope.showChangePlan = false
|
|
|
+ }
|
|
|
+ $scope.switchToDefaultView()
|
|
|
|
|
|
- $scope.view = 'overview'
|
|
|
- $scope.getSuffix = planCode =>
|
|
|
- __guard__(
|
|
|
- planCode != null ? planCode.match(/(.*?)_(.*)/) : undefined,
|
|
|
- x => x[2]
|
|
|
- ) || null
|
|
|
- $scope.subscriptionSuffix = $scope.getSuffix(
|
|
|
- __guard__(
|
|
|
- typeof window !== 'undefined' && window !== null
|
|
|
- ? window.subscription
|
|
|
- : undefined,
|
|
|
- x => x.planCode
|
|
|
- )
|
|
|
- )
|
|
|
- if ($scope.subscriptionSuffix === 'free_trial_7_days') {
|
|
|
- $scope.subscriptionSuffix = ''
|
|
|
+ $scope.switchToCancellationView = () => {
|
|
|
+ $scope.showCancellation = true
|
|
|
+ $scope.showChangePlan = false
|
|
|
}
|
|
|
- $scope.isNextGenPlan =
|
|
|
- ['heron', 'ibis'].includes($scope.subscriptionSuffix) ||
|
|
|
- subscription.groupPlan
|
|
|
|
|
|
- $scope.shouldShowPlan = function(planCode) {
|
|
|
- let needle
|
|
|
- return (
|
|
|
- (needle = $scope.getSuffix(planCode)),
|
|
|
- !['heron', 'ibis'].includes(needle)
|
|
|
- )
|
|
|
+ $scope.switchToChangePlanView = () => {
|
|
|
+ $scope.showCancellation = false
|
|
|
+ $scope.showChangePlan = true
|
|
|
}
|
|
|
+ })
|
|
|
+
|
|
|
+ App.controller('RecurlyCancellationController', function(
|
|
|
+ $scope,
|
|
|
+ RecurlyPricing,
|
|
|
+ $http
|
|
|
+ ) {
|
|
|
+ const subscription = window.subscription
|
|
|
+ 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
|
|
|
|
|
|
const isMonthlyCollab =
|
|
|
- __guard__(
|
|
|
- typeof subscription !== 'undefined' && subscription !== null
|
|
|
- ? subscription.planCode
|
|
|
- : undefined,
|
|
|
- x1 => x1.indexOf('collaborator')
|
|
|
- ) !== -1 &&
|
|
|
- __guard__(
|
|
|
- typeof subscription !== 'undefined' && subscription !== null
|
|
|
- ? subscription.planCode
|
|
|
- : undefined,
|
|
|
- x2 => x2.indexOf('ann')
|
|
|
- ) === -1 &&
|
|
|
+ subscription.plan.planCode.indexOf('collaborator') !== -1 &&
|
|
|
+ subscription.plan.planCode.indexOf('ann') === -1 &&
|
|
|
!subscription.groupPlan
|
|
|
const stillInFreeTrial = freeTrialInFuture && freeTrialExpiresUnderSevenDays
|
|
|
|
|
|
@@ -215,25 +171,13 @@ define(['base'], function(App) {
|
|
|
$scope.showBasicCancel = true
|
|
|
}
|
|
|
|
|
|
- setupReturly()
|
|
|
-
|
|
|
- recurly
|
|
|
- .Pricing()
|
|
|
- .plan('student', { quantity: 1 })
|
|
|
- .currency(MultiCurrencyPricing.currencyCode)
|
|
|
- .done(function(price) {
|
|
|
- const totalPriceExTax = parseFloat(price.next.total)
|
|
|
- return $scope.$evalAsync(function() {
|
|
|
- let taxAmmount = totalPriceExTax * taxRate
|
|
|
- if (isNaN(taxAmmount)) {
|
|
|
- taxAmmount = 0
|
|
|
- }
|
|
|
- $scope.currencySymbol =
|
|
|
- MultiCurrencyPricing.plans[MultiCurrencyPricing.currencyCode].symbol
|
|
|
- return ($scope.studentPrice =
|
|
|
- $scope.currencySymbol + (totalPriceExTax + taxAmmount))
|
|
|
- })
|
|
|
- })
|
|
|
+ const { currency, taxRate } = window.subscription.recurly
|
|
|
+ $scope.studentPrice = '...' // Placeholder while we talk to recurly
|
|
|
+ RecurlyPricing.loadDisplayPriceWithTax('student', currency, taxRate).then(
|
|
|
+ price => {
|
|
|
+ $scope.studentPrice = price
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
$scope.downgradeToStudent = function() {
|
|
|
const body = {
|
|
|
@@ -257,30 +201,13 @@ define(['base'], function(App) {
|
|
|
.catch(() => console.log('something went wrong changing plan'))
|
|
|
}
|
|
|
|
|
|
- $scope.removeSelfFromGroup = function(admin_id) {
|
|
|
- $scope.admin_id = admin_id
|
|
|
- return $modal.open({
|
|
|
- templateUrl: 'LeaveGroupModalTemplate',
|
|
|
- controller: 'LeaveGroupModalController',
|
|
|
- scope: $scope
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- $scope.switchToCancelationView = () => ($scope.view = 'cancelation')
|
|
|
-
|
|
|
- return ($scope.exendTrial = function() {
|
|
|
+ $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'))
|
|
|
- })
|
|
|
+ }
|
|
|
})
|
|
|
})
|
|
|
-
|
|
|
-function __guard__(value, transform) {
|
|
|
- return typeof value !== 'undefined' && value !== null
|
|
|
- ? transform(value)
|
|
|
- : undefined
|
|
|
-}
|