@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.
- package/esm2020/lib/core/payment/payment.interface.mjs +1 -1
- package/esm2020/lib/core/payment/payment.service.mjs +21 -1
- package/esm2020/lib/core/payment/sync/sync.service.mjs +34 -10
- package/esm2020/lib/core/payment-methods/payment-methods.service.mjs +12 -1
- package/esm2020/lib/core-library.service.mjs +3 -1
- package/fesm2015/xsolla-payment-client-core.mjs +88 -29
- package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
- package/fesm2020/xsolla-payment-client-core.mjs +84 -28
- package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
- package/lib/core/payment/payment.interface.d.ts +3 -1
- package/lib/core/payment/payment.service.d.ts +2 -0
- package/lib/core/payment/sync/sync.service.d.ts +3 -1
- package/lib/core/payment-methods/payment-methods.service.d.ts +2 -0
- package/package.json +1 -1
- package/xsolla-payment-client-core-0.1.20.tgz +0 -0
- package/xsolla-payment-client-core-0.1.18.tgz +0 -0
|
@@ -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' });
|
|
@@ -584,25 +595,6 @@ class SubmitResponse {
|
|
|
584
595
|
}
|
|
585
596
|
}
|
|
586
597
|
|
|
587
|
-
const isSubmitResponse = (value) => {
|
|
588
|
-
return value instanceof SubmitResponse;
|
|
589
|
-
};
|
|
590
|
-
|
|
591
|
-
var InputEventName;
|
|
592
|
-
(function (InputEventName) {
|
|
593
|
-
InputEventName["blur"] = "blur";
|
|
594
|
-
InputEventName["focus"] = "focus";
|
|
595
|
-
})(InputEventName || (InputEventName = {}));
|
|
596
|
-
|
|
597
|
-
class ShowErrorsAction {
|
|
598
|
-
constructor(errors) {
|
|
599
|
-
this.type = 'show_errors';
|
|
600
|
-
this.data = {
|
|
601
|
-
errors,
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
|
|
606
598
|
class InitializeResponse {
|
|
607
599
|
constructor(response) {
|
|
608
600
|
this.paymentForm = null;
|
|
@@ -646,6 +638,25 @@ class InitializeResponse {
|
|
|
646
638
|
}
|
|
647
639
|
}
|
|
648
640
|
|
|
641
|
+
const isSubmitResponse = (value) => {
|
|
642
|
+
return value instanceof SubmitResponse;
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
var InputEventName;
|
|
646
|
+
(function (InputEventName) {
|
|
647
|
+
InputEventName["blur"] = "blur";
|
|
648
|
+
InputEventName["focus"] = "focus";
|
|
649
|
+
})(InputEventName || (InputEventName = {}));
|
|
650
|
+
|
|
651
|
+
class ShowErrorsAction {
|
|
652
|
+
constructor(errors) {
|
|
653
|
+
this.type = 'show_errors';
|
|
654
|
+
this.data = {
|
|
655
|
+
errors,
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
649
660
|
const initializeResponseFactoryToken = new InjectionToken('InitializeResponse');
|
|
650
661
|
const initializeResponseFactoryProvider = {
|
|
651
662
|
provide: initializeResponseFactoryToken,
|
|
@@ -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
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
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
|
-
|
|
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' });
|
|
@@ -5271,6 +5306,7 @@ class PaymentService {
|
|
|
5271
5306
|
this.data = await this.initializeService.request(config);
|
|
5272
5307
|
this.fields = this.getFields();
|
|
5273
5308
|
this.form = this.formService.createForm(this.fields);
|
|
5309
|
+
this.updatePidConfig();
|
|
5274
5310
|
this.setupSyncService(this.form, this.fields);
|
|
5275
5311
|
this.listenFormStatusChanges(this.form);
|
|
5276
5312
|
this.emitFinanceDetails(this.data.paymentForm?.summary);
|
|
@@ -5310,6 +5346,15 @@ class PaymentService {
|
|
|
5310
5346
|
}
|
|
5311
5347
|
return this.data?.paymentForm?.fields ?? [];
|
|
5312
5348
|
}
|
|
5349
|
+
getPid() {
|
|
5350
|
+
if (this.data instanceof SubmitResponse) {
|
|
5351
|
+
return (Number(this.data.fields.find((field) => field.name === 'fix_pid')?.value) || null);
|
|
5352
|
+
}
|
|
5353
|
+
if (this.data instanceof InitializeResponse) {
|
|
5354
|
+
return (Number(this.data.paymentForm?.fields.find((field) => field.name === 'fix_pid')?.value) || null);
|
|
5355
|
+
}
|
|
5356
|
+
return null;
|
|
5357
|
+
}
|
|
5313
5358
|
async validate(field) {
|
|
5314
5359
|
const syncErrors = this.syncService.getSyncValidationErrors(field);
|
|
5315
5360
|
if (syncErrors) {
|
|
@@ -5432,6 +5477,15 @@ class PaymentService {
|
|
|
5432
5477
|
.pipe(takeUntil(this.formDestroy$))
|
|
5433
5478
|
.subscribe(() => this.emitFormFieldsStatus(form));
|
|
5434
5479
|
}
|
|
5480
|
+
/*
|
|
5481
|
+
* in case the form pid changes despite the one passed during initialization
|
|
5482
|
+
* */
|
|
5483
|
+
updatePidConfig() {
|
|
5484
|
+
const currentPid = this.getPid();
|
|
5485
|
+
if (currentPid) {
|
|
5486
|
+
this.config.paymentMethodId = currentPid;
|
|
5487
|
+
}
|
|
5488
|
+
}
|
|
5435
5489
|
}
|
|
5436
5490
|
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 });
|
|
5437
5491
|
PaymentService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, providedIn: 'root' });
|
|
@@ -5625,6 +5679,7 @@ class CoreLibraryService {
|
|
|
5625
5679
|
initialize: async () => this.paymentService.initialize(enrichedConfig),
|
|
5626
5680
|
submit: async () => this.paymentService.submit(),
|
|
5627
5681
|
getFields: () => this.paymentService.getFields(),
|
|
5682
|
+
getPid: () => this.paymentService.getPid(),
|
|
5628
5683
|
validate: async (field) => this.paymentService.validate(field),
|
|
5629
5684
|
getFinanceDetails: () => this.paymentService.getFinanceDetails(),
|
|
5630
5685
|
runThreeDs: () => this.paymentService.runThreeDs(),
|
|
@@ -5637,6 +5692,7 @@ class CoreLibraryService {
|
|
|
5637
5692
|
changeFieldState: (name, state) => this.paymentService.changeFieldState(name, state),
|
|
5638
5693
|
updateFieldFormState: (fieldName, formState) => this.paymentService.updateFieldFormState(fieldName, formState),
|
|
5639
5694
|
formMessages$: this.formMessagesService.data$,
|
|
5695
|
+
getFormStatus: () => this.paymentService.form?.status,
|
|
5640
5696
|
},
|
|
5641
5697
|
};
|
|
5642
5698
|
}
|