@xsolla/payment-client-core 0.1.14-test2 → 0.1.14-test21

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.
Files changed (40) hide show
  1. package/esm2020/lib/core/payment/actions/status-updated/status-updated.action.class.mjs +17 -7
  2. package/esm2020/lib/core/payment/actions/status-updated/status-updated.action.type.mjs +1 -1
  3. package/esm2020/lib/core/payment/config/config.service.mjs +12 -6
  4. package/esm2020/lib/core/payment/initialize/initialize.service.mjs +3 -3
  5. package/esm2020/lib/core/payment/payment.interface.mjs +1 -1
  6. package/esm2020/lib/core/payment/payment.service.mjs +11 -2
  7. package/esm2020/lib/core/payment/status/save-payment-method-status/api/saved-payment-account-changes.interface.mjs +2 -0
  8. package/esm2020/lib/core/payment/status/save-payment-method-status/api/saved-payment-account-changes.service.mjs +44 -0
  9. package/esm2020/lib/core/payment/status/save-payment-method-status/api/saved-payment-account.interface.mjs +2 -0
  10. package/esm2020/lib/core/payment/status/save-payment-method-status/save-payment-method-status.enum.mjs +6 -0
  11. package/esm2020/lib/core/payment/status/save-payment-method-status/save-payment-method-status.service.mjs +203 -0
  12. package/esm2020/lib/core/payment/status/status-request/status-request-params.interface.mjs +1 -1
  13. package/esm2020/lib/core/payment/status/status-request/status-search-param.enum.mjs +2 -1
  14. package/esm2020/lib/core/payment/status/status-request/status-search-params.map.mjs +8 -1
  15. package/esm2020/lib/core/payment/status/status.interface.mjs +1 -1
  16. package/esm2020/lib/core/payment/status/status.service.mjs +13 -4
  17. package/esm2020/lib/core/payment-methods/payment-methods.service.mjs +1 -1
  18. package/esm2020/lib/core-library.service.mjs +1 -1
  19. package/fesm2015/xsolla-payment-client-core.mjs +431 -145
  20. package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
  21. package/fesm2020/xsolla-payment-client-core.mjs +422 -142
  22. package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
  23. package/lib/core/payment/actions/status-updated/status-updated.action.class.d.ts +3 -1
  24. package/lib/core/payment/actions/status-updated/status-updated.action.type.d.ts +3 -0
  25. package/lib/core/payment/payment.interface.d.ts +1 -1
  26. package/lib/core/payment/payment.service.d.ts +2 -1
  27. package/lib/core/payment/status/save-payment-method-status/api/saved-payment-account-changes.interface.d.ts +6 -0
  28. package/lib/core/payment/status/save-payment-method-status/api/saved-payment-account-changes.service.d.ts +16 -0
  29. package/lib/core/payment/status/save-payment-method-status/api/saved-payment-account.interface.d.ts +7 -0
  30. package/lib/core/payment/status/save-payment-method-status/save-payment-method-status.enum.d.ts +4 -0
  31. package/lib/core/payment/status/save-payment-method-status/save-payment-method-status.service.d.ts +30 -0
  32. package/lib/core/payment/status/status-request/status-request-params.interface.d.ts +1 -0
  33. package/lib/core/payment/status/status-request/status-search-param.enum.d.ts +2 -1
  34. package/lib/core/payment/status/status.interface.d.ts +1 -0
  35. package/lib/core/payment/status/status.service.d.ts +5 -3
  36. package/lib/core/payment-methods/payment-methods.service.d.ts +1 -1
  37. package/lib/core-library.service.d.ts +2 -2
  38. package/package.json +1 -1
  39. package/xsolla-payment-client-core-0.1.14-test21.tgz +0 -0
  40. package/xsolla-payment-client-core-0.1.14-test2.tgz +0 -0
@@ -6,7 +6,7 @@ import * as i1 from '@angular/common/http';
6
6
  import { HttpParams, HttpHeaders, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
7
7
  import JSEncrypt from 'jsencrypt';
8
8
  import { UntypedFormGroup, Validators, UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
9
- import { filter, map as map$1, catchError } from 'rxjs/operators';
9
+ import { filter, map as map$1, tap, catchError } from 'rxjs/operators';
10
10
  import * as i1$1 from '@angular/router';
11
11
  import { CommonModule } from '@angular/common';
12
12
 
@@ -479,12 +479,18 @@ class PaymentConfigService {
479
479
  if (!config.returnUrl) {
480
480
  throw new Error('URL is not provided in payment config');
481
481
  }
482
- return Object.assign(Object.assign({}, config), { returnUrl: this.enrichReturnUrl(config.returnUrl) });
482
+ return Object.assign(Object.assign({}, config), { returnUrl: this.enrichReturnUrl(config.returnUrl, !!config.savePaymentMethod) });
483
483
  }
484
- enrichReturnUrl(returnUrl) {
485
- return this.urlService.addSearchParams(returnUrl, {
486
- token: this.settingsService.token,
484
+ enrichReturnUrl(returnUrl, savePaymentMethod) {
485
+ let enrichedUrl = this.urlService.addSearchParams(returnUrl, {
486
+ token: this.settingsService.token
487
487
  });
488
+ if (savePaymentMethod) {
489
+ enrichedUrl = this.urlService.addSearchParams(returnUrl, {
490
+ isSavePaymentAccount: "1" /* XpsBoolean.true */
491
+ });
492
+ }
493
+ return enrichedUrl;
488
494
  }
489
495
  }
490
496
  PaymentConfigService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentConfigService, deps: [{ token: UrlService }, { token: SettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
@@ -492,7 +498,7 @@ PaymentConfigService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0",
492
498
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentConfigService, decorators: [{
493
499
  type: Injectable,
494
500
  args: [{
495
- providedIn: 'root',
501
+ providedIn: 'root'
496
502
  }]
497
503
  }], ctorParameters: function () { return [{ type: UrlService }, { type: SettingsService }]; } });
498
504
 
@@ -806,15 +812,146 @@ const checkStatusActionFactoryProvider = {
806
812
  },
807
813
  };
808
814
 
815
+ class TerminalError extends AppError {
816
+ constructor(message, code) {
817
+ super(message);
818
+ this.code = code;
819
+ }
820
+ }
821
+
822
+ var StatusGroups;
823
+ (function (StatusGroups) {
824
+ StatusGroups["troubled"] = "troubled";
825
+ StatusGroups["done"] = "done";
826
+ StatusGroups["invoice"] = "invoice";
827
+ })(StatusGroups || (StatusGroups = {}));
828
+
829
+ var StatusEnum;
830
+ (function (StatusEnum) {
831
+ StatusEnum["created"] = "created";
832
+ StatusEnum["awaiting"] = "awaiting";
833
+ StatusEnum["processing"] = "processing";
834
+ StatusEnum["authorized"] = "authorized";
835
+ StatusEnum["held"] = "held";
836
+ StatusEnum["done"] = "done";
837
+ StatusEnum["error"] = "error";
838
+ StatusEnum["canceled"] = "canceled";
839
+ })(StatusEnum || (StatusEnum = {}));
840
+
841
+ class StatusResponse {
842
+ constructor(parameters) {
843
+ var _a, _b, _c, _d, _e, _f, _g;
844
+ if ((_a = parameters.errors) === null || _a === void 0 ? void 0 : _a[0]) {
845
+ this.error = {
846
+ code: parameters.errors[0].code.toString(),
847
+ message: parameters.errors[0].message,
848
+ };
849
+ }
850
+ if (!parameters.status) {
851
+ throw new TerminalError((_c = (_b = this.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : '', (_e = (_d = this.error) === null || _d === void 0 ? void 0 : _d.code.toString()) !== null && _e !== void 0 ? _e : '');
852
+ }
853
+ this.status = {
854
+ statusState: parameters.status.statusData.stateText,
855
+ email: parameters.status.statusData.email,
856
+ webSocketUrl: parameters.status.statusData.webSocketChannelUrl,
857
+ webSocketChannelName: parameters.status.statusData.webSocketChannelName,
858
+ webSocketClientType: parameters.status.statusData.webSocketClientType,
859
+ financeInfo: parameters.status.text.info,
860
+ discount: parameters.status.text.info.discount
861
+ ? Math.abs(Number.parseFloat((_g = (_f = parameters.status.text.info.discount) === null || _f === void 0 ? void 0 : _f.value) !== null && _g !== void 0 ? _g : ''))
862
+ : null,
863
+ isCancelUser: parameters.status.isCancelUser,
864
+ postMessageStatus: parameters.status.isCancelUser
865
+ ? StatusGroups.troubled
866
+ : parameters.status.group,
867
+ virtualCurrencyAmount: parameters.status.statusData.out,
868
+ backUrlSettings: {
869
+ backUrl: parameters.status.text.backurl,
870
+ backUrlAction: parameters.status.text.backurl_action,
871
+ backUrlCaption: parameters.status.text.backurl_caption,
872
+ returnRegion: parameters.status.return_region,
873
+ },
874
+ additionalBackButton: this.getAdditionalBackButton(parameters.status),
875
+ group: parameters.status.group,
876
+ needToCheck: parameters.status.needToCheck,
877
+ autoRedirect: parameters.status.autoredirect,
878
+ statusMessage: parameters.status.text.state,
879
+ userId: parameters.status.statusData.v1,
880
+ invoice: parameters.status.statusData.invoice,
881
+ pid: parameters.status.statusData.pid,
882
+ projectAmount: this.getProjectAmount(parameters.status),
883
+ titleClass: parameters.status.title_class,
884
+ paymentCountryIso: parameters.status.statusData.payment_country_iso,
885
+ order: parameters.status.text.order,
886
+ };
887
+ if (parameters.form) {
888
+ this.status.userReturnStatus = this.getUserReturnStatus(parameters.form);
889
+ }
890
+ if (this.status.statusState === StatusEnum.done ||
891
+ this.status.statusState === StatusEnum.authorized) {
892
+ this.status.isSuccess = true;
893
+ }
894
+ if (this.status.statusState === StatusEnum.canceled ||
895
+ this.status.isCancelUser) {
896
+ this.status.isCanceled = true;
897
+ }
898
+ }
899
+ getUserReturnStatus(form) {
900
+ var _a;
901
+ const value = (_a = form['fix_userReturnStatus']) === null || _a === void 0 ? void 0 : _a.value;
902
+ if (value === 'undefined')
903
+ return undefined;
904
+ return value;
905
+ }
906
+ getProjectAmount(status) {
907
+ if (!status.statusData.projectAmount) {
908
+ return;
909
+ }
910
+ const [amount, currency] = status.statusData.projectAmount.split(' ');
911
+ return {
912
+ amount,
913
+ currency,
914
+ };
915
+ }
916
+ getAdditionalBackButton(status) {
917
+ var _a, _b, _c, _d;
918
+ if (!status.text.is_additional_back_url_enabled) {
919
+ return {
920
+ link: '',
921
+ action: '',
922
+ label: '',
923
+ region: '',
924
+ isEnabled: false,
925
+ };
926
+ }
927
+ return {
928
+ link: (_a = status.text.additional_back_url_link) !== null && _a !== void 0 ? _a : '',
929
+ action: (_b = status.text.additional_back_url_action) !== null && _b !== void 0 ? _b : '',
930
+ label: (_c = status.text.additional_back_url_label) !== null && _c !== void 0 ? _c : '',
931
+ region: (_d = status.additional_button_return_region) !== null && _d !== void 0 ? _d : '',
932
+ isEnabled: status.text.is_additional_back_url_enabled,
933
+ };
934
+ }
935
+ }
936
+
809
937
  class StatusUpdatedAction {
810
- constructor(statusResponse) {
938
+ constructor(statusResponse, isSavePaymentMethodMode = false, savePaymentMethodStatus) {
811
939
  this.type = 'status_updated';
940
+ let status;
941
+ if (statusResponse instanceof StatusResponse) {
942
+ status = statusResponse.status;
943
+ }
944
+ else {
945
+ status = statusResponse;
946
+ }
812
947
  this.data = {
813
- statusState: statusResponse.status.statusState,
814
- invoice: statusResponse.status.invoice,
815
- isSuccess: statusResponse.status.isSuccess,
816
- isCanceled: statusResponse.status.isCanceled,
817
- group: statusResponse.status.group,
948
+ statusState: status.statusState,
949
+ invoice: status.invoice,
950
+ isSuccess: status.isSuccess,
951
+ isCanceled: status.isCanceled,
952
+ group: status.group,
953
+ isSavePaymentMethodMode,
954
+ savePaymentMethodStatus
818
955
  };
819
956
  }
820
957
  }
@@ -1493,7 +1630,7 @@ InitializeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", ve
1493
1630
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: InitializeService, decorators: [{
1494
1631
  type: Injectable,
1495
1632
  args: [{
1496
- providedIn: 'root',
1633
+ providedIn: 'root'
1497
1634
  }]
1498
1635
  }], ctorParameters: function () {
1499
1636
  return [{ type: undefined, decorators: [{
@@ -2881,6 +3018,7 @@ var StatusSearchParam;
2881
3018
  StatusSearchParam["testPs"] = "fix_testPs";
2882
3019
  StatusSearchParam["testXsolla"] = "fix_testXsolla";
2883
3020
  StatusSearchParam["userReturnStatus"] = "fix_userReturnStatus";
3021
+ StatusSearchParam["isSavePaymentAccount"] = "isSavePaymentAccount";
2884
3022
  })(StatusSearchParam || (StatusSearchParam = {}));
2885
3023
 
2886
3024
  const requiredStatusSearchParams = [
@@ -2960,15 +3098,15 @@ const statusSearchParamsMap = new Map([
2960
3098
  converter: numberConverter,
2961
3099
  },
2962
3100
  ],
3101
+ [
3102
+ StatusSearchParam.isSavePaymentAccount,
3103
+ {
3104
+ key: 'isSavePaymentAccount',
3105
+ converter: numberConverter,
3106
+ },
3107
+ ],
2963
3108
  ]);
2964
3109
 
2965
- class TerminalError extends AppError {
2966
- constructor(message, code) {
2967
- super(message);
2968
- this.code = code;
2969
- }
2970
- }
2971
-
2972
3110
  class XpsApiPart {
2973
3111
  constructor() {
2974
3112
  this.response = new BehaviorSubject(null);
@@ -3012,121 +3150,6 @@ const statusRequestFactoryProvider = {
3012
3150
  useValue: (...args) => new StatusRequest(...args),
3013
3151
  };
3014
3152
 
3015
- var StatusGroups;
3016
- (function (StatusGroups) {
3017
- StatusGroups["troubled"] = "troubled";
3018
- StatusGroups["done"] = "done";
3019
- StatusGroups["invoice"] = "invoice";
3020
- })(StatusGroups || (StatusGroups = {}));
3021
-
3022
- var StatusEnum;
3023
- (function (StatusEnum) {
3024
- StatusEnum["created"] = "created";
3025
- StatusEnum["awaiting"] = "awaiting";
3026
- StatusEnum["processing"] = "processing";
3027
- StatusEnum["authorized"] = "authorized";
3028
- StatusEnum["held"] = "held";
3029
- StatusEnum["done"] = "done";
3030
- StatusEnum["error"] = "error";
3031
- StatusEnum["canceled"] = "canceled";
3032
- })(StatusEnum || (StatusEnum = {}));
3033
-
3034
- class StatusResponse {
3035
- constructor(parameters) {
3036
- var _a, _b, _c, _d, _e, _f, _g;
3037
- if ((_a = parameters.errors) === null || _a === void 0 ? void 0 : _a[0]) {
3038
- this.error = {
3039
- code: parameters.errors[0].code.toString(),
3040
- message: parameters.errors[0].message,
3041
- };
3042
- }
3043
- if (!parameters.status) {
3044
- throw new TerminalError((_c = (_b = this.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : '', (_e = (_d = this.error) === null || _d === void 0 ? void 0 : _d.code.toString()) !== null && _e !== void 0 ? _e : '');
3045
- }
3046
- this.status = {
3047
- statusState: parameters.status.statusData.stateText,
3048
- email: parameters.status.statusData.email,
3049
- webSocketUrl: parameters.status.statusData.webSocketChannelUrl,
3050
- webSocketChannelName: parameters.status.statusData.webSocketChannelName,
3051
- webSocketClientType: parameters.status.statusData.webSocketClientType,
3052
- financeInfo: parameters.status.text.info,
3053
- discount: parameters.status.text.info.discount
3054
- ? Math.abs(Number.parseFloat((_g = (_f = parameters.status.text.info.discount) === null || _f === void 0 ? void 0 : _f.value) !== null && _g !== void 0 ? _g : ''))
3055
- : null,
3056
- isCancelUser: parameters.status.isCancelUser,
3057
- postMessageStatus: parameters.status.isCancelUser
3058
- ? StatusGroups.troubled
3059
- : parameters.status.group,
3060
- virtualCurrencyAmount: parameters.status.statusData.out,
3061
- backUrlSettings: {
3062
- backUrl: parameters.status.text.backurl,
3063
- backUrlAction: parameters.status.text.backurl_action,
3064
- backUrlCaption: parameters.status.text.backurl_caption,
3065
- returnRegion: parameters.status.return_region,
3066
- },
3067
- additionalBackButton: this.getAdditionalBackButton(parameters.status),
3068
- group: parameters.status.group,
3069
- needToCheck: parameters.status.needToCheck,
3070
- autoRedirect: parameters.status.autoredirect,
3071
- statusMessage: parameters.status.text.state,
3072
- userId: parameters.status.statusData.v1,
3073
- invoice: parameters.status.statusData.invoice,
3074
- pid: parameters.status.statusData.pid,
3075
- projectAmount: this.getProjectAmount(parameters.status),
3076
- titleClass: parameters.status.title_class,
3077
- paymentCountryIso: parameters.status.statusData.payment_country_iso,
3078
- order: parameters.status.text.order,
3079
- };
3080
- if (parameters.form) {
3081
- this.status.userReturnStatus = this.getUserReturnStatus(parameters.form);
3082
- }
3083
- if (this.status.statusState === StatusEnum.done ||
3084
- this.status.statusState === StatusEnum.authorized) {
3085
- this.status.isSuccess = true;
3086
- }
3087
- if (this.status.statusState === StatusEnum.canceled ||
3088
- this.status.isCancelUser) {
3089
- this.status.isCanceled = true;
3090
- }
3091
- }
3092
- getUserReturnStatus(form) {
3093
- var _a;
3094
- const value = (_a = form['fix_userReturnStatus']) === null || _a === void 0 ? void 0 : _a.value;
3095
- if (value === 'undefined')
3096
- return undefined;
3097
- return value;
3098
- }
3099
- getProjectAmount(status) {
3100
- if (!status.statusData.projectAmount) {
3101
- return;
3102
- }
3103
- const [amount, currency] = status.statusData.projectAmount.split(' ');
3104
- return {
3105
- amount,
3106
- currency,
3107
- };
3108
- }
3109
- getAdditionalBackButton(status) {
3110
- var _a, _b, _c, _d;
3111
- if (!status.text.is_additional_back_url_enabled) {
3112
- return {
3113
- link: '',
3114
- action: '',
3115
- label: '',
3116
- region: '',
3117
- isEnabled: false,
3118
- };
3119
- }
3120
- return {
3121
- link: (_a = status.text.additional_back_url_link) !== null && _a !== void 0 ? _a : '',
3122
- action: (_b = status.text.additional_back_url_action) !== null && _b !== void 0 ? _b : '',
3123
- label: (_c = status.text.additional_back_url_label) !== null && _c !== void 0 ? _c : '',
3124
- region: (_d = status.additional_button_return_region) !== null && _d !== void 0 ? _d : '',
3125
- isEnabled: status.text.is_additional_back_url_enabled,
3126
- };
3127
- }
3128
- }
3129
-
3130
3153
  const statusResponseFactoryToken = new InjectionToken('StatusResponse');
3131
3154
  const statusResponseFactoryProvider = {
3132
3155
  provide: statusResponseFactoryToken,
@@ -4656,16 +4679,275 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
4656
4679
  }]
4657
4680
  }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService }, { type: WebsocketStatusService }]; } });
4658
4681
 
4682
+ var TitleClass;
4683
+ (function (TitleClass) {
4684
+ TitleClass["done"] = "done";
4685
+ TitleClass["cancel"] = "cancel";
4686
+ TitleClass["cancelUser"] = "canceluser";
4687
+ })(TitleClass || (TitleClass = {}));
4688
+
4689
+ var SavePaymentMethodStatus;
4690
+ (function (SavePaymentMethodStatus) {
4691
+ SavePaymentMethodStatus["success"] = "success";
4692
+ SavePaymentMethodStatus["failed"] = "failed";
4693
+ })(SavePaymentMethodStatus || (SavePaymentMethodStatus = {}));
4694
+
4695
+ class XpsResponseError extends AppError {
4696
+ constructor(message) {
4697
+ super('XPS response failed' + (message ? `: "${message}".` : '.'));
4698
+ }
4699
+ }
4700
+
4701
+ class SavedPaymentAccountChangesService {
4702
+ constructor(settingsService, secureApi) {
4703
+ this.settingsService = settingsService;
4704
+ this.secureApi = secureApi;
4705
+ this.apiRoute = 'savedmethods/newaccountinfo';
4706
+ this.response = new Subject();
4707
+ }
4708
+ get response$() {
4709
+ return this.response.asObservable();
4710
+ }
4711
+ request(invoice) {
4712
+ return __awaiter(this, void 0, void 0, function* () {
4713
+ const requestParameters = {
4714
+ access_token: this.settingsService.token,
4715
+ invoice_id: invoice,
4716
+ };
4717
+ return lastValueFrom(this.secureApi
4718
+ .post(this.apiRoute, new URLSearchParams(requestParameters), {
4719
+ headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
4720
+ responseType: 'json',
4721
+ })
4722
+ .pipe(tap((value) => {
4723
+ this.response.next(value);
4724
+ }))).catch((error) => {
4725
+ throw new XpsResponseError(error.message);
4726
+ });
4727
+ });
4728
+ }
4729
+ }
4730
+ SavedPaymentAccountChangesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavedPaymentAccountChangesService, deps: [{ token: SettingsService }, { token: SecureApiClient }], target: i0.ɵɵFactoryTarget.Injectable });
4731
+ SavedPaymentAccountChangesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavedPaymentAccountChangesService, providedIn: 'root' });
4732
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavedPaymentAccountChangesService, decorators: [{
4733
+ type: Injectable,
4734
+ args: [{
4735
+ providedIn: 'root'
4736
+ }]
4737
+ }], ctorParameters: function () { return [{ type: SettingsService }, { type: SecureApiClient }]; } });
4738
+
4739
+ class SavePaymentMethodStatusService {
4740
+ constructor(statusRequestService, listenStatusService, savedPaymentAccountChangesService, nextActionService, checkStatusService) {
4741
+ this.statusRequestService = statusRequestService;
4742
+ this.listenStatusService = listenStatusService;
4743
+ this.savedPaymentAccountChangesService = savedPaymentAccountChangesService;
4744
+ this.nextActionService = nextActionService;
4745
+ this.checkStatusService = checkStatusService;
4746
+ this.statusChecked = false;
4747
+ }
4748
+ getStatus(params) {
4749
+ return __awaiter(this, void 0, void 0, function* () {
4750
+ if (this.listenStatusSubscription) {
4751
+ this.listenStatusSubscription.unsubscribe();
4752
+ this.listenStatusService.stopListening();
4753
+ }
4754
+ this.statusRequestService.setRequestParams(params);
4755
+ this.statusRequestService.request();
4756
+ const statusResponse = yield firstValueFrom(this.statusRequestService.response$);
4757
+ statusResponse.status.isSavePaymentAccount = true;
4758
+ // this.listenStatusService.stopListening();
4759
+ const accountData = yield this.getPaymentAccountData(params.invoice);
4760
+ if (this.savingFailedOrCancel(statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status) || this.savingSuccessful(accountData, statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status)) {
4761
+ return statusResponse.status;
4762
+ }
4763
+ if (!this.statusChecked) {
4764
+ this.checkStatus(params);
4765
+ statusResponse.status.statusState = StatusEnum.processing;
4766
+ return statusResponse.status;
4767
+ }
4768
+ statusResponse.status.statusState = StatusEnum.error;
4769
+ return statusResponse.status;
4770
+ });
4771
+ }
4772
+ checkStatus(params) {
4773
+ if (!this.statusChecked) {
4774
+ this.statusChecked = true;
4775
+ }
4776
+ this.startWaitingStatusUpdates(params.invoice);
4777
+ this.statusRequestService.request();
4778
+ }
4779
+ getStatusOld(params) {
4780
+ return __awaiter(this, void 0, void 0, function* () {
4781
+ console.log('getStatus', params);
4782
+ this.statusRequestService.setRequestParams(params);
4783
+ // this.startWaitingStatusUpdates(params.invoice);
4784
+ this.statusRequestService.request();
4785
+ const statusResponse = yield firstValueFrom(this.statusRequestService.response$);
4786
+ this.checkStatusService.setRequestParams(params.invoice);
4787
+ this.checkStatusService.request();
4788
+ const checkStatusResponse = yield firstValueFrom(this.checkStatusService.response$);
4789
+ if (!checkStatusResponse.final) {
4790
+ this.startWaitingStatusUpdates(params.invoice);
4791
+ statusResponse.status.isSavePaymentAccount = true;
4792
+ statusResponse.status.statusState = StatusEnum.processing;
4793
+ return statusResponse.status;
4794
+ }
4795
+ // todo: get account
4796
+ const accountData = yield this.getPaymentAccountData(params.invoice);
4797
+ if (!this.savingFailedOrCancel(statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status) && !this.savingSuccessful(accountData, statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status)) {
4798
+ // todo is proccessing
4799
+ this.startWaitingStatusUpdates(params.invoice);
4800
+ statusResponse.status.statusState = StatusEnum.processing;
4801
+ }
4802
+ statusResponse.status.isSavePaymentAccount = true;
4803
+ return statusResponse.status;
4804
+ // this.listenStatusService.listen(params.invoice);
4805
+ // this.statusRequestService.request();
4806
+ // const paramsCheck = {
4807
+ // section: 'getstatus',
4808
+ // action: 'getstatus',
4809
+ // // invoice: params.invoice,
4810
+ // ...params,
4811
+ // access_token: params.token || '8sogPLisB328Snf9M9aChSwkZn4IzOzf_lc_en'
4812
+ // };
4813
+ // // const check = await this.checkStatusService.requestPromise('directpayment', paramsCheck);
4814
+ // // console.log('requestPromise', check);
4815
+ // // todo: get account
4816
+ // // const accountData = await this.getPaymentAccountData(params.invoice);
4817
+ // // this.startWaitingStatusUpdates(params.invoice);
4818
+ // // this.listenStatusService.statusUpdated$
4819
+ // this.startWaitingStatusUpdates(params.invoice);
4820
+ // this.statusRequestService.request();
4821
+ // this.checkStatusService.setRequestParams(params.invoice);
4822
+ // this.checkStatusService.request();
4823
+ // this.checkStatusService.response$.subscribe((resp) => {
4824
+ // console.log('checkSt', resp);
4825
+ // });
4826
+ // const statusResponse = await firstValueFrom(
4827
+ // this.statusRequestService.response$
4828
+ // );
4829
+ // const savingFailedOrCancel = statusResponse.status?.titleClass === TitleClass.cancel || statusResponse.status?.titleClass === TitleClass.cancelUser;
4830
+ // const savingSuccessful = statusResponse.status?.titleClass === TitleClass.done && accountData?.new_account;
4831
+ // if (!accountData) {
4832
+ // this.startWaitingStatusUpdates(params.invoice);
4833
+ // statusResponse.status.statusState = StatusEnum.processing;
4834
+ // }
4835
+ // if (!this.savingFailedOrCancel(statusResponse?.status) && !this.savingSuccessful(accountData, statusResponse?.status)) {
4836
+ // // todo is proccessing
4837
+ //
4838
+ // // this.startWaitingStatusUpdates(params.invoice);
4839
+ // statusResponse.status.statusState = StatusEnum.processing;
4840
+ // }
4841
+ // statusResponse.status.isSavePaymentAccount = true;
4842
+ // return statusResponse.status;
4843
+ // return null;
4844
+ // if (!this.savePaymentMethodStatus) {
4845
+ // statusResponse.status.statusState = StatusEnum.processing;
4846
+ // }
4847
+ // statusResponse.status.isSavePaymentAccount = true;
4848
+ // return statusResponse.status;
4849
+ });
4850
+ }
4851
+ savingFailedOrCancel(status) {
4852
+ return (status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.cancel || (status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.cancelUser;
4853
+ }
4854
+ savingSuccessful(accountData, status, checkStatus) {
4855
+ return !!((status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.done && ((accountData === null || accountData === void 0 ? void 0 : accountData.new_account) || (checkStatus === null || checkStatus === void 0 ? void 0 : checkStatus.isPaymentAccountAttached)));
4856
+ }
4857
+ getPaymentAccountData(invoice) {
4858
+ return this.savedPaymentAccountChangesService
4859
+ .request(invoice);
4860
+ // .then((accountChanges: SavedPaymentAccountChanges) => {
4861
+ // if (accountChanges) {
4862
+ // this.handleSavingStatus(status, accountChanges.new_account);
4863
+ // }
4864
+ // });
4865
+ }
4866
+ startWaitingStatusUpdates(invoice) {
4867
+ if (this.listenStatusSubscription) {
4868
+ this.listenStatusSubscription.unsubscribe();
4869
+ this.listenStatusService.stopListening();
4870
+ }
4871
+ // debugger
4872
+ this.listenStatusService.listen(invoice);
4873
+ this.listenStatusSubscription = this.listenStatusService.statusUpdated$
4874
+ .subscribe((statusSettings) => {
4875
+ // this.checkStatusService.response$.subscribe((res) => {
4876
+ // if (res.final) {
4877
+ // if (statusSettings?.statusResponse.status) {
4878
+ // this.loadNewPaymentAccountData(statusSettings?.statusResponse.status, res)
4879
+ // }
4880
+ // }
4881
+ // });
4882
+ void firstValueFrom(this.checkStatusService.response$).then((checkStatusResponse) => {
4883
+ if (checkStatusResponse.final && (statusSettings === null || statusSettings === void 0 ? void 0 : statusSettings.statusResponse.status)) {
4884
+ this.loadNewPaymentAccountData(statusSettings === null || statusSettings === void 0 ? void 0 : statusSettings.statusResponse.status, checkStatusResponse);
4885
+ }
4886
+ });
4887
+ // this.checkStatusService.request();
4888
+ // const checkStatusResponse = await firstValueFrom(
4889
+ // this.checkStatusService.response$
4890
+ // );
4891
+ });
4892
+ // this.statusRequestService.request();
4893
+ }
4894
+ loadNewPaymentAccountData(status, checkStatus) {
4895
+ if (!status.invoice) {
4896
+ return;
4897
+ }
4898
+ void this.savedPaymentAccountChangesService
4899
+ .request(status.invoice)
4900
+ .then((accountChanges) => {
4901
+ if (accountChanges) {
4902
+ this.handleSavingStatus(status, accountChanges, checkStatus);
4903
+ }
4904
+ });
4905
+ }
4906
+ handleSavingStatus(status, account, checkStatus) {
4907
+ // const savingFailedOrCancel = status?.titleClass === TitleClass.cancel || status?.titleClass === TitleClass.cancelUser;
4908
+ //
4909
+ // const savingSuccessful = status?.titleClass === TitleClass.done && account;
4910
+ if (this.savingSuccessful(account, status, checkStatus)) {
4911
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.success;
4912
+ }
4913
+ else {
4914
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.failed;
4915
+ }
4916
+ this.listenStatusService.stopListening();
4917
+ this.listenStatusSubscription.unsubscribe();
4918
+ // const paymentAccountWasSaved = status?.titleClass === TitleClass.done && account !== null;
4919
+ const isSavePaymentMethod = true;
4920
+ // this.savePaymentMethodStatus = this.savingFailedOrCancel(status) ? SavePaymentMethodStatus.success : SavePaymentMethodStatus.failed;
4921
+ console.log(status, isSavePaymentMethod, this.savePaymentMethodStatus);
4922
+ this.nextActionService.emitFlowUpdates(new StatusUpdatedAction(status, isSavePaymentMethod, this.savePaymentMethodStatus));
4923
+ }
4924
+ }
4925
+ SavePaymentMethodStatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavePaymentMethodStatusService, deps: [{ token: StatusRequestService }, { token: ListenStatusService }, { token: SavedPaymentAccountChangesService }, { token: NextActionService }, { token: CheckStatusService }], target: i0.ɵɵFactoryTarget.Injectable });
4926
+ SavePaymentMethodStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavePaymentMethodStatusService, providedIn: 'root' });
4927
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavePaymentMethodStatusService, decorators: [{
4928
+ type: Injectable,
4929
+ args: [{
4930
+ providedIn: 'root'
4931
+ }]
4932
+ }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: ListenStatusService }, { type: SavedPaymentAccountChangesService }, { type: NextActionService }, { type: CheckStatusService }]; } });
4933
+
4659
4934
  class StatusService {
4660
- constructor(urlService, statusRequestService, financeDetailsService, listenStatusService, nextActionService) {
4935
+ constructor(urlService, statusRequestService, financeDetailsService, listenStatusService, nextActionService, savePaymentMethodStatusService) {
4661
4936
  this.urlService = urlService;
4662
4937
  this.statusRequestService = statusRequestService;
4663
4938
  this.financeDetailsService = financeDetailsService;
4664
4939
  this.listenStatusService = listenStatusService;
4665
4940
  this.nextActionService = nextActionService;
4941
+ this.savePaymentMethodStatusService = savePaymentMethodStatusService;
4666
4942
  }
4667
4943
  getStatus(params) {
4668
4944
  return __awaiter(this, void 0, void 0, function* () {
4945
+ // todo: если params.savePaymentMethod, то надо выполнить логику для
4946
+ // account status
4947
+ const isSavePaymentMethodMode = !!(params === null || params === void 0 ? void 0 : params.isSavePaymentAccount);
4948
+ if (isSavePaymentMethodMode) {
4949
+ return this.savePaymentMethodStatusService.getStatus(params); // todo: saveMethodStatus.getStatus();
4950
+ }
4669
4951
  this.statusRequestService.setRequestParams(params);
4670
4952
  this.startWaitingStatusUpdates(params.invoice);
4671
4953
  this.statusRequestService.request();
@@ -4677,6 +4959,7 @@ class StatusService {
4677
4959
  getStatusWithUrlSearchParams(url) {
4678
4960
  return __awaiter(this, void 0, void 0, function* () {
4679
4961
  const searchParams = this.getRequestParamsFromUrl(url);
4962
+ console.log('searchParams', searchParams);
4680
4963
  if (!searchParams) {
4681
4964
  throw new Error('No required search params to get status');
4682
4965
  }
@@ -4705,14 +4988,14 @@ class StatusService {
4705
4988
  });
4706
4989
  }
4707
4990
  }
4708
- StatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, deps: [{ token: UrlService }, { token: StatusRequestService }, { token: FinanceDetailsService }, { token: ListenStatusService }, { token: NextActionService }], target: i0.ɵɵFactoryTarget.Injectable });
4991
+ StatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, deps: [{ token: UrlService }, { token: StatusRequestService }, { token: FinanceDetailsService }, { token: ListenStatusService }, { token: NextActionService }, { token: SavePaymentMethodStatusService }], target: i0.ɵɵFactoryTarget.Injectable });
4709
4992
  StatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, providedIn: 'root' });
4710
4993
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, decorators: [{
4711
4994
  type: Injectable,
4712
4995
  args: [{
4713
4996
  providedIn: 'root',
4714
4997
  }]
4715
- }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: FinanceDetailsService }, { type: ListenStatusService }, { type: NextActionService }]; } });
4998
+ }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: FinanceDetailsService }, { type: ListenStatusService }, { type: NextActionService }, { type: SavePaymentMethodStatusService }]; } });
4716
4999
 
4717
5000
  class CreditCardStateService extends EmitDataService {
4718
5001
  }
@@ -4737,12 +5020,6 @@ var ThreeDsStatusTypes;
4737
5020
  ThreeDsStatusTypes["collectDfp"] = "collect_dfp";
4738
5021
  })(ThreeDsStatusTypes || (ThreeDsStatusTypes = {}));
4739
5022
 
4740
- class XpsResponseError extends AppError {
4741
- constructor(message) {
4742
- super('XPS response failed' + (message ? `: "${message}".` : '.'));
4743
- }
4744
- }
4745
-
4746
5023
  class StatusThreeDsRequest {
4747
5024
  constructor(token, threeDsId) {
4748
5025
  this.access_token = token;
@@ -5205,6 +5482,7 @@ class PaymentService {
5205
5482
  this.destroy$ = new Subject();
5206
5483
  this.formDestroy$ = new Subject();
5207
5484
  this.formFieldsStatusSubject = new BehaviorSubject(null);
5485
+ this.isSavingMethodMode = false;
5208
5486
  }
5209
5487
  initialize(config) {
5210
5488
  var _a, _b;
@@ -5234,9 +5512,14 @@ class PaymentService {
5234
5512
  this.emitFormFieldsStatus(this.form);
5235
5513
  return;
5236
5514
  }
5515
+ console.log('this.fields', this.fields);
5516
+ console.log('this.form', this.form);
5517
+ this.isSavingMethodMode = this.fields.some(({ name, value }) => name === 'savePsAccountOnly' && value === "1" /* XpsBoolean.true */);
5237
5518
  const submitResponse = yield this.submitService.request(this.fields, this.form);
5238
5519
  this.data = submitResponse;
5239
- this.emitFinanceDetails(submitResponse.summary);
5520
+ if (!this.isSavingMethodMode) {
5521
+ this.emitFinanceDetails(submitResponse.summary);
5522
+ }
5240
5523
  this.emitFormMessages(submitResponse.messages);
5241
5524
  // Handle 3ds flow
5242
5525
  if (submitResponse.currentCommand === XpsCommand.create) {
@@ -5290,7 +5573,10 @@ class PaymentService {
5290
5573
  invoice: parseInt((_a = this.data.fixInvoice) !== null && _a !== void 0 ? _a : ''),
5291
5574
  signature: (_b = this.data.signature) !== null && _b !== void 0 ? _b : '',
5292
5575
  locale: (_d = (_c = this.data.fields.find((field) => field.name === 'locale')) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 'en',
5576
+ isSavePaymentAccount: this.isSavingMethodMode ? 1 : 0,
5293
5577
  };
5578
+ console.log('this.data', this.data);
5579
+ console.log('getStatus', params);
5294
5580
  return this.statusService.getStatus(params);
5295
5581
  });
5296
5582
  }