plans.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /* eslint-disable
  2. camelcase,
  3. max-len
  4. */
  5. import App from '../base'
  6. import getMeta from '../utils/meta'
  7. App.factory('MultiCurrencyPricing', function () {
  8. const currencyCode = getMeta('ol-recomendedCurrency')
  9. return {
  10. currencyCode,
  11. plans: {
  12. USD: {
  13. symbol: '$',
  14. student: {
  15. monthly: '$8',
  16. annual: '$80',
  17. },
  18. personal: {
  19. monthly: '$10',
  20. annual: '$120',
  21. },
  22. collaborator: {
  23. monthly: '$15',
  24. annual: '$180',
  25. },
  26. professional: {
  27. monthly: '$30',
  28. annual: '$360',
  29. },
  30. },
  31. EUR: {
  32. symbol: '€',
  33. student: {
  34. monthly: '€7',
  35. annual: '€70',
  36. },
  37. personal: {
  38. monthly: '€9',
  39. annual: '€108',
  40. },
  41. collaborator: {
  42. monthly: '€14',
  43. annual: '€168',
  44. },
  45. professional: {
  46. monthly: '€28',
  47. annual: '€336',
  48. },
  49. },
  50. GBP: {
  51. symbol: '£',
  52. student: {
  53. monthly: '£6',
  54. annual: '£60',
  55. },
  56. personal: {
  57. monthly: '£8',
  58. annual: '£96',
  59. },
  60. collaborator: {
  61. monthly: '£12',
  62. annual: '£144',
  63. },
  64. professional: {
  65. monthly: '£24',
  66. annual: '£288',
  67. },
  68. },
  69. SEK: {
  70. symbol: 'kr',
  71. student: {
  72. monthly: '60 kr',
  73. annual: '600 kr',
  74. },
  75. personal: {
  76. monthly: '73 kr',
  77. annual: '876 kr',
  78. },
  79. collaborator: {
  80. monthly: '110 kr',
  81. annual: '1320 kr',
  82. },
  83. professional: {
  84. monthly: '220 kr',
  85. annual: '2640 kr',
  86. },
  87. },
  88. CAD: {
  89. symbol: '$',
  90. student: {
  91. monthly: '$9',
  92. annual: '$90',
  93. },
  94. personal: {
  95. monthly: '$11',
  96. annual: '$132',
  97. },
  98. collaborator: {
  99. monthly: '$17',
  100. annual: '$204',
  101. },
  102. professional: {
  103. monthly: '$34',
  104. annual: '$408',
  105. },
  106. },
  107. NOK: {
  108. symbol: 'kr',
  109. student: {
  110. monthly: '60 kr',
  111. annual: '600 kr',
  112. },
  113. personal: {
  114. monthly: '73 kr',
  115. annual: '876 kr',
  116. },
  117. collaborator: {
  118. monthly: '110 kr',
  119. annual: '1320 kr',
  120. },
  121. professional: {
  122. monthly: '220 kr',
  123. annual: '2640 kr',
  124. },
  125. },
  126. DKK: {
  127. symbol: 'kr',
  128. student: {
  129. monthly: '50 kr',
  130. annual: '500 kr',
  131. },
  132. personal: {
  133. monthly: '60 kr',
  134. annual: '720 kr',
  135. },
  136. collaborator: {
  137. monthly: '90 kr',
  138. annual: '1080 kr',
  139. },
  140. professional: {
  141. monthly: '180 kr',
  142. annual: '2160 kr',
  143. },
  144. },
  145. AUD: {
  146. symbol: '$',
  147. student: {
  148. monthly: '$10',
  149. annual: '$100',
  150. },
  151. personal: {
  152. monthly: '$12',
  153. annual: '$144',
  154. },
  155. collaborator: {
  156. monthly: '$18',
  157. annual: '$216',
  158. },
  159. professional: {
  160. monthly: '$35',
  161. annual: '$420',
  162. },
  163. },
  164. NZD: {
  165. symbol: '$',
  166. student: {
  167. monthly: '$10',
  168. annual: '$100',
  169. },
  170. personal: {
  171. monthly: '$12',
  172. annual: '$144',
  173. },
  174. collaborator: {
  175. monthly: '$18',
  176. annual: '$216',
  177. },
  178. professional: {
  179. monthly: '$35',
  180. annual: '$420',
  181. },
  182. },
  183. CHF: {
  184. symbol: 'Fr',
  185. student: {
  186. monthly: 'Fr 8',
  187. annual: 'Fr 80',
  188. },
  189. personal: {
  190. monthly: 'Fr 10',
  191. annual: 'Fr 120',
  192. },
  193. collaborator: {
  194. monthly: 'Fr 15',
  195. annual: 'Fr 180',
  196. },
  197. professional: {
  198. monthly: 'Fr 30',
  199. annual: 'Fr 360',
  200. },
  201. },
  202. SGD: {
  203. symbol: '$',
  204. student: {
  205. monthly: '$12',
  206. annual: '$120',
  207. },
  208. personal: {
  209. monthly: '$13',
  210. annual: '$156',
  211. },
  212. collaborator: {
  213. monthly: '$20',
  214. annual: '$240',
  215. },
  216. professional: {
  217. monthly: '$40',
  218. annual: '$480',
  219. },
  220. },
  221. },
  222. }
  223. })
  224. App.controller(
  225. 'PlansController',
  226. function (
  227. $scope,
  228. $modal,
  229. eventTracking,
  230. MultiCurrencyPricing,
  231. $http,
  232. $filter,
  233. $location
  234. ) {
  235. $scope.plans = MultiCurrencyPricing.plans
  236. $scope.currencyCode = MultiCurrencyPricing.currencyCode
  237. $scope.trial_len = 7
  238. $scope.planQueryString = '_free_trial_7_days'
  239. $scope.ui = { view: 'monthly' }
  240. $scope.changeCurreny = function (e, newCurrency) {
  241. e.preventDefault()
  242. $scope.currencyCode = newCurrency
  243. }
  244. // because ternary logic in angular bindings is hard
  245. $scope.getCollaboratorPlanCode = function () {
  246. const { view } = $scope.ui
  247. if (view === 'annual') {
  248. return 'collaborator-annual'
  249. } else {
  250. return `collaborator${$scope.planQueryString}`
  251. }
  252. }
  253. $scope.getPersonalPlanCode = function () {
  254. const { view } = $scope.ui
  255. if (view === 'annual') {
  256. return 'paid-personal-annual'
  257. } else {
  258. return `paid-personal${$scope.planQueryString}`
  259. }
  260. }
  261. $scope.signUpNowClicked = function (plan, location) {
  262. if ($scope.ui.view === 'annual') {
  263. plan = `${plan}_annual`
  264. }
  265. plan = eventLabel(plan, location)
  266. eventTracking.sendMB('plans-page-start-trial')
  267. eventTracking.send('subscription-funnel', 'sign_up_now_button', plan)
  268. }
  269. $scope.switchToMonthly = function (e, location) {
  270. const uiView = 'monthly'
  271. switchEvent(e, uiView + '-prices', location)
  272. $scope.ui.view = uiView
  273. }
  274. $scope.switchToStudent = function (e, location) {
  275. const uiView = 'student'
  276. switchEvent(e, uiView + '-prices', location)
  277. $scope.ui.view = uiView
  278. }
  279. $scope.switchToAnnual = function (e, location) {
  280. const uiView = 'annual'
  281. switchEvent(e, uiView + '-prices', location)
  282. $scope.ui.view = uiView
  283. }
  284. $scope.openGroupPlanModal = function () {
  285. const path = `${window.location.pathname}${window.location.search}`
  286. history.replaceState(null, document.title, path + '#groups')
  287. $modal
  288. .open({
  289. templateUrl: 'groupPlanModalPurchaseTemplate',
  290. controller: 'GroupPlansModalPurchaseController',
  291. })
  292. .result.finally(() =>
  293. history.replaceState(null, document.title, window.location.pathname)
  294. )
  295. eventTracking.send(
  296. 'subscription-funnel',
  297. 'plans-page',
  298. 'group-inquiry-potential'
  299. )
  300. }
  301. if ($location.hash() === 'groups') {
  302. $scope.openGroupPlanModal()
  303. }
  304. var eventLabel = (label, location) => label
  305. function switchEvent(e, label, location) {
  306. e.preventDefault()
  307. const gaLabel = eventLabel(label, location)
  308. eventTracking.send('subscription-funnel', 'plans-page', gaLabel)
  309. }
  310. }
  311. )
  312. App.controller(
  313. 'GroupPlansModalPurchaseController',
  314. function ($scope, $modal, $location, $httpParamSerializer) {
  315. $scope.options = {
  316. plan_codes: [
  317. {
  318. display: 'Collaborator',
  319. code: 'collaborator',
  320. },
  321. {
  322. display: 'Professional',
  323. code: 'professional',
  324. },
  325. ],
  326. currencies: [
  327. {
  328. display: 'USD ($)',
  329. code: 'USD',
  330. },
  331. {
  332. display: 'GBP (£)',
  333. code: 'GBP',
  334. },
  335. {
  336. display: 'EUR (€)',
  337. code: 'EUR',
  338. },
  339. ],
  340. currencySymbols: {
  341. USD: '$',
  342. EUR: '€',
  343. GBP: '£',
  344. },
  345. sizes: [2, 3, 4, 5, 10, 20, 50],
  346. usages: [
  347. {
  348. display: 'Enterprise',
  349. code: 'enterprise',
  350. },
  351. {
  352. display: 'Educational',
  353. code: 'educational',
  354. },
  355. ],
  356. }
  357. $scope.prices = getMeta('ol-groupPlans')
  358. let currency = 'USD'
  359. const recomendedCurrency = getMeta('ol-recomendedCurrency')
  360. if (['USD', 'GBP', 'EUR'].includes(recomendedCurrency)) {
  361. currency = recomendedCurrency
  362. }
  363. // default selected
  364. $scope.selected = {
  365. plan_code: 'collaborator',
  366. currency,
  367. size: '10',
  368. usage: 'enterprise',
  369. }
  370. // selected via query
  371. if ($location.search()) {
  372. // usage
  373. if ($location.search().usage) {
  374. $scope.options.usages.forEach(usage => {
  375. if (usage.code === $location.search().usage) {
  376. $scope.selected.usage = usage.code
  377. }
  378. })
  379. }
  380. // plan
  381. if ($location.search().plan) {
  382. $scope.options.plan_codes.forEach(plan => {
  383. if (plan.code === $location.search().plan) {
  384. $scope.selected.plan_code = plan.code
  385. }
  386. })
  387. }
  388. // number
  389. if ($location.search().number) {
  390. // $location.search().number is a string,
  391. // but $scope.options.sizes are numbers
  392. // and $scope.selected.size is a string
  393. const groupCount = parseInt($location.search().number, 10)
  394. if ($scope.options.sizes.indexOf(groupCount) !== -1) {
  395. $scope.selected.size = $location.search().number
  396. }
  397. }
  398. // currency
  399. if ($location.search().currency) {
  400. $scope.options.currencies.forEach(currency => {
  401. if (currency.code === $location.search().currency) {
  402. $scope.selected.currency = currency.code
  403. }
  404. })
  405. }
  406. }
  407. $scope.recalculatePrice = function () {
  408. const { usage, plan_code, currency, size } = $scope.selected
  409. const price = $scope.prices[usage][plan_code][currency][size]
  410. const currencySymbol = $scope.options.currencySymbols[currency]
  411. $scope.displayPrice = `${currencySymbol}${price}`
  412. }
  413. $scope.$watch('selected', $scope.recalculatePrice, true)
  414. $scope.recalculatePrice()
  415. $scope.purchase = function () {
  416. const { plan_code, size, usage, currency } = $scope.selected
  417. const queryParams = {
  418. planCode: `group_${plan_code}_${size}_${usage}`,
  419. currency,
  420. itm_campaign: 'groups',
  421. }
  422. if ($location.search().itm_content) {
  423. queryParams.itm_content = $location.search().itm_content
  424. }
  425. window.location = `/user/subscription/new?${$httpParamSerializer(
  426. queryParams
  427. )}`
  428. }
  429. }
  430. )