@xsolla/payment-client-core 0.1.18 → 0.1.20

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.
@@ -247,6 +247,9 @@ class PaymentMethodsService {
247
247
  getList(isSaveMethodMode) {
248
248
  return __awaiter(this, void 0, void 0, function* () {
249
249
  const response = yield this.request(isSaveMethodMode);
250
+ if (this.isFixedPaymentMethod) {
251
+ return this.filterMethodsByFixedPaymentMethod(response.remained);
252
+ }
250
253
  return response.remained;
251
254
  });
252
255
  }
@@ -280,6 +283,16 @@ class PaymentMethodsService {
280
283
  return this.cache.get(cacheKey);
281
284
  });
282
285
  }
286
+ filterMethodsByFixedPaymentMethod(methods) {
287
+ var _a, _b;
288
+ const fixedPid = (_b = (_a = this.settingsService.purchase) === null || _a === void 0 ? void 0 : _a.payment_system) === null || _b === void 0 ? void 0 : _b.id;
289
+ const paymentMethod = methods.find((method) => method.id === fixedPid);
290
+ return paymentMethod ? [paymentMethod] : [];
291
+ }
292
+ get isFixedPaymentMethod() {
293
+ var _a, _b;
294
+ return !!((_b = (_a = this.settingsService.purchase) === null || _a === void 0 ? void 0 : _a.payment_system) === null || _b === void 0 ? void 0 : _b.id);
295
+ }
283
296
  }
284
297
  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 });
285
298
  PaymentMethodsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentMethodsService, providedIn: 'root' });
@@ -609,25 +622,6 @@ class SubmitResponse {
609
622
  }
610
623
  }
611
624
 
612
- const isSubmitResponse = (value) => {
613
- return value instanceof SubmitResponse;
614
- };
615
-
616
- var InputEventName;
617
- (function (InputEventName) {
618
- InputEventName["blur"] = "blur";
619
- InputEventName["focus"] = "focus";
620
- })(InputEventName || (InputEventName = {}));
621
-
622
- class ShowErrorsAction {
623
- constructor(errors) {
624
- this.type = 'show_errors';
625
- this.data = {
626
- errors,
627
- };
628
- }
629
- }
630
-
631
625
  class InitializeResponse {
632
626
  constructor(response) {
633
627
  this.paymentForm = null;
@@ -672,6 +666,25 @@ class InitializeResponse {
672
666
  }
673
667
  }
674
668
 
669
+ const isSubmitResponse = (value) => {
670
+ return value instanceof SubmitResponse;
671
+ };
672
+
673
+ var InputEventName;
674
+ (function (InputEventName) {
675
+ InputEventName["blur"] = "blur";
676
+ InputEventName["focus"] = "focus";
677
+ })(InputEventName || (InputEventName = {}));
678
+
679
+ class ShowErrorsAction {
680
+ constructor(errors) {
681
+ this.type = 'show_errors';
682
+ this.data = {
683
+ errors,
684
+ };
685
+ }
686
+ }
687
+
675
688
  const initializeResponseFactoryToken = new InjectionToken('InitializeResponse');
676
689
  const initializeResponseFactoryProvider = {
677
690
  provide: initializeResponseFactoryToken,
@@ -1901,6 +1914,7 @@ class SyncService extends EmitDataService {
1901
1914
  this.prevFieldSyncStates = {};
1902
1915
  this.form = new UntypedFormGroup({});
1903
1916
  this.fields = [];
1917
+ this.fieldSyncTimers = {};
1904
1918
  this.fieldAsyncValidation = new Subject();
1905
1919
  }
1906
1920
  get fieldAsyncValidation$() {
@@ -1916,7 +1930,7 @@ class SyncService extends EmitDataService {
1916
1930
  this.form = new UntypedFormGroup({});
1917
1931
  this.fields = [];
1918
1932
  }
1919
- validate(field) {
1933
+ validate(field, delay = Number('750')) {
1920
1934
  return __awaiter(this, void 0, void 0, function* () {
1921
1935
  if (!this.isReadyField(field)) {
1922
1936
  return Promise.resolve(null);
@@ -1934,16 +1948,32 @@ class SyncService extends EmitDataService {
1934
1948
  return (_a = response === null || response === void 0 ? void 0 : response.error) !== null && _a !== void 0 ? _a : null;
1935
1949
  });
1936
1950
  }
1937
- const requestPromise = this.request(field);
1938
- this.setPrevFieldSyncState(field, value, requestPromise);
1939
- return requestPromise.then((response) => {
1940
- var _a;
1941
- this.fieldAsyncValidation.next({
1942
- value,
1943
- field,
1944
- response,
1951
+ const updateFieldState = () => __awaiter(this, void 0, void 0, function* () {
1952
+ const requestPromise = this.request(field);
1953
+ this.setPrevFieldSyncState(field, value, requestPromise);
1954
+ return requestPromise.then((response) => {
1955
+ var _a;
1956
+ this.fieldAsyncValidation.next({
1957
+ value,
1958
+ field,
1959
+ response,
1960
+ });
1961
+ return (_a = response.error) !== null && _a !== void 0 ? _a : null;
1945
1962
  });
1946
- return (_a = response.error) !== null && _a !== void 0 ? _a : null;
1963
+ });
1964
+ return new Promise((resolve) => {
1965
+ if (delay) {
1966
+ const timerId = setTimeout(() => {
1967
+ if (value !== (control === null || control === void 0 ? void 0 : control.value)) {
1968
+ return resolve(null);
1969
+ }
1970
+ void updateFieldState().then((errors) => resolve(errors));
1971
+ }, delay);
1972
+ this.resetFieldSyncTimer(field, Number(timerId));
1973
+ }
1974
+ else {
1975
+ void updateFieldState().then((errors) => resolve(errors));
1976
+ }
1947
1977
  });
1948
1978
  });
1949
1979
  }
@@ -1990,6 +2020,13 @@ class SyncService extends EmitDataService {
1990
2020
  this.nextActionService.emitFlowUpdates(new ShowErrorsAction(formErrors));
1991
2021
  }
1992
2022
  }
2023
+ resetFieldSyncTimer(field, timerId) {
2024
+ const prevTimerId = this.fieldSyncTimers[field.name];
2025
+ if (prevTimerId) {
2026
+ clearTimeout(prevTimerId);
2027
+ }
2028
+ this.fieldSyncTimers[field.name] = timerId;
2029
+ }
1993
2030
  }
1994
2031
  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 });
1995
2032
  SyncService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SyncService, providedIn: 'root' });
@@ -5407,6 +5444,7 @@ class PaymentService {
5407
5444
  this.data = yield this.initializeService.request(config);
5408
5445
  this.fields = this.getFields();
5409
5446
  this.form = this.formService.createForm(this.fields);
5447
+ this.updatePidConfig();
5410
5448
  this.setupSyncService(this.form, this.fields);
5411
5449
  this.listenFormStatusChanges(this.form);
5412
5450
  this.emitFinanceDetails((_a = this.data.paymentForm) === null || _a === void 0 ? void 0 : _a.summary);
@@ -5450,6 +5488,16 @@ class PaymentService {
5450
5488
  }
5451
5489
  return (_d = (_c = (_b = this.data) === null || _b === void 0 ? void 0 : _b.paymentForm) === null || _c === void 0 ? void 0 : _c.fields) !== null && _d !== void 0 ? _d : [];
5452
5490
  }
5491
+ getPid() {
5492
+ var _a, _b, _c;
5493
+ if (this.data instanceof SubmitResponse) {
5494
+ return (Number((_a = this.data.fields.find((field) => field.name === 'fix_pid')) === null || _a === void 0 ? void 0 : _a.value) || null);
5495
+ }
5496
+ if (this.data instanceof InitializeResponse) {
5497
+ return (Number((_c = (_b = this.data.paymentForm) === null || _b === void 0 ? void 0 : _b.fields.find((field) => field.name === 'fix_pid')) === null || _c === void 0 ? void 0 : _c.value) || null);
5498
+ }
5499
+ return null;
5500
+ }
5453
5501
  validate(field) {
5454
5502
  return __awaiter(this, void 0, void 0, function* () {
5455
5503
  const syncErrors = this.syncService.getSyncValidationErrors(field);
@@ -5578,6 +5626,15 @@ class PaymentService {
5578
5626
  .pipe(takeUntil(this.formDestroy$))
5579
5627
  .subscribe(() => this.emitFormFieldsStatus(form));
5580
5628
  }
5629
+ /*
5630
+ * in case the form pid changes despite the one passed during initialization
5631
+ * */
5632
+ updatePidConfig() {
5633
+ const currentPid = this.getPid();
5634
+ if (currentPid) {
5635
+ this.config.paymentMethodId = currentPid;
5636
+ }
5637
+ }
5581
5638
  }
5582
5639
  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 }, { token: ThreeDsService }, { token: FormMessagesService }], target: i0.ɵɵFactoryTarget.Injectable });
5583
5640
  PaymentService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, providedIn: 'root' });
@@ -5780,6 +5837,7 @@ class CoreLibraryService {
5780
5837
  initialize: () => __awaiter(this, void 0, void 0, function* () { return this.paymentService.initialize(enrichedConfig); }),
5781
5838
  submit: () => __awaiter(this, void 0, void 0, function* () { return this.paymentService.submit(); }),
5782
5839
  getFields: () => this.paymentService.getFields(),
5840
+ getPid: () => this.paymentService.getPid(),
5783
5841
  validate: (field) => __awaiter(this, void 0, void 0, function* () { return this.paymentService.validate(field); }),
5784
5842
  getFinanceDetails: () => this.paymentService.getFinanceDetails(),
5785
5843
  runThreeDs: () => this.paymentService.runThreeDs(),
@@ -5792,6 +5850,7 @@ class CoreLibraryService {
5792
5850
  changeFieldState: (name, state) => this.paymentService.changeFieldState(name, state),
5793
5851
  updateFieldFormState: (fieldName, formState) => this.paymentService.updateFieldFormState(fieldName, formState),
5794
5852
  formMessages$: this.formMessagesService.data$,
5853
+ getFormStatus: () => { var _a; return (_a = this.paymentService.form) === null || _a === void 0 ? void 0 : _a.status; },
5795
5854
  },
5796
5855
  };
5797
5856
  }