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

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 +198 -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 +426 -145
  20. package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
  21. package/fesm2020/xsolla-payment-client-core.mjs +417 -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-test20.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,270 @@ 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
+ this.statusRequestService.setRequestParams(params);
4751
+ this.statusRequestService.request();
4752
+ const statusResponse = yield firstValueFrom(this.statusRequestService.response$);
4753
+ statusResponse.status.isSavePaymentAccount = true;
4754
+ const accountData = yield this.getPaymentAccountData(params.invoice);
4755
+ if (this.savingFailedOrCancel(statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status) || this.savingSuccessful(accountData, statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status)) {
4756
+ return statusResponse.status;
4757
+ }
4758
+ if (!this.statusChecked) {
4759
+ this.checkStatus(params);
4760
+ statusResponse.status.statusState = StatusEnum.processing;
4761
+ return statusResponse.status;
4762
+ }
4763
+ statusResponse.status.statusState = StatusEnum.error;
4764
+ return statusResponse.status;
4765
+ });
4766
+ }
4767
+ checkStatus(params) {
4768
+ if (!this.statusChecked) {
4769
+ this.statusChecked = true;
4770
+ }
4771
+ this.startWaitingStatusUpdates(params.invoice);
4772
+ // this.statusRequestService.request();
4773
+ }
4774
+ getStatusOld(params) {
4775
+ return __awaiter(this, void 0, void 0, function* () {
4776
+ console.log('getStatus', params);
4777
+ this.statusRequestService.setRequestParams(params);
4778
+ // this.startWaitingStatusUpdates(params.invoice);
4779
+ this.statusRequestService.request();
4780
+ const statusResponse = yield firstValueFrom(this.statusRequestService.response$);
4781
+ this.checkStatusService.setRequestParams(params.invoice);
4782
+ this.checkStatusService.request();
4783
+ const checkStatusResponse = yield firstValueFrom(this.checkStatusService.response$);
4784
+ if (!checkStatusResponse.final) {
4785
+ this.startWaitingStatusUpdates(params.invoice);
4786
+ statusResponse.status.isSavePaymentAccount = true;
4787
+ statusResponse.status.statusState = StatusEnum.processing;
4788
+ return statusResponse.status;
4789
+ }
4790
+ // todo: get account
4791
+ const accountData = yield this.getPaymentAccountData(params.invoice);
4792
+ if (!this.savingFailedOrCancel(statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status) && !this.savingSuccessful(accountData, statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status)) {
4793
+ // todo is proccessing
4794
+ this.startWaitingStatusUpdates(params.invoice);
4795
+ statusResponse.status.statusState = StatusEnum.processing;
4796
+ }
4797
+ statusResponse.status.isSavePaymentAccount = true;
4798
+ return statusResponse.status;
4799
+ // this.listenStatusService.listen(params.invoice);
4800
+ // this.statusRequestService.request();
4801
+ // const paramsCheck = {
4802
+ // section: 'getstatus',
4803
+ // action: 'getstatus',
4804
+ // // invoice: params.invoice,
4805
+ // ...params,
4806
+ // access_token: params.token || '8sogPLisB328Snf9M9aChSwkZn4IzOzf_lc_en'
4807
+ // };
4808
+ // // const check = await this.checkStatusService.requestPromise('directpayment', paramsCheck);
4809
+ // // console.log('requestPromise', check);
4810
+ // // todo: get account
4811
+ // // const accountData = await this.getPaymentAccountData(params.invoice);
4812
+ // // this.startWaitingStatusUpdates(params.invoice);
4813
+ // // this.listenStatusService.statusUpdated$
4814
+ // this.startWaitingStatusUpdates(params.invoice);
4815
+ // this.statusRequestService.request();
4816
+ // this.checkStatusService.setRequestParams(params.invoice);
4817
+ // this.checkStatusService.request();
4818
+ // this.checkStatusService.response$.subscribe((resp) => {
4819
+ // console.log('checkSt', resp);
4820
+ // });
4821
+ // const statusResponse = await firstValueFrom(
4822
+ // this.statusRequestService.response$
4823
+ // );
4824
+ // const savingFailedOrCancel = statusResponse.status?.titleClass === TitleClass.cancel || statusResponse.status?.titleClass === TitleClass.cancelUser;
4825
+ // const savingSuccessful = statusResponse.status?.titleClass === TitleClass.done && accountData?.new_account;
4826
+ // if (!accountData) {
4827
+ // this.startWaitingStatusUpdates(params.invoice);
4828
+ // statusResponse.status.statusState = StatusEnum.processing;
4829
+ // }
4830
+ // if (!this.savingFailedOrCancel(statusResponse?.status) && !this.savingSuccessful(accountData, statusResponse?.status)) {
4831
+ // // todo is proccessing
4832
+ //
4833
+ // // this.startWaitingStatusUpdates(params.invoice);
4834
+ // statusResponse.status.statusState = StatusEnum.processing;
4835
+ // }
4836
+ // statusResponse.status.isSavePaymentAccount = true;
4837
+ // return statusResponse.status;
4838
+ // return null;
4839
+ // if (!this.savePaymentMethodStatus) {
4840
+ // statusResponse.status.statusState = StatusEnum.processing;
4841
+ // }
4842
+ // statusResponse.status.isSavePaymentAccount = true;
4843
+ // return statusResponse.status;
4844
+ });
4845
+ }
4846
+ savingFailedOrCancel(status) {
4847
+ return (status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.cancel || (status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.cancelUser;
4848
+ }
4849
+ savingSuccessful(accountData, status, checkStatus) {
4850
+ 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)));
4851
+ }
4852
+ getPaymentAccountData(invoice) {
4853
+ return this.savedPaymentAccountChangesService
4854
+ .request(invoice);
4855
+ // .then((accountChanges: SavedPaymentAccountChanges) => {
4856
+ // if (accountChanges) {
4857
+ // this.handleSavingStatus(status, accountChanges.new_account);
4858
+ // }
4859
+ // });
4860
+ }
4861
+ startWaitingStatusUpdates(invoice) {
4862
+ if (this.listenStatusSubscription) {
4863
+ this.listenStatusSubscription.unsubscribe();
4864
+ this.listenStatusService.stopListening();
4865
+ }
4866
+ // debugger
4867
+ this.listenStatusService.listen(invoice);
4868
+ this.listenStatusSubscription = this.listenStatusService.statusUpdated$
4869
+ .subscribe((statusSettings) => {
4870
+ // this.checkStatusService.response$.subscribe((res) => {
4871
+ // if (res.final) {
4872
+ // if (statusSettings?.statusResponse.status) {
4873
+ // this.loadNewPaymentAccountData(statusSettings?.statusResponse.status, res)
4874
+ // }
4875
+ // }
4876
+ // });
4877
+ void firstValueFrom(this.checkStatusService.response$).then((checkStatusResponse) => {
4878
+ if (checkStatusResponse.final && (statusSettings === null || statusSettings === void 0 ? void 0 : statusSettings.statusResponse.status)) {
4879
+ this.loadNewPaymentAccountData(statusSettings === null || statusSettings === void 0 ? void 0 : statusSettings.statusResponse.status, checkStatusResponse);
4880
+ }
4881
+ });
4882
+ // this.checkStatusService.request();
4883
+ // const checkStatusResponse = await firstValueFrom(
4884
+ // this.checkStatusService.response$
4885
+ // );
4886
+ });
4887
+ // this.statusRequestService.request();
4888
+ }
4889
+ loadNewPaymentAccountData(status, checkStatus) {
4890
+ if (!status.invoice) {
4891
+ return;
4892
+ }
4893
+ void this.savedPaymentAccountChangesService
4894
+ .request(status.invoice)
4895
+ .then((accountChanges) => {
4896
+ if (accountChanges) {
4897
+ this.handleSavingStatus(status, accountChanges, checkStatus);
4898
+ }
4899
+ });
4900
+ }
4901
+ handleSavingStatus(status, account, checkStatus) {
4902
+ // const savingFailedOrCancel = status?.titleClass === TitleClass.cancel || status?.titleClass === TitleClass.cancelUser;
4903
+ //
4904
+ // const savingSuccessful = status?.titleClass === TitleClass.done && account;
4905
+ if (this.savingSuccessful(account, status, checkStatus)) {
4906
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.success;
4907
+ }
4908
+ else {
4909
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.failed;
4910
+ }
4911
+ this.listenStatusService.stopListening();
4912
+ this.listenStatusSubscription.unsubscribe();
4913
+ // const paymentAccountWasSaved = status?.titleClass === TitleClass.done && account !== null;
4914
+ const isSavePaymentMethod = true;
4915
+ // this.savePaymentMethodStatus = this.savingFailedOrCancel(status) ? SavePaymentMethodStatus.success : SavePaymentMethodStatus.failed;
4916
+ console.log(status, isSavePaymentMethod, this.savePaymentMethodStatus);
4917
+ this.nextActionService.emitFlowUpdates(new StatusUpdatedAction(status, isSavePaymentMethod, this.savePaymentMethodStatus));
4918
+ }
4919
+ }
4920
+ 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 });
4921
+ SavePaymentMethodStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavePaymentMethodStatusService, providedIn: 'root' });
4922
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavePaymentMethodStatusService, decorators: [{
4923
+ type: Injectable,
4924
+ args: [{
4925
+ providedIn: 'root'
4926
+ }]
4927
+ }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: ListenStatusService }, { type: SavedPaymentAccountChangesService }, { type: NextActionService }, { type: CheckStatusService }]; } });
4928
+
4659
4929
  class StatusService {
4660
- constructor(urlService, statusRequestService, financeDetailsService, listenStatusService, nextActionService) {
4930
+ constructor(urlService, statusRequestService, financeDetailsService, listenStatusService, nextActionService, savePaymentMethodStatusService) {
4661
4931
  this.urlService = urlService;
4662
4932
  this.statusRequestService = statusRequestService;
4663
4933
  this.financeDetailsService = financeDetailsService;
4664
4934
  this.listenStatusService = listenStatusService;
4665
4935
  this.nextActionService = nextActionService;
4936
+ this.savePaymentMethodStatusService = savePaymentMethodStatusService;
4666
4937
  }
4667
4938
  getStatus(params) {
4668
4939
  return __awaiter(this, void 0, void 0, function* () {
4940
+ // todo: если params.savePaymentMethod, то надо выполнить логику для
4941
+ // account status
4942
+ const isSavePaymentMethodMode = !!(params === null || params === void 0 ? void 0 : params.isSavePaymentAccount);
4943
+ if (isSavePaymentMethodMode) {
4944
+ return this.savePaymentMethodStatusService.getStatus(params); // todo: saveMethodStatus.getStatus();
4945
+ }
4669
4946
  this.statusRequestService.setRequestParams(params);
4670
4947
  this.startWaitingStatusUpdates(params.invoice);
4671
4948
  this.statusRequestService.request();
@@ -4677,6 +4954,7 @@ class StatusService {
4677
4954
  getStatusWithUrlSearchParams(url) {
4678
4955
  return __awaiter(this, void 0, void 0, function* () {
4679
4956
  const searchParams = this.getRequestParamsFromUrl(url);
4957
+ console.log('searchParams', searchParams);
4680
4958
  if (!searchParams) {
4681
4959
  throw new Error('No required search params to get status');
4682
4960
  }
@@ -4705,14 +4983,14 @@ class StatusService {
4705
4983
  });
4706
4984
  }
4707
4985
  }
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 });
4986
+ 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
4987
  StatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, providedIn: 'root' });
4710
4988
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, decorators: [{
4711
4989
  type: Injectable,
4712
4990
  args: [{
4713
4991
  providedIn: 'root',
4714
4992
  }]
4715
- }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: FinanceDetailsService }, { type: ListenStatusService }, { type: NextActionService }]; } });
4993
+ }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: FinanceDetailsService }, { type: ListenStatusService }, { type: NextActionService }, { type: SavePaymentMethodStatusService }]; } });
4716
4994
 
4717
4995
  class CreditCardStateService extends EmitDataService {
4718
4996
  }
@@ -4737,12 +5015,6 @@ var ThreeDsStatusTypes;
4737
5015
  ThreeDsStatusTypes["collectDfp"] = "collect_dfp";
4738
5016
  })(ThreeDsStatusTypes || (ThreeDsStatusTypes = {}));
4739
5017
 
4740
- class XpsResponseError extends AppError {
4741
- constructor(message) {
4742
- super('XPS response failed' + (message ? `: "${message}".` : '.'));
4743
- }
4744
- }
4745
-
4746
5018
  class StatusThreeDsRequest {
4747
5019
  constructor(token, threeDsId) {
4748
5020
  this.access_token = token;
@@ -5205,6 +5477,7 @@ class PaymentService {
5205
5477
  this.destroy$ = new Subject();
5206
5478
  this.formDestroy$ = new Subject();
5207
5479
  this.formFieldsStatusSubject = new BehaviorSubject(null);
5480
+ this.isSavingMethodMode = false;
5208
5481
  }
5209
5482
  initialize(config) {
5210
5483
  var _a, _b;
@@ -5234,9 +5507,14 @@ class PaymentService {
5234
5507
  this.emitFormFieldsStatus(this.form);
5235
5508
  return;
5236
5509
  }
5510
+ console.log('this.fields', this.fields);
5511
+ console.log('this.form', this.form);
5512
+ this.isSavingMethodMode = this.fields.some(({ name, value }) => name === 'savePsAccountOnly' && value === "1" /* XpsBoolean.true */);
5237
5513
  const submitResponse = yield this.submitService.request(this.fields, this.form);
5238
5514
  this.data = submitResponse;
5239
- this.emitFinanceDetails(submitResponse.summary);
5515
+ if (!this.isSavingMethodMode) {
5516
+ this.emitFinanceDetails(submitResponse.summary);
5517
+ }
5240
5518
  this.emitFormMessages(submitResponse.messages);
5241
5519
  // Handle 3ds flow
5242
5520
  if (submitResponse.currentCommand === XpsCommand.create) {
@@ -5290,7 +5568,10 @@ class PaymentService {
5290
5568
  invoice: parseInt((_a = this.data.fixInvoice) !== null && _a !== void 0 ? _a : ''),
5291
5569
  signature: (_b = this.data.signature) !== null && _b !== void 0 ? _b : '',
5292
5570
  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',
5571
+ isSavePaymentAccount: this.isSavingMethodMode ? 1 : 0,
5293
5572
  };
5573
+ console.log('this.data', this.data);
5574
+ console.log('getStatus', params);
5294
5575
  return this.statusService.getStatus(params);
5295
5576
  });
5296
5577
  }