@xsolla/payment-client-core 0.2.44 → 0.2.46

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 (87) hide show
  1. package/esm2022/lib/core/agreements-group.const.mjs +17 -0
  2. package/esm2022/lib/core/extended-window.interface.mjs +1 -1
  3. package/esm2022/lib/core/payment/actions/action.interface.mjs +1 -1
  4. package/esm2022/lib/core/payment/actions/next-action.service.mjs +1 -1
  5. package/esm2022/lib/core/payment/field-names.enum.mjs +4 -1
  6. package/esm2022/lib/core/payment/field.interface.mjs +1 -1
  7. package/esm2022/lib/core/payment/finance-details/finance-details.service.mjs +4 -1
  8. package/esm2022/lib/core/payment/initialize-actions/action.interface.mjs +2 -0
  9. package/esm2022/lib/core/payment/initialize-actions/initialize-next-action.service.mjs +40 -0
  10. package/esm2022/lib/core/payment/initialize-actions/initialize-next-actions.mjs +7 -0
  11. package/esm2022/lib/core/payment/initialize-actions/next-action.interface.mjs +2 -0
  12. package/esm2022/lib/core/payment/initialize-actions/special-button/special-button.action.class.mjs +46 -0
  13. package/esm2022/lib/core/payment/initialize-actions/special-button/special-button.action.type.mjs +2 -0
  14. package/esm2022/lib/core/payment/initialized-form.inteface.mjs +1 -1
  15. package/esm2022/lib/core/payment/payment.service.mjs +72 -24
  16. package/esm2022/lib/core/payment/sync/request/sync-request.class.mjs +3 -1
  17. package/esm2022/lib/core/payment/sync/sync.service.mjs +4 -4
  18. package/esm2022/lib/core/payment/xps-error.interface.mjs +1 -1
  19. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay-integration.type.mjs +6 -2
  20. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay-params-builder.service.mjs +90 -0
  21. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay-session.interface.mjs +2 -0
  22. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay.errors.enum.mjs +6 -3
  23. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay.service.mjs +64 -87
  24. package/esm2022/lib/core/sdk-payment-systems/apple-pay/checkout-params.interface.mjs +1 -1
  25. package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/braintree.handler.mjs +80 -0
  26. package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/checkout.handler.mjs +65 -0
  27. package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.abstract.mjs +31 -0
  28. package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.type.mjs +2 -0
  29. package/esm2022/lib/core/sdk-payment-systems/google-pay/check-payment-device-data.interface.mjs +2 -0
  30. package/esm2022/lib/core/sdk-payment-systems/google-pay/google-pay-init-params.interface.mjs +1 -1
  31. package/esm2022/lib/core/sdk-payment-systems/google-pay/google-pay-library.interface.mjs +1 -1
  32. package/esm2022/lib/core/sdk-payment-systems/google-pay/google-pay.service.mjs +70 -59
  33. package/esm2022/lib/core/sdk-payment-systems/google-pay/payment/google-pay-checkout-payment.service.mjs +75 -0
  34. package/esm2022/lib/core/sdk-payment-systems/google-pay/payment/google-pay-instant-payment.service.mjs +121 -0
  35. package/esm2022/lib/core/sdk-payment-systems/google-pay/payment/google-pay-payment-service.interface.mjs +2 -0
  36. package/esm2022/lib/core/sdk-payment-systems/google-pay/updated-price.interface.mjs +2 -0
  37. package/esm2022/lib/core/sdk-payment-systems/sdk-payment-systems-initial-data.interface.mjs +1 -1
  38. package/esm2022/lib/core/sdk-payment-systems/sdk-payment-systems.interface.mjs +1 -1
  39. package/esm2022/lib/core/settings/project.interface.mjs +1 -1
  40. package/esm2022/lib/core-library.module.mjs +18 -1
  41. package/esm2022/lib/core-library.service.mjs +16 -2
  42. package/fesm2022/xsolla-payment-client-core.mjs +920 -336
  43. package/fesm2022/xsolla-payment-client-core.mjs.map +1 -1
  44. package/lib/core/extended-window.interface.d.ts +1 -1
  45. package/lib/core/payment/actions/action.interface.d.ts +2 -2
  46. package/lib/core/payment/actions/next-action.service.d.ts +1 -1
  47. package/lib/core/payment/actions/next-actions.d.ts +1 -1
  48. package/lib/core/payment/field-names.enum.d.ts +4 -1
  49. package/lib/core/payment/field.interface.d.ts +1 -1
  50. package/lib/core/payment/finance-details/finance-details.service.d.ts +1 -0
  51. package/lib/core/payment/initialize-actions/action.interface.d.ts +11 -0
  52. package/lib/core/payment/initialize-actions/initialize-next-action.service.d.ts +16 -0
  53. package/lib/core/payment/initialize-actions/initialize-next-actions.d.ts +5 -0
  54. package/lib/core/payment/initialize-actions/next-action.interface.d.ts +2 -0
  55. package/lib/core/payment/initialize-actions/special-button/special-button.action.class.d.ts +17 -0
  56. package/lib/core/payment/initialize-actions/special-button/special-button.action.type.d.ts +6 -0
  57. package/lib/core/payment/initialized-form.inteface.d.ts +2 -0
  58. package/lib/core/payment/payment.service.d.ts +11 -2
  59. package/lib/core/payment/sync/sync.service.d.ts +1 -1
  60. package/lib/core/payment/xps-error.interface.d.ts +1 -0
  61. package/lib/core/sdk-payment-systems/apple-pay/apple-pay-integration.type.d.ts +5 -1
  62. package/lib/core/sdk-payment-systems/apple-pay/apple-pay-params-builder.service.d.ts +15 -0
  63. package/lib/core/sdk-payment-systems/apple-pay/apple-pay-session.interface.d.ts +135 -0
  64. package/lib/core/sdk-payment-systems/apple-pay/apple-pay.errors.enum.d.ts +5 -2
  65. package/lib/core/sdk-payment-systems/apple-pay/apple-pay.service.d.ts +24 -13
  66. package/lib/core/sdk-payment-systems/apple-pay/checkout-params.interface.d.ts +1 -0
  67. package/lib/core/sdk-payment-systems/apple-pay/session-handlers/braintree.handler.d.ts +16 -0
  68. package/lib/core/sdk-payment-systems/apple-pay/session-handlers/checkout.handler.d.ts +13 -0
  69. package/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.abstract.d.ts +13 -0
  70. package/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.type.d.ts +3 -0
  71. package/lib/core/sdk-payment-systems/google-pay/check-payment-device-data.interface.d.ts +9 -0
  72. package/lib/core/sdk-payment-systems/google-pay/google-pay-init-params.interface.d.ts +6 -0
  73. package/lib/core/sdk-payment-systems/google-pay/google-pay-library.interface.d.ts +170 -52
  74. package/lib/core/sdk-payment-systems/google-pay/google-pay.service.d.ts +18 -10
  75. package/lib/core/sdk-payment-systems/google-pay/payment/google-pay-checkout-payment.service.d.ts +18 -0
  76. package/lib/core/sdk-payment-systems/google-pay/payment/google-pay-instant-payment.service.d.ts +18 -0
  77. package/lib/core/sdk-payment-systems/google-pay/payment/google-pay-payment-service.interface.d.ts +14 -0
  78. package/lib/core/sdk-payment-systems/google-pay/updated-price.interface.d.ts +7 -0
  79. package/lib/core/sdk-payment-systems/sdk-payment-systems-initial-data.interface.d.ts +7 -1
  80. package/lib/core/sdk-payment-systems/sdk-payment-systems.interface.d.ts +1 -1
  81. package/lib/core/settings/project.interface.d.ts +1 -0
  82. package/lib/core-library.service.d.ts +12 -0
  83. package/package.json +1 -1
  84. package/xsolla-payment-client-core-0.2.46.tgz +0 -0
  85. package/esm2022/lib/core/agreementsGroup.const.mjs +0 -17
  86. package/xsolla-payment-client-core-0.2.44.tgz +0 -0
  87. /package/lib/core/{agreementsGroup.const.d.ts → agreements-group.const.d.ts} +0 -0
@@ -1,10 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, Injectable, Inject, Pipe, isDevMode, NgModule } from '@angular/core';
2
+ import { InjectionToken, Injectable, Inject, isDevMode, Pipe, NgModule } from '@angular/core';
3
3
  import { firstValueFrom, lastValueFrom, map, Subject, BehaviorSubject, filter as filter$1, takeUntil, skip, take, of, interval, throwError } from 'rxjs';
4
4
  import * as i1 from '@angular/common/http';
5
5
  import { HttpParams, HttpHeaders, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
6
+ import { UntypedFormGroup, Validators, UntypedFormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
6
7
  import JSEncrypt from 'jsencrypt';
7
- import { UntypedFormGroup, Validators, UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
8
8
  import { filter, map as map$1, tap, debounce, debounceTime, catchError } from 'rxjs/operators';
9
9
  import * as i1$1 from '@angular/router';
10
10
  import { CommonModule } from '@angular/common';
@@ -540,6 +540,7 @@ var FieldNames;
540
540
  FieldNames["description"] = "description";
541
541
  FieldNames["email"] = "email";
542
542
  FieldNames["psEmail"] = "psEmail";
543
+ FieldNames["psAccountCountry"] = "psAccountCountry";
543
544
  FieldNames["bazitemail"] = "bazitemail";
544
545
  FieldNames["euCheck"] = "eu_check";
545
546
  FieldNames["extraCvv"] = "extra_cvv";
@@ -595,6 +596,8 @@ var FieldNames;
595
596
  FieldNames["payInstanceAccountId"] = "payInstanceAccountId";
596
597
  FieldNames["getApplePaySessionUrl"] = "getApplePaySessionUrl";
597
598
  FieldNames["payViaCheckoutUrl"] = "payViaCheckoutUrl";
599
+ FieldNames["googlePayInitData"] = "googlePayInitData";
600
+ FieldNames["googlePayPaymentData"] = "googlePayPaymentData";
598
601
  })(FieldNames || (FieldNames = {}));
599
602
 
600
603
  class SubmitResponse {
@@ -685,6 +688,145 @@ var InputEventName;
685
688
 
686
689
  const googlePayPid = 3431;
687
690
 
691
+ var ErrorTags;
692
+ (function (ErrorTags) {
693
+ ErrorTags["APP"] = "appError";
694
+ ErrorTags["HTTP"] = "httpError";
695
+ ErrorTags["JS"] = "jsError";
696
+ ErrorTags["WS"] = "webSocket";
697
+ ErrorTags["ENCRYPT"] = "encrypt";
698
+ ErrorTags["APPLEPAY"] = "applepay";
699
+ ErrorTags["HEADLESS_UI"] = "headlessUi";
700
+ ErrorTags["GOOGLEPAY"] = "googlepay";
701
+ ErrorTags["PAYTM"] = "paytm";
702
+ })(ErrorTags || (ErrorTags = {}));
703
+
704
+ class TaggedError extends Error {
705
+ constructor(message, tags) {
706
+ super(message);
707
+ this.tags = [];
708
+ this.parentTag = ErrorTags.HEADLESS_UI;
709
+ this.tags = this.childTag
710
+ ? [this.parentTag, this.childTag]
711
+ : [this.parentTag];
712
+ if (tags) {
713
+ const newTags = tags.filter((t, i, arr) => !this.tags.includes(t) && arr.indexOf(t) == i);
714
+ this.tags = [...this.tags, ...newTags];
715
+ }
716
+ }
717
+ }
718
+
719
+ class ElkLoggerService {
720
+ constructor(window, settingsService, http, ngZone) {
721
+ this.window = window;
722
+ this.settingsService = settingsService;
723
+ this.http = http;
724
+ this.ngZone = ngZone;
725
+ this.vendors = new RegExp('node_modules\\/(@angular|zone).*.js$');
726
+ this.stackTrace = this.loadStackTrace();
727
+ }
728
+ handleError(error) {
729
+ this.ngZone.runOutsideAngular(() => {
730
+ if (isDevMode()) {
731
+ console.error(error);
732
+ return;
733
+ }
734
+ this.parseError(error).catch(console.log);
735
+ });
736
+ }
737
+ log(message, tags, extra) {
738
+ const logTags = [ErrorTags.HEADLESS_UI, ...tags];
739
+ if (isDevMode()) {
740
+ console.log(message, tags);
741
+ return;
742
+ }
743
+ const logMessage = {
744
+ additionalInfo: this.getAdditionalInfo(),
745
+ extra,
746
+ message,
747
+ };
748
+ this.sendLog(logMessage, logTags);
749
+ }
750
+ async parseError(error) {
751
+ const errorObj = error instanceof TaggedError
752
+ ? error
753
+ : new TaggedError(error.message || error.toString());
754
+ errorObj.trace = await this.getErrorTrace(errorObj);
755
+ errorObj.additionalInfo = this.getAdditionalInfo();
756
+ const { tags } = errorObj;
757
+ const cleanError = this.removeErrorMetaFields(errorObj);
758
+ this.sendLog(cleanError, tags);
759
+ return errorObj;
760
+ }
761
+ async loadStackTrace() {
762
+ const library = await import('stacktrace-js');
763
+ return library.default;
764
+ }
765
+ async getErrorTrace(error) {
766
+ const stackTrace = await this.stackTrace;
767
+ const stackFramesArr = await stackTrace.fromError(error);
768
+ const filteredFramesArr = stackFramesArr.filter(({ fileName }) => fileName && !this.vendors.test(fileName));
769
+ return filteredFramesArr
770
+ .map((stackFrame) => stackFrame.toString())
771
+ .join('\n');
772
+ }
773
+ getAdditionalInfo() {
774
+ const extractUrlHost = (url) => url.replace(/^https?:\/\/([^/?#]+).*$/i, '$1');
775
+ return {
776
+ location: {
777
+ url: this.window.location.href,
778
+ },
779
+ project: {
780
+ id: this.settingsService.project.id,
781
+ },
782
+ referrer: {
783
+ url: this.window.document.referrer,
784
+ },
785
+ viewport: {
786
+ width: this.window.document.documentElement.clientWidth,
787
+ height: this.window.document.documentElement.clientHeight,
788
+ },
789
+ cdn_address: this.settingsService.settings.cdnUrl
790
+ ? extractUrlHost(this.settingsService.settings.cdnUrl)
791
+ : 'none',
792
+ country: this.settingsService.user.country.value,
793
+ local: this.settingsService.user.country.localized_name,
794
+ };
795
+ }
796
+ removeErrorMetaFields(error) {
797
+ const metaPropList = [
798
+ 'parentTag',
799
+ 'childTag',
800
+ 'RESTRICTED_KEYS_REGEXP',
801
+ 'tags',
802
+ ];
803
+ Object.keys(error).forEach((key) => {
804
+ if (metaPropList.includes(key))
805
+ delete error[key];
806
+ });
807
+ // implementing own 'message' property from prototype
808
+ return { ...error, message: error.message };
809
+ }
810
+ sendLog(message, tags) {
811
+ const url = `https://logs-01.xsolla.com/tag/${tags.join(',')}`;
812
+ firstValueFrom(this.http.post(url, message, {
813
+ headers: new HttpHeaders().set('Content-Type', 'text/plain'),
814
+ responseType: 'text',
815
+ })).catch((err) => console.error('Elk Logger: request error', err));
816
+ }
817
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ElkLoggerService, deps: [{ token: windowToken }, { token: SettingsService }, { token: i1.HttpClient }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); }
818
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ElkLoggerService, providedIn: 'root' }); }
819
+ }
820
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ElkLoggerService, decorators: [{
821
+ type: Injectable,
822
+ args: [{
823
+ providedIn: 'root',
824
+ }]
825
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
826
+ type: Inject,
827
+ args: [windowToken]
828
+ }] }, { type: SettingsService }, { type: i1.HttpClient }, { type: i0.NgZone }] });
829
+
688
830
  const initializeResponseFactoryToken = new InjectionToken('InitializeResponse');
689
831
  const initializeResponseFactoryProvider = {
690
832
  provide: initializeResponseFactoryToken,
@@ -1923,34 +2065,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
1923
2065
  args: [{ providedIn: 'root' }]
1924
2066
  }], ctorParameters: () => [{ type: UnescapeHtmlPipe }] });
1925
2067
 
1926
- var ErrorTags;
1927
- (function (ErrorTags) {
1928
- ErrorTags["APP"] = "appError";
1929
- ErrorTags["HTTP"] = "httpError";
1930
- ErrorTags["JS"] = "jsError";
1931
- ErrorTags["WS"] = "webSocket";
1932
- ErrorTags["ENCRYPT"] = "encrypt";
1933
- ErrorTags["APPLEPAY"] = "applepay";
1934
- ErrorTags["HEADLESS_UI"] = "headlessUi";
1935
- ErrorTags["GOOGLEPAY"] = "googlepay";
1936
- ErrorTags["PAYTM"] = "paytm";
1937
- })(ErrorTags || (ErrorTags = {}));
1938
-
1939
- class TaggedError extends Error {
1940
- constructor(message, tags) {
1941
- super(message);
1942
- this.tags = [];
1943
- this.parentTag = ErrorTags.HEADLESS_UI;
1944
- this.tags = this.childTag
1945
- ? [this.parentTag, this.childTag]
1946
- : [this.parentTag];
1947
- if (tags) {
1948
- const newTags = tags.filter((t, i, arr) => !this.tags.includes(t) && arr.indexOf(t) == i);
1949
- this.tags = [...this.tags, ...newTags];
1950
- }
1951
- }
1952
- }
1953
-
1954
2068
  class EncryptCreditCardError extends TaggedError {
1955
2069
  constructor(message, tags) {
1956
2070
  tags = tags ? [...tags, ErrorTags.ENCRYPT] : [ErrorTags.ENCRYPT];
@@ -2939,6 +3053,8 @@ class SyncRequest extends XpsApiPartRequest {
2939
3053
  this.addXpsParameters({
2940
3054
  ...fieldsValues,
2941
3055
  change_element: changedField.name,
3056
+ fix_command: changedField.javascript?.change?.staticParams?.fix_command ??
3057
+ this.xps_fix_command,
2942
3058
  });
2943
3059
  }
2944
3060
  getFieldsValues(changedField, fields, form) {
@@ -3070,13 +3186,13 @@ class SyncService extends EmitDataService {
3070
3186
  const control = this.form.get(field.name);
3071
3187
  return control?.errors ?? null;
3072
3188
  }
3073
- async request(field) {
3189
+ async request(field, fields, form) {
3074
3190
  const paymentSettingsParams = this.paymentSettingsService.getPaymentSettingsParams(this.paymentConfiguration);
3075
3191
  const requestParams = this.requestFactory({
3076
3192
  token: this.settingsService.token,
3077
3193
  changedField: field,
3078
- fields: this.fields,
3079
- form: this.form,
3194
+ fields: fields ?? this.fields,
3195
+ form: form ?? this.form,
3080
3196
  ...paymentSettingsParams,
3081
3197
  });
3082
3198
  const encryptedRequest = this.encryptCreditCardService.encryptCreditCard(requestParams);
@@ -5149,6 +5265,9 @@ class FinanceDetailsService extends EmitDataService {
5149
5265
  super.emit(financeDetails);
5150
5266
  }
5151
5267
  }
5268
+ getDetailsFromSummary(summary) {
5269
+ return this.summaryFinanceDetailsAdapterService.getFinanceDetails(summary);
5270
+ }
5152
5271
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: FinanceDetailsService, deps: [{ token: SessionService }, { token: SummaryFinanceDetailsAdapterService }, { token: StatusFinanceDetailsAdapterService }], target: i0.ɵɵFactoryTarget.Injectable }); }
5153
5272
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: FinanceDetailsService, providedIn: 'root' }); }
5154
5273
  }
@@ -5368,166 +5487,55 @@ class WsError extends TaggedError {
5368
5487
  }
5369
5488
  }
5370
5489
 
5371
- class ElkLoggerService {
5372
- constructor(window, settingsService, http, ngZone) {
5373
- this.window = window;
5374
- this.settingsService = settingsService;
5375
- this.http = http;
5376
- this.ngZone = ngZone;
5377
- this.vendors = new RegExp('node_modules\\/(@angular|zone).*.js$');
5378
- this.stackTrace = this.loadStackTrace();
5490
+ class CentrifugoWebSocketService {
5491
+ static { this.reconnectionTimeoutIncrementFactor = 2; }
5492
+ static { this.timeoutsMs = {
5493
+ reconnection: 1000,
5494
+ reconnectionMaxDeviation: 1000,
5495
+ }; }
5496
+ constructor(elkLoggerService) {
5497
+ this.elkLoggerService = elkLoggerService;
5498
+ this.type = WebSocketClientType.centrifugo;
5499
+ this.reconnectionTimerId = null;
5500
+ this.isConnectionOpen = false;
5501
+ this.isConnecting = false;
5502
+ this.incomingMessages$ = new Subject();
5503
+ this.successfulReconnectionEventsProxy$ = new Subject();
5379
5504
  }
5380
- handleError(error) {
5381
- this.ngZone.runOutsideAngular(() => {
5382
- if (isDevMode()) {
5383
- console.error(error);
5384
- return;
5385
- }
5386
- this.parseError(error).catch(console.log);
5387
- });
5505
+ async open(url, channel) {
5506
+ if (url === this.url && channel === this.channel) {
5507
+ return;
5508
+ }
5509
+ try {
5510
+ this.url = url;
5511
+ this.channel = channel;
5512
+ await this.createConnection(url, channel);
5513
+ }
5514
+ catch (error) {
5515
+ // @ts-expect-error error is unknown
5516
+ const message = (error?.message || error);
5517
+ const unknownError = new WsError(`unknown websocket error: ${message}`, channel);
5518
+ this.elkLoggerService.handleError(unknownError);
5519
+ }
5388
5520
  }
5389
- log(message, tags, extra) {
5390
- const logTags = [ErrorTags.HEADLESS_UI, ...tags];
5391
- if (isDevMode()) {
5392
- console.log(message, tags);
5521
+ close() {
5522
+ this.clearReconnectionTimer();
5523
+ if (!this.isConnectionOpen) {
5393
5524
  return;
5394
5525
  }
5395
- const logMessage = {
5396
- additionalInfo: this.getAdditionalInfo(),
5397
- extra,
5398
- message,
5399
- };
5400
- this.sendLog(logMessage, logTags);
5526
+ this.connection.disconnect();
5401
5527
  }
5402
- async parseError(error) {
5403
- const errorObj = error instanceof TaggedError
5404
- ? error
5405
- : new TaggedError(error.message || error.toString());
5406
- errorObj.trace = await this.getErrorTrace(errorObj);
5407
- errorObj.additionalInfo = this.getAdditionalInfo();
5408
- const { tags } = errorObj;
5409
- const cleanError = this.removeErrorMetaFields(errorObj);
5410
- this.sendLog(cleanError, tags);
5411
- return errorObj;
5528
+ get messages$() {
5529
+ return (this.incomingMessages$
5530
+ .asObservable()
5531
+ // event don't respect type from argument, it's weird
5532
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
5533
+ .pipe(map$1((event) => event.data)));
5412
5534
  }
5413
- async loadStackTrace() {
5414
- const library = await import('stacktrace-js');
5415
- return library.default;
5416
- }
5417
- async getErrorTrace(error) {
5418
- const stackTrace = await this.stackTrace;
5419
- const stackFramesArr = await stackTrace.fromError(error);
5420
- const filteredFramesArr = stackFramesArr.filter(({ fileName }) => fileName && !this.vendors.test(fileName));
5421
- return filteredFramesArr
5422
- .map((stackFrame) => stackFrame.toString())
5423
- .join('\n');
5424
- }
5425
- getAdditionalInfo() {
5426
- const extractUrlHost = (url) => url.replace(/^https?:\/\/([^/?#]+).*$/i, '$1');
5427
- return {
5428
- location: {
5429
- url: this.window.location.href,
5430
- },
5431
- project: {
5432
- id: this.settingsService.project.id,
5433
- },
5434
- referrer: {
5435
- url: this.window.document.referrer,
5436
- },
5437
- viewport: {
5438
- width: this.window.document.documentElement.clientWidth,
5439
- height: this.window.document.documentElement.clientHeight,
5440
- },
5441
- cdn_address: this.settingsService.settings.cdnUrl
5442
- ? extractUrlHost(this.settingsService.settings.cdnUrl)
5443
- : 'none',
5444
- country: this.settingsService.user.country.value,
5445
- local: this.settingsService.user.country.localized_name,
5446
- };
5447
- }
5448
- removeErrorMetaFields(error) {
5449
- const metaPropList = [
5450
- 'parentTag',
5451
- 'childTag',
5452
- 'RESTRICTED_KEYS_REGEXP',
5453
- 'tags',
5454
- ];
5455
- Object.keys(error).forEach((key) => {
5456
- if (metaPropList.includes(key))
5457
- delete error[key];
5458
- });
5459
- // implementing own 'message' property from prototype
5460
- return { ...error, message: error.message };
5461
- }
5462
- sendLog(message, tags) {
5463
- const url = `https://logs-01.xsolla.com/tag/${tags.join(',')}`;
5464
- firstValueFrom(this.http.post(url, message, {
5465
- headers: new HttpHeaders().set('Content-Type', 'text/plain'),
5466
- responseType: 'text',
5467
- })).catch((err) => console.error('Elk Logger: request error', err));
5468
- }
5469
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ElkLoggerService, deps: [{ token: windowToken }, { token: SettingsService }, { token: i1.HttpClient }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); }
5470
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ElkLoggerService, providedIn: 'root' }); }
5471
- }
5472
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ElkLoggerService, decorators: [{
5473
- type: Injectable,
5474
- args: [{
5475
- providedIn: 'root',
5476
- }]
5477
- }], ctorParameters: () => [{ type: undefined, decorators: [{
5478
- type: Inject,
5479
- args: [windowToken]
5480
- }] }, { type: SettingsService }, { type: i1.HttpClient }, { type: i0.NgZone }] });
5481
-
5482
- class CentrifugoWebSocketService {
5483
- static { this.reconnectionTimeoutIncrementFactor = 2; }
5484
- static { this.timeoutsMs = {
5485
- reconnection: 1000,
5486
- reconnectionMaxDeviation: 1000,
5487
- }; }
5488
- constructor(elkLoggerService) {
5489
- this.elkLoggerService = elkLoggerService;
5490
- this.type = WebSocketClientType.centrifugo;
5491
- this.reconnectionTimerId = null;
5492
- this.isConnectionOpen = false;
5493
- this.isConnecting = false;
5494
- this.incomingMessages$ = new Subject();
5495
- this.successfulReconnectionEventsProxy$ = new Subject();
5496
- }
5497
- async open(url, channel) {
5498
- if (url === this.url && channel === this.channel) {
5499
- return;
5500
- }
5501
- try {
5502
- this.url = url;
5503
- this.channel = channel;
5504
- await this.createConnection(url, channel);
5505
- }
5506
- catch (error) {
5507
- // @ts-expect-error error is unknown
5508
- const message = (error?.message || error);
5509
- const unknownError = new WsError(`unknown websocket error: ${message}`, channel);
5510
- this.elkLoggerService.handleError(unknownError);
5511
- }
5512
- }
5513
- close() {
5514
- this.clearReconnectionTimer();
5515
- if (!this.isConnectionOpen) {
5516
- return;
5517
- }
5518
- this.connection.disconnect();
5519
- }
5520
- get messages$() {
5521
- return (this.incomingMessages$
5522
- .asObservable()
5523
- // event don't respect type from argument, it's weird
5524
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
5525
- .pipe(map$1((event) => event.data)));
5526
- }
5527
- subscribeOnSuccessfulReconnection(next) {
5528
- return this.successfulReconnectionEventsProxy$
5529
- .asObservable()
5530
- .subscribe(next);
5535
+ subscribeOnSuccessfulReconnection(next) {
5536
+ return this.successfulReconnectionEventsProxy$
5537
+ .asObservable()
5538
+ .subscribe(next);
5531
5539
  }
5532
5540
  clearReconnectionTimer() {
5533
5541
  if (this.reconnectionTimerId) {
@@ -6117,6 +6125,88 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
6117
6125
  }]
6118
6126
  }] });
6119
6127
 
6128
+ class InitializeSpecialButtonActionCreator {
6129
+ constructor(elkLoggerService) {
6130
+ this.elkLoggerService = elkLoggerService;
6131
+ this.type = 'special_button';
6132
+ this.pids = [googlePayPid];
6133
+ this.sdkPaymentMethodsName = new Map([
6134
+ [googlePayPid, 'google-pay'],
6135
+ ]);
6136
+ }
6137
+ getActionData(response) {
6138
+ return {
6139
+ type: this.type,
6140
+ data: {
6141
+ buttonName: this.getPaymentMethodName(response.paymentForm?.pid),
6142
+ },
6143
+ };
6144
+ }
6145
+ isSuitable(response) {
6146
+ if (!response.paymentForm)
6147
+ return false;
6148
+ const hasGooglePayInitDataField = response.paymentForm.fields.some((field) => field.name === FieldNames.googlePayInitData);
6149
+ return (this.pids.includes(response.paymentForm.pid) && hasGooglePayInitDataField);
6150
+ }
6151
+ getPaymentMethodName(pid = 0) {
6152
+ const buttonName = this.sdkPaymentMethodsName.get(pid);
6153
+ if (!buttonName) {
6154
+ this.elkLoggerService.log('No special button for provided pid', [ErrorTags.GOOGLEPAY], {
6155
+ pid,
6156
+ });
6157
+ throw new Error('Special button not found');
6158
+ }
6159
+ return buttonName;
6160
+ }
6161
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: InitializeSpecialButtonActionCreator, deps: [{ token: ElkLoggerService }], target: i0.ɵɵFactoryTarget.Injectable }); }
6162
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: InitializeSpecialButtonActionCreator }); }
6163
+ }
6164
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: InitializeSpecialButtonActionCreator, decorators: [{
6165
+ type: Injectable
6166
+ }], ctorParameters: () => [{ type: ElkLoggerService }] });
6167
+
6168
+ const initializeNextActionsToken = new InjectionToken('InitializeNextActions');
6169
+ const initializeNextActions = [
6170
+ InitializeSpecialButtonActionCreator,
6171
+ ];
6172
+
6173
+ class InitializeNextActionService {
6174
+ constructor(initializeNextActionTokens, injector) {
6175
+ this.initializeNextActionTokens = initializeNextActionTokens;
6176
+ this.injector = injector;
6177
+ this.initializeNextActionsList = [];
6178
+ this.fillNextActionsList();
6179
+ }
6180
+ getNextAction(response) {
6181
+ const nextAction = this.findNextAction(response);
6182
+ if (!nextAction)
6183
+ return null;
6184
+ return nextAction.getActionData(response);
6185
+ }
6186
+ fillNextActionsList() {
6187
+ this.initializeNextActionTokens.forEach((nextAction) => {
6188
+ const item = this.injector.get(nextAction);
6189
+ this.initializeNextActionsList.push(item);
6190
+ });
6191
+ }
6192
+ findNextAction(response) {
6193
+ return this.initializeNextActionsList.find((nextAction) => {
6194
+ return nextAction.isSuitable(response);
6195
+ });
6196
+ }
6197
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: InitializeNextActionService, deps: [{ token: initializeNextActionsToken }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
6198
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: InitializeNextActionService, providedIn: 'root' }); }
6199
+ }
6200
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: InitializeNextActionService, decorators: [{
6201
+ type: Injectable,
6202
+ args: [{
6203
+ providedIn: 'root',
6204
+ }]
6205
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
6206
+ type: Inject,
6207
+ args: [initializeNextActionsToken]
6208
+ }] }, { type: i0.Injector }] });
6209
+
6120
6210
  var ThreeDsStatusWebSocketTypes;
6121
6211
  (function (ThreeDsStatusWebSocketTypes) {
6122
6212
  ThreeDsStatusWebSocketTypes["status3DS_changed"] = "status3DS_changed";
@@ -6608,7 +6698,8 @@ class PaymentService {
6608
6698
  get formResponseValue() {
6609
6699
  return this._formResponse$.getValue();
6610
6700
  }
6611
- constructor(initializeService, submitService, syncService, formService, statusService, financeDetailsService, creditCardStateService, nextActionService, controlConfigService, threeDsService, formMessagesService, settingsService, countryService, checkStatusActionCreator, printInstructionService) {
6701
+ constructor(elkLoggerService, initializeService, submitService, syncService, formService, statusService, financeDetailsService, creditCardStateService, nextActionService, initializeNextActionService, controlConfigService, threeDsService, formMessagesService, settingsService, countryService, checkStatusActionCreator, printInstructionService) {
6702
+ this.elkLoggerService = elkLoggerService;
6612
6703
  this.initializeService = initializeService;
6613
6704
  this.submitService = submitService;
6614
6705
  this.syncService = syncService;
@@ -6617,6 +6708,7 @@ class PaymentService {
6617
6708
  this.financeDetailsService = financeDetailsService;
6618
6709
  this.creditCardStateService = creditCardStateService;
6619
6710
  this.nextActionService = nextActionService;
6711
+ this.initializeNextActionService = initializeNextActionService;
6620
6712
  this.controlConfigService = controlConfigService;
6621
6713
  this.threeDsService = threeDsService;
6622
6714
  this.formMessagesService = formMessagesService;
@@ -6661,6 +6753,7 @@ class PaymentService {
6661
6753
  return {
6662
6754
  fields: this.fields.filter((field) => field?.isVisible === "1" /* XpsBoolean.true */),
6663
6755
  isFormAutoSubmitted: isNeedAutoSubmit,
6756
+ nextAction: this.initializeNextActionService.getNextAction(this.data),
6664
6757
  };
6665
6758
  }
6666
6759
  async submit() {
@@ -6692,6 +6785,26 @@ class PaymentService {
6692
6785
  this.syncService.setup(this.form, this.fields, this.config);
6693
6786
  return this.nextActionService.getNextAction(submitResponse);
6694
6787
  }
6788
+ async submitWithFields(fields) {
6789
+ if (!this.form) {
6790
+ this.elkLoggerService.log('submit error: trying to submit with no form', [
6791
+ ErrorTags.GOOGLEPAY,
6792
+ ]);
6793
+ throw new Error('form is empty!');
6794
+ }
6795
+ this.isSavingMethodMode = this.fields.some(({ name, value }) => name === 'savePsAccountOnly' && value === "1" /* XpsBoolean.true */);
6796
+ const submitResponse = await this.submitService.request(fields ?? this.fields, this.form, this.config);
6797
+ this.data = submitResponse;
6798
+ this.emitFormResponse(this.data);
6799
+ if (!this.isSavingMethodMode) {
6800
+ this.emitFinanceDetails(submitResponse.summary);
6801
+ }
6802
+ this.emitFormMessages(submitResponse.messages);
6803
+ this.fields = this.getFields();
6804
+ this.form = this.formService.createForm(this.fields);
6805
+ this.syncService.setup(this.form, this.fields, this.config);
6806
+ return submitResponse;
6807
+ }
6695
6808
  getFields() {
6696
6809
  if (this.data instanceof SubmitResponse) {
6697
6810
  return this.data.fields ?? [];
@@ -6709,17 +6822,21 @@ class PaymentService {
6709
6822
  status: control.status,
6710
6823
  };
6711
6824
  }
6712
- getInitialDataForSdkPaymentSystems() {
6713
- if (!isSubmitResponse(this.data)) {
6825
+ async getInitialDataForSdkPaymentSystems() {
6826
+ if (!this.data) {
6714
6827
  throw new Error('Should submit form first');
6715
6828
  }
6716
- return {
6717
- data: this.data.parameters.checkout.data.data,
6829
+ const sdkPaymentData = this.getSdkPaymentDataFromResponse(this.data);
6830
+ return Promise.resolve({
6831
+ data: sdkPaymentData.checkoutData,
6718
6832
  sandbox: this.settingsService.isSandboxMode()
6719
6833
  ? "1" /* XpsBoolean.true */
6720
6834
  : "0" /* XpsBoolean.false */,
6721
6835
  country: this.countryService.getCountry(),
6722
- };
6836
+ fields: sdkPaymentData.fields,
6837
+ submitResponse: isSubmitResponse(this.data) ? this.data : null,
6838
+ summary: sdkPaymentData.summary,
6839
+ });
6723
6840
  }
6724
6841
  getQrCode() {
6725
6842
  if (!isSubmitResponse(this.data)) {
@@ -6771,6 +6888,9 @@ class PaymentService {
6771
6888
  }
6772
6889
  return this.syncService.validate(field);
6773
6890
  }
6891
+ async calculateField(changedField, fields) {
6892
+ return this.syncService.request(changedField, fields, new FormGroup({}));
6893
+ }
6774
6894
  runThreeDs() {
6775
6895
  if (!isSubmitResponse(this.data)) {
6776
6896
  throw new Error('Should submit form first');
@@ -6975,7 +7095,21 @@ class PaymentService {
6975
7095
  (visibleFields.length === 0 &&
6976
7096
  suitablePids.includes(response.paymentForm.pid)));
6977
7097
  }
6978
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: PaymentService, deps: [{ token: InitializeService }, { token: SubmitService }, { token: SyncService }, { token: FormService }, { token: StatusService }, { token: FinanceDetailsService }, { token: CreditCardStateService }, { token: NextActionService }, { token: ControlConfigService }, { token: ThreeDsService }, { token: FormMessagesService }, { token: SettingsService }, { token: CountryService }, { token: CheckStatusActionCreator }, { token: PrintInstructionService }], target: i0.ɵɵFactoryTarget.Injectable }); }
7098
+ getSdkPaymentDataFromResponse(data) {
7099
+ if (isSubmitResponse(data)) {
7100
+ return {
7101
+ checkoutData: data.parameters.checkout.data.data,
7102
+ fields: data.fields,
7103
+ summary: data.summary,
7104
+ };
7105
+ }
7106
+ return {
7107
+ checkoutData: null,
7108
+ fields: data.paymentForm?.fields ?? [],
7109
+ summary: data.paymentForm?.summary ?? null,
7110
+ };
7111
+ }
7112
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: PaymentService, deps: [{ token: ElkLoggerService }, { token: InitializeService }, { token: SubmitService }, { token: SyncService }, { token: FormService }, { token: StatusService }, { token: FinanceDetailsService }, { token: CreditCardStateService }, { token: NextActionService }, { token: InitializeNextActionService }, { token: ControlConfigService }, { token: ThreeDsService }, { token: FormMessagesService }, { token: SettingsService }, { token: CountryService }, { token: CheckStatusActionCreator }, { token: PrintInstructionService }], target: i0.ɵɵFactoryTarget.Injectable }); }
6979
7113
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: PaymentService, providedIn: 'root' }); }
6980
7114
  }
6981
7115
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: PaymentService, decorators: [{
@@ -6983,7 +7117,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
6983
7117
  args: [{
6984
7118
  providedIn: 'root',
6985
7119
  }]
6986
- }], ctorParameters: () => [{ type: InitializeService }, { type: SubmitService }, { type: SyncService }, { type: FormService }, { type: StatusService }, { type: FinanceDetailsService }, { type: CreditCardStateService }, { type: NextActionService }, { type: ControlConfigService }, { type: ThreeDsService }, { type: FormMessagesService }, { type: SettingsService }, { type: CountryService }, { type: CheckStatusActionCreator }, { type: PrintInstructionService }] });
7120
+ }], ctorParameters: () => [{ type: ElkLoggerService }, { type: InitializeService }, { type: SubmitService }, { type: SyncService }, { type: FormService }, { type: StatusService }, { type: FinanceDetailsService }, { type: CreditCardStateService }, { type: NextActionService }, { type: InitializeNextActionService }, { type: ControlConfigService }, { type: ThreeDsService }, { type: FormMessagesService }, { type: SettingsService }, { type: CountryService }, { type: CheckStatusActionCreator }, { type: PrintInstructionService }] });
6987
7121
 
6988
7122
  const euCountries = new Set([
6989
7123
  'AT',
@@ -7653,7 +7787,12 @@ class CoreLibraryService {
7653
7787
  deleteSavedMethod: async (id, type) => this.editSavedMethodsService.deleteSavedMethodRequest(id, type),
7654
7788
  };
7655
7789
  this.sdkPaymentSystems = {
7656
- getInitialData: () => this.paymentService.getInitialDataForSdkPaymentSystems(),
7790
+ getInitialData: async () => this.paymentService.getInitialDataForSdkPaymentSystems(),
7791
+ };
7792
+ this.finance = {
7793
+ getDetailsFromSummary: (summary) => {
7794
+ return this.financeDetailsService.getDetailsFromSummary(summary);
7795
+ },
7657
7796
  };
7658
7797
  }
7659
7798
  async init(configuration) {
@@ -7666,6 +7805,12 @@ class CoreLibraryService {
7666
7805
  async getStatus(url) {
7667
7806
  return this.statusService.getStatusWithUrlSearchParams(url);
7668
7807
  }
7808
+ async calculateField(changedField, fields) {
7809
+ return this.paymentService.calculateField(changedField, fields);
7810
+ }
7811
+ async submit(fields) {
7812
+ return this.paymentService.submitWithFields(fields);
7813
+ }
7669
7814
  sendAnalytics(action, type, options) {
7670
7815
  this.userBehaviourAnalyticsService.send(action, type, options);
7671
7816
  }
@@ -7752,6 +7897,9 @@ class CoreLibraryService {
7752
7897
  get formResponseValue() {
7753
7898
  return this.paymentService.formResponseValue;
7754
7899
  }
7900
+ get projectSettings() {
7901
+ return this.settingsService.project;
7902
+ }
7755
7903
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", 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 }, { token: UserBehaviourAnalyticsService }, { token: PerformanceService }, { token: CombinedPaymentMethodsService }, { token: CountriesApiService }, { token: SendInstructionService }, { token: ScriptTrackerService }], target: i0.ɵɵFactoryTarget.Injectable }); }
7756
7904
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryService, providedIn: 'root' }); }
7757
7905
  }
@@ -7916,6 +8064,176 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
7916
8064
  }]
7917
8065
  }] });
7918
8066
 
8067
+ const applePayVersion = 3;
8068
+
8069
+ var ApplePayErrors;
8070
+ (function (ApplePayErrors) {
8071
+ ApplePayErrors["paymentError"] = "Apple Pay: payment error";
8072
+ ApplePayErrors["deviceIsNotCapableError"] = "Apple Pay: device is not capable";
8073
+ ApplePayErrors["cancelled"] = "Apple Pay: payment cancelled";
8074
+ ApplePayErrors["merchantValidationError"] = "Apple Pay: merchant validation error";
8075
+ ApplePayErrors["braintreeInitializeError"] = "Apple Pay: Braintree library is not initialized";
8076
+ })(ApplePayErrors || (ApplePayErrors = {}));
8077
+
8078
+ class ApplePaySessionHandlerAbstract {
8079
+ constructor() {
8080
+ this.payment = new Subject();
8081
+ this._errorSubject = new Subject();
8082
+ }
8083
+ get error$() {
8084
+ return this._errorSubject.asObservable();
8085
+ }
8086
+ get payment$() {
8087
+ return this.payment.asObservable();
8088
+ }
8089
+ emitError(error) {
8090
+ this._errorSubject.next(error);
8091
+ }
8092
+ buildPaymentRequest(params) {
8093
+ return {
8094
+ total: {
8095
+ label: params.totalLabel,
8096
+ amount: params.totalAmount,
8097
+ },
8098
+ currencyCode: params.currencyCode,
8099
+ countryCode: params.countryCode,
8100
+ merchantCapabilities: params.merchantCapabilities,
8101
+ requiredBillingContactFields: params.requiredBillingContactFields,
8102
+ requiredShippingContactFields: params.requiredShippingContactFields,
8103
+ supportedNetworks: params.supportedNetworks,
8104
+ };
8105
+ }
8106
+ }
8107
+
8108
+ class BraintreeHandler extends ApplePaySessionHandlerAbstract {
8109
+ constructor(window, elkLoggerService) {
8110
+ super();
8111
+ this.window = window;
8112
+ this.elkLoggerService = elkLoggerService;
8113
+ this.paymentClient = null;
8114
+ }
8115
+ setClient(client) {
8116
+ this.paymentClient = client;
8117
+ }
8118
+ startSession(params, iframeIntegrationEnabled) {
8119
+ if (!this.paymentClient) {
8120
+ console.error(ApplePayErrors.braintreeInitializeError);
8121
+ this.elkLoggerService.log(ApplePayErrors.braintreeInitializeError, [
8122
+ ErrorTags.APPLEPAY,
8123
+ ]);
8124
+ return;
8125
+ }
8126
+ const request = this.buildPaymentRequest(params);
8127
+ const applePayRequest = this.paymentClient.createPaymentRequest(request);
8128
+ const session = new this.window.ApplePaySession(applePayVersion, applePayRequest);
8129
+ session.onvalidatemerchant = (event) => {
8130
+ const validationParams = {
8131
+ validationURL: event.validationURL,
8132
+ displayName: params.totalLabel,
8133
+ };
8134
+ if (iframeIntegrationEnabled && params.topLevelDomain) {
8135
+ // @ts-expect-error unknown property
8136
+ validationParams.domainName = params.topLevelDomain;
8137
+ }
8138
+ this.paymentClient
8139
+ ?.performValidation(validationParams)
8140
+ .then((merchantSession) => {
8141
+ session.completeMerchantValidation(merchantSession);
8142
+ })
8143
+ .catch((error) => {
8144
+ console.error(ApplePayErrors.merchantValidationError, error);
8145
+ session.abort();
8146
+ });
8147
+ };
8148
+ session.onpaymentauthorized = (event) => {
8149
+ this.paymentClient
8150
+ ?.tokenize({ token: event.payment.token })
8151
+ .then((response) => {
8152
+ this.payment.next(JSON.stringify({
8153
+ token: response?.nonce ?? '',
8154
+ email: event.payment.billingContact?.emailAddress ?? null,
8155
+ postalCode: event.payment.billingContact?.postalCode ?? null,
8156
+ }));
8157
+ session.completePayment(this.window.ApplePaySession.STATUS_SUCCESS);
8158
+ })
8159
+ .catch((error) => {
8160
+ console.error('Apple Pay: Tokenization error', error);
8161
+ session.completePayment(this.window.ApplePaySession.STATUS_FAILURE);
8162
+ });
8163
+ };
8164
+ session.oncancel = () => {
8165
+ console.error(ApplePayErrors.cancelled);
8166
+ this.emitError(ApplePayErrors.cancelled);
8167
+ };
8168
+ session.begin();
8169
+ }
8170
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: BraintreeHandler, deps: [{ token: windowToken }, { token: ElkLoggerService }], target: i0.ɵɵFactoryTarget.Injectable }); }
8171
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: BraintreeHandler }); }
8172
+ }
8173
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: BraintreeHandler, decorators: [{
8174
+ type: Injectable
8175
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
8176
+ type: Inject,
8177
+ args: [windowToken]
8178
+ }] }, { type: ElkLoggerService }] });
8179
+
8180
+ class CheckoutHandler extends ApplePaySessionHandlerAbstract {
8181
+ constructor(window, http) {
8182
+ super();
8183
+ this.window = window;
8184
+ this.http = http;
8185
+ }
8186
+ startSession(params, iframeIntegrationEnabled) {
8187
+ const request = this.buildPaymentRequest(params);
8188
+ const session = new this.window.ApplePaySession(applePayVersion, request);
8189
+ session.onvalidatemerchant = (event) => {
8190
+ const validationParams = {
8191
+ validationURL: event.validationURL,
8192
+ accountId: params.payInstanceAccountId,
8193
+ isSandbox: params.isSandbox,
8194
+ };
8195
+ if (iframeIntegrationEnabled && params.topLevelDomain) {
8196
+ // @ts-expect-error unknown property
8197
+ validationParams.domainName = params.topLevelDomain;
8198
+ }
8199
+ this.http
8200
+ .post(params.getApplePaySessionUrl, JSON.stringify(validationParams), {
8201
+ headers: new HttpHeaders().set('Content-Type', 'application/json'),
8202
+ })
8203
+ .subscribe({
8204
+ next: (response) => {
8205
+ session.completeMerchantValidation(response.merchantSession);
8206
+ },
8207
+ error: (error) => {
8208
+ console.error(ApplePayErrors.merchantValidationError, error);
8209
+ session.abort();
8210
+ },
8211
+ });
8212
+ };
8213
+ session.onpaymentauthorized = (event) => {
8214
+ this.payment.next(JSON.stringify({
8215
+ token: event.payment.token ?? '',
8216
+ email: event.payment.billingContact?.emailAddress ?? null,
8217
+ postalCode: event.payment.billingContact?.postalCode ?? null,
8218
+ }));
8219
+ session.completePayment(this.window.ApplePaySession.STATUS_SUCCESS);
8220
+ };
8221
+ session.oncancel = () => {
8222
+ console.error(ApplePayErrors.cancelled);
8223
+ this.emitError(ApplePayErrors.cancelled);
8224
+ };
8225
+ session.begin();
8226
+ }
8227
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CheckoutHandler, deps: [{ token: windowToken }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
8228
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CheckoutHandler }); }
8229
+ }
8230
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CheckoutHandler, decorators: [{
8231
+ type: Injectable
8232
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
8233
+ type: Inject,
8234
+ args: [windowToken]
8235
+ }] }, { type: i1.HttpClient }] });
8236
+
7919
8237
  class CoreLibraryModule {
7920
8238
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
7921
8239
  static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryModule, imports: [HttpClientModule, FormModule, PipesModule] }); }
@@ -7945,11 +8263,18 @@ class CoreLibraryModule {
7945
8263
  provide: nextActionsToken,
7946
8264
  useValue: nextActions,
7947
8265
  },
8266
+ {
8267
+ provide: initializeNextActionsToken,
8268
+ useValue: initializeNextActions,
8269
+ },
7948
8270
  ...nextActions,
8271
+ ...initializeNextActions,
7949
8272
  ...flowUpdateNextActions,
7950
8273
  printInstructionRequestFactoryProvider,
7951
8274
  sendInstructionRequestFactoryProvider,
7952
8275
  sendInstructionStatusResponseFactoryProvider,
8276
+ BraintreeHandler,
8277
+ CheckoutHandler,
7953
8278
  ], imports: [HttpClientModule, FormModule, PipesModule] }); }
7954
8279
  }
7955
8280
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryModule, decorators: [{
@@ -7982,11 +8307,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
7982
8307
  provide: nextActionsToken,
7983
8308
  useValue: nextActions,
7984
8309
  },
8310
+ {
8311
+ provide: initializeNextActionsToken,
8312
+ useValue: initializeNextActions,
8313
+ },
7985
8314
  ...nextActions,
8315
+ ...initializeNextActions,
7986
8316
  ...flowUpdateNextActions,
7987
8317
  printInstructionRequestFactoryProvider,
7988
8318
  sendInstructionRequestFactoryProvider,
7989
8319
  sendInstructionStatusResponseFactoryProvider,
8320
+ BraintreeHandler,
8321
+ CheckoutHandler,
7990
8322
  ],
7991
8323
  }]
7992
8324
  }] });
@@ -8069,6 +8401,195 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8069
8401
  args: [windowToken]
8070
8402
  }] }] });
8071
8403
 
8404
+ class GooglePayCheckoutPaymentService {
8405
+ constructor(paymentSystemProcessingService) {
8406
+ this.paymentSystemProcessingService = paymentSystemProcessingService;
8407
+ this.checkout = null;
8408
+ }
8409
+ preparePayment({ initParams, checkDeviceData, }) {
8410
+ if (!initParams || !checkDeviceData.base64checkoutData)
8411
+ return null;
8412
+ this.initParams = initParams;
8413
+ this.checkout =
8414
+ this.paymentSystemProcessingService.getDecodedCheckout(checkDeviceData.base64checkoutData);
8415
+ if (!this.checkout)
8416
+ return null;
8417
+ const checkoutData = this.checkout.request.form.fields;
8418
+ const paymentDataRequest = JSON.parse(checkoutData.paymentDataRequest);
8419
+ const isReadyToPayRequest = JSON.parse(checkoutData.isReadyToPayRequest);
8420
+ const result = { paymentDataRequest, isReadyToPayRequest };
8421
+ if (checkoutData.amexCardNotification) {
8422
+ result.amexCardNotification = JSON.parse(checkoutData.amexCardNotification);
8423
+ }
8424
+ return result;
8425
+ }
8426
+ getPaymentRequest() {
8427
+ if (!this.checkout)
8428
+ return null;
8429
+ const checkoutData = this.checkout.request.form.fields;
8430
+ const paymentDataRequest = JSON.parse(checkoutData.paymentDataRequest);
8431
+ paymentDataRequest.transactionInfo = {
8432
+ currencyCode: checkoutData.currency,
8433
+ totalPriceStatus: 'FINAL',
8434
+ totalPrice: checkoutData.sum?.toString(),
8435
+ countryCode: this.initParams.country.toUpperCase(),
8436
+ };
8437
+ return paymentDataRequest;
8438
+ }
8439
+ getAllowedPaymentMethods() {
8440
+ if (!this.checkout)
8441
+ return [];
8442
+ const paymentDataRequest = JSON.parse(this.checkout.request.form.fields.paymentDataRequest);
8443
+ return paymentDataRequest.allowedPaymentMethods;
8444
+ }
8445
+ handleSuccessfulPayment(response) {
8446
+ if (!this.checkout)
8447
+ return;
8448
+ let returnUrl = this.checkout.request.form.fields.returnSuccessUrl;
8449
+ const data = this.checkout.request.form.fields;
8450
+ returnUrl += `&cpf_number=${data.cpf_number}&descriptor=${data.descriptor}&paymentData=${JSON.stringify(response)}`;
8451
+ this.paymentSystemProcessingService.emitStatusUrl(returnUrl);
8452
+ }
8453
+ handleFailedPayment(error) {
8454
+ if (!this.checkout)
8455
+ return;
8456
+ const statusCode = error?.statusCode;
8457
+ const isStatusCanceled = statusCode && this.isCancelledStatus(statusCode);
8458
+ if (isStatusCanceled)
8459
+ return;
8460
+ const returnUrl = this.checkout.request.form.fields.returnFailUrl;
8461
+ this.paymentSystemProcessingService.emitStatusUrl(returnUrl);
8462
+ }
8463
+ isCancelledStatus(statusCode) {
8464
+ return statusCode.toLowerCase() === 'canceled';
8465
+ }
8466
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayCheckoutPaymentService, deps: [{ token: PaymentSystemProcessingService }], target: i0.ɵɵFactoryTarget.Injectable }); }
8467
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayCheckoutPaymentService, providedIn: 'root' }); }
8468
+ }
8469
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayCheckoutPaymentService, decorators: [{
8470
+ type: Injectable,
8471
+ args: [{
8472
+ providedIn: 'root',
8473
+ }]
8474
+ }], ctorParameters: () => [{ type: PaymentSystemProcessingService }] });
8475
+
8476
+ class GooglePayInstantPaymentService {
8477
+ constructor(summaryFinanceDetailsAdapterService) {
8478
+ this.summaryFinanceDetailsAdapterService = summaryFinanceDetailsAdapterService;
8479
+ this.googleInitData = null;
8480
+ }
8481
+ preparePayment({ initParams, checkDeviceData, }) {
8482
+ if (!initParams)
8483
+ return null;
8484
+ this.initParams = initParams;
8485
+ this.googleInitData = this.extractGoogleInitData(initParams.fields);
8486
+ if (!this.googleInitData)
8487
+ return null;
8488
+ const displayItems = checkDeviceData.summary
8489
+ ? this.getItemsTaxes(checkDeviceData.summary)
8490
+ : [];
8491
+ this.googleInitData.paymentDataRequest = {
8492
+ ...this.googleInitData.paymentDataRequest,
8493
+ transactionInfo: {
8494
+ ...this.googleInitData.paymentDataRequest.transactionInfo,
8495
+ totalPriceStatus: 'ESTIMATED',
8496
+ totalPrice: this.googleInitData.paymentDataRequest.transactionInfo.totalPrice?.toString(),
8497
+ countryCode: initParams.country.toUpperCase() ??
8498
+ this.googleInitData.paymentDataRequest.transactionInfo.countryCode?.toUpperCase(),
8499
+ totalPriceLabel: this.googleInitData.paymentDataRequest.transactionInfo
8500
+ .totalPriceLabel ?? 'Total',
8501
+ displayItems,
8502
+ },
8503
+ shippingAddressRequired: true,
8504
+ callbackIntents: ['SHIPPING_ADDRESS', 'PAYMENT_AUTHORIZATION'],
8505
+ };
8506
+ return this.googleInitData;
8507
+ }
8508
+ getPaymentRequest() {
8509
+ if (!this.googleInitData)
8510
+ return null;
8511
+ return {
8512
+ ...this.googleInitData.paymentDataRequest,
8513
+ transactionInfo: {
8514
+ ...this.googleInitData.paymentDataRequest.transactionInfo,
8515
+ totalPriceStatus: 'ESTIMATED',
8516
+ totalPrice: this.googleInitData.paymentDataRequest.transactionInfo.totalPrice?.toString(),
8517
+ countryCode: this.initParams.country.toUpperCase() ??
8518
+ this.googleInitData.paymentDataRequest.transactionInfo.countryCode?.toUpperCase(),
8519
+ },
8520
+ shippingAddressRequired: true,
8521
+ callbackIntents: ['SHIPPING_ADDRESS', 'PAYMENT_AUTHORIZATION'],
8522
+ };
8523
+ }
8524
+ getAllowedPaymentMethods() {
8525
+ if (!this.googleInitData)
8526
+ return [];
8527
+ return this.googleInitData.paymentDataRequest.allowedPaymentMethods;
8528
+ }
8529
+ extractGoogleInitData(fields) {
8530
+ try {
8531
+ const googlePayInitData = fields.filter((field) => field.name === FieldNames.googlePayInitData)[0]?.value;
8532
+ const data = JSON.parse(googlePayInitData ?? null);
8533
+ return data;
8534
+ }
8535
+ catch (error) {
8536
+ return null;
8537
+ }
8538
+ }
8539
+ getItemsTaxes(summary) {
8540
+ const financeResponse = this.summaryFinanceDetailsAdapterService.getFinanceDetails(summary);
8541
+ const newCartPricing = financeResponse.cartSummary;
8542
+ if (!newCartPricing.total?.money?.amount || !financeResponse.finance) {
8543
+ return [];
8544
+ }
8545
+ const newPrice = {
8546
+ total: this.getTotalAmount(financeResponse.finance),
8547
+ subtotalDetails: newCartPricing.subtotalDetails,
8548
+ subtotalPayment: newCartPricing.subtotalPayment,
8549
+ totalDetails: newCartPricing.totalDetails,
8550
+ };
8551
+ const displayItems = [];
8552
+ if (newPrice.subtotalPayment?.money?.amount) {
8553
+ displayItems.push({
8554
+ label: newPrice.subtotalPayment.title || 'Subtotal',
8555
+ amount: newPrice.subtotalPayment.money?.amount.toString(),
8556
+ });
8557
+ }
8558
+ let paymentsDetails = [];
8559
+ if (newPrice.subtotalDetails?.length) {
8560
+ paymentsDetails = newPrice.subtotalDetails;
8561
+ }
8562
+ if (newPrice.totalDetails?.length) {
8563
+ paymentsDetails = paymentsDetails.concat(newPrice.totalDetails);
8564
+ }
8565
+ paymentsDetails.forEach((cartItem) => {
8566
+ if (!cartItem.title || !cartItem.money?.amount) {
8567
+ return;
8568
+ }
8569
+ displayItems.push({
8570
+ label: cartItem.title,
8571
+ amount: cartItem.money.amount.toString(),
8572
+ });
8573
+ });
8574
+ return displayItems.map((item) => ({
8575
+ label: item.label ?? '',
8576
+ type: 'TAX',
8577
+ price: item.amount,
8578
+ }));
8579
+ }
8580
+ getTotalAmount(finance) {
8581
+ return finance?.grand_total?.amount ?? finance?.total?.amount;
8582
+ }
8583
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayInstantPaymentService, deps: [{ token: SummaryFinanceDetailsAdapterService }], target: i0.ɵɵFactoryTarget.Injectable }); }
8584
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayInstantPaymentService, providedIn: 'root' }); }
8585
+ }
8586
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayInstantPaymentService, decorators: [{
8587
+ type: Injectable,
8588
+ args: [{
8589
+ providedIn: 'root',
8590
+ }]
8591
+ }], ctorParameters: () => [{ type: SummaryFinanceDetailsAdapterService }] });
8592
+
8072
8593
  class GooglePayService {
8073
8594
  get libraryWasInitialized() {
8074
8595
  return !!this.window.google;
@@ -8076,14 +8597,17 @@ class GooglePayService {
8076
8597
  get googlePaymentClientWasInitialized() {
8077
8598
  return !!this.googlePaymentClient;
8078
8599
  }
8079
- constructor(window, paymentSystemProcessingService, injector) {
8600
+ constructor(window, elkLoggerService, paymentSystemProcessingService, googlePayCheckoutPaymentService, googlePayInstantPaymentService, injector) {
8080
8601
  this.window = window;
8602
+ this.elkLoggerService = elkLoggerService;
8081
8603
  this.paymentSystemProcessingService = paymentSystemProcessingService;
8604
+ this.googlePayCheckoutPaymentService = googlePayCheckoutPaymentService;
8605
+ this.googlePayInstantPaymentService = googlePayInstantPaymentService;
8082
8606
  this.injector = injector;
8083
8607
  this.googlePayScriptUrl = 'https://pay.google.com/gp/p/js/pay.js';
8084
8608
  this.readyToPay = new BehaviorSubject(null);
8085
- this.checkout = null;
8086
8609
  this.googlePaymentClient = null;
8610
+ this.paymentService = null;
8087
8611
  }
8088
8612
  get readyToPay$() {
8089
8613
  return this.readyToPay.asObservable();
@@ -8092,8 +8616,9 @@ class GooglePayService {
8092
8616
  return this.readyToPay.getValue();
8093
8617
  }
8094
8618
  initGooglePayLibrary(data) {
8095
- this.isSandbox = data.isSandbox;
8096
- this.country = data.country;
8619
+ this.initParams = data;
8620
+ this.onPaymentDataChanged = data.onPaymentDataChanged;
8621
+ this.onPaymentAuthorized = data.onPaymentAuthorized;
8097
8622
  if (this.libraryWasInitialized && this.googlePaymentClientWasInitialized) {
8098
8623
  return;
8099
8624
  }
@@ -8103,28 +8628,36 @@ class GooglePayService {
8103
8628
  }
8104
8629
  this.paymentSystemProcessingService.loadScript(this.googlePayScriptUrl, this.onLoadScript.bind(this));
8105
8630
  }
8106
- checkPaymentDevice(base64checkoutData) {
8631
+ checkPaymentDevice(data) {
8107
8632
  this.paymentSystemProcessingService.initialize$
8108
8633
  .pipe(filter$1(Boolean), take(1))
8109
8634
  .subscribe(() => {
8110
- this.checkout =
8111
- this.paymentSystemProcessingService.getDecodedCheckout(base64checkoutData);
8112
- if (!this.checkout || !this.googlePaymentClient) {
8113
- throw new AppError(`Google Pay: no checkout or google payment client, checkout - ${Boolean(this.checkout).toString()}, client - ${Boolean(this.googlePaymentClient).toString()}`);
8635
+ if (!this.googlePaymentClient) {
8636
+ this.elkLoggerService.log('Google payment client is not initialized', [ErrorTags.GOOGLEPAY]);
8637
+ throw new AppError(`Google Pay: Google payment client is not initialized`);
8638
+ }
8639
+ this.paymentService = this.getPaymentService();
8640
+ const initData = this.paymentService.preparePayment({
8641
+ initParams: this.initParams,
8642
+ checkDeviceData: data,
8643
+ });
8644
+ if (!initData) {
8645
+ this.elkLoggerService.log('No initialization data', [
8646
+ ErrorTags.GOOGLEPAY,
8647
+ ]);
8648
+ throw new AppError('Google Pay: no initialization data');
8114
8649
  }
8115
- const checkoutData = this.checkout.request.form.fields;
8116
- const isReadyToPayRequest = JSON.parse(checkoutData.isReadyToPayRequest);
8117
8650
  this.googlePaymentClient
8118
- .isReadyToPay(isReadyToPayRequest)
8651
+ .isReadyToPay(initData.isReadyToPayRequest)
8119
8652
  .then((response) => {
8120
8653
  if (response.result && this.googlePaymentClient) {
8121
- this.googlePaymentClient.prefetchPaymentData(JSON.parse(checkoutData.paymentDataRequest));
8654
+ this.googlePaymentClient.prefetchPaymentData(initData.paymentDataRequest);
8122
8655
  return this.readyToPay.next(true);
8123
8656
  }
8124
8657
  this.readyToPay.next(false);
8125
8658
  const result = response.result?.toString() ?? '';
8126
8659
  const isHavePaymentClient = Boolean(this.googlePaymentClient).toString();
8127
- throw new Error(`Google Pay: possibly no response.result or googlePaymentClient is missing, result - ${result}, isHavePaymentClient - ${isHavePaymentClient}`);
8660
+ throw new AppError(`Google Pay: possibly no response.result or googlePaymentClient is missing, result - ${result}, isHavePaymentClient - ${isHavePaymentClient}`);
8128
8661
  })
8129
8662
  .catch((error) => {
8130
8663
  this.readyToPay.next(false);
@@ -8137,60 +8670,46 @@ class GooglePayService {
8137
8670
  });
8138
8671
  }
8139
8672
  async proceedCheckout() {
8140
- if (!this.checkout || !this.googlePaymentClient) {
8141
- const isHaveCheckout = !!this.checkout;
8142
- const isHaveClient = !!this.googlePaymentClient;
8143
- throw new AppError(`Google Pay: no checkout or google payment client, checkout - ${isHaveCheckout.toString()}, client - ${isHaveClient.toString()}`);
8673
+ if (!this.googlePaymentClient) {
8674
+ this.elkLoggerService.log('Google payment client is not initialized to proceed checkout', [ErrorTags.GOOGLEPAY]);
8675
+ throw new AppError(`Google Pay. proceedCheckout: no google payment client`);
8676
+ }
8677
+ if (!this.paymentService) {
8678
+ this.elkLoggerService.log('Google payment service is not initialized to proceed checkout', [ErrorTags.GOOGLEPAY]);
8679
+ throw new AppError(`Google Pay. proceedCheckout: no google payment service`);
8680
+ }
8681
+ const paymentDataRequest = this.paymentService.getPaymentRequest();
8682
+ if (!paymentDataRequest) {
8683
+ this.elkLoggerService.log('No data for payment data request', [
8684
+ ErrorTags.GOOGLEPAY,
8685
+ ]);
8686
+ throw new AppError(`Google Pay: No data for payment data request`);
8144
8687
  }
8145
- const checkoutData = this.checkout.request.form.fields;
8146
- const paymentDataRequest = JSON.parse(checkoutData.paymentDataRequest);
8147
- paymentDataRequest.transactionInfo = {
8148
- currencyCode: checkoutData.currency,
8149
- totalPriceStatus: 'FINAL',
8150
- totalPrice: checkoutData.sum,
8151
- countryCode: this.country,
8152
- };
8153
8688
  const checkStatusAction = this.injector
8154
8689
  .get(CheckStatusActionCreator)
8155
8690
  .getActionData();
8156
8691
  try {
8157
8692
  const paymentData = await this.googlePaymentClient.loadPaymentData(paymentDataRequest);
8158
8693
  if (!paymentData?.paymentMethodData?.tokenizationData?.token) {
8694
+ this.elkLoggerService.log('Token is missing', [ErrorTags.GOOGLEPAY]);
8159
8695
  throw new AppError('Google Pay: token is missing');
8160
8696
  }
8161
- if (!this.checkout) {
8162
- throw new AppError('Google Pay: no checkout data in then');
8163
- }
8164
- let returnUrl = this.checkout.request.form.fields.returnSuccessUrl;
8165
- const data = this.checkout.request.form.fields;
8166
- returnUrl += `&cpf_number=${data.cpf_number}&descriptor=${data.descriptor}&paymentData=${JSON.stringify(paymentData)}`;
8167
- this.paymentSystemProcessingService.emitStatusUrl(returnUrl);
8697
+ this.paymentService.handleSuccessfulPayment?.(paymentData);
8168
8698
  return checkStatusAction;
8169
8699
  }
8170
8700
  catch (error) {
8171
- if (!this.checkout) {
8172
- throw new AppError(`Google Pay: no checkout data`);
8173
- }
8174
- const statusCode = error
8175
- ?.statusCode;
8176
- const isStatusCanceled = statusCode && this.isCancelledStatus(statusCode);
8177
- if (isStatusCanceled) {
8178
- return null;
8179
- }
8180
- const returnUrl = this.checkout.request.form.fields.returnFailUrl;
8181
- this.paymentSystemProcessingService.emitStatusUrl(returnUrl);
8701
+ this.paymentService.handleFailedPayment?.(error);
8182
8702
  return checkStatusAction;
8183
8703
  }
8184
8704
  }
8185
8705
  createButton(onClickHandler, buttonColor = 'default') {
8186
- if (!this.checkout || !this.googlePaymentClient) {
8706
+ if (!this.googlePaymentClient) {
8187
8707
  return null;
8188
8708
  }
8189
- const checkoutData = this.checkout.request.form.fields;
8190
- const paymentDataRequest = JSON.parse(checkoutData.paymentDataRequest);
8709
+ const allowedPaymentMethods = this.paymentService?.getAllowedPaymentMethods() || [];
8191
8710
  return this.googlePaymentClient.createButton({
8192
8711
  onClick: onClickHandler,
8193
- allowedPaymentMethods: paymentDataRequest.allowedPaymentMethods,
8712
+ allowedPaymentMethods: allowedPaymentMethods,
8194
8713
  buttonSizeMode: 'fill',
8195
8714
  buttonType: 'buy',
8196
8715
  buttonColor,
@@ -8200,11 +8719,18 @@ class GooglePayService {
8200
8719
  if (!this.window.google) {
8201
8720
  return;
8202
8721
  }
8203
- const environment = this.isSandbox ? 'TEST' : 'PRODUCTION';
8722
+ const environment = this.initParams.isSandbox ? 'TEST' : 'PRODUCTION';
8723
+ const googlePaymentClientData = {
8724
+ environment,
8725
+ };
8726
+ if (this.initParams.isInstantPayFlow) {
8727
+ googlePaymentClientData.paymentDataCallbacks = {
8728
+ onPaymentDataChanged: this.onPaymentDataChanged,
8729
+ onPaymentAuthorized: this.onPaymentAuthorized,
8730
+ };
8731
+ }
8204
8732
  this.googlePaymentClient =
8205
- new this.window.google.payments.api.PaymentsClient({
8206
- environment,
8207
- });
8733
+ new this.window.google.payments.api.PaymentsClient(googlePaymentClientData);
8208
8734
  }
8209
8735
  onLoadScript() {
8210
8736
  if (!this.window.google) {
@@ -8223,10 +8749,12 @@ class GooglePayService {
8223
8749
  this.paymentSystemProcessingService.emitInitialize(true);
8224
8750
  }
8225
8751
  }
8226
- isCancelledStatus(statusCode) {
8227
- return statusCode.toLowerCase() === 'canceled';
8752
+ getPaymentService() {
8753
+ if (this.initParams.isInstantPayFlow)
8754
+ return this.googlePayInstantPaymentService;
8755
+ return this.googlePayCheckoutPaymentService;
8228
8756
  }
8229
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayService, deps: [{ token: windowToken }, { token: PaymentSystemProcessingService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
8757
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayService, deps: [{ token: windowToken }, { token: ElkLoggerService }, { token: PaymentSystemProcessingService }, { token: GooglePayCheckoutPaymentService }, { token: GooglePayInstantPaymentService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
8230
8758
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayService, providedIn: 'root' }); }
8231
8759
  }
8232
8760
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayService, decorators: [{
@@ -8237,9 +8765,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8237
8765
  }], ctorParameters: () => [{ type: undefined, decorators: [{
8238
8766
  type: Inject,
8239
8767
  args: [windowToken]
8240
- }] }, { type: PaymentSystemProcessingService }, { type: i0.Injector }] });
8768
+ }] }, { type: ElkLoggerService }, { type: PaymentSystemProcessingService }, { type: GooglePayCheckoutPaymentService }, { type: GooglePayInstantPaymentService }, { type: i0.Injector }] });
8241
8769
 
8242
- const applePayVersion = 3;
8770
+ var ApplePayIntegrationType;
8771
+ (function (ApplePayIntegrationType) {
8772
+ ApplePayIntegrationType["redirect"] = "redirect";
8773
+ ApplePayIntegrationType["native"] = "native";
8774
+ })(ApplePayIntegrationType || (ApplePayIntegrationType = {}));
8243
8775
 
8244
8776
  const agreementsGroup = [
8245
8777
  FieldNames.licenseDisclaimer,
@@ -8257,11 +8789,91 @@ const agreementsGroup = [
8257
8789
  FieldNames.koreaLimitsInstruction,
8258
8790
  ];
8259
8791
 
8260
- var ApplePayErrors;
8261
- (function (ApplePayErrors) {
8262
- ApplePayErrors["paymentError"] = "paymentError";
8263
- ApplePayErrors["deviceIsNotCapableError"] = "deviceIsNotCapableError";
8264
- })(ApplePayErrors || (ApplePayErrors = {}));
8792
+ class ApplePayParamsBuilderService {
8793
+ constructor() {
8794
+ this.agreementFieldsNames = agreementsGroup;
8795
+ }
8796
+ buildParams(paymentForm) {
8797
+ const { fields, summary } = paymentForm;
8798
+ if (!fields || !summary)
8799
+ return null;
8800
+ const formFields = fields.reduce((acc, field) => {
8801
+ if (this.agreementFieldsNames.includes(field.name) &&
8802
+ field.isVisible === "1" /* XpsBoolean.true */) {
8803
+ acc[field.name] = field.title;
8804
+ }
8805
+ else {
8806
+ acc[field.name] = field.value;
8807
+ }
8808
+ return acc;
8809
+ }, {});
8810
+ const agreements = this.agreementFieldsNames
8811
+ .map((fieldName) => [fieldName, formFields[fieldName]])
8812
+ .filter((fieldEntry) => {
8813
+ const [, value] = fieldEntry;
8814
+ return !!value;
8815
+ });
8816
+ return {
8817
+ tokenKey: this.getAppleToken(fields),
8818
+ totalLabel: formFields[FieldNames.labelApplePay] ?? '',
8819
+ totalAmount: this.getTotalAmount(summary),
8820
+ currencyCode: this.getTotalCurrency(summary),
8821
+ countryCode: formFields[FieldNames.countryCode] ?? '',
8822
+ merchantCapabilities: this.getJsonValueFromField(formFields, FieldNames.merchantCapabilities),
8823
+ requiredBillingContactFields: this.getJsonValueFromField(formFields, FieldNames.requiredBillingContactFields),
8824
+ requiredShippingContactFields: this.getJsonValueFromField(formFields, FieldNames.requiredShippingContactFields),
8825
+ supportedNetworks: this.getJsonValueFromField(formFields, FieldNames.supportedNetworks),
8826
+ agreements,
8827
+ acquirer: formFields[FieldNames.acquirer] ?? '',
8828
+ isSandbox: formFields[FieldNames.isSandbox] ?? '',
8829
+ payInstanceAccountId: formFields[FieldNames.payInstanceAccountId] ?? '',
8830
+ getApplePaySessionUrl: formFields[FieldNames.getApplePaySessionUrl] ?? '',
8831
+ payViaCheckoutUrl: formFields[FieldNames.payViaCheckoutUrl] ?? '',
8832
+ };
8833
+ }
8834
+ updateParams(params, summary) {
8835
+ return {
8836
+ ...params,
8837
+ totalAmount: this.getTotalAmount(summary),
8838
+ currencyCode: this.getTotalCurrency(summary),
8839
+ };
8840
+ }
8841
+ getJsonValueFromField(fields, fieldName) {
8842
+ const field = fields[fieldName];
8843
+ try {
8844
+ return field ? JSON.parse(field) : undefined;
8845
+ }
8846
+ catch (error) {
8847
+ return undefined;
8848
+ }
8849
+ }
8850
+ getAppleToken(fields) {
8851
+ const appleTokenField = fields.find((field) => {
8852
+ return field.name === 'token_key';
8853
+ });
8854
+ if (!appleTokenField) {
8855
+ return '';
8856
+ }
8857
+ return appleTokenField.value;
8858
+ }
8859
+ getTotalAmount(summary) {
8860
+ const finance = summary?.finance;
8861
+ const total = finance?.grand_total?.amount ?? finance?.total.amount;
8862
+ return total?.toString() ?? '';
8863
+ }
8864
+ getTotalCurrency(summary) {
8865
+ const finance = summary?.finance;
8866
+ return finance?.grand_total?.currency ?? finance?.total?.currency ?? '';
8867
+ }
8868
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayParamsBuilderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
8869
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayParamsBuilderService, providedIn: 'root' }); }
8870
+ }
8871
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayParamsBuilderService, decorators: [{
8872
+ type: Injectable,
8873
+ args: [{
8874
+ providedIn: 'root',
8875
+ }]
8876
+ }] });
8265
8877
 
8266
8878
  class ApplePayService {
8267
8879
  get paymentParameters() {
@@ -8276,11 +8888,14 @@ class ApplePayService {
8276
8888
  get integrationType$() {
8277
8889
  return this.integrationType.asObservable();
8278
8890
  }
8279
- constructor(window, userAgentService, summaryFinanceDetailsAdapterService) {
8891
+ constructor(window, userAgentService, summaryFinanceDetailsAdapterService, braintreeHandler, checkoutHandler, appleParamsBuilder, elkLoggerService) {
8280
8892
  this.window = window;
8281
8893
  this.userAgentService = userAgentService;
8282
8894
  this.summaryFinanceDetailsAdapterService = summaryFinanceDetailsAdapterService;
8283
- this.agreementFieldsNames = agreementsGroup;
8895
+ this.braintreeHandler = braintreeHandler;
8896
+ this.checkoutHandler = checkoutHandler;
8897
+ this.appleParamsBuilder = appleParamsBuilder;
8898
+ this.elkLoggerService = elkLoggerService;
8284
8899
  this.payment = new Subject();
8285
8900
  this.error = new Subject();
8286
8901
  this.integrationType = new Subject();
@@ -8288,48 +8903,18 @@ class ApplePayService {
8288
8903
  this.applePayParams = null;
8289
8904
  this.order = null;
8290
8905
  this.api = this.loadBraintree();
8906
+ this.subscribeToHandlers();
8291
8907
  }
8292
8908
  setApplePayParams(data) {
8293
- const formFields = data?.paymentForm?.fields;
8294
- const summary = data?.paymentForm?.summary;
8909
+ const paymentForm = data?.paymentForm;
8910
+ const formFields = paymentForm?.fields;
8911
+ const summary = paymentForm?.summary;
8295
8912
  if (!formFields || !summary) {
8296
8913
  return;
8297
8914
  }
8298
- const fields = formFields.reduce((acc, field) => {
8299
- if (this.agreementFieldsNames.includes(field.name) &&
8300
- field.isVisible === '1') {
8301
- acc[field.name] = field.title;
8302
- }
8303
- else {
8304
- acc[field.name] = field.value;
8305
- }
8306
- return acc;
8307
- }, {});
8308
- const agreements = this.agreementFieldsNames
8309
- .map((fieldName) => [fieldName, fields[fieldName]])
8310
- .filter((fieldEntry) => {
8311
- const [, value] = fieldEntry;
8312
- return !!value;
8313
- });
8314
- this.applePayParams = {
8315
- tokenKey: this.getAppleToken(formFields),
8316
- totalLabel: fields[FieldNames.labelApplePay] ?? '',
8317
- totalAmount: this.getTotalAmount(summary),
8318
- currencyCode: this.getTotalCurrency(summary),
8319
- countryCode: fields[FieldNames.countryCode] ?? '',
8320
- merchantCapabilities: this.getJsonValueFromField(fields, FieldNames.merchantCapabilities),
8321
- requiredBillingContactFields: this.getJsonValueFromField(fields, FieldNames.requiredBillingContactFields),
8322
- requiredShippingContactFields: this.getJsonValueFromField(fields, FieldNames.requiredShippingContactFields),
8323
- supportedNetworks: this.getJsonValueFromField(fields, FieldNames.supportedNetworks),
8324
- agreements: agreements,
8325
- acquirer: fields[FieldNames.acquirer] ?? '',
8326
- isSandbox: fields[FieldNames.isSandbox] ?? '',
8327
- payInstanceAccountId: fields[FieldNames.payInstanceAccountId] ?? '',
8328
- getApplePaySessionUrl: fields[FieldNames.getApplePaySessionUrl] ?? '',
8329
- payViaCheckoutUrl: fields[FieldNames.payViaCheckoutUrl] ?? '',
8330
- };
8915
+ this.applePayParams = this.appleParamsBuilder.buildParams(paymentForm);
8331
8916
  }
8332
- async initLibrary(tokenKey) {
8917
+ async initBraintreeLibrary(tokenKey) {
8333
8918
  try {
8334
8919
  const api = await this.api;
8335
8920
  const clientInstance = await api.client.create({
@@ -8338,12 +8923,16 @@ class ApplePayService {
8338
8923
  this.paymentClient = await api.applePay.create({
8339
8924
  client: clientInstance,
8340
8925
  });
8926
+ this.braintreeHandler.setClient(this.paymentClient);
8341
8927
  }
8342
8928
  catch (error) {
8343
- console.error('apple pay: initialize failed', error);
8929
+ console.error(ApplePayErrors.braintreeInitializeError, error);
8930
+ this.elkLoggerService.log(ApplePayErrors.braintreeInitializeError, [
8931
+ ErrorTags.APPLEPAY,
8932
+ ]);
8344
8933
  }
8345
8934
  this.emitIntegrationType();
8346
- if (!this.paymentClient || !this.isDeviceCapable()) {
8935
+ if (!this.paymentClient || !this.isDeviceCapable) {
8347
8936
  this.emitError(ApplePayErrors.deviceIsNotCapableError);
8348
8937
  }
8349
8938
  }
@@ -8383,7 +8972,7 @@ class ApplePayService {
8383
8972
  }, '');
8384
8973
  }
8385
8974
  }
8386
- isDeviceCapable() {
8975
+ get isDeviceCapable() {
8387
8976
  // Apple SDK is used on non-Safari devices.
8388
8977
  // Support of ApplePay payments will be defined on the external PS4 page
8389
8978
  if (!this.userAgentService.isSafari)
@@ -8406,54 +8995,49 @@ class ApplePayService {
8406
8995
  if (!this.applePayParams || !summary) {
8407
8996
  return;
8408
8997
  }
8409
- this.applePayParams.totalAmount = this.getTotalAmount(summary);
8410
- this.applePayParams.currencyCode = this.getTotalCurrency(summary);
8411
- }
8412
- async loadBraintree() {
8413
- const api = await import('braintree-web');
8414
- return api;
8998
+ this.applePayParams = this.appleParamsBuilder.updateParams(this.applePayParams, summary);
8415
8999
  }
8416
- getAppleToken(formFields) {
8417
- const appleTokenField = formFields.find((field) => {
8418
- return field.name === 'token_key';
8419
- });
8420
- if (!appleTokenField) {
8421
- return '';
9000
+ proceedCheckout(parameters, iframeIntegrationEnabled = false) {
9001
+ const sessionHandler = this.getSessionHandler(parameters.acquirer);
9002
+ if (!sessionHandler) {
9003
+ console.error('Apple Pay: Unsupported acquirer:', parameters.acquirer);
9004
+ return;
8422
9005
  }
8423
- return appleTokenField.value;
8424
- }
8425
- getTotalAmount(summary) {
8426
- const finance = summary?.finance;
8427
- const total = finance?.grand_total?.amount ?? finance?.total.amount;
8428
- return total?.toString() ?? '';
8429
- }
8430
- getTotalCurrency(summary) {
8431
- const finance = summary?.finance;
8432
- return finance?.grand_total?.currency ?? finance?.total?.currency ?? '';
9006
+ sessionHandler.startSession(parameters, iframeIntegrationEnabled);
8433
9007
  }
8434
- getJsonValueFromField(fields, fieldName) {
8435
- const field = fields[fieldName];
8436
- try {
8437
- return field ? JSON.parse(field) : undefined;
8438
- }
8439
- catch (error) {
8440
- return undefined;
9008
+ getSessionHandler(acquirer) {
9009
+ switch (acquirer) {
9010
+ case 'braintree':
9011
+ return this.braintreeHandler;
9012
+ case 'checkout':
9013
+ return this.checkoutHandler;
9014
+ default:
9015
+ return undefined;
8441
9016
  }
8442
9017
  }
9018
+ async loadBraintree() {
9019
+ const api = await import('braintree-web');
9020
+ return api;
9021
+ }
8443
9022
  emitError(error) {
8444
9023
  this.error.next(error);
8445
9024
  }
8446
9025
  emitIntegrationType() {
8447
- let integrationType;
8448
- if (this.paymentClient && this.isDeviceCapable()) {
8449
- integrationType = 'redirect';
9026
+ if (this.userAgentService.isSafari && this.isDeviceCapable) {
9027
+ this.integrationType.next(ApplePayIntegrationType.native);
8450
9028
  }
8451
- else {
8452
- integrationType = 'none';
9029
+ else if (this.paymentClient && this.isDeviceCapable) {
9030
+ this.integrationType.next(ApplePayIntegrationType.redirect);
8453
9031
  }
8454
- this.integrationType.next(integrationType);
8455
9032
  }
8456
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, deps: [{ token: windowToken }, { token: UserAgentService }, { token: SummaryFinanceDetailsAdapterService }], target: i0.ɵɵFactoryTarget.Injectable }); }
9033
+ subscribeToHandlers() {
9034
+ const handlers = [this.braintreeHandler, this.checkoutHandler];
9035
+ handlers.forEach((handler) => {
9036
+ handler.error$.subscribe((error) => this.emitError(error));
9037
+ handler.payment$.subscribe((token) => this.payment.next(token));
9038
+ });
9039
+ }
9040
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, deps: [{ token: windowToken }, { token: UserAgentService }, { token: SummaryFinanceDetailsAdapterService }, { token: BraintreeHandler }, { token: CheckoutHandler }, { token: ApplePayParamsBuilderService }, { token: ElkLoggerService }], target: i0.ɵɵFactoryTarget.Injectable }); }
8457
9041
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, providedIn: 'root' }); }
8458
9042
  }
8459
9043
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, decorators: [{
@@ -8464,7 +9048,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8464
9048
  }], ctorParameters: () => [{ type: undefined, decorators: [{
8465
9049
  type: Inject,
8466
9050
  args: [windowToken]
8467
- }] }, { type: UserAgentService }, { type: SummaryFinanceDetailsAdapterService }] });
9051
+ }] }, { type: UserAgentService }, { type: SummaryFinanceDetailsAdapterService }, { type: BraintreeHandler }, { type: CheckoutHandler }, { type: ApplePayParamsBuilderService }, { type: ElkLoggerService }] });
8468
9052
 
8469
9053
  /*
8470
9054
  * Public API Surface of core-library