2022-07-07 09:36:25 -04:00
|
|
|
import getMeta from '../../../utils/meta'
|
|
|
|
|
2023-07-11 04:36:41 -04:00
|
|
|
const LOCALES = {
|
|
|
|
BRL: 'pt-BR',
|
|
|
|
MXN: 'es-MX',
|
|
|
|
COP: 'es-CO',
|
|
|
|
CLP: 'es-CL',
|
|
|
|
PEN: 'es-PE',
|
|
|
|
}
|
|
|
|
|
2022-07-07 09:36:25 -04:00
|
|
|
// plan: 'collaborator' or 'professional'
|
|
|
|
// the rest of available arguments can be seen in the groupPlans value
|
|
|
|
export function createLocalizedGroupPlanPrice({
|
|
|
|
plan,
|
|
|
|
licenseSize,
|
|
|
|
currency,
|
|
|
|
usage,
|
|
|
|
}) {
|
|
|
|
const groupPlans = getMeta('ol-groupPlans')
|
|
|
|
const currencySymbols = getMeta('ol-currencySymbols')
|
|
|
|
const priceInCents =
|
|
|
|
groupPlans[usage][plan][currency][licenseSize].price_in_cents
|
|
|
|
|
|
|
|
const price = priceInCents / 100
|
|
|
|
const perUserPrice = price / parseInt(licenseSize)
|
|
|
|
|
|
|
|
const strPrice = price.toFixed()
|
|
|
|
let strPerUserPrice = ''
|
|
|
|
|
|
|
|
if (Number.isInteger(perUserPrice)) {
|
|
|
|
strPerUserPrice = String(perUserPrice)
|
|
|
|
} else {
|
|
|
|
strPerUserPrice = perUserPrice.toFixed(2)
|
|
|
|
}
|
|
|
|
|
|
|
|
const currencySymbol = currencySymbols[currency]
|
|
|
|
|
2023-07-11 04:36:41 -04:00
|
|
|
switch (currency) {
|
|
|
|
case 'BRL':
|
|
|
|
case 'MXN':
|
|
|
|
case 'COP':
|
|
|
|
case 'CLP':
|
|
|
|
case 'PEN':
|
|
|
|
// Test using toLocaleString to format currencies for new LATAM regions
|
|
|
|
return {
|
|
|
|
localizedPrice: price.toLocaleString(LOCALES[currency], {
|
|
|
|
style: 'currency',
|
|
|
|
currency,
|
|
|
|
minimumFractionDigits: 0,
|
|
|
|
}),
|
|
|
|
localizedPerUserPrice: perUserPrice.toLocaleString(LOCALES[currency], {
|
|
|
|
style: 'currency',
|
|
|
|
currency,
|
|
|
|
minimumFractionDigits: Number.isInteger(perUserPrice) ? 0 : null,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
case 'CHF':
|
2022-07-07 09:36:25 -04:00
|
|
|
return {
|
|
|
|
localizedPrice: `${currencySymbol} ${strPrice}`,
|
|
|
|
localizedPerUserPrice: `${currencySymbol} ${strPerUserPrice}`,
|
|
|
|
}
|
2023-07-11 04:36:41 -04:00
|
|
|
case 'DKK':
|
|
|
|
case 'SEK':
|
|
|
|
case 'NOK':
|
2022-07-07 09:36:25 -04:00
|
|
|
return {
|
|
|
|
localizedPrice: `${strPrice} ${currencySymbol}`,
|
|
|
|
localizedPerUserPrice: `${strPerUserPrice} ${currencySymbol}`,
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return {
|
|
|
|
localizedPrice: `${currencySymbol}${strPrice}`,
|
|
|
|
localizedPerUserPrice: `${currencySymbol}${strPerUserPrice}`,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|