@xsolla/payment-client-core 0.2.44 → 0.2.45

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 (60) hide show
  1. package/esm2022/lib/core/payment/actions/action.interface.mjs +1 -1
  2. package/esm2022/lib/core/payment/actions/next-action.service.mjs +1 -1
  3. package/esm2022/lib/core/payment/field-names.enum.mjs +4 -1
  4. package/esm2022/lib/core/payment/field.interface.mjs +1 -1
  5. package/esm2022/lib/core/payment/finance-details/finance-details.service.mjs +4 -1
  6. package/esm2022/lib/core/payment/initialize-actions/action.interface.mjs +2 -0
  7. package/esm2022/lib/core/payment/initialize-actions/initialize-next-action.service.mjs +40 -0
  8. package/esm2022/lib/core/payment/initialize-actions/initialize-next-actions.mjs +7 -0
  9. package/esm2022/lib/core/payment/initialize-actions/next-action.interface.mjs +2 -0
  10. package/esm2022/lib/core/payment/initialize-actions/special-button/special-button.action.class.mjs +46 -0
  11. package/esm2022/lib/core/payment/initialize-actions/special-button/special-button.action.type.mjs +2 -0
  12. package/esm2022/lib/core/payment/initialized-form.inteface.mjs +1 -1
  13. package/esm2022/lib/core/payment/payment.service.mjs +72 -24
  14. package/esm2022/lib/core/payment/sync/request/sync-request.class.mjs +3 -1
  15. package/esm2022/lib/core/payment/sync/sync.service.mjs +4 -4
  16. package/esm2022/lib/core/payment/xps-error.interface.mjs +1 -1
  17. package/esm2022/lib/core/sdk-payment-systems/google-pay/check-payment-device-data.interface.mjs +2 -0
  18. package/esm2022/lib/core/sdk-payment-systems/google-pay/google-pay-init-params.interface.mjs +1 -1
  19. package/esm2022/lib/core/sdk-payment-systems/google-pay/google-pay-library.interface.mjs +1 -1
  20. package/esm2022/lib/core/sdk-payment-systems/google-pay/google-pay.service.mjs +70 -59
  21. package/esm2022/lib/core/sdk-payment-systems/google-pay/payment/google-pay-checkout-payment.service.mjs +75 -0
  22. package/esm2022/lib/core/sdk-payment-systems/google-pay/payment/google-pay-instant-payment.service.mjs +121 -0
  23. package/esm2022/lib/core/sdk-payment-systems/google-pay/payment/google-pay-payment-service.interface.mjs +2 -0
  24. package/esm2022/lib/core/sdk-payment-systems/google-pay/updated-price.interface.mjs +2 -0
  25. package/esm2022/lib/core/sdk-payment-systems/sdk-payment-systems-initial-data.interface.mjs +1 -1
  26. package/esm2022/lib/core/sdk-payment-systems/sdk-payment-systems.interface.mjs +1 -1
  27. package/esm2022/lib/core-library.module.mjs +12 -1
  28. package/esm2022/lib/core-library.service.mjs +13 -2
  29. package/fesm2022/xsolla-payment-client-core.mjs +560 -209
  30. package/fesm2022/xsolla-payment-client-core.mjs.map +1 -1
  31. package/lib/core/payment/actions/action.interface.d.ts +2 -2
  32. package/lib/core/payment/actions/next-action.service.d.ts +1 -1
  33. package/lib/core/payment/actions/next-actions.d.ts +1 -1
  34. package/lib/core/payment/field-names.enum.d.ts +4 -1
  35. package/lib/core/payment/field.interface.d.ts +1 -1
  36. package/lib/core/payment/finance-details/finance-details.service.d.ts +1 -0
  37. package/lib/core/payment/initialize-actions/action.interface.d.ts +11 -0
  38. package/lib/core/payment/initialize-actions/initialize-next-action.service.d.ts +16 -0
  39. package/lib/core/payment/initialize-actions/initialize-next-actions.d.ts +5 -0
  40. package/lib/core/payment/initialize-actions/next-action.interface.d.ts +2 -0
  41. package/lib/core/payment/initialize-actions/special-button/special-button.action.class.d.ts +17 -0
  42. package/lib/core/payment/initialize-actions/special-button/special-button.action.type.d.ts +6 -0
  43. package/lib/core/payment/initialized-form.inteface.d.ts +2 -0
  44. package/lib/core/payment/payment.service.d.ts +11 -2
  45. package/lib/core/payment/sync/sync.service.d.ts +1 -1
  46. package/lib/core/payment/xps-error.interface.d.ts +1 -0
  47. package/lib/core/sdk-payment-systems/google-pay/check-payment-device-data.interface.d.ts +9 -0
  48. package/lib/core/sdk-payment-systems/google-pay/google-pay-init-params.interface.d.ts +6 -0
  49. package/lib/core/sdk-payment-systems/google-pay/google-pay-library.interface.d.ts +170 -52
  50. package/lib/core/sdk-payment-systems/google-pay/google-pay.service.d.ts +18 -10
  51. package/lib/core/sdk-payment-systems/google-pay/payment/google-pay-checkout-payment.service.d.ts +18 -0
  52. package/lib/core/sdk-payment-systems/google-pay/payment/google-pay-instant-payment.service.d.ts +18 -0
  53. package/lib/core/sdk-payment-systems/google-pay/payment/google-pay-payment-service.interface.d.ts +14 -0
  54. package/lib/core/sdk-payment-systems/google-pay/updated-price.interface.d.ts +7 -0
  55. package/lib/core/sdk-payment-systems/sdk-payment-systems-initial-data.interface.d.ts +7 -1
  56. package/lib/core/sdk-payment-systems/sdk-payment-systems.interface.d.ts +1 -1
  57. package/lib/core-library.service.d.ts +9 -0
  58. package/package.json +1 -1
  59. package/xsolla-payment-client-core-0.2.45.tgz +0 -0
  60. package/xsolla-payment-client-core-0.2.44.tgz +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,117 +5487,6 @@ 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();
5379
- }
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
- });
5388
- }
5389
- log(message, tags, extra) {
5390
- const logTags = [ErrorTags.HEADLESS_UI, ...tags];
5391
- if (isDevMode()) {
5392
- console.log(message, tags);
5393
- return;
5394
- }
5395
- const logMessage = {
5396
- additionalInfo: this.getAdditionalInfo(),
5397
- extra,
5398
- message,
5399
- };
5400
- this.sendLog(logMessage, logTags);
5401
- }
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;
5412
- }
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
5490
  class CentrifugoWebSocketService {
5483
5491
  static { this.reconnectionTimeoutIncrementFactor = 2; }
5484
5492
  static { this.timeoutsMs = {
@@ -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
  }
@@ -7945,7 +8090,12 @@ class CoreLibraryModule {
7945
8090
  provide: nextActionsToken,
7946
8091
  useValue: nextActions,
7947
8092
  },
8093
+ {
8094
+ provide: initializeNextActionsToken,
8095
+ useValue: initializeNextActions,
8096
+ },
7948
8097
  ...nextActions,
8098
+ ...initializeNextActions,
7949
8099
  ...flowUpdateNextActions,
7950
8100
  printInstructionRequestFactoryProvider,
7951
8101
  sendInstructionRequestFactoryProvider,
@@ -7982,7 +8132,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
7982
8132
  provide: nextActionsToken,
7983
8133
  useValue: nextActions,
7984
8134
  },
8135
+ {
8136
+ provide: initializeNextActionsToken,
8137
+ useValue: initializeNextActions,
8138
+ },
7985
8139
  ...nextActions,
8140
+ ...initializeNextActions,
7986
8141
  ...flowUpdateNextActions,
7987
8142
  printInstructionRequestFactoryProvider,
7988
8143
  sendInstructionRequestFactoryProvider,
@@ -8069,6 +8224,195 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8069
8224
  args: [windowToken]
8070
8225
  }] }] });
8071
8226
 
8227
+ class GooglePayCheckoutPaymentService {
8228
+ constructor(paymentSystemProcessingService) {
8229
+ this.paymentSystemProcessingService = paymentSystemProcessingService;
8230
+ this.checkout = null;
8231
+ }
8232
+ preparePayment({ initParams, checkDeviceData, }) {
8233
+ if (!initParams || !checkDeviceData.base64checkoutData)
8234
+ return null;
8235
+ this.initParams = initParams;
8236
+ this.checkout =
8237
+ this.paymentSystemProcessingService.getDecodedCheckout(checkDeviceData.base64checkoutData);
8238
+ if (!this.checkout)
8239
+ return null;
8240
+ const checkoutData = this.checkout.request.form.fields;
8241
+ const paymentDataRequest = JSON.parse(checkoutData.paymentDataRequest);
8242
+ const isReadyToPayRequest = JSON.parse(checkoutData.isReadyToPayRequest);
8243
+ const result = { paymentDataRequest, isReadyToPayRequest };
8244
+ if (checkoutData.amexCardNotification) {
8245
+ result.amexCardNotification = JSON.parse(checkoutData.amexCardNotification);
8246
+ }
8247
+ return result;
8248
+ }
8249
+ getPaymentRequest() {
8250
+ if (!this.checkout)
8251
+ return null;
8252
+ const checkoutData = this.checkout.request.form.fields;
8253
+ const paymentDataRequest = JSON.parse(checkoutData.paymentDataRequest);
8254
+ paymentDataRequest.transactionInfo = {
8255
+ currencyCode: checkoutData.currency,
8256
+ totalPriceStatus: 'FINAL',
8257
+ totalPrice: checkoutData.sum?.toString(),
8258
+ countryCode: this.initParams.country.toUpperCase(),
8259
+ };
8260
+ return paymentDataRequest;
8261
+ }
8262
+ getAllowedPaymentMethods() {
8263
+ if (!this.checkout)
8264
+ return [];
8265
+ const paymentDataRequest = JSON.parse(this.checkout.request.form.fields.paymentDataRequest);
8266
+ return paymentDataRequest.allowedPaymentMethods;
8267
+ }
8268
+ handleSuccessfulPayment(response) {
8269
+ if (!this.checkout)
8270
+ return;
8271
+ let returnUrl = this.checkout.request.form.fields.returnSuccessUrl;
8272
+ const data = this.checkout.request.form.fields;
8273
+ returnUrl += `&cpf_number=${data.cpf_number}&descriptor=${data.descriptor}&paymentData=${JSON.stringify(response)}`;
8274
+ this.paymentSystemProcessingService.emitStatusUrl(returnUrl);
8275
+ }
8276
+ handleFailedPayment(error) {
8277
+ if (!this.checkout)
8278
+ return;
8279
+ const statusCode = error?.statusCode;
8280
+ const isStatusCanceled = statusCode && this.isCancelledStatus(statusCode);
8281
+ if (isStatusCanceled)
8282
+ return;
8283
+ const returnUrl = this.checkout.request.form.fields.returnFailUrl;
8284
+ this.paymentSystemProcessingService.emitStatusUrl(returnUrl);
8285
+ }
8286
+ isCancelledStatus(statusCode) {
8287
+ return statusCode.toLowerCase() === 'canceled';
8288
+ }
8289
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayCheckoutPaymentService, deps: [{ token: PaymentSystemProcessingService }], target: i0.ɵɵFactoryTarget.Injectable }); }
8290
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayCheckoutPaymentService, providedIn: 'root' }); }
8291
+ }
8292
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayCheckoutPaymentService, decorators: [{
8293
+ type: Injectable,
8294
+ args: [{
8295
+ providedIn: 'root',
8296
+ }]
8297
+ }], ctorParameters: () => [{ type: PaymentSystemProcessingService }] });
8298
+
8299
+ class GooglePayInstantPaymentService {
8300
+ constructor(summaryFinanceDetailsAdapterService) {
8301
+ this.summaryFinanceDetailsAdapterService = summaryFinanceDetailsAdapterService;
8302
+ this.googleInitData = null;
8303
+ }
8304
+ preparePayment({ initParams, checkDeviceData, }) {
8305
+ if (!initParams)
8306
+ return null;
8307
+ this.initParams = initParams;
8308
+ this.googleInitData = this.extractGoogleInitData(initParams.fields);
8309
+ if (!this.googleInitData)
8310
+ return null;
8311
+ const displayItems = checkDeviceData.summary
8312
+ ? this.getItemsTaxes(checkDeviceData.summary)
8313
+ : [];
8314
+ this.googleInitData.paymentDataRequest = {
8315
+ ...this.googleInitData.paymentDataRequest,
8316
+ transactionInfo: {
8317
+ ...this.googleInitData.paymentDataRequest.transactionInfo,
8318
+ totalPriceStatus: 'ESTIMATED',
8319
+ totalPrice: this.googleInitData.paymentDataRequest.transactionInfo.totalPrice?.toString(),
8320
+ countryCode: initParams.country.toUpperCase() ??
8321
+ this.googleInitData.paymentDataRequest.transactionInfo.countryCode?.toUpperCase(),
8322
+ totalPriceLabel: this.googleInitData.paymentDataRequest.transactionInfo
8323
+ .totalPriceLabel ?? 'Total',
8324
+ displayItems,
8325
+ },
8326
+ shippingAddressRequired: true,
8327
+ callbackIntents: ['SHIPPING_ADDRESS', 'PAYMENT_AUTHORIZATION'],
8328
+ };
8329
+ return this.googleInitData;
8330
+ }
8331
+ getPaymentRequest() {
8332
+ if (!this.googleInitData)
8333
+ return null;
8334
+ return {
8335
+ ...this.googleInitData.paymentDataRequest,
8336
+ transactionInfo: {
8337
+ ...this.googleInitData.paymentDataRequest.transactionInfo,
8338
+ totalPriceStatus: 'ESTIMATED',
8339
+ totalPrice: this.googleInitData.paymentDataRequest.transactionInfo.totalPrice?.toString(),
8340
+ countryCode: this.initParams.country.toUpperCase() ??
8341
+ this.googleInitData.paymentDataRequest.transactionInfo.countryCode?.toUpperCase(),
8342
+ },
8343
+ shippingAddressRequired: true,
8344
+ callbackIntents: ['SHIPPING_ADDRESS', 'PAYMENT_AUTHORIZATION'],
8345
+ };
8346
+ }
8347
+ getAllowedPaymentMethods() {
8348
+ if (!this.googleInitData)
8349
+ return [];
8350
+ return this.googleInitData.paymentDataRequest.allowedPaymentMethods;
8351
+ }
8352
+ extractGoogleInitData(fields) {
8353
+ try {
8354
+ const googlePayInitData = fields.filter((field) => field.name === FieldNames.googlePayInitData)[0]?.value;
8355
+ const data = JSON.parse(googlePayInitData ?? null);
8356
+ return data;
8357
+ }
8358
+ catch (error) {
8359
+ return null;
8360
+ }
8361
+ }
8362
+ getItemsTaxes(summary) {
8363
+ const financeResponse = this.summaryFinanceDetailsAdapterService.getFinanceDetails(summary);
8364
+ const newCartPricing = financeResponse.cartSummary;
8365
+ if (!newCartPricing.total?.money?.amount || !financeResponse.finance) {
8366
+ return [];
8367
+ }
8368
+ const newPrice = {
8369
+ total: this.getTotalAmount(financeResponse.finance),
8370
+ subtotalDetails: newCartPricing.subtotalDetails,
8371
+ subtotalPayment: newCartPricing.subtotalPayment,
8372
+ totalDetails: newCartPricing.totalDetails,
8373
+ };
8374
+ const displayItems = [];
8375
+ if (newPrice.subtotalPayment?.money?.amount) {
8376
+ displayItems.push({
8377
+ label: newPrice.subtotalPayment.title || 'Subtotal',
8378
+ amount: newPrice.subtotalPayment.money?.amount.toString(),
8379
+ });
8380
+ }
8381
+ let paymentsDetails = [];
8382
+ if (newPrice.subtotalDetails?.length) {
8383
+ paymentsDetails = newPrice.subtotalDetails;
8384
+ }
8385
+ if (newPrice.totalDetails?.length) {
8386
+ paymentsDetails = paymentsDetails.concat(newPrice.totalDetails);
8387
+ }
8388
+ paymentsDetails.forEach((cartItem) => {
8389
+ if (!cartItem.title || !cartItem.money?.amount) {
8390
+ return;
8391
+ }
8392
+ displayItems.push({
8393
+ label: cartItem.title,
8394
+ amount: cartItem.money.amount.toString(),
8395
+ });
8396
+ });
8397
+ return displayItems.map((item) => ({
8398
+ label: item.label ?? '',
8399
+ type: 'TAX',
8400
+ price: item.amount,
8401
+ }));
8402
+ }
8403
+ getTotalAmount(finance) {
8404
+ return finance?.grand_total?.amount ?? finance?.total?.amount;
8405
+ }
8406
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayInstantPaymentService, deps: [{ token: SummaryFinanceDetailsAdapterService }], target: i0.ɵɵFactoryTarget.Injectable }); }
8407
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayInstantPaymentService, providedIn: 'root' }); }
8408
+ }
8409
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayInstantPaymentService, decorators: [{
8410
+ type: Injectable,
8411
+ args: [{
8412
+ providedIn: 'root',
8413
+ }]
8414
+ }], ctorParameters: () => [{ type: SummaryFinanceDetailsAdapterService }] });
8415
+
8072
8416
  class GooglePayService {
8073
8417
  get libraryWasInitialized() {
8074
8418
  return !!this.window.google;
@@ -8076,14 +8420,17 @@ class GooglePayService {
8076
8420
  get googlePaymentClientWasInitialized() {
8077
8421
  return !!this.googlePaymentClient;
8078
8422
  }
8079
- constructor(window, paymentSystemProcessingService, injector) {
8423
+ constructor(window, elkLoggerService, paymentSystemProcessingService, googlePayCheckoutPaymentService, googlePayInstantPaymentService, injector) {
8080
8424
  this.window = window;
8425
+ this.elkLoggerService = elkLoggerService;
8081
8426
  this.paymentSystemProcessingService = paymentSystemProcessingService;
8427
+ this.googlePayCheckoutPaymentService = googlePayCheckoutPaymentService;
8428
+ this.googlePayInstantPaymentService = googlePayInstantPaymentService;
8082
8429
  this.injector = injector;
8083
8430
  this.googlePayScriptUrl = 'https://pay.google.com/gp/p/js/pay.js';
8084
8431
  this.readyToPay = new BehaviorSubject(null);
8085
- this.checkout = null;
8086
8432
  this.googlePaymentClient = null;
8433
+ this.paymentService = null;
8087
8434
  }
8088
8435
  get readyToPay$() {
8089
8436
  return this.readyToPay.asObservable();
@@ -8092,8 +8439,9 @@ class GooglePayService {
8092
8439
  return this.readyToPay.getValue();
8093
8440
  }
8094
8441
  initGooglePayLibrary(data) {
8095
- this.isSandbox = data.isSandbox;
8096
- this.country = data.country;
8442
+ this.initParams = data;
8443
+ this.onPaymentDataChanged = data.onPaymentDataChanged;
8444
+ this.onPaymentAuthorized = data.onPaymentAuthorized;
8097
8445
  if (this.libraryWasInitialized && this.googlePaymentClientWasInitialized) {
8098
8446
  return;
8099
8447
  }
@@ -8103,28 +8451,36 @@ class GooglePayService {
8103
8451
  }
8104
8452
  this.paymentSystemProcessingService.loadScript(this.googlePayScriptUrl, this.onLoadScript.bind(this));
8105
8453
  }
8106
- checkPaymentDevice(base64checkoutData) {
8454
+ checkPaymentDevice(data) {
8107
8455
  this.paymentSystemProcessingService.initialize$
8108
8456
  .pipe(filter$1(Boolean), take(1))
8109
8457
  .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()}`);
8458
+ if (!this.googlePaymentClient) {
8459
+ this.elkLoggerService.log('Google payment client is not initialized', [ErrorTags.GOOGLEPAY]);
8460
+ throw new AppError(`Google Pay: Google payment client is not initialized`);
8461
+ }
8462
+ this.paymentService = this.getPaymentService();
8463
+ const initData = this.paymentService.preparePayment({
8464
+ initParams: this.initParams,
8465
+ checkDeviceData: data,
8466
+ });
8467
+ if (!initData) {
8468
+ this.elkLoggerService.log('No initialization data', [
8469
+ ErrorTags.GOOGLEPAY,
8470
+ ]);
8471
+ throw new AppError('Google Pay: no initialization data');
8114
8472
  }
8115
- const checkoutData = this.checkout.request.form.fields;
8116
- const isReadyToPayRequest = JSON.parse(checkoutData.isReadyToPayRequest);
8117
8473
  this.googlePaymentClient
8118
- .isReadyToPay(isReadyToPayRequest)
8474
+ .isReadyToPay(initData.isReadyToPayRequest)
8119
8475
  .then((response) => {
8120
8476
  if (response.result && this.googlePaymentClient) {
8121
- this.googlePaymentClient.prefetchPaymentData(JSON.parse(checkoutData.paymentDataRequest));
8477
+ this.googlePaymentClient.prefetchPaymentData(initData.paymentDataRequest);
8122
8478
  return this.readyToPay.next(true);
8123
8479
  }
8124
8480
  this.readyToPay.next(false);
8125
8481
  const result = response.result?.toString() ?? '';
8126
8482
  const isHavePaymentClient = Boolean(this.googlePaymentClient).toString();
8127
- throw new Error(`Google Pay: possibly no response.result or googlePaymentClient is missing, result - ${result}, isHavePaymentClient - ${isHavePaymentClient}`);
8483
+ throw new AppError(`Google Pay: possibly no response.result or googlePaymentClient is missing, result - ${result}, isHavePaymentClient - ${isHavePaymentClient}`);
8128
8484
  })
8129
8485
  .catch((error) => {
8130
8486
  this.readyToPay.next(false);
@@ -8137,60 +8493,46 @@ class GooglePayService {
8137
8493
  });
8138
8494
  }
8139
8495
  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()}`);
8496
+ if (!this.googlePaymentClient) {
8497
+ this.elkLoggerService.log('Google payment client is not initialized to proceed checkout', [ErrorTags.GOOGLEPAY]);
8498
+ throw new AppError(`Google Pay. proceedCheckout: no google payment client`);
8499
+ }
8500
+ if (!this.paymentService) {
8501
+ this.elkLoggerService.log('Google payment service is not initialized to proceed checkout', [ErrorTags.GOOGLEPAY]);
8502
+ throw new AppError(`Google Pay. proceedCheckout: no google payment service`);
8503
+ }
8504
+ const paymentDataRequest = this.paymentService.getPaymentRequest();
8505
+ if (!paymentDataRequest) {
8506
+ this.elkLoggerService.log('No data for payment data request', [
8507
+ ErrorTags.GOOGLEPAY,
8508
+ ]);
8509
+ throw new AppError(`Google Pay: No data for payment data request`);
8144
8510
  }
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
8511
  const checkStatusAction = this.injector
8154
8512
  .get(CheckStatusActionCreator)
8155
8513
  .getActionData();
8156
8514
  try {
8157
8515
  const paymentData = await this.googlePaymentClient.loadPaymentData(paymentDataRequest);
8158
8516
  if (!paymentData?.paymentMethodData?.tokenizationData?.token) {
8517
+ this.elkLoggerService.log('Token is missing', [ErrorTags.GOOGLEPAY]);
8159
8518
  throw new AppError('Google Pay: token is missing');
8160
8519
  }
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);
8520
+ this.paymentService.handleSuccessfulPayment?.(paymentData);
8168
8521
  return checkStatusAction;
8169
8522
  }
8170
8523
  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);
8524
+ this.paymentService.handleFailedPayment?.(error);
8182
8525
  return checkStatusAction;
8183
8526
  }
8184
8527
  }
8185
8528
  createButton(onClickHandler, buttonColor = 'default') {
8186
- if (!this.checkout || !this.googlePaymentClient) {
8529
+ if (!this.googlePaymentClient) {
8187
8530
  return null;
8188
8531
  }
8189
- const checkoutData = this.checkout.request.form.fields;
8190
- const paymentDataRequest = JSON.parse(checkoutData.paymentDataRequest);
8532
+ const allowedPaymentMethods = this.paymentService?.getAllowedPaymentMethods() || [];
8191
8533
  return this.googlePaymentClient.createButton({
8192
8534
  onClick: onClickHandler,
8193
- allowedPaymentMethods: paymentDataRequest.allowedPaymentMethods,
8535
+ allowedPaymentMethods: allowedPaymentMethods,
8194
8536
  buttonSizeMode: 'fill',
8195
8537
  buttonType: 'buy',
8196
8538
  buttonColor,
@@ -8200,11 +8542,18 @@ class GooglePayService {
8200
8542
  if (!this.window.google) {
8201
8543
  return;
8202
8544
  }
8203
- const environment = this.isSandbox ? 'TEST' : 'PRODUCTION';
8545
+ const environment = this.initParams.isSandbox ? 'TEST' : 'PRODUCTION';
8546
+ const googlePaymentClientData = {
8547
+ environment,
8548
+ };
8549
+ if (this.initParams.isInstantPayFlow) {
8550
+ googlePaymentClientData.paymentDataCallbacks = {
8551
+ onPaymentDataChanged: this.onPaymentDataChanged,
8552
+ onPaymentAuthorized: this.onPaymentAuthorized,
8553
+ };
8554
+ }
8204
8555
  this.googlePaymentClient =
8205
- new this.window.google.payments.api.PaymentsClient({
8206
- environment,
8207
- });
8556
+ new this.window.google.payments.api.PaymentsClient(googlePaymentClientData);
8208
8557
  }
8209
8558
  onLoadScript() {
8210
8559
  if (!this.window.google) {
@@ -8223,10 +8572,12 @@ class GooglePayService {
8223
8572
  this.paymentSystemProcessingService.emitInitialize(true);
8224
8573
  }
8225
8574
  }
8226
- isCancelledStatus(statusCode) {
8227
- return statusCode.toLowerCase() === 'canceled';
8575
+ getPaymentService() {
8576
+ if (this.initParams.isInstantPayFlow)
8577
+ return this.googlePayInstantPaymentService;
8578
+ return this.googlePayCheckoutPaymentService;
8228
8579
  }
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 }); }
8580
+ 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
8581
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayService, providedIn: 'root' }); }
8231
8582
  }
8232
8583
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: GooglePayService, decorators: [{
@@ -8237,7 +8588,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8237
8588
  }], ctorParameters: () => [{ type: undefined, decorators: [{
8238
8589
  type: Inject,
8239
8590
  args: [windowToken]
8240
- }] }, { type: PaymentSystemProcessingService }, { type: i0.Injector }] });
8591
+ }] }, { type: ElkLoggerService }, { type: PaymentSystemProcessingService }, { type: GooglePayCheckoutPaymentService }, { type: GooglePayInstantPaymentService }, { type: i0.Injector }] });
8241
8592
 
8242
8593
  const applePayVersion = 3;
8243
8594