@xsolla/payment-client-core 0.1.5 → 0.1.6
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.
- package/esm2020/lib/core/payment/form/controls/card-number/card-number-control.config.mjs +10 -0
- package/esm2020/lib/core/payment/form/controls/checkbox/checkbox-control.config.mjs +10 -0
- package/esm2020/lib/core/payment/form/controls/coupon/coupon-control.config.mjs +8 -0
- package/esm2020/lib/core/payment/form/controls/radio-control/radio-control.config.mjs +9 -0
- package/esm2020/lib/core/payment/form/controls/radio-control/radio-option.interface.mjs +2 -0
- package/esm2020/lib/core/payment/form/controls/search-select/search-select-control.config.mjs +8 -0
- package/esm2020/lib/core/payment/form/controls/search-select/search-select-option.interface.mjs +2 -0
- package/esm2020/lib/core/payment/form/controls/search-select/select-option.interface.mjs +2 -0
- package/esm2020/lib/core/payment/form/converters/birth-date/birth-date.converter.mjs +38 -0
- package/esm2020/lib/core/payment/form/converters/card-month/card-month.converter.mjs +38 -0
- package/esm2020/lib/core/payment/form/converters/card-number/card-number.converter.mjs +45 -0
- package/esm2020/lib/core/payment/form/converters/card-year/card-year.converter.mjs +38 -0
- package/esm2020/lib/core/payment/form/converters/cardholder-name/cardholder-name.converter.mjs +25 -0
- package/esm2020/lib/core/payment/form/converters/checkbox/checkbox.converter.mjs +34 -0
- package/esm2020/lib/core/payment/form/converters/converter.abstract.mjs +4 -3
- package/esm2020/lib/core/payment/form/converters/converters-map.mjs +32 -16
- package/esm2020/lib/core/payment/form/converters/coupon/coupon.converter.mjs +25 -0
- package/esm2020/lib/core/payment/form/converters/cpf-name/cpf-name-regex.variable.mjs +2 -0
- package/esm2020/lib/core/payment/form/converters/cpf-name/cpf-name.converter.mjs +34 -0
- package/esm2020/lib/core/payment/form/converters/cpf-number/cpf-number.converter.mjs +31 -0
- package/esm2020/lib/core/payment/form/converters/cvv/cvv-form-state.interface.mjs +2 -0
- package/esm2020/lib/core/payment/form/converters/cvv/cvv.converter.mjs +72 -0
- package/esm2020/lib/core/payment/form/converters/email/email.converter.mjs +29 -0
- package/esm2020/lib/core/payment/form/converters/pin/pin.converter.mjs +19 -0
- package/esm2020/lib/core/payment/form/converters/pricepoint/pricepoint.converter.mjs +32 -0
- package/esm2020/lib/core/payment/form/converters/radio-group/radio-group.converter.mjs +21 -0
- package/esm2020/lib/core/payment/form/converters/select/select.converter.mjs +21 -0
- package/esm2020/lib/core/payment/form/converters/street-number/street-number.converter.mjs +2 -2
- package/esm2020/lib/core/payment/form/converters/text/text.converter.mjs +19 -0
- package/esm2020/lib/core/payment/form/converters/zip/zip.converter.mjs +67 -0
- package/esm2020/lib/core/payment/form/field-form-states.interface.mjs +2 -0
- package/esm2020/lib/core/payment/form/form.module.mjs +48 -19
- package/esm2020/lib/core/payment/form/form.service.mjs +19 -1
- package/esm2020/lib/core/payment/form/validators/birth-date/birth-date.validator.mjs +37 -0
- package/esm2020/lib/core/payment/form/validators/card-month/card-month.validator.mjs +37 -0
- package/esm2020/lib/core/payment/form/validators/card-year/card-year.validator.mjs +34 -0
- package/esm2020/lib/core/payment/form/validators/coupon/coupon-validator.mjs +6 -0
- package/esm2020/lib/core/payment/form/validators/credit-card-length/credit-card-min-length.validator.mjs +32 -0
- package/esm2020/lib/core/payment/form/validators/email/email-validator.mjs +7 -0
- package/esm2020/lib/core/payment/form/validators/required/required.validator.mjs +6 -0
- package/esm2020/lib/core/payment/form/validators/restricted-value/restricted-value.validator.mjs +6 -0
- package/esm2020/lib/core/payment/form/validators/validators.module.mjs +2 -2
- package/esm2020/lib/core/payment/payment.interface.mjs +1 -1
- package/esm2020/lib/core/payment/payment.service.mjs +6 -1
- package/esm2020/lib/core-library.service.mjs +2 -1
- package/fesm2015/xsolla-payment-client-core.mjs +357 -24
- package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
- package/fesm2020/xsolla-payment-client-core.mjs +357 -24
- package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
- package/lib/core/payment/form/controls/{card-number-control.config.d.ts → card-number/card-number-control.config.d.ts} +2 -2
- package/lib/core/payment/form/controls/checkbox/checkbox-control.config.d.ts +6 -0
- package/lib/core/payment/form/controls/coupon/coupon-control.config.d.ts +8 -0
- package/lib/core/payment/form/controls/radio-control/radio-control.config.d.ts +6 -0
- package/lib/core/payment/form/controls/radio-control/radio-option.interface.d.ts +5 -0
- package/lib/core/payment/form/controls/search-select/search-select-control.config.d.ts +11 -0
- package/lib/core/payment/form/controls/search-select/search-select-option.interface.d.ts +19 -0
- package/lib/core/payment/form/controls/search-select/select-option.interface.d.ts +13 -0
- package/lib/core/payment/form/converters/{birth-date.converter.d.ts → birth-date/birth-date.converter.d.ts} +4 -4
- package/lib/core/payment/form/converters/card-month/card-month.converter.d.ts +16 -0
- package/lib/core/payment/form/converters/{card-number.converter.d.ts → card-number/card-number.converter.d.ts} +6 -6
- package/lib/core/payment/form/converters/card-year/card-year.converter.d.ts +16 -0
- package/lib/core/payment/form/converters/{cardholder-name.converter.d.ts → cardholder-name/cardholder-name.converter.d.ts} +4 -4
- package/lib/core/payment/form/converters/checkbox/checkbox.converter.d.ts +16 -0
- package/lib/core/payment/form/converters/converter.abstract.d.ts +1 -1
- package/lib/core/payment/form/converters/coupon/coupon.converter.d.ts +13 -0
- package/lib/core/payment/form/converters/{cpf-name.converter.d.ts → cpf-name/cpf-name.converter.d.ts} +4 -4
- package/lib/core/payment/form/converters/{cpf-number.converter.d.ts → cpf-number/cpf-number.converter.d.ts} +4 -4
- package/lib/core/payment/form/converters/cvv/cvv-form-state.interface.d.ts +3 -0
- package/lib/core/payment/form/converters/{cvv.converter.d.ts → cvv/cvv.converter.d.ts} +8 -7
- package/lib/core/payment/form/converters/{email.converter.d.ts → email/email.converter.d.ts} +5 -5
- package/lib/core/payment/form/converters/pin/pin.converter.d.ts +11 -0
- package/lib/core/payment/form/converters/pricepoint/pricepoint.converter.d.ts +14 -0
- package/lib/core/payment/form/converters/radio-group/radio-group.converter.d.ts +11 -0
- package/lib/core/payment/form/converters/select/select.converter.d.ts +11 -0
- package/lib/core/payment/form/converters/{text.converter.d.ts → text/text.converter.d.ts} +4 -4
- package/lib/core/payment/form/converters/{zip.converter.d.ts → zip/zip.converter.d.ts} +5 -5
- package/lib/core/payment/form/field-form-states.interface.d.ts +4 -0
- package/lib/core/payment/form/form.service.d.ts +4 -0
- package/lib/core/payment/form/validators/card-month/card-month.validator.d.ts +5 -0
- package/lib/core/payment/form/validators/card-year/card-year.validator.d.ts +5 -0
- package/lib/core/payment/form/validators/coupon/coupon-validator.d.ts +2 -0
- 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
- package/lib/core/payment/form/validators/{email-validator.d.ts → email/email-validator.d.ts} +1 -1
- package/lib/core/payment/form/validators/{restricted-value.validator.d.ts → restricted-value/restricted-value.validator.d.ts} +1 -1
- package/lib/core/payment/payment.interface.d.ts +2 -0
- package/lib/core/payment/payment.service.d.ts +2 -0
- package/package.json +1 -1
- package/xsolla-payment-client-core-0.1.6.tgz +0 -0
- package/esm2020/lib/core/payment/form/controls/card-number-control.config.mjs +0 -10
- package/esm2020/lib/core/payment/form/converters/birth-date.converter.mjs +0 -38
- package/esm2020/lib/core/payment/form/converters/card-expiration.converter.mjs +0 -36
- package/esm2020/lib/core/payment/form/converters/card-number.converter.mjs +0 -45
- package/esm2020/lib/core/payment/form/converters/cardholder-name.converter.mjs +0 -25
- package/esm2020/lib/core/payment/form/converters/cpf-name-regex.variable.mjs +0 -2
- package/esm2020/lib/core/payment/form/converters/cpf-name.converter.mjs +0 -34
- package/esm2020/lib/core/payment/form/converters/cpf-number.converter.mjs +0 -31
- package/esm2020/lib/core/payment/form/converters/cvv.converter.mjs +0 -50
- package/esm2020/lib/core/payment/form/converters/email.converter.mjs +0 -29
- package/esm2020/lib/core/payment/form/converters/text.converter.mjs +0 -19
- package/esm2020/lib/core/payment/form/converters/zip.converter.mjs +0 -67
- package/esm2020/lib/core/payment/form/validators/birth-date.validator.mjs +0 -37
- package/esm2020/lib/core/payment/form/validators/credit-card-min-length.validator.mjs +0 -32
- package/esm2020/lib/core/payment/form/validators/email-validator.mjs +0 -7
- package/esm2020/lib/core/payment/form/validators/required-validator.mjs +0 -6
- package/esm2020/lib/core/payment/form/validators/restricted-value.validator.mjs +0 -6
- package/lib/core/payment/form/converters/card-expiration.converter.d.ts +0 -16
- package/xsolla-payment-client-core-0.1.5.tgz +0 -0
- /package/lib/core/payment/form/converters/{cpf-name-regex.variable.d.ts → cpf-name/cpf-name-regex.variable.d.ts} +0 -0
- /package/lib/core/payment/form/validators/{birth-date.validator.d.ts → birth-date/birth-date.validator.d.ts} +0 -0
- /package/lib/core/payment/form/validators/{required-validator.d.ts → required/required.validator.d.ts} +0 -0
|
@@ -1765,7 +1765,8 @@ class Converter {
|
|
|
1765
1765
|
convertToFormControl(field) {
|
|
1766
1766
|
return new UntypedFormControl(this.getValue(field), this.getValidators(field), this.getAsyncValidators(field));
|
|
1767
1767
|
}
|
|
1768
|
-
|
|
1768
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1769
|
+
getValidators(field, formState) {
|
|
1769
1770
|
const validators = [];
|
|
1770
1771
|
if (field.isMandatory === "1" /* XpsBoolean.true */) {
|
|
1771
1772
|
validators.push(convertedRequiredValidator());
|
|
@@ -2029,12 +2030,49 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
2029
2030
|
type: Injectable
|
|
2030
2031
|
}], ctorParameters: function () { return [{ type: SyncService }, { type: CreditCardMinLengthValidator }, { type: CreditCardMinLengthValidator }]; } });
|
|
2031
2032
|
|
|
2032
|
-
|
|
2033
|
+
const maxMonths = 12;
|
|
2034
|
+
const getMinMonth = (parsedYear) => {
|
|
2035
|
+
let minMonth = 1;
|
|
2036
|
+
const year = parsedYear ? Number('20' + parsedYear) : null;
|
|
2037
|
+
const today = new Date();
|
|
2038
|
+
minMonth = year === today.getFullYear() ? today.getMonth() + 1 : 1;
|
|
2039
|
+
return minMonth;
|
|
2040
|
+
};
|
|
2041
|
+
const sendErrMessage$1 = (fn) => ({
|
|
2042
|
+
cardMonthExpiration: {
|
|
2043
|
+
message: fn,
|
|
2044
|
+
},
|
|
2045
|
+
});
|
|
2046
|
+
function cardMonthValidator(formState) {
|
|
2047
|
+
return (control) => {
|
|
2048
|
+
const { value } = control;
|
|
2049
|
+
if (typeof value !== 'string')
|
|
2050
|
+
return null;
|
|
2051
|
+
const minMonth = getMinMonth(formState?.cardYearValue ?? null);
|
|
2052
|
+
const twoDigitsRegex = new RegExp(/^\d{2}$/);
|
|
2053
|
+
const fieldCommonLength = 2;
|
|
2054
|
+
if (value.length !== fieldCommonLength) {
|
|
2055
|
+
return sendErrMessage$1(`Enter ${fieldCommonLength} characters`);
|
|
2056
|
+
}
|
|
2057
|
+
if (!twoDigitsRegex.test(value)) {
|
|
2058
|
+
return sendErrMessage$1(`Enter a valid expiration month`);
|
|
2059
|
+
}
|
|
2060
|
+
if (Number(value) < minMonth) {
|
|
2061
|
+
return sendErrMessage$1(`Enter a month greater than or equal to ${minMonth}`);
|
|
2062
|
+
}
|
|
2063
|
+
if (Number(value) > maxMonths) {
|
|
2064
|
+
return sendErrMessage$1(`Enter a month less than or equal to ${maxMonths}`);
|
|
2065
|
+
}
|
|
2066
|
+
return null;
|
|
2067
|
+
};
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
class CardMonthConverter extends Converter {
|
|
2033
2071
|
constructor(syncService) {
|
|
2034
2072
|
super(syncService);
|
|
2035
2073
|
}
|
|
2036
|
-
getValidators() {
|
|
2037
|
-
return [];
|
|
2074
|
+
getValidators(field, formState) {
|
|
2075
|
+
return super.getValidators(field).concat([cardMonthValidator(formState)]);
|
|
2038
2076
|
}
|
|
2039
2077
|
createControlConfig(field, formState) {
|
|
2040
2078
|
const config = this.createDefaultControlConfig(TextControlConfig, field);
|
|
@@ -2043,20 +2081,21 @@ class CardExpirationConverter extends Converter {
|
|
|
2043
2081
|
guide: false,
|
|
2044
2082
|
};
|
|
2045
2083
|
config.inputMode = 'numeric';
|
|
2046
|
-
config.
|
|
2084
|
+
config.placeholder = `MM`;
|
|
2085
|
+
config.title = `MM`;
|
|
2047
2086
|
config.disabled = formState?.disabled ?? false;
|
|
2048
2087
|
return config;
|
|
2049
2088
|
}
|
|
2050
2089
|
getAutocomplete() {
|
|
2051
|
-
return 'cc-exp';
|
|
2090
|
+
return 'cc-exp-month';
|
|
2052
2091
|
}
|
|
2053
2092
|
getDataType() {
|
|
2054
2093
|
return 'text';
|
|
2055
2094
|
}
|
|
2056
2095
|
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type:
|
|
2096
|
+
CardMonthConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardMonthConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2097
|
+
CardMonthConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardMonthConverter });
|
|
2098
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardMonthConverter, decorators: [{
|
|
2060
2099
|
type: Injectable
|
|
2061
2100
|
}], ctorParameters: function () { return [{ type: SyncService }]; } });
|
|
2062
2101
|
|
|
@@ -2066,8 +2105,27 @@ class CvvConverter extends Converter {
|
|
|
2066
2105
|
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
2067
2106
|
this.maxFieldLength = 4;
|
|
2068
2107
|
}
|
|
2069
|
-
getValidators() {
|
|
2070
|
-
|
|
2108
|
+
getValidators(field, formState) {
|
|
2109
|
+
const validators = super.getValidators(field);
|
|
2110
|
+
const activeCardType = formState ? formState.activeCardType : null;
|
|
2111
|
+
const getPatternValidator = (pattern) => convert(Validators.pattern(pattern), `Enter a valid CVV/CVC`);
|
|
2112
|
+
switch (activeCardType) {
|
|
2113
|
+
case CreditCardTypes.AMERICAN_EXPRESS: {
|
|
2114
|
+
this.maxFieldLength = 4;
|
|
2115
|
+
validators.push(getPatternValidator(/^\d{4}$/));
|
|
2116
|
+
break;
|
|
2117
|
+
}
|
|
2118
|
+
case CreditCardTypes.MAESTRO: {
|
|
2119
|
+
this.maxFieldLength = 3;
|
|
2120
|
+
validators.push(getPatternValidator(/^\d{0,3}$/));
|
|
2121
|
+
break;
|
|
2122
|
+
}
|
|
2123
|
+
default: {
|
|
2124
|
+
this.maxFieldLength = 3;
|
|
2125
|
+
validators.push(getPatternValidator(/^\d{3}$/));
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
return validators;
|
|
2071
2129
|
}
|
|
2072
2130
|
createControlConfig(field, formState) {
|
|
2073
2131
|
const config = this.createDefaultControlConfig(TextControlConfig, field);
|
|
@@ -2279,21 +2337,250 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
2279
2337
|
type: Injectable
|
|
2280
2338
|
}], ctorParameters: function () { return [{ type: SyncService }]; } });
|
|
2281
2339
|
|
|
2340
|
+
class CheckboxControlConfig extends ControlConfig {
|
|
2341
|
+
constructor() {
|
|
2342
|
+
super(...arguments);
|
|
2343
|
+
this.controlType = 'checkbox';
|
|
2344
|
+
this.checkedValue = true; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
2345
|
+
this.uncheckedValue = false; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
class CheckboxConverter extends Converter {
|
|
2350
|
+
constructor(syncService) {
|
|
2351
|
+
super(syncService);
|
|
2352
|
+
this.checkedValue = "1" /* XpsBoolean.true */;
|
|
2353
|
+
this.uncheckedValue = "0" /* XpsBoolean.false */;
|
|
2354
|
+
}
|
|
2355
|
+
getValidators(field) {
|
|
2356
|
+
const validators = [];
|
|
2357
|
+
if (field.isMandatory === this.checkedValue) {
|
|
2358
|
+
validators.push(convert(restrictedValueValidator(this.uncheckedValue), 'validation_message_required_checkbox'));
|
|
2359
|
+
}
|
|
2360
|
+
return validators;
|
|
2361
|
+
}
|
|
2362
|
+
createControlConfig(field) {
|
|
2363
|
+
const config = this.createDefaultControlConfig(CheckboxControlConfig, field);
|
|
2364
|
+
config.placeholder = config.title;
|
|
2365
|
+
config.checkedValue = this.checkedValue;
|
|
2366
|
+
config.uncheckedValue = this.uncheckedValue;
|
|
2367
|
+
return config;
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
CheckboxConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckboxConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2371
|
+
CheckboxConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckboxConverter });
|
|
2372
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckboxConverter, decorators: [{
|
|
2373
|
+
type: Injectable
|
|
2374
|
+
}], ctorParameters: function () { return [{ type: SyncService }]; } });
|
|
2375
|
+
|
|
2376
|
+
class SearchSelectControlConfig extends ControlConfig {
|
|
2377
|
+
constructor() {
|
|
2378
|
+
super(...arguments);
|
|
2379
|
+
this.controlType = 'search-select';
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
class SelectConverter extends Converter {
|
|
2384
|
+
constructor(syncService) {
|
|
2385
|
+
super(syncService);
|
|
2386
|
+
}
|
|
2387
|
+
createControlConfig(field) {
|
|
2388
|
+
const config = this.createDefaultControlConfig(SearchSelectControlConfig, field);
|
|
2389
|
+
config.options = field.options;
|
|
2390
|
+
return config;
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
SelectConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SelectConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2394
|
+
SelectConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SelectConverter });
|
|
2395
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SelectConverter, decorators: [{
|
|
2396
|
+
type: Injectable
|
|
2397
|
+
}], ctorParameters: function () { return [{ type: SyncService }]; } });
|
|
2398
|
+
|
|
2399
|
+
class PinConverter extends Converter {
|
|
2400
|
+
constructor(syncService) {
|
|
2401
|
+
super(syncService);
|
|
2402
|
+
}
|
|
2403
|
+
createControlConfig(field) {
|
|
2404
|
+
return this.createDefaultControlConfig(TextControlConfig, field);
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
PinConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PinConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2408
|
+
PinConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PinConverter });
|
|
2409
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PinConverter, decorators: [{
|
|
2410
|
+
type: Injectable
|
|
2411
|
+
}], ctorParameters: function () { return [{ type: SyncService }]; } });
|
|
2412
|
+
|
|
2413
|
+
class RadioControlConfig extends ControlConfig {
|
|
2414
|
+
constructor() {
|
|
2415
|
+
super(...arguments);
|
|
2416
|
+
this.controlType = 'radio';
|
|
2417
|
+
this.options = [];
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
class RadioGroupConverter extends Converter {
|
|
2422
|
+
constructor(syncService) {
|
|
2423
|
+
super(syncService);
|
|
2424
|
+
}
|
|
2425
|
+
createControlConfig(field) {
|
|
2426
|
+
const config = this.createDefaultControlConfig(RadioControlConfig, field);
|
|
2427
|
+
config.options = field.options;
|
|
2428
|
+
return config;
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
RadioGroupConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: RadioGroupConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2432
|
+
RadioGroupConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: RadioGroupConverter });
|
|
2433
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: RadioGroupConverter, decorators: [{
|
|
2434
|
+
type: Injectable
|
|
2435
|
+
}], ctorParameters: function () { return [{ type: SyncService }]; } });
|
|
2436
|
+
|
|
2437
|
+
class PricepointConverter extends Converter {
|
|
2438
|
+
constructor(syncService) {
|
|
2439
|
+
super(syncService);
|
|
2440
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
2441
|
+
this.maxFieldLength = 30;
|
|
2442
|
+
}
|
|
2443
|
+
getValidators(field) {
|
|
2444
|
+
return super.getValidators(field);
|
|
2445
|
+
}
|
|
2446
|
+
createControlConfig(field) {
|
|
2447
|
+
const config = this.createDefaultControlConfig(TextControlConfig, field);
|
|
2448
|
+
config.maskConfig = {
|
|
2449
|
+
mask: () => new Array(this.maxFieldLength).fill('9').join(``),
|
|
2450
|
+
unmaskModelValue: false,
|
|
2451
|
+
guide: false,
|
|
2452
|
+
};
|
|
2453
|
+
config.placeholder = field.title;
|
|
2454
|
+
config.inputMode = 'numeric';
|
|
2455
|
+
return config;
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
PricepointConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PricepointConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2459
|
+
PricepointConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PricepointConverter });
|
|
2460
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PricepointConverter, decorators: [{
|
|
2461
|
+
type: Injectable
|
|
2462
|
+
}], ctorParameters: function () { return [{ type: SyncService }]; } });
|
|
2463
|
+
|
|
2464
|
+
class CouponControlConfig extends ControlConfig {
|
|
2465
|
+
constructor() {
|
|
2466
|
+
super(...arguments);
|
|
2467
|
+
this.controlType = 'coupon';
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
function couponValidator(message = `Enter a valid promo code`) {
|
|
2472
|
+
return convert(Validators.pattern(/^[0-9a-z_-]+$/i), message);
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
class CouponConverter extends Converter {
|
|
2476
|
+
constructor(syncService) {
|
|
2477
|
+
super(syncService);
|
|
2478
|
+
}
|
|
2479
|
+
getValidators() {
|
|
2480
|
+
return [couponValidator()];
|
|
2481
|
+
}
|
|
2482
|
+
createControlConfig(field) {
|
|
2483
|
+
const config = this.createDefaultControlConfig(CouponControlConfig, field);
|
|
2484
|
+
config.placeholder = `Enter promo code`;
|
|
2485
|
+
return config;
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
CouponConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CouponConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2489
|
+
CouponConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CouponConverter });
|
|
2490
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CouponConverter, decorators: [{
|
|
2491
|
+
type: Injectable
|
|
2492
|
+
}], ctorParameters: function () { return [{ type: SyncService }]; } });
|
|
2493
|
+
|
|
2494
|
+
const sendErrMessage = (fn) => ({
|
|
2495
|
+
cardYearExpiration: {
|
|
2496
|
+
message: fn,
|
|
2497
|
+
},
|
|
2498
|
+
});
|
|
2499
|
+
const getLastCharactersInYear = (str = new Date().getFullYear().toString()) => {
|
|
2500
|
+
// for getting last characters in year; need to check in future
|
|
2501
|
+
return str.slice(str.length - 2);
|
|
2502
|
+
};
|
|
2503
|
+
// Карта выдается максимум на 50 лет
|
|
2504
|
+
const maxYearsCount = 50;
|
|
2505
|
+
function cardYearValidator(control) {
|
|
2506
|
+
const { value } = control;
|
|
2507
|
+
if (typeof value !== 'string')
|
|
2508
|
+
return null;
|
|
2509
|
+
const minYear = parseInt(getLastCharactersInYear(), 10);
|
|
2510
|
+
const twoDigitsRegex = new RegExp(/^\d{2}$/);
|
|
2511
|
+
const fieldCommonLength = 2;
|
|
2512
|
+
if (value.length !== fieldCommonLength) {
|
|
2513
|
+
return sendErrMessage(`Enter ${fieldCommonLength} characters`);
|
|
2514
|
+
}
|
|
2515
|
+
if (!twoDigitsRegex.test(value)) {
|
|
2516
|
+
return sendErrMessage(`Enter a valid expiration year`);
|
|
2517
|
+
}
|
|
2518
|
+
if (Number(value) < minYear) {
|
|
2519
|
+
return sendErrMessage(`Enter a year greater than or equal to ${minYear}`);
|
|
2520
|
+
}
|
|
2521
|
+
const maxValidYear = minYear + maxYearsCount;
|
|
2522
|
+
if (Number(value) > maxValidYear) {
|
|
2523
|
+
return sendErrMessage(`Enter a year less than or equal to ${maxValidYear}`);
|
|
2524
|
+
}
|
|
2525
|
+
return null;
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
class CardYearConverter extends Converter {
|
|
2529
|
+
constructor(syncService) {
|
|
2530
|
+
super(syncService);
|
|
2531
|
+
}
|
|
2532
|
+
getValidators(field) {
|
|
2533
|
+
return super.getValidators(field).concat([cardYearValidator]);
|
|
2534
|
+
}
|
|
2535
|
+
createControlConfig(field, formState) {
|
|
2536
|
+
const config = this.createDefaultControlConfig(TextControlConfig, field);
|
|
2537
|
+
config.maskConfig = {
|
|
2538
|
+
mask: '99',
|
|
2539
|
+
guide: false,
|
|
2540
|
+
};
|
|
2541
|
+
config.inputMode = 'numeric';
|
|
2542
|
+
config.placeholder = `YY`;
|
|
2543
|
+
config.title = `YY`;
|
|
2544
|
+
config.disabled = formState?.disabled ?? false;
|
|
2545
|
+
return config;
|
|
2546
|
+
}
|
|
2547
|
+
getAutocomplete() {
|
|
2548
|
+
return 'cc-exp-year';
|
|
2549
|
+
}
|
|
2550
|
+
getDataType() {
|
|
2551
|
+
return 'text';
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
CardYearConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardYearConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2555
|
+
CardYearConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardYearConverter });
|
|
2556
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CardYearConverter, decorators: [{
|
|
2557
|
+
type: Injectable
|
|
2558
|
+
}], ctorParameters: function () { return [{ type: SyncService }]; } });
|
|
2559
|
+
|
|
2282
2560
|
const convertersMapToken = new InjectionToken('ConvertersTokensMap');
|
|
2283
2561
|
const convertersMap = {
|
|
2284
|
-
zip: ZipConverter,
|
|
2285
|
-
email: EmailConverter,
|
|
2286
2562
|
card_number: CardNumberConverter,
|
|
2287
|
-
card_month:
|
|
2288
|
-
card_year:
|
|
2563
|
+
card_month: CardMonthConverter,
|
|
2564
|
+
card_year: CardYearConverter,
|
|
2289
2565
|
cvv: CvvConverter,
|
|
2290
2566
|
extra_cvv: CvvConverter,
|
|
2567
|
+
zip: ZipConverter,
|
|
2291
2568
|
cardholdername: CardholderNameConverter,
|
|
2292
2569
|
cpf_number: CpfNumberConverter,
|
|
2293
2570
|
cpf_name: CpfNameConverter,
|
|
2294
2571
|
birth_date: BirthDateConverter,
|
|
2295
|
-
street_number: StreetNumberConverter,
|
|
2296
2572
|
text: TextConverter,
|
|
2573
|
+
check: CheckboxConverter,
|
|
2574
|
+
select: SelectConverter,
|
|
2575
|
+
pin: PinConverter,
|
|
2576
|
+
radiogroup: RadioGroupConverter,
|
|
2577
|
+
email: EmailConverter,
|
|
2578
|
+
psEmail: EmailConverter,
|
|
2579
|
+
bazitemail: EmailConverter,
|
|
2580
|
+
street_number: StreetNumberConverter,
|
|
2581
|
+
sum: PricepointConverter,
|
|
2582
|
+
out: PricepointConverter,
|
|
2583
|
+
couponCode: CouponConverter,
|
|
2297
2584
|
};
|
|
2298
2585
|
|
|
2299
2586
|
class ControlConfigService {
|
|
@@ -2342,6 +2629,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
2342
2629
|
class FormService {
|
|
2343
2630
|
constructor(controlConfigService) {
|
|
2344
2631
|
this.controlConfigService = controlConfigService;
|
|
2632
|
+
this.fieldFormStates = {};
|
|
2345
2633
|
}
|
|
2346
2634
|
createForm(fields) {
|
|
2347
2635
|
const controls = this.getVisibleFields(fields).reduce((result, field) => {
|
|
@@ -2353,6 +2641,23 @@ class FormService {
|
|
|
2353
2641
|
}, {});
|
|
2354
2642
|
return new UntypedFormGroup(controls);
|
|
2355
2643
|
}
|
|
2644
|
+
updateFieldFormState(form, fields, fieldName, formState) {
|
|
2645
|
+
const field = fields.find((fieldItem) => fieldItem.name === fieldName);
|
|
2646
|
+
if (!field) {
|
|
2647
|
+
return;
|
|
2648
|
+
}
|
|
2649
|
+
const converter = this.controlConfigService.getConverter(field);
|
|
2650
|
+
const control = form.controls[fieldName];
|
|
2651
|
+
if (!control) {
|
|
2652
|
+
return;
|
|
2653
|
+
}
|
|
2654
|
+
this.fieldFormStates[fieldName] = {
|
|
2655
|
+
...this.fieldFormStates[fieldName],
|
|
2656
|
+
...formState,
|
|
2657
|
+
};
|
|
2658
|
+
control.setValidators(converter?.getValidators(field, this.fieldFormStates[fieldName]) ?? []);
|
|
2659
|
+
control.updateValueAndValidity();
|
|
2660
|
+
}
|
|
2356
2661
|
getVisibleFields(fields) {
|
|
2357
2662
|
return fields.filter(({ isVisible }) => isVisible === "1" /* XpsBoolean.true */);
|
|
2358
2663
|
}
|
|
@@ -4241,6 +4546,11 @@ class PaymentService {
|
|
|
4241
4546
|
getFinanceDetails() {
|
|
4242
4547
|
return this.financeDetails;
|
|
4243
4548
|
}
|
|
4549
|
+
updateFieldFormState(fieldName, formState) {
|
|
4550
|
+
if (this.form) {
|
|
4551
|
+
this.formService.updateFieldFormState(this.form, this.fields, fieldName, formState);
|
|
4552
|
+
}
|
|
4553
|
+
}
|
|
4244
4554
|
async getStatus() {
|
|
4245
4555
|
if (!isSubmitResponse(this.data)) {
|
|
4246
4556
|
throw new Error('Should submit form first');
|
|
@@ -4496,6 +4806,7 @@ class CoreLibraryService {
|
|
|
4496
4806
|
getControlConfig: (field) => this.paymentService.getFieldConfig(field),
|
|
4497
4807
|
changeFieldValue: (name, value) => this.paymentService.changeFieldValue(name, value),
|
|
4498
4808
|
changeFieldState: (name, state) => this.paymentService.changeFieldState(name, state),
|
|
4809
|
+
updateFieldFormState: (fieldName, formState) => this.paymentService.updateFieldFormState(fieldName, formState),
|
|
4499
4810
|
},
|
|
4500
4811
|
};
|
|
4501
4812
|
}
|
|
@@ -4602,17 +4913,28 @@ FormModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15
|
|
|
4602
4913
|
FormModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FormModule, providers: [
|
|
4603
4914
|
FormService,
|
|
4604
4915
|
ControlConfigService,
|
|
4605
|
-
ZipConverter,
|
|
4606
|
-
EmailConverter,
|
|
4607
4916
|
CardNumberConverter,
|
|
4608
|
-
|
|
4917
|
+
CardMonthConverter,
|
|
4918
|
+
CardYearConverter,
|
|
4919
|
+
CvvConverter,
|
|
4609
4920
|
CvvConverter,
|
|
4921
|
+
ZipConverter,
|
|
4610
4922
|
CardholderNameConverter,
|
|
4611
4923
|
CpfNumberConverter,
|
|
4612
4924
|
CpfNameConverter,
|
|
4613
4925
|
BirthDateConverter,
|
|
4614
|
-
StreetNumberConverter,
|
|
4615
4926
|
TextConverter,
|
|
4927
|
+
CheckboxConverter,
|
|
4928
|
+
SelectConverter,
|
|
4929
|
+
PinConverter,
|
|
4930
|
+
RadioGroupConverter,
|
|
4931
|
+
EmailConverter,
|
|
4932
|
+
EmailConverter,
|
|
4933
|
+
EmailConverter,
|
|
4934
|
+
StreetNumberConverter,
|
|
4935
|
+
PricepointConverter,
|
|
4936
|
+
PricepointConverter,
|
|
4937
|
+
CouponConverter,
|
|
4616
4938
|
{ provide: convertersMapToken, useValue: convertersMap },
|
|
4617
4939
|
], imports: [ReactiveFormsModule, ValidatorsModule] });
|
|
4618
4940
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FormModule, decorators: [{
|
|
@@ -4622,17 +4944,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
4622
4944
|
providers: [
|
|
4623
4945
|
FormService,
|
|
4624
4946
|
ControlConfigService,
|
|
4625
|
-
ZipConverter,
|
|
4626
|
-
EmailConverter,
|
|
4627
4947
|
CardNumberConverter,
|
|
4628
|
-
|
|
4948
|
+
CardMonthConverter,
|
|
4949
|
+
CardYearConverter,
|
|
4950
|
+
CvvConverter,
|
|
4629
4951
|
CvvConverter,
|
|
4952
|
+
ZipConverter,
|
|
4630
4953
|
CardholderNameConverter,
|
|
4631
4954
|
CpfNumberConverter,
|
|
4632
4955
|
CpfNameConverter,
|
|
4633
4956
|
BirthDateConverter,
|
|
4634
|
-
StreetNumberConverter,
|
|
4635
4957
|
TextConverter,
|
|
4958
|
+
CheckboxConverter,
|
|
4959
|
+
SelectConverter,
|
|
4960
|
+
PinConverter,
|
|
4961
|
+
RadioGroupConverter,
|
|
4962
|
+
EmailConverter,
|
|
4963
|
+
EmailConverter,
|
|
4964
|
+
EmailConverter,
|
|
4965
|
+
StreetNumberConverter,
|
|
4966
|
+
PricepointConverter,
|
|
4967
|
+
PricepointConverter,
|
|
4968
|
+
CouponConverter,
|
|
4636
4969
|
{ provide: convertersMapToken, useValue: convertersMap },
|
|
4637
4970
|
],
|
|
4638
4971
|
}]
|