@xsolla/payment-client-core 0.2.45 → 0.2.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/esm2022/lib/core/agreements-group.const.mjs +17 -0
  2. package/esm2022/lib/core/extended-window.interface.mjs +1 -1
  3. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay-integration.type.mjs +6 -2
  4. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay-params-builder.service.mjs +90 -0
  5. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay-session.interface.mjs +2 -0
  6. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay.errors.enum.mjs +6 -3
  7. package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay.service.mjs +64 -87
  8. package/esm2022/lib/core/sdk-payment-systems/apple-pay/checkout-params.interface.mjs +1 -1
  9. package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/braintree.handler.mjs +80 -0
  10. package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/checkout.handler.mjs +65 -0
  11. package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.abstract.mjs +31 -0
  12. package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.type.mjs +2 -0
  13. package/esm2022/lib/core/settings/project.interface.mjs +1 -1
  14. package/esm2022/lib/core-library.module.mjs +7 -1
  15. package/esm2022/lib/core-library.service.mjs +4 -1
  16. package/fesm2022/xsolla-payment-client-core.mjs +317 -84
  17. package/fesm2022/xsolla-payment-client-core.mjs.map +1 -1
  18. package/lib/core/extended-window.interface.d.ts +1 -1
  19. package/lib/core/sdk-payment-systems/apple-pay/apple-pay-integration.type.d.ts +5 -1
  20. package/lib/core/sdk-payment-systems/apple-pay/apple-pay-params-builder.service.d.ts +15 -0
  21. package/lib/core/sdk-payment-systems/apple-pay/apple-pay-session.interface.d.ts +135 -0
  22. package/lib/core/sdk-payment-systems/apple-pay/apple-pay.errors.enum.d.ts +5 -2
  23. package/lib/core/sdk-payment-systems/apple-pay/apple-pay.service.d.ts +24 -13
  24. package/lib/core/sdk-payment-systems/apple-pay/checkout-params.interface.d.ts +1 -0
  25. package/lib/core/sdk-payment-systems/apple-pay/session-handlers/braintree.handler.d.ts +16 -0
  26. package/lib/core/sdk-payment-systems/apple-pay/session-handlers/checkout.handler.d.ts +13 -0
  27. package/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.abstract.d.ts +13 -0
  28. package/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.type.d.ts +3 -0
  29. package/lib/core/settings/project.interface.d.ts +1 -0
  30. package/lib/core-library.service.d.ts +3 -0
  31. package/package.json +1 -1
  32. package/xsolla-payment-client-core-0.2.46.tgz +0 -0
  33. package/esm2022/lib/core/agreementsGroup.const.mjs +0 -17
  34. package/xsolla-payment-client-core-0.2.45.tgz +0 -0
  35. /package/lib/core/{agreementsGroup.const.d.ts → agreements-group.const.d.ts} +0 -0
@@ -7897,6 +7897,9 @@ class CoreLibraryService {
7897
7897
  get formResponseValue() {
7898
7898
  return this.paymentService.formResponseValue;
7899
7899
  }
7900
+ get projectSettings() {
7901
+ return this.settingsService.project;
7902
+ }
7900
7903
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryService, deps: [{ token: SettingsService }, { token: CountryService }, { token: PaymentMethodsService }, { token: SavedMethodsService }, { token: UserBalanceService }, { token: PaymentConfigService }, { token: PaymentService }, { token: DeviceFingerPrintService }, { token: FinanceDetailsService }, { token: LegalService }, { token: StatusService }, { token: NextActionService }, { token: CreditCardService }, { token: CreditCardStateService }, { token: FormMessagesService }, { token: EditSavedMethodsService }, { token: UserBehaviourAnalyticsService }, { token: PerformanceService }, { token: CombinedPaymentMethodsService }, { token: CountriesApiService }, { token: SendInstructionService }, { token: ScriptTrackerService }], target: i0.ɵɵFactoryTarget.Injectable }); }
7901
7904
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryService, providedIn: 'root' }); }
7902
7905
  }
@@ -8061,6 +8064,176 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8061
8064
  }]
8062
8065
  }] });
8063
8066
 
8067
+ const applePayVersion = 3;
8068
+
8069
+ var ApplePayErrors;
8070
+ (function (ApplePayErrors) {
8071
+ ApplePayErrors["paymentError"] = "Apple Pay: payment error";
8072
+ ApplePayErrors["deviceIsNotCapableError"] = "Apple Pay: device is not capable";
8073
+ ApplePayErrors["cancelled"] = "Apple Pay: payment cancelled";
8074
+ ApplePayErrors["merchantValidationError"] = "Apple Pay: merchant validation error";
8075
+ ApplePayErrors["braintreeInitializeError"] = "Apple Pay: Braintree library is not initialized";
8076
+ })(ApplePayErrors || (ApplePayErrors = {}));
8077
+
8078
+ class ApplePaySessionHandlerAbstract {
8079
+ constructor() {
8080
+ this.payment = new Subject();
8081
+ this._errorSubject = new Subject();
8082
+ }
8083
+ get error$() {
8084
+ return this._errorSubject.asObservable();
8085
+ }
8086
+ get payment$() {
8087
+ return this.payment.asObservable();
8088
+ }
8089
+ emitError(error) {
8090
+ this._errorSubject.next(error);
8091
+ }
8092
+ buildPaymentRequest(params) {
8093
+ return {
8094
+ total: {
8095
+ label: params.totalLabel,
8096
+ amount: params.totalAmount,
8097
+ },
8098
+ currencyCode: params.currencyCode,
8099
+ countryCode: params.countryCode,
8100
+ merchantCapabilities: params.merchantCapabilities,
8101
+ requiredBillingContactFields: params.requiredBillingContactFields,
8102
+ requiredShippingContactFields: params.requiredShippingContactFields,
8103
+ supportedNetworks: params.supportedNetworks,
8104
+ };
8105
+ }
8106
+ }
8107
+
8108
+ class BraintreeHandler extends ApplePaySessionHandlerAbstract {
8109
+ constructor(window, elkLoggerService) {
8110
+ super();
8111
+ this.window = window;
8112
+ this.elkLoggerService = elkLoggerService;
8113
+ this.paymentClient = null;
8114
+ }
8115
+ setClient(client) {
8116
+ this.paymentClient = client;
8117
+ }
8118
+ startSession(params, iframeIntegrationEnabled) {
8119
+ if (!this.paymentClient) {
8120
+ console.error(ApplePayErrors.braintreeInitializeError);
8121
+ this.elkLoggerService.log(ApplePayErrors.braintreeInitializeError, [
8122
+ ErrorTags.APPLEPAY,
8123
+ ]);
8124
+ return;
8125
+ }
8126
+ const request = this.buildPaymentRequest(params);
8127
+ const applePayRequest = this.paymentClient.createPaymentRequest(request);
8128
+ const session = new this.window.ApplePaySession(applePayVersion, applePayRequest);
8129
+ session.onvalidatemerchant = (event) => {
8130
+ const validationParams = {
8131
+ validationURL: event.validationURL,
8132
+ displayName: params.totalLabel,
8133
+ };
8134
+ if (iframeIntegrationEnabled && params.topLevelDomain) {
8135
+ // @ts-expect-error unknown property
8136
+ validationParams.domainName = params.topLevelDomain;
8137
+ }
8138
+ this.paymentClient
8139
+ ?.performValidation(validationParams)
8140
+ .then((merchantSession) => {
8141
+ session.completeMerchantValidation(merchantSession);
8142
+ })
8143
+ .catch((error) => {
8144
+ console.error(ApplePayErrors.merchantValidationError, error);
8145
+ session.abort();
8146
+ });
8147
+ };
8148
+ session.onpaymentauthorized = (event) => {
8149
+ this.paymentClient
8150
+ ?.tokenize({ token: event.payment.token })
8151
+ .then((response) => {
8152
+ this.payment.next(JSON.stringify({
8153
+ token: response?.nonce ?? '',
8154
+ email: event.payment.billingContact?.emailAddress ?? null,
8155
+ postalCode: event.payment.billingContact?.postalCode ?? null,
8156
+ }));
8157
+ session.completePayment(this.window.ApplePaySession.STATUS_SUCCESS);
8158
+ })
8159
+ .catch((error) => {
8160
+ console.error('Apple Pay: Tokenization error', error);
8161
+ session.completePayment(this.window.ApplePaySession.STATUS_FAILURE);
8162
+ });
8163
+ };
8164
+ session.oncancel = () => {
8165
+ console.error(ApplePayErrors.cancelled);
8166
+ this.emitError(ApplePayErrors.cancelled);
8167
+ };
8168
+ session.begin();
8169
+ }
8170
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: BraintreeHandler, deps: [{ token: windowToken }, { token: ElkLoggerService }], target: i0.ɵɵFactoryTarget.Injectable }); }
8171
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: BraintreeHandler }); }
8172
+ }
8173
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: BraintreeHandler, decorators: [{
8174
+ type: Injectable
8175
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
8176
+ type: Inject,
8177
+ args: [windowToken]
8178
+ }] }, { type: ElkLoggerService }] });
8179
+
8180
+ class CheckoutHandler extends ApplePaySessionHandlerAbstract {
8181
+ constructor(window, http) {
8182
+ super();
8183
+ this.window = window;
8184
+ this.http = http;
8185
+ }
8186
+ startSession(params, iframeIntegrationEnabled) {
8187
+ const request = this.buildPaymentRequest(params);
8188
+ const session = new this.window.ApplePaySession(applePayVersion, request);
8189
+ session.onvalidatemerchant = (event) => {
8190
+ const validationParams = {
8191
+ validationURL: event.validationURL,
8192
+ accountId: params.payInstanceAccountId,
8193
+ isSandbox: params.isSandbox,
8194
+ };
8195
+ if (iframeIntegrationEnabled && params.topLevelDomain) {
8196
+ // @ts-expect-error unknown property
8197
+ validationParams.domainName = params.topLevelDomain;
8198
+ }
8199
+ this.http
8200
+ .post(params.getApplePaySessionUrl, JSON.stringify(validationParams), {
8201
+ headers: new HttpHeaders().set('Content-Type', 'application/json'),
8202
+ })
8203
+ .subscribe({
8204
+ next: (response) => {
8205
+ session.completeMerchantValidation(response.merchantSession);
8206
+ },
8207
+ error: (error) => {
8208
+ console.error(ApplePayErrors.merchantValidationError, error);
8209
+ session.abort();
8210
+ },
8211
+ });
8212
+ };
8213
+ session.onpaymentauthorized = (event) => {
8214
+ this.payment.next(JSON.stringify({
8215
+ token: event.payment.token ?? '',
8216
+ email: event.payment.billingContact?.emailAddress ?? null,
8217
+ postalCode: event.payment.billingContact?.postalCode ?? null,
8218
+ }));
8219
+ session.completePayment(this.window.ApplePaySession.STATUS_SUCCESS);
8220
+ };
8221
+ session.oncancel = () => {
8222
+ console.error(ApplePayErrors.cancelled);
8223
+ this.emitError(ApplePayErrors.cancelled);
8224
+ };
8225
+ session.begin();
8226
+ }
8227
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CheckoutHandler, deps: [{ token: windowToken }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
8228
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CheckoutHandler }); }
8229
+ }
8230
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CheckoutHandler, decorators: [{
8231
+ type: Injectable
8232
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
8233
+ type: Inject,
8234
+ args: [windowToken]
8235
+ }] }, { type: i1.HttpClient }] });
8236
+
8064
8237
  class CoreLibraryModule {
8065
8238
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
8066
8239
  static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryModule, imports: [HttpClientModule, FormModule, PipesModule] }); }
@@ -8100,6 +8273,8 @@ class CoreLibraryModule {
8100
8273
  printInstructionRequestFactoryProvider,
8101
8274
  sendInstructionRequestFactoryProvider,
8102
8275
  sendInstructionStatusResponseFactoryProvider,
8276
+ BraintreeHandler,
8277
+ CheckoutHandler,
8103
8278
  ], imports: [HttpClientModule, FormModule, PipesModule] }); }
8104
8279
  }
8105
8280
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryModule, decorators: [{
@@ -8142,6 +8317,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8142
8317
  printInstructionRequestFactoryProvider,
8143
8318
  sendInstructionRequestFactoryProvider,
8144
8319
  sendInstructionStatusResponseFactoryProvider,
8320
+ BraintreeHandler,
8321
+ CheckoutHandler,
8145
8322
  ],
8146
8323
  }]
8147
8324
  }] });
@@ -8590,7 +8767,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8590
8767
  args: [windowToken]
8591
8768
  }] }, { type: ElkLoggerService }, { type: PaymentSystemProcessingService }, { type: GooglePayCheckoutPaymentService }, { type: GooglePayInstantPaymentService }, { type: i0.Injector }] });
8592
8769
 
8593
- const applePayVersion = 3;
8770
+ var ApplePayIntegrationType;
8771
+ (function (ApplePayIntegrationType) {
8772
+ ApplePayIntegrationType["redirect"] = "redirect";
8773
+ ApplePayIntegrationType["native"] = "native";
8774
+ })(ApplePayIntegrationType || (ApplePayIntegrationType = {}));
8594
8775
 
8595
8776
  const agreementsGroup = [
8596
8777
  FieldNames.licenseDisclaimer,
@@ -8608,11 +8789,91 @@ const agreementsGroup = [
8608
8789
  FieldNames.koreaLimitsInstruction,
8609
8790
  ];
8610
8791
 
8611
- var ApplePayErrors;
8612
- (function (ApplePayErrors) {
8613
- ApplePayErrors["paymentError"] = "paymentError";
8614
- ApplePayErrors["deviceIsNotCapableError"] = "deviceIsNotCapableError";
8615
- })(ApplePayErrors || (ApplePayErrors = {}));
8792
+ class ApplePayParamsBuilderService {
8793
+ constructor() {
8794
+ this.agreementFieldsNames = agreementsGroup;
8795
+ }
8796
+ buildParams(paymentForm) {
8797
+ const { fields, summary } = paymentForm;
8798
+ if (!fields || !summary)
8799
+ return null;
8800
+ const formFields = fields.reduce((acc, field) => {
8801
+ if (this.agreementFieldsNames.includes(field.name) &&
8802
+ field.isVisible === "1" /* XpsBoolean.true */) {
8803
+ acc[field.name] = field.title;
8804
+ }
8805
+ else {
8806
+ acc[field.name] = field.value;
8807
+ }
8808
+ return acc;
8809
+ }, {});
8810
+ const agreements = this.agreementFieldsNames
8811
+ .map((fieldName) => [fieldName, formFields[fieldName]])
8812
+ .filter((fieldEntry) => {
8813
+ const [, value] = fieldEntry;
8814
+ return !!value;
8815
+ });
8816
+ return {
8817
+ tokenKey: this.getAppleToken(fields),
8818
+ totalLabel: formFields[FieldNames.labelApplePay] ?? '',
8819
+ totalAmount: this.getTotalAmount(summary),
8820
+ currencyCode: this.getTotalCurrency(summary),
8821
+ countryCode: formFields[FieldNames.countryCode] ?? '',
8822
+ merchantCapabilities: this.getJsonValueFromField(formFields, FieldNames.merchantCapabilities),
8823
+ requiredBillingContactFields: this.getJsonValueFromField(formFields, FieldNames.requiredBillingContactFields),
8824
+ requiredShippingContactFields: this.getJsonValueFromField(formFields, FieldNames.requiredShippingContactFields),
8825
+ supportedNetworks: this.getJsonValueFromField(formFields, FieldNames.supportedNetworks),
8826
+ agreements,
8827
+ acquirer: formFields[FieldNames.acquirer] ?? '',
8828
+ isSandbox: formFields[FieldNames.isSandbox] ?? '',
8829
+ payInstanceAccountId: formFields[FieldNames.payInstanceAccountId] ?? '',
8830
+ getApplePaySessionUrl: formFields[FieldNames.getApplePaySessionUrl] ?? '',
8831
+ payViaCheckoutUrl: formFields[FieldNames.payViaCheckoutUrl] ?? '',
8832
+ };
8833
+ }
8834
+ updateParams(params, summary) {
8835
+ return {
8836
+ ...params,
8837
+ totalAmount: this.getTotalAmount(summary),
8838
+ currencyCode: this.getTotalCurrency(summary),
8839
+ };
8840
+ }
8841
+ getJsonValueFromField(fields, fieldName) {
8842
+ const field = fields[fieldName];
8843
+ try {
8844
+ return field ? JSON.parse(field) : undefined;
8845
+ }
8846
+ catch (error) {
8847
+ return undefined;
8848
+ }
8849
+ }
8850
+ getAppleToken(fields) {
8851
+ const appleTokenField = fields.find((field) => {
8852
+ return field.name === 'token_key';
8853
+ });
8854
+ if (!appleTokenField) {
8855
+ return '';
8856
+ }
8857
+ return appleTokenField.value;
8858
+ }
8859
+ getTotalAmount(summary) {
8860
+ const finance = summary?.finance;
8861
+ const total = finance?.grand_total?.amount ?? finance?.total.amount;
8862
+ return total?.toString() ?? '';
8863
+ }
8864
+ getTotalCurrency(summary) {
8865
+ const finance = summary?.finance;
8866
+ return finance?.grand_total?.currency ?? finance?.total?.currency ?? '';
8867
+ }
8868
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayParamsBuilderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
8869
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayParamsBuilderService, providedIn: 'root' }); }
8870
+ }
8871
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayParamsBuilderService, decorators: [{
8872
+ type: Injectable,
8873
+ args: [{
8874
+ providedIn: 'root',
8875
+ }]
8876
+ }] });
8616
8877
 
8617
8878
  class ApplePayService {
8618
8879
  get paymentParameters() {
@@ -8627,11 +8888,14 @@ class ApplePayService {
8627
8888
  get integrationType$() {
8628
8889
  return this.integrationType.asObservable();
8629
8890
  }
8630
- constructor(window, userAgentService, summaryFinanceDetailsAdapterService) {
8891
+ constructor(window, userAgentService, summaryFinanceDetailsAdapterService, braintreeHandler, checkoutHandler, appleParamsBuilder, elkLoggerService) {
8631
8892
  this.window = window;
8632
8893
  this.userAgentService = userAgentService;
8633
8894
  this.summaryFinanceDetailsAdapterService = summaryFinanceDetailsAdapterService;
8634
- this.agreementFieldsNames = agreementsGroup;
8895
+ this.braintreeHandler = braintreeHandler;
8896
+ this.checkoutHandler = checkoutHandler;
8897
+ this.appleParamsBuilder = appleParamsBuilder;
8898
+ this.elkLoggerService = elkLoggerService;
8635
8899
  this.payment = new Subject();
8636
8900
  this.error = new Subject();
8637
8901
  this.integrationType = new Subject();
@@ -8639,48 +8903,18 @@ class ApplePayService {
8639
8903
  this.applePayParams = null;
8640
8904
  this.order = null;
8641
8905
  this.api = this.loadBraintree();
8906
+ this.subscribeToHandlers();
8642
8907
  }
8643
8908
  setApplePayParams(data) {
8644
- const formFields = data?.paymentForm?.fields;
8645
- const summary = data?.paymentForm?.summary;
8909
+ const paymentForm = data?.paymentForm;
8910
+ const formFields = paymentForm?.fields;
8911
+ const summary = paymentForm?.summary;
8646
8912
  if (!formFields || !summary) {
8647
8913
  return;
8648
8914
  }
8649
- const fields = formFields.reduce((acc, field) => {
8650
- if (this.agreementFieldsNames.includes(field.name) &&
8651
- field.isVisible === '1') {
8652
- acc[field.name] = field.title;
8653
- }
8654
- else {
8655
- acc[field.name] = field.value;
8656
- }
8657
- return acc;
8658
- }, {});
8659
- const agreements = this.agreementFieldsNames
8660
- .map((fieldName) => [fieldName, fields[fieldName]])
8661
- .filter((fieldEntry) => {
8662
- const [, value] = fieldEntry;
8663
- return !!value;
8664
- });
8665
- this.applePayParams = {
8666
- tokenKey: this.getAppleToken(formFields),
8667
- totalLabel: fields[FieldNames.labelApplePay] ?? '',
8668
- totalAmount: this.getTotalAmount(summary),
8669
- currencyCode: this.getTotalCurrency(summary),
8670
- countryCode: fields[FieldNames.countryCode] ?? '',
8671
- merchantCapabilities: this.getJsonValueFromField(fields, FieldNames.merchantCapabilities),
8672
- requiredBillingContactFields: this.getJsonValueFromField(fields, FieldNames.requiredBillingContactFields),
8673
- requiredShippingContactFields: this.getJsonValueFromField(fields, FieldNames.requiredShippingContactFields),
8674
- supportedNetworks: this.getJsonValueFromField(fields, FieldNames.supportedNetworks),
8675
- agreements: agreements,
8676
- acquirer: fields[FieldNames.acquirer] ?? '',
8677
- isSandbox: fields[FieldNames.isSandbox] ?? '',
8678
- payInstanceAccountId: fields[FieldNames.payInstanceAccountId] ?? '',
8679
- getApplePaySessionUrl: fields[FieldNames.getApplePaySessionUrl] ?? '',
8680
- payViaCheckoutUrl: fields[FieldNames.payViaCheckoutUrl] ?? '',
8681
- };
8915
+ this.applePayParams = this.appleParamsBuilder.buildParams(paymentForm);
8682
8916
  }
8683
- async initLibrary(tokenKey) {
8917
+ async initBraintreeLibrary(tokenKey) {
8684
8918
  try {
8685
8919
  const api = await this.api;
8686
8920
  const clientInstance = await api.client.create({
@@ -8689,12 +8923,16 @@ class ApplePayService {
8689
8923
  this.paymentClient = await api.applePay.create({
8690
8924
  client: clientInstance,
8691
8925
  });
8926
+ this.braintreeHandler.setClient(this.paymentClient);
8692
8927
  }
8693
8928
  catch (error) {
8694
- console.error('apple pay: initialize failed', error);
8929
+ console.error(ApplePayErrors.braintreeInitializeError, error);
8930
+ this.elkLoggerService.log(ApplePayErrors.braintreeInitializeError, [
8931
+ ErrorTags.APPLEPAY,
8932
+ ]);
8695
8933
  }
8696
8934
  this.emitIntegrationType();
8697
- if (!this.paymentClient || !this.isDeviceCapable()) {
8935
+ if (!this.paymentClient || !this.isDeviceCapable) {
8698
8936
  this.emitError(ApplePayErrors.deviceIsNotCapableError);
8699
8937
  }
8700
8938
  }
@@ -8734,7 +8972,7 @@ class ApplePayService {
8734
8972
  }, '');
8735
8973
  }
8736
8974
  }
8737
- isDeviceCapable() {
8975
+ get isDeviceCapable() {
8738
8976
  // Apple SDK is used on non-Safari devices.
8739
8977
  // Support of ApplePay payments will be defined on the external PS4 page
8740
8978
  if (!this.userAgentService.isSafari)
@@ -8757,54 +8995,49 @@ class ApplePayService {
8757
8995
  if (!this.applePayParams || !summary) {
8758
8996
  return;
8759
8997
  }
8760
- this.applePayParams.totalAmount = this.getTotalAmount(summary);
8761
- this.applePayParams.currencyCode = this.getTotalCurrency(summary);
8762
- }
8763
- async loadBraintree() {
8764
- const api = await import('braintree-web');
8765
- return api;
8998
+ this.applePayParams = this.appleParamsBuilder.updateParams(this.applePayParams, summary);
8766
8999
  }
8767
- getAppleToken(formFields) {
8768
- const appleTokenField = formFields.find((field) => {
8769
- return field.name === 'token_key';
8770
- });
8771
- if (!appleTokenField) {
8772
- return '';
9000
+ proceedCheckout(parameters, iframeIntegrationEnabled = false) {
9001
+ const sessionHandler = this.getSessionHandler(parameters.acquirer);
9002
+ if (!sessionHandler) {
9003
+ console.error('Apple Pay: Unsupported acquirer:', parameters.acquirer);
9004
+ return;
8773
9005
  }
8774
- return appleTokenField.value;
9006
+ sessionHandler.startSession(parameters, iframeIntegrationEnabled);
8775
9007
  }
8776
- getTotalAmount(summary) {
8777
- const finance = summary?.finance;
8778
- const total = finance?.grand_total?.amount ?? finance?.total.amount;
8779
- return total?.toString() ?? '';
8780
- }
8781
- getTotalCurrency(summary) {
8782
- const finance = summary?.finance;
8783
- return finance?.grand_total?.currency ?? finance?.total?.currency ?? '';
8784
- }
8785
- getJsonValueFromField(fields, fieldName) {
8786
- const field = fields[fieldName];
8787
- try {
8788
- return field ? JSON.parse(field) : undefined;
8789
- }
8790
- catch (error) {
8791
- return undefined;
9008
+ getSessionHandler(acquirer) {
9009
+ switch (acquirer) {
9010
+ case 'braintree':
9011
+ return this.braintreeHandler;
9012
+ case 'checkout':
9013
+ return this.checkoutHandler;
9014
+ default:
9015
+ return undefined;
8792
9016
  }
8793
9017
  }
9018
+ async loadBraintree() {
9019
+ const api = await import('braintree-web');
9020
+ return api;
9021
+ }
8794
9022
  emitError(error) {
8795
9023
  this.error.next(error);
8796
9024
  }
8797
9025
  emitIntegrationType() {
8798
- let integrationType;
8799
- if (this.paymentClient && this.isDeviceCapable()) {
8800
- integrationType = 'redirect';
9026
+ if (this.userAgentService.isSafari && this.isDeviceCapable) {
9027
+ this.integrationType.next(ApplePayIntegrationType.native);
8801
9028
  }
8802
- else {
8803
- integrationType = 'none';
9029
+ else if (this.paymentClient && this.isDeviceCapable) {
9030
+ this.integrationType.next(ApplePayIntegrationType.redirect);
8804
9031
  }
8805
- this.integrationType.next(integrationType);
8806
9032
  }
8807
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, deps: [{ token: windowToken }, { token: UserAgentService }, { token: SummaryFinanceDetailsAdapterService }], target: i0.ɵɵFactoryTarget.Injectable }); }
9033
+ subscribeToHandlers() {
9034
+ const handlers = [this.braintreeHandler, this.checkoutHandler];
9035
+ handlers.forEach((handler) => {
9036
+ handler.error$.subscribe((error) => this.emitError(error));
9037
+ handler.payment$.subscribe((token) => this.payment.next(token));
9038
+ });
9039
+ }
9040
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, deps: [{ token: windowToken }, { token: UserAgentService }, { token: SummaryFinanceDetailsAdapterService }, { token: BraintreeHandler }, { token: CheckoutHandler }, { token: ApplePayParamsBuilderService }, { token: ElkLoggerService }], target: i0.ɵɵFactoryTarget.Injectable }); }
8808
9041
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, providedIn: 'root' }); }
8809
9042
  }
8810
9043
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, decorators: [{
@@ -8815,7 +9048,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8815
9048
  }], ctorParameters: () => [{ type: undefined, decorators: [{
8816
9049
  type: Inject,
8817
9050
  args: [windowToken]
8818
- }] }, { type: UserAgentService }, { type: SummaryFinanceDetailsAdapterService }] });
9051
+ }] }, { type: UserAgentService }, { type: SummaryFinanceDetailsAdapterService }, { type: BraintreeHandler }, { type: CheckoutHandler }, { type: ApplePayParamsBuilderService }, { type: ElkLoggerService }] });
8819
9052
 
8820
9053
  /*
8821
9054
  * Public API Surface of core-library