salesTax.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import {t} from 'sentry/locale';
  2. import type {BillingDetails} from 'getsentry/types';
  3. type TaxFieldInfo = {
  4. label: React.ReactNode;
  5. placeholder: React.ReactNode;
  6. taxNumberName: React.ReactNode;
  7. };
  8. const getTaxFieldInfo = (countryCode?: BillingDetails['countryCode']): TaxFieldInfo =>
  9. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  10. countryCode ? SALES_TAX_COUNTRY_INFO[countryCode] || taxInfo.DEFAULT : taxInfo.DEFAULT;
  11. const countryHasSalesTax = (countryCode?: BillingDetails['countryCode']): boolean =>
  12. countryCode ? countryCode in SALES_TAX_COUNTRY_INFO : false;
  13. const taxInfo = {
  14. ABN: {
  15. label: t('ABN'),
  16. placeholder: t('ABN'),
  17. taxNumberName: t('Australian Business Number'),
  18. },
  19. BRN: {
  20. label: t('BRN'),
  21. placeholder: t('BRN'),
  22. taxNumberName: t('Business Registration Number'),
  23. },
  24. GST: {
  25. label: t('GST Number'),
  26. placeholder: t('GST number'),
  27. taxNumberName: t('Goods and Services Tax Number'),
  28. },
  29. GSTHST: {
  30. label: t('GST/HST Number'),
  31. placeholder: t('GST/HST number'),
  32. taxNumberName: t('Goods and Services or Harmonized Sales Tax Number'),
  33. },
  34. GUIUBN: {
  35. label: t('GUI/UBN Number'),
  36. placeholder: t('GUI/UBN number'),
  37. taxNumberName: t('Government Unified Invoices or Unified Business Number'),
  38. },
  39. CT: {
  40. label: t('CT Number'),
  41. placeholder: t('CT number'),
  42. taxNumberName: t('Consumption Tax Number'),
  43. },
  44. TIN: {
  45. label: t('TIN'),
  46. placeholder: t('TIN'),
  47. taxNumberName: t('Taxpayer Identification Number'),
  48. },
  49. TRN: {
  50. label: t('TRN'),
  51. placeholder: t('TRN'),
  52. taxNumberName: t('Taxpayer Registration Number'),
  53. },
  54. VAT: {
  55. label: t('VAT Number'),
  56. placeholder: t('VAT number'),
  57. taxNumberName: t('Value-Added Tax Number'),
  58. },
  59. DEFAULT: {
  60. label: t('Tax Number'),
  61. placeholder: t('Tax number'),
  62. taxNumberName: t('Tax Identification Number'),
  63. },
  64. };
  65. const SALES_TAX_COUNTRY_INFO = {
  66. AE: taxInfo.TRN,
  67. AT: taxInfo.VAT,
  68. AU: taxInfo.ABN,
  69. BE: taxInfo.VAT,
  70. BG: taxInfo.VAT,
  71. CA: taxInfo.GSTHST,
  72. CL: taxInfo.TIN,
  73. CY: taxInfo.VAT,
  74. CZ: taxInfo.VAT,
  75. DE: taxInfo.VAT,
  76. DK: taxInfo.VAT,
  77. EE: taxInfo.VAT,
  78. ES: taxInfo.VAT,
  79. FI: taxInfo.VAT,
  80. FR: taxInfo.VAT,
  81. GB: taxInfo.VAT,
  82. GE: taxInfo.VAT,
  83. GR: taxInfo.VAT,
  84. HR: taxInfo.VAT,
  85. HU: taxInfo.VAT,
  86. IE: taxInfo.VAT,
  87. IN: taxInfo.VAT,
  88. IS: taxInfo.VAT,
  89. IT: taxInfo.VAT,
  90. JP: taxInfo.CT,
  91. KR: taxInfo.BRN,
  92. LT: taxInfo.VAT,
  93. LU: taxInfo.VAT,
  94. LV: taxInfo.VAT,
  95. MT: taxInfo.VAT,
  96. NL: taxInfo.VAT,
  97. NO: taxInfo.VAT,
  98. PL: taxInfo.VAT,
  99. PT: taxInfo.VAT,
  100. RO: taxInfo.VAT,
  101. SA: taxInfo.VAT,
  102. SE: taxInfo.VAT,
  103. SG: taxInfo.GST,
  104. SI: taxInfo.VAT,
  105. SK: taxInfo.VAT,
  106. TH: taxInfo.VAT,
  107. TR: taxInfo.VAT,
  108. TW: taxInfo.GUIUBN,
  109. };
  110. const REGION_BY_COUNTRY_CODE = {
  111. US: {
  112. AL: 'Alabama',
  113. AK: 'Alaska',
  114. AS: 'American Samoa',
  115. AZ: 'Arizona',
  116. AR: 'Arkansas',
  117. CA: 'California',
  118. CO: 'Colorado',
  119. CT: 'Connecticut',
  120. DE: 'Delaware',
  121. FL: 'Florida',
  122. GA: 'Georgia',
  123. GU: 'Guam',
  124. HI: 'Hawaii',
  125. ID: 'Idaho',
  126. IL: 'Illinois',
  127. IN: 'Indiana',
  128. IA: 'Iowa',
  129. KS: 'Kansas',
  130. KY: 'Kentucky',
  131. LA: 'Louisiana',
  132. ME: 'Maine',
  133. MD: 'Maryland',
  134. MA: 'Massachusetts',
  135. MI: 'Michigan',
  136. FM: 'Micronesia',
  137. MN: 'Minnesota',
  138. MS: 'Mississippi',
  139. MO: 'Missouri',
  140. MT: 'Montana',
  141. NE: 'Nebraska',
  142. NV: 'Nevada',
  143. NH: 'New Hampshire',
  144. NJ: 'New Jersey',
  145. NM: 'New Mexico',
  146. NY: 'New York',
  147. NC: 'North Carolina',
  148. ND: 'North Dakota',
  149. MP: 'Northern Mariana Islands',
  150. OH: 'Ohio',
  151. OK: 'Oklahoma',
  152. OR: 'Oregon',
  153. PA: 'Pennsylvania',
  154. PR: 'Puerto Rico',
  155. RI: 'Rhode Island',
  156. SC: 'South Carolina',
  157. SD: 'South Dakota',
  158. TN: 'Tennessee',
  159. TX: 'Texas',
  160. UT: 'Utah',
  161. VI: 'Virgin Islands',
  162. VT: 'Vermont',
  163. VA: 'Virginia',
  164. WA: 'Washington',
  165. DC: 'Washington DC',
  166. WV: 'West Virginia',
  167. WI: 'Wisconsin',
  168. WY: 'Wyoming',
  169. },
  170. CA: {
  171. AB: 'Alberta',
  172. BC: 'British Columbia',
  173. MB: 'Manitoba',
  174. NB: 'New Brunswick',
  175. NL: 'Newfoundland and Labrador',
  176. NT: 'Northwest Territories',
  177. NS: 'Nova Scotia',
  178. NU: 'Nunavut',
  179. ON: 'Ontario',
  180. PE: 'Prince Edward Island',
  181. QC: 'Quebec',
  182. SK: 'Saskatchewan',
  183. YT: 'Yukon',
  184. },
  185. };
  186. function countryHasRegionChoices(
  187. countryCode?: BillingDetails['countryCode']
  188. ): countryCode is string {
  189. return !!countryCode && countryCode in REGION_BY_COUNTRY_CODE;
  190. }
  191. function getRegionChoices(countryCode?: BillingDetails['countryCode']) {
  192. return countryHasRegionChoices(countryCode)
  193. ? // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  194. Object.entries(REGION_BY_COUNTRY_CODE[countryCode])
  195. : [];
  196. }
  197. function getRegionChoiceCode(
  198. countryCode?: BillingDetails['countryCode'],
  199. region?: BillingDetails['region']
  200. ) {
  201. return countryHasRegionChoices(countryCode) &&
  202. !!region &&
  203. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  204. region in REGION_BY_COUNTRY_CODE[countryCode]
  205. ? region
  206. : undefined;
  207. }
  208. function getRegionChoiceName(
  209. countryCode?: BillingDetails['countryCode'],
  210. region?: BillingDetails['region']
  211. ) {
  212. return countryHasRegionChoices(countryCode) &&
  213. !!region &&
  214. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  215. region in REGION_BY_COUNTRY_CODE[countryCode]
  216. ? // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  217. REGION_BY_COUNTRY_CODE[countryCode][region]
  218. : region;
  219. }
  220. export {
  221. countryHasRegionChoices,
  222. countryHasSalesTax,
  223. getRegionChoices,
  224. getRegionChoiceCode,
  225. getRegionChoiceName,
  226. getTaxFieldInfo,
  227. type TaxFieldInfo,
  228. };