mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-08 08:39:03 +02:00
2ef5db2938
[web] Clean up localized currency format test (`local-ccy-format-v2`) GitOrigin-RevId: 30d671479522b87ee9205994508b745d2b0ae4c3
59 lines
1.8 KiB
JavaScript
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,
|
|
}
|