@xsolla/payment-client-core 0.1.15 → 0.1.17-test

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 (50) hide show
  1. package/esm2020/lib/core/edit-saved-methods/delete-method-response.interface.mjs +2 -0
  2. package/esm2020/lib/core/edit-saved-methods/edit-saved-methods.service.mjs +43 -0
  3. package/esm2020/lib/core/payment/actions/status-updated/status-updated.action.class.mjs +17 -7
  4. package/esm2020/lib/core/payment/actions/status-updated/status-updated.action.type.mjs +1 -1
  5. package/esm2020/lib/core/payment/config/config.service.mjs +8 -4
  6. package/esm2020/lib/core/payment/initialize/initialize-request-params.interface.mjs +1 -1
  7. package/esm2020/lib/core/payment/initialize/initialize.service.mjs +4 -1
  8. package/esm2020/lib/core/payment/payment-config.interface.mjs +1 -1
  9. package/esm2020/lib/core/payment/payment.service.mjs +9 -2
  10. package/esm2020/lib/core/payment/status/save-payment-method-status/api/saved-payment-account-changes.interface.mjs +2 -0
  11. package/esm2020/lib/core/payment/status/save-payment-method-status/api/saved-payment-account-changes.service.mjs +44 -0
  12. package/esm2020/lib/core/payment/status/save-payment-method-status/api/saved-payment-account.interface.mjs +2 -0
  13. package/esm2020/lib/core/payment/status/save-payment-method-status/save-payment-method-status.enum.mjs +6 -0
  14. package/esm2020/lib/core/payment/status/save-payment-method-status/save-payment-method-status.service.mjs +116 -0
  15. package/esm2020/lib/core/payment/status/status-request/status-request-params.interface.mjs +1 -1
  16. package/esm2020/lib/core/payment/status/status-request/status-search-param.enum.mjs +2 -1
  17. package/esm2020/lib/core/payment/status/status-request/status-search-params.map.mjs +8 -1
  18. package/esm2020/lib/core/payment/status/status.interface.mjs +1 -1
  19. package/esm2020/lib/core/payment/status/status.service.mjs +10 -4
  20. package/esm2020/lib/core/payment-methods/payment-methods-request-params.interface.mjs +1 -1
  21. package/esm2020/lib/core/payment-methods/payment-methods.service.mjs +7 -4
  22. package/esm2020/lib/core/saved-methods/saved-methods.service.mjs +5 -2
  23. package/esm2020/lib/core-library.service.mjs +8 -5
  24. package/fesm2015/xsolla-payment-client-core.mjs +389 -150
  25. package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
  26. package/fesm2020/xsolla-payment-client-core.mjs +380 -147
  27. package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
  28. package/lib/core/edit-saved-methods/delete-method-response.interface.d.ts +5 -0
  29. package/lib/core/edit-saved-methods/edit-saved-methods.service.d.ts +14 -0
  30. package/lib/core/payment/actions/status-updated/status-updated.action.class.d.ts +3 -1
  31. package/lib/core/payment/actions/status-updated/status-updated.action.type.d.ts +3 -0
  32. package/lib/core/payment/initialize/initialize-request-params.interface.d.ts +1 -0
  33. package/lib/core/payment/payment-config.interface.d.ts +1 -0
  34. package/lib/core/payment/payment.service.d.ts +1 -0
  35. package/lib/core/payment/status/save-payment-method-status/api/saved-payment-account-changes.interface.d.ts +6 -0
  36. package/lib/core/payment/status/save-payment-method-status/api/saved-payment-account-changes.service.d.ts +16 -0
  37. package/lib/core/payment/status/save-payment-method-status/api/saved-payment-account.interface.d.ts +7 -0
  38. package/lib/core/payment/status/save-payment-method-status/save-payment-method-status.enum.d.ts +4 -0
  39. package/lib/core/payment/status/save-payment-method-status/save-payment-method-status.service.d.ts +31 -0
  40. package/lib/core/payment/status/status-request/status-request-params.interface.d.ts +1 -0
  41. package/lib/core/payment/status/status-request/status-search-param.enum.d.ts +2 -1
  42. package/lib/core/payment/status/status.interface.d.ts +1 -0
  43. package/lib/core/payment/status/status.service.d.ts +3 -1
  44. package/lib/core/payment-methods/payment-methods-request-params.interface.d.ts +2 -0
  45. package/lib/core/payment-methods/payment-methods.service.d.ts +1 -1
  46. package/lib/core/saved-methods/saved-methods.service.d.ts +1 -1
  47. package/lib/core-library.service.d.ts +5 -2
  48. package/package.json +1 -1
  49. package/xsolla-payment-client-core-0.1.17-test.tgz +0 -0
  50. package/xsolla-payment-client-core-0.1.15.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
 
@@ -244,9 +244,9 @@ class PaymentMethodsService {
244
244
  this.apiRoute = 'remained_payment_methods';
245
245
  this.cache = new Map();
246
246
  }
247
- getList() {
247
+ getList(isSaveMethodMode) {
248
248
  return __awaiter(this, void 0, void 0, function* () {
249
- const response = yield this.request();
249
+ const response = yield this.request(isSaveMethodMode);
250
250
  return response.remained;
251
251
  });
252
252
  }
@@ -256,11 +256,14 @@ class PaymentMethodsService {
256
256
  return response.especial;
257
257
  });
258
258
  }
259
- request() {
259
+ request(isSaveMethodMode) {
260
260
  return __awaiter(this, void 0, void 0, function* () {
261
261
  const requestParams = {
262
262
  access_token: this.settingsService.token,
263
263
  country: this.countryService.getCountry(),
264
+ save_payment_account_only: isSaveMethodMode
265
+ ? "1" /* XpsBoolean.true */
266
+ : "0" /* XpsBoolean.false */,
264
267
  };
265
268
  const cacheKey = JSON.stringify(requestParams);
266
269
  if (!this.cache.has(cacheKey)) {
@@ -330,8 +333,11 @@ class SavedMethodsService {
330
333
  this.apiRoute = 'savedmethods';
331
334
  this.cache = new Map();
332
335
  }
333
- getList() {
336
+ getList(needResetCache = false) {
334
337
  return __awaiter(this, void 0, void 0, function* () {
338
+ if (needResetCache) {
339
+ this.cache.clear();
340
+ }
335
341
  const response = yield this.request();
336
342
  return response.list;
337
343
  });
@@ -478,12 +484,16 @@ class PaymentConfigService {
478
484
  if (!config.returnUrl) {
479
485
  throw new Error('URL is not provided in payment config');
480
486
  }
481
- return Object.assign(Object.assign({}, config), { returnUrl: this.enrichReturnUrl(config.returnUrl) });
487
+ return Object.assign(Object.assign({}, config), { returnUrl: this.enrichReturnUrl(config.returnUrl, !!config.savePaymentMethod) });
482
488
  }
483
- enrichReturnUrl(returnUrl) {
484
- return this.urlService.addSearchParams(returnUrl, {
489
+ enrichReturnUrl(returnUrl, savePaymentMethod) {
490
+ const enrichedUrl = this.urlService.addSearchParams(returnUrl, {
485
491
  token: this.settingsService.token,
492
+ isSavePaymentAccount: savePaymentMethod
493
+ ? "1" /* XpsBoolean.true */
494
+ : "0" /* XpsBoolean.false */,
486
495
  });
496
+ return enrichedUrl;
487
497
  }
488
498
  }
489
499
  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 });
@@ -805,15 +815,146 @@ const checkStatusActionFactoryProvider = {
805
815
  },
806
816
  };
807
817
 
818
+ class TerminalError extends AppError {
819
+ constructor(message, code) {
820
+ super(message);
821
+ this.code = code;
822
+ }
823
+ }
824
+
825
+ var StatusGroups;
826
+ (function (StatusGroups) {
827
+ StatusGroups["troubled"] = "troubled";
828
+ StatusGroups["done"] = "done";
829
+ StatusGroups["invoice"] = "invoice";
830
+ })(StatusGroups || (StatusGroups = {}));
831
+
832
+ var StatusEnum;
833
+ (function (StatusEnum) {
834
+ StatusEnum["created"] = "created";
835
+ StatusEnum["awaiting"] = "awaiting";
836
+ StatusEnum["processing"] = "processing";
837
+ StatusEnum["authorized"] = "authorized";
838
+ StatusEnum["held"] = "held";
839
+ StatusEnum["done"] = "done";
840
+ StatusEnum["error"] = "error";
841
+ StatusEnum["canceled"] = "canceled";
842
+ })(StatusEnum || (StatusEnum = {}));
843
+
844
+ class StatusResponse {
845
+ constructor(parameters) {
846
+ var _a, _b, _c, _d, _e, _f, _g;
847
+ if ((_a = parameters.errors) === null || _a === void 0 ? void 0 : _a[0]) {
848
+ this.error = {
849
+ code: parameters.errors[0].code.toString(),
850
+ message: parameters.errors[0].message,
851
+ };
852
+ }
853
+ if (!parameters.status) {
854
+ 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 : '');
855
+ }
856
+ this.status = {
857
+ statusState: parameters.status.statusData.stateText,
858
+ email: parameters.status.statusData.email,
859
+ webSocketUrl: parameters.status.statusData.webSocketChannelUrl,
860
+ webSocketChannelName: parameters.status.statusData.webSocketChannelName,
861
+ webSocketClientType: parameters.status.statusData.webSocketClientType,
862
+ financeInfo: parameters.status.text.info,
863
+ discount: parameters.status.text.info.discount
864
+ ? Math.abs(Number.parseFloat((_g = (_f = parameters.status.text.info.discount) === null || _f === void 0 ? void 0 : _f.value) !== null && _g !== void 0 ? _g : ''))
865
+ : null,
866
+ isCancelUser: parameters.status.isCancelUser,
867
+ postMessageStatus: parameters.status.isCancelUser
868
+ ? StatusGroups.troubled
869
+ : parameters.status.group,
870
+ virtualCurrencyAmount: parameters.status.statusData.out,
871
+ backUrlSettings: {
872
+ backUrl: parameters.status.text.backurl,
873
+ backUrlAction: parameters.status.text.backurl_action,
874
+ backUrlCaption: parameters.status.text.backurl_caption,
875
+ returnRegion: parameters.status.return_region,
876
+ },
877
+ additionalBackButton: this.getAdditionalBackButton(parameters.status),
878
+ group: parameters.status.group,
879
+ needToCheck: parameters.status.needToCheck,
880
+ autoRedirect: parameters.status.autoredirect,
881
+ statusMessage: parameters.status.text.state,
882
+ userId: parameters.status.statusData.v1,
883
+ invoice: parameters.status.statusData.invoice,
884
+ pid: parameters.status.statusData.pid,
885
+ projectAmount: this.getProjectAmount(parameters.status),
886
+ titleClass: parameters.status.title_class,
887
+ paymentCountryIso: parameters.status.statusData.payment_country_iso,
888
+ order: parameters.status.text.order,
889
+ };
890
+ if (parameters.form) {
891
+ this.status.userReturnStatus = this.getUserReturnStatus(parameters.form);
892
+ }
893
+ if (this.status.statusState === StatusEnum.done ||
894
+ this.status.statusState === StatusEnum.authorized) {
895
+ this.status.isSuccess = true;
896
+ }
897
+ if (this.status.statusState === StatusEnum.canceled ||
898
+ this.status.isCancelUser) {
899
+ this.status.isCanceled = true;
900
+ }
901
+ }
902
+ getUserReturnStatus(form) {
903
+ var _a;
904
+ const value = (_a = form['fix_userReturnStatus']) === null || _a === void 0 ? void 0 : _a.value;
905
+ if (value === 'undefined')
906
+ return undefined;
907
+ return value;
908
+ }
909
+ getProjectAmount(status) {
910
+ if (!status.statusData.projectAmount) {
911
+ return;
912
+ }
913
+ const [amount, currency] = status.statusData.projectAmount.split(' ');
914
+ return {
915
+ amount,
916
+ currency,
917
+ };
918
+ }
919
+ getAdditionalBackButton(status) {
920
+ var _a, _b, _c, _d;
921
+ if (!status.text.is_additional_back_url_enabled) {
922
+ return {
923
+ link: '',
924
+ action: '',
925
+ label: '',
926
+ region: '',
927
+ isEnabled: false,
928
+ };
929
+ }
930
+ return {
931
+ link: (_a = status.text.additional_back_url_link) !== null && _a !== void 0 ? _a : '',
932
+ action: (_b = status.text.additional_back_url_action) !== null && _b !== void 0 ? _b : '',
933
+ label: (_c = status.text.additional_back_url_label) !== null && _c !== void 0 ? _c : '',
934
+ region: (_d = status.additional_button_return_region) !== null && _d !== void 0 ? _d : '',
935
+ isEnabled: status.text.is_additional_back_url_enabled,
936
+ };
937
+ }
938
+ }
939
+
808
940
  class StatusUpdatedAction {
809
- constructor(statusResponse) {
941
+ constructor(statusResponse, isSavePaymentMethodMode = false, savePaymentMethodStatus) {
810
942
  this.type = 'status_updated';
943
+ let status;
944
+ if (statusResponse instanceof StatusResponse) {
945
+ status = statusResponse.status;
946
+ }
947
+ else {
948
+ status = statusResponse;
949
+ }
811
950
  this.data = {
812
- statusState: statusResponse.status.statusState,
813
- invoice: statusResponse.status.invoice,
814
- isSuccess: statusResponse.status.isSuccess,
815
- isCanceled: statusResponse.status.isCanceled,
816
- group: statusResponse.status.group,
951
+ statusState: status.statusState,
952
+ invoice: status.invoice,
953
+ isSuccess: status.isSuccess,
954
+ isCanceled: status.isCanceled,
955
+ group: status.group,
956
+ isSavePaymentMethodMode,
957
+ savePaymentMethodStatus,
817
958
  };
818
959
  }
819
960
  }
@@ -1458,6 +1599,9 @@ class InitializeService {
1458
1599
  ? "1" /* XpsBoolean.true */
1459
1600
  : "0" /* XpsBoolean.false */,
1460
1601
  saved_method_id: config.savedMethodId,
1602
+ save_payment_account_only: config.savePaymentMethod
1603
+ ? "1" /* XpsBoolean.true */
1604
+ : "0" /* XpsBoolean.false */,
1461
1605
  };
1462
1606
  return this.xpsApiService
1463
1607
  .directPaymentRequest(requestParams)
@@ -2879,6 +3023,7 @@ var StatusSearchParam;
2879
3023
  StatusSearchParam["testPs"] = "fix_testPs";
2880
3024
  StatusSearchParam["testXsolla"] = "fix_testXsolla";
2881
3025
  StatusSearchParam["userReturnStatus"] = "fix_userReturnStatus";
3026
+ StatusSearchParam["isSavePaymentAccount"] = "isSavePaymentAccount";
2882
3027
  })(StatusSearchParam || (StatusSearchParam = {}));
2883
3028
 
2884
3029
  const requiredStatusSearchParams = [
@@ -2958,15 +3103,15 @@ const statusSearchParamsMap = new Map([
2958
3103
  converter: numberConverter,
2959
3104
  },
2960
3105
  ],
3106
+ [
3107
+ StatusSearchParam.isSavePaymentAccount,
3108
+ {
3109
+ key: 'isSavePaymentAccount',
3110
+ converter: stringConverter,
3111
+ },
3112
+ ],
2961
3113
  ]);
2962
3114
 
2963
- class TerminalError extends AppError {
2964
- constructor(message, code) {
2965
- super(message);
2966
- this.code = code;
2967
- }
2968
- }
2969
-
2970
3115
  class XpsApiPart {
2971
3116
  constructor() {
2972
3117
  this.response = new BehaviorSubject(null);
@@ -3010,121 +3155,6 @@ const statusRequestFactoryProvider = {
3010
3155
  useValue: (...args) => new StatusRequest(...args),
3011
3156
  };
3012
3157
 
3013
- var StatusGroups;
3014
- (function (StatusGroups) {
3015
- StatusGroups["troubled"] = "troubled";
3016
- StatusGroups["done"] = "done";
3017
- StatusGroups["invoice"] = "invoice";
3018
- })(StatusGroups || (StatusGroups = {}));
3019
-
3020
- var StatusEnum;
3021
- (function (StatusEnum) {
3022
- StatusEnum["created"] = "created";
3023
- StatusEnum["awaiting"] = "awaiting";
3024
- StatusEnum["processing"] = "processing";
3025
- StatusEnum["authorized"] = "authorized";
3026
- StatusEnum["held"] = "held";
3027
- StatusEnum["done"] = "done";
3028
- StatusEnum["error"] = "error";
3029
- StatusEnum["canceled"] = "canceled";
3030
- })(StatusEnum || (StatusEnum = {}));
3031
-
3032
- class StatusResponse {
3033
- constructor(parameters) {
3034
- var _a, _b, _c, _d, _e, _f, _g;
3035
- if ((_a = parameters.errors) === null || _a === void 0 ? void 0 : _a[0]) {
3036
- this.error = {
3037
- code: parameters.errors[0].code.toString(),
3038
- message: parameters.errors[0].message,
3039
- };
3040
- }
3041
- if (!parameters.status) {
3042
- 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 : '');
3043
- }
3044
- this.status = {
3045
- statusState: parameters.status.statusData.stateText,
3046
- email: parameters.status.statusData.email,
3047
- webSocketUrl: parameters.status.statusData.webSocketChannelUrl,
3048
- webSocketChannelName: parameters.status.statusData.webSocketChannelName,
3049
- webSocketClientType: parameters.status.statusData.webSocketClientType,
3050
- financeInfo: parameters.status.text.info,
3051
- discount: parameters.status.text.info.discount
3052
- ? Math.abs(Number.parseFloat((_g = (_f = parameters.status.text.info.discount) === null || _f === void 0 ? void 0 : _f.value) !== null && _g !== void 0 ? _g : ''))
3053
- : null,
3054
- isCancelUser: parameters.status.isCancelUser,
3055
- postMessageStatus: parameters.status.isCancelUser
3056
- ? StatusGroups.troubled
3057
- : parameters.status.group,
3058
- virtualCurrencyAmount: parameters.status.statusData.out,
3059
- backUrlSettings: {
3060
- backUrl: parameters.status.text.backurl,
3061
- backUrlAction: parameters.status.text.backurl_action,
3062
- backUrlCaption: parameters.status.text.backurl_caption,
3063
- returnRegion: parameters.status.return_region,
3064
- },
3065
- additionalBackButton: this.getAdditionalBackButton(parameters.status),
3066
- group: parameters.status.group,
3067
- needToCheck: parameters.status.needToCheck,
3068
- autoRedirect: parameters.status.autoredirect,
3069
- statusMessage: parameters.status.text.state,
3070
- userId: parameters.status.statusData.v1,
3071
- invoice: parameters.status.statusData.invoice,
3072
- pid: parameters.status.statusData.pid,
3073
- projectAmount: this.getProjectAmount(parameters.status),
3074
- titleClass: parameters.status.title_class,
3075
- paymentCountryIso: parameters.status.statusData.payment_country_iso,
3076
- order: parameters.status.text.order,
3077
- };
3078
- if (parameters.form) {
3079
- this.status.userReturnStatus = this.getUserReturnStatus(parameters.form);
3080
- }
3081
- if (this.status.statusState === StatusEnum.done ||
3082
- this.status.statusState === StatusEnum.authorized) {
3083
- this.status.isSuccess = true;
3084
- }
3085
- if (this.status.statusState === StatusEnum.canceled ||
3086
- this.status.isCancelUser) {
3087
- this.status.isCanceled = true;
3088
- }
3089
- }
3090
- getUserReturnStatus(form) {
3091
- var _a;
3092
- const value = (_a = form['fix_userReturnStatus']) === null || _a === void 0 ? void 0 : _a.value;
3093
- if (value === 'undefined')
3094
- return undefined;
3095
- return value;
3096
- }
3097
- getProjectAmount(status) {
3098
- if (!status.statusData.projectAmount) {
3099
- return;
3100
- }
3101
- const [amount, currency] = status.statusData.projectAmount.split(' ');
3102
- return {
3103
- amount,
3104
- currency,
3105
- };
3106
- }
3107
- getAdditionalBackButton(status) {
3108
- var _a, _b, _c, _d;
3109
- if (!status.text.is_additional_back_url_enabled) {
3110
- return {
3111
- link: '',
3112
- action: '',
3113
- label: '',
3114
- region: '',
3115
- isEnabled: false,
3116
- };
3117
- }
3118
- return {
3119
- link: (_a = status.text.additional_back_url_link) !== null && _a !== void 0 ? _a : '',
3120
- action: (_b = status.text.additional_back_url_action) !== null && _b !== void 0 ? _b : '',
3121
- label: (_c = status.text.additional_back_url_label) !== null && _c !== void 0 ? _c : '',
3122
- region: (_d = status.additional_button_return_region) !== null && _d !== void 0 ? _d : '',
3123
- isEnabled: status.text.is_additional_back_url_enabled,
3124
- };
3125
- }
3126
- }
3127
-
3128
3158
  const statusResponseFactoryToken = new InjectionToken('StatusResponse');
3129
3159
  const statusResponseFactoryProvider = {
3130
3160
  provide: statusResponseFactoryToken,
@@ -4654,16 +4684,184 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
4654
4684
  }]
4655
4685
  }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService }, { type: WebsocketStatusService }]; } });
4656
4686
 
4687
+ var TitleClass;
4688
+ (function (TitleClass) {
4689
+ TitleClass["done"] = "done";
4690
+ TitleClass["cancel"] = "cancel";
4691
+ TitleClass["cancelUser"] = "canceluser";
4692
+ })(TitleClass || (TitleClass = {}));
4693
+
4694
+ var SavePaymentMethodStatus;
4695
+ (function (SavePaymentMethodStatus) {
4696
+ SavePaymentMethodStatus["success"] = "success";
4697
+ SavePaymentMethodStatus["failed"] = "failed";
4698
+ })(SavePaymentMethodStatus || (SavePaymentMethodStatus = {}));
4699
+
4700
+ class XpsResponseError extends AppError {
4701
+ constructor(message) {
4702
+ super('XPS response failed' + (message ? `: "${message}".` : '.'));
4703
+ }
4704
+ }
4705
+
4706
+ class SavedPaymentAccountChangesService {
4707
+ constructor(settingsService, secureApi) {
4708
+ this.settingsService = settingsService;
4709
+ this.secureApi = secureApi;
4710
+ this.apiRoute = 'savedmethods/newaccountinfo';
4711
+ this.response = new Subject();
4712
+ }
4713
+ get response$() {
4714
+ return this.response.asObservable();
4715
+ }
4716
+ request(invoice) {
4717
+ return __awaiter(this, void 0, void 0, function* () {
4718
+ const requestParameters = {
4719
+ access_token: this.settingsService.token,
4720
+ invoice_id: invoice,
4721
+ };
4722
+ return lastValueFrom(this.secureApi
4723
+ .post(this.apiRoute, new URLSearchParams(requestParameters), {
4724
+ headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
4725
+ responseType: 'json',
4726
+ })
4727
+ .pipe(tap((value) => {
4728
+ this.response.next(value);
4729
+ }))).catch((error) => {
4730
+ throw new XpsResponseError(error.message);
4731
+ });
4732
+ });
4733
+ }
4734
+ }
4735
+ 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 });
4736
+ SavedPaymentAccountChangesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavedPaymentAccountChangesService, providedIn: 'root' });
4737
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavedPaymentAccountChangesService, decorators: [{
4738
+ type: Injectable,
4739
+ args: [{
4740
+ providedIn: 'root',
4741
+ }]
4742
+ }], ctorParameters: function () { return [{ type: SettingsService }, { type: SecureApiClient }]; } });
4743
+
4744
+ class SavePaymentMethodStatusService {
4745
+ constructor(statusRequestService, listenStatusService, savedPaymentAccountChangesService, nextActionService, checkStatusService) {
4746
+ this.statusRequestService = statusRequestService;
4747
+ this.listenStatusService = listenStatusService;
4748
+ this.savedPaymentAccountChangesService = savedPaymentAccountChangesService;
4749
+ this.nextActionService = nextActionService;
4750
+ this.checkStatusService = checkStatusService;
4751
+ this.statusChecked = false;
4752
+ }
4753
+ getStatus(params) {
4754
+ return __awaiter(this, void 0, void 0, function* () {
4755
+ if (!this.accountData || !this.status) {
4756
+ this.statusRequestService.setRequestParams(params);
4757
+ this.statusRequestService.request();
4758
+ const statusResponse = yield firstValueFrom(this.statusRequestService.response$);
4759
+ this.status = statusResponse.status;
4760
+ this.status.isSavePaymentAccount = true;
4761
+ this.accountData = yield this.getPaymentAccountData(params.invoice);
4762
+ }
4763
+ if (this.savingFailedOrCancel(this.status) ||
4764
+ (this.accountData && this.savingSuccessful(this.accountData, this.status))) {
4765
+ return this.status;
4766
+ }
4767
+ if (!this.statusChecked) {
4768
+ this.checkStatus(params);
4769
+ this.status.statusState = StatusEnum.processing;
4770
+ return this.status;
4771
+ }
4772
+ this.statusChecked = false;
4773
+ this.status.statusState = StatusEnum.error;
4774
+ const outStatus = Object.assign({}, this.status);
4775
+ this.status = null;
4776
+ return outStatus;
4777
+ });
4778
+ }
4779
+ checkStatus(params) {
4780
+ if (!this.statusChecked) {
4781
+ this.statusChecked = true;
4782
+ }
4783
+ this.startWaitingStatusUpdates(params.invoice);
4784
+ this.statusRequestService.request();
4785
+ }
4786
+ savingFailedOrCancel(status) {
4787
+ return ((status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.cancel ||
4788
+ (status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.cancelUser);
4789
+ }
4790
+ savingSuccessful(accountData, status, checkStatus) {
4791
+ return !!((status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.done &&
4792
+ ((accountData === null || accountData === void 0 ? void 0 : accountData.new_account) || (checkStatus === null || checkStatus === void 0 ? void 0 : checkStatus.isPaymentAccountAttached)));
4793
+ }
4794
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
4795
+ getPaymentAccountData(invoice) {
4796
+ return this.savedPaymentAccountChangesService.request(invoice);
4797
+ }
4798
+ startWaitingStatusUpdates(invoice) {
4799
+ if (this.listenStatusSubscription) {
4800
+ this.listenStatusSubscription.unsubscribe();
4801
+ this.listenStatusService.stopListening();
4802
+ }
4803
+ this.listenStatusService.listen(invoice);
4804
+ this.listenStatusSubscription =
4805
+ this.listenStatusService.statusUpdated$.subscribe(({ statusResponse }) => {
4806
+ if (!(statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status)) {
4807
+ return;
4808
+ }
4809
+ this.status = statusResponse.status;
4810
+ void firstValueFrom(this.checkStatusService.response$).then((checkStatusResponse) => {
4811
+ if ((checkStatusResponse === null || checkStatusResponse === void 0 ? void 0 : checkStatusResponse.final) && statusResponse.status) {
4812
+ this.loadNewPaymentAccountData(statusResponse.status, checkStatusResponse);
4813
+ }
4814
+ });
4815
+ });
4816
+ }
4817
+ loadNewPaymentAccountData(status, checkStatus) {
4818
+ if (!status.invoice) {
4819
+ return;
4820
+ }
4821
+ void this.getPaymentAccountData(status.invoice).then((accountChanges) => {
4822
+ if (accountChanges) {
4823
+ this.accountData = accountChanges;
4824
+ this.handleSavingStatus(status, accountChanges, checkStatus);
4825
+ }
4826
+ });
4827
+ }
4828
+ handleSavingStatus(status, account, checkStatus) {
4829
+ if (this.savingSuccessful(account, status, checkStatus)) {
4830
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.success;
4831
+ }
4832
+ else {
4833
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.failed;
4834
+ }
4835
+ this.listenStatusService.stopListening();
4836
+ this.listenStatusSubscription.unsubscribe();
4837
+ const isSavePaymentMethod = true;
4838
+ this.nextActionService.emitFlowUpdates(new StatusUpdatedAction(status, isSavePaymentMethod, this.savePaymentMethodStatus));
4839
+ }
4840
+ }
4841
+ 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 });
4842
+ SavePaymentMethodStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavePaymentMethodStatusService, providedIn: 'root' });
4843
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavePaymentMethodStatusService, decorators: [{
4844
+ type: Injectable,
4845
+ args: [{
4846
+ providedIn: 'root',
4847
+ }]
4848
+ }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: ListenStatusService }, { type: SavedPaymentAccountChangesService }, { type: NextActionService }, { type: CheckStatusService }]; } });
4849
+
4657
4850
  class StatusService {
4658
- constructor(urlService, statusRequestService, financeDetailsService, listenStatusService, nextActionService) {
4851
+ constructor(urlService, statusRequestService, financeDetailsService, listenStatusService, nextActionService, savePaymentMethodStatusService) {
4659
4852
  this.urlService = urlService;
4660
4853
  this.statusRequestService = statusRequestService;
4661
4854
  this.financeDetailsService = financeDetailsService;
4662
4855
  this.listenStatusService = listenStatusService;
4663
4856
  this.nextActionService = nextActionService;
4857
+ this.savePaymentMethodStatusService = savePaymentMethodStatusService;
4664
4858
  }
4665
4859
  getStatus(params) {
4666
4860
  return __awaiter(this, void 0, void 0, function* () {
4861
+ const isSavePaymentMethodMode = !!(params === null || params === void 0 ? void 0 : params.isSavePaymentAccount);
4862
+ if (isSavePaymentMethodMode) {
4863
+ return this.savePaymentMethodStatusService.getStatus(params);
4864
+ }
4667
4865
  this.statusRequestService.setRequestParams(params);
4668
4866
  this.startWaitingStatusUpdates(params.invoice);
4669
4867
  this.statusRequestService.request();
@@ -4703,14 +4901,14 @@ class StatusService {
4703
4901
  });
4704
4902
  }
4705
4903
  }
4706
- 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 });
4904
+ 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 });
4707
4905
  StatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, providedIn: 'root' });
4708
4906
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, decorators: [{
4709
4907
  type: Injectable,
4710
4908
  args: [{
4711
4909
  providedIn: 'root',
4712
4910
  }]
4713
- }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: FinanceDetailsService }, { type: ListenStatusService }, { type: NextActionService }]; } });
4911
+ }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: FinanceDetailsService }, { type: ListenStatusService }, { type: NextActionService }, { type: SavePaymentMethodStatusService }]; } });
4714
4912
 
4715
4913
  class CreditCardStateService extends EmitDataService {
4716
4914
  }
@@ -4735,12 +4933,6 @@ var ThreeDsStatusTypes;
4735
4933
  ThreeDsStatusTypes["collectDfp"] = "collect_dfp";
4736
4934
  })(ThreeDsStatusTypes || (ThreeDsStatusTypes = {}));
4737
4935
 
4738
- class XpsResponseError extends AppError {
4739
- constructor(message) {
4740
- super('XPS response failed' + (message ? `: "${message}".` : '.'));
4741
- }
4742
- }
4743
-
4744
4936
  class StatusThreeDsRequest {
4745
4937
  constructor(token, threeDsId) {
4746
4938
  this.access_token = token;
@@ -5203,6 +5395,7 @@ class PaymentService {
5203
5395
  this.destroy$ = new Subject();
5204
5396
  this.formDestroy$ = new Subject();
5205
5397
  this.formFieldsStatusSubject = new BehaviorSubject(null);
5398
+ this.isSavingMethodMode = false;
5206
5399
  }
5207
5400
  initialize(config) {
5208
5401
  var _a, _b;
@@ -5232,9 +5425,12 @@ class PaymentService {
5232
5425
  this.emitFormFieldsStatus(this.form);
5233
5426
  return;
5234
5427
  }
5428
+ this.isSavingMethodMode = this.fields.some(({ name, value }) => name === 'savePsAccountOnly' && value === "1" /* XpsBoolean.true */);
5235
5429
  const submitResponse = yield this.submitService.request(this.fields, this.form);
5236
5430
  this.data = submitResponse;
5237
- this.emitFinanceDetails(submitResponse.summary);
5431
+ if (!this.isSavingMethodMode) {
5432
+ this.emitFinanceDetails(submitResponse.summary);
5433
+ }
5238
5434
  this.emitFormMessages(submitResponse.messages);
5239
5435
  // Handle 3ds flow
5240
5436
  if (submitResponse.currentCommand === XpsCommand.create) {
@@ -5288,6 +5484,9 @@ class PaymentService {
5288
5484
  invoice: parseInt((_a = this.data.fixInvoice) !== null && _a !== void 0 ? _a : ''),
5289
5485
  signature: (_b = this.data.signature) !== null && _b !== void 0 ? _b : '',
5290
5486
  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',
5487
+ isSavePaymentAccount: this.isSavingMethodMode
5488
+ ? "1" /* XpsBoolean.true */
5489
+ : "0" /* XpsBoolean.false */,
5291
5490
  };
5292
5491
  return this.statusService.getStatus(params);
5293
5492
  });
@@ -5494,8 +5693,46 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
5494
5693
  }]
5495
5694
  }], ctorParameters: function () { return [{ type: SettingsService }, { type: RefundPolicyService }, { type: SecureConnectionService }, { type: DisclaimerService }]; } });
5496
5695
 
5696
+ class EditSavedMethodsService {
5697
+ constructor(savedMethodsService, settingsService, secureApi) {
5698
+ this.savedMethodsService = savedMethodsService;
5699
+ this.settingsService = settingsService;
5700
+ this.secureApi = secureApi;
5701
+ this.deleteRoute = 'savedmethods/delete';
5702
+ }
5703
+ deleteSavedMethodRequest(id, type) {
5704
+ return __awaiter(this, void 0, void 0, function* () {
5705
+ const token = this.settingsService.token;
5706
+ const parameters = {
5707
+ access_token: token,
5708
+ id,
5709
+ type,
5710
+ };
5711
+ return lastValueFrom(this.secureApi.post(this.deleteRoute, new URLSearchParams(parameters), {
5712
+ headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
5713
+ responseType: 'json',
5714
+ }))
5715
+ .then(() => __awaiter(this, void 0, void 0, function* () {
5716
+ yield this.savedMethodsService.getList(true);
5717
+ return true;
5718
+ }))
5719
+ .catch(() => {
5720
+ return false;
5721
+ });
5722
+ });
5723
+ }
5724
+ }
5725
+ EditSavedMethodsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: EditSavedMethodsService, deps: [{ token: SavedMethodsService }, { token: SettingsService }, { token: SecureApiClient }], target: i0.ɵɵFactoryTarget.Injectable });
5726
+ EditSavedMethodsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: EditSavedMethodsService, providedIn: 'root' });
5727
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: EditSavedMethodsService, decorators: [{
5728
+ type: Injectable,
5729
+ args: [{
5730
+ providedIn: 'root',
5731
+ }]
5732
+ }], ctorParameters: function () { return [{ type: SavedMethodsService }, { type: SettingsService }, { type: SecureApiClient }]; } });
5733
+
5497
5734
  class CoreLibraryService {
5498
- constructor(settingsService, countryService, paymentMethodsService, savedMethodsService, userBalanceService, paymentConfigService, paymentService, deviceFingerPrintService, financeDetailsService, legalService, statusService, nextActionService, creditCardService, creditCardStateService, formMessagesService) {
5735
+ constructor(settingsService, countryService, paymentMethodsService, savedMethodsService, userBalanceService, paymentConfigService, paymentService, deviceFingerPrintService, financeDetailsService, legalService, statusService, nextActionService, creditCardService, creditCardStateService, formMessagesService, editSavedMethodsService) {
5499
5736
  this.settingsService = settingsService;
5500
5737
  this.countryService = countryService;
5501
5738
  this.paymentMethodsService = paymentMethodsService;
@@ -5511,11 +5748,13 @@ class CoreLibraryService {
5511
5748
  this.creditCardService = creditCardService;
5512
5749
  this.creditCardStateService = creditCardStateService;
5513
5750
  this.formMessagesService = formMessagesService;
5751
+ this.editSavedMethodsService = editSavedMethodsService;
5514
5752
  this.paymentMethods = {
5515
- getList: () => __awaiter(this, void 0, void 0, function* () { return this.paymentMethodsService.getList(); }),
5753
+ getList: (isSaveMethodMode) => __awaiter(this, void 0, void 0, function* () { return this.paymentMethodsService.getList(isSaveMethodMode); }),
5516
5754
  getQuickMethods: () => __awaiter(this, void 0, void 0, function* () { return this.paymentMethodsService.getQuickMethods(); }),
5517
5755
  getSavedMethods: () => __awaiter(this, void 0, void 0, function* () { return this.savedMethodsService.getList(); }),
5518
5756
  getUserBalance: () => __awaiter(this, void 0, void 0, function* () { return this.userBalanceService.getUserBalance(); }),
5757
+ deleteSavedMethod: (id, type) => __awaiter(this, void 0, void 0, function* () { return this.editSavedMethodsService.deleteSavedMethodRequest(id, type); }),
5519
5758
  };
5520
5759
  }
5521
5760
  init(configuration) {
@@ -5583,14 +5822,14 @@ class CoreLibraryService {
5583
5822
  return this.userBalanceService.getUserBalanceValue();
5584
5823
  }
5585
5824
  }
5586
- CoreLibraryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, deps: [{ token: SettingsService }, { token: CountryService }, { token: PaymentMethodsService }, { token: SavedMethodsService }, { token: UserBalanceService }, { token: PaymentConfigService }, { token: PaymentService }, { token: DeviceFingerPrintService }, { token: FinanceDetailsService }, { token: LegalService }, { token: StatusService }, { token: NextActionService }, { token: CreditCardService }, { token: CreditCardStateService }, { token: FormMessagesService }], target: i0.ɵɵFactoryTarget.Injectable });
5825
+ CoreLibraryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, deps: [{ token: SettingsService }, { token: CountryService }, { token: PaymentMethodsService }, { token: SavedMethodsService }, { token: UserBalanceService }, { token: PaymentConfigService }, { token: PaymentService }, { token: DeviceFingerPrintService }, { token: FinanceDetailsService }, { token: LegalService }, { token: StatusService }, { token: NextActionService }, { token: CreditCardService }, { token: CreditCardStateService }, { token: FormMessagesService }, { token: EditSavedMethodsService }], target: i0.ɵɵFactoryTarget.Injectable });
5587
5826
  CoreLibraryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, providedIn: 'root' });
5588
5827
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, decorators: [{
5589
5828
  type: Injectable,
5590
5829
  args: [{
5591
5830
  providedIn: 'root',
5592
5831
  }]
5593
- }], ctorParameters: function () { return [{ type: SettingsService }, { type: CountryService }, { type: PaymentMethodsService }, { type: SavedMethodsService }, { type: UserBalanceService }, { type: PaymentConfigService }, { type: PaymentService }, { type: DeviceFingerPrintService }, { type: FinanceDetailsService }, { type: LegalService }, { type: StatusService }, { type: NextActionService }, { type: CreditCardService }, { type: CreditCardStateService }, { type: FormMessagesService }]; } });
5832
+ }], ctorParameters: function () { return [{ type: SettingsService }, { type: CountryService }, { type: PaymentMethodsService }, { type: SavedMethodsService }, { type: UserBalanceService }, { type: PaymentConfigService }, { type: PaymentService }, { type: DeviceFingerPrintService }, { type: FinanceDetailsService }, { type: LegalService }, { type: StatusService }, { type: NextActionService }, { type: CreditCardService }, { type: CreditCardStateService }, { type: FormMessagesService }, { type: EditSavedMethodsService }]; } });
5594
5833
 
5595
5834
  class HttpError extends AppError {
5596
5835
  constructor(error, req) {