@xsolla/payment-client-core 0.2.45 → 0.2.47
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.
- package/esm2022/lib/core/agreements-group.const.mjs +17 -0
- package/esm2022/lib/core/extended-window.interface.mjs +1 -1
- package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay-integration.type.mjs +6 -2
- package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay-params-builder.service.mjs +90 -0
- package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay-session.interface.mjs +2 -0
- package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay.errors.enum.mjs +6 -3
- package/esm2022/lib/core/sdk-payment-systems/apple-pay/apple-pay.service.mjs +67 -87
- package/esm2022/lib/core/sdk-payment-systems/apple-pay/checkout-params.interface.mjs +1 -1
- package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/braintree.handler.mjs +83 -0
- package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/checkout.handler.mjs +68 -0
- package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.abstract.mjs +31 -0
- package/esm2022/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.type.mjs +2 -0
- package/esm2022/lib/core/settings/project.interface.mjs +1 -1
- package/esm2022/lib/core-library.module.mjs +7 -1
- package/esm2022/lib/core-library.service.mjs +4 -1
- package/fesm2022/xsolla-payment-client-core.mjs +326 -84
- package/fesm2022/xsolla-payment-client-core.mjs.map +1 -1
- package/lib/core/extended-window.interface.d.ts +1 -1
- package/lib/core/sdk-payment-systems/apple-pay/apple-pay-integration.type.d.ts +5 -1
- package/lib/core/sdk-payment-systems/apple-pay/apple-pay-params-builder.service.d.ts +15 -0
- package/lib/core/sdk-payment-systems/apple-pay/apple-pay-session.interface.d.ts +135 -0
- package/lib/core/sdk-payment-systems/apple-pay/apple-pay.errors.enum.d.ts +5 -2
- package/lib/core/sdk-payment-systems/apple-pay/apple-pay.service.d.ts +24 -13
- package/lib/core/sdk-payment-systems/apple-pay/checkout-params.interface.d.ts +1 -0
- package/lib/core/sdk-payment-systems/apple-pay/session-handlers/braintree.handler.d.ts +16 -0
- package/lib/core/sdk-payment-systems/apple-pay/session-handlers/checkout.handler.d.ts +13 -0
- package/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.abstract.d.ts +13 -0
- package/lib/core/sdk-payment-systems/apple-pay/session-handlers/session-handler.type.d.ts +3 -0
- package/lib/core/settings/project.interface.d.ts +1 -0
- package/lib/core-library.service.d.ts +3 -0
- package/package.json +1 -1
- package/xsolla-payment-client-core-0.2.47.tgz +0 -0
- package/esm2022/lib/core/agreementsGroup.const.mjs +0 -17
- package/xsolla-payment-client-core-0.2.45.tgz +0 -0
- /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,182 @@ 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
|
+
console.log('🟡[LOG] braintree onvalidatemerchant params.topLevelDomain :>>', params.topLevelDomain);
|
|
8135
|
+
if (iframeIntegrationEnabled && params.topLevelDomain) {
|
|
8136
|
+
// @ts-expect-error unknown property
|
|
8137
|
+
validationParams.domainName = params.topLevelDomain;
|
|
8138
|
+
}
|
|
8139
|
+
this.paymentClient
|
|
8140
|
+
?.performValidation(validationParams)
|
|
8141
|
+
.then((merchantSession) => {
|
|
8142
|
+
session.completeMerchantValidation(merchantSession);
|
|
8143
|
+
})
|
|
8144
|
+
.catch((error) => {
|
|
8145
|
+
console.error(ApplePayErrors.merchantValidationError, error);
|
|
8146
|
+
session.abort();
|
|
8147
|
+
});
|
|
8148
|
+
};
|
|
8149
|
+
session.onpaymentauthorized = (event) => {
|
|
8150
|
+
this.paymentClient
|
|
8151
|
+
?.tokenize({ token: event.payment.token })
|
|
8152
|
+
.then((response) => {
|
|
8153
|
+
console.log('🟡[LOG] braintree response :>>', response);
|
|
8154
|
+
this.payment.next(JSON.stringify({
|
|
8155
|
+
token: response?.nonce ?? '',
|
|
8156
|
+
email: event.payment.billingContact?.emailAddress ?? null,
|
|
8157
|
+
postalCode: event.payment.billingContact?.postalCode ?? null,
|
|
8158
|
+
}));
|
|
8159
|
+
session.completePayment(this.window.ApplePaySession.STATUS_SUCCESS);
|
|
8160
|
+
})
|
|
8161
|
+
.catch((error) => {
|
|
8162
|
+
console.log('🟡[LOG] braintree error :>>', error);
|
|
8163
|
+
console.error('Apple Pay: Tokenization error', error);
|
|
8164
|
+
session.completePayment(this.window.ApplePaySession.STATUS_FAILURE);
|
|
8165
|
+
});
|
|
8166
|
+
};
|
|
8167
|
+
session.oncancel = (event) => {
|
|
8168
|
+
console.error(ApplePayErrors.cancelled, event);
|
|
8169
|
+
this.emitError(ApplePayErrors.cancelled);
|
|
8170
|
+
};
|
|
8171
|
+
session.begin();
|
|
8172
|
+
}
|
|
8173
|
+
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 }); }
|
|
8174
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: BraintreeHandler }); }
|
|
8175
|
+
}
|
|
8176
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: BraintreeHandler, decorators: [{
|
|
8177
|
+
type: Injectable
|
|
8178
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
8179
|
+
type: Inject,
|
|
8180
|
+
args: [windowToken]
|
|
8181
|
+
}] }, { type: ElkLoggerService }] });
|
|
8182
|
+
|
|
8183
|
+
class CheckoutHandler extends ApplePaySessionHandlerAbstract {
|
|
8184
|
+
constructor(window, http) {
|
|
8185
|
+
super();
|
|
8186
|
+
this.window = window;
|
|
8187
|
+
this.http = http;
|
|
8188
|
+
}
|
|
8189
|
+
startSession(params, iframeIntegrationEnabled) {
|
|
8190
|
+
const request = this.buildPaymentRequest(params);
|
|
8191
|
+
const session = new this.window.ApplePaySession(applePayVersion, request);
|
|
8192
|
+
session.onvalidatemerchant = (event) => {
|
|
8193
|
+
const validationParams = {
|
|
8194
|
+
validationURL: event.validationURL,
|
|
8195
|
+
accountId: params.payInstanceAccountId,
|
|
8196
|
+
isSandbox: params.isSandbox,
|
|
8197
|
+
};
|
|
8198
|
+
console.log('🟡[LOG] checkout onvalidatemerchant params.topLevelDomain :>>', params.topLevelDomain);
|
|
8199
|
+
if (iframeIntegrationEnabled && params.topLevelDomain) {
|
|
8200
|
+
// @ts-expect-error unknown property
|
|
8201
|
+
validationParams.domainName = params.topLevelDomain;
|
|
8202
|
+
}
|
|
8203
|
+
this.http
|
|
8204
|
+
.post(params.getApplePaySessionUrl, JSON.stringify(validationParams), {
|
|
8205
|
+
headers: new HttpHeaders().set('Content-Type', 'application/json'),
|
|
8206
|
+
})
|
|
8207
|
+
.subscribe({
|
|
8208
|
+
next: (response) => {
|
|
8209
|
+
console.log('🟡[LOG] checkout http response :>>', response);
|
|
8210
|
+
session.completeMerchantValidation(response.merchantSession);
|
|
8211
|
+
},
|
|
8212
|
+
error: (error) => {
|
|
8213
|
+
console.error(ApplePayErrors.merchantValidationError, error);
|
|
8214
|
+
session.abort();
|
|
8215
|
+
},
|
|
8216
|
+
});
|
|
8217
|
+
};
|
|
8218
|
+
session.onpaymentauthorized = (event) => {
|
|
8219
|
+
console.log('🟡[LOG] checkout onpaymentauthorized :>>', event);
|
|
8220
|
+
this.payment.next(JSON.stringify({
|
|
8221
|
+
token: event.payment.token ?? '',
|
|
8222
|
+
email: event.payment.billingContact?.emailAddress ?? null,
|
|
8223
|
+
postalCode: event.payment.billingContact?.postalCode ?? null,
|
|
8224
|
+
}));
|
|
8225
|
+
session.completePayment(this.window.ApplePaySession.STATUS_SUCCESS);
|
|
8226
|
+
};
|
|
8227
|
+
session.oncancel = (event) => {
|
|
8228
|
+
console.error(ApplePayErrors.cancelled, event);
|
|
8229
|
+
this.emitError(ApplePayErrors.cancelled);
|
|
8230
|
+
};
|
|
8231
|
+
session.begin();
|
|
8232
|
+
}
|
|
8233
|
+
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 }); }
|
|
8234
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CheckoutHandler }); }
|
|
8235
|
+
}
|
|
8236
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CheckoutHandler, decorators: [{
|
|
8237
|
+
type: Injectable
|
|
8238
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
8239
|
+
type: Inject,
|
|
8240
|
+
args: [windowToken]
|
|
8241
|
+
}] }, { type: i1.HttpClient }] });
|
|
8242
|
+
|
|
8064
8243
|
class CoreLibraryModule {
|
|
8065
8244
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
8066
8245
|
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryModule, imports: [HttpClientModule, FormModule, PipesModule] }); }
|
|
@@ -8100,6 +8279,8 @@ class CoreLibraryModule {
|
|
|
8100
8279
|
printInstructionRequestFactoryProvider,
|
|
8101
8280
|
sendInstructionRequestFactoryProvider,
|
|
8102
8281
|
sendInstructionStatusResponseFactoryProvider,
|
|
8282
|
+
BraintreeHandler,
|
|
8283
|
+
CheckoutHandler,
|
|
8103
8284
|
], imports: [HttpClientModule, FormModule, PipesModule] }); }
|
|
8104
8285
|
}
|
|
8105
8286
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: CoreLibraryModule, decorators: [{
|
|
@@ -8142,6 +8323,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
|
|
|
8142
8323
|
printInstructionRequestFactoryProvider,
|
|
8143
8324
|
sendInstructionRequestFactoryProvider,
|
|
8144
8325
|
sendInstructionStatusResponseFactoryProvider,
|
|
8326
|
+
BraintreeHandler,
|
|
8327
|
+
CheckoutHandler,
|
|
8145
8328
|
],
|
|
8146
8329
|
}]
|
|
8147
8330
|
}] });
|
|
@@ -8590,7 +8773,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
|
|
|
8590
8773
|
args: [windowToken]
|
|
8591
8774
|
}] }, { type: ElkLoggerService }, { type: PaymentSystemProcessingService }, { type: GooglePayCheckoutPaymentService }, { type: GooglePayInstantPaymentService }, { type: i0.Injector }] });
|
|
8592
8775
|
|
|
8593
|
-
|
|
8776
|
+
var ApplePayIntegrationType;
|
|
8777
|
+
(function (ApplePayIntegrationType) {
|
|
8778
|
+
ApplePayIntegrationType["redirect"] = "redirect";
|
|
8779
|
+
ApplePayIntegrationType["native"] = "native";
|
|
8780
|
+
})(ApplePayIntegrationType || (ApplePayIntegrationType = {}));
|
|
8594
8781
|
|
|
8595
8782
|
const agreementsGroup = [
|
|
8596
8783
|
FieldNames.licenseDisclaimer,
|
|
@@ -8608,11 +8795,91 @@ const agreementsGroup = [
|
|
|
8608
8795
|
FieldNames.koreaLimitsInstruction,
|
|
8609
8796
|
];
|
|
8610
8797
|
|
|
8611
|
-
|
|
8612
|
-
(
|
|
8613
|
-
|
|
8614
|
-
|
|
8615
|
-
|
|
8798
|
+
class ApplePayParamsBuilderService {
|
|
8799
|
+
constructor() {
|
|
8800
|
+
this.agreementFieldsNames = agreementsGroup;
|
|
8801
|
+
}
|
|
8802
|
+
buildParams(paymentForm) {
|
|
8803
|
+
const { fields, summary } = paymentForm;
|
|
8804
|
+
if (!fields || !summary)
|
|
8805
|
+
return null;
|
|
8806
|
+
const formFields = fields.reduce((acc, field) => {
|
|
8807
|
+
if (this.agreementFieldsNames.includes(field.name) &&
|
|
8808
|
+
field.isVisible === "1" /* XpsBoolean.true */) {
|
|
8809
|
+
acc[field.name] = field.title;
|
|
8810
|
+
}
|
|
8811
|
+
else {
|
|
8812
|
+
acc[field.name] = field.value;
|
|
8813
|
+
}
|
|
8814
|
+
return acc;
|
|
8815
|
+
}, {});
|
|
8816
|
+
const agreements = this.agreementFieldsNames
|
|
8817
|
+
.map((fieldName) => [fieldName, formFields[fieldName]])
|
|
8818
|
+
.filter((fieldEntry) => {
|
|
8819
|
+
const [, value] = fieldEntry;
|
|
8820
|
+
return !!value;
|
|
8821
|
+
});
|
|
8822
|
+
return {
|
|
8823
|
+
tokenKey: this.getAppleToken(fields),
|
|
8824
|
+
totalLabel: formFields[FieldNames.labelApplePay] ?? '',
|
|
8825
|
+
totalAmount: this.getTotalAmount(summary),
|
|
8826
|
+
currencyCode: this.getTotalCurrency(summary),
|
|
8827
|
+
countryCode: formFields[FieldNames.countryCode] ?? '',
|
|
8828
|
+
merchantCapabilities: this.getJsonValueFromField(formFields, FieldNames.merchantCapabilities),
|
|
8829
|
+
requiredBillingContactFields: this.getJsonValueFromField(formFields, FieldNames.requiredBillingContactFields),
|
|
8830
|
+
requiredShippingContactFields: this.getJsonValueFromField(formFields, FieldNames.requiredShippingContactFields),
|
|
8831
|
+
supportedNetworks: this.getJsonValueFromField(formFields, FieldNames.supportedNetworks),
|
|
8832
|
+
agreements,
|
|
8833
|
+
acquirer: formFields[FieldNames.acquirer] ?? '',
|
|
8834
|
+
isSandbox: formFields[FieldNames.isSandbox] ?? '',
|
|
8835
|
+
payInstanceAccountId: formFields[FieldNames.payInstanceAccountId] ?? '',
|
|
8836
|
+
getApplePaySessionUrl: formFields[FieldNames.getApplePaySessionUrl] ?? '',
|
|
8837
|
+
payViaCheckoutUrl: formFields[FieldNames.payViaCheckoutUrl] ?? '',
|
|
8838
|
+
};
|
|
8839
|
+
}
|
|
8840
|
+
updateParams(params, summary) {
|
|
8841
|
+
return {
|
|
8842
|
+
...params,
|
|
8843
|
+
totalAmount: this.getTotalAmount(summary),
|
|
8844
|
+
currencyCode: this.getTotalCurrency(summary),
|
|
8845
|
+
};
|
|
8846
|
+
}
|
|
8847
|
+
getJsonValueFromField(fields, fieldName) {
|
|
8848
|
+
const field = fields[fieldName];
|
|
8849
|
+
try {
|
|
8850
|
+
return field ? JSON.parse(field) : undefined;
|
|
8851
|
+
}
|
|
8852
|
+
catch (error) {
|
|
8853
|
+
return undefined;
|
|
8854
|
+
}
|
|
8855
|
+
}
|
|
8856
|
+
getAppleToken(fields) {
|
|
8857
|
+
const appleTokenField = fields.find((field) => {
|
|
8858
|
+
return field.name === 'token_key';
|
|
8859
|
+
});
|
|
8860
|
+
if (!appleTokenField) {
|
|
8861
|
+
return '';
|
|
8862
|
+
}
|
|
8863
|
+
return appleTokenField.value;
|
|
8864
|
+
}
|
|
8865
|
+
getTotalAmount(summary) {
|
|
8866
|
+
const finance = summary?.finance;
|
|
8867
|
+
const total = finance?.grand_total?.amount ?? finance?.total.amount;
|
|
8868
|
+
return total?.toString() ?? '';
|
|
8869
|
+
}
|
|
8870
|
+
getTotalCurrency(summary) {
|
|
8871
|
+
const finance = summary?.finance;
|
|
8872
|
+
return finance?.grand_total?.currency ?? finance?.total?.currency ?? '';
|
|
8873
|
+
}
|
|
8874
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayParamsBuilderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
8875
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayParamsBuilderService, providedIn: 'root' }); }
|
|
8876
|
+
}
|
|
8877
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayParamsBuilderService, decorators: [{
|
|
8878
|
+
type: Injectable,
|
|
8879
|
+
args: [{
|
|
8880
|
+
providedIn: 'root',
|
|
8881
|
+
}]
|
|
8882
|
+
}] });
|
|
8616
8883
|
|
|
8617
8884
|
class ApplePayService {
|
|
8618
8885
|
get paymentParameters() {
|
|
@@ -8627,11 +8894,14 @@ class ApplePayService {
|
|
|
8627
8894
|
get integrationType$() {
|
|
8628
8895
|
return this.integrationType.asObservable();
|
|
8629
8896
|
}
|
|
8630
|
-
constructor(window, userAgentService, summaryFinanceDetailsAdapterService) {
|
|
8897
|
+
constructor(window, userAgentService, summaryFinanceDetailsAdapterService, braintreeHandler, checkoutHandler, appleParamsBuilder, elkLoggerService) {
|
|
8631
8898
|
this.window = window;
|
|
8632
8899
|
this.userAgentService = userAgentService;
|
|
8633
8900
|
this.summaryFinanceDetailsAdapterService = summaryFinanceDetailsAdapterService;
|
|
8634
|
-
this.
|
|
8901
|
+
this.braintreeHandler = braintreeHandler;
|
|
8902
|
+
this.checkoutHandler = checkoutHandler;
|
|
8903
|
+
this.appleParamsBuilder = appleParamsBuilder;
|
|
8904
|
+
this.elkLoggerService = elkLoggerService;
|
|
8635
8905
|
this.payment = new Subject();
|
|
8636
8906
|
this.error = new Subject();
|
|
8637
8907
|
this.integrationType = new Subject();
|
|
@@ -8639,48 +8909,18 @@ class ApplePayService {
|
|
|
8639
8909
|
this.applePayParams = null;
|
|
8640
8910
|
this.order = null;
|
|
8641
8911
|
this.api = this.loadBraintree();
|
|
8912
|
+
this.subscribeToHandlers();
|
|
8642
8913
|
}
|
|
8643
8914
|
setApplePayParams(data) {
|
|
8644
|
-
const
|
|
8645
|
-
const
|
|
8915
|
+
const paymentForm = data?.paymentForm;
|
|
8916
|
+
const formFields = paymentForm?.fields;
|
|
8917
|
+
const summary = paymentForm?.summary;
|
|
8646
8918
|
if (!formFields || !summary) {
|
|
8647
8919
|
return;
|
|
8648
8920
|
}
|
|
8649
|
-
|
|
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
|
-
};
|
|
8921
|
+
this.applePayParams = this.appleParamsBuilder.buildParams(paymentForm);
|
|
8682
8922
|
}
|
|
8683
|
-
async
|
|
8923
|
+
async initBraintreeLibrary(tokenKey) {
|
|
8684
8924
|
try {
|
|
8685
8925
|
const api = await this.api;
|
|
8686
8926
|
const clientInstance = await api.client.create({
|
|
@@ -8689,12 +8929,16 @@ class ApplePayService {
|
|
|
8689
8929
|
this.paymentClient = await api.applePay.create({
|
|
8690
8930
|
client: clientInstance,
|
|
8691
8931
|
});
|
|
8932
|
+
this.braintreeHandler.setClient(this.paymentClient);
|
|
8692
8933
|
}
|
|
8693
8934
|
catch (error) {
|
|
8694
|
-
console.error(
|
|
8935
|
+
console.error(ApplePayErrors.braintreeInitializeError, error);
|
|
8936
|
+
this.elkLoggerService.log(ApplePayErrors.braintreeInitializeError, [
|
|
8937
|
+
ErrorTags.APPLEPAY,
|
|
8938
|
+
]);
|
|
8695
8939
|
}
|
|
8696
8940
|
this.emitIntegrationType();
|
|
8697
|
-
if (!this.paymentClient || !this.isDeviceCapable
|
|
8941
|
+
if (!this.paymentClient || !this.isDeviceCapable) {
|
|
8698
8942
|
this.emitError(ApplePayErrors.deviceIsNotCapableError);
|
|
8699
8943
|
}
|
|
8700
8944
|
}
|
|
@@ -8734,7 +8978,7 @@ class ApplePayService {
|
|
|
8734
8978
|
}, '');
|
|
8735
8979
|
}
|
|
8736
8980
|
}
|
|
8737
|
-
isDeviceCapable() {
|
|
8981
|
+
get isDeviceCapable() {
|
|
8738
8982
|
// Apple SDK is used on non-Safari devices.
|
|
8739
8983
|
// Support of ApplePay payments will be defined on the external PS4 page
|
|
8740
8984
|
if (!this.userAgentService.isSafari)
|
|
@@ -8757,54 +9001,52 @@ class ApplePayService {
|
|
|
8757
9001
|
if (!this.applePayParams || !summary) {
|
|
8758
9002
|
return;
|
|
8759
9003
|
}
|
|
8760
|
-
this.applePayParams
|
|
8761
|
-
this.applePayParams.currencyCode = this.getTotalCurrency(summary);
|
|
8762
|
-
}
|
|
8763
|
-
async loadBraintree() {
|
|
8764
|
-
const api = await import('braintree-web');
|
|
8765
|
-
return api;
|
|
9004
|
+
this.applePayParams = this.appleParamsBuilder.updateParams(this.applePayParams, summary);
|
|
8766
9005
|
}
|
|
8767
|
-
|
|
8768
|
-
const
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
return '';
|
|
9006
|
+
proceedCheckout(parameters, iframeIntegrationEnabled = false) {
|
|
9007
|
+
const sessionHandler = this.getSessionHandler(parameters.acquirer);
|
|
9008
|
+
if (!sessionHandler) {
|
|
9009
|
+
console.error('Apple Pay: Unsupported acquirer:', parameters.acquirer);
|
|
9010
|
+
return;
|
|
8773
9011
|
}
|
|
8774
|
-
|
|
9012
|
+
sessionHandler.startSession(parameters, iframeIntegrationEnabled);
|
|
8775
9013
|
}
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
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;
|
|
9014
|
+
getSessionHandler(acquirer) {
|
|
9015
|
+
switch (acquirer) {
|
|
9016
|
+
case 'braintree':
|
|
9017
|
+
return this.braintreeHandler;
|
|
9018
|
+
case 'checkout':
|
|
9019
|
+
return this.checkoutHandler;
|
|
9020
|
+
default:
|
|
9021
|
+
return undefined;
|
|
8792
9022
|
}
|
|
8793
9023
|
}
|
|
9024
|
+
async loadBraintree() {
|
|
9025
|
+
const api = await import('braintree-web');
|
|
9026
|
+
return api;
|
|
9027
|
+
}
|
|
8794
9028
|
emitError(error) {
|
|
8795
9029
|
this.error.next(error);
|
|
8796
9030
|
}
|
|
8797
9031
|
emitIntegrationType() {
|
|
8798
|
-
|
|
8799
|
-
|
|
8800
|
-
integrationType = 'redirect';
|
|
9032
|
+
if (this.userAgentService.isSafari && this.isDeviceCapable) {
|
|
9033
|
+
this.integrationType.next(ApplePayIntegrationType.native);
|
|
8801
9034
|
}
|
|
8802
|
-
else {
|
|
8803
|
-
integrationType
|
|
9035
|
+
else if (this.paymentClient && this.isDeviceCapable) {
|
|
9036
|
+
this.integrationType.next(ApplePayIntegrationType.redirect);
|
|
8804
9037
|
}
|
|
8805
|
-
this.integrationType.next(integrationType);
|
|
8806
9038
|
}
|
|
8807
|
-
|
|
9039
|
+
subscribeToHandlers() {
|
|
9040
|
+
const handlers = [this.braintreeHandler, this.checkoutHandler];
|
|
9041
|
+
handlers.forEach((handler) => {
|
|
9042
|
+
handler.error$.subscribe((error) => this.emitError(error));
|
|
9043
|
+
handler.payment$.subscribe((token) => {
|
|
9044
|
+
console.log('🟡[LOG] payment token :>>', token);
|
|
9045
|
+
this.payment.next(token);
|
|
9046
|
+
});
|
|
9047
|
+
});
|
|
9048
|
+
}
|
|
9049
|
+
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
9050
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, providedIn: 'root' }); }
|
|
8809
9051
|
}
|
|
8810
9052
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ApplePayService, decorators: [{
|
|
@@ -8815,7 +9057,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
|
|
|
8815
9057
|
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
8816
9058
|
type: Inject,
|
|
8817
9059
|
args: [windowToken]
|
|
8818
|
-
}] }, { type: UserAgentService }, { type: SummaryFinanceDetailsAdapterService }] });
|
|
9060
|
+
}] }, { type: UserAgentService }, { type: SummaryFinanceDetailsAdapterService }, { type: BraintreeHandler }, { type: CheckoutHandler }, { type: ApplePayParamsBuilderService }, { type: ElkLoggerService }] });
|
|
8819
9061
|
|
|
8820
9062
|
/*
|
|
8821
9063
|
* Public API Surface of core-library
|