@xsolla/payment-client-core 0.0.14 → 0.1.1
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 +8 -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/actions/show-field-state/show-field-state.action.class.mjs +11 -0
- package/esm2020/lib/core/payment/actions/show-field-state/show-field-state.action.token.mjs +13 -0
- package/esm2020/lib/core/payment/actions/show-field-state/show-field-state.action.type.mjs +2 -0
- package/esm2020/lib/core/payment/config/config.service.mjs +4 -1
- package/esm2020/lib/core/payment/initialize/initialize.service.mjs +13 -6
- package/esm2020/lib/core/payment/payment.service.mjs +25 -1
- package/esm2020/lib/core/payment/show-field-state.interface.mjs +2 -0
- 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 +276 -180
- package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
- package/fesm2020/xsolla-payment-client-core.mjs +269 -177
- package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
- package/lib/core/payment/actions/next-action.interface.d.ts +3 -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/actions/show-field-state/show-field-state.action.class.d.ts +8 -0
- package/lib/core/payment/actions/show-field-state/show-field-state.action.token.d.ts +4 -0
- package/lib/core/payment/actions/show-field-state/show-field-state.action.type.d.ts +10 -0
- package/lib/core/payment/initialize/initialize.service.d.ts +3 -1
- package/lib/core/payment/payment.service.d.ts +4 -1
- package/lib/core/payment/show-field-state.interface.d.ts +7 -0
- package/lib/core/payment/sync/sync.service.d.ts +3 -1
- package/package.json +1 -1
- package/xsolla-payment-client-core-0.1.1.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,17 @@ const isSubmitResponse = (value) => {
|
|
|
589
598
|
return value instanceof SubmitResponse;
|
|
590
599
|
};
|
|
591
600
|
|
|
601
|
+
class ShowFieldStateAction {
|
|
602
|
+
constructor(control) {
|
|
603
|
+
this.type = 'show_field_state';
|
|
604
|
+
this.data = {
|
|
605
|
+
fieldName: control.fieldName,
|
|
606
|
+
fieldState: control.fieldState,
|
|
607
|
+
error: control.error,
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
592
612
|
class InitializeResponse {
|
|
593
613
|
constructor(response) {
|
|
594
614
|
this.paymentForm = null;
|
|
@@ -639,12 +659,225 @@ const initializeResponseFactoryProvider = {
|
|
|
639
659
|
useValue: (...args) => new InitializeResponse(...args),
|
|
640
660
|
};
|
|
641
661
|
|
|
662
|
+
class ShowErrorsAction {
|
|
663
|
+
constructor(errors) {
|
|
664
|
+
this.type = 'show_errors';
|
|
665
|
+
this.data = {
|
|
666
|
+
errors,
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
class ShowFieldsAction {
|
|
672
|
+
constructor(submitResponse) {
|
|
673
|
+
this.type = 'show_fields';
|
|
674
|
+
this.data = {
|
|
675
|
+
fields: [],
|
|
676
|
+
errors: [],
|
|
677
|
+
messages: [],
|
|
678
|
+
order: {},
|
|
679
|
+
};
|
|
680
|
+
this.data.fields = submitResponse.fields.filter((field) => (field === null || field === void 0 ? void 0 : field.isVisible) === "1" /* XpsBoolean.true */);
|
|
681
|
+
this.data.errors = submitResponse.errors;
|
|
682
|
+
this.data.messages = submitResponse.messages;
|
|
683
|
+
this.data.order = submitResponse.summary;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const showFieldsActionFactoryToken = new InjectionToken('ShowFieldsAction');
|
|
688
|
+
const showFieldsActionFactoryProvider = {
|
|
689
|
+
provide: showFieldsActionFactoryToken,
|
|
690
|
+
useValue: {
|
|
691
|
+
factory: (...args) => new ShowFieldsAction(...args),
|
|
692
|
+
isSuitable: (response) => {
|
|
693
|
+
return response.currentCommand === XpsCommand.check;
|
|
694
|
+
},
|
|
695
|
+
},
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
class CheckStatusAction {
|
|
699
|
+
constructor(submitResponse) {
|
|
700
|
+
var _a, _b, _c, _d, _e, _f;
|
|
701
|
+
this.type = 'check_status';
|
|
702
|
+
const status = submitResponse.parameters.status;
|
|
703
|
+
this.data = {
|
|
704
|
+
invoice: status === null || status === void 0 ? void 0 : status.invoice,
|
|
705
|
+
signature: (_a = submitResponse.parameters.form.signature) === null || _a === void 0 ? void 0 : _a.value,
|
|
706
|
+
locale: (_b = submitResponse.parameters.form.locale) === null || _b === void 0 ? void 0 : _b.value,
|
|
707
|
+
testPs: (_c = submitResponse.parameters.form.testPs) === null || _c === void 0 ? void 0 : _c.value,
|
|
708
|
+
testXsolla: (_d = submitResponse.parameters.form.testXsolla) === null || _d === void 0 ? void 0 : _d.value,
|
|
709
|
+
testProject: (_e = submitResponse.parameters.form.testProject) === null || _e === void 0 ? void 0 : _e.value,
|
|
710
|
+
userReturnStatus: (_f = submitResponse.parameters.form.userReturnStatus) === null || _f === void 0 ? void 0 : _f.value,
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
const checkStatusActionFactoryToken = new InjectionToken('CheckStatusAction');
|
|
716
|
+
const checkStatusActionFactoryProvider = {
|
|
717
|
+
provide: checkStatusActionFactoryToken,
|
|
718
|
+
useValue: {
|
|
719
|
+
factory: (...args) => new CheckStatusAction(...args),
|
|
720
|
+
isSuitable: (response) => {
|
|
721
|
+
return response.currentCommand === XpsCommand.status;
|
|
722
|
+
},
|
|
723
|
+
},
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
class StatusUpdatedAction {
|
|
727
|
+
constructor(statusResponse) {
|
|
728
|
+
this.type = 'status_updated';
|
|
729
|
+
this.data = {
|
|
730
|
+
statusState: statusResponse.status.statusState,
|
|
731
|
+
invoice: statusResponse.status.invoice,
|
|
732
|
+
isSuccess: statusResponse.status.isSuccess,
|
|
733
|
+
isCanceled: statusResponse.status.isCanceled,
|
|
734
|
+
group: statusResponse.status.group,
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
const statusUpdatedActionFactoryToken = new InjectionToken('StatusUpdatedAction');
|
|
740
|
+
const statusUpdatedActionFactoryProvider = {
|
|
741
|
+
provide: statusUpdatedActionFactoryToken,
|
|
742
|
+
useValue: {
|
|
743
|
+
factory: (...args) => new StatusUpdatedAction(...args),
|
|
744
|
+
isSuitable: () => false,
|
|
745
|
+
},
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
class RedirectAction {
|
|
749
|
+
constructor(submitResponse) {
|
|
750
|
+
this.type = 'redirect';
|
|
751
|
+
this.data = {
|
|
752
|
+
fields: submitResponse.fields,
|
|
753
|
+
errors: submitResponse.errors,
|
|
754
|
+
messages: submitResponse.messages,
|
|
755
|
+
order: submitResponse.summary,
|
|
756
|
+
invoiceId: submitResponse.fixInvoice,
|
|
757
|
+
redirect: this.getRedirect(submitResponse),
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
getRedirect(submitResponse) {
|
|
761
|
+
return {
|
|
762
|
+
redirectUrl: submitResponse.parameters.checkout.action,
|
|
763
|
+
data: submitResponse.parameters.checkout.data,
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const redirectActionFactoryToken = new InjectionToken('RedirectAction');
|
|
769
|
+
const redirectActionFactoryProvider = {
|
|
770
|
+
provide: redirectActionFactoryToken,
|
|
771
|
+
useValue: {
|
|
772
|
+
factory: (...args) => new RedirectAction(...args),
|
|
773
|
+
isSuitable: (response) => {
|
|
774
|
+
return (response.currentCommand === XpsCommand.account ||
|
|
775
|
+
(response.currentCommand === XpsCommand.checkout &&
|
|
776
|
+
Boolean(response.parameters.checkout)));
|
|
777
|
+
},
|
|
778
|
+
},
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
const showErrorsActionFactoryToken = new InjectionToken('ShowErrorsAction');
|
|
782
|
+
const showErrorsActionFactoryProvider = {
|
|
783
|
+
provide: showErrorsActionFactoryToken,
|
|
784
|
+
useValue: {
|
|
785
|
+
factory: (...args) => new ShowErrorsAction(...args),
|
|
786
|
+
isSuitable: (response) => {
|
|
787
|
+
var _a;
|
|
788
|
+
return Boolean((_a = response.errors) === null || _a === void 0 ? void 0 : _a.length);
|
|
789
|
+
},
|
|
790
|
+
},
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
const showFieldStateActionFactoryToken = new InjectionToken('ShowFieldStateAction');
|
|
794
|
+
const showFieldStateActionFactoryProvider = {
|
|
795
|
+
provide: showFieldStateActionFactoryToken,
|
|
796
|
+
useValue: {
|
|
797
|
+
factory: (...args) => new ShowFieldStateAction(...args),
|
|
798
|
+
isSuitable: () => {
|
|
799
|
+
return true;
|
|
800
|
+
},
|
|
801
|
+
},
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
const nextActionsToken = new InjectionToken('Action');
|
|
805
|
+
const nextActions = [
|
|
806
|
+
showFieldsActionFactoryProvider,
|
|
807
|
+
checkStatusActionFactoryProvider,
|
|
808
|
+
redirectActionFactoryProvider,
|
|
809
|
+
];
|
|
810
|
+
const flowUpdateNextActions = [
|
|
811
|
+
statusUpdatedActionFactoryProvider,
|
|
812
|
+
showErrorsActionFactoryProvider,
|
|
813
|
+
showFieldStateActionFactoryProvider,
|
|
814
|
+
];
|
|
815
|
+
|
|
816
|
+
class NextActionService {
|
|
817
|
+
get flowUpdates$() {
|
|
818
|
+
return this.flowUpdatesSubject.asObservable();
|
|
819
|
+
}
|
|
820
|
+
constructor(nextActionTokens, injector) {
|
|
821
|
+
this.nextActionTokens = nextActionTokens;
|
|
822
|
+
this.injector = injector;
|
|
823
|
+
this.flowUpdatesSubject = new Subject();
|
|
824
|
+
this.nextActionsList = [];
|
|
825
|
+
this.fillNextActionsList();
|
|
826
|
+
}
|
|
827
|
+
getNextAction(submitResponse) {
|
|
828
|
+
var _a;
|
|
829
|
+
if ((_a = submitResponse.errors) === null || _a === void 0 ? void 0 : _a.length) {
|
|
830
|
+
this.emitFlowUpdates(new ShowErrorsAction(submitResponse.errors));
|
|
831
|
+
}
|
|
832
|
+
if (!submitResponse.currentCommand) {
|
|
833
|
+
return null;
|
|
834
|
+
}
|
|
835
|
+
const nextActionFactory = this.findNextAction(submitResponse);
|
|
836
|
+
if (nextActionFactory) {
|
|
837
|
+
return nextActionFactory(submitResponse);
|
|
838
|
+
}
|
|
839
|
+
throw new Error('Next action is undefined.');
|
|
840
|
+
}
|
|
841
|
+
emitFlowUpdates(action) {
|
|
842
|
+
this.flowUpdatesSubject.next(action);
|
|
843
|
+
}
|
|
844
|
+
fillNextActionsList() {
|
|
845
|
+
this.nextActionTokens.forEach((nextAction) => {
|
|
846
|
+
const item = this.injector.get(nextAction.provide);
|
|
847
|
+
this.nextActionsList.push(item);
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
findNextAction(submitResponse) {
|
|
851
|
+
const actionType = this.nextActionsList.find((nextAction) => {
|
|
852
|
+
return nextAction.isSuitable(submitResponse);
|
|
853
|
+
});
|
|
854
|
+
if (!actionType) {
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
return actionType.factory;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
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 });
|
|
861
|
+
NextActionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NextActionService, providedIn: 'root' });
|
|
862
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NextActionService, decorators: [{
|
|
863
|
+
type: Injectable,
|
|
864
|
+
args: [{
|
|
865
|
+
providedIn: 'root',
|
|
866
|
+
}]
|
|
867
|
+
}], ctorParameters: function () {
|
|
868
|
+
return [{ type: undefined, decorators: [{
|
|
869
|
+
type: Inject,
|
|
870
|
+
args: [nextActionsToken]
|
|
871
|
+
}] }, { type: i0.Injector }];
|
|
872
|
+
} });
|
|
873
|
+
|
|
642
874
|
class InitializeService {
|
|
643
|
-
constructor(responseFactory, secureApi, settingsService, countryService) {
|
|
875
|
+
constructor(responseFactory, secureApi, settingsService, countryService, nextActionService) {
|
|
644
876
|
this.responseFactory = responseFactory;
|
|
645
877
|
this.secureApi = secureApi;
|
|
646
878
|
this.settingsService = settingsService;
|
|
647
879
|
this.countryService = countryService;
|
|
880
|
+
this.nextActionService = nextActionService;
|
|
648
881
|
this.apiRoute = 'directpayment';
|
|
649
882
|
// TODO PAYMENTS-15743: replace with new refer id for headless core
|
|
650
883
|
this.ps4ReferId = '22';
|
|
@@ -663,13 +896,18 @@ class InitializeService {
|
|
|
663
896
|
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
|
|
664
897
|
responseType: 'json',
|
|
665
898
|
})
|
|
666
|
-
.pipe(map((response) => this.responseFactory(response))
|
|
899
|
+
.pipe(map((response) => this.responseFactory(response)), tap((response) => {
|
|
900
|
+
var _a, _b;
|
|
901
|
+
if ((_b = (_a = response.paymentForm) === null || _a === void 0 ? void 0 : _a.errors) === null || _b === void 0 ? void 0 : _b.length) {
|
|
902
|
+
this.nextActionService.emitFlowUpdates(new ShowErrorsAction(response.paymentForm.errors));
|
|
903
|
+
}
|
|
904
|
+
}))).catch((error) => {
|
|
667
905
|
throw new ResponseError(error.message);
|
|
668
906
|
});
|
|
669
907
|
});
|
|
670
908
|
}
|
|
671
909
|
}
|
|
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 });
|
|
910
|
+
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
911
|
InitializeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: InitializeService, providedIn: 'root' });
|
|
674
912
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: InitializeService, decorators: [{
|
|
675
913
|
type: Injectable,
|
|
@@ -680,7 +918,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
680
918
|
return [{ type: undefined, decorators: [{
|
|
681
919
|
type: Inject,
|
|
682
920
|
args: [initializeResponseFactoryToken]
|
|
683
|
-
}] }, { type: SecureApiClient }, { type: SettingsService }, { type: CountryService }];
|
|
921
|
+
}] }, { type: SecureApiClient }, { type: SettingsService }, { type: CountryService }, { type: NextActionService }];
|
|
684
922
|
} });
|
|
685
923
|
|
|
686
924
|
class XpsApiPartRequest {
|
|
@@ -1047,11 +1285,12 @@ const syncResponseFactoryProvider = {
|
|
|
1047
1285
|
};
|
|
1048
1286
|
|
|
1049
1287
|
class SyncService extends EmitDataService {
|
|
1050
|
-
constructor(requestFactory, responseFactory, secureApi, settingsService) {
|
|
1288
|
+
constructor(requestFactory, responseFactory, secureApi, nextActionService, settingsService) {
|
|
1051
1289
|
super();
|
|
1052
1290
|
this.requestFactory = requestFactory;
|
|
1053
1291
|
this.responseFactory = responseFactory;
|
|
1054
1292
|
this.secureApi = secureApi;
|
|
1293
|
+
this.nextActionService = nextActionService;
|
|
1055
1294
|
this.settingsService = settingsService;
|
|
1056
1295
|
this.apiRoute = 'directpayment';
|
|
1057
1296
|
this.prevFieldSyncStates = {};
|
|
@@ -1117,6 +1356,10 @@ class SyncService extends EmitDataService {
|
|
|
1117
1356
|
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
|
|
1118
1357
|
responseType: 'json',
|
|
1119
1358
|
})).then((response) => {
|
|
1359
|
+
var _a;
|
|
1360
|
+
if ((_a = response.errors) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1361
|
+
this.nextActionService.emitFlowUpdates(new ShowErrorsAction(response.errors));
|
|
1362
|
+
}
|
|
1120
1363
|
this.emit(response);
|
|
1121
1364
|
return this.responseFactory(field, response);
|
|
1122
1365
|
});
|
|
@@ -1135,7 +1378,7 @@ class SyncService extends EmitDataService {
|
|
|
1135
1378
|
this.prevFieldSyncStates[field.name] = { value, result };
|
|
1136
1379
|
}
|
|
1137
1380
|
}
|
|
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 });
|
|
1381
|
+
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
1382
|
SyncService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SyncService, providedIn: 'root' });
|
|
1140
1383
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SyncService, decorators: [{
|
|
1141
1384
|
type: Injectable,
|
|
@@ -1149,7 +1392,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
1149
1392
|
}] }, { type: undefined, decorators: [{
|
|
1150
1393
|
type: Inject,
|
|
1151
1394
|
args: [syncResponseFactoryToken]
|
|
1152
|
-
}] }, { type: SecureApiClient }, { type: SettingsService }];
|
|
1395
|
+
}] }, { type: SecureApiClient }, { type: NextActionService }, { type: SettingsService }];
|
|
1153
1396
|
} });
|
|
1154
1397
|
|
|
1155
1398
|
class ControlConfig {
|
|
@@ -1435,19 +1678,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
1435
1678
|
type: Injectable
|
|
1436
1679
|
}], ctorParameters: function () { return [{ type: ControlConfigService }]; } });
|
|
1437
1680
|
|
|
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
1681
|
var StatusSearchParam;
|
|
1452
1682
|
(function (StatusSearchParam) {
|
|
1453
1683
|
StatusSearchParam["token"] = "token";
|
|
@@ -2537,165 +2767,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
2537
2767
|
}]
|
|
2538
2768
|
}], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService }, { type: WebsocketStatusService }]; } });
|
|
2539
2769
|
|
|
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
2770
|
class StatusService {
|
|
2700
2771
|
constructor(urlService, statusRequestService, listenStatusService, nextActionService) {
|
|
2701
2772
|
this.urlService = urlService;
|
|
@@ -3064,16 +3135,19 @@ class PaymentService {
|
|
|
3064
3135
|
this.financeDetails = null;
|
|
3065
3136
|
this.fields = [];
|
|
3066
3137
|
this.destroy$ = new Subject();
|
|
3138
|
+
this.formDestroy$ = new Subject();
|
|
3067
3139
|
}
|
|
3068
3140
|
initialize(config) {
|
|
3069
3141
|
var _a;
|
|
3070
3142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3071
3143
|
this.destroy$ = new Subject();
|
|
3144
|
+
this.formDestroy$ = new Subject();
|
|
3072
3145
|
this.listenFinanceDetails();
|
|
3073
3146
|
this.config = config;
|
|
3074
3147
|
this.data = yield this.initializeService.request(config);
|
|
3075
3148
|
this.fields = this.getFields();
|
|
3076
3149
|
this.form = this.formService.createForm(this.fields);
|
|
3150
|
+
this.listenSyncValidationErrors(this.form);
|
|
3077
3151
|
this.emitFinanceDetails((_a = this.data.paymentForm) === null || _a === void 0 ? void 0 : _a.summary);
|
|
3078
3152
|
this.setupSyncService(this.form, this.fields);
|
|
3079
3153
|
return this.fields.filter((field) => (field === null || field === void 0 ? void 0 : field.isVisible) === "1" /* XpsBoolean.true */);
|
|
@@ -3140,6 +3214,7 @@ class PaymentService {
|
|
|
3140
3214
|
this.financeDetails = null;
|
|
3141
3215
|
this.form = null;
|
|
3142
3216
|
this.fields = [];
|
|
3217
|
+
this.formDestroy$.next();
|
|
3143
3218
|
this.destroy$.next();
|
|
3144
3219
|
}
|
|
3145
3220
|
emitFinanceDetails(summary) {
|
|
@@ -3156,6 +3231,25 @@ class PaymentService {
|
|
|
3156
3231
|
.pipe(takeUntil(this.destroy$))
|
|
3157
3232
|
.subscribe((financeDetails) => (this.financeDetails = financeDetails));
|
|
3158
3233
|
}
|
|
3234
|
+
listenSyncValidationErrors(form) {
|
|
3235
|
+
Object.keys(form.controls).forEach((key) => {
|
|
3236
|
+
const control = form.get(key);
|
|
3237
|
+
if (control) {
|
|
3238
|
+
control.statusChanges
|
|
3239
|
+
.pipe(takeUntil(this.formDestroy$))
|
|
3240
|
+
.subscribe((status) => {
|
|
3241
|
+
var _a, _b;
|
|
3242
|
+
const controlError = (_b = (_a = control.errors) === null || _a === void 0 ? void 0 : _a['rewritableError']) !== null && _b !== void 0 ? _b : null;
|
|
3243
|
+
const controlObject = {
|
|
3244
|
+
fieldName: key,
|
|
3245
|
+
fieldState: status,
|
|
3246
|
+
error: controlError,
|
|
3247
|
+
};
|
|
3248
|
+
this.nextActionService.emitFlowUpdates(new ShowFieldStateAction(controlObject));
|
|
3249
|
+
});
|
|
3250
|
+
}
|
|
3251
|
+
});
|
|
3252
|
+
}
|
|
3159
3253
|
}
|
|
3160
3254
|
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
3255
|
PaymentService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, providedIn: 'root' });
|
|
@@ -3448,6 +3542,7 @@ CoreLibraryModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", versi
|
|
|
3448
3542
|
useValue: nextActions,
|
|
3449
3543
|
},
|
|
3450
3544
|
...nextActions,
|
|
3545
|
+
...flowUpdateNextActions,
|
|
3451
3546
|
], imports: [HttpClientModule, FormModule] });
|
|
3452
3547
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryModule, decorators: [{
|
|
3453
3548
|
type: NgModule,
|
|
@@ -3478,6 +3573,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
3478
3573
|
useValue: nextActions,
|
|
3479
3574
|
},
|
|
3480
3575
|
...nextActions,
|
|
3576
|
+
...flowUpdateNextActions,
|
|
3481
3577
|
],
|
|
3482
3578
|
}]
|
|
3483
3579
|
}] });
|