new-subscription.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. import _ from 'lodash'
  2. /* eslint-disable
  3. camelcase,
  4. max-len,
  5. no-return-assign
  6. */
  7. /* global recurly */
  8. import App from '../base'
  9. import getMeta from '../utils/meta'
  10. import { assign } from '../shared/components/location'
  11. export default App.controller(
  12. 'NewSubscriptionController',
  13. function (
  14. $scope,
  15. $modal,
  16. MultiCurrencyPricing,
  17. $http,
  18. $location,
  19. eventTracking
  20. ) {
  21. window.couponCode = $location.search().cc || ''
  22. window.plan_code = $location.search().planCode || ''
  23. window.ITMCampaign = $location.search().itm_campaign || ''
  24. window.ITMContent = $location.search().itm_content || ''
  25. window.ITMReferrer = $location.search().itm_referrer || ''
  26. if (typeof recurly === 'undefined' || !recurly) {
  27. $scope.recurlyLoadError = true
  28. return
  29. }
  30. $scope.ui = {
  31. showCurrencyDropdown: false,
  32. showAddressSecondLine: false,
  33. addCompanyDetails: false,
  34. }
  35. $scope.recurlyLoadError = false
  36. $scope.currencyCode = MultiCurrencyPricing.currencyCode
  37. $scope.initiallySelectedCurrencyCode = MultiCurrencyPricing.currencyCode
  38. $scope.allCurrencies = MultiCurrencyPricing.plans
  39. $scope.availableCurrencies = {}
  40. $scope.planCode = window.plan_code
  41. const isStudentCheckModalEnabled =
  42. getMeta('ol-splitTestVariants')?.['student-check-modal'] === 'enabled'
  43. if (isStudentCheckModalEnabled && $scope.planCode.includes('student')) {
  44. $modal.open({
  45. templateUrl: 'StudentCheckModalTemplate',
  46. controller: 'StudentCheckModalController',
  47. backdrop: 'static',
  48. size: 'dialog-centered',
  49. })
  50. }
  51. $scope.switchToStudent = function () {
  52. const currentPlanCode = window.plan_code
  53. const planCode = currentPlanCode.replace('collaborator', 'student')
  54. eventTracking.sendMB('payment-page-switch-to-student', {
  55. plan_code: window.plan_code,
  56. })
  57. eventTracking.send(
  58. 'subscription-funnel',
  59. 'subscription-form-switch-to-student',
  60. window.plan_code
  61. )
  62. window.location =
  63. '/user/subscription/new' +
  64. `?planCode=${planCode}` +
  65. `&currency=${$scope.currencyCode}` +
  66. `&cc=${$scope.data.coupon}` +
  67. `&itm_campaign=${window.ITMCampaign}` +
  68. `&itm_content=${window.ITMContent}` +
  69. `&itm_referrer=${window.ITMReferrer}`
  70. }
  71. eventTracking.sendMB('payment-page-view', { plan: window.plan_code })
  72. eventTracking.send(
  73. 'subscription-funnel',
  74. 'subscription-form-viewed',
  75. window.plan_code
  76. )
  77. $scope.paymentMethod = { value: 'credit_card' }
  78. $scope.data = {
  79. first_name: '',
  80. last_name: '',
  81. postal_code: '',
  82. address1: '',
  83. address2: '',
  84. state: '',
  85. city: '',
  86. company: '',
  87. vat_number: '',
  88. country: getMeta('ol-countryCode'),
  89. coupon: window.couponCode,
  90. }
  91. $scope.validation = {}
  92. $scope.processing = false
  93. $scope.threeDSecureFlow = false
  94. $scope.threeDSecureContainer = document.querySelector(
  95. '.three-d-secure-container'
  96. )
  97. $scope.threeDSecureRecurlyContainer = document.querySelector(
  98. '.three-d-secure-recurly-container'
  99. )
  100. recurly.configure({
  101. publicKey: getMeta('ol-recurlyApiKey'),
  102. style: {
  103. all: {
  104. fontFamily: '"Open Sans", sans-serif',
  105. fontSize: '16px',
  106. fontColor: '#7a7a7a',
  107. },
  108. month: {
  109. placeholder: 'MM',
  110. },
  111. year: {
  112. placeholder: 'YY',
  113. },
  114. cvv: {
  115. placeholder: 'CVV',
  116. },
  117. },
  118. })
  119. const pricing = recurly.Pricing()
  120. window.pricing = pricing
  121. function setupPricing() {
  122. pricing
  123. .plan(window.plan_code, { quantity: 1 })
  124. .address({
  125. country: $scope.data.country,
  126. })
  127. .tax({ tax_code: 'digital', vat_number: '' })
  128. .currency($scope.currencyCode)
  129. .coupon($scope.data.coupon)
  130. .catch(function (err) {
  131. if (
  132. $scope.currencyCode !== 'USD' &&
  133. err.name === 'invalid-currency'
  134. ) {
  135. $scope.currencyCode = 'USD'
  136. setupPricing()
  137. } else if (err.name === 'api-error' && err.code === 'not-found') {
  138. // not-found here should refer to the coupon code, plan_code should be valid
  139. $scope.$applyAsync(() => {
  140. $scope.couponError = 'Coupon code is not valid for selected plan'
  141. })
  142. } else {
  143. // Bail out on other errors, form state will not be correct
  144. $scope.$applyAsync(() => {
  145. $scope.recurlyLoadError = true
  146. })
  147. throw err
  148. }
  149. })
  150. .done()
  151. }
  152. setupPricing()
  153. pricing.on('change', () => {
  154. $scope.planName = pricing.items.plan.name
  155. if (pricing.items.plan.trial) {
  156. $scope.trialLength = pricing.items.plan.trial.length
  157. }
  158. $scope.recurlyPrice = $scope.trialLength
  159. ? pricing.price.next
  160. : pricing.price.now
  161. $scope.taxes = pricing.price.taxes
  162. $scope.monthlyBilling = pricing.items.plan.period.length === 1
  163. $scope.availableCurrencies = {}
  164. for (const currencyCode in pricing.items.plan.price) {
  165. if (MultiCurrencyPricing.plans[currencyCode]) {
  166. $scope.availableCurrencies[currencyCode] =
  167. MultiCurrencyPricing.plans[currencyCode]
  168. }
  169. }
  170. $scope.limitedCurrencies = {}
  171. const limitedCurrencyCodes = ['USD', 'EUR', 'GBP']
  172. if (
  173. limitedCurrencyCodes.indexOf($scope.initiallySelectedCurrencyCode) ===
  174. -1
  175. ) {
  176. limitedCurrencyCodes.unshift($scope.initiallySelectedCurrencyCode)
  177. }
  178. limitedCurrencyCodes.forEach(currencyCode => {
  179. $scope.limitedCurrencies[currencyCode] =
  180. MultiCurrencyPricing.plans[currencyCode]
  181. })
  182. if (
  183. pricing.items &&
  184. pricing.items.coupon &&
  185. pricing.items.coupon.discount &&
  186. pricing.items.coupon.discount.type === 'percent'
  187. ) {
  188. const basePrice = parseInt(pricing.price.base.plan.unit, 10)
  189. $scope.coupon = {
  190. singleUse: pricing.items.coupon.single_use,
  191. normalPrice: basePrice,
  192. name: pricing.items.coupon.name,
  193. normalPriceWithoutTax: basePrice,
  194. }
  195. if (
  196. pricing.items.coupon.applies_for_months > 0 &&
  197. pricing.items.coupon.discount.rate &&
  198. pricing.items.coupon.applies_for_months
  199. ) {
  200. $scope.coupon.discountMonths = pricing.items.coupon.applies_for_months
  201. $scope.coupon.discountRate = pricing.items.coupon.discount.rate * 100
  202. }
  203. if (pricing.price.taxes[0] && pricing.price.taxes[0].rate) {
  204. $scope.coupon.normalPrice += basePrice * pricing.price.taxes[0].rate
  205. }
  206. } else {
  207. $scope.coupon = null
  208. }
  209. $scope.$apply()
  210. })
  211. $scope.applyCoupon = () => {
  212. $scope.couponError = ''
  213. pricing
  214. .coupon($scope.data.coupon)
  215. .catch(err => {
  216. if (err.name === 'api-error' && err.code === 'not-found') {
  217. $scope.$applyAsync(() => {
  218. $scope.couponError = 'Coupon code is not valid for selected plan'
  219. })
  220. } else {
  221. $scope.$applyAsync(() => {
  222. $scope.couponError =
  223. 'An error occured when verifying the coupon code'
  224. })
  225. throw err
  226. }
  227. })
  228. .done()
  229. }
  230. $scope.showAddressSecondLine = function (e) {
  231. e.preventDefault()
  232. $scope.ui.showAddressSecondLine = true
  233. }
  234. $scope.showCurrencyDropdown = function (e) {
  235. e.preventDefault()
  236. $scope.ui.showCurrencyDropdown = true
  237. }
  238. const elements = recurly.Elements()
  239. const card = elements.CardElement({
  240. displayIcon: true,
  241. style: {
  242. inputType: 'mobileSelect',
  243. fontColor: '#5d6879',
  244. placeholder: {},
  245. invalid: {
  246. fontColor: '#a93529',
  247. },
  248. },
  249. })
  250. card.attach('#recurly-card-input')
  251. card.on('change', state => {
  252. $scope.$applyAsync(() => {
  253. $scope.showCardElementInvalid =
  254. !state.focus && !state.empty && !state.valid
  255. $scope.cardIsValid = state.valid
  256. })
  257. })
  258. $scope.applyVatNumber = () =>
  259. pricing
  260. .tax({ tax_code: 'digital', vat_number: $scope.data.vat_number })
  261. .done()
  262. $scope.changeCurrency = function (newCurrency) {
  263. $scope.currencyCode = newCurrency
  264. return pricing
  265. .currency(newCurrency)
  266. .catch(function (err) {
  267. if (
  268. $scope.currencyCode !== 'USD' &&
  269. err.name === 'invalid-currency'
  270. ) {
  271. $scope.changeCurrency('USD')
  272. } else {
  273. throw err
  274. }
  275. })
  276. .done()
  277. }
  278. $scope.inputHasError = function (formItem) {
  279. if (formItem == null) {
  280. return false
  281. }
  282. return formItem.$touched && formItem.$invalid
  283. }
  284. $scope.isFormValid = function (form) {
  285. if ($scope.paymentMethod.value === 'paypal') {
  286. return $scope.data.country !== ''
  287. } else {
  288. return form.$valid && $scope.cardIsValid
  289. }
  290. }
  291. $scope.updateCountry = () =>
  292. pricing.address({ country: $scope.data.country }).done()
  293. $scope.setPaymentMethod = function (method) {
  294. $scope.paymentMethod.value = method
  295. $scope.validation.errorFields = {}
  296. $scope.genericError = ''
  297. }
  298. let cachedRecurlyBillingToken
  299. const completeSubscription = function (
  300. err,
  301. recurlyBillingToken,
  302. recurly3DSecureResultToken
  303. ) {
  304. if (recurlyBillingToken) {
  305. // temporary store the billing token as it might be needed when
  306. // re-sending the request after SCA authentication
  307. cachedRecurlyBillingToken = recurlyBillingToken
  308. }
  309. $scope.validation.errorFields = {}
  310. if (err != null) {
  311. eventTracking.sendMB('payment-page-form-error', err)
  312. eventTracking.send('subscription-funnel', 'subscription-error')
  313. // We may or may not be in a digest loop here depending on
  314. // whether recurly could do validation locally, so do it async
  315. $scope.$evalAsync(function () {
  316. $scope.processing = false
  317. $scope.genericError = err.message
  318. _.each(
  319. err.fields,
  320. field => ($scope.validation.errorFields[field] = true)
  321. )
  322. })
  323. } else {
  324. const postData = {
  325. _csrf: window.csrfToken,
  326. recurly_token_id: cachedRecurlyBillingToken.id,
  327. recurly_three_d_secure_action_result_token_id:
  328. recurly3DSecureResultToken && recurly3DSecureResultToken.id,
  329. subscriptionDetails: {
  330. currencyCode: pricing.items.currency,
  331. plan_code: pricing.items.plan.code,
  332. coupon_code: pricing.items.coupon ? pricing.items.coupon.code : '',
  333. first_name: $scope.data.first_name,
  334. last_name: $scope.data.last_name,
  335. isPaypal: $scope.paymentMethod.value === 'paypal',
  336. address: {
  337. address1: $scope.data.address1,
  338. address2: $scope.data.address2,
  339. country: $scope.data.country,
  340. state: $scope.data.state,
  341. zip: $scope.data.postal_code,
  342. },
  343. ITMCampaign: window.ITMCampaign,
  344. ITMContent: window.ITMContent,
  345. ITMReferrer: window.ITMReferrer,
  346. },
  347. }
  348. if (
  349. postData.subscriptionDetails.isPaypal &&
  350. $scope.ui.addCompanyDetails
  351. ) {
  352. postData.subscriptionDetails.billing_info = {}
  353. if ($scope.data.company && $scope.data.company !== '') {
  354. postData.subscriptionDetails.billing_info.company =
  355. $scope.data.company
  356. }
  357. if ($scope.data.vat_number && $scope.data.vat_number !== '') {
  358. postData.subscriptionDetails.billing_info.vat_number =
  359. $scope.data.vat_number
  360. }
  361. }
  362. eventTracking.sendMB('payment-page-form-submit', {
  363. currencyCode: postData.subscriptionDetails.currencyCode,
  364. plan_code: postData.subscriptionDetails.plan_code,
  365. coupon_code: postData.subscriptionDetails.coupon_code,
  366. isPaypal: postData.subscriptionDetails.isPaypal,
  367. })
  368. eventTracking.send(
  369. 'subscription-funnel',
  370. 'subscription-form-submitted',
  371. postData.subscriptionDetails.plan_code
  372. )
  373. return $http
  374. .post('/user/subscription/create', postData)
  375. .then(function () {
  376. eventTracking.sendMB('payment-page-form-success')
  377. eventTracking.send(
  378. 'subscription-funnel',
  379. 'subscription-submission-success',
  380. postData.subscriptionDetails.plan_code
  381. )
  382. window.location.href = '/user/subscription/thank-you'
  383. })
  384. .catch(response => {
  385. $scope.processing = false
  386. const { data } = response
  387. $scope.genericError =
  388. (data && data.message) ||
  389. 'Something went wrong processing the request'
  390. if (data.threeDSecureActionTokenId) {
  391. initThreeDSecure(data.threeDSecureActionTokenId)
  392. }
  393. })
  394. }
  395. }
  396. $scope.submit = function () {
  397. $scope.processing = true
  398. if ($scope.paymentMethod.value === 'paypal') {
  399. const opts = { description: $scope.planName }
  400. recurly.paypal(opts, completeSubscription)
  401. } else {
  402. const tokenData = _.cloneDeep($scope.data)
  403. if (!$scope.ui.addCompanyDetails) {
  404. delete tokenData.company
  405. delete tokenData.vat_number
  406. }
  407. recurly.token(elements, tokenData, completeSubscription)
  408. }
  409. }
  410. const initThreeDSecure = function (threeDSecureActionTokenId) {
  411. // instanciate and configure Recurly 3DSecure flow
  412. const risk = recurly.Risk()
  413. const threeDSecure = risk.ThreeDSecure({
  414. actionTokenId: threeDSecureActionTokenId,
  415. })
  416. // on SCA verification error: show payment UI with the error message
  417. threeDSecure.on('error', error => {
  418. $scope.genericError = `Error: ${error.message}`
  419. $scope.threeDSecureFlow = false
  420. $scope.$apply()
  421. })
  422. // on SCA verification success: show payment UI in processing mode and
  423. // resubmit the payment with the new token final success or error will be
  424. // handled by `completeSubscription`
  425. threeDSecure.on('token', recurly3DSecureResultToken => {
  426. completeSubscription(null, null, recurly3DSecureResultToken)
  427. $scope.genericError = null
  428. $scope.threeDSecureFlow = false
  429. $scope.processing = true
  430. $scope.$apply()
  431. })
  432. // make sure the threeDSecureRecurlyContainer is empty (in case of
  433. // retries) and show 3DSecure UI
  434. $scope.threeDSecureRecurlyContainer.innerHTML = ''
  435. $scope.threeDSecureFlow = true
  436. threeDSecure.attach($scope.threeDSecureRecurlyContainer)
  437. // scroll the UI into view (timeout needed to make sure the element is
  438. // visible)
  439. window.setTimeout(() => {
  440. $scope.threeDSecureContainer.scrollIntoView()
  441. }, 0)
  442. }
  443. // list taken from Recurly (see https://docs.recurly.com/docs/countries-provinces-and-states). Country code must exist on Recurly, so update with care
  444. $scope.countries = [
  445. { code: 'AF', name: 'Afghanistan' },
  446. { code: 'AX', name: 'Åland Islands' },
  447. { code: 'AL', name: 'Albania' },
  448. { code: 'DZ', name: 'Algeria' },
  449. { code: 'AS', name: 'American Samoa' },
  450. { code: 'AD', name: 'Andorra' },
  451. { code: 'AO', name: 'Angola' },
  452. { code: 'AI', name: 'Anguilla' },
  453. { code: 'AQ', name: 'Antarctica' },
  454. { code: 'AG', name: 'Antigua and Barbuda' },
  455. { code: 'AR', name: 'Argentina' },
  456. { code: 'AM', name: 'Armenia' },
  457. { code: 'AW', name: 'Aruba' },
  458. { code: 'AC', name: 'Ascension Island' },
  459. { code: 'AU', name: 'Australia' },
  460. { code: 'AT', name: 'Austria' },
  461. { code: 'AZ', name: 'Azerbaijan' },
  462. { code: 'BS', name: 'Bahamas' },
  463. { code: 'BH', name: 'Bahrain' },
  464. { code: 'BD', name: 'Bangladesh' },
  465. { code: 'BB', name: 'Barbados' },
  466. { code: 'BY', name: 'Belarus' },
  467. { code: 'BE', name: 'Belgium' },
  468. { code: 'BZ', name: 'Belize' },
  469. { code: 'BJ', name: 'Benin' },
  470. { code: 'BM', name: 'Bermuda' },
  471. { code: 'BT', name: 'Bhutan' },
  472. { code: 'BO', name: 'Bolivia' },
  473. { code: 'BA', name: 'Bosnia and Herzegovina' },
  474. { code: 'BW', name: 'Botswana' },
  475. { code: 'BV', name: 'Bouvet Island' },
  476. { code: 'BR', name: 'Brazil' },
  477. { code: 'BQ', name: 'British Antarctic Territory' },
  478. { code: 'IO', name: 'British Indian Ocean Territory' },
  479. { code: 'VG', name: 'British Virgin Islands' },
  480. { code: 'BN', name: 'Brunei' },
  481. { code: 'BG', name: 'Bulgaria' },
  482. { code: 'BF', name: 'Burkina Faso' },
  483. { code: 'BI', name: 'Burundi' },
  484. { code: 'CV', name: 'Cabo Verde' },
  485. { code: 'KH', name: 'Cambodia' },
  486. { code: 'CM', name: 'Cameroon' },
  487. { code: 'CA', name: 'Canada' },
  488. { code: 'IC', name: 'Canary Islands' },
  489. { code: 'CT', name: 'Canton and Enderbury Islands' },
  490. { code: 'KY', name: 'Cayman Islands' },
  491. { code: 'CF', name: 'Central African Republic' },
  492. { code: 'EA', name: 'Ceuta and Melilla' },
  493. { code: 'TD', name: 'Chad' },
  494. { code: 'CL', name: 'Chile' },
  495. { code: 'CN', name: 'China' },
  496. { code: 'CX', name: 'Christmas Island' },
  497. { code: 'CP', name: 'Clipperton Island' },
  498. { code: 'CC', name: 'Cocos [Keeling] Islands' },
  499. { code: 'CO', name: 'Colombia' },
  500. { code: 'KM', name: 'Comoros' },
  501. { code: 'CG', name: 'Congo - Brazzaville' },
  502. { code: 'CD', name: 'Congo - Kinshasa' },
  503. { code: 'CD', name: 'Congo [DRC]' },
  504. { code: 'CG', name: 'Congo [Republic]' },
  505. { code: 'CK', name: 'Cook Islands' },
  506. { code: 'CR', name: 'Costa Rica' },
  507. { code: 'CI', name: 'Côte d’Ivoire' },
  508. { code: 'HR', name: 'Croatia' },
  509. { code: 'CU', name: 'Cuba' },
  510. { code: 'CY', name: 'Cyprus' },
  511. { code: 'CZ', name: 'Czech Republic' },
  512. { code: 'DK', name: 'Denmark' },
  513. { code: 'DG', name: 'Diego Garcia' },
  514. { code: 'DJ', name: 'Djibouti' },
  515. { code: 'DM', name: 'Dominica' },
  516. { code: 'DO', name: 'Dominican Republic' },
  517. { code: 'NQ', name: 'Dronning Maud Land' },
  518. { code: 'TL', name: 'East Timor' },
  519. { code: 'EC', name: 'Ecuador' },
  520. { code: 'EG', name: 'Egypt' },
  521. { code: 'SV', name: 'El Salvador' },
  522. { code: 'GQ', name: 'Equatorial Guinea' },
  523. { code: 'ER', name: 'Eritrea' },
  524. { code: 'EE', name: 'Estonia' },
  525. { code: 'ET', name: 'Ethiopia' },
  526. { code: 'FK', name: 'Falkland Islands [Islas Malvinas]' },
  527. { code: 'FK', name: 'Falkland Islands' },
  528. { code: 'FO', name: 'Faroe Islands' },
  529. { code: 'FJ', name: 'Fiji' },
  530. { code: 'FI', name: 'Finland' },
  531. { code: 'FR', name: 'France' },
  532. { code: 'GF', name: 'French Guiana' },
  533. { code: 'PF', name: 'French Polynesia' },
  534. { code: 'FQ', name: 'French Southern and Antarctic Territories' },
  535. { code: 'TF', name: 'French Southern Territories' },
  536. { code: 'GA', name: 'Gabon' },
  537. { code: 'GM', name: 'Gambia' },
  538. { code: 'GE', name: 'Georgia' },
  539. { code: 'DE', name: 'Germany' },
  540. { code: 'GH', name: 'Ghana' },
  541. { code: 'GI', name: 'Gibraltar' },
  542. { code: 'GR', name: 'Greece' },
  543. { code: 'GL', name: 'Greenland' },
  544. { code: 'GD', name: 'Grenada' },
  545. { code: 'GP', name: 'Guadeloupe' },
  546. { code: 'GU', name: 'Guam' },
  547. { code: 'GT', name: 'Guatemala' },
  548. { code: 'GG', name: 'Guernsey' },
  549. { code: 'GW', name: 'Guinea-Bissau' },
  550. { code: 'GN', name: 'Guinea' },
  551. { code: 'GY', name: 'Guyana' },
  552. { code: 'HT', name: 'Haiti' },
  553. { code: 'HM', name: 'Heard Island and McDonald Islands' },
  554. { code: 'HN', name: 'Honduras' },
  555. { code: 'HK', name: 'Hong Kong' },
  556. { code: 'HU', name: 'Hungary' },
  557. { code: 'IS', name: 'Iceland' },
  558. { code: 'IN', name: 'India' },
  559. { code: 'ID', name: 'Indonesia' },
  560. { code: 'IR', name: 'Iran' },
  561. { code: 'IQ', name: 'Iraq' },
  562. { code: 'IE', name: 'Ireland' },
  563. { code: 'IM', name: 'Isle of Man' },
  564. { code: 'IL', name: 'Israel' },
  565. { code: 'IT', name: 'Italy' },
  566. { code: 'CI', name: 'Ivory Coast' },
  567. { code: 'JM', name: 'Jamaica' },
  568. { code: 'JP', name: 'Japan' },
  569. { code: 'JE', name: 'Jersey' },
  570. { code: 'JT', name: 'Johnston Island' },
  571. { code: 'JO', name: 'Jordan' },
  572. { code: 'KZ', name: 'Kazakhstan' },
  573. { code: 'KE', name: 'Kenya' },
  574. { code: 'KI', name: 'Kiribati' },
  575. { code: 'KW', name: 'Kuwait' },
  576. { code: 'KG', name: 'Kyrgyzstan' },
  577. { code: 'LA', name: 'Laos' },
  578. { code: 'LV', name: 'Latvia' },
  579. { code: 'LB', name: 'Lebanon' },
  580. { code: 'LS', name: 'Lesotho' },
  581. { code: 'LR', name: 'Liberia' },
  582. { code: 'LY', name: 'Libya' },
  583. { code: 'LI', name: 'Liechtenstein' },
  584. { code: 'LT', name: 'Lithuania' },
  585. { code: 'LU', name: 'Luxembourg' },
  586. { code: 'MO', name: 'Macau SAR China' },
  587. { code: 'MO', name: 'Macau' },
  588. { code: 'MK', name: 'Macedonia [FYROM]' },
  589. { code: 'MK', name: 'Macedonia' },
  590. { code: 'MG', name: 'Madagascar' },
  591. { code: 'MW', name: 'Malawi' },
  592. { code: 'MY', name: 'Malaysia' },
  593. { code: 'MV', name: 'Maldives' },
  594. { code: 'ML', name: 'Mali' },
  595. { code: 'MT', name: 'Malta' },
  596. { code: 'MH', name: 'Marshall Islands' },
  597. { code: 'MQ', name: 'Martinique' },
  598. { code: 'MR', name: 'Mauritania' },
  599. { code: 'MU', name: 'Mauritius' },
  600. { code: 'YT', name: 'Mayotte' },
  601. { code: 'FX', name: 'Metropolitan France' },
  602. { code: 'MX', name: 'Mexico' },
  603. { code: 'FM', name: 'Micronesia' },
  604. { code: 'MI', name: 'Midway Islands' },
  605. { code: 'MD', name: 'Moldova' },
  606. { code: 'MC', name: 'Monaco' },
  607. { code: 'MN', name: 'Mongolia' },
  608. { code: 'ME', name: 'Montenegro' },
  609. { code: 'MS', name: 'Montserrat' },
  610. { code: 'MA', name: 'Morocco' },
  611. { code: 'MZ', name: 'Mozambique' },
  612. { code: 'MM', name: 'Myanmar [Burma]' },
  613. { code: 'NA', name: 'Namibia' },
  614. { code: 'NR', name: 'Nauru' },
  615. { code: 'NP', name: 'Nepal' },
  616. { code: 'AN', name: 'Netherlands Antilles' },
  617. { code: 'NL', name: 'Netherlands' },
  618. { code: 'NC', name: 'New Caledonia' },
  619. { code: 'NZ', name: 'New Zealand' },
  620. { code: 'NI', name: 'Nicaragua' },
  621. { code: 'NE', name: 'Niger' },
  622. { code: 'NG', name: 'Nigeria' },
  623. { code: 'NU', name: 'Niue' },
  624. { code: 'NF', name: 'Norfolk Island' },
  625. { code: 'KP', name: 'North Korea' },
  626. { code: 'VD', name: 'North Vietnam' },
  627. { code: 'MP', name: 'Northern Mariana Islands' },
  628. { code: 'NO', name: 'Norway' },
  629. { code: 'OM', name: 'Oman' },
  630. { code: 'QO', name: 'Outlying Oceania' },
  631. { code: 'PC', name: 'Pacific Islands Trust Territory' },
  632. { code: 'PK', name: 'Pakistan' },
  633. { code: 'PW', name: 'Palau' },
  634. { code: 'PS', name: 'Palestinian Territories' },
  635. { code: 'PZ', name: 'Panama Canal Zone' },
  636. { code: 'PA', name: 'Panama' },
  637. { code: 'PG', name: 'Papua New Guinea' },
  638. { code: 'PY', name: 'Paraguay' },
  639. { code: 'YD', name: "People's Democratic Republic of Yemen" },
  640. { code: 'PE', name: 'Peru' },
  641. { code: 'PH', name: 'Philippines' },
  642. { code: 'PN', name: 'Pitcairn Islands' },
  643. { code: 'PL', name: 'Poland' },
  644. { code: 'PT', name: 'Portugal' },
  645. { code: 'PR', name: 'Puerto Rico' },
  646. { code: 'QA', name: 'Qatar' },
  647. { code: 'RE', name: 'Réunion' },
  648. { code: 'RO', name: 'Romania' },
  649. { code: 'RU', name: 'Russia' },
  650. { code: 'RW', name: 'Rwanda' },
  651. { code: 'BL', name: 'Saint Barthélemy' },
  652. { code: 'SH', name: 'Saint Helena' },
  653. { code: 'KN', name: 'Saint Kitts and Nevis' },
  654. { code: 'LC', name: 'Saint Lucia' },
  655. { code: 'MF', name: 'Saint Martin' },
  656. { code: 'PM', name: 'Saint Pierre and Miquelon' },
  657. { code: 'VC', name: 'Saint Vincent and the Grenadines' },
  658. { code: 'WS', name: 'Samoa' },
  659. { code: 'SM', name: 'San Marino' },
  660. { code: 'ST', name: 'São Tomé and Príncipe' },
  661. { code: 'SA', name: 'Saudi Arabia' },
  662. { code: 'SN', name: 'Senegal' },
  663. { code: 'CS', name: 'Serbia and Montenegro' },
  664. { code: 'RS', name: 'Serbia' },
  665. { code: 'SC', name: 'Seychelles' },
  666. { code: 'SL', name: 'Sierra Leone' },
  667. { code: 'SG', name: 'Singapore' },
  668. { code: 'SK', name: 'Slovakia' },
  669. { code: 'SI', name: 'Slovenia' },
  670. { code: 'SB', name: 'Solomon Islands' },
  671. { code: 'SO', name: 'Somalia' },
  672. { code: 'ZA', name: 'South Africa' },
  673. { code: 'GS', name: 'South Georgia and the South Sandwich Islands' },
  674. { code: 'KR', name: 'South Korea' },
  675. { code: 'ES', name: 'Spain' },
  676. { code: 'LK', name: 'Sri Lanka' },
  677. { code: 'SD', name: 'Sudan' },
  678. { code: 'SR', name: 'Suriname' },
  679. { code: 'SJ', name: 'Svalbard and Jan Mayen' },
  680. { code: 'SZ', name: 'Swaziland' },
  681. { code: 'SE', name: 'Sweden' },
  682. { code: 'CH', name: 'Switzerland' },
  683. { code: 'SY', name: 'Syria' },
  684. { code: 'TW', name: 'Taiwan' },
  685. { code: 'TJ', name: 'Tajikistan' },
  686. { code: 'TZ', name: 'Tanzania' },
  687. { code: 'TH', name: 'Thailand' },
  688. { code: 'TL', name: 'Timor-Leste' },
  689. { code: 'TG', name: 'Togo' },
  690. { code: 'TK', name: 'Tokelau' },
  691. { code: 'TO', name: 'Tonga' },
  692. { code: 'TT', name: 'Trinidad and Tobago' },
  693. { code: 'TA', name: 'Tristan da Cunha' },
  694. { code: 'TN', name: 'Tunisia' },
  695. { code: 'TR', name: 'Turkey' },
  696. { code: 'TM', name: 'Turkmenistan' },
  697. { code: 'TC', name: 'Turks and Caicos Islands' },
  698. { code: 'TV', name: 'Tuvalu' },
  699. { code: 'UM', name: 'U.S. Minor Outlying Islands' },
  700. { code: 'PU', name: 'U.S. Miscellaneous Pacific Islands' },
  701. { code: 'VI', name: 'U.S. Virgin Islands' },
  702. { code: 'UG', name: 'Uganda' },
  703. { code: 'UA', name: 'Ukraine' },
  704. { code: 'AE', name: 'United Arab Emirates' },
  705. { code: 'GB', name: 'United Kingdom' },
  706. { code: 'US', name: 'United States' },
  707. { code: 'UY', name: 'Uruguay' },
  708. { code: 'UZ', name: 'Uzbekistan' },
  709. { code: 'VU', name: 'Vanuatu' },
  710. { code: 'VA', name: 'Vatican City' },
  711. { code: 'VE', name: 'Venezuela' },
  712. { code: 'VN', name: 'Vietnam' },
  713. { code: 'WK', name: 'Wake Island' },
  714. { code: 'WF', name: 'Wallis and Futuna' },
  715. { code: 'EH', name: 'Western Sahara' },
  716. { code: 'YE', name: 'Yemen' },
  717. { code: 'ZM', name: 'Zambia' },
  718. { code: 'ZW', name: 'Zimbabwe' },
  719. ]
  720. }
  721. )
  722. App.controller(
  723. 'StudentCheckModalController',
  724. function ($scope, $modalInstance, eventTracking) {
  725. $modalInstance.rendered.then(() => {
  726. eventTracking.sendMB('student-check-displayed')
  727. })
  728. $scope.browsePlans = () => {
  729. if (document.referrer?.includes('/user/subscription/choose-your-plan')) {
  730. // redirect to interstitial page with `itm_referrer` param
  731. assign(
  732. '/user/subscription/choose-your-plan?itm_referrer=student-status-declined'
  733. )
  734. } else {
  735. // redirect to plans page with `itm_referrer` param
  736. assign('/user/subscription/plans?itm_referrer=student-status-declined')
  737. }
  738. }
  739. $scope.confirm = () => $modalInstance.dismiss('cancel')
  740. }
  741. )