Files
overleaf-cep/services/web/app/src/Features/Subscription/SubscriptionHelper.js
T
M Fahru 2ef5db2938 Merge pull request #22340 from overleaf/mf-clean-up-currency-format-test
[web] Clean up localized currency format test (`local-ccy-format-v2`)

GitOrigin-RevId: 30d671479522b87ee9205994508b745d2b0ae4c3
2025-01-14 09:05:49 +00:00

59 lines
1.8 KiB
JavaScript

const { formatCurrency } = require('../../util/currency')
const GroupPlansData = require('./GroupPlansData')
/**
* If the user changes to a less expensive plan, we shouldn't apply the change immediately.
* This is to avoid unintended/artifical credits on users Recurly accounts.
*/
function shouldPlanChangeAtTermEnd(oldPlan, newPlan) {
return oldPlan.price_in_cents > newPlan.price_in_cents
}
/**
* @import { CurrencyCode } from '../../../../types/subscription/currency'
*/
/**
* @param {CurrencyCode} recommendedCurrency
* @param {string} locale
* @returns {{ price: { collaborator: string, professional: string }, pricePerUser: { collaborator: string, professional: string } }} - localized group price
*/
function generateInitialLocalizedGroupPrice(recommendedCurrency, locale) {
const INITIAL_LICENSE_SIZE = 2
// the price is in cents, so divide by 100 to get the value
const collaboratorPrice =
GroupPlansData.enterprise.collaborator[recommendedCurrency][
INITIAL_LICENSE_SIZE
].price_in_cents / 100
const collaboratorPricePerUser = collaboratorPrice / INITIAL_LICENSE_SIZE
const professionalPrice =
GroupPlansData.enterprise.professional[recommendedCurrency][
INITIAL_LICENSE_SIZE
].price_in_cents / 100
const professionalPricePerUser = professionalPrice / INITIAL_LICENSE_SIZE
/**
* @param {number} price
* @returns {string}
*/
const formatPrice = price =>
formatCurrency(price, recommendedCurrency, locale, true)
return {
price: {
collaborator: formatPrice(collaboratorPrice),
professional: formatPrice(professionalPrice),
},
pricePerUser: {
collaborator: formatPrice(collaboratorPricePerUser),
professional: formatPrice(professionalPricePerUser),
},
}
}
module.exports = {
shouldPlanChangeAtTermEnd,
generateInitialLocalizedGroupPrice,
}