Merge pull request #26934 from overleaf/ls-support-individual-to-group-plan-upgrade

Support individual to group plan upgrade in Stripe

GitOrigin-RevId: 24cbe7bd6de86a4d9410e1abc49b6457e0871f40
This commit is contained in:
Liangjun Song
2025-07-16 08:05:20 +00:00
committed by Copybot
parent 1375f695d3
commit 9e22ed9c3f
12 changed files with 364 additions and 91 deletions
@@ -5,3 +5,11 @@ export function getRecurlyGroupPlanCode(
) {
return `group_${planCode}_${size}_${usage}`
}
export function getConsolidatedGroupPlanCode(planCode: string, usage: string) {
if (usage === 'enterprise') {
return `group_${planCode}`
}
return `group_${planCode}_${usage}`
}
@@ -1,9 +1,15 @@
import { SubscriptionPricingState } from '@recurly/recurly-js'
import { PriceForDisplayData } from '../../../../../types/subscription/plan'
import { CurrencyCode } from '../../../../../types/subscription/currency'
import { getRecurlyGroupPlanCode } from './recurly-group-plan-code'
import {
getRecurlyGroupPlanCode,
getConsolidatedGroupPlanCode,
} from './recurly-group-plan-code'
import { debugConsole } from '@/utils/debugging'
import { formatCurrency } from '@/shared/utils/currency'
import { getJSON } from '../../../infrastructure/fetch-json'
let groupPlanPerUserPrices: Record<string, number> | undefined
function queryRecurlyPlanPrice(planCode: string, currency: CurrencyCode) {
return new Promise(resolve => {
@@ -73,7 +79,7 @@ export async function loadDisplayPriceWithTaxPromise(
)
}
export async function loadGroupDisplayPriceWithTaxPromise(
export async function loadGroupDisplayPriceWithTaxForRecurlyPromise(
groupPlanCode: string,
currencyCode: CurrencyCode,
taxRate: number,
@@ -102,3 +108,44 @@ export async function loadGroupDisplayPriceWithTaxPromise(
return price
}
export async function loadGroupDisplayPriceWithTaxForStripePromise(
groupPlanCode: string,
currencyCode: CurrencyCode,
taxRate: number,
size: string,
usage: string,
locale: string
) {
if (!groupPlanPerUserPrices) {
groupPlanPerUserPrices = await getJSON<Record<string, number>>(
`/user/subscription/group/group-plan-per-user-prices?currency=${currencyCode}`
)
}
const planCode = getConsolidatedGroupPlanCode(groupPlanCode, usage)
if (!(planCode in groupPlanPerUserPrices)) {
throw new Error(
`Group plan code ${planCode} not found in groupPlanPerUserPrices`
)
}
const subtotalPrice = groupPlanPerUserPrices[planCode] * parseInt(size)
const result = formatPriceForDisplayData(
subtotalPrice.toString(),
taxRate,
currencyCode,
locale
)
result.perUserDisplayPrice = formatCurrency(
groupPlanPerUserPrices[planCode],
currencyCode,
locale,
true
)
return result
}