group-plan-pricing.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import getMeta from '../../../utils/meta'
  2. // plan: 'collaborator' or 'professional'
  3. // the rest of available arguments can be seen in the groupPlans value
  4. export function createLocalizedGroupPlanPrice({
  5. plan,
  6. licenseSize,
  7. currency,
  8. usage,
  9. }) {
  10. const groupPlans = getMeta('ol-groupPlans')
  11. const currencySymbols = getMeta('ol-currencySymbols')
  12. const priceInCents =
  13. groupPlans[usage][plan][currency][licenseSize].price_in_cents
  14. const price = priceInCents / 100
  15. const perUserPrice = price / parseInt(licenseSize)
  16. const strPrice = price.toFixed()
  17. let strPerUserPrice = ''
  18. if (Number.isInteger(perUserPrice)) {
  19. strPerUserPrice = String(perUserPrice)
  20. } else {
  21. strPerUserPrice = perUserPrice.toFixed(2)
  22. }
  23. const currencySymbol = currencySymbols[currency]
  24. switch (currencySymbol) {
  25. case 'Fr':
  26. return {
  27. localizedPrice: `${currencySymbol} ${strPrice}`,
  28. localizedPerUserPrice: `${currencySymbol} ${strPerUserPrice}`,
  29. }
  30. case 'kr':
  31. return {
  32. localizedPrice: `${strPrice} ${currencySymbol}`,
  33. localizedPerUserPrice: `${strPerUserPrice} ${currencySymbol}`,
  34. }
  35. default: {
  36. return {
  37. localizedPrice: `${currencySymbol}${strPrice}`,
  38. localizedPerUserPrice: `${currencySymbol}${strPerUserPrice}`,
  39. }
  40. }
  41. }
  42. }