@xsolla/payment-client-core 0.1.5 → 0.1.6-1

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 (121) hide show
  1. package/esm2020/lib/core/payment/form/controls/card-number/card-number-control.config.mjs +10 -0
  2. package/esm2020/lib/core/payment/form/controls/checkbox/checkbox-control.config.mjs +10 -0
  3. package/esm2020/lib/core/payment/form/controls/coupon/coupon-control.config.mjs +8 -0
  4. package/esm2020/lib/core/payment/form/controls/phone-control.config.mjs +8 -0
  5. package/esm2020/lib/core/payment/form/controls/radio-control/radio-control.config.mjs +9 -0
  6. package/esm2020/lib/core/payment/form/controls/radio-control/radio-option.interface.mjs +2 -0
  7. package/esm2020/lib/core/payment/form/controls/search-select/search-select-control.config.mjs +8 -0
  8. package/esm2020/lib/core/payment/form/controls/search-select/search-select-option.interface.mjs +2 -0
  9. package/esm2020/lib/core/payment/form/controls/search-select/select-option.interface.mjs +2 -0
  10. package/esm2020/lib/core/payment/form/converters/birth-date/birth-date.converter.mjs +38 -0
  11. package/esm2020/lib/core/payment/form/converters/card-month/card-month.converter.mjs +38 -0
  12. package/esm2020/lib/core/payment/form/converters/card-number/card-number.converter.mjs +45 -0
  13. package/esm2020/lib/core/payment/form/converters/card-year/card-year.converter.mjs +38 -0
  14. package/esm2020/lib/core/payment/form/converters/cardholder-name/cardholder-name.converter.mjs +25 -0
  15. package/esm2020/lib/core/payment/form/converters/checkbox/checkbox.converter.mjs +34 -0
  16. package/esm2020/lib/core/payment/form/converters/converter.abstract.mjs +4 -3
  17. package/esm2020/lib/core/payment/form/converters/converters-map.mjs +34 -16
  18. package/esm2020/lib/core/payment/form/converters/coupon/coupon.converter.mjs +25 -0
  19. package/esm2020/lib/core/payment/form/converters/cpf-name/cpf-name-regex.variable.mjs +2 -0
  20. package/esm2020/lib/core/payment/form/converters/cpf-name/cpf-name.converter.mjs +34 -0
  21. package/esm2020/lib/core/payment/form/converters/cpf-number/cpf-number.converter.mjs +31 -0
  22. package/esm2020/lib/core/payment/form/converters/cvv/cvv-form-state.interface.mjs +2 -0
  23. package/esm2020/lib/core/payment/form/converters/cvv/cvv.converter.mjs +72 -0
  24. package/esm2020/lib/core/payment/form/converters/email/email.converter.mjs +29 -0
  25. package/esm2020/lib/core/payment/form/converters/phone.converter.mjs +37 -0
  26. package/esm2020/lib/core/payment/form/converters/pin/pin.converter.mjs +19 -0
  27. package/esm2020/lib/core/payment/form/converters/pricepoint/pricepoint.converter.mjs +32 -0
  28. package/esm2020/lib/core/payment/form/converters/radio-group/radio-group.converter.mjs +21 -0
  29. package/esm2020/lib/core/payment/form/converters/select/select.converter.mjs +21 -0
  30. package/esm2020/lib/core/payment/form/converters/street-number/street-number.converter.mjs +2 -2
  31. package/esm2020/lib/core/payment/form/converters/text/text.converter.mjs +19 -0
  32. package/esm2020/lib/core/payment/form/converters/zip/zip.converter.mjs +67 -0
  33. package/esm2020/lib/core/payment/form/field-form-states.interface.mjs +2 -0
  34. package/esm2020/lib/core/payment/form/form.module.mjs +51 -17
  35. package/esm2020/lib/core/payment/form/form.service.mjs +19 -1
  36. package/esm2020/lib/core/payment/form/validators/birth-date/birth-date.validator.mjs +37 -0
  37. package/esm2020/lib/core/payment/form/validators/card-month/card-month.validator.mjs +37 -0
  38. package/esm2020/lib/core/payment/form/validators/card-year/card-year.validator.mjs +34 -0
  39. package/esm2020/lib/core/payment/form/validators/coupon/coupon-validator.mjs +6 -0
  40. package/esm2020/lib/core/payment/form/validators/credit-card-length/credit-card-min-length.validator.mjs +32 -0
  41. package/esm2020/lib/core/payment/form/validators/email/email-validator.mjs +7 -0
  42. package/esm2020/lib/core/payment/form/validators/max-length-validator.mjs +6 -0
  43. package/esm2020/lib/core/payment/form/validators/min-length-validator.mjs +6 -0
  44. package/esm2020/lib/core/payment/form/validators/phone-validator.mjs +6 -0
  45. package/esm2020/lib/core/payment/form/validators/required/required.validator.mjs +6 -0
  46. package/esm2020/lib/core/payment/form/validators/restricted-value/restricted-value.validator.mjs +6 -0
  47. package/esm2020/lib/core/payment/form/validators/validators.module.mjs +2 -2
  48. package/esm2020/lib/core/payment/payment.interface.mjs +1 -1
  49. package/esm2020/lib/core/payment/payment.service.mjs +6 -1
  50. package/esm2020/lib/core-library.service.mjs +5 -1
  51. package/fesm2015/xsolla-payment-client-core.mjs +410 -22
  52. package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
  53. package/fesm2020/xsolla-payment-client-core.mjs +410 -22
  54. package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
  55. package/lib/core/payment/form/controls/{card-number-control.config.d.ts → card-number/card-number-control.config.d.ts} +2 -2
  56. package/lib/core/payment/form/controls/checkbox/checkbox-control.config.d.ts +6 -0
  57. package/lib/core/payment/form/controls/coupon/coupon-control.config.d.ts +8 -0
  58. package/lib/core/payment/form/controls/phone-control.config.d.ts +6 -0
  59. package/lib/core/payment/form/controls/radio-control/radio-control.config.d.ts +6 -0
  60. package/lib/core/payment/form/controls/radio-control/radio-option.interface.d.ts +5 -0
  61. package/lib/core/payment/form/controls/search-select/search-select-control.config.d.ts +11 -0
  62. package/lib/core/payment/form/controls/search-select/search-select-option.interface.d.ts +19 -0
  63. package/lib/core/payment/form/controls/search-select/select-option.interface.d.ts +13 -0
  64. package/lib/core/payment/form/converters/{birth-date.converter.d.ts → birth-date/birth-date.converter.d.ts} +4 -4
  65. package/lib/core/payment/form/converters/card-month/card-month.converter.d.ts +16 -0
  66. package/lib/core/payment/form/converters/{card-number.converter.d.ts → card-number/card-number.converter.d.ts} +6 -6
  67. package/lib/core/payment/form/converters/card-year/card-year.converter.d.ts +16 -0
  68. package/lib/core/payment/form/converters/{cardholder-name.converter.d.ts → cardholder-name/cardholder-name.converter.d.ts} +4 -4
  69. package/lib/core/payment/form/converters/checkbox/checkbox.converter.d.ts +16 -0
  70. package/lib/core/payment/form/converters/converter.abstract.d.ts +1 -1
  71. package/lib/core/payment/form/converters/coupon/coupon.converter.d.ts +13 -0
  72. package/lib/core/payment/form/converters/{cpf-name.converter.d.ts → cpf-name/cpf-name.converter.d.ts} +4 -4
  73. package/lib/core/payment/form/converters/{cpf-number.converter.d.ts → cpf-number/cpf-number.converter.d.ts} +4 -4
  74. package/lib/core/payment/form/converters/cvv/cvv-form-state.interface.d.ts +3 -0
  75. package/lib/core/payment/form/converters/{cvv.converter.d.ts → cvv/cvv.converter.d.ts} +8 -7
  76. package/lib/core/payment/form/converters/{email.converter.d.ts → email/email.converter.d.ts} +5 -5
  77. package/lib/core/payment/form/converters/phone.converter.d.ts +13 -0
  78. package/lib/core/payment/form/converters/pin/pin.converter.d.ts +11 -0
  79. package/lib/core/payment/form/converters/pricepoint/pricepoint.converter.d.ts +14 -0
  80. package/lib/core/payment/form/converters/radio-group/radio-group.converter.d.ts +11 -0
  81. package/lib/core/payment/form/converters/select/select.converter.d.ts +11 -0
  82. package/lib/core/payment/form/converters/{text.converter.d.ts → text/text.converter.d.ts} +4 -4
  83. package/lib/core/payment/form/converters/{zip.converter.d.ts → zip/zip.converter.d.ts} +5 -5
  84. package/lib/core/payment/form/field-form-states.interface.d.ts +4 -0
  85. package/lib/core/payment/form/form.service.d.ts +4 -0
  86. package/lib/core/payment/form/validators/card-month/card-month.validator.d.ts +5 -0
  87. package/lib/core/payment/form/validators/card-year/card-year.validator.d.ts +5 -0
  88. package/lib/core/payment/form/validators/coupon/coupon-validator.d.ts +2 -0
  89. package/lib/core/payment/form/validators/{credit-card-min-length.validator.d.ts → credit-card-length/credit-card-min-length.validator.d.ts} +1 -1
  90. package/lib/core/payment/form/validators/{email-validator.d.ts → email/email-validator.d.ts} +1 -1
  91. package/lib/core/payment/form/validators/max-length-validator.d.ts +2 -0
  92. package/lib/core/payment/form/validators/min-length-validator.d.ts +2 -0
  93. package/lib/core/payment/form/validators/phone-validator.d.ts +2 -0
  94. package/lib/core/payment/form/validators/{restricted-value.validator.d.ts → restricted-value/restricted-value.validator.d.ts} +1 -1
  95. package/lib/core/payment/payment.interface.d.ts +2 -0
  96. package/lib/core/payment/payment.service.d.ts +2 -0
  97. package/lib/core-library.service.d.ts +1 -0
  98. package/package.json +1 -1
  99. package/xsolla-payment-client-core-0.1.6-1.tgz +0 -0
  100. package/esm2020/lib/core/payment/form/controls/card-number-control.config.mjs +0 -10
  101. package/esm2020/lib/core/payment/form/converters/birth-date.converter.mjs +0 -38
  102. package/esm2020/lib/core/payment/form/converters/card-expiration.converter.mjs +0 -36
  103. package/esm2020/lib/core/payment/form/converters/card-number.converter.mjs +0 -45
  104. package/esm2020/lib/core/payment/form/converters/cardholder-name.converter.mjs +0 -25
  105. package/esm2020/lib/core/payment/form/converters/cpf-name-regex.variable.mjs +0 -2
  106. package/esm2020/lib/core/payment/form/converters/cpf-name.converter.mjs +0 -34
  107. package/esm2020/lib/core/payment/form/converters/cpf-number.converter.mjs +0 -31
  108. package/esm2020/lib/core/payment/form/converters/cvv.converter.mjs +0 -50
  109. package/esm2020/lib/core/payment/form/converters/email.converter.mjs +0 -29
  110. package/esm2020/lib/core/payment/form/converters/text.converter.mjs +0 -19
  111. package/esm2020/lib/core/payment/form/converters/zip.converter.mjs +0 -67
  112. package/esm2020/lib/core/payment/form/validators/birth-date.validator.mjs +0 -37
  113. package/esm2020/lib/core/payment/form/validators/credit-card-min-length.validator.mjs +0 -32
  114. package/esm2020/lib/core/payment/form/validators/email-validator.mjs +0 -7
  115. package/esm2020/lib/core/payment/form/validators/required-validator.mjs +0 -6
  116. package/esm2020/lib/core/payment/form/validators/restricted-value.validator.mjs +0 -6
  117. package/lib/core/payment/form/converters/card-expiration.converter.d.ts +0 -16
  118. package/xsolla-payment-client-core-0.1.5.tgz +0 -0
  119. /package/lib/core/payment/form/converters/{cpf-name-regex.variable.d.ts → cpf-name/cpf-name-regex.variable.d.ts} +0 -0
  120. /package/lib/core/payment/form/validators/{birth-date.validator.d.ts → birth-date/birth-date.validator.d.ts} +0 -0
  121. /package/lib/core/payment/form/validators/{required-validator.d.ts → required/required.validator.d.ts} +0 -0
@@ -1822,7 +1822,8 @@ class Converter {
1822
1822
  convertToFormControl(field) {
1823
1823
  return new UntypedFormControl(this.getValue(field), this.getValidators(field), this.getAsyncValidators(field));
1824
1824
  }
1825
- getValidators(field) {
1825
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1826
+ getValidators(field, formState) {
1826
1827
  const validators = [];
1827
1828
  if (field.isMandatory === "1" /* XpsBoolean.true */) {
1828
1829
  validators.push(convertedRequiredValidator());
@@ -2087,12 +2088,50 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
2087
2088
  type: Injectable
2088
2089
  }], ctorParameters: function () { return [{ type: SyncService }, { type: CreditCardMinLengthValidator }, { type: CreditCardMinLengthValidator }]; } });
2089
2090
 
2090
- class CardExpirationConverter extends Converter {
2091
+ const maxMonths = 12;
2092
+ const getMinMonth = (parsedYear) => {
2093
+ let minMonth = 1;
2094
+ const year = parsedYear ? Number('20' + parsedYear) : null;
2095
+ const today = new Date();
2096
+ minMonth = year === today.getFullYear() ? today.getMonth() + 1 : 1;
2097
+ return minMonth;
2098
+ };
2099
+ const sendErrMessage$1 = (fn) => ({
2100
+ cardMonthExpiration: {
2101
+ message: fn,
2102
+ },
2103
+ });
2104
+ function cardMonthValidator(formState) {
2105
+ return (control) => {
2106
+ var _a;
2107
+ const { value } = control;
2108
+ if (typeof value !== 'string')
2109
+ return null;
2110
+ const minMonth = getMinMonth((_a = formState === null || formState === void 0 ? void 0 : formState.cardYearValue) !== null && _a !== void 0 ? _a : null);
2111
+ const twoDigitsRegex = new RegExp(/^\d{2}$/);
2112
+ const fieldCommonLength = 2;
2113
+ if (value.length !== fieldCommonLength) {
2114
+ return sendErrMessage$1(`Enter ${fieldCommonLength} characters`);
2115
+ }
2116
+ if (!twoDigitsRegex.test(value)) {
2117
+ return sendErrMessage$1(`Enter a valid expiration month`);
2118
+ }
2119
+ if (Number(value) < minMonth) {
2120
+ return sendErrMessage$1(`Enter a month greater than or equal to ${minMonth}`);
2121
+ }
2122
+ if (Number(value) > maxMonths) {
2123
+ return sendErrMessage$1(`Enter a month less than or equal to ${maxMonths}`);
2124
+ }
2125
+ return null;
2126
+ };
2127
+ }
2128
+
2129
+ class CardMonthConverter extends Converter {
2091
2130
  constructor(syncService) {
2092
2131
  super(syncService);
2093
2132
  }
2094
- getValidators() {
2095
- return [];
2133
+ getValidators(field, formState) {
2134
+ return super.getValidators(field).concat([cardMonthValidator(formState)]);
2096
2135
  }
2097
2136
  createControlConfig(field, formState) {
2098
2137
  var _a;
@@ -2102,20 +2141,21 @@ class CardExpirationConverter extends Converter {
2102
2141
  guide: false,
2103
2142
  };
2104
2143
  config.inputMode = 'numeric';
2105
- config.title = 'date';
2144
+ config.placeholder = `MM`;
2145
+ config.title = `MM`;
2106
2146
  config.disabled = (_a = formState === null || formState === void 0 ? void 0 : formState.disabled) !== null && _a !== void 0 ? _a : false;
2107
2147
  return config;
2108
2148
  }
2109
2149
  getAutocomplete() {
2110
- return 'cc-exp';
2150
+ return 'cc-exp-month';
2111
2151
  }
2112
2152
  getDataType() {
2113
2153
  return 'text';
2114
2154
  }
2115
2155
  }
2116
- CardExpirationConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardExpirationConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
2117
- CardExpirationConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardExpirationConverter });
2118
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardExpirationConverter, decorators: [{
2156
+ CardMonthConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardMonthConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
2157
+ CardMonthConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardMonthConverter });
2158
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardMonthConverter, decorators: [{
2119
2159
  type: Injectable
2120
2160
  }], ctorParameters: function () { return [{ type: SyncService }]; } });
2121
2161
 
@@ -2125,8 +2165,27 @@ class CvvConverter extends Converter {
2125
2165
  // eslint-disable-next-line @typescript-eslint/no-magic-numbers
2126
2166
  this.maxFieldLength = 4;
2127
2167
  }
2128
- getValidators() {
2129
- return [];
2168
+ getValidators(field, formState) {
2169
+ const validators = super.getValidators(field);
2170
+ const activeCardType = formState ? formState.activeCardType : null;
2171
+ const getPatternValidator = (pattern) => convert(Validators.pattern(pattern), `Enter a valid CVV/CVC`);
2172
+ switch (activeCardType) {
2173
+ case CreditCardTypes.AMERICAN_EXPRESS: {
2174
+ this.maxFieldLength = 4;
2175
+ validators.push(getPatternValidator(/^\d{4}$/));
2176
+ break;
2177
+ }
2178
+ case CreditCardTypes.MAESTRO: {
2179
+ this.maxFieldLength = 3;
2180
+ validators.push(getPatternValidator(/^\d{0,3}$/));
2181
+ break;
2182
+ }
2183
+ default: {
2184
+ this.maxFieldLength = 3;
2185
+ validators.push(getPatternValidator(/^\d{3}$/));
2186
+ }
2187
+ }
2188
+ return validators;
2130
2189
  }
2131
2190
  createControlConfig(field, formState) {
2132
2191
  var _a;
@@ -2339,21 +2398,299 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
2339
2398
  type: Injectable
2340
2399
  }], ctorParameters: function () { return [{ type: SyncService }]; } });
2341
2400
 
2401
+ class CheckboxControlConfig extends ControlConfig {
2402
+ constructor() {
2403
+ super(...arguments);
2404
+ this.controlType = 'checkbox';
2405
+ this.checkedValue = true; // eslint-disable-line @typescript-eslint/no-explicit-any
2406
+ this.uncheckedValue = false; // eslint-disable-line @typescript-eslint/no-explicit-any
2407
+ }
2408
+ }
2409
+
2410
+ class CheckboxConverter extends Converter {
2411
+ constructor(syncService) {
2412
+ super(syncService);
2413
+ this.checkedValue = "1" /* XpsBoolean.true */;
2414
+ this.uncheckedValue = "0" /* XpsBoolean.false */;
2415
+ }
2416
+ getValidators(field) {
2417
+ const validators = [];
2418
+ if (field.isMandatory === this.checkedValue) {
2419
+ validators.push(convert(restrictedValueValidator(this.uncheckedValue), 'validation_message_required_checkbox'));
2420
+ }
2421
+ return validators;
2422
+ }
2423
+ createControlConfig(field) {
2424
+ const config = this.createDefaultControlConfig(CheckboxControlConfig, field);
2425
+ config.placeholder = config.title;
2426
+ config.checkedValue = this.checkedValue;
2427
+ config.uncheckedValue = this.uncheckedValue;
2428
+ return config;
2429
+ }
2430
+ }
2431
+ CheckboxConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckboxConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
2432
+ CheckboxConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckboxConverter });
2433
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckboxConverter, decorators: [{
2434
+ type: Injectable
2435
+ }], ctorParameters: function () { return [{ type: SyncService }]; } });
2436
+
2437
+ class SearchSelectControlConfig extends ControlConfig {
2438
+ constructor() {
2439
+ super(...arguments);
2440
+ this.controlType = 'search-select';
2441
+ }
2442
+ }
2443
+
2444
+ class SelectConverter extends Converter {
2445
+ constructor(syncService) {
2446
+ super(syncService);
2447
+ }
2448
+ createControlConfig(field) {
2449
+ const config = this.createDefaultControlConfig(SearchSelectControlConfig, field);
2450
+ config.options = field.options;
2451
+ return config;
2452
+ }
2453
+ }
2454
+ SelectConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SelectConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
2455
+ SelectConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SelectConverter });
2456
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SelectConverter, decorators: [{
2457
+ type: Injectable
2458
+ }], ctorParameters: function () { return [{ type: SyncService }]; } });
2459
+
2460
+ class PinConverter extends Converter {
2461
+ constructor(syncService) {
2462
+ super(syncService);
2463
+ }
2464
+ createControlConfig(field) {
2465
+ return this.createDefaultControlConfig(TextControlConfig, field);
2466
+ }
2467
+ }
2468
+ PinConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PinConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
2469
+ PinConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PinConverter });
2470
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PinConverter, decorators: [{
2471
+ type: Injectable
2472
+ }], ctorParameters: function () { return [{ type: SyncService }]; } });
2473
+
2474
+ class RadioControlConfig extends ControlConfig {
2475
+ constructor() {
2476
+ super(...arguments);
2477
+ this.controlType = 'radio';
2478
+ this.options = [];
2479
+ }
2480
+ }
2481
+
2482
+ class RadioGroupConverter extends Converter {
2483
+ constructor(syncService) {
2484
+ super(syncService);
2485
+ }
2486
+ createControlConfig(field) {
2487
+ const config = this.createDefaultControlConfig(RadioControlConfig, field);
2488
+ config.options = field.options;
2489
+ return config;
2490
+ }
2491
+ }
2492
+ RadioGroupConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: RadioGroupConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
2493
+ RadioGroupConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: RadioGroupConverter });
2494
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: RadioGroupConverter, decorators: [{
2495
+ type: Injectable
2496
+ }], ctorParameters: function () { return [{ type: SyncService }]; } });
2497
+
2498
+ class PricepointConverter extends Converter {
2499
+ constructor(syncService) {
2500
+ super(syncService);
2501
+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
2502
+ this.maxFieldLength = 30;
2503
+ }
2504
+ getValidators(field) {
2505
+ return super.getValidators(field);
2506
+ }
2507
+ createControlConfig(field) {
2508
+ const config = this.createDefaultControlConfig(TextControlConfig, field);
2509
+ config.maskConfig = {
2510
+ mask: () => new Array(this.maxFieldLength).fill('9').join(``),
2511
+ unmaskModelValue: false,
2512
+ guide: false,
2513
+ };
2514
+ config.placeholder = field.title;
2515
+ config.inputMode = 'numeric';
2516
+ return config;
2517
+ }
2518
+ }
2519
+ PricepointConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PricepointConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
2520
+ PricepointConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PricepointConverter });
2521
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PricepointConverter, decorators: [{
2522
+ type: Injectable
2523
+ }], ctorParameters: function () { return [{ type: SyncService }]; } });
2524
+
2525
+ class CouponControlConfig extends ControlConfig {
2526
+ constructor() {
2527
+ super(...arguments);
2528
+ this.controlType = 'coupon';
2529
+ }
2530
+ }
2531
+
2532
+ function couponValidator(message = `Enter a valid promo code`) {
2533
+ return convert(Validators.pattern(/^[0-9a-z_-]+$/i), message);
2534
+ }
2535
+
2536
+ class CouponConverter extends Converter {
2537
+ constructor(syncService) {
2538
+ super(syncService);
2539
+ }
2540
+ getValidators() {
2541
+ return [couponValidator()];
2542
+ }
2543
+ createControlConfig(field) {
2544
+ const config = this.createDefaultControlConfig(CouponControlConfig, field);
2545
+ config.placeholder = `Enter promo code`;
2546
+ return config;
2547
+ }
2548
+ }
2549
+ CouponConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CouponConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
2550
+ CouponConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CouponConverter });
2551
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CouponConverter, decorators: [{
2552
+ type: Injectable
2553
+ }], ctorParameters: function () { return [{ type: SyncService }]; } });
2554
+
2555
+ const sendErrMessage = (fn) => ({
2556
+ cardYearExpiration: {
2557
+ message: fn,
2558
+ },
2559
+ });
2560
+ const getLastCharactersInYear = (str = new Date().getFullYear().toString()) => {
2561
+ // for getting last characters in year; need to check in future
2562
+ return str.slice(str.length - 2);
2563
+ };
2564
+ // Карта выдается максимум на 50 лет
2565
+ const maxYearsCount = 50;
2566
+ function cardYearValidator(control) {
2567
+ const { value } = control;
2568
+ if (typeof value !== 'string')
2569
+ return null;
2570
+ const minYear = parseInt(getLastCharactersInYear(), 10);
2571
+ const twoDigitsRegex = new RegExp(/^\d{2}$/);
2572
+ const fieldCommonLength = 2;
2573
+ if (value.length !== fieldCommonLength) {
2574
+ return sendErrMessage(`Enter ${fieldCommonLength} characters`);
2575
+ }
2576
+ if (!twoDigitsRegex.test(value)) {
2577
+ return sendErrMessage(`Enter a valid expiration year`);
2578
+ }
2579
+ if (Number(value) < minYear) {
2580
+ return sendErrMessage(`Enter a year greater than or equal to ${minYear}`);
2581
+ }
2582
+ const maxValidYear = minYear + maxYearsCount;
2583
+ if (Number(value) > maxValidYear) {
2584
+ return sendErrMessage(`Enter a year less than or equal to ${maxValidYear}`);
2585
+ }
2586
+ return null;
2587
+ }
2588
+
2589
+ class CardYearConverter extends Converter {
2590
+ constructor(syncService) {
2591
+ super(syncService);
2592
+ }
2593
+ getValidators(field) {
2594
+ return super.getValidators(field).concat([cardYearValidator]);
2595
+ }
2596
+ createControlConfig(field, formState) {
2597
+ var _a;
2598
+ const config = this.createDefaultControlConfig(TextControlConfig, field);
2599
+ config.maskConfig = {
2600
+ mask: '99',
2601
+ guide: false,
2602
+ };
2603
+ config.inputMode = 'numeric';
2604
+ config.placeholder = `YY`;
2605
+ config.title = `YY`;
2606
+ config.disabled = (_a = formState === null || formState === void 0 ? void 0 : formState.disabled) !== null && _a !== void 0 ? _a : false;
2607
+ return config;
2608
+ }
2609
+ getAutocomplete() {
2610
+ return 'cc-exp-year';
2611
+ }
2612
+ getDataType() {
2613
+ return 'text';
2614
+ }
2615
+ }
2616
+ CardYearConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardYearConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
2617
+ CardYearConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardYearConverter });
2618
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardYearConverter, decorators: [{
2619
+ type: Injectable
2620
+ }], ctorParameters: function () { return [{ type: SyncService }]; } });
2621
+
2622
+ function phoneValidator() {
2623
+ return convert(Validators.pattern(/^\d*$/), 'Enter a valid phone');
2624
+ }
2625
+
2626
+ function minLengthValidator(minLength) {
2627
+ return convert(Validators.minLength(minLength), `Enter at least ${minLength} characters`);
2628
+ }
2629
+
2630
+ function maxLengthValidator(maxLength) {
2631
+ return convert(Validators.maxLength(maxLength), `Enter no more than ${maxLength} characters`);
2632
+ }
2633
+
2634
+ class PhoneControlConfig extends ControlConfig {
2635
+ constructor() {
2636
+ super(...arguments);
2637
+ this.controlType = 'phone';
2638
+ }
2639
+ }
2640
+
2641
+ class PhoneConverter extends Converter {
2642
+ constructor(syncService) {
2643
+ super(syncService);
2644
+ }
2645
+ getValidators(field) {
2646
+ const minLength = 10;
2647
+ const maxLength = 15;
2648
+ return super
2649
+ .getValidators(field)
2650
+ .concat([
2651
+ convertedRequiredValidator(),
2652
+ phoneValidator(),
2653
+ minLengthValidator(minLength),
2654
+ maxLengthValidator(maxLength),
2655
+ ]);
2656
+ }
2657
+ createControlConfig(field) {
2658
+ const config = this.createDefaultControlConfig(PhoneControlConfig, field);
2659
+ config.inputMode = 'numeric';
2660
+ return config;
2661
+ }
2662
+ }
2663
+ PhoneConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PhoneConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
2664
+ PhoneConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PhoneConverter });
2665
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PhoneConverter, decorators: [{
2666
+ type: Injectable
2667
+ }], ctorParameters: function () { return [{ type: SyncService }]; } });
2668
+
2342
2669
  const convertersMapToken = new InjectionToken('ConvertersTokensMap');
2343
2670
  const convertersMap = {
2344
- zip: ZipConverter,
2345
- email: EmailConverter,
2346
2671
  card_number: CardNumberConverter,
2347
- card_month: CardExpirationConverter,
2348
- card_year: CardExpirationConverter,
2672
+ card_month: CardMonthConverter,
2673
+ card_year: CardYearConverter,
2349
2674
  cvv: CvvConverter,
2350
2675
  extra_cvv: CvvConverter,
2676
+ zip: ZipConverter,
2351
2677
  cardholdername: CardholderNameConverter,
2352
2678
  cpf_number: CpfNumberConverter,
2353
2679
  cpf_name: CpfNameConverter,
2354
2680
  birth_date: BirthDateConverter,
2355
- street_number: StreetNumberConverter,
2356
2681
  text: TextConverter,
2682
+ check: CheckboxConverter,
2683
+ select: SelectConverter,
2684
+ pin: PinConverter,
2685
+ radiogroup: RadioGroupConverter,
2686
+ email: EmailConverter,
2687
+ psEmail: EmailConverter,
2688
+ bazitemail: EmailConverter,
2689
+ street_number: StreetNumberConverter,
2690
+ sum: PricepointConverter,
2691
+ out: PricepointConverter,
2692
+ couponCode: CouponConverter,
2693
+ phone: PhoneConverter,
2357
2694
  };
2358
2695
 
2359
2696
  class ControlConfigService {
@@ -2404,6 +2741,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
2404
2741
  class FormService {
2405
2742
  constructor(controlConfigService) {
2406
2743
  this.controlConfigService = controlConfigService;
2744
+ this.fieldFormStates = {};
2407
2745
  }
2408
2746
  createForm(fields) {
2409
2747
  const controls = this.getVisibleFields(fields).reduce((result, field) => {
@@ -2415,6 +2753,21 @@ class FormService {
2415
2753
  }, {});
2416
2754
  return new UntypedFormGroup(controls);
2417
2755
  }
2756
+ updateFieldFormState(form, fields, fieldName, formState) {
2757
+ var _a;
2758
+ const field = fields.find((fieldItem) => fieldItem.name === fieldName);
2759
+ if (!field) {
2760
+ return;
2761
+ }
2762
+ const converter = this.controlConfigService.getConverter(field);
2763
+ const control = form.controls[fieldName];
2764
+ if (!control) {
2765
+ return;
2766
+ }
2767
+ this.fieldFormStates[fieldName] = Object.assign(Object.assign({}, this.fieldFormStates[fieldName]), formState);
2768
+ control.setValidators((_a = converter === null || converter === void 0 ? void 0 : converter.getValidators(field, this.fieldFormStates[fieldName])) !== null && _a !== void 0 ? _a : []);
2769
+ control.updateValueAndValidity();
2770
+ }
2418
2771
  getVisibleFields(fields) {
2419
2772
  return fields.filter(({ isVisible }) => isVisible === "1" /* XpsBoolean.true */);
2420
2773
  }
@@ -4377,6 +4730,11 @@ class PaymentService {
4377
4730
  getFinanceDetails() {
4378
4731
  return this.financeDetails;
4379
4732
  }
4733
+ updateFieldFormState(fieldName, formState) {
4734
+ if (this.form) {
4735
+ this.formService.updateFieldFormState(this.form, this.fields, fieldName, formState);
4736
+ }
4737
+ }
4380
4738
  getStatus() {
4381
4739
  var _a, _b, _c, _d;
4382
4740
  return __awaiter(this, void 0, void 0, function* () {
@@ -4626,6 +4984,9 @@ class CoreLibraryService {
4626
4984
  setCountry(country) {
4627
4985
  this.countryService.setCountry(country);
4628
4986
  }
4987
+ getCountry() {
4988
+ return this.countryService.getCountry();
4989
+ }
4629
4990
  createPayment(config) {
4630
4991
  const enrichedConfig = this.paymentConfigService.enrich(config);
4631
4992
  return {
@@ -4643,6 +5004,7 @@ class CoreLibraryService {
4643
5004
  getControlConfig: (field) => this.paymentService.getFieldConfig(field),
4644
5005
  changeFieldValue: (name, value) => this.paymentService.changeFieldValue(name, value),
4645
5006
  changeFieldState: (name, state) => this.paymentService.changeFieldState(name, state),
5007
+ updateFieldFormState: (fieldName, formState) => this.paymentService.updateFieldFormState(fieldName, formState),
4646
5008
  },
4647
5009
  };
4648
5010
  }
@@ -4747,17 +5109,30 @@ FormModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15
4747
5109
  FormModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FormModule, providers: [
4748
5110
  FormService,
4749
5111
  ControlConfigService,
4750
- ZipConverter,
4751
- EmailConverter,
4752
5112
  CardNumberConverter,
4753
- CardExpirationConverter,
5113
+ CardMonthConverter,
5114
+ CardYearConverter,
5115
+ CvvConverter,
4754
5116
  CvvConverter,
5117
+ ZipConverter,
4755
5118
  CardholderNameConverter,
4756
5119
  CpfNumberConverter,
4757
5120
  CpfNameConverter,
4758
5121
  BirthDateConverter,
5122
+ TextConverter,
5123
+ CheckboxConverter,
5124
+ SelectConverter,
5125
+ PinConverter,
5126
+ RadioGroupConverter,
5127
+ EmailConverter,
5128
+ EmailConverter,
5129
+ EmailConverter,
4759
5130
  StreetNumberConverter,
5131
+ PricepointConverter,
5132
+ PricepointConverter,
5133
+ CouponConverter,
4760
5134
  TextConverter,
5135
+ PhoneConverter,
4761
5136
  { provide: convertersMapToken, useValue: convertersMap },
4762
5137
  ], imports: [ReactiveFormsModule, ValidatorsModule] });
4763
5138
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FormModule, decorators: [{
@@ -4767,17 +5142,30 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
4767
5142
  providers: [
4768
5143
  FormService,
4769
5144
  ControlConfigService,
4770
- ZipConverter,
4771
- EmailConverter,
4772
5145
  CardNumberConverter,
4773
- CardExpirationConverter,
5146
+ CardMonthConverter,
5147
+ CardYearConverter,
4774
5148
  CvvConverter,
5149
+ CvvConverter,
5150
+ ZipConverter,
4775
5151
  CardholderNameConverter,
4776
5152
  CpfNumberConverter,
4777
5153
  CpfNameConverter,
4778
5154
  BirthDateConverter,
5155
+ TextConverter,
5156
+ CheckboxConverter,
5157
+ SelectConverter,
5158
+ PinConverter,
5159
+ RadioGroupConverter,
5160
+ EmailConverter,
5161
+ EmailConverter,
5162
+ EmailConverter,
4779
5163
  StreetNumberConverter,
5164
+ PricepointConverter,
5165
+ PricepointConverter,
5166
+ CouponConverter,
4780
5167
  TextConverter,
5168
+ PhoneConverter,
4781
5169
  { provide: convertersMapToken, useValue: convertersMap },
4782
5170
  ],
4783
5171
  }]