@xsolla/payment-client-core 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/esm2020/lib/core/credit-card/credit-card-settings.interface.mjs +2 -0
  2. package/esm2020/lib/core/credit-card/credit-card-types.enum.mjs +20 -0
  3. package/esm2020/lib/core/credit-card/credit-card.interface.mjs +2 -0
  4. package/esm2020/lib/core/credit-card/credit-card.service.mjs +41 -0
  5. package/esm2020/lib/core/credit-card/credit-cards-map.const.mjs +36 -0
  6. package/esm2020/lib/core/credit-card/default-mask.const.mjs +2 -0
  7. package/esm2020/lib/core/credit-card/four-block-mask.const.mjs +2 -0
  8. package/esm2020/lib/core/credit-card/ordered-cards-settings.const.mjs +45 -0
  9. package/esm2020/lib/core/credit-card/types/american-express.mjs +13 -0
  10. package/esm2020/lib/core/credit-card/types/aura.mjs +15 -0
  11. package/esm2020/lib/core/credit-card/types/china-union-pay.mjs +12 -0
  12. package/esm2020/lib/core/credit-card/types/dankort.mjs +15 -0
  13. package/esm2020/lib/core/credit-card/types/default-card.mjs +13 -0
  14. package/esm2020/lib/core/credit-card/types/diners-clubs.mjs +13 -0
  15. package/esm2020/lib/core/credit-card/types/discover.mjs +13 -0
  16. package/esm2020/lib/core/credit-card/types/elo.mjs +13 -0
  17. package/esm2020/lib/core/credit-card/types/hipercard.mjs +13 -0
  18. package/esm2020/lib/core/credit-card/types/jcb.mjs +13 -0
  19. package/esm2020/lib/core/credit-card/types/maestro.mjs +14 -0
  20. package/esm2020/lib/core/credit-card/types/mastercard.mjs +16 -0
  21. package/esm2020/lib/core/credit-card/types/mir.mjs +15 -0
  22. package/esm2020/lib/core/credit-card/types/naranja.mjs +15 -0
  23. package/esm2020/lib/core/credit-card/types/postepay.mjs +13 -0
  24. package/esm2020/lib/core/credit-card/types/visa.mjs +13 -0
  25. package/esm2020/lib/core/payment/credit-card-state/credit-card-state.interface.mjs +2 -0
  26. package/esm2020/lib/core/payment/credit-card-state/credit-card-state.service.mjs +14 -0
  27. package/esm2020/lib/core/payment/form/controls/card-number-control.config.mjs +10 -0
  28. package/esm2020/lib/core/payment/form/converters/card-number.converter.mjs +45 -0
  29. package/esm2020/lib/core/payment/form/converters/converters-map.mjs +3 -1
  30. package/esm2020/lib/core/payment/form/form.module.mjs +8 -4
  31. package/esm2020/lib/core/payment/form/validators/credit-card-min-length.validator.mjs +32 -0
  32. package/esm2020/lib/core/payment/form/validators/is-empty-input-value.function.mjs +4 -0
  33. package/esm2020/lib/core/payment/form/validators/luhn-formula-validator/luhn-formula.validator.mjs +40 -0
  34. package/esm2020/lib/core/payment/form/validators/validators.module.mjs +18 -0
  35. package/esm2020/lib/core/payment/payment.service.mjs +23 -7
  36. package/esm2020/lib/core/payment/sync/field-async-validation.interface.mjs +2 -0
  37. package/esm2020/lib/core/payment/sync/sync.service.mjs +11 -2
  38. package/esm2020/lib/core/payment/xps-response.interface.mjs +1 -1
  39. package/esm2020/lib/core/type-guards/is-string.function.mjs +4 -0
  40. package/esm2020/lib/core-library.service.mjs +18 -4
  41. package/fesm2015/xsolla-payment-client-core.mjs +494 -10
  42. package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
  43. package/fesm2020/xsolla-payment-client-core.mjs +493 -10
  44. package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
  45. package/lib/core/credit-card/credit-card-settings.interface.d.ts +10 -0
  46. package/lib/core/credit-card/credit-card-types.enum.d.ts +18 -0
  47. package/lib/core/credit-card/credit-card.interface.d.ts +9 -0
  48. package/lib/core/credit-card/credit-card.service.d.ts +11 -0
  49. package/lib/core/credit-card/credit-cards-map.const.d.ts +5 -0
  50. package/lib/core/credit-card/default-mask.const.d.ts +1 -0
  51. package/lib/core/credit-card/four-block-mask.const.d.ts +1 -0
  52. package/lib/core/credit-card/ordered-cards-settings.const.d.ts +12 -0
  53. package/lib/core/credit-card/types/american-express.d.ts +2 -0
  54. package/lib/core/credit-card/types/aura.d.ts +2 -0
  55. package/lib/core/credit-card/types/china-union-pay.d.ts +2 -0
  56. package/lib/core/credit-card/types/dankort.d.ts +2 -0
  57. package/lib/core/credit-card/types/default-card.d.ts +2 -0
  58. package/lib/core/credit-card/types/diners-clubs.d.ts +2 -0
  59. package/lib/core/credit-card/types/discover.d.ts +2 -0
  60. package/lib/core/credit-card/types/elo.d.ts +2 -0
  61. package/lib/core/credit-card/types/hipercard.d.ts +2 -0
  62. package/lib/core/credit-card/types/jcb.d.ts +2 -0
  63. package/lib/core/credit-card/types/maestro.d.ts +2 -0
  64. package/lib/core/credit-card/types/mastercard.d.ts +2 -0
  65. package/lib/core/credit-card/types/mir.d.ts +2 -0
  66. package/lib/core/credit-card/types/naranja.d.ts +2 -0
  67. package/lib/core/credit-card/types/postepay.d.ts +2 -0
  68. package/lib/core/credit-card/types/visa.d.ts +2 -0
  69. package/lib/core/payment/credit-card-state/credit-card-state.interface.d.ts +3 -0
  70. package/lib/core/payment/credit-card-state/credit-card-state.service.d.ts +7 -0
  71. package/lib/core/payment/form/controls/card-number-control.config.d.ts +11 -0
  72. package/lib/core/payment/form/converters/card-number.converter.d.ts +19 -0
  73. package/lib/core/payment/form/form.module.d.ts +2 -1
  74. package/lib/core/payment/form/validators/credit-card-min-length.validator.d.ts +12 -0
  75. package/lib/core/payment/form/validators/is-empty-input-value.function.d.ts +1 -0
  76. package/lib/core/payment/form/validators/luhn-formula-validator/luhn-formula.validator.d.ts +6 -0
  77. package/lib/core/payment/form/validators/validators.module.d.ts +7 -0
  78. package/lib/core/payment/payment.service.d.ts +4 -1
  79. package/lib/core/payment/sync/field-async-validation.interface.d.ts +7 -0
  80. package/lib/core/payment/sync/sync.service.d.ts +4 -0
  81. package/lib/core/payment/xps-response.interface.d.ts +1 -0
  82. package/lib/core/type-guards/is-string.function.d.ts +1 -0
  83. package/lib/core-library.service.d.ts +10 -1
  84. package/package.json +1 -1
  85. package/xsolla-payment-client-core-0.1.4.tgz +0 -0
  86. package/xsolla-payment-client-core-0.1.3.tgz +0 -0
@@ -7,6 +7,7 @@ import { HttpParams, HttpHeaders, HttpClientModule, HTTP_INTERCEPTORS } from '@a
7
7
  import { UntypedFormGroup, Validators, UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
8
8
  import { filter, map as map$1, catchError } from 'rxjs/operators';
9
9
  import * as i1$1 from '@angular/router';
10
+ import { CommonModule } from '@angular/common';
10
11
 
11
12
  const masksFunctionsMap = {
12
13
  zip: () => {
@@ -1283,6 +1284,10 @@ class SyncService extends EmitDataService {
1283
1284
  this.prevFieldSyncStates = {};
1284
1285
  this.form = new UntypedFormGroup({});
1285
1286
  this.fields = [];
1287
+ this.fieldAsyncValidation = new Subject();
1288
+ }
1289
+ get fieldAsyncValidation$() {
1290
+ return this.fieldAsyncValidation.asObservable();
1286
1291
  }
1287
1292
  setup(form, fields) {
1288
1293
  this.reset();
@@ -1316,6 +1321,11 @@ class SyncService extends EmitDataService {
1316
1321
  this.setPrevFieldSyncState(field, value, requestPromise);
1317
1322
  return requestPromise.then((response) => {
1318
1323
  var _a;
1324
+ this.fieldAsyncValidation.next({
1325
+ value,
1326
+ field,
1327
+ response,
1328
+ });
1319
1329
  return (_a = response.error) !== null && _a !== void 0 ? _a : null;
1320
1330
  });
1321
1331
  });
@@ -1571,10 +1581,431 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
1571
1581
  type: Injectable
1572
1582
  }], ctorParameters: function () { return [{ type: SyncService }, { type: CountryService }]; } });
1573
1583
 
1584
+ function isEmptyInputValue(value) {
1585
+ return value == null || value.length === 0;
1586
+ }
1587
+
1588
+ function isString(value) {
1589
+ return typeof value === 'string';
1590
+ }
1591
+
1592
+ /**
1593
+ * Checks number match Luhn algorithm.
1594
+ * Based on http://en.wikipedia.org/wiki/Luhn.
1595
+ */
1596
+ const luhnFormulaValidator = ({ value }) => {
1597
+ if (isEmptyInputValue(value) || !isString(value)) {
1598
+ return null;
1599
+ }
1600
+ const error = {
1601
+ rewritableError: {
1602
+ message: `Enter a valid card number`,
1603
+ },
1604
+ };
1605
+ if (/[^0-9 -]+/.test(value)) {
1606
+ // accept only spaces, digits and dashes
1607
+ return error;
1608
+ }
1609
+ let resultSum = 0;
1610
+ let digit = 0;
1611
+ let isEven = false;
1612
+ const modBase = 10;
1613
+ const digitRadix = 10;
1614
+ const maxNumber = 9;
1615
+ const digits = value.replace(/\D/g, '');
1616
+ // Checks if number match Luhn algorithm
1617
+ // based on http://en.wikipedia.org/wiki/Luhn
1618
+ for (let index = digits.length - 1; index >= 0; index--) {
1619
+ const char = digits.charAt(index);
1620
+ digit = parseInt(char, digitRadix);
1621
+ if (isEven && (digit *= 2) > maxNumber) {
1622
+ digit -= maxNumber;
1623
+ }
1624
+ resultSum += digit;
1625
+ isEven = !isEven;
1626
+ }
1627
+ return resultSum % modBase === 0 ? null : error;
1628
+ };
1629
+
1630
+ class CardNumberConfig extends ControlConfig {
1631
+ constructor() {
1632
+ super(...arguments);
1633
+ this.controlType = 'card-number';
1634
+ this.availableCardTypes = [];
1635
+ this.customError = '';
1636
+ }
1637
+ }
1638
+
1639
+ const fourBlockMask = '9999 9999 9999 9999';
1640
+
1641
+ var CreditCardTypes;
1642
+ (function (CreditCardTypes) {
1643
+ CreditCardTypes["DEFAULT"] = "0";
1644
+ CreditCardTypes["VISA"] = "1";
1645
+ CreditCardTypes["MASTERCARD"] = "2";
1646
+ CreditCardTypes["MAESTRO"] = "3";
1647
+ CreditCardTypes["AMERICAN_EXPRESS"] = "4";
1648
+ CreditCardTypes["DINERS_CLUBS"] = "5";
1649
+ CreditCardTypes["DISCOVER"] = "6";
1650
+ CreditCardTypes["JCB"] = "9";
1651
+ CreditCardTypes["DANKORT"] = "11";
1652
+ CreditCardTypes["HIPERCARD"] = "12";
1653
+ CreditCardTypes["ELO"] = "13";
1654
+ CreditCardTypes["AURA"] = "14";
1655
+ CreditCardTypes["NARANJA"] = "15";
1656
+ CreditCardTypes["MIR"] = "16";
1657
+ CreditCardTypes["CHINA_UNION_PAY"] = "17";
1658
+ CreditCardTypes["POSTEPAY"] = "18";
1659
+ })(CreditCardTypes || (CreditCardTypes = {}));
1660
+
1661
+ const visa = {
1662
+ id: CreditCardTypes.VISA,
1663
+ minLength: 13,
1664
+ maxLength: 16,
1665
+ iconName: 'visa',
1666
+ mask: fourBlockMask,
1667
+ checkNumber(number) {
1668
+ return number.startsWith('4');
1669
+ },
1670
+ };
1671
+
1672
+ const mastercard = {
1673
+ id: CreditCardTypes.MASTERCARD,
1674
+ minLength: 16,
1675
+ maxLength: 16,
1676
+ iconName: 'mastercard',
1677
+ mask: fourBlockMask,
1678
+ checkNumber(number) {
1679
+ const subLength = 6;
1680
+ const cardNumberSub = number.substring(0, subLength);
1681
+ return (new RegExp(/^5[1-5]/).test(number) ||
1682
+ (cardNumberSub >= '222100' && cardNumberSub <= '272099'));
1683
+ },
1684
+ };
1685
+
1686
+ const defaultMask = '9999 9999 9999 9999 999';
1687
+
1688
+ const maestro = {
1689
+ id: CreditCardTypes.MAESTRO,
1690
+ minLength: 12,
1691
+ maxLength: 19,
1692
+ iconName: 'maestro',
1693
+ mask: defaultMask,
1694
+ checkNumber(number) {
1695
+ return new RegExp(/^(5018)|^(5020)|^(5038)|^(5893)|^(6304)|^(6759)|^(6761)|^(6762)|^(6763)|^(0604)|^(6706)|^(6771)|^(6709)/).test(number);
1696
+ },
1697
+ maxCvvLength: 3,
1698
+ };
1699
+
1700
+ const americanExpress = {
1701
+ id: CreditCardTypes.AMERICAN_EXPRESS,
1702
+ minLength: 15,
1703
+ maxLength: 15,
1704
+ iconName: 'american-express',
1705
+ mask: '9999 999999 99999',
1706
+ checkNumber(number) {
1707
+ return new RegExp(/^(34)|^(37)/).test(number);
1708
+ },
1709
+ maxCvvLength: 4,
1710
+ };
1711
+
1712
+ const dinersClubs = {
1713
+ id: CreditCardTypes.DINERS_CLUBS,
1714
+ minLength: 14,
1715
+ maxLength: 14,
1716
+ iconName: 'dinersclub',
1717
+ mask: '9999 9999 9999 99',
1718
+ checkNumber(number) {
1719
+ const regex = /^(36[0-9]|3(?:0[0-59]|[68][0-9])[0-9])/;
1720
+ return regex.test(number);
1721
+ },
1722
+ };
1723
+
1724
+ const discover = {
1725
+ id: CreditCardTypes.DISCOVER,
1726
+ minLength: 16,
1727
+ maxLength: 19,
1728
+ iconName: 'discover',
1729
+ mask: defaultMask,
1730
+ checkNumber(number) {
1731
+ return new RegExp(/^(6011)|^(622(1(2[6-9]|[3-9][0-9])|[2-8][0-9]{2}|9([01][0-9]|2[0-5])))|^(64[4-9])|^65/).test(number);
1732
+ },
1733
+ };
1734
+
1735
+ const jcb = {
1736
+ id: CreditCardTypes.JCB,
1737
+ minLength: 15,
1738
+ maxLength: 16,
1739
+ iconName: 'jcb',
1740
+ mask: fourBlockMask,
1741
+ checkNumber(number) {
1742
+ return new RegExp(/^35(2[89]|[3-8][0-9])/).test(number);
1743
+ },
1744
+ };
1745
+
1746
+ const dankort = {
1747
+ id: CreditCardTypes.DANKORT,
1748
+ minLength: 16,
1749
+ maxLength: 16,
1750
+ iconName: 'dankort',
1751
+ mask: fourBlockMask,
1752
+ checkNumber(number) {
1753
+ const subLength = 4;
1754
+ const cardNumberSub = number.substring(0, subLength);
1755
+ return cardNumberSub === '5019';
1756
+ },
1757
+ };
1758
+
1759
+ const hipercard = {
1760
+ id: CreditCardTypes.HIPERCARD,
1761
+ minLength: 13,
1762
+ maxLength: 19,
1763
+ iconName: 'hipercard',
1764
+ mask: defaultMask,
1765
+ checkNumber(number) {
1766
+ return new RegExp(/^((606282|637095|637568)[0-9]|38[0-9]{14,17})/).test(number);
1767
+ },
1768
+ };
1769
+
1770
+ const elo = {
1771
+ id: CreditCardTypes.ELO,
1772
+ minLength: 16,
1773
+ maxLength: 19,
1774
+ iconName: 'elo',
1775
+ mask: defaultMask,
1776
+ checkNumber(number) {
1777
+ return new RegExp(/^(40117[8-9]|431274|438935|451416|457393|45763[1-2]|506(699|7[0-6][0-9]|77[0-8])|509\d{3}|504175|627780|636297|636368|65003[1-3]|6500(3[5-9]|4[0-9]|5[0-1])|6504(0[5-9]|[1-3][0-9])|650(4[8-9][0-9]|5[0-2][0-9]|53[0-8])|6505(4[1-9]|[5-8][0-9]|9[0-8])|6507(0[0-9]|1[0-8])|65072[0-7]|6509(0[1-9]|1[0-9]|20)|6516(5[2-9]|[6-7][0-9])|6550([0-1][0-9]|2[1-9]|[3-4][0-9]|5[0-8]))/).test(number);
1778
+ },
1779
+ };
1780
+
1781
+ const aura = {
1782
+ id: CreditCardTypes.AURA,
1783
+ minLength: 16,
1784
+ maxLength: 19,
1785
+ iconName: 'aura',
1786
+ mask: defaultMask,
1787
+ checkNumber(number) {
1788
+ const subLength = 8;
1789
+ const cardNumberSub = number.substring(0, subLength);
1790
+ return ['50786000', '50786018', '50786019'].includes(cardNumberSub);
1791
+ },
1792
+ };
1793
+
1794
+ const naranja = {
1795
+ id: CreditCardTypes.NARANJA,
1796
+ minLength: 12,
1797
+ maxLength: 19,
1798
+ iconName: 'naranja',
1799
+ mask: defaultMask,
1800
+ checkNumber(number) {
1801
+ const subLength = 6;
1802
+ const cardNumberSub = number.substring(0, subLength);
1803
+ return cardNumberSub === '589562';
1804
+ },
1805
+ };
1806
+
1807
+ const mir = {
1808
+ id: CreditCardTypes.MIR,
1809
+ minLength: 16,
1810
+ maxLength: 16,
1811
+ iconName: 'mir',
1812
+ mask: defaultMask,
1813
+ checkNumber(number) {
1814
+ const subLength = 4;
1815
+ const cardNumberSub = number.substring(0, subLength);
1816
+ return cardNumberSub >= '2200' && cardNumberSub <= '2204';
1817
+ },
1818
+ };
1819
+
1820
+ const chinaUnionPay = {
1821
+ id: CreditCardTypes.CHINA_UNION_PAY,
1822
+ minLength: 16,
1823
+ maxLength: 19,
1824
+ iconName: 'unionpay',
1825
+ mask: '999 9999 9999 99999999',
1826
+ checkNumber(number) {
1827
+ return number.startsWith('62');
1828
+ },
1829
+ };
1830
+
1831
+ const defaultCard = {
1832
+ id: CreditCardTypes.DEFAULT,
1833
+ minLength: 12,
1834
+ maxLength: 19,
1835
+ iconName: null,
1836
+ mask: defaultMask,
1837
+ checkNumber() {
1838
+ return false;
1839
+ },
1840
+ };
1841
+
1842
+ const postePay = {
1843
+ id: CreditCardTypes.POSTEPAY,
1844
+ minLength: 12,
1845
+ maxLength: 19,
1846
+ iconName: 'poste_pay',
1847
+ mask: '9999 9999 9999 9999 999',
1848
+ checkNumber(number) {
1849
+ const regex = /^(5018)|^(5020)|^(5038)|^(5893)|^(6304)|^(6759)|^(6761)|^(6762)|^(6763)|^(0604)|^(6706)|^(6771)|^(6709)/;
1850
+ return regex.test(number);
1851
+ },
1852
+ };
1853
+
1854
+ /**
1855
+ * order does matter
1856
+ * settings with more specific pattern should be placed above
1857
+ * Example:
1858
+ * - 12*
1859
+ * - 12
1860
+ * - 1
1861
+ * "12*" pattern should be checked first, otherwise pattern "1" will be taken
1862
+ * before "12*" checked
1863
+ */
1864
+ const orderedCardSettings = [
1865
+ aura,
1866
+ naranja,
1867
+ maestro,
1868
+ postePay,
1869
+ elo,
1870
+ discover,
1871
+ dankort,
1872
+ hipercard,
1873
+ mir,
1874
+ jcb,
1875
+ dinersClubs,
1876
+ americanExpress,
1877
+ mastercard,
1878
+ chinaUnionPay,
1879
+ visa,
1880
+ defaultCard,
1881
+ ];
1882
+
1883
+ const creditCardsMap = {
1884
+ [CreditCardTypes.DEFAULT]: defaultCard,
1885
+ [CreditCardTypes.VISA]: visa,
1886
+ [CreditCardTypes.MASTERCARD]: mastercard,
1887
+ [CreditCardTypes.MAESTRO]: maestro,
1888
+ [CreditCardTypes.AMERICAN_EXPRESS]: americanExpress,
1889
+ [CreditCardTypes.DINERS_CLUBS]: dinersClubs,
1890
+ [CreditCardTypes.DISCOVER]: discover,
1891
+ [CreditCardTypes.JCB]: jcb,
1892
+ [CreditCardTypes.DANKORT]: dankort,
1893
+ [CreditCardTypes.HIPERCARD]: hipercard,
1894
+ [CreditCardTypes.ELO]: elo,
1895
+ [CreditCardTypes.AURA]: aura,
1896
+ [CreditCardTypes.NARANJA]: naranja,
1897
+ [CreditCardTypes.MIR]: mir,
1898
+ [CreditCardTypes.CHINA_UNION_PAY]: chinaUnionPay,
1899
+ [CreditCardTypes.POSTEPAY]: postePay,
1900
+ };
1901
+
1902
+ class CreditCardService {
1903
+ getBinNumber(cardNumber) {
1904
+ const binNumberLength = 6;
1905
+ return cardNumber.replace(/\s+/g, '').substring(0, binNumberLength);
1906
+ }
1907
+ getAccountSuffix(cardNumber) {
1908
+ const accountSuffixLength = 4;
1909
+ return cardNumber
1910
+ .replace(/\s+/g, '')
1911
+ .substring(cardNumber.length - accountSuffixLength);
1912
+ }
1913
+ getTypeByNumber(cardNumber) {
1914
+ cardNumber = cardNumber.replace(/\s+/g, '');
1915
+ const cardSettings = orderedCardSettings.find((settings) => {
1916
+ const isNumberMatched = settings.checkNumber(cardNumber);
1917
+ return isNumberMatched ? settings.id : false;
1918
+ });
1919
+ return cardSettings ? cardSettings.id : defaultCard.id;
1920
+ }
1921
+ getCreditCardSettings(cardType) {
1922
+ const creditCard = creditCardsMap[cardType];
1923
+ if (!creditCard) {
1924
+ return defaultCard;
1925
+ }
1926
+ return creditCard;
1927
+ }
1928
+ }
1929
+ CreditCardService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1930
+ CreditCardService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardService, providedIn: 'root' });
1931
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardService, decorators: [{
1932
+ type: Injectable,
1933
+ args: [{
1934
+ providedIn: 'root',
1935
+ }]
1936
+ }] });
1937
+
1938
+ class CreditCardMinLengthValidator {
1939
+ constructor(creditService) {
1940
+ this.creditService = creditService;
1941
+ this.validate = (field) => {
1942
+ if (isEmptyInputValue(field.value) || !isString(field.value)) {
1943
+ return null;
1944
+ }
1945
+ const length = field.value.length;
1946
+ const cardType = this.creditService.getTypeByNumber(field.value);
1947
+ const { minLength } = this.creditService.getCreditCardSettings(cardType);
1948
+ return length < minLength
1949
+ ? {
1950
+ rewritableError: {
1951
+ message: `Enter at least ${minLength} characters`,
1952
+ number: minLength,
1953
+ },
1954
+ }
1955
+ : null;
1956
+ };
1957
+ }
1958
+ }
1959
+ CreditCardMinLengthValidator.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardMinLengthValidator, deps: [{ token: CreditCardService }], target: i0.ɵɵFactoryTarget.Injectable });
1960
+ CreditCardMinLengthValidator.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardMinLengthValidator });
1961
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardMinLengthValidator, decorators: [{
1962
+ type: Injectable
1963
+ }], ctorParameters: function () { return [{ type: CreditCardService }]; } });
1964
+
1965
+ class CardNumberConverter extends Converter {
1966
+ constructor(syncService, maxLengthValidator, minLengthValidator) {
1967
+ super(syncService);
1968
+ this.maxLengthValidator = maxLengthValidator;
1969
+ this.minLengthValidator = minLengthValidator;
1970
+ }
1971
+ getValidators(field) {
1972
+ return super
1973
+ .getValidators(field)
1974
+ .concat([
1975
+ luhnFormulaValidator,
1976
+ this.minLengthValidator.validate,
1977
+ this.maxLengthValidator.validate,
1978
+ ]);
1979
+ }
1980
+ createControlConfig(field, formState) {
1981
+ var _a, _b;
1982
+ const config = this.createDefaultControlConfig(CardNumberConfig, field);
1983
+ config.placeholder = config.title;
1984
+ config.availableCardTypes =
1985
+ (_a = formState === null || formState === void 0 ? void 0 : formState.availableCardTypes) !== null && _a !== void 0 ? _a : [];
1986
+ config.activeCardType = formState === null || formState === void 0 ? void 0 : formState.activeCardType;
1987
+ config.customError = formState === null || formState === void 0 ? void 0 : formState.customError;
1988
+ config.disabled = (_b = formState === null || formState === void 0 ? void 0 : formState.disabled) !== null && _b !== void 0 ? _b : false;
1989
+ return config;
1990
+ }
1991
+ getAutocomplete() {
1992
+ return 'cc-number';
1993
+ }
1994
+ getDataType() {
1995
+ return 'text';
1996
+ }
1997
+ }
1998
+ CardNumberConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardNumberConverter, deps: [{ token: SyncService }, { token: CreditCardMinLengthValidator }, { token: CreditCardMinLengthValidator }], target: i0.ɵɵFactoryTarget.Injectable });
1999
+ CardNumberConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardNumberConverter });
2000
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardNumberConverter, decorators: [{
2001
+ type: Injectable
2002
+ }], ctorParameters: function () { return [{ type: SyncService }, { type: CreditCardMinLengthValidator }, { type: CreditCardMinLengthValidator }]; } });
2003
+
1574
2004
  const convertersMapToken = new InjectionToken('ConvertersTokensMap');
1575
2005
  const convertersMap = {
1576
2006
  zip: ZipConverter,
1577
2007
  email: EmailConverter,
2008
+ card_number: CardNumberConverter,
1578
2009
  };
1579
2010
 
1580
2011
  class ControlConfigService {
@@ -3088,17 +3519,29 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
3088
3519
  }] }];
3089
3520
  } });
3090
3521
 
3522
+ class CreditCardStateService extends EmitDataService {
3523
+ }
3524
+ CreditCardStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardStateService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
3525
+ CreditCardStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardStateService, providedIn: 'root' });
3526
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardStateService, decorators: [{
3527
+ type: Injectable,
3528
+ args: [{
3529
+ providedIn: 'root',
3530
+ }]
3531
+ }] });
3532
+
3091
3533
  class PaymentService {
3092
3534
  get formFieldsStatus$() {
3093
3535
  return this.formFieldsStatusSubject.asObservable().pipe(filter$1(Boolean));
3094
3536
  }
3095
- constructor(initializeService, submitService, syncService, formService, statusService, financeDetailsService, nextActionService, controlConfigService) {
3537
+ constructor(initializeService, submitService, syncService, formService, statusService, financeDetailsService, creditCardStateService, nextActionService, controlConfigService) {
3096
3538
  this.initializeService = initializeService;
3097
3539
  this.submitService = submitService;
3098
3540
  this.syncService = syncService;
3099
3541
  this.formService = formService;
3100
3542
  this.statusService = statusService;
3101
3543
  this.financeDetailsService = financeDetailsService;
3544
+ this.creditCardStateService = creditCardStateService;
3102
3545
  this.nextActionService = nextActionService;
3103
3546
  this.controlConfigService = controlConfigService;
3104
3547
  this.form = null;
@@ -3219,6 +3662,9 @@ class PaymentService {
3219
3662
  emitFinanceDetails(summary) {
3220
3663
  this.financeDetailsService.emit(summary);
3221
3664
  }
3665
+ emitCreditCardState(idCardType) {
3666
+ this.creditCardStateService.emit({ idCardType });
3667
+ }
3222
3668
  emitFormFieldsStatus(form) {
3223
3669
  const formFieldsStatus = {};
3224
3670
  Object.keys(form.controls).forEach((name) => {
@@ -3236,7 +3682,17 @@ class PaymentService {
3236
3682
  this.syncService.setup(form, fields);
3237
3683
  this.syncService.data$
3238
3684
  .pipe(takeUntil(this.destroy$))
3239
- .subscribe((response) => this.emitFinanceDetails(response.summary));
3685
+ .subscribe((response) => {
3686
+ this.emitFinanceDetails(response.summary);
3687
+ });
3688
+ this.syncService.fieldAsyncValidation$
3689
+ .pipe(takeUntil(this.destroy$))
3690
+ .subscribe((fieldAsyncValidation) => {
3691
+ switch (fieldAsyncValidation.field.name) {
3692
+ case FieldNames.cardNumber:
3693
+ this.emitCreditCardState(fieldAsyncValidation.response.parameters.idCardType);
3694
+ }
3695
+ });
3240
3696
  }
3241
3697
  listenFinanceDetails() {
3242
3698
  this.financeDetailsService.data$
@@ -3249,14 +3705,14 @@ class PaymentService {
3249
3705
  .subscribe(() => this.emitFormFieldsStatus(form));
3250
3706
  }
3251
3707
  }
3252
- PaymentService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, deps: [{ token: InitializeService }, { token: SubmitService }, { token: SyncService }, { token: FormService }, { token: StatusService }, { token: FinanceDetailsService }, { token: NextActionService }, { token: ControlConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
3708
+ PaymentService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, deps: [{ token: InitializeService }, { token: SubmitService }, { token: SyncService }, { token: FormService }, { token: StatusService }, { token: FinanceDetailsService }, { token: CreditCardStateService }, { token: NextActionService }, { token: ControlConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
3253
3709
  PaymentService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, providedIn: 'root' });
3254
3710
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, decorators: [{
3255
3711
  type: Injectable,
3256
3712
  args: [{
3257
3713
  providedIn: 'root',
3258
3714
  }]
3259
- }], ctorParameters: function () { return [{ type: InitializeService }, { type: SubmitService }, { type: SyncService }, { type: FormService }, { type: StatusService }, { type: FinanceDetailsService }, { type: NextActionService }, { type: ControlConfigService }]; } });
3715
+ }], ctorParameters: function () { return [{ type: InitializeService }, { type: SubmitService }, { type: SyncService }, { type: FormService }, { type: StatusService }, { type: FinanceDetailsService }, { type: CreditCardStateService }, { type: NextActionService }, { type: ControlConfigService }]; } });
3260
3716
 
3261
3717
  class RefundPolicyService {
3262
3718
  constructor(settingsService) {
@@ -3364,7 +3820,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
3364
3820
  }], ctorParameters: function () { return [{ type: SettingsService }, { type: RefundPolicyService }, { type: SecureConnectionService }, { type: DisclaimerService }]; } });
3365
3821
 
3366
3822
  class CoreLibraryService {
3367
- constructor(settingsService, countryService, paymentMethodsService, savedMethodsService, userBalanceService, paymentConfigService, paymentService, deviceFingerPrintService, financeDetailsService, legalService, statusService, nextActionService) {
3823
+ constructor(settingsService, countryService, paymentMethodsService, savedMethodsService, userBalanceService, paymentConfigService, paymentService, deviceFingerPrintService, financeDetailsService, legalService, statusService, nextActionService, creditCardService, creditCardStateService) {
3368
3824
  this.settingsService = settingsService;
3369
3825
  this.countryService = countryService;
3370
3826
  this.paymentMethodsService = paymentMethodsService;
@@ -3377,6 +3833,8 @@ class CoreLibraryService {
3377
3833
  this.legalService = legalService;
3378
3834
  this.statusService = statusService;
3379
3835
  this.nextActionService = nextActionService;
3836
+ this.creditCardService = creditCardService;
3837
+ this.creditCardStateService = creditCardStateService;
3380
3838
  this.paymentMethods = {
3381
3839
  getList: () => __awaiter(this, void 0, void 0, function* () { return this.paymentMethodsService.getList(); }),
3382
3840
  getQuickMethods: () => __awaiter(this, void 0, void 0, function* () { return this.paymentMethodsService.getQuickMethods(); }),
@@ -3418,6 +3876,16 @@ class CoreLibraryService {
3418
3876
  },
3419
3877
  };
3420
3878
  }
3879
+ getCreditCardService() {
3880
+ return {
3881
+ getTypeByNumber: (cardNumber) => this.creditCardService.getTypeByNumber(cardNumber),
3882
+ getCreditCardSettings: (cardType) => this.creditCardService.getCreditCardSettings(cardType),
3883
+ cardTypeUpdates$: this.creditCardStateService.data$,
3884
+ };
3885
+ }
3886
+ get cardTypeUpdates$() {
3887
+ return this.creditCardStateService.data$;
3888
+ }
3421
3889
  getLegalComponentConfig() {
3422
3890
  return this.legalService.getLegalComponentConfig();
3423
3891
  }
@@ -3426,14 +3894,14 @@ class CoreLibraryService {
3426
3894
  return masksFunctionsMap[sanitizedName];
3427
3895
  }
3428
3896
  }
3429
- CoreLibraryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, deps: [{ token: SettingsService }, { token: CountryService }, { token: PaymentMethodsService }, { token: SavedMethodsService }, { token: UserBalanceService }, { token: PaymentConfigService }, { token: PaymentService }, { token: DeviceFingerPrintService }, { token: FinanceDetailsService }, { token: LegalService }, { token: StatusService }, { token: NextActionService }], target: i0.ɵɵFactoryTarget.Injectable });
3897
+ CoreLibraryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, deps: [{ token: SettingsService }, { token: CountryService }, { token: PaymentMethodsService }, { token: SavedMethodsService }, { token: UserBalanceService }, { token: PaymentConfigService }, { token: PaymentService }, { token: DeviceFingerPrintService }, { token: FinanceDetailsService }, { token: LegalService }, { token: StatusService }, { token: NextActionService }, { token: CreditCardService }, { token: CreditCardStateService }], target: i0.ɵɵFactoryTarget.Injectable });
3430
3898
  CoreLibraryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, providedIn: 'root' });
3431
3899
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, decorators: [{
3432
3900
  type: Injectable,
3433
3901
  args: [{
3434
3902
  providedIn: 'root',
3435
3903
  }]
3436
- }], ctorParameters: function () { return [{ type: SettingsService }, { type: CountryService }, { type: PaymentMethodsService }, { type: SavedMethodsService }, { type: UserBalanceService }, { type: PaymentConfigService }, { type: PaymentService }, { type: DeviceFingerPrintService }, { type: FinanceDetailsService }, { type: LegalService }, { type: StatusService }, { type: NextActionService }]; } });
3904
+ }], ctorParameters: function () { return [{ type: SettingsService }, { type: CountryService }, { type: PaymentMethodsService }, { type: SavedMethodsService }, { type: UserBalanceService }, { type: PaymentConfigService }, { type: PaymentService }, { type: DeviceFingerPrintService }, { type: FinanceDetailsService }, { type: LegalService }, { type: StatusService }, { type: NextActionService }, { type: CreditCardService }, { type: CreditCardStateService }]; } });
3437
3905
 
3438
3906
  class HttpError extends AppError {
3439
3907
  constructor(error, req) {
@@ -3488,26 +3956,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
3488
3956
  type: Injectable
3489
3957
  }], ctorParameters: function () { return [{ type: i1$1.Router }]; } });
3490
3958
 
3959
+ class ValidatorsModule {
3960
+ }
3961
+ ValidatorsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ValidatorsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
3962
+ ValidatorsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: ValidatorsModule, imports: [CommonModule] });
3963
+ ValidatorsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ValidatorsModule, providers: [CreditCardMinLengthValidator], imports: [CommonModule] });
3964
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ValidatorsModule, decorators: [{
3965
+ type: NgModule,
3966
+ args: [{
3967
+ declarations: [],
3968
+ imports: [CommonModule],
3969
+ providers: [CreditCardMinLengthValidator],
3970
+ }]
3971
+ }] });
3972
+
3491
3973
  class FormModule {
3492
3974
  }
3493
3975
  FormModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FormModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
3494
- FormModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: FormModule, imports: [ReactiveFormsModule] });
3976
+ FormModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: FormModule, imports: [ReactiveFormsModule, ValidatorsModule] });
3495
3977
  FormModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FormModule, providers: [
3496
3978
  FormService,
3497
3979
  ControlConfigService,
3498
3980
  ZipConverter,
3499
3981
  EmailConverter,
3982
+ CardNumberConverter,
3500
3983
  { provide: convertersMapToken, useValue: convertersMap },
3501
- ], imports: [ReactiveFormsModule] });
3984
+ ], imports: [ReactiveFormsModule, ValidatorsModule] });
3502
3985
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FormModule, decorators: [{
3503
3986
  type: NgModule,
3504
3987
  args: [{
3505
- imports: [ReactiveFormsModule],
3988
+ imports: [ReactiveFormsModule, ValidatorsModule],
3506
3989
  providers: [
3507
3990
  FormService,
3508
3991
  ControlConfigService,
3509
3992
  ZipConverter,
3510
3993
  EmailConverter,
3994
+ CardNumberConverter,
3511
3995
  { provide: convertersMapToken, useValue: convertersMap },
3512
3996
  ],
3513
3997
  }]