@xsolla/payment-client-core 0.2.56 → 0.2.57

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 (36) hide show
  1. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay-cart/apple-pay-cart.service.mjs +13 -9
  2. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay.service.mjs +44 -6
  3. package/esm2022/lib/core/sdk-payment-systems/apple-pay/commands-for-pages.enum.mjs +2 -0
  4. package/esm2022/lib/core/sdk-payment-systems/apple-pay/external-window-communication/external-window-communication.service.mjs +64 -0
  5. package/esm2022/lib/core/sdk-payment-systems/apple-pay/map-shipping-address-to-contact.function.mjs +11 -0
  6. package/esm2022/lib/core/sdk-payment-systems/apple-pay/socket-messages/recalculate-cart-message.interface.mjs +2 -0
  7. package/esm2022/lib/core/sdk-payment-systems/apple-pay/socket-messages/return-message.interface.mjs +2 -0
  8. package/esm2022/lib/core/sdk-payment-systems/apple-pay/socket-messages/send-token-message.interface.mjs +2 -0
  9. package/esm2022/lib/core/sdk-payment-systems/apple-pay/socket-messages/update-price-message.interface.mjs +2 -0
  10. package/esm2022/lib/core/sdk-payment-systems/apple-pay/socket-messages/window-close-message.interface.mjs +2 -0
  11. package/esm2022/lib/core/web-socket/centrifugo-web-socket.service.mjs +2 -2
  12. package/esm2022/lib/core/web-socket/socket-bridge/bridge-command.interface.mjs +2 -0
  13. package/esm2022/lib/core/web-socket/socket-bridge/bridge-connection-channel.interface.mjs +2 -0
  14. package/esm2022/lib/core/web-socket/socket-bridge/bridge-request-payload.interface.mjs +2 -0
  15. package/esm2022/lib/core/web-socket/socket-bridge/socket-bridge.service.mjs +40 -0
  16. package/esm2022/lib/core/window-command.interface.mjs +2 -0
  17. package/fesm2022/xsolla-payment-client-core.mjs +155 -13
  18. package/fesm2022/xsolla-payment-client-core.mjs.map +1 -1
  19. package/lib/core/sdk-payment-systems/apple-pay/apple-pay-cart/apple-pay-cart.service.d.ts +3 -0
  20. package/lib/core/sdk-payment-systems/apple-pay/apple-pay.service.d.ts +8 -2
  21. package/lib/core/sdk-payment-systems/apple-pay/commands-for-pages.enum.d.ts +7 -0
  22. package/lib/core/sdk-payment-systems/apple-pay/external-window-communication/external-window-communication.service.d.ts +28 -0
  23. package/lib/core/sdk-payment-systems/apple-pay/map-shipping-address-to-contact.function.d.ts +3 -0
  24. package/lib/core/sdk-payment-systems/apple-pay/socket-messages/recalculate-cart-message.interface.d.ts +9 -0
  25. package/lib/core/sdk-payment-systems/apple-pay/socket-messages/return-message.interface.d.ts +9 -0
  26. package/lib/core/sdk-payment-systems/apple-pay/socket-messages/send-token-message.interface.d.ts +8 -0
  27. package/lib/core/sdk-payment-systems/apple-pay/socket-messages/update-price-message.interface.d.ts +9 -0
  28. package/lib/core/sdk-payment-systems/apple-pay/socket-messages/window-close-message.interface.d.ts +5 -0
  29. package/lib/core/web-socket/socket-bridge/bridge-command.interface.d.ts +4 -0
  30. package/lib/core/web-socket/socket-bridge/bridge-connection-channel.interface.d.ts +6 -0
  31. package/lib/core/web-socket/socket-bridge/bridge-request-payload.interface.d.ts +4 -0
  32. package/lib/core/web-socket/socket-bridge/socket-bridge.service.d.ts +15 -0
  33. package/lib/core/window-command.interface.d.ts +6 -0
  34. package/package.json +1 -1
  35. package/xsolla-payment-client-core-0.2.57.tgz +0 -0
  36. package/xsolla-payment-client-core-0.2.56.tgz +0 -0
@@ -0,0 +1,40 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { firstValueFrom } from 'rxjs';
3
+ import { HttpHeaders, HttpParams } from '@angular/common/http';
4
+ import * as i0 from "@angular/core";
5
+ import * as i1 from "../../http/secure-api/secure-api.service";
6
+ export class SocketBridgeService {
7
+ constructor(secureApiClient) {
8
+ this.secureApiClient = secureApiClient;
9
+ this.apiUrl = 'socket_bridge';
10
+ }
11
+ async getBridgeConnectionChannel(token) {
12
+ this.token = token;
13
+ const params = new HttpParams().set('access_token', token);
14
+ return firstValueFrom(this.secureApiClient.get(`${this.apiUrl}/socket_url`, {
15
+ params,
16
+ }));
17
+ }
18
+ async publishMessage(message, messagePayload) {
19
+ const requestPayload = {
20
+ message: {
21
+ command: message,
22
+ data: messagePayload,
23
+ },
24
+ };
25
+ const endpointUrl = `${this.apiUrl}/message?access_token=${this.token}`;
26
+ return firstValueFrom(this.secureApiClient.post(endpointUrl.toString(), requestPayload, {
27
+ headers: new HttpHeaders().set('Content-Type', 'application/json; charset=utf-8'),
28
+ responseType: 'json',
29
+ }));
30
+ }
31
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SocketBridgeService, deps: [{ token: i1.SecureApiClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
32
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SocketBridgeService, providedIn: 'root' }); }
33
+ }
34
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SocketBridgeService, decorators: [{
35
+ type: Injectable,
36
+ args: [{
37
+ providedIn: 'root',
38
+ }]
39
+ }], ctorParameters: () => [{ type: i1.SecureApiClient }] });
40
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic29ja2V0LWJyaWRnZS5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvcGF5bWVudC1jbGllbnQtY29yZS9zcmMvbGliL2NvcmUvd2ViLXNvY2tldC9zb2NrZXQtYnJpZGdlL3NvY2tldC1icmlkZ2Uuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBQzNDLE9BQU8sRUFBRSxjQUFjLEVBQUUsTUFBTSxN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vbShcbiAgICAgIHRoaXMuc2VjdXJlQXBpQ2xpZW50LnBvc3Q8dm9pZCwgQnJpZGdlUmVxdWVzdE1lc3NhZ2VQYXlsb2FkPFA+PihcbiAgICAgICAgZW5kcG9pbnRVcmwudG9TdHJpbmcoKSxcbiAgICAgICAgcmVxdWVzdFBheWxvYWQsXG4gICAgICAgIHtcbiAgICAgICAgICBoZWFkZXJzOiBuZXcgSHR0cEhlYWRlcnMoKS5zZXQoXG4gICAgICAgICAgICAnQ29udGVudC1UeXBlJyxcbiAgICAgICAgICAgICdhcHBsaWNhdGlvbi9qc29uOyBjaGFyc2V0PXV0Zi04J1xuICAgICAgICAgICksXG4gICAgICAgICAgcmVzcG9uc2VUeXBlOiAnanNvbicsXG4gICAgICAgIH1cbiAgICAgIClcbiAgICApO1xuICB9XG59XG4iXX0=
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2luZG93LWNvbW1hbmQuaW50ZXJmYWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvcGF5bWVudC1jbGllbnQtY29yZS9zcmMvbGliL2NvcmUvd2luZG93LWNvbW1hbmQuaW50ZXJmYWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgaW50ZXJmYWNlIFdpbmRvd0NvbW1hbmQ8VCA9IHsgW2tleTogc3RyaW5nXTogdW5rbm93biB9PiB7XG4gIGNvbW1hbmQ6IHN0cmluZztcbiAgZGF0YT86IFQ7XG59XG4iXX0=
@@ -5553,7 +5553,7 @@ class CentrifugoWebSocketService {
5553
5553
  if (!this.isConnectionOpen) {
5554
5554
  return;
5555
5555
  }
5556
- this.connection.disconnect();
5556
+ this.connection?.disconnect();
5557
5557
  }
5558
5558
  get messages$() {
5559
5559
  return (this.incomingMessages$
@@ -8241,12 +8241,100 @@ class ApplePaySessionHandlerAbstract {
8241
8241
  }
8242
8242
  }
8243
8243
 
8244
- class ApplePayCartService {
8245
- constructor() {
8246
- this.cartSuccessfulRecalculated = new Subject();
8247
- this.cartErrorRecalculated = new Subject();
8248
- this.cartRecalculationRequest = new Subject();
8244
+ class SocketBridgeService {
8245
+ constructor(secureApiClient) {
8246
+ this.secureApiClient = secureApiClient;
8247
+ this.apiUrl = 'socket_bridge';
8248
+ }
8249
+ async getBridgeConnectionChannel(token) {
8250
+ this.token = token;
8251
+ const params = new HttpParams().set('access_token', token);
8252
+ return firstValueFrom(this.secureApiClient.get(`${this.apiUrl}/socket_url`, {
8253
+ params,
8254
+ }));
8255
+ }
8256
+ async publishMessage(message, messagePayload) {
8257
+ const requestPayload = {
8258
+ message: {
8259
+ command: message,
8260
+ data: messagePayload,
8261
+ },
8262
+ };
8263
+ const endpointUrl = `${this.apiUrl}/message?access_token=${this.token}`;
8264
+ return firstValueFrom(this.secureApiClient.post(endpointUrl.toString(), requestPayload, {
8265
+ headers: new HttpHeaders().set('Content-Type', 'application/json; charset=utf-8'),
8266
+ responseType: 'json',
8267
+ }));
8268
+ }
8269
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SocketBridgeService, deps: [{ token: SecureApiClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
8270
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SocketBridgeService, providedIn: 'root' }); }
8271
+ }
8272
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SocketBridgeService, decorators: [{
8273
+ type: Injectable,
8274
+ args: [{
8275
+ providedIn: 'root',
8276
+ }]
8277
+ }], ctorParameters: () => [{ type: SecureApiClient }] });
8278
+
8279
+ class ApplePayExternalWindowCommunicationService {
8280
+ constructor(window, webSocketFactory, socketBridgeService) {
8281
+ this.window = window;
8282
+ this.webSocketFactory = webSocketFactory;
8283
+ this.socketBridgeService = socketBridgeService;
8284
+ }
8285
+ getWindowClose$() {
8286
+ const isWindowCloseMessage = (message) => message.command === "apple-pay-window-close" /* CommandsForPages.APPLE_PAY_WINDOW_CLOSE */;
8287
+ const eventSource$ = this.getEventSource(isWindowCloseMessage);
8288
+ return eventSource$.pipe(tap(() => {
8289
+ this.window.focus();
8290
+ }));
8291
+ }
8292
+ getWindowReturnMessage$() {
8293
+ const isReturnMessage = (message) => message.command === "apple-pay-return" /* CommandsForPages.APPLE_PAY_RETURN */;
8294
+ const eventSource$ = this.getEventSource(isReturnMessage);
8295
+ return eventSource$.pipe(tap(() => {
8296
+ // TODO: send close event to sdk
8297
+ }));
8298
+ }
8299
+ getWindowSendTokenMessage$() {
8300
+ const isSendTokenMessage = (message) => message.command === "apple-pay-send-token" /* CommandsForPages.APPLE_PAY_SEND_TOKEN */;
8301
+ return this.getEventSource(isSendTokenMessage);
8302
+ }
8303
+ getCartRecalculationMessage$() {
8304
+ const isRecalculateCartMessage = (message) => message.command === "apple-pay-recalculate-cart" /* CommandsForPages.APPLE_PAY_RECALCULATE_CART */;
8305
+ return this.getEventSource(isRecalculateCartMessage);
8306
+ }
8307
+ async openWebSocketConnection(token) {
8308
+ const bridgeInfo = await this.socketBridgeService.getBridgeConnectionChannel(token);
8309
+ if (this.websocketClient) {
8310
+ this.websocketClient.close();
8311
+ }
8312
+ this.websocketClient = this.webSocketFactory.createWebSocketClient(bridgeInfo.subscribeUrl, bridgeInfo.clientType);
8313
+ await this.websocketClient.open(bridgeInfo.subscribeUrl, bridgeInfo.channelName);
8314
+ }
8315
+ async sendMessageToAnotherWindow(command, payload) {
8316
+ await this.socketBridgeService.publishMessage(command, payload);
8249
8317
  }
8318
+ getEventSource(eventHandler) {
8319
+ return this.websocketClient.messages$.pipe(map$1((message) => {
8320
+ console.info('websocket message', message);
8321
+ return JSON.parse(message);
8322
+ }), filter(eventHandler));
8323
+ }
8324
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayExternalWindowCommunicationService, deps: [{ token: windowToken }, { token: WebSocketFactory }, { token: SocketBridgeService }], target: i0.ɵɵFactoryTarget.Injectable }); }
8325
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayExternalWindowCommunicationService, providedIn: 'root' }); }
8326
+ }
8327
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayExternalWindowCommunicationService, decorators: [{
8328
+ type: Injectable,
8329
+ args: [{
8330
+ providedIn: 'root',
8331
+ }]
8332
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
8333
+ type: Inject,
8334
+ args: [windowToken]
8335
+ }] }, { type: WebSocketFactory }, { type: SocketBridgeService }] });
8336
+
8337
+ class ApplePayCartService {
8250
8338
  get cartSuccessfulRecalculated$() {
8251
8339
  return this.cartSuccessfulRecalculated.asObservable();
8252
8340
  }
@@ -8256,6 +8344,12 @@ class ApplePayCartService {
8256
8344
  get cartRecalculationRequest$() {
8257
8345
  return this.cartRecalculationRequest.asObservable();
8258
8346
  }
8347
+ constructor(externalWindowCommunicationService) {
8348
+ this.externalWindowCommunicationService = externalWindowCommunicationService;
8349
+ this.cartSuccessfulRecalculated = new Subject();
8350
+ this.cartErrorRecalculated = new Subject();
8351
+ this.cartRecalculationRequest = new Subject();
8352
+ }
8259
8353
  recalculateCartTaxes(shippingContact) {
8260
8354
  const zip = shippingContact.postalCode;
8261
8355
  const country = shippingContact.countryCode?.toUpperCase() ?? '';
@@ -8277,7 +8371,9 @@ class ApplePayCartService {
8277
8371
  }
8278
8372
  sendSuccessfulRecalculatedCart(updatedPrice) {
8279
8373
  this.cartSuccessfulRecalculated.next(updatedPrice);
8280
- // TODO send web socket message to external window here
8374
+ void this.externalWindowCommunicationService.sendMessageToAnotherWindow("apple-pay-update-price" /* CommandsForPages.APPLE_PAY_UPDATE_PRICE */, {
8375
+ newCartPricing: updatedPrice,
8376
+ });
8281
8377
  }
8282
8378
  sendErrorRecalculatedCart(error) {
8283
8379
  this.cartErrorRecalculated.next(error);
@@ -8311,7 +8407,7 @@ class ApplePayCartService {
8311
8407
  });
8312
8408
  return newLineItems;
8313
8409
  }
8314
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayCartService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
8410
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayCartService, deps: [{ token: ApplePayExternalWindowCommunicationService }], target: i0.ɵɵFactoryTarget.Injectable }); }
8315
8411
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayCartService, providedIn: 'root' }); }
8316
8412
  }
8317
8413
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayCartService, decorators: [{
@@ -8319,7 +8415,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8319
8415
  args: [{
8320
8416
  providedIn: 'root',
8321
8417
  }]
8322
- }] });
8418
+ }], ctorParameters: () => [{ type: ApplePayExternalWindowCommunicationService }] });
8323
8419
 
8324
8420
  class BraintreeHandler extends ApplePaySessionHandlerAbstract {
8325
8421
  constructor(window, elkLoggerService, applePayCartService) {
@@ -9076,6 +9172,17 @@ var ApplePayIntegrationType;
9076
9172
  ApplePayIntegrationType["native"] = "native";
9077
9173
  })(ApplePayIntegrationType || (ApplePayIntegrationType = {}));
9078
9174
 
9175
+ const mapShippingAddressToContact = (shippingAddress) => {
9176
+ return {
9177
+ postalCode: shippingAddress.zip,
9178
+ country: shippingAddress.country,
9179
+ countryCode: shippingAddress.country,
9180
+ administrativeArea: '',
9181
+ locality: '',
9182
+ newLineItems: [],
9183
+ };
9184
+ };
9185
+
9079
9186
  const agreementsGroup = [
9080
9187
  FieldNames.licenseDisclaimer,
9081
9188
  FieldNames.termsAndConditions,
@@ -9288,7 +9395,7 @@ class ApplePayService {
9288
9395
  get integrationType$() {
9289
9396
  return this.integrationType.asObservable();
9290
9397
  }
9291
- constructor(window, summaryFinanceDetailsAdapterService, braintreeHandler, checkoutHandler, appleParamsBuilder, elkLoggerService, applePaySdkService) {
9398
+ constructor(window, summaryFinanceDetailsAdapterService, braintreeHandler, checkoutHandler, appleParamsBuilder, elkLoggerService, applePaySdkService, externalWindowCommunicationService, applePayCartService) {
9292
9399
  this.window = window;
9293
9400
  this.summaryFinanceDetailsAdapterService = summaryFinanceDetailsAdapterService;
9294
9401
  this.braintreeHandler = braintreeHandler;
@@ -9296,10 +9403,13 @@ class ApplePayService {
9296
9403
  this.appleParamsBuilder = appleParamsBuilder;
9297
9404
  this.elkLoggerService = elkLoggerService;
9298
9405
  this.applePaySdkService = applePaySdkService;
9406
+ this.externalWindowCommunicationService = externalWindowCommunicationService;
9407
+ this.applePayCartService = applePayCartService;
9299
9408
  this.payment = new Subject();
9300
9409
  this.error = new Subject();
9301
9410
  this.integrationType = new Subject();
9302
9411
  this.applePayQrOpened = new Subject();
9412
+ this.destroy$ = new Subject();
9303
9413
  this.paymentClient = null;
9304
9414
  this.applePayParams = null;
9305
9415
  this.order = null;
@@ -9312,6 +9422,8 @@ class ApplePayService {
9312
9422
  }
9313
9423
  /* istanbul ignore next */
9314
9424
  removeListeners() {
9425
+ this.destroy$.next();
9426
+ this.destroy$.complete();
9315
9427
  this.applePaySdkService.removeListeners();
9316
9428
  }
9317
9429
  setApplePayParams(data) {
@@ -9350,11 +9462,14 @@ class ApplePayService {
9350
9462
  }
9351
9463
  this.emitIntegrationType();
9352
9464
  }
9353
- redirectToPaymentPage(parameters, token, isSandbox) {
9465
+ async redirectToPaymentPage(parameters, token, isSandbox) {
9354
9466
  const route = pagesRoutes.get(applePayId);
9355
9467
  if (!route) {
9356
9468
  return;
9357
9469
  }
9470
+ console.log('🟡[LOG] token :>>', token);
9471
+ await this.externalWindowCommunicationService.openWebSocketConnection(token);
9472
+ this.listenWebsocketMessages();
9358
9473
  const query = new URLSearchParams({
9359
9474
  ...parameters,
9360
9475
  merchantCapabilities: JSON.stringify(parameters.merchantCapabilities),
@@ -9460,7 +9575,34 @@ class ApplePayService {
9460
9575
  this.applePayQrOpened.next();
9461
9576
  }
9462
9577
  }
9463
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, deps: [{ token: windowToken }, { token: SummaryFinanceDetailsAdapterService }, { token: BraintreeHandler }, { token: CheckoutHandler }, { token: ApplePayParamsBuilderService }, { token: ElkLoggerService }, { token: ApplePaySdkService }], target: i0.ɵɵFactoryTarget.Injectable }); }
9578
+ listenWebsocketMessages() {
9579
+ // Cart recalculation
9580
+ this.externalWindowCommunicationService
9581
+ .getCartRecalculationMessage$()
9582
+ .pipe(takeUntil(this.destroy$))
9583
+ .subscribe((message) => {
9584
+ const shippingContact = mapShippingAddressToContact(message.data.shippingAddress);
9585
+ this.applePayCartService.recalculateCartTaxes(shippingContact);
9586
+ });
9587
+ // Send token
9588
+ this.externalWindowCommunicationService
9589
+ .getWindowSendTokenMessage$()
9590
+ .pipe(takeUntil(this.destroy$))
9591
+ .subscribe((message) => {
9592
+ this.payment.next(message.data.applePayToken);
9593
+ });
9594
+ // Close window
9595
+ this.externalWindowCommunicationService.getWindowClose$().subscribe(() => {
9596
+ // TODO handle
9597
+ });
9598
+ // Close window with 'back' button
9599
+ this.externalWindowCommunicationService
9600
+ .getWindowReturnMessage$()
9601
+ .subscribe(() => {
9602
+ // TODO handle
9603
+ });
9604
+ }
9605
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, deps: [{ token: windowToken }, { token: SummaryFinanceDetailsAdapterService }, { token: BraintreeHandler }, { token: CheckoutHandler }, { token: ApplePayParamsBuilderService }, { token: ElkLoggerService }, { token: ApplePaySdkService }, { token: ApplePayExternalWindowCommunicationService }, { token: ApplePayCartService }], target: i0.ɵɵFactoryTarget.Injectable }); }
9464
9606
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, providedIn: 'root' }); }
9465
9607
  }
9466
9608
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, decorators: [{
@@ -9471,7 +9613,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
9471
9613
  }], ctorParameters: () => [{ type: undefined, decorators: [{
9472
9614
  type: Inject,
9473
9615
  args: [windowToken]
9474
- }] }, { type: SummaryFinanceDetailsAdapterService }, { type: BraintreeHandler }, { type: CheckoutHandler }, { type: ApplePayParamsBuilderService }, { type: ElkLoggerService }, { type: ApplePaySdkService }] });
9616
+ }] }, { type: SummaryFinanceDetailsAdapterService }, { type: BraintreeHandler }, { type: CheckoutHandler }, { type: ApplePayParamsBuilderService }, { type: ElkLoggerService }, { type: ApplePaySdkService }, { type: ApplePayExternalWindowCommunicationService }, { type: ApplePayCartService }] });
9475
9617
 
9476
9618
  /*
9477
9619
  * Public API Surface of core-library