@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
@@ -5,7 +5,7 @@ import * as i1 from '@angular/common/http';
5
5
  import { HttpParams, HttpHeaders, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
6
6
  import JSEncrypt from 'jsencrypt';
7
7
  import { UntypedFormGroup, Validators, UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
8
- import { filter, map as map$1, catchError } from 'rxjs/operators';
8
+ import { filter, map as map$1, tap, catchError } from 'rxjs/operators';
9
9
  import * as i1$1 from '@angular/router';
10
10
  import { CommonModule } from '@angular/common';
11
11
 
@@ -238,18 +238,21 @@ class PaymentMethodsService {
238
238
  this.apiRoute = 'remained_payment_methods';
239
239
  this.cache = new Map();
240
240
  }
241
- async getList() {
242
- const response = await this.request();
241
+ async getList(isSaveMethodMode) {
242
+ const response = await this.request(isSaveMethodMode);
243
243
  return response.remained;
244
244
  }
245
245
  async getQuickMethods() {
246
246
  const response = await this.request();
247
247
  return response.especial;
248
248
  }
249
- async request() {
249
+ async request(isSaveMethodMode) {
250
250
  const requestParams = {
251
251
  access_token: this.settingsService.token,
252
252
  country: this.countryService.getCountry(),
253
+ save_payment_account_only: isSaveMethodMode
254
+ ? "1" /* XpsBoolean.true */
255
+ : "0" /* XpsBoolean.false */,
253
256
  };
254
257
  const cacheKey = JSON.stringify(requestParams);
255
258
  if (!this.cache.has(cacheKey)) {
@@ -316,7 +319,10 @@ class SavedMethodsService {
316
319
  this.apiRoute = 'savedmethods';
317
320
  this.cache = new Map();
318
321
  }
319
- async getList() {
322
+ async getList(needResetCache = false) {
323
+ if (needResetCache) {
324
+ this.cache.clear();
325
+ }
320
326
  const response = await this.request();
321
327
  return response.list;
322
328
  }
@@ -453,13 +459,17 @@ class PaymentConfigService {
453
459
  }
454
460
  return {
455
461
  ...config,
456
- returnUrl: this.enrichReturnUrl(config.returnUrl),
462
+ returnUrl: this.enrichReturnUrl(config.returnUrl, !!config.savePaymentMethod),
457
463
  };
458
464
  }
459
- enrichReturnUrl(returnUrl) {
460
- return this.urlService.addSearchParams(returnUrl, {
465
+ enrichReturnUrl(returnUrl, savePaymentMethod) {
466
+ const enrichedUrl = this.urlService.addSearchParams(returnUrl, {
461
467
  token: this.settingsService.token,
468
+ isSavePaymentAccount: savePaymentMethod
469
+ ? "1" /* XpsBoolean.true */
470
+ : "0" /* XpsBoolean.false */,
462
471
  });
472
+ return enrichedUrl;
463
473
  }
464
474
  }
465
475
  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 });
@@ -781,15 +791,143 @@ const checkStatusActionFactoryProvider = {
781
791
  },
782
792
  };
783
793
 
794
+ class TerminalError extends AppError {
795
+ constructor(message, code) {
796
+ super(message);
797
+ this.code = code;
798
+ }
799
+ }
800
+
801
+ var StatusGroups;
802
+ (function (StatusGroups) {
803
+ StatusGroups["troubled"] = "troubled";
804
+ StatusGroups["done"] = "done";
805
+ StatusGroups["invoice"] = "invoice";
806
+ })(StatusGroups || (StatusGroups = {}));
807
+
808
+ var StatusEnum;
809
+ (function (StatusEnum) {
810
+ StatusEnum["created"] = "created";
811
+ StatusEnum["awaiting"] = "awaiting";
812
+ StatusEnum["processing"] = "processing";
813
+ StatusEnum["authorized"] = "authorized";
814
+ StatusEnum["held"] = "held";
815
+ StatusEnum["done"] = "done";
816
+ StatusEnum["error"] = "error";
817
+ StatusEnum["canceled"] = "canceled";
818
+ })(StatusEnum || (StatusEnum = {}));
819
+
820
+ class StatusResponse {
821
+ constructor(parameters) {
822
+ if (parameters.errors?.[0]) {
823
+ this.error = {
824
+ code: parameters.errors[0].code.toString(),
825
+ message: parameters.errors[0].message,
826
+ };
827
+ }
828
+ if (!parameters.status) {
829
+ throw new TerminalError(this.error?.message ?? '', this.error?.code.toString() ?? '');
830
+ }
831
+ this.status = {
832
+ statusState: parameters.status.statusData.stateText,
833
+ email: parameters.status.statusData.email,
834
+ webSocketUrl: parameters.status.statusData.webSocketChannelUrl,
835
+ webSocketChannelName: parameters.status.statusData.webSocketChannelName,
836
+ webSocketClientType: parameters.status.statusData.webSocketClientType,
837
+ financeInfo: parameters.status.text.info,
838
+ discount: parameters.status.text.info.discount
839
+ ? Math.abs(Number.parseFloat(parameters.status.text.info.discount?.value ?? ''))
840
+ : null,
841
+ isCancelUser: parameters.status.isCancelUser,
842
+ postMessageStatus: parameters.status.isCancelUser
843
+ ? StatusGroups.troubled
844
+ : parameters.status.group,
845
+ virtualCurrencyAmount: parameters.status.statusData.out,
846
+ backUrlSettings: {
847
+ backUrl: parameters.status.text.backurl,
848
+ backUrlAction: parameters.status.text.backurl_action,
849
+ backUrlCaption: parameters.status.text.backurl_caption,
850
+ returnRegion: parameters.status.return_region,
851
+ },
852
+ additionalBackButton: this.getAdditionalBackButton(parameters.status),
853
+ group: parameters.status.group,
854
+ needToCheck: parameters.status.needToCheck,
855
+ autoRedirect: parameters.status.autoredirect,
856
+ statusMessage: parameters.status.text.state,
857
+ userId: parameters.status.statusData.v1,
858
+ invoice: parameters.status.statusData.invoice,
859
+ pid: parameters.status.statusData.pid,
860
+ projectAmount: this.getProjectAmount(parameters.status),
861
+ titleClass: parameters.status.title_class,
862
+ paymentCountryIso: parameters.status.statusData.payment_country_iso,
863
+ order: parameters.status.text.order,
864
+ };
865
+ if (parameters.form) {
866
+ this.status.userReturnStatus = this.getUserReturnStatus(parameters.form);
867
+ }
868
+ if (this.status.statusState === StatusEnum.done ||
869
+ this.status.statusState === StatusEnum.authorized) {
870
+ this.status.isSuccess = true;
871
+ }
872
+ if (this.status.statusState === StatusEnum.canceled ||
873
+ this.status.isCancelUser) {
874
+ this.status.isCanceled = true;
875
+ }
876
+ }
877
+ getUserReturnStatus(form) {
878
+ const value = form['fix_userReturnStatus']?.value;
879
+ if (value === 'undefined')
880
+ return undefined;
881
+ return value;
882
+ }
883
+ getProjectAmount(status) {
884
+ if (!status.statusData.projectAmount) {
885
+ return;
886
+ }
887
+ const [amount, currency] = status.statusData.projectAmount.split(' ');
888
+ return {
889
+ amount,
890
+ currency,
891
+ };
892
+ }
893
+ getAdditionalBackButton(status) {
894
+ if (!status.text.is_additional_back_url_enabled) {
895
+ return {
896
+ link: '',
897
+ action: '',
898
+ label: '',
899
+ region: '',
900
+ isEnabled: false,
901
+ };
902
+ }
903
+ return {
904
+ link: status.text.additional_back_url_link ?? '',
905
+ action: status.text.additional_back_url_action ?? '',
906
+ label: status.text.additional_back_url_label ?? '',
907
+ region: status.additional_button_return_region ?? '',
908
+ isEnabled: status.text.is_additional_back_url_enabled,
909
+ };
910
+ }
911
+ }
912
+
784
913
  class StatusUpdatedAction {
785
- constructor(statusResponse) {
914
+ constructor(statusResponse, isSavePaymentMethodMode = false, savePaymentMethodStatus) {
786
915
  this.type = 'status_updated';
916
+ let status;
917
+ if (statusResponse instanceof StatusResponse) {
918
+ status = statusResponse.status;
919
+ }
920
+ else {
921
+ status = statusResponse;
922
+ }
787
923
  this.data = {
788
- statusState: statusResponse.status.statusState,
789
- invoice: statusResponse.status.invoice,
790
- isSuccess: statusResponse.status.isSuccess,
791
- isCanceled: statusResponse.status.isCanceled,
792
- group: statusResponse.status.group,
924
+ statusState: status.statusState,
925
+ invoice: status.invoice,
926
+ isSuccess: status.isSuccess,
927
+ isCanceled: status.isCanceled,
928
+ group: status.group,
929
+ isSavePaymentMethodMode,
930
+ savePaymentMethodStatus,
793
931
  };
794
932
  }
795
933
  }
@@ -1435,6 +1573,9 @@ class InitializeService {
1435
1573
  ? "1" /* XpsBoolean.true */
1436
1574
  : "0" /* XpsBoolean.false */,
1437
1575
  saved_method_id: config.savedMethodId,
1576
+ save_payment_account_only: config.savePaymentMethod
1577
+ ? "1" /* XpsBoolean.true */
1578
+ : "0" /* XpsBoolean.false */,
1438
1579
  };
1439
1580
  return this.xpsApiService
1440
1581
  .directPaymentRequest(requestParams)
@@ -2824,6 +2965,7 @@ var StatusSearchParam;
2824
2965
  StatusSearchParam["testPs"] = "fix_testPs";
2825
2966
  StatusSearchParam["testXsolla"] = "fix_testXsolla";
2826
2967
  StatusSearchParam["userReturnStatus"] = "fix_userReturnStatus";
2968
+ StatusSearchParam["isSavePaymentAccount"] = "isSavePaymentAccount";
2827
2969
  })(StatusSearchParam || (StatusSearchParam = {}));
2828
2970
 
2829
2971
  const requiredStatusSearchParams = [
@@ -2903,15 +3045,15 @@ const statusSearchParamsMap = new Map([
2903
3045
  converter: numberConverter,
2904
3046
  },
2905
3047
  ],
3048
+ [
3049
+ StatusSearchParam.isSavePaymentAccount,
3050
+ {
3051
+ key: 'isSavePaymentAccount',
3052
+ converter: stringConverter,
3053
+ },
3054
+ ],
2906
3055
  ]);
2907
3056
 
2908
- class TerminalError extends AppError {
2909
- constructor(message, code) {
2910
- super(message);
2911
- this.code = code;
2912
- }
2913
- }
2914
-
2915
3057
  class XpsApiPart {
2916
3058
  constructor() {
2917
3059
  this.response = new BehaviorSubject(null);
@@ -2955,118 +3097,6 @@ const statusRequestFactoryProvider = {
2955
3097
  useValue: (...args) => new StatusRequest(...args),
2956
3098
  };
2957
3099
 
2958
- var StatusGroups;
2959
- (function (StatusGroups) {
2960
- StatusGroups["troubled"] = "troubled";
2961
- StatusGroups["done"] = "done";
2962
- StatusGroups["invoice"] = "invoice";
2963
- })(StatusGroups || (StatusGroups = {}));
2964
-
2965
- var StatusEnum;
2966
- (function (StatusEnum) {
2967
- StatusEnum["created"] = "created";
2968
- StatusEnum["awaiting"] = "awaiting";
2969
- StatusEnum["processing"] = "processing";
2970
- StatusEnum["authorized"] = "authorized";
2971
- StatusEnum["held"] = "held";
2972
- StatusEnum["done"] = "done";
2973
- StatusEnum["error"] = "error";
2974
- StatusEnum["canceled"] = "canceled";
2975
- })(StatusEnum || (StatusEnum = {}));
2976
-
2977
- class StatusResponse {
2978
- constructor(parameters) {
2979
- if (parameters.errors?.[0]) {
2980
- this.error = {
2981
- code: parameters.errors[0].code.toString(),
2982
- message: parameters.errors[0].message,
2983
- };
2984
- }
2985
- if (!parameters.status) {
2986
- throw new TerminalError(this.error?.message ?? '', this.error?.code.toString() ?? '');
2987
- }
2988
- this.status = {
2989
- statusState: parameters.status.statusData.stateText,
2990
- email: parameters.status.statusData.email,
2991
- webSocketUrl: parameters.status.statusData.webSocketChannelUrl,
2992
- webSocketChannelName: parameters.status.statusData.webSocketChannelName,
2993
- webSocketClientType: parameters.status.statusData.webSocketClientType,
2994
- financeInfo: parameters.status.text.info,
2995
- discount: parameters.status.text.info.discount
2996
- ? Math.abs(Number.parseFloat(parameters.status.text.info.discount?.value ?? ''))
2997
- : null,
2998
- isCancelUser: parameters.status.isCancelUser,
2999
- postMessageStatus: parameters.status.isCancelUser
3000
- ? StatusGroups.troubled
3001
- : parameters.status.group,
3002
- virtualCurrencyAmount: parameters.status.statusData.out,
3003
- backUrlSettings: {
3004
- backUrl: parameters.status.text.backurl,
3005
- backUrlAction: parameters.status.text.backurl_action,
3006
- backUrlCaption: parameters.status.text.backurl_caption,
3007
- returnRegion: parameters.status.return_region,
3008
- },
3009
- additionalBackButton: this.getAdditionalBackButton(parameters.status),
3010
- group: parameters.status.group,
3011
- needToCheck: parameters.status.needToCheck,
3012
- autoRedirect: parameters.status.autoredirect,
3013
- statusMessage: parameters.status.text.state,
3014
- userId: parameters.status.statusData.v1,
3015
- invoice: parameters.status.statusData.invoice,
3016
- pid: parameters.status.statusData.pid,
3017
- projectAmount: this.getProjectAmount(parameters.status),
3018
- titleClass: parameters.status.title_class,
3019
- paymentCountryIso: parameters.status.statusData.payment_country_iso,
3020
- order: parameters.status.text.order,
3021
- };
3022
- if (parameters.form) {
3023
- this.status.userReturnStatus = this.getUserReturnStatus(parameters.form);
3024
- }
3025
- if (this.status.statusState === StatusEnum.done ||
3026
- this.status.statusState === StatusEnum.authorized) {
3027
- this.status.isSuccess = true;
3028
- }
3029
- if (this.status.statusState === StatusEnum.canceled ||
3030
- this.status.isCancelUser) {
3031
- this.status.isCanceled = true;
3032
- }
3033
- }
3034
- getUserReturnStatus(form) {
3035
- const value = form['fix_userReturnStatus']?.value;
3036
- if (value === 'undefined')
3037
- return undefined;
3038
- return value;
3039
- }
3040
- getProjectAmount(status) {
3041
- if (!status.statusData.projectAmount) {
3042
- return;
3043
- }
3044
- const [amount, currency] = status.statusData.projectAmount.split(' ');
3045
- return {
3046
- amount,
3047
- currency,
3048
- };
3049
- }
3050
- getAdditionalBackButton(status) {
3051
- if (!status.text.is_additional_back_url_enabled) {
3052
- return {
3053
- link: '',
3054
- action: '',
3055
- label: '',
3056
- region: '',
3057
- isEnabled: false,
3058
- };
3059
- }
3060
- return {
3061
- link: status.text.additional_back_url_link ?? '',
3062
- action: status.text.additional_back_url_action ?? '',
3063
- label: status.text.additional_back_url_label ?? '',
3064
- region: status.additional_button_return_region ?? '',
3065
- isEnabled: status.text.is_additional_back_url_enabled,
3066
- };
3067
- }
3068
- }
3069
-
3070
3100
  const statusResponseFactoryToken = new InjectionToken('StatusResponse');
3071
3101
  const statusResponseFactoryProvider = {
3072
3102
  provide: statusResponseFactoryToken,
@@ -4543,15 +4573,179 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
4543
4573
  }]
4544
4574
  }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService }, { type: WebsocketStatusService }]; } });
4545
4575
 
4576
+ var TitleClass;
4577
+ (function (TitleClass) {
4578
+ TitleClass["done"] = "done";
4579
+ TitleClass["cancel"] = "cancel";
4580
+ TitleClass["cancelUser"] = "canceluser";
4581
+ })(TitleClass || (TitleClass = {}));
4582
+
4583
+ var SavePaymentMethodStatus;
4584
+ (function (SavePaymentMethodStatus) {
4585
+ SavePaymentMethodStatus["success"] = "success";
4586
+ SavePaymentMethodStatus["failed"] = "failed";
4587
+ })(SavePaymentMethodStatus || (SavePaymentMethodStatus = {}));
4588
+
4589
+ class XpsResponseError extends AppError {
4590
+ constructor(message) {
4591
+ super('XPS response failed' + (message ? `: "${message}".` : '.'));
4592
+ }
4593
+ }
4594
+
4595
+ class SavedPaymentAccountChangesService {
4596
+ constructor(settingsService, secureApi) {
4597
+ this.settingsService = settingsService;
4598
+ this.secureApi = secureApi;
4599
+ this.apiRoute = 'savedmethods/newaccountinfo';
4600
+ this.response = new Subject();
4601
+ }
4602
+ get response$() {
4603
+ return this.response.asObservable();
4604
+ }
4605
+ async request(invoice) {
4606
+ const requestParameters = {
4607
+ access_token: this.settingsService.token,
4608
+ invoice_id: invoice,
4609
+ };
4610
+ return lastValueFrom(this.secureApi
4611
+ .post(this.apiRoute, new URLSearchParams(requestParameters), {
4612
+ headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
4613
+ responseType: 'json',
4614
+ })
4615
+ .pipe(tap((value) => {
4616
+ this.response.next(value);
4617
+ }))).catch((error) => {
4618
+ throw new XpsResponseError(error.message);
4619
+ });
4620
+ }
4621
+ }
4622
+ 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 });
4623
+ SavedPaymentAccountChangesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavedPaymentAccountChangesService, providedIn: 'root' });
4624
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavedPaymentAccountChangesService, decorators: [{
4625
+ type: Injectable,
4626
+ args: [{
4627
+ providedIn: 'root',
4628
+ }]
4629
+ }], ctorParameters: function () { return [{ type: SettingsService }, { type: SecureApiClient }]; } });
4630
+
4631
+ class SavePaymentMethodStatusService {
4632
+ constructor(statusRequestService, listenStatusService, savedPaymentAccountChangesService, nextActionService, checkStatusService) {
4633
+ this.statusRequestService = statusRequestService;
4634
+ this.listenStatusService = listenStatusService;
4635
+ this.savedPaymentAccountChangesService = savedPaymentAccountChangesService;
4636
+ this.nextActionService = nextActionService;
4637
+ this.checkStatusService = checkStatusService;
4638
+ this.statusChecked = false;
4639
+ }
4640
+ async getStatus(params) {
4641
+ if (!this.accountData || !this.status) {
4642
+ this.statusRequestService.setRequestParams(params);
4643
+ this.statusRequestService.request();
4644
+ const statusResponse = await firstValueFrom(this.statusRequestService.response$);
4645
+ this.status = statusResponse.status;
4646
+ this.status.isSavePaymentAccount = true;
4647
+ this.accountData = await this.getPaymentAccountData(params.invoice);
4648
+ }
4649
+ if (this.savingFailedOrCancel(this.status) ||
4650
+ (this.accountData && this.savingSuccessful(this.accountData, this.status))) {
4651
+ return this.status;
4652
+ }
4653
+ if (!this.statusChecked) {
4654
+ this.checkStatus(params);
4655
+ this.status.statusState = StatusEnum.processing;
4656
+ return this.status;
4657
+ }
4658
+ this.statusChecked = false;
4659
+ this.status.statusState = StatusEnum.error;
4660
+ const outStatus = { ...this.status };
4661
+ this.status = null;
4662
+ return outStatus;
4663
+ }
4664
+ checkStatus(params) {
4665
+ if (!this.statusChecked) {
4666
+ this.statusChecked = true;
4667
+ }
4668
+ this.startWaitingStatusUpdates(params.invoice);
4669
+ this.statusRequestService.request();
4670
+ }
4671
+ savingFailedOrCancel(status) {
4672
+ return (status?.titleClass === TitleClass.cancel ||
4673
+ status?.titleClass === TitleClass.cancelUser);
4674
+ }
4675
+ savingSuccessful(accountData, status, checkStatus) {
4676
+ return !!(status?.titleClass === TitleClass.done &&
4677
+ (accountData?.new_account || checkStatus?.isPaymentAccountAttached));
4678
+ }
4679
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
4680
+ getPaymentAccountData(invoice) {
4681
+ return this.savedPaymentAccountChangesService.request(invoice);
4682
+ }
4683
+ startWaitingStatusUpdates(invoice) {
4684
+ if (this.listenStatusSubscription) {
4685
+ this.listenStatusSubscription.unsubscribe();
4686
+ this.listenStatusService.stopListening();
4687
+ }
4688
+ this.listenStatusService.listen(invoice);
4689
+ this.listenStatusSubscription =
4690
+ this.listenStatusService.statusUpdated$.subscribe(({ statusResponse }) => {
4691
+ if (!statusResponse?.status) {
4692
+ return;
4693
+ }
4694
+ this.status = statusResponse.status;
4695
+ void firstValueFrom(this.checkStatusService.response$).then((checkStatusResponse) => {
4696
+ if (checkStatusResponse?.final && statusResponse.status) {
4697
+ this.loadNewPaymentAccountData(statusResponse.status, checkStatusResponse);
4698
+ }
4699
+ });
4700
+ });
4701
+ }
4702
+ loadNewPaymentAccountData(status, checkStatus) {
4703
+ if (!status.invoice) {
4704
+ return;
4705
+ }
4706
+ void this.getPaymentAccountData(status.invoice).then((accountChanges) => {
4707
+ if (accountChanges) {
4708
+ this.accountData = accountChanges;
4709
+ this.handleSavingStatus(status, accountChanges, checkStatus);
4710
+ }
4711
+ });
4712
+ }
4713
+ handleSavingStatus(status, account, checkStatus) {
4714
+ if (this.savingSuccessful(account, status, checkStatus)) {
4715
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.success;
4716
+ }
4717
+ else {
4718
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.failed;
4719
+ }
4720
+ this.listenStatusService.stopListening();
4721
+ this.listenStatusSubscription.unsubscribe();
4722
+ const isSavePaymentMethod = true;
4723
+ this.nextActionService.emitFlowUpdates(new StatusUpdatedAction(status, isSavePaymentMethod, this.savePaymentMethodStatus));
4724
+ }
4725
+ }
4726
+ 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 });
4727
+ SavePaymentMethodStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavePaymentMethodStatusService, providedIn: 'root' });
4728
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavePaymentMethodStatusService, decorators: [{
4729
+ type: Injectable,
4730
+ args: [{
4731
+ providedIn: 'root',
4732
+ }]
4733
+ }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: ListenStatusService }, { type: SavedPaymentAccountChangesService }, { type: NextActionService }, { type: CheckStatusService }]; } });
4734
+
4546
4735
  class StatusService {
4547
- constructor(urlService, statusRequestService, financeDetailsService, listenStatusService, nextActionService) {
4736
+ constructor(urlService, statusRequestService, financeDetailsService, listenStatusService, nextActionService, savePaymentMethodStatusService) {
4548
4737
  this.urlService = urlService;
4549
4738
  this.statusRequestService = statusRequestService;
4550
4739
  this.financeDetailsService = financeDetailsService;
4551
4740
  this.listenStatusService = listenStatusService;
4552
4741
  this.nextActionService = nextActionService;
4742
+ this.savePaymentMethodStatusService = savePaymentMethodStatusService;
4553
4743
  }
4554
4744
  async getStatus(params) {
4745
+ const isSavePaymentMethodMode = !!params?.isSavePaymentAccount;
4746
+ if (isSavePaymentMethodMode) {
4747
+ return this.savePaymentMethodStatusService.getStatus(params);
4748
+ }
4555
4749
  this.statusRequestService.setRequestParams(params);
4556
4750
  this.startWaitingStatusUpdates(params.invoice);
4557
4751
  this.statusRequestService.request();
@@ -4588,14 +4782,14 @@ class StatusService {
4588
4782
  });
4589
4783
  }
4590
4784
  }
4591
- 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 });
4785
+ 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 });
4592
4786
  StatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, providedIn: 'root' });
4593
4787
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, decorators: [{
4594
4788
  type: Injectable,
4595
4789
  args: [{
4596
4790
  providedIn: 'root',
4597
4791
  }]
4598
- }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: FinanceDetailsService }, { type: ListenStatusService }, { type: NextActionService }]; } });
4792
+ }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: FinanceDetailsService }, { type: ListenStatusService }, { type: NextActionService }, { type: SavePaymentMethodStatusService }]; } });
4599
4793
 
4600
4794
  class CreditCardStateService extends EmitDataService {
4601
4795
  }
@@ -4620,12 +4814,6 @@ var ThreeDsStatusTypes;
4620
4814
  ThreeDsStatusTypes["collectDfp"] = "collect_dfp";
4621
4815
  })(ThreeDsStatusTypes || (ThreeDsStatusTypes = {}));
4622
4816
 
4623
- class XpsResponseError extends AppError {
4624
- constructor(message) {
4625
- super('XPS response failed' + (message ? `: "${message}".` : '.'));
4626
- }
4627
- }
4628
-
4629
4817
  class StatusThreeDsRequest {
4630
4818
  constructor(token, threeDsId) {
4631
4819
  this.access_token = token;
@@ -5073,6 +5261,7 @@ class PaymentService {
5073
5261
  this.destroy$ = new Subject();
5074
5262
  this.formDestroy$ = new Subject();
5075
5263
  this.formFieldsStatusSubject = new BehaviorSubject(null);
5264
+ this.isSavingMethodMode = false;
5076
5265
  }
5077
5266
  async initialize(config) {
5078
5267
  this.destroy$ = new Subject();
@@ -5098,9 +5287,12 @@ class PaymentService {
5098
5287
  this.emitFormFieldsStatus(this.form);
5099
5288
  return;
5100
5289
  }
5290
+ this.isSavingMethodMode = this.fields.some(({ name, value }) => name === 'savePsAccountOnly' && value === "1" /* XpsBoolean.true */);
5101
5291
  const submitResponse = await this.submitService.request(this.fields, this.form);
5102
5292
  this.data = submitResponse;
5103
- this.emitFinanceDetails(submitResponse.summary);
5293
+ if (!this.isSavingMethodMode) {
5294
+ this.emitFinanceDetails(submitResponse.summary);
5295
+ }
5104
5296
  this.emitFormMessages(submitResponse.messages);
5105
5297
  // Handle 3ds flow
5106
5298
  if (submitResponse.currentCommand === XpsCommand.create) {
@@ -5149,6 +5341,9 @@ class PaymentService {
5149
5341
  signature: this.data.signature ?? '',
5150
5342
  locale: this.data.fields.find((field) => field.name === 'locale')?.value ??
5151
5343
  'en',
5344
+ isSavePaymentAccount: this.isSavingMethodMode
5345
+ ? "1" /* XpsBoolean.true */
5346
+ : "0" /* XpsBoolean.false */,
5152
5347
  };
5153
5348
  return this.statusService.getStatus(params);
5154
5349
  }
@@ -5349,8 +5544,44 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
5349
5544
  }]
5350
5545
  }], ctorParameters: function () { return [{ type: SettingsService }, { type: RefundPolicyService }, { type: SecureConnectionService }, { type: DisclaimerService }]; } });
5351
5546
 
5547
+ class EditSavedMethodsService {
5548
+ constructor(savedMethodsService, settingsService, secureApi) {
5549
+ this.savedMethodsService = savedMethodsService;
5550
+ this.settingsService = settingsService;
5551
+ this.secureApi = secureApi;
5552
+ this.deleteRoute = 'savedmethods/delete';
5553
+ }
5554
+ async deleteSavedMethodRequest(id, type) {
5555
+ const token = this.settingsService.token;
5556
+ const parameters = {
5557
+ access_token: token,
5558
+ id,
5559
+ type,
5560
+ };
5561
+ return lastValueFrom(this.secureApi.post(this.deleteRoute, new URLSearchParams(parameters), {
5562
+ headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
5563
+ responseType: 'json',
5564
+ }))
5565
+ .then(async () => {
5566
+ await this.savedMethodsService.getList(true);
5567
+ return true;
5568
+ })
5569
+ .catch(() => {
5570
+ return false;
5571
+ });
5572
+ }
5573
+ }
5574
+ 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 });
5575
+ EditSavedMethodsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: EditSavedMethodsService, providedIn: 'root' });
5576
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: EditSavedMethodsService, decorators: [{
5577
+ type: Injectable,
5578
+ args: [{
5579
+ providedIn: 'root',
5580
+ }]
5581
+ }], ctorParameters: function () { return [{ type: SavedMethodsService }, { type: SettingsService }, { type: SecureApiClient }]; } });
5582
+
5352
5583
  class CoreLibraryService {
5353
- constructor(settingsService, countryService, paymentMethodsService, savedMethodsService, userBalanceService, paymentConfigService, paymentService, deviceFingerPrintService, financeDetailsService, legalService, statusService, nextActionService, creditCardService, creditCardStateService, formMessagesService) {
5584
+ constructor(settingsService, countryService, paymentMethodsService, savedMethodsService, userBalanceService, paymentConfigService, paymentService, deviceFingerPrintService, financeDetailsService, legalService, statusService, nextActionService, creditCardService, creditCardStateService, formMessagesService, editSavedMethodsService) {
5354
5585
  this.settingsService = settingsService;
5355
5586
  this.countryService = countryService;
5356
5587
  this.paymentMethodsService = paymentMethodsService;
@@ -5366,11 +5597,13 @@ class CoreLibraryService {
5366
5597
  this.creditCardService = creditCardService;
5367
5598
  this.creditCardStateService = creditCardStateService;
5368
5599
  this.formMessagesService = formMessagesService;
5600
+ this.editSavedMethodsService = editSavedMethodsService;
5369
5601
  this.paymentMethods = {
5370
- getList: async () => this.paymentMethodsService.getList(),
5602
+ getList: async (isSaveMethodMode) => this.paymentMethodsService.getList(isSaveMethodMode),
5371
5603
  getQuickMethods: async () => this.paymentMethodsService.getQuickMethods(),
5372
5604
  getSavedMethods: async () => this.savedMethodsService.getList(),
5373
5605
  getUserBalance: async () => this.userBalanceService.getUserBalance(),
5606
+ deleteSavedMethod: async (id, type) => this.editSavedMethodsService.deleteSavedMethodRequest(id, type),
5374
5607
  };
5375
5608
  }
5376
5609
  async init(configuration) {
@@ -5434,14 +5667,14 @@ class CoreLibraryService {
5434
5667
  return this.userBalanceService.getUserBalanceValue();
5435
5668
  }
5436
5669
  }
5437
- 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 });
5670
+ 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 });
5438
5671
  CoreLibraryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, providedIn: 'root' });
5439
5672
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, decorators: [{
5440
5673
  type: Injectable,
5441
5674
  args: [{
5442
5675
  providedIn: 'root',
5443
5676
  }]
5444
- }], 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 }]; } });
5677
+ }], 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 }]; } });
5445
5678
 
5446
5679
  class HttpError extends AppError {
5447
5680
  constructor(error, req) {