|
@@ -8,6 +8,7 @@ import SessionManager from '../Authentication/SessionManager.js'
|
|
|
import UserAuditLogHandler from '../User/UserAuditLogHandler.js'
|
|
import UserAuditLogHandler from '../User/UserAuditLogHandler.js'
|
|
|
import { expressify } from '@overleaf/promise-utils'
|
|
import { expressify } from '@overleaf/promise-utils'
|
|
|
import Modules from '../../infrastructure/Modules.js'
|
|
import Modules from '../../infrastructure/Modules.js'
|
|
|
|
|
+import SplitTestHandler from '../SplitTests/SplitTestHandler.js'
|
|
|
import UserGetter from '../User/UserGetter.js'
|
|
import UserGetter from '../User/UserGetter.js'
|
|
|
import { Subscription } from '../../models/Subscription.js'
|
|
import { Subscription } from '../../models/Subscription.js'
|
|
|
import { isProfessionalGroupPlan } from './PlansHelper.mjs'
|
|
import { isProfessionalGroupPlan } from './PlansHelper.mjs'
|
|
@@ -18,7 +19,6 @@ import {
|
|
|
InactiveError,
|
|
InactiveError,
|
|
|
SubtotalLimitExceededError,
|
|
SubtotalLimitExceededError,
|
|
|
HasPastDueInvoiceError,
|
|
HasPastDueInvoiceError,
|
|
|
- HasNoAdditionalLicenseWhenManuallyCollectedError,
|
|
|
|
|
} from './Errors.js'
|
|
} from './Errors.js'
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -151,13 +151,26 @@ async function addSeatsToGroupSubscription(req, res) {
|
|
|
await SubscriptionGroupHandler.promises.ensureSubscriptionHasNoPastDueInvoice(
|
|
await SubscriptionGroupHandler.promises.ensureSubscriptionHasNoPastDueInvoice(
|
|
|
subscription
|
|
subscription
|
|
|
)
|
|
)
|
|
|
- await SubscriptionGroupHandler.promises.checkBillingInfoExistence(
|
|
|
|
|
- paymentProviderSubscription,
|
|
|
|
|
- userId
|
|
|
|
|
- )
|
|
|
|
|
- await SubscriptionGroupHandler.promises.ensureSubscriptionHasAdditionalLicenseAddOnWhenCollectionMethodIsManual(
|
|
|
|
|
- paymentProviderSubscription
|
|
|
|
|
- )
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const { variant: flexibleLicensingForManuallyBilledSubscriptionsVariant } =
|
|
|
|
|
+ await SplitTestHandler.promises.getAssignment(
|
|
|
|
|
+ req,
|
|
|
|
|
+ res,
|
|
|
|
|
+ 'flexible-group-licensing-for-manually-billed-subscriptions'
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ if (flexibleLicensingForManuallyBilledSubscriptionsVariant === 'enabled') {
|
|
|
|
|
+ await SubscriptionGroupHandler.promises.checkBillingInfoExistence(
|
|
|
|
|
+ paymentProviderSubscription,
|
|
|
|
|
+ userId
|
|
|
|
|
+ )
|
|
|
|
|
+ } else {
|
|
|
|
|
+ await SubscriptionGroupHandler.promises.ensureSubscriptionCollectionMethodIsNotManual(
|
|
|
|
|
+ paymentProviderSubscription
|
|
|
|
|
+ )
|
|
|
|
|
+ // Check if the user has missing billing details
|
|
|
|
|
+ await Modules.promises.hooks.fire('getPaymentMethod', userId)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
res.render('subscriptions/add-seats', {
|
|
res.render('subscriptions/add-seats', {
|
|
|
subscriptionId: subscription._id,
|
|
subscriptionId: subscription._id,
|
|
@@ -174,7 +187,7 @@ async function addSeatsToGroupSubscription(req, res) {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (error instanceof HasNoAdditionalLicenseWhenManuallyCollectedError) {
|
|
|
|
|
|
|
+ if (error instanceof ManuallyCollectedError) {
|
|
|
return res.redirect(
|
|
return res.redirect(
|
|
|
'/user/subscription/group/manually-collected-subscription'
|
|
'/user/subscription/group/manually-collected-subscription'
|
|
|
)
|
|
)
|
|
@@ -215,10 +228,10 @@ async function previewAddSeatsSubscriptionChange(req, res) {
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
if (
|
|
if (
|
|
|
error instanceof MissingBillingInfoError ||
|
|
error instanceof MissingBillingInfoError ||
|
|
|
|
|
+ error instanceof ManuallyCollectedError ||
|
|
|
error instanceof PendingChangeError ||
|
|
error instanceof PendingChangeError ||
|
|
|
error instanceof InactiveError ||
|
|
error instanceof InactiveError ||
|
|
|
- error instanceof HasPastDueInvoiceError ||
|
|
|
|
|
- error instanceof HasNoAdditionalLicenseWhenManuallyCollectedError
|
|
|
|
|
|
|
+ error instanceof HasPastDueInvoiceError
|
|
|
) {
|
|
) {
|
|
|
return res.status(422).end()
|
|
return res.status(422).end()
|
|
|
}
|
|
}
|
|
@@ -258,10 +271,10 @@ async function createAddSeatsSubscriptionChange(req, res) {
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
if (
|
|
if (
|
|
|
error instanceof MissingBillingInfoError ||
|
|
error instanceof MissingBillingInfoError ||
|
|
|
|
|
+ error instanceof ManuallyCollectedError ||
|
|
|
error instanceof PendingChangeError ||
|
|
error instanceof PendingChangeError ||
|
|
|
error instanceof InactiveError ||
|
|
error instanceof InactiveError ||
|
|
|
- error instanceof HasPastDueInvoiceError ||
|
|
|
|
|
- error instanceof HasNoAdditionalLicenseWhenManuallyCollectedError
|
|
|
|
|
|
|
+ error instanceof HasPastDueInvoiceError
|
|
|
) {
|
|
) {
|
|
|
return res.status(422).end()
|
|
return res.status(422).end()
|
|
|
}
|
|
}
|
|
@@ -398,6 +411,12 @@ async function manuallyCollectedSubscription(req, res) {
|
|
|
const subscription =
|
|
const subscription =
|
|
|
await SubscriptionLocator.promises.getUsersSubscription(userId)
|
|
await SubscriptionLocator.promises.getUsersSubscription(userId)
|
|
|
|
|
|
|
|
|
|
+ await SplitTestHandler.promises.getAssignment(
|
|
|
|
|
+ req,
|
|
|
|
|
+ res,
|
|
|
|
|
+ 'flexible-group-licensing-for-manually-billed-subscriptions'
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
res.render('subscriptions/manually-collected-subscription', {
|
|
res.render('subscriptions/manually-collected-subscription', {
|
|
|
groupName: subscription.teamName,
|
|
groupName: subscription.teamName,
|
|
|
})
|
|
})
|