group-plan-pricing.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { formatCurrency } from '@/shared/utils/currency'
  2. import getMeta from '../../../utils/meta'
  3. /**
  4. * @import { CurrencyCode } from '../../../../../types/subscription/currency'
  5. */
  6. // plan: 'collaborator' or 'professional'
  7. // the rest of available arguments can be seen in the groupPlans value
  8. /**
  9. * @param {Object} opts
  10. * @param {'collaborator' | 'professional'} opts.plan
  11. * @param {string} opts.licenseSize
  12. * @param {CurrencyCode} opts.currency
  13. * @param {'enterprise' | 'educational'} opts.usage
  14. * @param {string} [opts.locale]
  15. * @returns {{localizedPrice: string, localizedPerUserPrice: string}}
  16. */
  17. export function createLocalizedGroupPlanPrice({
  18. plan,
  19. licenseSize,
  20. currency,
  21. usage,
  22. locale = getMeta('ol-i18n').currentLangCode || 'en',
  23. }) {
  24. const groupPlans = getMeta('ol-groupPlans')
  25. const priceInCents =
  26. groupPlans[usage][plan][currency][licenseSize].price_in_cents
  27. const price = priceInCents / 100
  28. const perUserPrice = price / parseInt(licenseSize)
  29. /**
  30. * @param {number} price
  31. * @returns {string}
  32. */
  33. const formatPrice = price => formatCurrency(price, currency, locale, true)
  34. return {
  35. localizedPrice: formatPrice(price),
  36. localizedPerUserPrice: formatPrice(perUserPrice),
  37. }
  38. }