@tap-payments/apple-pay-button 0.0.89-development → 0.0.90-development
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/build/@types/charge.d.ts +0 -1
- package/build/hooks/useApplePay.d.ts +64 -4
- package/build/hooks/useApplePay.js +28 -25
- package/build/hooks/useMerchantApplePay.d.ts +2 -1
- package/build/hooks/useMerchantApplePay.js +19 -18
- package/build/utils/config.d.ts +2 -2
- package/build/utils/config.js +4 -12
- package/package.json +2 -2
package/build/@types/charge.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ApplePayDataToLunchSDKFromMerchantSide, ApplePayRequestData } from '../@types';
|
|
1
|
+
import { ApplePayButtonProps, ApplePayDataToLunchSDKFromMerchantSide, ApplePayRequestData, IntegrationType } from '../@types';
|
|
2
|
+
import { Scope } from '@tap-payments/acceptance-sdk';
|
|
2
3
|
interface UseApplePayParams {
|
|
3
|
-
buttonProps:
|
|
4
|
+
buttonProps: ApplePayButtonProps;
|
|
4
5
|
}
|
|
5
6
|
export declare const useApplePay: ({ buttonProps }: UseApplePayParams) => {
|
|
6
7
|
onClick: () => void;
|
|
@@ -10,12 +11,71 @@ export declare const useApplePay: ({ buttonProps }: UseApplePayParams) => {
|
|
|
10
11
|
disabled: boolean;
|
|
11
12
|
applePayRequestData: ApplePayRequestData | undefined;
|
|
12
13
|
applePayRequestConfiguration: Omit<ApplePayDataToLunchSDKFromMerchantSide, "applePayRequestData"> | undefined;
|
|
13
|
-
mappedProps:
|
|
14
|
+
mappedProps: {
|
|
15
|
+
interface: {
|
|
16
|
+
locale?: import("@tap-payments/acceptance-sdk").Locale | undefined;
|
|
17
|
+
theme?: import("@tap-payments/acceptance-sdk").ThemeMode | undefined;
|
|
18
|
+
edges?: import("@tap-payments/acceptance-sdk").Edges | undefined;
|
|
19
|
+
colorStyle?: import("@tap-payments/acceptance-sdk").ColorStyle | undefined;
|
|
20
|
+
loader?: boolean | undefined;
|
|
21
|
+
userExperience?: (string & {}) | "popup" | "page" | undefined;
|
|
22
|
+
powered?: boolean | undefined;
|
|
23
|
+
direction?: import("@tap-payments/acceptance-sdk").Direction | undefined;
|
|
24
|
+
cardDirection?: import("@tap-payments/acceptance-sdk").Direction | undefined;
|
|
25
|
+
} | undefined;
|
|
26
|
+
merchant: import("@tap-payments/acceptance-sdk/build/@types").Merchant & {
|
|
27
|
+
identifier?: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
onClick?: ((data?: ApplePayDataToLunchSDKFromMerchantSide | undefined) => void) | undefined;
|
|
30
|
+
integration?: IntegrationType | undefined;
|
|
31
|
+
debug?: boolean | undefined;
|
|
32
|
+
scope: Scope;
|
|
33
|
+
order: import("@tap-payments/acceptance-sdk/build/@types").Order;
|
|
34
|
+
invoice?: import("@tap-payments/acceptance-sdk/build/@types").Invoice | undefined;
|
|
35
|
+
operator: import("@tap-payments/acceptance-sdk/build/@types").Operator;
|
|
36
|
+
customer: import("@tap-payments/acceptance-sdk").CustomerWithNameOnCard;
|
|
37
|
+
features?: import("@tap-payments/acceptance-sdk/build/@types").Features | undefined;
|
|
38
|
+
acceptance?: import("@tap-payments/acceptance-sdk/build/@types").Acceptance | undefined;
|
|
39
|
+
transaction?: import("@tap-payments/acceptance-sdk/build/@types").Transaction | undefined;
|
|
40
|
+
fieldVisibility?: import("@tap-payments/acceptance-sdk/build/@types").FieldVisibility | undefined;
|
|
41
|
+
post?: {
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
url: string;
|
|
44
|
+
} | undefined;
|
|
45
|
+
redirect?: {
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
url: string;
|
|
48
|
+
} | undefined;
|
|
49
|
+
metadata?: ({
|
|
50
|
+
headers?: ({
|
|
51
|
+
authorization: string;
|
|
52
|
+
mdn: string;
|
|
53
|
+
application: string;
|
|
54
|
+
ip?: string | undefined;
|
|
55
|
+
session?: string | undefined;
|
|
56
|
+
} & {
|
|
57
|
+
[x: string]: any;
|
|
58
|
+
}) | undefined;
|
|
59
|
+
profileData?: import("@tap-payments/acceptance-sdk").CheckoutProfileResponse | undefined;
|
|
60
|
+
} & {
|
|
61
|
+
[x: string]: any;
|
|
62
|
+
}) | undefined;
|
|
63
|
+
platform?: {
|
|
64
|
+
id: string;
|
|
65
|
+
} | undefined;
|
|
66
|
+
onReady?: (() => void) | undefined;
|
|
67
|
+
onError?: ((error: any) => void) | undefined;
|
|
68
|
+
onCancel?: (() => void) | undefined;
|
|
69
|
+
onSuccess?: ((data: any) => void) | undefined;
|
|
70
|
+
onBinIdentification?: ((data: any) => void) | undefined;
|
|
71
|
+
onChargeCreated?: ((charge: Record<string, any>) => void) | undefined;
|
|
72
|
+
onOrderCreated?: ((orderId: string) => void) | undefined;
|
|
73
|
+
};
|
|
14
74
|
theme: import("@tap-payments/acceptance-sdk").ThemeMode;
|
|
15
75
|
isRounded: boolean;
|
|
16
76
|
success: boolean;
|
|
17
77
|
error: boolean;
|
|
18
|
-
applePayPaymentMethodOptions: import("@tap-payments/acceptance-sdk").PaymentMethod | null;
|
|
78
|
+
applePayPaymentMethodOptions: import("@tap-payments/acceptance-sdk").PaymentMethod | null | undefined;
|
|
19
79
|
profileData: import("@tap-payments/acceptance-sdk").CheckoutProfileResponse | undefined;
|
|
20
80
|
};
|
|
21
81
|
export {};
|
|
@@ -47,12 +47,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
};
|
|
48
48
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
49
49
|
import { ApplePayVersion, MW_BASE_URL } from '../constants';
|
|
50
|
-
import { prepareApplePayRequest, shallRenderApplePay } from '../utils/config';
|
|
50
|
+
import { PAYMENT_METHOD_KEY, prepareApplePayRequest, shallRenderApplePay } from '../utils/config';
|
|
51
51
|
import { IntegrationType } from '../@types';
|
|
52
52
|
import { useMerchantApplePay } from './useMerchantApplePay';
|
|
53
|
-
import {
|
|
53
|
+
import { getDefaultThemeMode } from '../utils';
|
|
54
54
|
import appService, { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api';
|
|
55
|
-
import { areAllTheObjectStringValuesValid, ChargeCode, mappingInterface, Scope } from '@tap-payments/acceptance-sdk';
|
|
55
|
+
import { areAllTheObjectStringValuesValid, ChargeCode, getPaymentMethod, mappingInterface, Scope } from '@tap-payments/acceptance-sdk';
|
|
56
56
|
var FALLBACK_MERCHANT_IDENTIFIER = 'merchant.tap.gosell';
|
|
57
57
|
export var useApplePay = function (_a) {
|
|
58
58
|
var buttonProps = _a.buttonProps;
|
|
@@ -64,8 +64,8 @@ export var useApplePay = function (_a) {
|
|
|
64
64
|
var _g = useState(false), loading = _g[0], setLoading = _g[1];
|
|
65
65
|
var _h = useState(false), isRounded = _h[0], setIsRounded = _h[1];
|
|
66
66
|
var mappedProps = __assign(__assign({}, buttonProps), { interface: mappingInterface(buttonProps.interface) });
|
|
67
|
-
var
|
|
68
|
-
var
|
|
67
|
+
var interfaceObj = mappedProps.interface, merchant = mappedProps.merchant, customer = mappedProps.customer, acceptance = mappedProps.acceptance, scope = mappedProps.scope, debug = mappedProps.debug, onError = mappedProps.onError, onSuccess = mappedProps.onSuccess, onCancel = mappedProps.onCancel, onReady = mappedProps.onReady, metadata = mappedProps.metadata, operator = mappedProps.operator, order = mappedProps.order, onOrderCreated = mappedProps.onOrderCreated, transaction = mappedProps.transaction, post = mappedProps.post, redirect = mappedProps.redirect, integration = mappedProps.integration, features = mappedProps.features;
|
|
68
|
+
var _j = metadata || {}, profileData = _j.profileData, headers = _j.headers;
|
|
69
69
|
var isIframeIntegration = integration === IntegrationType.IFRAME;
|
|
70
70
|
var isWebViewIntegration = integration === IntegrationType.WEBVIEW;
|
|
71
71
|
useMerchantApplePay({
|
|
@@ -83,13 +83,14 @@ export var useApplePay = function (_a) {
|
|
|
83
83
|
redirect: redirect,
|
|
84
84
|
setError: setError,
|
|
85
85
|
setSuccess: setSuccess,
|
|
86
|
-
setLoading: setLoading
|
|
86
|
+
setLoading: setLoading,
|
|
87
|
+
features: features
|
|
87
88
|
});
|
|
88
89
|
var theme = useMemo(function () { return getDefaultThemeMode(interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.theme); }, [interfaceObj === null || interfaceObj === void 0 ? void 0 : interfaceObj.theme]);
|
|
89
90
|
var applePayPaymentMethodOptions = useMemo(function () {
|
|
90
91
|
if (!profileData)
|
|
91
92
|
return null;
|
|
92
|
-
return
|
|
93
|
+
return getPaymentMethod(profileData.payment_options.payment_methods || [], PAYMENT_METHOD_KEY);
|
|
93
94
|
}, [profileData]);
|
|
94
95
|
var merchantValidationRequestData = useMemo(function () {
|
|
95
96
|
if (!profileData)
|
|
@@ -112,6 +113,9 @@ export var useApplePay = function (_a) {
|
|
|
112
113
|
if (!shallRenderApplePay()) {
|
|
113
114
|
throw new Error('The device/customer is not eligible to use ApplePay');
|
|
114
115
|
}
|
|
116
|
+
if (!applePayPaymentMethodOptions) {
|
|
117
|
+
throw new Error("000::".concat(PAYMENT_METHOD_KEY.toUpperCase(), " is not configured in your payment options"));
|
|
118
|
+
}
|
|
115
119
|
if (!profileData) {
|
|
116
120
|
throw new Error('000::Profile data is not available');
|
|
117
121
|
}
|
|
@@ -224,15 +228,15 @@ export var useApplePay = function (_a) {
|
|
|
224
228
|
}); };
|
|
225
229
|
session_1.onpaymentauthorized = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
226
230
|
var _a, paymentData, paymentMethod, transactionIdentifier, _b, data, tokenId, supportCurrency, transactionRequest, transactionResponse, _c, successState, error_2;
|
|
227
|
-
var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
228
|
-
return __generator(this, function (
|
|
229
|
-
switch (
|
|
231
|
+
var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
|
|
232
|
+
return __generator(this, function (_4) {
|
|
233
|
+
switch (_4.label) {
|
|
230
234
|
case 0:
|
|
231
235
|
if (debug)
|
|
232
236
|
console.info('onpaymentauthorized event', event);
|
|
233
|
-
|
|
237
|
+
_4.label = 1;
|
|
234
238
|
case 1:
|
|
235
|
-
|
|
239
|
+
_4.trys.push([1, 16, 17, 18]);
|
|
236
240
|
_a = (_d = event.payment.token) !== null && _d !== void 0 ? _d : {}, paymentData = _a.paymentData, paymentMethod = _a.paymentMethod, transactionIdentifier = _a.transactionIdentifier;
|
|
237
241
|
_b = scope;
|
|
238
242
|
switch (_b) {
|
|
@@ -244,25 +248,25 @@ export var useApplePay = function (_a) {
|
|
|
244
248
|
return [3, 14];
|
|
245
249
|
case 2: return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(event.payment.token))];
|
|
246
250
|
case 3:
|
|
247
|
-
|
|
251
|
+
_4.sent();
|
|
248
252
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
249
253
|
return [3, 15];
|
|
250
254
|
case 4:
|
|
251
255
|
setLoading(true);
|
|
252
256
|
return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
|
|
253
257
|
case 5:
|
|
254
|
-
data =
|
|
258
|
+
data = _4.sent();
|
|
255
259
|
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
256
260
|
return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data))];
|
|
257
261
|
case 6:
|
|
258
|
-
|
|
262
|
+
_4.sent();
|
|
259
263
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
260
264
|
return [3, 15];
|
|
261
265
|
case 7:
|
|
262
266
|
setLoading(true);
|
|
263
267
|
return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
|
|
264
268
|
case 8:
|
|
265
|
-
tokenId = (
|
|
269
|
+
tokenId = (_4.sent()).id;
|
|
266
270
|
supportCurrency = ((_f = (_e = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _e === void 0 ? void 0 : _e.supported_currencies) !== null && _f !== void 0 ? _f : [])[0];
|
|
267
271
|
transactionRequest = {
|
|
268
272
|
auto: (_g = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _g === void 0 ? void 0 : _g.auto,
|
|
@@ -281,15 +285,14 @@ export var useApplePay = function (_a) {
|
|
|
281
285
|
number: (_x = (_w = (_v = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _v === void 0 ? void 0 : _v.phone) === null || _w === void 0 ? void 0 : _w.number) !== null && _x !== void 0 ? _x : ''
|
|
282
286
|
}
|
|
283
287
|
},
|
|
284
|
-
fee: 0,
|
|
285
288
|
merchant: {
|
|
286
289
|
id: (_z = (_y = profileData === null || profileData === void 0 ? void 0 : profileData.merchant) === null || _y === void 0 ? void 0 : _y.id) !== null && _z !== void 0 ? _z : ''
|
|
287
290
|
},
|
|
288
291
|
order: (_0 = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _0 === void 0 ? void 0 : _0.order,
|
|
289
292
|
product: 'Apple-Pay-Button',
|
|
290
|
-
save_card:
|
|
293
|
+
save_card: !!((_1 = features === null || features === void 0 ? void 0 : features.customerCards) === null || _1 === void 0 ? void 0 : _1.saveCard),
|
|
291
294
|
source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
|
|
292
|
-
threeDSecure: transaction === null || transaction === void 0 ? void 0 : transaction.
|
|
295
|
+
threeDSecure: (_3 = (_2 = transaction === null || transaction === void 0 ? void 0 : transaction.authenticate) === null || _2 === void 0 ? void 0 : _2.required) !== null && _3 !== void 0 ? _3 : true,
|
|
293
296
|
hashstring: operator.hashstring,
|
|
294
297
|
redirect: redirect,
|
|
295
298
|
metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
|
|
@@ -304,12 +307,12 @@ export var useApplePay = function (_a) {
|
|
|
304
307
|
if (!(scope === Scope.AUTHORIZE)) return [3, 10];
|
|
305
308
|
return [4, appService.createAuthorize(transactionRequest)];
|
|
306
309
|
case 9:
|
|
307
|
-
_c =
|
|
310
|
+
_c = _4.sent();
|
|
308
311
|
return [3, 12];
|
|
309
312
|
case 10: return [4, appService.createCharge(transactionRequest)];
|
|
310
313
|
case 11:
|
|
311
|
-
_c =
|
|
312
|
-
|
|
314
|
+
_c = _4.sent();
|
|
315
|
+
_4.label = 12;
|
|
313
316
|
case 12:
|
|
314
317
|
transactionResponse = _c;
|
|
315
318
|
successState = scope === Scope.AUTHORIZE ? ChargeCode.AUTHORIZED : ChargeCode.SUCCESS;
|
|
@@ -321,17 +324,17 @@ export var useApplePay = function (_a) {
|
|
|
321
324
|
}
|
|
322
325
|
return [4, (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse))];
|
|
323
326
|
case 13:
|
|
324
|
-
|
|
327
|
+
_4.sent();
|
|
325
328
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
326
329
|
return [3, 15];
|
|
327
330
|
case 14:
|
|
328
331
|
console.error('We only support AppleToken and TapToken for now');
|
|
329
332
|
console.info('Completing payment with status: STATUS_FAILURE');
|
|
330
333
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
331
|
-
|
|
334
|
+
_4.label = 15;
|
|
332
335
|
case 15: return [3, 18];
|
|
333
336
|
case 16:
|
|
334
|
-
error_2 =
|
|
337
|
+
error_2 = _4.sent();
|
|
335
338
|
if (debug)
|
|
336
339
|
console.error('error in onpaymentauthorized', error_2);
|
|
337
340
|
setError(true);
|
|
@@ -16,6 +16,7 @@ interface ApplePayRequestData {
|
|
|
16
16
|
operator: ApplePayButtonProps['operator'];
|
|
17
17
|
redirect?: ApplePayButtonProps['redirect'];
|
|
18
18
|
post?: ApplePayButtonProps['post'];
|
|
19
|
+
features?: ApplePayButtonProps['features'];
|
|
19
20
|
}
|
|
20
|
-
export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, setLoading, setError, setSuccess, scope, profileData, order, customer, transaction, operator, redirect, post }: ApplePayRequestData) => void;
|
|
21
|
+
export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, setLoading, setError, setSuccess, scope, profileData, order, customer, transaction, operator, redirect, post, features }: ApplePayRequestData) => void;
|
|
21
22
|
export {};
|
|
@@ -48,25 +48,27 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
48
|
import * as React from 'react';
|
|
49
49
|
import appService from '../api';
|
|
50
50
|
import { CHARGE_CODE } from '../@types';
|
|
51
|
-
import { Scope } from '@tap-payments/acceptance-sdk';
|
|
51
|
+
import { getPaymentMethod, Scope } from '@tap-payments/acceptance-sdk';
|
|
52
|
+
import { PAYMENT_METHOD_KEY } from '../utils';
|
|
52
53
|
var EVENT_NAME = 'TAP_BUTTON::APPLE_PAY_ON_PAYMENT_AUTHORIZED';
|
|
53
54
|
export var useMerchantApplePay = function (_a) {
|
|
54
|
-
var isIframeIntegration = _a.isIframeIntegration, onError = _a.onError, onSuccess = _a.onSuccess, setLoading = _a.setLoading, setError = _a.setError, setSuccess = _a.setSuccess, scope = _a.scope, profileData = _a.profileData, order = _a.order, customer = _a.customer, transaction = _a.transaction, operator = _a.operator, redirect = _a.redirect, post = _a.post;
|
|
55
|
+
var isIframeIntegration = _a.isIframeIntegration, onError = _a.onError, onSuccess = _a.onSuccess, setLoading = _a.setLoading, setError = _a.setError, setSuccess = _a.setSuccess, scope = _a.scope, profileData = _a.profileData, order = _a.order, customer = _a.customer, transaction = _a.transaction, operator = _a.operator, redirect = _a.redirect, post = _a.post, features = _a.features;
|
|
55
56
|
var onMessageReceived = React.useCallback(function (_a) {
|
|
56
57
|
var message = _a.data;
|
|
57
58
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
58
|
-
var _b, event, data, _c, paymentData, paymentMethod, transactionIdentifier, _d, response, tokenId, supportCurrency, transactionRequest, transactionResponse, _e, successState, e_1;
|
|
59
|
-
var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
|
|
60
|
-
return __generator(this, function (
|
|
61
|
-
switch (
|
|
59
|
+
var _b, event, data, _c, paymentData, paymentMethod, transactionIdentifier, applyPayPaymentMethod, _d, response, tokenId, supportCurrency, transactionRequest, transactionResponse, _e, successState, e_1;
|
|
60
|
+
var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5;
|
|
61
|
+
return __generator(this, function (_6) {
|
|
62
|
+
switch (_6.label) {
|
|
62
63
|
case 0:
|
|
63
64
|
_b = message !== null && message !== void 0 ? message : {}, event = _b.event, data = _b.data;
|
|
64
65
|
if (!data || event !== EVENT_NAME)
|
|
65
66
|
return [2];
|
|
66
67
|
_c = data !== null && data !== void 0 ? data : {}, paymentData = _c.paymentData, paymentMethod = _c.paymentMethod, transactionIdentifier = _c.transactionIdentifier;
|
|
67
|
-
|
|
68
|
+
applyPayPaymentMethod = getPaymentMethod((profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.payment_methods) || [], PAYMENT_METHOD_KEY);
|
|
69
|
+
_6.label = 1;
|
|
68
70
|
case 1:
|
|
69
|
-
|
|
71
|
+
_6.trys.push([1, 13, 14, 15]);
|
|
70
72
|
_d = scope;
|
|
71
73
|
switch (_d) {
|
|
72
74
|
case Scope.APPLE_PAY_TOKEN: return [3, 2];
|
|
@@ -82,7 +84,7 @@ export var useMerchantApplePay = function (_a) {
|
|
|
82
84
|
setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
|
|
83
85
|
return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
|
|
84
86
|
case 4:
|
|
85
|
-
response =
|
|
87
|
+
response = _6.sent();
|
|
86
88
|
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
87
89
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
|
|
88
90
|
return [3, 12];
|
|
@@ -90,7 +92,7 @@ export var useMerchantApplePay = function (_a) {
|
|
|
90
92
|
setLoading === null || setLoading === void 0 ? void 0 : setLoading(true);
|
|
91
93
|
return [4, appService.tapTokenization(__assign(__assign({}, paymentData), { paymentMethod: paymentMethod, transactionIdentifier: transactionIdentifier }))];
|
|
92
94
|
case 6:
|
|
93
|
-
tokenId = (
|
|
95
|
+
tokenId = (_6.sent()).id;
|
|
94
96
|
supportCurrency = ((_g = (_f = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _f === void 0 ? void 0 : _f.supported_currencies) !== null && _g !== void 0 ? _g : [])[0];
|
|
95
97
|
transactionRequest = {
|
|
96
98
|
auto: (_h = transaction === null || transaction === void 0 ? void 0 : transaction.authorize) === null || _h === void 0 ? void 0 : _h.auto,
|
|
@@ -109,15 +111,14 @@ export var useMerchantApplePay = function (_a) {
|
|
|
109
111
|
number: (_y = (_x = (_w = customer === null || customer === void 0 ? void 0 : customer.contact) === null || _w === void 0 ? void 0 : _w.phone) === null || _x === void 0 ? void 0 : _x.number) !== null && _y !== void 0 ? _y : ''
|
|
110
112
|
}
|
|
111
113
|
},
|
|
112
|
-
fee: 0,
|
|
113
114
|
merchant: {
|
|
114
115
|
id: (_0 = (_z = profileData === null || profileData === void 0 ? void 0 : profileData.merchant) === null || _z === void 0 ? void 0 : _z.id) !== null && _0 !== void 0 ? _0 : ''
|
|
115
116
|
},
|
|
116
117
|
order: (_1 = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options) === null || _1 === void 0 ? void 0 : _1.order,
|
|
117
118
|
product: 'Apple-Pay-Button',
|
|
118
|
-
save_card:
|
|
119
|
+
save_card: !!((_2 = features === null || features === void 0 ? void 0 : features.customerCards) === null || _2 === void 0 ? void 0 : _2.saveCard),
|
|
119
120
|
source: { id: tokenId !== null && tokenId !== void 0 ? tokenId : '' },
|
|
120
|
-
threeDSecure: transaction === null || transaction === void 0 ? void 0 : transaction.
|
|
121
|
+
threeDSecure: (_4 = (_3 = transaction === null || transaction === void 0 ? void 0 : transaction.authenticate) === null || _3 === void 0 ? void 0 : _3.required) !== null && _4 !== void 0 ? _4 : true,
|
|
121
122
|
hashstring: operator.hashstring,
|
|
122
123
|
redirect: redirect,
|
|
123
124
|
metadata: transaction === null || transaction === void 0 ? void 0 : transaction.metadata,
|
|
@@ -132,12 +133,12 @@ export var useMerchantApplePay = function (_a) {
|
|
|
132
133
|
if (!(scope === Scope.AUTHORIZE)) return [3, 8];
|
|
133
134
|
return [4, appService.createAuthorize(transactionRequest)];
|
|
134
135
|
case 7:
|
|
135
|
-
_e =
|
|
136
|
+
_e = _6.sent();
|
|
136
137
|
return [3, 10];
|
|
137
138
|
case 8: return [4, appService.createCharge(transactionRequest)];
|
|
138
139
|
case 9:
|
|
139
|
-
_e =
|
|
140
|
-
|
|
140
|
+
_e = _6.sent();
|
|
141
|
+
_6.label = 10;
|
|
141
142
|
case 10:
|
|
142
143
|
transactionResponse = _e;
|
|
143
144
|
successState = scope === Scope.AUTHORIZE ? CHARGE_CODE.AUTHORIZED : CHARGE_CODE.SUCCESS;
|
|
@@ -155,14 +156,14 @@ export var useMerchantApplePay = function (_a) {
|
|
|
155
156
|
return [3, 12];
|
|
156
157
|
case 12: return [3, 15];
|
|
157
158
|
case 13:
|
|
158
|
-
e_1 =
|
|
159
|
+
e_1 = _6.sent();
|
|
159
160
|
if (!onError)
|
|
160
161
|
return [2];
|
|
161
162
|
if (e_1.errors) {
|
|
162
163
|
onError(e_1.errors);
|
|
163
164
|
return [2];
|
|
164
165
|
}
|
|
165
|
-
if ((
|
|
166
|
+
if ((_5 = e_1.response) === null || _5 === void 0 ? void 0 : _5.data.errors) {
|
|
166
167
|
onError(e_1.response.data.errors);
|
|
167
168
|
return [2];
|
|
168
169
|
}
|
package/build/utils/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Acceptance, ApplePayButtonProps, ApplePayRequestData, ProfileData } from '../@types';
|
|
2
|
+
export declare const PAYMENT_METHOD_KEY = "apple_pay";
|
|
2
3
|
export declare const validateSupportedNetworks: (supportedNetworksOptions: Acceptance['supportedSchemes'], merchantSupportedNetworks?: Acceptance['supportedSchemes']) => Acceptance['supportedSchemes'];
|
|
3
|
-
export declare const getApplePayPaymentMethod: (paymentMethods: ProfileData['payment_options']['payment_methods']) => import("@tap-payments/acceptance-sdk").PaymentMethod;
|
|
4
4
|
export declare const getApplePayRequest: ({ order, customer, supportedNetworks, merchantCapabilities, countryCode, name }: Pick<ApplePayButtonProps, "order" | "customer"> & {
|
|
5
5
|
supportedNetworks: Acceptance['supportedSchemes'];
|
|
6
6
|
merchantCapabilities: ApplePayRequestData['merchantCapabilities'];
|
|
@@ -9,6 +9,6 @@ export declare const getApplePayRequest: ({ order, customer, supportedNetworks,
|
|
|
9
9
|
}) => ApplePayRequestData;
|
|
10
10
|
export declare const prepareApplePayRequest: ({ payment_options, merchant, order, customer, acceptance }: ProfileData & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) => {
|
|
11
11
|
applePaySessionRequest: ApplePayRequestData;
|
|
12
|
-
paymentMethod: import("@tap-payments/acceptance-sdk").PaymentMethod;
|
|
12
|
+
paymentMethod: import("@tap-payments/acceptance-sdk").PaymentMethod | undefined;
|
|
13
13
|
};
|
|
14
14
|
export declare const shallRenderApplePay: () => boolean;
|
package/build/utils/config.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { getMerchantCapabilities } from './defaultValues';
|
|
2
|
+
import { getPaymentMethod } from '@tap-payments/acceptance-sdk';
|
|
3
|
+
export var PAYMENT_METHOD_KEY = 'apple_pay';
|
|
2
4
|
export var validateSupportedNetworks = function (supportedNetworksOptions, merchantSupportedNetworks) {
|
|
3
5
|
var toLowerCase = function (item) { return item.toLowerCase(); };
|
|
4
6
|
if (!supportedNetworksOptions)
|
|
@@ -15,16 +17,6 @@ export var validateSupportedNetworks = function (supportedNetworksOptions, merch
|
|
|
15
17
|
}
|
|
16
18
|
return supportedNetworks.map(toLowerCase);
|
|
17
19
|
};
|
|
18
|
-
export var getApplePayPaymentMethod = function (paymentMethods) {
|
|
19
|
-
var paymentMethod = paymentMethods.find(function (_a) {
|
|
20
|
-
var name = _a.name, payment_type = _a.payment_type;
|
|
21
|
-
return [name, payment_type].some(function (item) { return item.toLowerCase() === 'apple_pay'; });
|
|
22
|
-
});
|
|
23
|
-
if (!paymentMethod) {
|
|
24
|
-
throw new Error('apple_pay is not configured in your payment options');
|
|
25
|
-
}
|
|
26
|
-
return paymentMethod;
|
|
27
|
-
};
|
|
28
20
|
export var getApplePayRequest = function (_a) {
|
|
29
21
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
30
22
|
var order = _a.order, customer = _a.customer, supportedNetworks = _a.supportedNetworks, merchantCapabilities = _a.merchantCapabilities, countryCode = _a.countryCode, name = _a.name;
|
|
@@ -47,8 +39,8 @@ export var getApplePayRequest = function (_a) {
|
|
|
47
39
|
};
|
|
48
40
|
export var prepareApplePayRequest = function (_a) {
|
|
49
41
|
var payment_options = _a.payment_options, merchant = _a.merchant, order = _a.order, customer = _a.customer, acceptance = _a.acceptance;
|
|
50
|
-
var paymentMethod =
|
|
51
|
-
var supportedNetworks = validateSupportedNetworks(paymentMethod.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedSchemes);
|
|
42
|
+
var paymentMethod = getPaymentMethod(payment_options.payment_methods || [], PAYMENT_METHOD_KEY);
|
|
43
|
+
var supportedNetworks = validateSupportedNetworks(paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.supported_card_brands, acceptance === null || acceptance === void 0 ? void 0 : acceptance.supportedSchemes);
|
|
52
44
|
var request = getApplePayRequest({
|
|
53
45
|
countryCode: merchant.country_code,
|
|
54
46
|
order: order,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/apple-pay-button",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.90-development",
|
|
4
4
|
"description": "Apple Pay Button React Component",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"module": "build/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"license": "ISC",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@tap-payments/acceptance-sdk": "0.0.
|
|
32
|
+
"@tap-payments/acceptance-sdk": "0.0.61",
|
|
33
33
|
"@tap-payments/browser-info": "^1.0.2",
|
|
34
34
|
"@tap-payments/web-error-handing": "^1.0.1",
|
|
35
35
|
"axios": "^1.2.2",
|