@xsolla/payment-client-core 0.0.14 → 0.1.0
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/actions/next-action.interface.mjs +1 -1
- package/esm2020/lib/core/payment/actions/next-action.service.mjs +6 -2
- package/esm2020/lib/core/payment/actions/next-actions.mjs +6 -2
- package/esm2020/lib/core/payment/actions/show-errors/show-errors.action.class.mjs +9 -0
- package/esm2020/lib/core/payment/actions/show-errors/show-errors.action.token.mjs +13 -0
- package/esm2020/lib/core/payment/actions/show-errors/show-errors.action.type.mjs +2 -0
- package/esm2020/lib/core/payment/config/config.service.mjs +4 -1
- package/esm2020/lib/core/payment/extended-xps-error.mjs +2 -0
- package/esm2020/lib/core/payment/initialize/initialize.service.mjs +13 -6
- package/esm2020/lib/core/payment/payment.service.mjs +28 -1
- package/esm2020/lib/core/payment/sync/sync.service.mjs +11 -5
- package/esm2020/lib/core/url/url.service.mjs +7 -1
- package/esm2020/lib/core-library.module.mjs +4 -2
- package/fesm2015/xsolla-payment-client-core.mjs +258 -180
- package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
- package/fesm2020/xsolla-payment-client-core.mjs +249 -177
- package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
- package/lib/core/payment/actions/next-action.interface.d.ts +2 -1
- package/lib/core/payment/actions/next-action.service.d.ts +1 -1
- package/lib/core/payment/actions/next-actions.d.ts +1 -0
- package/lib/core/payment/actions/show-errors/show-errors.action.class.d.ts +8 -0
- package/lib/core/payment/actions/show-errors/show-errors.action.token.d.ts +4 -0
- package/lib/core/payment/actions/show-errors/show-errors.action.type.d.ts +7 -0
- package/lib/core/payment/extended-xps-error.d.ts +4 -0
- package/lib/core/payment/initialize/initialize.service.d.ts +3 -1
- package/lib/core/payment/payment.service.d.ts +3 -1
- package/lib/core/payment/sync/sync.service.d.ts +3 -1
- package/package.json +1 -1
- package/xsolla-payment-client-core-0.1.0.tgz +0 -0
- package/xsolla-payment-client-core-0.0.14.tgz +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
3
|
import { InjectionToken, Injectable, Inject, isDevMode, NgModule } from '@angular/core';
|
|
4
|
-
import { firstValueFrom, lastValueFrom, map, Subject, BehaviorSubject, filter as filter$1, takeUntil, skip, throwError } from 'rxjs';
|
|
4
|
+
import { firstValueFrom, lastValueFrom, map, Subject, tap, BehaviorSubject, filter as filter$1, takeUntil, skip, throwError } from 'rxjs';
|
|
5
5
|
import * as i1 from '@angular/common/http';
|
|
6
6
|
import { HttpParams, HttpHeaders, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
7
7
|
import { UntypedFormGroup, Validators, UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
|
|
@@ -434,6 +434,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
434
434
|
|
|
435
435
|
class UrlService {
|
|
436
436
|
addSearchParams(url, params = {}) {
|
|
437
|
+
if (!url) {
|
|
438
|
+
return '';
|
|
439
|
+
}
|
|
437
440
|
const urlObject = new URL(url);
|
|
438
441
|
for (const [key, value] of Object.entries(params)) {
|
|
439
442
|
urlObject.searchParams.set(key, value);
|
|
@@ -441,6 +444,9 @@ class UrlService {
|
|
|
441
444
|
return urlObject.toString();
|
|
442
445
|
}
|
|
443
446
|
getSearchParams(url) {
|
|
447
|
+
if (!url) {
|
|
448
|
+
return {};
|
|
449
|
+
}
|
|
444
450
|
const urlObject = new URL(url);
|
|
445
451
|
const searchParams = {};
|
|
446
452
|
for (const [key, value] of urlObject.searchParams) {
|
|
@@ -464,6 +470,9 @@ class PaymentConfigService {
|
|
|
464
470
|
this.settingsService = settingsService;
|
|
465
471
|
}
|
|
466
472
|
enrich(config) {
|
|
473
|
+
if (!config.returnUrl) {
|
|
474
|
+
throw new Error('URL is not provided in payment config');
|
|
475
|
+
}
|
|
467
476
|
return Object.assign(Object.assign({}, config), { returnUrl: this.enrichReturnUrl(config.returnUrl) });
|
|
468
477
|
}
|
|
469
478
|
enrichReturnUrl(returnUrl) {
|
|
@@ -589,6 +598,15 @@ const isSubmitResponse = (value) => {
|
|
|
589
598
|
return value instanceof SubmitResponse;
|
|
590
599
|
};
|
|
591
600
|
|
|
601
|
+
class ShowErrorsAction {
|
|
602
|
+
constructor(errors) {
|
|
603
|
+
this.type = 'show_errors';
|
|
604
|
+
this.data = {
|
|
605
|
+
errors,
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
592
610
|
class InitializeResponse {
|
|
593
611
|
constructor(response) {
|
|
594
612
|
this.paymentForm = null;
|
|
@@ -639,12 +657,204 @@ const initializeResponseFactoryProvider = {
|
|
|
639
657
|
useValue: (...args) => new InitializeResponse(...args),
|
|
640
658
|
};
|
|
641
659
|
|
|
660
|
+
class ShowFieldsAction {
|
|
661
|
+
constructor(submitResponse) {
|
|
662
|
+
this.type = 'show_fields';
|
|
663
|
+
this.data = {
|
|
664
|
+
fields: [],
|
|
665
|
+
errors: [],
|
|
666
|
+
messages: [],
|
|
667
|
+
order: {},
|
|
668
|
+
};
|
|
669
|
+
this.data.fields = submitResponse.fields.filter((field) => (field === null || field === void 0 ? void 0 : field.isVisible) === "1" /* XpsBoolean.true */);
|
|
670
|
+
this.data.errors = submitResponse.errors;
|
|
671
|
+
this.data.messages = submitResponse.messages;
|
|
672
|
+
this.data.order = submitResponse.summary;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const showFieldsActionFactoryToken = new InjectionToken('ShowFieldsAction');
|
|
677
|
+
const showFieldsActionFactoryProvider = {
|
|
678
|
+
provide: showFieldsActionFactoryToken,
|
|
679
|
+
useValue: {
|
|
680
|
+
factory: (...args) => new ShowFieldsAction(...args),
|
|
681
|
+
isSuitable: (response) => {
|
|
682
|
+
return response.currentCommand === XpsCommand.check;
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
class CheckStatusAction {
|
|
688
|
+
constructor(submitResponse) {
|
|
689
|
+
var _a, _b, _c, _d, _e, _f;
|
|
690
|
+
this.type = 'check_status';
|
|
691
|
+
const status = submitResponse.parameters.status;
|
|
692
|
+
this.data = {
|
|
693
|
+
invoice: status === null || status === void 0 ? void 0 : status.invoice,
|
|
694
|
+
signature: (_a = submitResponse.parameters.form.signature) === null || _a === void 0 ? void 0 : _a.value,
|
|
695
|
+
locale: (_b = submitResponse.parameters.form.locale) === null || _b === void 0 ? void 0 : _b.value,
|
|
696
|
+
testPs: (_c = submitResponse.parameters.form.testPs) === null || _c === void 0 ? void 0 : _c.value,
|
|
697
|
+
testXsolla: (_d = submitResponse.parameters.form.testXsolla) === null || _d === void 0 ? void 0 : _d.value,
|
|
698
|
+
testProject: (_e = submitResponse.parameters.form.testProject) === null || _e === void 0 ? void 0 : _e.value,
|
|
699
|
+
userReturnStatus: (_f = submitResponse.parameters.form.userReturnStatus) === null || _f === void 0 ? void 0 : _f.value,
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
const checkStatusActionFactoryToken = new InjectionToken('CheckStatusAction');
|
|
705
|
+
const checkStatusActionFactoryProvider = {
|
|
706
|
+
provide: checkStatusActionFactoryToken,
|
|
707
|
+
useValue: {
|
|
708
|
+
factory: (...args) => new CheckStatusAction(...args),
|
|
709
|
+
isSuitable: (response) => {
|
|
710
|
+
return response.currentCommand === XpsCommand.status;
|
|
711
|
+
},
|
|
712
|
+
},
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
class StatusUpdatedAction {
|
|
716
|
+
constructor(statusResponse) {
|
|
717
|
+
this.type = 'status_updated';
|
|
718
|
+
this.data = {
|
|
719
|
+
statusState: statusResponse.status.statusState,
|
|
720
|
+
invoice: statusResponse.status.invoice,
|
|
721
|
+
isSuccess: statusResponse.status.isSuccess,
|
|
722
|
+
isCanceled: statusResponse.status.isCanceled,
|
|
723
|
+
group: statusResponse.status.group,
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
const statusUpdatedActionFactoryToken = new InjectionToken('StatusUpdatedAction');
|
|
729
|
+
const statusUpdatedActionFactoryProvider = {
|
|
730
|
+
provide: statusUpdatedActionFactoryToken,
|
|
731
|
+
useValue: {
|
|
732
|
+
factory: (...args) => new StatusUpdatedAction(...args),
|
|
733
|
+
isSuitable: () => false,
|
|
734
|
+
},
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
class RedirectAction {
|
|
738
|
+
constructor(submitResponse) {
|
|
739
|
+
this.type = 'redirect';
|
|
740
|
+
this.data = {
|
|
741
|
+
fields: submitResponse.fields,
|
|
742
|
+
errors: submitResponse.errors,
|
|
743
|
+
messages: submitResponse.messages,
|
|
744
|
+
order: submitResponse.summary,
|
|
745
|
+
invoiceId: submitResponse.fixInvoice,
|
|
746
|
+
redirect: this.getRedirect(submitResponse),
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
getRedirect(submitResponse) {
|
|
750
|
+
return {
|
|
751
|
+
redirectUrl: submitResponse.parameters.checkout.action,
|
|
752
|
+
data: submitResponse.parameters.checkout.data,
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
const redirectActionFactoryToken = new InjectionToken('RedirectAction');
|
|
758
|
+
const redirectActionFactoryProvider = {
|
|
759
|
+
provide: redirectActionFactoryToken,
|
|
760
|
+
useValue: {
|
|
761
|
+
factory: (...args) => new RedirectAction(...args),
|
|
762
|
+
isSuitable: (response) => {
|
|
763
|
+
return (response.currentCommand === XpsCommand.account ||
|
|
764
|
+
(response.currentCommand === XpsCommand.checkout &&
|
|
765
|
+
Boolean(response.parameters.checkout)));
|
|
766
|
+
},
|
|
767
|
+
},
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
const showErrorsActionFactoryToken = new InjectionToken('ShowErrorsAction');
|
|
771
|
+
const showErrorsActionFactoryProvider = {
|
|
772
|
+
provide: showErrorsActionFactoryToken,
|
|
773
|
+
useValue: {
|
|
774
|
+
factory: (...args) => new ShowErrorsAction(...args),
|
|
775
|
+
isSuitable: (response) => {
|
|
776
|
+
var _a;
|
|
777
|
+
return Boolean((_a = response.errors) === null || _a === void 0 ? void 0 : _a.length);
|
|
778
|
+
},
|
|
779
|
+
},
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
const nextActionsToken = new InjectionToken('Action');
|
|
783
|
+
const nextActions = [
|
|
784
|
+
showFieldsActionFactoryProvider,
|
|
785
|
+
checkStatusActionFactoryProvider,
|
|
786
|
+
redirectActionFactoryProvider,
|
|
787
|
+
];
|
|
788
|
+
const flowUpdateNextActions = [
|
|
789
|
+
statusUpdatedActionFactoryProvider,
|
|
790
|
+
showErrorsActionFactoryProvider,
|
|
791
|
+
];
|
|
792
|
+
|
|
793
|
+
class NextActionService {
|
|
794
|
+
get flowUpdates$() {
|
|
795
|
+
return this.flowUpdatesSubject.asObservable();
|
|
796
|
+
}
|
|
797
|
+
constructor(nextActionTokens, injector) {
|
|
798
|
+
this.nextActionTokens = nextActionTokens;
|
|
799
|
+
this.injector = injector;
|
|
800
|
+
this.flowUpdatesSubject = new Subject();
|
|
801
|
+
this.nextActionsList = [];
|
|
802
|
+
this.fillNextActionsList();
|
|
803
|
+
}
|
|
804
|
+
getNextAction(submitResponse) {
|
|
805
|
+
var _a;
|
|
806
|
+
if ((_a = submitResponse.errors) === null || _a === void 0 ? void 0 : _a.length) {
|
|
807
|
+
this.emitFlowUpdates(new ShowErrorsAction(submitResponse.errors));
|
|
808
|
+
}
|
|
809
|
+
if (!submitResponse.currentCommand) {
|
|
810
|
+
return null;
|
|
811
|
+
}
|
|
812
|
+
const nextActionFactory = this.findNextAction(submitResponse);
|
|
813
|
+
if (nextActionFactory) {
|
|
814
|
+
return nextActionFactory(submitResponse);
|
|
815
|
+
}
|
|
816
|
+
throw new Error('Next action is undefined.');
|
|
817
|
+
}
|
|
818
|
+
emitFlowUpdates(action) {
|
|
819
|
+
this.flowUpdatesSubject.next(action);
|
|
820
|
+
}
|
|
821
|
+
fillNextActionsList() {
|
|
822
|
+
this.nextActionTokens.forEach((nextAction) => {
|
|
823
|
+
const item = this.injector.get(nextAction.provide);
|
|
824
|
+
this.nextActionsList.push(item);
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
findNextAction(submitResponse) {
|
|
828
|
+
const actionType = this.nextActionsList.find((nextAction) => {
|
|
829
|
+
return nextAction.isSuitable(submitResponse);
|
|
830
|
+
});
|
|
831
|
+
if (!actionType) {
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
return actionType.factory;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
NextActionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NextActionService, deps: [{ token: nextActionsToken }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
838
|
+
NextActionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NextActionService, providedIn: 'root' });
|
|
839
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NextActionService, decorators: [{
|
|
840
|
+
type: Injectable,
|
|
841
|
+
args: [{
|
|
842
|
+
providedIn: 'root',
|
|
843
|
+
}]
|
|
844
|
+
}], ctorParameters: function () {
|
|
845
|
+
return [{ type: undefined, decorators: [{
|
|
846
|
+
type: Inject,
|
|
847
|
+
args: [nextActionsToken]
|
|
848
|
+
}] }, { type: i0.Injector }];
|
|
849
|
+
} });
|
|
850
|
+
|
|
642
851
|
class InitializeService {
|
|
643
|
-
constructor(responseFactory, secureApi, settingsService, countryService) {
|
|
852
|
+
constructor(responseFactory, secureApi, settingsService, countryService, nextActionService) {
|
|
644
853
|
this.responseFactory = responseFactory;
|
|
645
854
|
this.secureApi = secureApi;
|
|
646
855
|
this.settingsService = settingsService;
|
|
647
856
|
this.countryService = countryService;
|
|
857
|
+
this.nextActionService = nextActionService;
|
|
648
858
|
this.apiRoute = 'directpayment';
|
|
649
859
|
// TODO PAYMENTS-15743: replace with new refer id for headless core
|
|
650
860
|
this.ps4ReferId = '22';
|
|
@@ -663,13 +873,18 @@ class InitializeService {
|
|
|
663
873
|
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
|
|
664
874
|
responseType: 'json',
|
|
665
875
|
})
|
|
666
|
-
.pipe(map((response) => this.responseFactory(response))
|
|
876
|
+
.pipe(map((response) => this.responseFactory(response)), tap((response) => {
|
|
877
|
+
var _a, _b;
|
|
878
|
+
if ((_b = (_a = response.paymentForm) === null || _a === void 0 ? void 0 : _a.errors) === null || _b === void 0 ? void 0 : _b.length) {
|
|
879
|
+
this.nextActionService.emitFlowUpdates(new ShowErrorsAction(response.paymentForm.errors));
|
|
880
|
+
}
|
|
881
|
+
}))).catch((error) => {
|
|
667
882
|
throw new ResponseError(error.message);
|
|
668
883
|
});
|
|
669
884
|
});
|
|
670
885
|
}
|
|
671
886
|
}
|
|
672
|
-
InitializeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: InitializeService, deps: [{ token: initializeResponseFactoryToken }, { token: SecureApiClient }, { token: SettingsService }, { token: CountryService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
887
|
+
InitializeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: InitializeService, deps: [{ token: initializeResponseFactoryToken }, { token: SecureApiClient }, { token: SettingsService }, { token: CountryService }, { token: NextActionService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
673
888
|
InitializeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: InitializeService, providedIn: 'root' });
|
|
674
889
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: InitializeService, decorators: [{
|
|
675
890
|
type: Injectable,
|
|
@@ -680,7 +895,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
680
895
|
return [{ type: undefined, decorators: [{
|
|
681
896
|
type: Inject,
|
|
682
897
|
args: [initializeResponseFactoryToken]
|
|
683
|
-
}] }, { type: SecureApiClient }, { type: SettingsService }, { type: CountryService }];
|
|
898
|
+
}] }, { type: SecureApiClient }, { type: SettingsService }, { type: CountryService }, { type: NextActionService }];
|
|
684
899
|
} });
|
|
685
900
|
|
|
686
901
|
class XpsApiPartRequest {
|
|
@@ -1047,11 +1262,12 @@ const syncResponseFactoryProvider = {
|
|
|
1047
1262
|
};
|
|
1048
1263
|
|
|
1049
1264
|
class SyncService extends EmitDataService {
|
|
1050
|
-
constructor(requestFactory, responseFactory, secureApi, settingsService) {
|
|
1265
|
+
constructor(requestFactory, responseFactory, secureApi, nextActionService, settingsService) {
|
|
1051
1266
|
super();
|
|
1052
1267
|
this.requestFactory = requestFactory;
|
|
1053
1268
|
this.responseFactory = responseFactory;
|
|
1054
1269
|
this.secureApi = secureApi;
|
|
1270
|
+
this.nextActionService = nextActionService;
|
|
1055
1271
|
this.settingsService = settingsService;
|
|
1056
1272
|
this.apiRoute = 'directpayment';
|
|
1057
1273
|
this.prevFieldSyncStates = {};
|
|
@@ -1117,6 +1333,10 @@ class SyncService extends EmitDataService {
|
|
|
1117
1333
|
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
|
|
1118
1334
|
responseType: 'json',
|
|
1119
1335
|
})).then((response) => {
|
|
1336
|
+
var _a;
|
|
1337
|
+
if ((_a = response.errors) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1338
|
+
this.nextActionService.emitFlowUpdates(new ShowErrorsAction(response.errors));
|
|
1339
|
+
}
|
|
1120
1340
|
this.emit(response);
|
|
1121
1341
|
return this.responseFactory(field, response);
|
|
1122
1342
|
});
|
|
@@ -1135,7 +1355,7 @@ class SyncService extends EmitDataService {
|
|
|
1135
1355
|
this.prevFieldSyncStates[field.name] = { value, result };
|
|
1136
1356
|
}
|
|
1137
1357
|
}
|
|
1138
|
-
SyncService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SyncService, deps: [{ token: syncRequestFactoryToken }, { token: syncResponseFactoryToken }, { token: SecureApiClient }, { token: SettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1358
|
+
SyncService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SyncService, deps: [{ token: syncRequestFactoryToken }, { token: syncResponseFactoryToken }, { token: SecureApiClient }, { token: NextActionService }, { token: SettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1139
1359
|
SyncService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SyncService, providedIn: 'root' });
|
|
1140
1360
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SyncService, decorators: [{
|
|
1141
1361
|
type: Injectable,
|
|
@@ -1149,7 +1369,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
1149
1369
|
}] }, { type: undefined, decorators: [{
|
|
1150
1370
|
type: Inject,
|
|
1151
1371
|
args: [syncResponseFactoryToken]
|
|
1152
|
-
}] }, { type: SecureApiClient }, { type: SettingsService }];
|
|
1372
|
+
}] }, { type: SecureApiClient }, { type: NextActionService }, { type: SettingsService }];
|
|
1153
1373
|
} });
|
|
1154
1374
|
|
|
1155
1375
|
class ControlConfig {
|
|
@@ -1435,19 +1655,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
1435
1655
|
type: Injectable
|
|
1436
1656
|
}], ctorParameters: function () { return [{ type: ControlConfigService }]; } });
|
|
1437
1657
|
|
|
1438
|
-
class StatusUpdatedAction {
|
|
1439
|
-
constructor(statusResponse) {
|
|
1440
|
-
this.type = 'status_updated';
|
|
1441
|
-
this.data = {
|
|
1442
|
-
statusState: statusResponse.status.statusState,
|
|
1443
|
-
invoice: statusResponse.status.invoice,
|
|
1444
|
-
isSuccess: statusResponse.status.isSuccess,
|
|
1445
|
-
isCanceled: statusResponse.status.isCanceled,
|
|
1446
|
-
group: statusResponse.status.group,
|
|
1447
|
-
};
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
1658
|
var StatusSearchParam;
|
|
1452
1659
|
(function (StatusSearchParam) {
|
|
1453
1660
|
StatusSearchParam["token"] = "token";
|
|
@@ -2537,165 +2744,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
2537
2744
|
}]
|
|
2538
2745
|
}], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService }, { type: WebsocketStatusService }]; } });
|
|
2539
2746
|
|
|
2540
|
-
class ShowFieldsAction {
|
|
2541
|
-
constructor(submitResponse) {
|
|
2542
|
-
this.type = 'show_fields';
|
|
2543
|
-
this.data = {
|
|
2544
|
-
fields: [],
|
|
2545
|
-
errors: [],
|
|
2546
|
-
messages: [],
|
|
2547
|
-
order: {},
|
|
2548
|
-
};
|
|
2549
|
-
this.data.fields = submitResponse.fields.filter((field) => (field === null || field === void 0 ? void 0 : field.isVisible) === "1" /* XpsBoolean.true */);
|
|
2550
|
-
this.data.errors = submitResponse.errors;
|
|
2551
|
-
this.data.messages = submitResponse.messages;
|
|
2552
|
-
this.data.order = submitResponse.summary;
|
|
2553
|
-
}
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
|
-
const showFieldsActionFactoryToken = new InjectionToken('ShowFieldsAction');
|
|
2557
|
-
const showFieldsActionFactoryProvider = {
|
|
2558
|
-
provide: showFieldsActionFactoryToken,
|
|
2559
|
-
useValue: {
|
|
2560
|
-
factory: (...args) => new ShowFieldsAction(...args),
|
|
2561
|
-
isSuitable: (response) => {
|
|
2562
|
-
return response.currentCommand === XpsCommand.check;
|
|
2563
|
-
},
|
|
2564
|
-
},
|
|
2565
|
-
};
|
|
2566
|
-
|
|
2567
|
-
class CheckStatusAction {
|
|
2568
|
-
constructor(submitResponse) {
|
|
2569
|
-
var _a, _b, _c, _d, _e, _f;
|
|
2570
|
-
this.type = 'check_status';
|
|
2571
|
-
const status = submitResponse.parameters.status;
|
|
2572
|
-
this.data = {
|
|
2573
|
-
invoice: status === null || status === void 0 ? void 0 : status.invoice,
|
|
2574
|
-
signature: (_a = submitResponse.parameters.form.signature) === null || _a === void 0 ? void 0 : _a.value,
|
|
2575
|
-
locale: (_b = submitResponse.parameters.form.locale) === null || _b === void 0 ? void 0 : _b.value,
|
|
2576
|
-
testPs: (_c = submitResponse.parameters.form.testPs) === null || _c === void 0 ? void 0 : _c.value,
|
|
2577
|
-
testXsolla: (_d = submitResponse.parameters.form.testXsolla) === null || _d === void 0 ? void 0 : _d.value,
|
|
2578
|
-
testProject: (_e = submitResponse.parameters.form.testProject) === null || _e === void 0 ? void 0 : _e.value,
|
|
2579
|
-
userReturnStatus: (_f = submitResponse.parameters.form.userReturnStatus) === null || _f === void 0 ? void 0 : _f.value,
|
|
2580
|
-
};
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
|
|
2584
|
-
const checkStatusActionFactoryToken = new InjectionToken('CheckStatusAction');
|
|
2585
|
-
const checkStatusActionFactoryProvider = {
|
|
2586
|
-
provide: checkStatusActionFactoryToken,
|
|
2587
|
-
useValue: {
|
|
2588
|
-
factory: (...args) => new CheckStatusAction(...args),
|
|
2589
|
-
isSuitable: (response) => {
|
|
2590
|
-
return response.currentCommand === XpsCommand.status;
|
|
2591
|
-
},
|
|
2592
|
-
},
|
|
2593
|
-
};
|
|
2594
|
-
|
|
2595
|
-
const statusUpdatedActionFactoryToken = new InjectionToken('StatusUpdatedAction');
|
|
2596
|
-
const statusUpdatedActionFactoryProvider = {
|
|
2597
|
-
provide: statusUpdatedActionFactoryToken,
|
|
2598
|
-
useValue: {
|
|
2599
|
-
factory: (...args) => new StatusUpdatedAction(...args),
|
|
2600
|
-
isSuitable: () => false,
|
|
2601
|
-
},
|
|
2602
|
-
};
|
|
2603
|
-
|
|
2604
|
-
class RedirectAction {
|
|
2605
|
-
constructor(submitResponse) {
|
|
2606
|
-
this.type = 'redirect';
|
|
2607
|
-
this.data = {
|
|
2608
|
-
fields: submitResponse.fields,
|
|
2609
|
-
errors: submitResponse.errors,
|
|
2610
|
-
messages: submitResponse.messages,
|
|
2611
|
-
order: submitResponse.summary,
|
|
2612
|
-
invoiceId: submitResponse.fixInvoice,
|
|
2613
|
-
redirect: this.getRedirect(submitResponse),
|
|
2614
|
-
};
|
|
2615
|
-
}
|
|
2616
|
-
getRedirect(submitResponse) {
|
|
2617
|
-
return {
|
|
2618
|
-
redirectUrl: submitResponse.parameters.checkout.action,
|
|
2619
|
-
data: submitResponse.parameters.checkout.data,
|
|
2620
|
-
};
|
|
2621
|
-
}
|
|
2622
|
-
}
|
|
2623
|
-
|
|
2624
|
-
const redirectActionFactoryToken = new InjectionToken('RedirectAction');
|
|
2625
|
-
const redirectActionFactoryProvider = {
|
|
2626
|
-
provide: redirectActionFactoryToken,
|
|
2627
|
-
useValue: {
|
|
2628
|
-
factory: (...args) => new RedirectAction(...args),
|
|
2629
|
-
isSuitable: (response) => {
|
|
2630
|
-
return (response.currentCommand === XpsCommand.account ||
|
|
2631
|
-
(response.currentCommand === XpsCommand.checkout &&
|
|
2632
|
-
Boolean(response.parameters.checkout)));
|
|
2633
|
-
},
|
|
2634
|
-
},
|
|
2635
|
-
};
|
|
2636
|
-
|
|
2637
|
-
const nextActionsToken = new InjectionToken('Action');
|
|
2638
|
-
const nextActions = [
|
|
2639
|
-
showFieldsActionFactoryProvider,
|
|
2640
|
-
checkStatusActionFactoryProvider,
|
|
2641
|
-
statusUpdatedActionFactoryProvider,
|
|
2642
|
-
redirectActionFactoryProvider,
|
|
2643
|
-
];
|
|
2644
|
-
|
|
2645
|
-
class NextActionService {
|
|
2646
|
-
get flowUpdates$() {
|
|
2647
|
-
return this.flowUpdatesSubject.asObservable();
|
|
2648
|
-
}
|
|
2649
|
-
constructor(nextActionTokens, injector) {
|
|
2650
|
-
this.nextActionTokens = nextActionTokens;
|
|
2651
|
-
this.injector = injector;
|
|
2652
|
-
this.flowUpdatesSubject = new Subject();
|
|
2653
|
-
this.nextActionsList = [];
|
|
2654
|
-
this.fillNextActionsList();
|
|
2655
|
-
}
|
|
2656
|
-
getNextAction(submitResponse) {
|
|
2657
|
-
if (!submitResponse.currentCommand) {
|
|
2658
|
-
return null;
|
|
2659
|
-
}
|
|
2660
|
-
const nextActionFactory = this.findNextAction(submitResponse);
|
|
2661
|
-
if (nextActionFactory) {
|
|
2662
|
-
return nextActionFactory(submitResponse);
|
|
2663
|
-
}
|
|
2664
|
-
throw new Error('Next action is undefined.');
|
|
2665
|
-
}
|
|
2666
|
-
emitFlowUpdates(action) {
|
|
2667
|
-
this.flowUpdatesSubject.next(action);
|
|
2668
|
-
}
|
|
2669
|
-
fillNextActionsList() {
|
|
2670
|
-
this.nextActionTokens.forEach((nextAction) => {
|
|
2671
|
-
const item = this.injector.get(nextAction.provide);
|
|
2672
|
-
this.nextActionsList.push(item);
|
|
2673
|
-
});
|
|
2674
|
-
}
|
|
2675
|
-
findNextAction(submitResponse) {
|
|
2676
|
-
const actionType = this.nextActionsList.find((nextAction) => {
|
|
2677
|
-
return nextAction.isSuitable(submitResponse);
|
|
2678
|
-
});
|
|
2679
|
-
if (!actionType) {
|
|
2680
|
-
return;
|
|
2681
|
-
}
|
|
2682
|
-
return actionType.factory;
|
|
2683
|
-
}
|
|
2684
|
-
}
|
|
2685
|
-
NextActionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NextActionService, deps: [{ token: nextActionsToken }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2686
|
-
NextActionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NextActionService, providedIn: 'root' });
|
|
2687
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NextActionService, decorators: [{
|
|
2688
|
-
type: Injectable,
|
|
2689
|
-
args: [{
|
|
2690
|
-
providedIn: 'root',
|
|
2691
|
-
}]
|
|
2692
|
-
}], ctorParameters: function () {
|
|
2693
|
-
return [{ type: undefined, decorators: [{
|
|
2694
|
-
type: Inject,
|
|
2695
|
-
args: [nextActionsToken]
|
|
2696
|
-
}] }, { type: i0.Injector }];
|
|
2697
|
-
} });
|
|
2698
|
-
|
|
2699
2747
|
class StatusService {
|
|
2700
2748
|
constructor(urlService, statusRequestService, listenStatusService, nextActionService) {
|
|
2701
2749
|
this.urlService = urlService;
|
|
@@ -3074,6 +3122,7 @@ class PaymentService {
|
|
|
3074
3122
|
this.data = yield this.initializeService.request(config);
|
|
3075
3123
|
this.fields = this.getFields();
|
|
3076
3124
|
this.form = this.formService.createForm(this.fields);
|
|
3125
|
+
this.listenSyncValidationErrors(this.form);
|
|
3077
3126
|
this.emitFinanceDetails((_a = this.data.paymentForm) === null || _a === void 0 ? void 0 : _a.summary);
|
|
3078
3127
|
this.setupSyncService(this.form, this.fields);
|
|
3079
3128
|
return this.fields.filter((field) => (field === null || field === void 0 ? void 0 : field.isVisible) === "1" /* XpsBoolean.true */);
|
|
@@ -3156,6 +3205,33 @@ class PaymentService {
|
|
|
3156
3205
|
.pipe(takeUntil(this.destroy$))
|
|
3157
3206
|
.subscribe((financeDetails) => (this.financeDetails = financeDetails));
|
|
3158
3207
|
}
|
|
3208
|
+
listenSyncValidationErrors(form) {
|
|
3209
|
+
form.statusChanges.subscribe(() => {
|
|
3210
|
+
var _a;
|
|
3211
|
+
const controls = (_a = this.form) === null || _a === void 0 ? void 0 : _a.controls;
|
|
3212
|
+
if (controls) {
|
|
3213
|
+
const invalidControls = Object.entries(controls).filter(([key]) => controls[key].invalid);
|
|
3214
|
+
if (invalidControls.length) {
|
|
3215
|
+
const syncValidationErrors = invalidControls
|
|
3216
|
+
.map(([controlName, control]) => {
|
|
3217
|
+
var _a, _b;
|
|
3218
|
+
const error = (_a = control.errors) === null || _a === void 0 ? void 0 : _a['rewritableError'];
|
|
3219
|
+
if (!error) {
|
|
3220
|
+
return null;
|
|
3221
|
+
}
|
|
3222
|
+
return {
|
|
3223
|
+
code: 101,
|
|
3224
|
+
fieldValidationError: error === null || error === void 0 ? void 0 : error.code,
|
|
3225
|
+
message: (_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : '',
|
|
3226
|
+
element_name: controlName,
|
|
3227
|
+
};
|
|
3228
|
+
})
|
|
3229
|
+
.filter(Boolean);
|
|
3230
|
+
this.nextActionService.emitFlowUpdates(new ShowErrorsAction(syncValidationErrors));
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
});
|
|
3234
|
+
}
|
|
3159
3235
|
}
|
|
3160
3236
|
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: NextActionService }, { token: ControlConfigService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
3161
3237
|
PaymentService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, providedIn: 'root' });
|
|
@@ -3448,6 +3524,7 @@ CoreLibraryModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", versi
|
|
|
3448
3524
|
useValue: nextActions,
|
|
3449
3525
|
},
|
|
3450
3526
|
...nextActions,
|
|
3527
|
+
...flowUpdateNextActions,
|
|
3451
3528
|
], imports: [HttpClientModule, FormModule] });
|
|
3452
3529
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryModule, decorators: [{
|
|
3453
3530
|
type: NgModule,
|
|
@@ -3478,6 +3555,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
3478
3555
|
useValue: nextActions,
|
|
3479
3556
|
},
|
|
3480
3557
|
...nextActions,
|
|
3558
|
+
...flowUpdateNextActions,
|
|
3481
3559
|
],
|
|
3482
3560
|
}]
|
|
3483
3561
|
}] });
|