@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
@@ -6,6 +6,7 @@ import { HttpParams, HttpHeaders, HttpClientModule, HTTP_INTERCEPTORS } from '@a
6
6
  import { UntypedFormGroup, Validators, UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
7
7
  import { filter, map as map$1, catchError } from 'rxjs/operators';
8
8
  import * as i1$1 from '@angular/router';
9
+ import { CommonModule } from '@angular/common';
9
10
 
10
11
  const masksFunctionsMap = {
11
12
  zip: () => {
@@ -1227,6 +1228,10 @@ class SyncService extends EmitDataService {
1227
1228
  this.prevFieldSyncStates = {};
1228
1229
  this.form = new UntypedFormGroup({});
1229
1230
  this.fields = [];
1231
+ this.fieldAsyncValidation = new Subject();
1232
+ }
1233
+ get fieldAsyncValidation$() {
1234
+ return this.fieldAsyncValidation.asObservable();
1230
1235
  }
1231
1236
  setup(form, fields) {
1232
1237
  this.reset();
@@ -1257,6 +1262,11 @@ class SyncService extends EmitDataService {
1257
1262
  const requestPromise = this.request(field);
1258
1263
  this.setPrevFieldSyncState(field, value, requestPromise);
1259
1264
  return requestPromise.then((response) => {
1265
+ this.fieldAsyncValidation.next({
1266
+ value,
1267
+ field,
1268
+ response,
1269
+ });
1260
1270
  return response.error ?? null;
1261
1271
  });
1262
1272
  }
@@ -1504,10 +1514,430 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
1504
1514
  type: Injectable
1505
1515
  }], ctorParameters: function () { return [{ type: SyncService }, { type: CountryService }]; } });
1506
1516
 
1517
+ function isEmptyInputValue(value) {
1518
+ return value == null || value.length === 0;
1519
+ }
1520
+
1521
+ function isString(value) {
1522
+ return typeof value === 'string';
1523
+ }
1524
+
1525
+ /**
1526
+ * Checks number match Luhn algorithm.
1527
+ * Based on http://en.wikipedia.org/wiki/Luhn.
1528
+ */
1529
+ const luhnFormulaValidator = ({ value }) => {
1530
+ if (isEmptyInputValue(value) || !isString(value)) {
1531
+ return null;
1532
+ }
1533
+ const error = {
1534
+ rewritableError: {
1535
+ message: `Enter a valid card number`,
1536
+ },
1537
+ };
1538
+ if (/[^0-9 -]+/.test(value)) {
1539
+ // accept only spaces, digits and dashes
1540
+ return error;
1541
+ }
1542
+ let resultSum = 0;
1543
+ let digit = 0;
1544
+ let isEven = false;
1545
+ const modBase = 10;
1546
+ const digitRadix = 10;
1547
+ const maxNumber = 9;
1548
+ const digits = value.replace(/\D/g, '');
1549
+ // Checks if number match Luhn algorithm
1550
+ // based on http://en.wikipedia.org/wiki/Luhn
1551
+ for (let index = digits.length - 1; index >= 0; index--) {
1552
+ const char = digits.charAt(index);
1553
+ digit = parseInt(char, digitRadix);
1554
+ if (isEven && (digit *= 2) > maxNumber) {
1555
+ digit -= maxNumber;
1556
+ }
1557
+ resultSum += digit;
1558
+ isEven = !isEven;
1559
+ }
1560
+ return resultSum % modBase === 0 ? null : error;
1561
+ };
1562
+
1563
+ class CardNumberConfig extends ControlConfig {
1564
+ constructor() {
1565
+ super(...arguments);
1566
+ this.controlType = 'card-number';
1567
+ this.availableCardTypes = [];
1568
+ this.customError = '';
1569
+ }
1570
+ }
1571
+
1572
+ const fourBlockMask = '9999 9999 9999 9999';
1573
+
1574
+ var CreditCardTypes;
1575
+ (function (CreditCardTypes) {
1576
+ CreditCardTypes["DEFAULT"] = "0";
1577
+ CreditCardTypes["VISA"] = "1";
1578
+ CreditCardTypes["MASTERCARD"] = "2";
1579
+ CreditCardTypes["MAESTRO"] = "3";
1580
+ CreditCardTypes["AMERICAN_EXPRESS"] = "4";
1581
+ CreditCardTypes["DINERS_CLUBS"] = "5";
1582
+ CreditCardTypes["DISCOVER"] = "6";
1583
+ CreditCardTypes["JCB"] = "9";
1584
+ CreditCardTypes["DANKORT"] = "11";
1585
+ CreditCardTypes["HIPERCARD"] = "12";
1586
+ CreditCardTypes["ELO"] = "13";
1587
+ CreditCardTypes["AURA"] = "14";
1588
+ CreditCardTypes["NARANJA"] = "15";
1589
+ CreditCardTypes["MIR"] = "16";
1590
+ CreditCardTypes["CHINA_UNION_PAY"] = "17";
1591
+ CreditCardTypes["POSTEPAY"] = "18";
1592
+ })(CreditCardTypes || (CreditCardTypes = {}));
1593
+
1594
+ const visa = {
1595
+ id: CreditCardTypes.VISA,
1596
+ minLength: 13,
1597
+ maxLength: 16,
1598
+ iconName: 'visa',
1599
+ mask: fourBlockMask,
1600
+ checkNumber(number) {
1601
+ return number.startsWith('4');
1602
+ },
1603
+ };
1604
+
1605
+ const mastercard = {
1606
+ id: CreditCardTypes.MASTERCARD,
1607
+ minLength: 16,
1608
+ maxLength: 16,
1609
+ iconName: 'mastercard',
1610
+ mask: fourBlockMask,
1611
+ checkNumber(number) {
1612
+ const subLength = 6;
1613
+ const cardNumberSub = number.substring(0, subLength);
1614
+ return (new RegExp(/^5[1-5]/).test(number) ||
1615
+ (cardNumberSub >= '222100' && cardNumberSub <= '272099'));
1616
+ },
1617
+ };
1618
+
1619
+ const defaultMask = '9999 9999 9999 9999 999';
1620
+
1621
+ const maestro = {
1622
+ id: CreditCardTypes.MAESTRO,
1623
+ minLength: 12,
1624
+ maxLength: 19,
1625
+ iconName: 'maestro',
1626
+ mask: defaultMask,
1627
+ checkNumber(number) {
1628
+ return new RegExp(/^(5018)|^(5020)|^(5038)|^(5893)|^(6304)|^(6759)|^(6761)|^(6762)|^(6763)|^(0604)|^(6706)|^(6771)|^(6709)/).test(number);
1629
+ },
1630
+ maxCvvLength: 3,
1631
+ };
1632
+
1633
+ const americanExpress = {
1634
+ id: CreditCardTypes.AMERICAN_EXPRESS,
1635
+ minLength: 15,
1636
+ maxLength: 15,
1637
+ iconName: 'american-express',
1638
+ mask: '9999 999999 99999',
1639
+ checkNumber(number) {
1640
+ return new RegExp(/^(34)|^(37)/).test(number);
1641
+ },
1642
+ maxCvvLength: 4,
1643
+ };
1644
+
1645
+ const dinersClubs = {
1646
+ id: CreditCardTypes.DINERS_CLUBS,
1647
+ minLength: 14,
1648
+ maxLength: 14,
1649
+ iconName: 'dinersclub',
1650
+ mask: '9999 9999 9999 99',
1651
+ checkNumber(number) {
1652
+ const regex = /^(36[0-9]|3(?:0[0-59]|[68][0-9])[0-9])/;
1653
+ return regex.test(number);
1654
+ },
1655
+ };
1656
+
1657
+ const discover = {
1658
+ id: CreditCardTypes.DISCOVER,
1659
+ minLength: 16,
1660
+ maxLength: 19,
1661
+ iconName: 'discover',
1662
+ mask: defaultMask,
1663
+ checkNumber(number) {
1664
+ 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);
1665
+ },
1666
+ };
1667
+
1668
+ const jcb = {
1669
+ id: CreditCardTypes.JCB,
1670
+ minLength: 15,
1671
+ maxLength: 16,
1672
+ iconName: 'jcb',
1673
+ mask: fourBlockMask,
1674
+ checkNumber(number) {
1675
+ return new RegExp(/^35(2[89]|[3-8][0-9])/).test(number);
1676
+ },
1677
+ };
1678
+
1679
+ const dankort = {
1680
+ id: CreditCardTypes.DANKORT,
1681
+ minLength: 16,
1682
+ maxLength: 16,
1683
+ iconName: 'dankort',
1684
+ mask: fourBlockMask,
1685
+ checkNumber(number) {
1686
+ const subLength = 4;
1687
+ const cardNumberSub = number.substring(0, subLength);
1688
+ return cardNumberSub === '5019';
1689
+ },
1690
+ };
1691
+
1692
+ const hipercard = {
1693
+ id: CreditCardTypes.HIPERCARD,
1694
+ minLength: 13,
1695
+ maxLength: 19,
1696
+ iconName: 'hipercard',
1697
+ mask: defaultMask,
1698
+ checkNumber(number) {
1699
+ return new RegExp(/^((606282|637095|637568)[0-9]|38[0-9]{14,17})/).test(number);
1700
+ },
1701
+ };
1702
+
1703
+ const elo = {
1704
+ id: CreditCardTypes.ELO,
1705
+ minLength: 16,
1706
+ maxLength: 19,
1707
+ iconName: 'elo',
1708
+ mask: defaultMask,
1709
+ checkNumber(number) {
1710
+ 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);
1711
+ },
1712
+ };
1713
+
1714
+ const aura = {
1715
+ id: CreditCardTypes.AURA,
1716
+ minLength: 16,
1717
+ maxLength: 19,
1718
+ iconName: 'aura',
1719
+ mask: defaultMask,
1720
+ checkNumber(number) {
1721
+ const subLength = 8;
1722
+ const cardNumberSub = number.substring(0, subLength);
1723
+ return ['50786000', '50786018', '50786019'].includes(cardNumberSub);
1724
+ },
1725
+ };
1726
+
1727
+ const naranja = {
1728
+ id: CreditCardTypes.NARANJA,
1729
+ minLength: 12,
1730
+ maxLength: 19,
1731
+ iconName: 'naranja',
1732
+ mask: defaultMask,
1733
+ checkNumber(number) {
1734
+ const subLength = 6;
1735
+ const cardNumberSub = number.substring(0, subLength);
1736
+ return cardNumberSub === '589562';
1737
+ },
1738
+ };
1739
+
1740
+ const mir = {
1741
+ id: CreditCardTypes.MIR,
1742
+ minLength: 16,
1743
+ maxLength: 16,
1744
+ iconName: 'mir',
1745
+ mask: defaultMask,
1746
+ checkNumber(number) {
1747
+ const subLength = 4;
1748
+ const cardNumberSub = number.substring(0, subLength);
1749
+ return cardNumberSub >= '2200' && cardNumberSub <= '2204';
1750
+ },
1751
+ };
1752
+
1753
+ const chinaUnionPay = {
1754
+ id: CreditCardTypes.CHINA_UNION_PAY,
1755
+ minLength: 16,
1756
+ maxLength: 19,
1757
+ iconName: 'unionpay',
1758
+ mask: '999 9999 9999 99999999',
1759
+ checkNumber(number) {
1760
+ return number.startsWith('62');
1761
+ },
1762
+ };
1763
+
1764
+ const defaultCard = {
1765
+ id: CreditCardTypes.DEFAULT,
1766
+ minLength: 12,
1767
+ maxLength: 19,
1768
+ iconName: null,
1769
+ mask: defaultMask,
1770
+ checkNumber() {
1771
+ return false;
1772
+ },
1773
+ };
1774
+
1775
+ const postePay = {
1776
+ id: CreditCardTypes.POSTEPAY,
1777
+ minLength: 12,
1778
+ maxLength: 19,
1779
+ iconName: 'poste_pay',
1780
+ mask: '9999 9999 9999 9999 999',
1781
+ checkNumber(number) {
1782
+ const regex = /^(5018)|^(5020)|^(5038)|^(5893)|^(6304)|^(6759)|^(6761)|^(6762)|^(6763)|^(0604)|^(6706)|^(6771)|^(6709)/;
1783
+ return regex.test(number);
1784
+ },
1785
+ };
1786
+
1787
+ /**
1788
+ * order does matter
1789
+ * settings with more specific pattern should be placed above
1790
+ * Example:
1791
+ * - 12*
1792
+ * - 12
1793
+ * - 1
1794
+ * "12*" pattern should be checked first, otherwise pattern "1" will be taken
1795
+ * before "12*" checked
1796
+ */
1797
+ const orderedCardSettings = [
1798
+ aura,
1799
+ naranja,
1800
+ maestro,
1801
+ postePay,
1802
+ elo,
1803
+ discover,
1804
+ dankort,
1805
+ hipercard,
1806
+ mir,
1807
+ jcb,
1808
+ dinersClubs,
1809
+ americanExpress,
1810
+ mastercard,
1811
+ chinaUnionPay,
1812
+ visa,
1813
+ defaultCard,
1814
+ ];
1815
+
1816
+ const creditCardsMap = {
1817
+ [CreditCardTypes.DEFAULT]: defaultCard,
1818
+ [CreditCardTypes.VISA]: visa,
1819
+ [CreditCardTypes.MASTERCARD]: mastercard,
1820
+ [CreditCardTypes.MAESTRO]: maestro,
1821
+ [CreditCardTypes.AMERICAN_EXPRESS]: americanExpress,
1822
+ [CreditCardTypes.DINERS_CLUBS]: dinersClubs,
1823
+ [CreditCardTypes.DISCOVER]: discover,
1824
+ [CreditCardTypes.JCB]: jcb,
1825
+ [CreditCardTypes.DANKORT]: dankort,
1826
+ [CreditCardTypes.HIPERCARD]: hipercard,
1827
+ [CreditCardTypes.ELO]: elo,
1828
+ [CreditCardTypes.AURA]: aura,
1829
+ [CreditCardTypes.NARANJA]: naranja,
1830
+ [CreditCardTypes.MIR]: mir,
1831
+ [CreditCardTypes.CHINA_UNION_PAY]: chinaUnionPay,
1832
+ [CreditCardTypes.POSTEPAY]: postePay,
1833
+ };
1834
+
1835
+ class CreditCardService {
1836
+ getBinNumber(cardNumber) {
1837
+ const binNumberLength = 6;
1838
+ return cardNumber.replace(/\s+/g, '').substring(0, binNumberLength);
1839
+ }
1840
+ getAccountSuffix(cardNumber) {
1841
+ const accountSuffixLength = 4;
1842
+ return cardNumber
1843
+ .replace(/\s+/g, '')
1844
+ .substring(cardNumber.length - accountSuffixLength);
1845
+ }
1846
+ getTypeByNumber(cardNumber) {
1847
+ cardNumber = cardNumber.replace(/\s+/g, '');
1848
+ const cardSettings = orderedCardSettings.find((settings) => {
1849
+ const isNumberMatched = settings.checkNumber(cardNumber);
1850
+ return isNumberMatched ? settings.id : false;
1851
+ });
1852
+ return cardSettings ? cardSettings.id : defaultCard.id;
1853
+ }
1854
+ getCreditCardSettings(cardType) {
1855
+ const creditCard = creditCardsMap[cardType];
1856
+ if (!creditCard) {
1857
+ return defaultCard;
1858
+ }
1859
+ return creditCard;
1860
+ }
1861
+ }
1862
+ CreditCardService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1863
+ CreditCardService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardService, providedIn: 'root' });
1864
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardService, decorators: [{
1865
+ type: Injectable,
1866
+ args: [{
1867
+ providedIn: 'root',
1868
+ }]
1869
+ }] });
1870
+
1871
+ class CreditCardMinLengthValidator {
1872
+ constructor(creditService) {
1873
+ this.creditService = creditService;
1874
+ this.validate = (field) => {
1875
+ if (isEmptyInputValue(field.value) || !isString(field.value)) {
1876
+ return null;
1877
+ }
1878
+ const length = field.value.length;
1879
+ const cardType = this.creditService.getTypeByNumber(field.value);
1880
+ const { minLength } = this.creditService.getCreditCardSettings(cardType);
1881
+ return length < minLength
1882
+ ? {
1883
+ rewritableError: {
1884
+ message: `Enter at least ${minLength} characters`,
1885
+ number: minLength,
1886
+ },
1887
+ }
1888
+ : null;
1889
+ };
1890
+ }
1891
+ }
1892
+ CreditCardMinLengthValidator.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardMinLengthValidator, deps: [{ token: CreditCardService }], target: i0.ɵɵFactoryTarget.Injectable });
1893
+ CreditCardMinLengthValidator.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardMinLengthValidator });
1894
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardMinLengthValidator, decorators: [{
1895
+ type: Injectable
1896
+ }], ctorParameters: function () { return [{ type: CreditCardService }]; } });
1897
+
1898
+ class CardNumberConverter extends Converter {
1899
+ constructor(syncService, maxLengthValidator, minLengthValidator) {
1900
+ super(syncService);
1901
+ this.maxLengthValidator = maxLengthValidator;
1902
+ this.minLengthValidator = minLengthValidator;
1903
+ }
1904
+ getValidators(field) {
1905
+ return super
1906
+ .getValidators(field)
1907
+ .concat([
1908
+ luhnFormulaValidator,
1909
+ this.minLengthValidator.validate,
1910
+ this.maxLengthValidator.validate,
1911
+ ]);
1912
+ }
1913
+ createControlConfig(field, formState) {
1914
+ const config = this.createDefaultControlConfig(CardNumberConfig, field);
1915
+ config.placeholder = config.title;
1916
+ config.availableCardTypes =
1917
+ formState?.availableCardTypes ?? [];
1918
+ config.activeCardType = formState?.activeCardType;
1919
+ config.customError = formState?.customError;
1920
+ config.disabled = formState?.disabled ?? false;
1921
+ return config;
1922
+ }
1923
+ getAutocomplete() {
1924
+ return 'cc-number';
1925
+ }
1926
+ getDataType() {
1927
+ return 'text';
1928
+ }
1929
+ }
1930
+ 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 });
1931
+ CardNumberConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardNumberConverter });
1932
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardNumberConverter, decorators: [{
1933
+ type: Injectable
1934
+ }], ctorParameters: function () { return [{ type: SyncService }, { type: CreditCardMinLengthValidator }, { type: CreditCardMinLengthValidator }]; } });
1935
+
1507
1936
  const convertersMapToken = new InjectionToken('ConvertersTokensMap');
1508
1937
  const convertersMap = {
1509
1938
  zip: ZipConverter,
1510
1939
  email: EmailConverter,
1940
+ card_number: CardNumberConverter,
1511
1941
  };
1512
1942
 
1513
1943
  class ControlConfigService {
@@ -2968,17 +3398,29 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
2968
3398
  args: [financeDetailsResponseFactoryToken]
2969
3399
  }] }]; } });
2970
3400
 
3401
+ class CreditCardStateService extends EmitDataService {
3402
+ }
3403
+ CreditCardStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardStateService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
3404
+ CreditCardStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardStateService, providedIn: 'root' });
3405
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CreditCardStateService, decorators: [{
3406
+ type: Injectable,
3407
+ args: [{
3408
+ providedIn: 'root',
3409
+ }]
3410
+ }] });
3411
+
2971
3412
  class PaymentService {
2972
3413
  get formFieldsStatus$() {
2973
3414
  return this.formFieldsStatusSubject.asObservable().pipe(filter$1(Boolean));
2974
3415
  }
2975
- constructor(initializeService, submitService, syncService, formService, statusService, financeDetailsService, nextActionService, controlConfigService) {
3416
+ constructor(initializeService, submitService, syncService, formService, statusService, financeDetailsService, creditCardStateService, nextActionService, controlConfigService) {
2976
3417
  this.initializeService = initializeService;
2977
3418
  this.submitService = submitService;
2978
3419
  this.syncService = syncService;
2979
3420
  this.formService = formService;
2980
3421
  this.statusService = statusService;
2981
3422
  this.financeDetailsService = financeDetailsService;
3423
+ this.creditCardStateService = creditCardStateService;
2982
3424
  this.nextActionService = nextActionService;
2983
3425
  this.controlConfigService = controlConfigService;
2984
3426
  this.form = null;
@@ -3087,6 +3529,9 @@ class PaymentService {
3087
3529
  emitFinanceDetails(summary) {
3088
3530
  this.financeDetailsService.emit(summary);
3089
3531
  }
3532
+ emitCreditCardState(idCardType) {
3533
+ this.creditCardStateService.emit({ idCardType });
3534
+ }
3090
3535
  emitFormFieldsStatus(form) {
3091
3536
  const formFieldsStatus = {};
3092
3537
  Object.keys(form.controls).forEach((name) => {
@@ -3104,7 +3549,17 @@ class PaymentService {
3104
3549
  this.syncService.setup(form, fields);
3105
3550
  this.syncService.data$
3106
3551
  .pipe(takeUntil(this.destroy$))
3107
- .subscribe((response) => this.emitFinanceDetails(response.summary));
3552
+ .subscribe((response) => {
3553
+ this.emitFinanceDetails(response.summary);
3554
+ });
3555
+ this.syncService.fieldAsyncValidation$
3556
+ .pipe(takeUntil(this.destroy$))
3557
+ .subscribe((fieldAsyncValidation) => {
3558
+ switch (fieldAsyncValidation.field.name) {
3559
+ case FieldNames.cardNumber:
3560
+ this.emitCreditCardState(fieldAsyncValidation.response.parameters.idCardType);
3561
+ }
3562
+ });
3108
3563
  }
3109
3564
  listenFinanceDetails() {
3110
3565
  this.financeDetailsService.data$
@@ -3117,14 +3572,14 @@ class PaymentService {
3117
3572
  .subscribe(() => this.emitFormFieldsStatus(form));
3118
3573
  }
3119
3574
  }
3120
- 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 });
3575
+ 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 });
3121
3576
  PaymentService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, providedIn: 'root' });
3122
3577
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, decorators: [{
3123
3578
  type: Injectable,
3124
3579
  args: [{
3125
3580
  providedIn: 'root',
3126
3581
  }]
3127
- }], ctorParameters: function () { return [{ type: InitializeService }, { type: SubmitService }, { type: SyncService }, { type: FormService }, { type: StatusService }, { type: FinanceDetailsService }, { type: NextActionService }, { type: ControlConfigService }]; } });
3582
+ }], ctorParameters: function () { return [{ type: InitializeService }, { type: SubmitService }, { type: SyncService }, { type: FormService }, { type: StatusService }, { type: FinanceDetailsService }, { type: CreditCardStateService }, { type: NextActionService }, { type: ControlConfigService }]; } });
3128
3583
 
3129
3584
  class RefundPolicyService {
3130
3585
  constructor(settingsService) {
@@ -3229,7 +3684,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
3229
3684
  }], ctorParameters: function () { return [{ type: SettingsService }, { type: RefundPolicyService }, { type: SecureConnectionService }, { type: DisclaimerService }]; } });
3230
3685
 
3231
3686
  class CoreLibraryService {
3232
- constructor(settingsService, countryService, paymentMethodsService, savedMethodsService, userBalanceService, paymentConfigService, paymentService, deviceFingerPrintService, financeDetailsService, legalService, statusService, nextActionService) {
3687
+ constructor(settingsService, countryService, paymentMethodsService, savedMethodsService, userBalanceService, paymentConfigService, paymentService, deviceFingerPrintService, financeDetailsService, legalService, statusService, nextActionService, creditCardService, creditCardStateService) {
3233
3688
  this.settingsService = settingsService;
3234
3689
  this.countryService = countryService;
3235
3690
  this.paymentMethodsService = paymentMethodsService;
@@ -3242,6 +3697,8 @@ class CoreLibraryService {
3242
3697
  this.legalService = legalService;
3243
3698
  this.statusService = statusService;
3244
3699
  this.nextActionService = nextActionService;
3700
+ this.creditCardService = creditCardService;
3701
+ this.creditCardStateService = creditCardStateService;
3245
3702
  this.paymentMethods = {
3246
3703
  getList: async () => this.paymentMethodsService.getList(),
3247
3704
  getQuickMethods: async () => this.paymentMethodsService.getQuickMethods(),
@@ -3279,6 +3736,16 @@ class CoreLibraryService {
3279
3736
  },
3280
3737
  };
3281
3738
  }
3739
+ getCreditCardService() {
3740
+ return {
3741
+ getTypeByNumber: (cardNumber) => this.creditCardService.getTypeByNumber(cardNumber),
3742
+ getCreditCardSettings: (cardType) => this.creditCardService.getCreditCardSettings(cardType),
3743
+ cardTypeUpdates$: this.creditCardStateService.data$,
3744
+ };
3745
+ }
3746
+ get cardTypeUpdates$() {
3747
+ return this.creditCardStateService.data$;
3748
+ }
3282
3749
  getLegalComponentConfig() {
3283
3750
  return this.legalService.getLegalComponentConfig();
3284
3751
  }
@@ -3287,14 +3754,14 @@ class CoreLibraryService {
3287
3754
  return masksFunctionsMap[sanitizedName];
3288
3755
  }
3289
3756
  }
3290
- 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 });
3757
+ 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 });
3291
3758
  CoreLibraryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, providedIn: 'root' });
3292
3759
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, decorators: [{
3293
3760
  type: Injectable,
3294
3761
  args: [{
3295
3762
  providedIn: 'root',
3296
3763
  }]
3297
- }], 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 }]; } });
3764
+ }], 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 }]; } });
3298
3765
 
3299
3766
  class HttpError extends AppError {
3300
3767
  constructor(error, req) {
@@ -3351,26 +3818,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
3351
3818
  type: Injectable
3352
3819
  }], ctorParameters: function () { return [{ type: i1$1.Router }]; } });
3353
3820
 
3821
+ class ValidatorsModule {
3822
+ }
3823
+ ValidatorsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ValidatorsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
3824
+ ValidatorsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: ValidatorsModule, imports: [CommonModule] });
3825
+ ValidatorsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ValidatorsModule, providers: [CreditCardMinLengthValidator], imports: [CommonModule] });
3826
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ValidatorsModule, decorators: [{
3827
+ type: NgModule,
3828
+ args: [{
3829
+ declarations: [],
3830
+ imports: [CommonModule],
3831
+ providers: [CreditCardMinLengthValidator],
3832
+ }]
3833
+ }] });
3834
+
3354
3835
  class FormModule {
3355
3836
  }
3356
3837
  FormModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FormModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
3357
- FormModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: FormModule, imports: [ReactiveFormsModule] });
3838
+ FormModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: FormModule, imports: [ReactiveFormsModule, ValidatorsModule] });
3358
3839
  FormModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FormModule, providers: [
3359
3840
  FormService,
3360
3841
  ControlConfigService,
3361
3842
  ZipConverter,
3362
3843
  EmailConverter,
3844
+ CardNumberConverter,
3363
3845
  { provide: convertersMapToken, useValue: convertersMap },
3364
- ], imports: [ReactiveFormsModule] });
3846
+ ], imports: [ReactiveFormsModule, ValidatorsModule] });
3365
3847
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FormModule, decorators: [{
3366
3848
  type: NgModule,
3367
3849
  args: [{
3368
- imports: [ReactiveFormsModule],
3850
+ imports: [ReactiveFormsModule, ValidatorsModule],
3369
3851
  providers: [
3370
3852
  FormService,
3371
3853
  ControlConfigService,
3372
3854
  ZipConverter,
3373
3855
  EmailConverter,
3856
+ CardNumberConverter,
3374
3857
  { provide: convertersMapToken, useValue: convertersMap },
3375
3858
  ],
3376
3859
  }]