@xsolla/payment-client-core 0.1.18 → 0.1.19

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.
@@ -240,6 +240,9 @@ class PaymentMethodsService {
240
240
  }
241
241
  async getList(isSaveMethodMode) {
242
242
  const response = await this.request(isSaveMethodMode);
243
+ if (this.isFixedPaymentMethod) {
244
+ return this.filterMethodsByFixedPaymentMethod(response.remained);
245
+ }
243
246
  return response.remained;
244
247
  }
245
248
  async getQuickMethods() {
@@ -268,6 +271,14 @@ class PaymentMethodsService {
268
271
  // @ts-expect-error the map already has the cache with key
269
272
  return this.cache.get(cacheKey);
270
273
  }
274
+ filterMethodsByFixedPaymentMethod(methods) {
275
+ const fixedPid = this.settingsService.purchase?.payment_system?.id;
276
+ const paymentMethod = methods.find((method) => method.id === fixedPid);
277
+ return paymentMethod ? [paymentMethod] : [];
278
+ }
279
+ get isFixedPaymentMethod() {
280
+ return !!this.settingsService.purchase?.payment_system?.id;
281
+ }
271
282
  }
272
283
  PaymentMethodsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentMethodsService, deps: [{ token: paymentMethodsResponseFactoryToken }, { token: SettingsService }, { token: CountryService }, { token: SecureApiClient }], target: i0.ɵɵFactoryTarget.Injectable });
273
284
  PaymentMethodsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentMethodsService, providedIn: 'root' });
@@ -1859,6 +1870,7 @@ class SyncService extends EmitDataService {
1859
1870
  this.prevFieldSyncStates = {};
1860
1871
  this.form = new UntypedFormGroup({});
1861
1872
  this.fields = [];
1873
+ this.fieldSyncTimers = {};
1862
1874
  this.fieldAsyncValidation = new Subject();
1863
1875
  }
1864
1876
  get fieldAsyncValidation$() {
@@ -1874,7 +1886,7 @@ class SyncService extends EmitDataService {
1874
1886
  this.form = new UntypedFormGroup({});
1875
1887
  this.fields = [];
1876
1888
  }
1877
- async validate(field) {
1889
+ async validate(field, delay = Number('750')) {
1878
1890
  if (!this.isReadyField(field)) {
1879
1891
  return Promise.resolve(null);
1880
1892
  }
@@ -1890,15 +1902,31 @@ class SyncService extends EmitDataService {
1890
1902
  return response?.error ?? null;
1891
1903
  });
1892
1904
  }
1893
- const requestPromise = this.request(field);
1894
- this.setPrevFieldSyncState(field, value, requestPromise);
1895
- return requestPromise.then((response) => {
1896
- this.fieldAsyncValidation.next({
1897
- value,
1898
- field,
1899
- response,
1905
+ const updateFieldState = async () => {
1906
+ const requestPromise = this.request(field);
1907
+ this.setPrevFieldSyncState(field, value, requestPromise);
1908
+ return requestPromise.then((response) => {
1909
+ this.fieldAsyncValidation.next({
1910
+ value,
1911
+ field,
1912
+ response,
1913
+ });
1914
+ return response.error ?? null;
1900
1915
  });
1901
- return response.error ?? null;
1916
+ };
1917
+ return new Promise((resolve) => {
1918
+ if (delay) {
1919
+ const timerId = setTimeout(() => {
1920
+ if (value !== control?.value) {
1921
+ return resolve(null);
1922
+ }
1923
+ void updateFieldState().then((errors) => resolve(errors));
1924
+ }, delay);
1925
+ this.resetFieldSyncTimer(field, Number(timerId));
1926
+ }
1927
+ else {
1928
+ void updateFieldState().then((errors) => resolve(errors));
1929
+ }
1902
1930
  });
1903
1931
  }
1904
1932
  getSyncValidationErrors(field) {
@@ -1939,6 +1967,13 @@ class SyncService extends EmitDataService {
1939
1967
  this.nextActionService.emitFlowUpdates(new ShowErrorsAction(formErrors));
1940
1968
  }
1941
1969
  }
1970
+ resetFieldSyncTimer(field, timerId) {
1971
+ const prevTimerId = this.fieldSyncTimers[field.name];
1972
+ if (prevTimerId) {
1973
+ clearTimeout(prevTimerId);
1974
+ }
1975
+ this.fieldSyncTimers[field.name] = timerId;
1976
+ }
1942
1977
  }
1943
1978
  SyncService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SyncService, deps: [{ token: syncRequestFactoryToken }, { token: syncResponseFactoryToken }, { token: XpsApiService }, { token: NextActionService }, { token: SettingsService }, { token: XpsResponseErrorsMappingService }, { token: EncryptCreditCardService }], target: i0.ɵɵFactoryTarget.Injectable });
1944
1979
  SyncService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SyncService, providedIn: 'root' });
@@ -5637,6 +5672,7 @@ class CoreLibraryService {
5637
5672
  changeFieldState: (name, state) => this.paymentService.changeFieldState(name, state),
5638
5673
  updateFieldFormState: (fieldName, formState) => this.paymentService.updateFieldFormState(fieldName, formState),
5639
5674
  formMessages$: this.formMessagesService.data$,
5675
+ getFormStatus: () => this.paymentService.form?.status,
5640
5676
  },
5641
5677
  };
5642
5678
  }