@tap-payments/apple-pay-button 0.0.57-development → 0.0.58-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/components/ActionButton/ActionButton.js +2 -1
- package/build/components/InitialLoader/InitialLoader.js +3 -6
- package/build/components/PayButton/PayButton.d.ts +1 -0
- package/build/components/PayButton/PayButton.js +2 -2
- package/build/components/PayButton/style.d.ts +0 -6
- package/build/components/PayButton/style.js +0 -22
- package/build/features/ApplePayButton/ApplePayButton.js +3 -3
- package/build/features/ApplePayButton/style.d.ts +4 -1
- package/build/features/ApplePayButton/style.js +19 -11
- package/build/hooks/useApplePay.js +12 -5
- package/build/hooks/useMerchantApplePay.d.ts +4 -1
- package/build/hooks/useMerchantApplePay.js +17 -5
- package/package.json +1 -1
|
@@ -50,7 +50,8 @@ export default function ActionButton(props) {
|
|
|
50
50
|
background: background
|
|
51
51
|
}, '&:disabled': {
|
|
52
52
|
background: background,
|
|
53
|
-
color: textColor
|
|
53
|
+
color: textColor,
|
|
54
|
+
pointerEvents: 'none'
|
|
54
55
|
} }, sx), disabled: disabled, rounded: rounded, onClick: onClick }, rest, { children: children })));
|
|
55
56
|
}
|
|
56
57
|
ActionButton.defaultProps = {
|
|
@@ -11,19 +11,16 @@ var StyledLottie = styled(Lottie, {
|
|
|
11
11
|
return ({
|
|
12
12
|
border: 'none',
|
|
13
13
|
width: '100%',
|
|
14
|
-
borderRadius: edges === Edges.STRAIGHT ? '
|
|
14
|
+
borderRadius: edges === Edges.STRAIGHT ? '0px' : '30px',
|
|
15
15
|
overflow: 'hidden',
|
|
16
16
|
height: '48px',
|
|
17
17
|
maxWidth: '360px',
|
|
18
|
-
minWidth: '170px'
|
|
19
|
-
'& svg': {
|
|
20
|
-
width: '100%'
|
|
21
|
-
}
|
|
18
|
+
minWidth: '170px'
|
|
22
19
|
});
|
|
23
20
|
});
|
|
24
21
|
export default function InitialLoader(_a) {
|
|
25
22
|
var open = _a.open, themeMode = _a.themeMode, edges = _a.edges;
|
|
26
23
|
if (!open)
|
|
27
24
|
return null;
|
|
28
|
-
return (_jsx(StyledLottie, { animationData: themeMode === ThemeMode.DARK ? DarkLoader : LightLoader, edges: edges, loop: true }));
|
|
25
|
+
return (_jsx(StyledLottie, { "data-testid": 'InitialLoader-StyledLottie', animationData: themeMode === ThemeMode.DARK ? DarkLoader : LightLoader, edges: edges, loop: true }));
|
|
29
26
|
}
|
|
@@ -20,7 +20,7 @@ import BlackErrorGif from '../../assets/gif/error-black.gif';
|
|
|
20
20
|
import { StyledContainerLoader } from './style';
|
|
21
21
|
import { Edges, ThemeMode } from '../../@types/enums';
|
|
22
22
|
var PayButton = function (_a) {
|
|
23
|
-
var theme = _a.theme, isRounded = _a.isRounded, isFailed = _a.isFailed, isSuccess = _a.isSuccess, bgColor = _a.bgColor, gradientColor = _a.gradientColor, edges = _a.edges, titleAsset = _a.titleAsset, onClick = _a.onClick;
|
|
23
|
+
var theme = _a.theme, isRounded = _a.isRounded, isFailed = _a.isFailed, isSuccess = _a.isSuccess, disabled = _a.disabled, bgColor = _a.bgColor, gradientColor = _a.gradientColor, edges = _a.edges, titleAsset = _a.titleAsset, onClick = _a.onClick;
|
|
24
24
|
var renderButtonLabel = function () {
|
|
25
25
|
if (isFailed) {
|
|
26
26
|
return _jsx("img", { src: theme === ThemeMode.DARK ? BlackErrorGif : WhiteErrorGif, alt: 'error', width: 30, height: 30 });
|
|
@@ -33,7 +33,7 @@ var PayButton = function (_a) {
|
|
|
33
33
|
}
|
|
34
34
|
return _jsx("img", { src: titleAsset, alt: 'logo' });
|
|
35
35
|
};
|
|
36
|
-
return (_jsx(StyledContainerLoader, __assign({ "data-testid": 'PayButton', "data-src": 'apple-pay-button-element', "data-is-rounded": isRounded, "data-is-error": isFailed, "data-is-success": isSuccess, edges: edges }, { children: _jsx(ActionButton, __assign({ "data-testid": 'PayButton-ActionButton', "data-src": 'apple-pay-button-element', "data-is-error": isFailed, "data-is-success": isSuccess, gradientColor: gradientColor, bgColor: bgColor, rounded: isRounded, onClick: onClick, style: {
|
|
36
|
+
return (_jsx(StyledContainerLoader, __assign({ "data-testid": 'PayButton', "data-src": 'apple-pay-button-element', "data-is-rounded": isRounded, "data-is-error": isFailed, "data-is-success": isSuccess, edges: edges }, { children: _jsx(ActionButton, __assign({ "data-testid": 'PayButton-ActionButton', "data-src": 'apple-pay-button-element', "data-is-error": isFailed, "data-is-success": isSuccess, gradientColor: gradientColor, bgColor: bgColor, rounded: isRounded, onClick: onClick, disabled: disabled, style: {
|
|
37
37
|
borderRadius: edges === Edges.STRAIGHT ? '0px' : '30px'
|
|
38
38
|
} }, { children: renderButtonLabel() })) })));
|
|
39
39
|
};
|
|
@@ -3,9 +3,3 @@ import { Edges } from '../../@types';
|
|
|
3
3
|
export declare const StyledContainerLoader: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
|
|
4
4
|
edges?: Edges | undefined;
|
|
5
5
|
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, {}>;
|
|
6
|
-
export declare const DisabledButton: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
|
|
7
|
-
edges?: Edges | undefined;
|
|
8
|
-
backgroundColor?: string | undefined;
|
|
9
|
-
color?: string | undefined;
|
|
10
|
-
font?: string | undefined;
|
|
11
|
-
}, import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, {}>;
|
|
@@ -17,25 +17,3 @@ export var StyledContainerLoader = styled('section', {
|
|
|
17
17
|
overflow: 'hidden'
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
|
-
export var DisabledButton = styled('button', {
|
|
21
|
-
shouldForwardProp: function (prop) { return !['edges', 'backgroundColor', 'color', 'font'].includes(prop); }
|
|
22
|
-
})(function (_a) {
|
|
23
|
-
var edges = _a.edges, backgroundColor = _a.backgroundColor, color = _a.color, font = _a.font;
|
|
24
|
-
return ({
|
|
25
|
-
border: 'none',
|
|
26
|
-
width: 'calc(100% - 16px)',
|
|
27
|
-
borderRadius: edges === Edges.STRAIGHT ? '0px' : '30px',
|
|
28
|
-
overflow: 'hidden',
|
|
29
|
-
height: '48px',
|
|
30
|
-
color: color,
|
|
31
|
-
backgroundColor: backgroundColor,
|
|
32
|
-
maxWidth: '360px',
|
|
33
|
-
minWidth: '170px',
|
|
34
|
-
pointerEvents: 'none',
|
|
35
|
-
cursor: 'not-allowed',
|
|
36
|
-
display: 'flex',
|
|
37
|
-
justifyContent: 'center',
|
|
38
|
-
alignItems: 'center',
|
|
39
|
-
font: font
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -19,14 +19,14 @@ import './ApplePayButton.css';
|
|
|
19
19
|
import { StyledContainer } from './style';
|
|
20
20
|
import PayButton from '../../components/PayButton';
|
|
21
21
|
var ApplePay = React.memo(function (props) {
|
|
22
|
-
var _a, _b, _c;
|
|
23
|
-
var
|
|
22
|
+
var _a, _b, _c, _d;
|
|
23
|
+
var _e = useApplePay({ buttonProps: props }), onClick = _e.onClick, loading = _e.loading, onApplePayButtonClicked = _e.onApplePayButtonClicked, disabled = _e.disabled, applePayRequestData = _e.applePayRequestData, isIframeIntegration = _e.isIframeIntegration, applePayRequestConfiguration = _e.applePayRequestConfiguration, mappedProps = _e.mappedProps, theme = _e.theme, isRounded = _e.isRounded, success = _e.success, error = _e.error, backgroundColor = _e.backgroundColor, gradientColor = _e.gradientColor, titleAsset = _e.titleAsset;
|
|
24
24
|
React.useEffect(function () {
|
|
25
25
|
if (props.debug) {
|
|
26
26
|
console.log('ApplePayButtonProps', props);
|
|
27
27
|
}
|
|
28
28
|
}, []);
|
|
29
|
-
return (_jsx(StyledContainer, __assign({ "data-src": 'apple-pay-button-element', "data-testid": 'ApplePayButton-section' }, { children: loading ? (_jsx(InitialLoader, { open: true, themeMode: (
|
|
29
|
+
return (_jsx(StyledContainer, __assign({ "data-src": 'apple-pay-button-element', "data-testid": 'ApplePayButton-section', edges: (_a = mappedProps.interface) === null || _a === void 0 ? void 0 : _a.edges }, { children: loading ? (_jsx(InitialLoader, { open: true, themeMode: (_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.theme, edges: (_c = mappedProps.interface) === null || _c === void 0 ? void 0 : _c.edges })) : (_jsx(_Fragment, { children: _jsx(PayButton, { "data-src": 'apple-pay-button-element', "data-testid": 'ApplePayButton', theme: theme, isRounded: isRounded, isSuccess: success, isFailed: error, bgColor: backgroundColor, gradientColor: gradientColor, titleAsset: titleAsset, edges: (_d = mappedProps.interface) === null || _d === void 0 ? void 0 : _d.edges, disabled: disabled, onClick: onClick }) })) })));
|
|
30
30
|
});
|
|
31
31
|
export function ApplePayButton(props) {
|
|
32
32
|
return _jsx(ApplePay, __assign({}, props));
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
2
|
+
import { Edges } from '../../@types';
|
|
3
|
+
export declare const StyledContainer: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
|
|
4
|
+
edges?: Edges | undefined;
|
|
5
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, {}>;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { styled } from '@mui/material';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
import { Edges } from '../../@types';
|
|
3
|
+
export var StyledContainer = styled('section', {
|
|
4
|
+
shouldForwardProp: function (prop) { return !['edges'].includes(prop); }
|
|
5
|
+
})(function (_a) {
|
|
6
|
+
var edges = _a.edges;
|
|
7
|
+
return ({
|
|
8
|
+
width: '100%',
|
|
9
|
+
display: 'flex',
|
|
10
|
+
borderRadius: edges === Edges.STRAIGHT ? '0px' : '30px',
|
|
11
|
+
overflow: 'hidden',
|
|
12
|
+
justifyContent: 'center',
|
|
13
|
+
alignItems: 'center',
|
|
14
|
+
flexDirection: 'column',
|
|
15
|
+
margin: '0 auto',
|
|
16
|
+
height: '48px',
|
|
17
|
+
maxWidth: '360px',
|
|
18
|
+
minWidth: '170px'
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -68,8 +68,9 @@ export var useApplePay = function (_a) {
|
|
|
68
68
|
var _r = useState(false), isRounded = _r[0], setIsRounded = _r[1];
|
|
69
69
|
var mappedProps = getDefaultValues(buttonProps);
|
|
70
70
|
var environment = mappedProps.environment, 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, headers = mappedProps.headers, operator = mappedProps.operator, order = mappedProps.order, onOrderCreated = mappedProps.onOrderCreated, integration = mappedProps.integration, transaction = mappedProps.transaction, post = mappedProps.post, redirect = mappedProps.redirect;
|
|
71
|
+
var isIframeIntegration = buttonProps.integration === 'iframe';
|
|
71
72
|
useMerchantApplePay({
|
|
72
|
-
isIframeIntegration:
|
|
73
|
+
isIframeIntegration: isIframeIntegration,
|
|
73
74
|
onError: onError,
|
|
74
75
|
onSuccess: onSuccess,
|
|
75
76
|
scope: scope,
|
|
@@ -80,11 +81,13 @@ export var useApplePay = function (_a) {
|
|
|
80
81
|
transaction: transaction,
|
|
81
82
|
operator: operator,
|
|
82
83
|
post: post,
|
|
83
|
-
redirect: redirect
|
|
84
|
+
redirect: redirect,
|
|
85
|
+
setError: setError,
|
|
86
|
+
setSuccess: setSuccess,
|
|
87
|
+
setIsRounded: setIsRounded
|
|
84
88
|
});
|
|
85
89
|
var lang = (_c = (_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.locale) !== null && _c !== void 0 ? _c : 'en';
|
|
86
90
|
var theme = getDefaultThemeMode((_d = mappedProps.interface) === null || _d === void 0 ? void 0 : _d.theme);
|
|
87
|
-
var isIframeIntegration = buttonProps.integration === 'iframe';
|
|
88
91
|
var applePayPaymentMethodOptions = useMemo(function () {
|
|
89
92
|
if (!profileData)
|
|
90
93
|
return null;
|
|
@@ -245,7 +248,7 @@ export var useApplePay = function (_a) {
|
|
|
245
248
|
console.info('Creating merchant session and validating merchant session');
|
|
246
249
|
console.info('onvalidatemerchant event', event);
|
|
247
250
|
}
|
|
248
|
-
|
|
251
|
+
setDisabled(true);
|
|
249
252
|
_a.label = 1;
|
|
250
253
|
case 1:
|
|
251
254
|
_a.trys.push([1, 3, , 4]);
|
|
@@ -267,7 +270,7 @@ export var useApplePay = function (_a) {
|
|
|
267
270
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
268
271
|
throw error_1;
|
|
269
272
|
case 4:
|
|
270
|
-
|
|
273
|
+
setDisabled(false);
|
|
271
274
|
return [2];
|
|
272
275
|
}
|
|
273
276
|
});
|
|
@@ -283,6 +286,7 @@ export var useApplePay = function (_a) {
|
|
|
283
286
|
_b.label = 1;
|
|
284
287
|
case 1:
|
|
285
288
|
_b.trys.push([1, 7, 8, 9]);
|
|
289
|
+
setIsRounded === null || setIsRounded === void 0 ? void 0 : setIsRounded(true);
|
|
286
290
|
_a = scope;
|
|
287
291
|
switch (_a) {
|
|
288
292
|
case Scope.APPLE_PAY_TOKEN: return [3, 2];
|
|
@@ -296,6 +300,7 @@ export var useApplePay = function (_a) {
|
|
|
296
300
|
case 3: return [4, appService.tapTokenization(event.payment.token.paymentData)];
|
|
297
301
|
case 4:
|
|
298
302
|
data = _b.sent();
|
|
303
|
+
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
299
304
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
300
305
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
301
306
|
return [3, 6];
|
|
@@ -309,10 +314,12 @@ export var useApplePay = function (_a) {
|
|
|
309
314
|
error_2 = _b.sent();
|
|
310
315
|
if (debug)
|
|
311
316
|
console.error('error in onpaymentauthorized', error_2);
|
|
317
|
+
setError(true);
|
|
312
318
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
313
319
|
throw error_2;
|
|
314
320
|
case 8:
|
|
315
321
|
setLoading(false);
|
|
322
|
+
setIsRounded === null || setIsRounded === void 0 ? void 0 : setIsRounded(false);
|
|
316
323
|
return [7];
|
|
317
324
|
case 9: return [2];
|
|
318
325
|
}
|
|
@@ -3,6 +3,9 @@ interface ApplePayRequestData {
|
|
|
3
3
|
isIframeIntegration: boolean;
|
|
4
4
|
onError?: (error: any) => void;
|
|
5
5
|
onSuccess?: (data: Record<string, any>) => void;
|
|
6
|
+
setIsRounded?: (loading: boolean) => void;
|
|
7
|
+
setSuccess?: (success: boolean) => void;
|
|
8
|
+
setError?: (error: boolean) => void;
|
|
6
9
|
scope: typeof Scope[keyof typeof Scope];
|
|
7
10
|
profileData?: Pick<MetaData, 'merchant' | 'payment_options'>;
|
|
8
11
|
merchant: Pick<MetaData['merchant'], 'id'>;
|
|
@@ -13,5 +16,5 @@ interface ApplePayRequestData {
|
|
|
13
16
|
redirect?: ApplePayButtonProps['redirect'];
|
|
14
17
|
post?: ApplePayButtonProps['post'];
|
|
15
18
|
}
|
|
16
|
-
export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, scope, profileData, order, customer, transaction, operator, redirect, post }: ApplePayRequestData) => void;
|
|
19
|
+
export declare const useMerchantApplePay: ({ isIframeIntegration, onError, onSuccess, merchant, setIsRounded, setError, setSuccess, scope, profileData, order, customer, transaction, operator, redirect, post }: ApplePayRequestData) => void;
|
|
17
20
|
export {};
|
|
@@ -36,14 +36,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
};
|
|
37
37
|
import * as React from 'react';
|
|
38
38
|
import appService from '../api/app.service';
|
|
39
|
-
import { Scope } from '../@types';
|
|
39
|
+
import { Scope, CHARGE_CODE } from '../@types';
|
|
40
40
|
var EVENT_NAME = 'TAP_BUTTON::APPLE_PAY_ON_PAYMENT_AUTHORIZED';
|
|
41
41
|
export var useMerchantApplePay = function (_a) {
|
|
42
|
-
var isIframeIntegration = _a.isIframeIntegration, onError = _a.onError, onSuccess = _a.onSuccess, scope = _a.scope, profileData = _a.profileData, order = _a.order, customer = _a.customer, transaction = _a.transaction, operator = _a.operator, redirect = _a.redirect, post = _a.post;
|
|
42
|
+
var isIframeIntegration = _a.isIframeIntegration, onError = _a.onError, onSuccess = _a.onSuccess, merchant = _a.merchant, setIsRounded = _a.setIsRounded, 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;
|
|
43
43
|
var onMessageReceived = React.useCallback(function (_a) {
|
|
44
44
|
var message = _a.data;
|
|
45
45
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
-
var _b, event, data, _c, response, tokenId, supportCurrency, transactionRequest, transactionResponse, _d, e_1;
|
|
46
|
+
var _b, event, data, _c, response, tokenId, supportCurrency, transactionRequest, transactionResponse, _d, successState, e_1;
|
|
47
47
|
var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
48
48
|
return __generator(this, function (_w) {
|
|
49
49
|
switch (_w.label) {
|
|
@@ -65,12 +65,17 @@ export var useMerchantApplePay = function (_a) {
|
|
|
65
65
|
case 2:
|
|
66
66
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
67
67
|
return [3, 12];
|
|
68
|
-
case 3:
|
|
68
|
+
case 3:
|
|
69
|
+
setIsRounded === null || setIsRounded === void 0 ? void 0 : setIsRounded(true);
|
|
70
|
+
return [4, appService.tapTokenization(data)];
|
|
69
71
|
case 4:
|
|
70
72
|
response = _w.sent();
|
|
73
|
+
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
71
74
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
|
|
72
75
|
return [3, 12];
|
|
73
|
-
case 5:
|
|
76
|
+
case 5:
|
|
77
|
+
setIsRounded === null || setIsRounded === void 0 ? void 0 : setIsRounded(true);
|
|
78
|
+
return [4, appService.tapTokenization(data)];
|
|
74
79
|
case 6:
|
|
75
80
|
tokenId = (_w.sent()).id;
|
|
76
81
|
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];
|
|
@@ -122,6 +127,13 @@ export var useMerchantApplePay = function (_a) {
|
|
|
122
127
|
_w.label = 10;
|
|
123
128
|
case 10:
|
|
124
129
|
transactionResponse = _d;
|
|
130
|
+
successState = scope === Scope.AUTHORIZE ? CHARGE_CODE.AUTHORIZED : CHARGE_CODE.SUCCESS;
|
|
131
|
+
if ((transactionResponse === null || transactionResponse === void 0 ? void 0 : transactionResponse.response.code) === successState) {
|
|
132
|
+
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
setError === null || setError === void 0 ? void 0 : setError(true);
|
|
136
|
+
}
|
|
125
137
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionResponse);
|
|
126
138
|
return [3, 12];
|
|
127
139
|
case 11:
|