@xsolla/payment-client-core 0.2.56 → 0.2.58

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 +27 -10
  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 +168 -14
  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 +8 -1
  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.58.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);
8249
8314
  }
8315
+ async sendMessageToAnotherWindow(command, payload) {
8316
+ await this.socketBridgeService.publishMessage(command, payload);
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,13 @@ class ApplePayCartService {
8256
8344
  get cartRecalculationRequest$() {
8257
8345
  return this.cartRecalculationRequest.asObservable();
8258
8346
  }
8347
+ constructor(externalWindowCommunicationService, summaryFinanceDetailsAdapterService) {
8348
+ this.externalWindowCommunicationService = externalWindowCommunicationService;
8349
+ this.summaryFinanceDetailsAdapterService = summaryFinanceDetailsAdapterService;
8350
+ this.cartSuccessfulRecalculated = new Subject();
8351
+ this.cartErrorRecalculated = new Subject();
8352
+ this.cartRecalculationRequest = new Subject();
8353
+ }
8259
8354
  recalculateCartTaxes(shippingContact) {
8260
8355
  const zip = shippingContact.postalCode;
8261
8356
  const country = shippingContact.countryCode?.toUpperCase() ?? '';
@@ -8275,9 +8370,19 @@ class ApplePayCartService {
8275
8370
  newLineItems: this.getLineItems(updatedPrice),
8276
8371
  };
8277
8372
  }
8278
- sendSuccessfulRecalculatedCart(updatedPrice) {
8373
+ sendSuccessfulRecalculatedCart(xpsResponse) {
8374
+ const financeDetails = this.summaryFinanceDetailsAdapterService.getFinanceDetails(xpsResponse.summary);
8375
+ const updatedPrice = {
8376
+ // @ts-expect-error finance exist
8377
+ total: this.getTotalAmount(xpsResponse.summary.finance),
8378
+ subtotalDetails: financeDetails.cartSummary.subtotalDetails,
8379
+ totalDetails: financeDetails.cartSummary.totalDetails,
8380
+ subtotalPayment: financeDetails.cartSummary.subtotalPayment,
8381
+ };
8279
8382
  this.cartSuccessfulRecalculated.next(updatedPrice);
8280
- // TODO send web socket message to external window here
8383
+ void this.externalWindowCommunicationService.sendMessageToAnotherWindow("apple-pay-update-price" /* CommandsForPages.APPLE_PAY_UPDATE_PRICE */, {
8384
+ newCartPricing: updatedPrice,
8385
+ });
8281
8386
  }
8282
8387
  sendErrorRecalculatedCart(error) {
8283
8388
  this.cartErrorRecalculated.next(error);
@@ -8311,7 +8416,10 @@ class ApplePayCartService {
8311
8416
  });
8312
8417
  return newLineItems;
8313
8418
  }
8314
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayCartService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
8419
+ getTotalAmount(finance) {
8420
+ return finance?.grand_total?.amount ?? finance?.total?.amount;
8421
+ }
8422
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayCartService, deps: [{ token: ApplePayExternalWindowCommunicationService }, { token: SummaryFinanceDetailsAdapterService }], target: i0.ɵɵFactoryTarget.Injectable }); }
8315
8423
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayCartService, providedIn: 'root' }); }
8316
8424
  }
8317
8425
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayCartService, decorators: [{
@@ -8319,7 +8427,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8319
8427
  args: [{
8320
8428
  providedIn: 'root',
8321
8429
  }]
8322
- }] });
8430
+ }], ctorParameters: () => [{ type: ApplePayExternalWindowCommunicationService }, { type: SummaryFinanceDetailsAdapterService }] });
8323
8431
 
8324
8432
  class BraintreeHandler extends ApplePaySessionHandlerAbstract {
8325
8433
  constructor(window, elkLoggerService, applePayCartService) {
@@ -9076,6 +9184,17 @@ var ApplePayIntegrationType;
9076
9184
  ApplePayIntegrationType["native"] = "native";
9077
9185
  })(ApplePayIntegrationType || (ApplePayIntegrationType = {}));
9078
9186
 
9187
+ const mapShippingAddressToContact = (shippingAddress) => {
9188
+ return {
9189
+ postalCode: shippingAddress.zip,
9190
+ country: shippingAddress.country,
9191
+ countryCode: shippingAddress.country,
9192
+ administrativeArea: '',
9193
+ locality: '',
9194
+ newLineItems: [],
9195
+ };
9196
+ };
9197
+
9079
9198
  const agreementsGroup = [
9080
9199
  FieldNames.licenseDisclaimer,
9081
9200
  FieldNames.termsAndConditions,
@@ -9288,7 +9407,7 @@ class ApplePayService {
9288
9407
  get integrationType$() {
9289
9408
  return this.integrationType.asObservable();
9290
9409
  }
9291
- constructor(window, summaryFinanceDetailsAdapterService, braintreeHandler, checkoutHandler, appleParamsBuilder, elkLoggerService, applePaySdkService) {
9410
+ constructor(window, summaryFinanceDetailsAdapterService, braintreeHandler, checkoutHandler, appleParamsBuilder, elkLoggerService, applePaySdkService, externalWindowCommunicationService, applePayCartService) {
9292
9411
  this.window = window;
9293
9412
  this.summaryFinanceDetailsAdapterService = summaryFinanceDetailsAdapterService;
9294
9413
  this.braintreeHandler = braintreeHandler;
@@ -9296,10 +9415,13 @@ class ApplePayService {
9296
9415
  this.appleParamsBuilder = appleParamsBuilder;
9297
9416
  this.elkLoggerService = elkLoggerService;
9298
9417
  this.applePaySdkService = applePaySdkService;
9418
+ this.externalWindowCommunicationService = externalWindowCommunicationService;
9419
+ this.applePayCartService = applePayCartService;
9299
9420
  this.payment = new Subject();
9300
9421
  this.error = new Subject();
9301
9422
  this.integrationType = new Subject();
9302
9423
  this.applePayQrOpened = new Subject();
9424
+ this.destroy$ = new Subject();
9303
9425
  this.paymentClient = null;
9304
9426
  this.applePayParams = null;
9305
9427
  this.order = null;
@@ -9312,6 +9434,8 @@ class ApplePayService {
9312
9434
  }
9313
9435
  /* istanbul ignore next */
9314
9436
  removeListeners() {
9437
+ this.destroy$.next();
9438
+ this.destroy$.complete();
9315
9439
  this.applePaySdkService.removeListeners();
9316
9440
  }
9317
9441
  setApplePayParams(data) {
@@ -9350,11 +9474,14 @@ class ApplePayService {
9350
9474
  }
9351
9475
  this.emitIntegrationType();
9352
9476
  }
9353
- redirectToPaymentPage(parameters, token, isSandbox) {
9477
+ async redirectToPaymentPage(parameters, token, isSandbox) {
9354
9478
  const route = pagesRoutes.get(applePayId);
9355
9479
  if (!route) {
9356
9480
  return;
9357
9481
  }
9482
+ console.log('🟡[LOG] token :>>', token);
9483
+ await this.externalWindowCommunicationService.openWebSocketConnection(token);
9484
+ this.listenWebsocketMessages();
9358
9485
  const query = new URLSearchParams({
9359
9486
  ...parameters,
9360
9487
  merchantCapabilities: JSON.stringify(parameters.merchantCapabilities),
@@ -9460,7 +9587,34 @@ class ApplePayService {
9460
9587
  this.applePayQrOpened.next();
9461
9588
  }
9462
9589
  }
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 }); }
9590
+ listenWebsocketMessages() {
9591
+ // Cart recalculation
9592
+ this.externalWindowCommunicationService
9593
+ .getCartRecalculationMessage$()
9594
+ .pipe(takeUntil(this.destroy$))
9595
+ .subscribe((message) => {
9596
+ const shippingContact = mapShippingAddressToContact(message.data.shippingAddress);
9597
+ this.applePayCartService.recalculateCartTaxes(shippingContact);
9598
+ });
9599
+ // Send token
9600
+ this.externalWindowCommunicationService
9601
+ .getWindowSendTokenMessage$()
9602
+ .pipe(takeUntil(this.destroy$))
9603
+ .subscribe((message) => {
9604
+ this.payment.next(message.data.applePayToken);
9605
+ });
9606
+ // Close window
9607
+ this.externalWindowCommunicationService.getWindowClose$().subscribe(() => {
9608
+ // TODO handle
9609
+ });
9610
+ // Close window with 'back' button
9611
+ this.externalWindowCommunicationService
9612
+ .getWindowReturnMessage$()
9613
+ .subscribe(() => {
9614
+ // TODO handle
9615
+ });
9616
+ }
9617
+ 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
9618
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, providedIn: 'root' }); }
9465
9619
  }
9466
9620
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, decorators: [{
@@ -9471,7 +9625,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
9471
9625
  }], ctorParameters: () => [{ type: undefined, decorators: [{
9472
9626
  type: Inject,
9473
9627
  args: [windowToken]
9474
- }] }, { type: SummaryFinanceDetailsAdapterService }, { type: BraintreeHandler }, { type: CheckoutHandler }, { type: ApplePayParamsBuilderService }, { type: ElkLoggerService }, { type: ApplePaySdkService }] });
9628
+ }] }, { type: SummaryFinanceDetailsAdapterService }, { type: BraintreeHandler }, { type: CheckoutHandler }, { type: ApplePayParamsBuilderService }, { type: ElkLoggerService }, { type: ApplePaySdkService }, { type: ApplePayExternalWindowCommunicationService }, { type: ApplePayCartService }] });
9475
9629
 
9476
9630
  /*
9477
9631
  * Public API Surface of core-library