new-subscription.js 28 KB

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