@tap-payments/apple-pay-button 0.0.56-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/@types/ApplePayButtonProps.d.ts +3 -1
- package/build/components/ActionButton/ActionButton.d.ts +0 -7
- package/build/components/ActionButton/ActionButton.js +5 -4
- package/build/components/InitialLoader/InitialLoader.js +3 -6
- package/build/components/PayButton/PayButton.d.ts +1 -7
- 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 +5 -21
- package/build/features/ApplePayButton/style.d.ts +4 -1
- package/build/features/ApplePayButton/style.js +19 -11
- package/build/hooks/useApplePay.d.ts +87 -7
- package/build/hooks/useApplePay.js +102 -15
- package/build/hooks/useMerchantApplePay.d.ts +4 -1
- package/build/hooks/useMerchantApplePay.js +17 -5
- package/build/utils/config.d.ts +1 -1
- package/build/utils/config.js +10 -10
- package/build/utils/defaultValues.d.ts +2 -0
- package/build/utils/theme.d.ts +11 -1
- package/build/utils/theme.js +54 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CheckoutProfileResponse } from './checkoutProfile';
|
|
2
|
-
import { Locale, Environment, ThemeMode, Edges, Scope, MerchantCapabilities, SupportedNetworks, ButtonType } from './enums';
|
|
2
|
+
import { Locale, Environment, ThemeMode, Edges, Scope, MerchantCapabilities, SupportedNetworks, ButtonType, ColorStyle } from './enums';
|
|
3
3
|
export interface ApplePayRequestData {
|
|
4
4
|
countryCode: string;
|
|
5
5
|
currencyCode: string;
|
|
@@ -29,6 +29,8 @@ export interface Interface {
|
|
|
29
29
|
theme?: ThemeMode;
|
|
30
30
|
edges?: Edges;
|
|
31
31
|
type?: ButtonType;
|
|
32
|
+
colorStyle?: ColorStyle;
|
|
33
|
+
loader?: boolean;
|
|
32
34
|
}
|
|
33
35
|
export interface Customer {
|
|
34
36
|
id?: string;
|
|
@@ -11,13 +11,6 @@ interface IProps extends ButtonProps {
|
|
|
11
11
|
bgColor?: string;
|
|
12
12
|
textColor?: string;
|
|
13
13
|
gradientColor?: string;
|
|
14
|
-
showDisabledButton: boolean;
|
|
15
|
-
disableButton: {
|
|
16
|
-
text: string;
|
|
17
|
-
font: string | undefined;
|
|
18
|
-
color: string;
|
|
19
|
-
backgroundColor: string;
|
|
20
|
-
};
|
|
21
14
|
}
|
|
22
15
|
declare function ActionButton(props: IProps): JSX.Element;
|
|
23
16
|
declare namespace ActionButton {
|
|
@@ -44,14 +44,15 @@ var StyledButton = styled(Button, {
|
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
46
|
export default function ActionButton(props) {
|
|
47
|
-
var children = props.children, onClick = props.onClick, disabled = props.disabled, rounded = props.rounded, bgColor = props.bgColor, textColor = props.textColor, gradientColor = props.gradientColor,
|
|
48
|
-
var background =
|
|
47
|
+
var children = props.children, onClick = props.onClick, disabled = props.disabled, rounded = props.rounded, bgColor = props.bgColor, textColor = props.textColor, gradientColor = props.gradientColor, sx = props.sx, rest = __rest(props, ["children", "onClick", "disabled", "rounded", "bgColor", "textColor", "gradientColor", "sx"]);
|
|
48
|
+
var background = rounded ? bgColor : gradientColor || bgColor;
|
|
49
49
|
return (_jsx(StyledButton, __assign({ "data-testid": 'ActionButton', "data-is-rounded": rounded, sx: __assign({ background: background, color: textColor, '&:hover': {
|
|
50
50
|
background: background
|
|
51
51
|
}, '&:disabled': {
|
|
52
52
|
background: background,
|
|
53
|
-
color: textColor
|
|
54
|
-
|
|
53
|
+
color: textColor,
|
|
54
|
+
pointerEvents: 'none'
|
|
55
|
+
} }, sx), disabled: disabled, rounded: rounded, onClick: onClick }, rest, { children: children })));
|
|
55
56
|
}
|
|
56
57
|
ActionButton.defaultProps = {
|
|
57
58
|
children: 'Pay',
|
|
@@ -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
|
}
|
|
@@ -5,18 +5,12 @@ export interface PayButtonProps {
|
|
|
5
5
|
isRounded?: boolean;
|
|
6
6
|
isFailed?: boolean;
|
|
7
7
|
isSuccess?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
8
9
|
bgColor?: string;
|
|
9
10
|
gradientColor?: string;
|
|
10
11
|
edges?: Edges;
|
|
11
12
|
titleAsset?: string;
|
|
12
13
|
onClick: () => void;
|
|
13
|
-
showDisabledButton: boolean;
|
|
14
|
-
disableButton: {
|
|
15
|
-
text: string;
|
|
16
|
-
font: string | undefined;
|
|
17
|
-
color: string;
|
|
18
|
-
backgroundColor: string;
|
|
19
|
-
};
|
|
20
14
|
}
|
|
21
15
|
declare const _default: React.NamedExoticComponent<PayButtonProps>;
|
|
22
16
|
export default _default;
|
|
@@ -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,
|
|
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
|
-
});
|
|
@@ -9,40 +9,24 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
13
|
import * as React from 'react';
|
|
14
14
|
import { createRoot } from 'react-dom/client';
|
|
15
15
|
import { findOrCreateElementAndInject } from '../../utils';
|
|
16
16
|
import { useApplePay } from '../../hooks/useApplePay';
|
|
17
|
-
import { getDefaultValues } from '../../utils/defaultValues';
|
|
18
|
-
import { ButtonStyle, Edges, ThemeMode } from '../../@types/enums';
|
|
19
17
|
import InitialLoader from '../../components/InitialLoader';
|
|
20
18
|
import './ApplePayButton.css';
|
|
21
19
|
import { StyledContainer } from './style';
|
|
20
|
+
import PayButton from '../../components/PayButton';
|
|
22
21
|
var ApplePay = React.memo(function (props) {
|
|
23
|
-
var _a, _b;
|
|
24
|
-
var
|
|
25
|
-
var _c = useApplePay(mappedProps), loading = _c.loading, onApplePayButtonClicked = _c.onApplePayButtonClicked, disabled = _c.disabled, applePayRequestData = _c.applePayRequestData, applePayRequestConfiguration = _c.applePayRequestConfiguration;
|
|
26
|
-
var isIframeIntegration = props.integration === 'iframe';
|
|
27
|
-
var handleClick = function () {
|
|
28
|
-
var _a, _b;
|
|
29
|
-
if (isIframeIntegration) {
|
|
30
|
-
(_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, __assign(__assign({}, applePayRequestConfiguration), { applePayRequestData: applePayRequestData }));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
onApplePayButtonClicked();
|
|
34
|
-
(_b = props.onClick) === null || _b === void 0 ? void 0 : _b.call(props);
|
|
35
|
-
};
|
|
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;
|
|
36
24
|
React.useEffect(function () {
|
|
37
25
|
if (props.debug) {
|
|
38
26
|
console.log('ApplePayButtonProps', props);
|
|
39
27
|
}
|
|
40
28
|
}, []);
|
|
41
|
-
return (_jsx(StyledContainer, __assign({ "data-src": 'apple-pay-button-element', "data-testid": 'ApplePayButton-section' }, { children: loading ? (_jsx(InitialLoader, { open: true, themeMode: (
|
|
42
|
-
ApplePayButtonType: mappedProps.interface.type,
|
|
43
|
-
ApplePayButtonStyle: mappedProps.interface.theme === ThemeMode.DARK ? ButtonStyle.Black : ButtonStyle.White,
|
|
44
|
-
borderRadius: mappedProps.interface.edges === Edges.STRAIGHT ? '0' : '10px'
|
|
45
|
-
} })) })));
|
|
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 }) })) })));
|
|
46
30
|
});
|
|
47
31
|
export function ApplePayButton(props) {
|
|
48
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
|
+
});
|
|
@@ -1,11 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface
|
|
1
|
+
import { Locale, Scope } from '../@types/enums';
|
|
2
|
+
import { ApplePayButtonProps, ApplePayDataToLunchSDKFromMerchantSide, ApplePayRequestData, MetaData } from '../@types';
|
|
3
|
+
interface UsaApplePayProps {
|
|
4
|
+
buttonProps: ApplePayButtonProps;
|
|
5
|
+
}
|
|
6
|
+
export declare const useApplePay: ({ buttonProps }: UsaApplePayProps) => {
|
|
7
|
+
onClick: () => void;
|
|
4
8
|
loading: boolean;
|
|
9
|
+
isIframeIntegration: boolean;
|
|
5
10
|
onApplePayButtonClicked: () => Promise<void>;
|
|
6
11
|
disabled: boolean;
|
|
7
|
-
applePayRequestData
|
|
8
|
-
applePayRequestConfiguration
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
applePayRequestData: ApplePayRequestData | undefined;
|
|
13
|
+
applePayRequestConfiguration: Omit<ApplePayDataToLunchSDKFromMerchantSide, "applePayRequestData"> | undefined;
|
|
14
|
+
mappedProps: {
|
|
15
|
+
interface: {
|
|
16
|
+
locale?: Locale | undefined;
|
|
17
|
+
theme?: import("../@types").ThemeMode | undefined;
|
|
18
|
+
edges?: import("../@types").Edges | undefined;
|
|
19
|
+
type?: import("../@types").ButtonType | undefined;
|
|
20
|
+
colorStyle?: import("../@types").ColorStyle | undefined;
|
|
21
|
+
loader?: boolean | undefined;
|
|
22
|
+
};
|
|
23
|
+
operator: {
|
|
24
|
+
publicKey: string;
|
|
25
|
+
hashstring?: string | undefined;
|
|
26
|
+
};
|
|
27
|
+
merchant: {
|
|
28
|
+
id: string;
|
|
29
|
+
};
|
|
30
|
+
scope: Scope;
|
|
31
|
+
environment: import("../@types").Environment;
|
|
32
|
+
customer?: import("../@types").Customer | undefined;
|
|
33
|
+
acceptance?: import("../@types").Acceptance | undefined;
|
|
34
|
+
transaction?: {
|
|
35
|
+
authentication?: boolean | undefined;
|
|
36
|
+
authorize?: {
|
|
37
|
+
auto: {
|
|
38
|
+
type: string;
|
|
39
|
+
time: number;
|
|
40
|
+
};
|
|
41
|
+
} | undefined;
|
|
42
|
+
metadata?: Record<string, string> | undefined;
|
|
43
|
+
reference?: string | undefined;
|
|
44
|
+
paymentAgreement?: {
|
|
45
|
+
id: string;
|
|
46
|
+
contract?: {
|
|
47
|
+
id: string;
|
|
48
|
+
} | undefined;
|
|
49
|
+
} | undefined;
|
|
50
|
+
destinations?: Record<string, any> | undefined;
|
|
51
|
+
} | undefined;
|
|
52
|
+
invoice?: {
|
|
53
|
+
id: string;
|
|
54
|
+
} | undefined;
|
|
55
|
+
order: {
|
|
56
|
+
amount: number;
|
|
57
|
+
currency: string;
|
|
58
|
+
id?: string | undefined;
|
|
59
|
+
description?: string | undefined;
|
|
60
|
+
metadata?: Record<string, string> | undefined;
|
|
61
|
+
reference?: string | undefined;
|
|
62
|
+
};
|
|
63
|
+
post?: {
|
|
64
|
+
url: string;
|
|
65
|
+
} | undefined;
|
|
66
|
+
redirect?: {
|
|
67
|
+
url: string;
|
|
68
|
+
} | undefined;
|
|
69
|
+
onOrderCreated?: ((orderId: string) => void) | undefined;
|
|
70
|
+
onCancel?: (() => void) | undefined;
|
|
71
|
+
onError?: ((error: any) => void) | undefined;
|
|
72
|
+
onSuccess?: ((data: Record<string, any>) => void) | undefined;
|
|
73
|
+
onClick?: ((data?: ApplePayDataToLunchSDKFromMerchantSide | undefined) => void) | undefined;
|
|
74
|
+
onReady?: (() => void) | undefined;
|
|
75
|
+
metaData?: MetaData | undefined;
|
|
76
|
+
debug?: boolean | undefined;
|
|
77
|
+
integration?: "sdk" | "iframe" | undefined;
|
|
78
|
+
headers?: {
|
|
79
|
+
mdn: string;
|
|
80
|
+
application: string;
|
|
81
|
+
} | undefined;
|
|
82
|
+
};
|
|
83
|
+
theme: import("../@types").ThemeMode;
|
|
84
|
+
isRounded: boolean;
|
|
85
|
+
success: boolean;
|
|
86
|
+
error: boolean;
|
|
87
|
+
backgroundColor: string | undefined;
|
|
88
|
+
gradientColor: string | undefined;
|
|
89
|
+
titleAsset: string | undefined;
|
|
90
|
+
};
|
|
11
91
|
export {};
|
|
@@ -45,22 +45,32 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
45
45
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
-
import { useEffect, useState } from 'react';
|
|
48
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
49
49
|
import appService from '../api/app.service';
|
|
50
50
|
import { getAxiosGlobalHeaders, setAxiosGlobalHeaders } from '../api/httpClient';
|
|
51
51
|
import { ApplePayVersion } from '../constants';
|
|
52
52
|
import { Scope } from '../@types/enums';
|
|
53
53
|
import { prepareApplePayRequest } from '../utils/config';
|
|
54
54
|
import { useMerchantApplePay } from './useMerchantApplePay';
|
|
55
|
+
import { getApplePayPaymentMethod, getDefaultThemeMode, getDefaultValues, getFullThemeMode } from '../utils';
|
|
55
56
|
export var useApplePay = function (_a) {
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
var
|
|
60
|
-
var
|
|
61
|
-
var
|
|
57
|
+
var _b, _c, _d, _e, _f;
|
|
58
|
+
var buttonProps = _a.buttonProps;
|
|
59
|
+
var _g = useState(), applePayRequestData = _g[0], setApplePayRequestData = _g[1];
|
|
60
|
+
var _h = useState(), applePayRequestConfiguration = _h[0], setApplePayRequestConfiguration = _h[1];
|
|
61
|
+
var _j = useState(), profileData = _j[0], setProfile = _j[1];
|
|
62
|
+
var _k = useState(false), disabled = _k[0], setDisabled = _k[1];
|
|
63
|
+
var _l = useState(null), tapTheme = _l[0], setTapTheme = _l[1];
|
|
64
|
+
var _m = useState(), tapLocalization = _m[0], setTapLocalization = _m[1];
|
|
65
|
+
var _o = useState(false), error = _o[0], setError = _o[1];
|
|
66
|
+
var _p = useState(false), success = _p[0], setSuccess = _p[1];
|
|
67
|
+
var _q = useState(false), loading = _q[0], setLoading = _q[1];
|
|
68
|
+
var _r = useState(false), isRounded = _r[0], setIsRounded = _r[1];
|
|
69
|
+
var mappedProps = getDefaultValues(buttonProps);
|
|
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';
|
|
62
72
|
useMerchantApplePay({
|
|
63
|
-
isIframeIntegration:
|
|
73
|
+
isIframeIntegration: isIframeIntegration,
|
|
64
74
|
onError: onError,
|
|
65
75
|
onSuccess: onSuccess,
|
|
66
76
|
scope: scope,
|
|
@@ -71,8 +81,52 @@ export var useApplePay = function (_a) {
|
|
|
71
81
|
transaction: transaction,
|
|
72
82
|
operator: operator,
|
|
73
83
|
post: post,
|
|
74
|
-
redirect: redirect
|
|
84
|
+
redirect: redirect,
|
|
85
|
+
setError: setError,
|
|
86
|
+
setSuccess: setSuccess,
|
|
87
|
+
setIsRounded: setIsRounded
|
|
75
88
|
});
|
|
89
|
+
var lang = (_c = (_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.locale) !== null && _c !== void 0 ? _c : 'en';
|
|
90
|
+
var theme = getDefaultThemeMode((_d = mappedProps.interface) === null || _d === void 0 ? void 0 : _d.theme);
|
|
91
|
+
var applePayPaymentMethodOptions = useMemo(function () {
|
|
92
|
+
if (!profileData)
|
|
93
|
+
return null;
|
|
94
|
+
return getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
|
|
95
|
+
}, [profileData]);
|
|
96
|
+
var gradientColor = useMemo(function () {
|
|
97
|
+
var _a, _b, _c;
|
|
98
|
+
if (!applePayPaymentMethodOptions)
|
|
99
|
+
return undefined;
|
|
100
|
+
var backgroundColor = (_a = applePayPaymentMethodOptions.button_style.background) === null || _a === void 0 ? void 0 : _a[getFullThemeMode((_b = buttonProps.interface) === null || _b === void 0 ? void 0 : _b.theme, (_c = buttonProps.interface) === null || _c === void 0 ? void 0 : _c.colorStyle)].background_colors;
|
|
101
|
+
if (backgroundColor.length > 1)
|
|
102
|
+
return "linear-gradient(-90deg,".concat(backgroundColor.join(','), ")");
|
|
103
|
+
return backgroundColor[0];
|
|
104
|
+
}, [applePayPaymentMethodOptions, buttonProps]);
|
|
105
|
+
var backgroundColor = useMemo(function () {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
if (!applePayPaymentMethodOptions)
|
|
108
|
+
return undefined;
|
|
109
|
+
return applePayPaymentMethodOptions.button_style.background[getFullThemeMode((_a = buttonProps.interface) === null || _a === void 0 ? void 0 : _a.theme, (_b = buttonProps.interface) === null || _b === void 0 ? void 0 : _b.colorStyle)].base_color;
|
|
110
|
+
}, [applePayPaymentMethodOptions, buttonProps]);
|
|
111
|
+
var titleAsset = useMemo(function () {
|
|
112
|
+
var _a, _b, _c;
|
|
113
|
+
if (!applePayPaymentMethodOptions)
|
|
114
|
+
return undefined;
|
|
115
|
+
var imgSrc = (_a = profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.payment_methods.find(function (method) { return method.name === applePayPaymentMethodOptions.name; })) === null || _a === void 0 ? void 0 : _a.button_style.title_asset;
|
|
116
|
+
var theme = getFullThemeMode((_b = buttonProps.interface) === null || _b === void 0 ? void 0 : _b.theme, (_c = buttonProps.interface) === null || _c === void 0 ? void 0 : _c.colorStyle);
|
|
117
|
+
var titleAsset = (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.replace('{theme}', theme).replace('{lang}', lang)) + '.svg';
|
|
118
|
+
return titleAsset;
|
|
119
|
+
}, [
|
|
120
|
+
applePayPaymentMethodOptions,
|
|
121
|
+
lang,
|
|
122
|
+
profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.payment_methods,
|
|
123
|
+
(_e = buttonProps.interface) === null || _e === void 0 ? void 0 : _e.colorStyle,
|
|
124
|
+
(_f = buttonProps.interface) === null || _f === void 0 ? void 0 : _f.theme
|
|
125
|
+
]);
|
|
126
|
+
var showLoader = useMemo(function () {
|
|
127
|
+
var _a;
|
|
128
|
+
return ((_a = mappedProps.interface) === null || _a === void 0 ? void 0 : _a.loader) !== false;
|
|
129
|
+
}, [mappedProps]);
|
|
76
130
|
var initialize = function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
77
131
|
var merchantProfile, payment_options, headers_1, data, err_1;
|
|
78
132
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
@@ -160,9 +214,6 @@ export var useApplePay = function (_a) {
|
|
|
160
214
|
}
|
|
161
215
|
});
|
|
162
216
|
}); };
|
|
163
|
-
useEffect(function () {
|
|
164
|
-
initialize(metaData);
|
|
165
|
-
}, []);
|
|
166
217
|
var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
167
218
|
var ApplePaySession, session_1;
|
|
168
219
|
var _a;
|
|
@@ -197,7 +248,7 @@ export var useApplePay = function (_a) {
|
|
|
197
248
|
console.info('Creating merchant session and validating merchant session');
|
|
198
249
|
console.info('onvalidatemerchant event', event);
|
|
199
250
|
}
|
|
200
|
-
|
|
251
|
+
setDisabled(true);
|
|
201
252
|
_a.label = 1;
|
|
202
253
|
case 1:
|
|
203
254
|
_a.trys.push([1, 3, , 4]);
|
|
@@ -219,7 +270,7 @@ export var useApplePay = function (_a) {
|
|
|
219
270
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
220
271
|
throw error_1;
|
|
221
272
|
case 4:
|
|
222
|
-
|
|
273
|
+
setDisabled(false);
|
|
223
274
|
return [2];
|
|
224
275
|
}
|
|
225
276
|
});
|
|
@@ -235,6 +286,7 @@ export var useApplePay = function (_a) {
|
|
|
235
286
|
_b.label = 1;
|
|
236
287
|
case 1:
|
|
237
288
|
_b.trys.push([1, 7, 8, 9]);
|
|
289
|
+
setIsRounded === null || setIsRounded === void 0 ? void 0 : setIsRounded(true);
|
|
238
290
|
_a = scope;
|
|
239
291
|
switch (_a) {
|
|
240
292
|
case Scope.APPLE_PAY_TOKEN: return [3, 2];
|
|
@@ -248,6 +300,7 @@ export var useApplePay = function (_a) {
|
|
|
248
300
|
case 3: return [4, appService.tapTokenization(event.payment.token.paymentData)];
|
|
249
301
|
case 4:
|
|
250
302
|
data = _b.sent();
|
|
303
|
+
setSuccess === null || setSuccess === void 0 ? void 0 : setSuccess(true);
|
|
251
304
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
252
305
|
session_1.completePayment({ status: ApplePaySession.STATUS_SUCCESS });
|
|
253
306
|
return [3, 6];
|
|
@@ -261,10 +314,12 @@ export var useApplePay = function (_a) {
|
|
|
261
314
|
error_2 = _b.sent();
|
|
262
315
|
if (debug)
|
|
263
316
|
console.error('error in onpaymentauthorized', error_2);
|
|
317
|
+
setError(true);
|
|
264
318
|
session_1.completePayment({ status: ApplePaySession.STATUS_FAILURE });
|
|
265
319
|
throw error_2;
|
|
266
320
|
case 8:
|
|
267
321
|
setLoading(false);
|
|
322
|
+
setIsRounded === null || setIsRounded === void 0 ? void 0 : setIsRounded(false);
|
|
268
323
|
return [7];
|
|
269
324
|
case 9: return [2];
|
|
270
325
|
}
|
|
@@ -297,11 +352,43 @@ export var useApplePay = function (_a) {
|
|
|
297
352
|
return [2];
|
|
298
353
|
});
|
|
299
354
|
}); };
|
|
355
|
+
var handleClick = useCallback(function () {
|
|
356
|
+
var _a, _b;
|
|
357
|
+
if (isIframeIntegration) {
|
|
358
|
+
(_a = buttonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(buttonProps, __assign(__assign({}, applePayRequestConfiguration), { applePayRequestData: applePayRequestData }));
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
onApplePayButtonClicked();
|
|
362
|
+
(_b = buttonProps.onClick) === null || _b === void 0 ? void 0 : _b.call(buttonProps);
|
|
363
|
+
}, [applePayRequestConfiguration, applePayRequestData, buttonProps, isIframeIntegration, onApplePayButtonClicked]);
|
|
364
|
+
useEffect(function () {
|
|
365
|
+
initialize(metaData);
|
|
366
|
+
}, []);
|
|
367
|
+
useEffect(function () {
|
|
368
|
+
if (!error)
|
|
369
|
+
return;
|
|
370
|
+
var timer = setTimeout(function () {
|
|
371
|
+
setError(false);
|
|
372
|
+
setLoading(false);
|
|
373
|
+
setIsRounded(false);
|
|
374
|
+
}, 2000);
|
|
375
|
+
return function () { return clearTimeout(timer); };
|
|
376
|
+
}, [error]);
|
|
300
377
|
return {
|
|
378
|
+
onClick: handleClick,
|
|
301
379
|
loading: loading,
|
|
380
|
+
isIframeIntegration: isIframeIntegration,
|
|
302
381
|
onApplePayButtonClicked: onApplePayButtonClicked,
|
|
303
382
|
disabled: !profileData || disabled || !applePayRequestData,
|
|
304
383
|
applePayRequestData: applePayRequestData,
|
|
305
|
-
applePayRequestConfiguration: applePayRequestConfiguration
|
|
384
|
+
applePayRequestConfiguration: applePayRequestConfiguration,
|
|
385
|
+
mappedProps: mappedProps,
|
|
386
|
+
theme: theme,
|
|
387
|
+
isRounded: isRounded,
|
|
388
|
+
success: success,
|
|
389
|
+
error: error,
|
|
390
|
+
backgroundColor: backgroundColor,
|
|
391
|
+
gradientColor: gradientColor,
|
|
392
|
+
titleAsset: titleAsset
|
|
306
393
|
};
|
|
307
394
|
};
|
|
@@ -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:
|
package/build/utils/config.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Acceptance, ApplePayButtonProps, ApplePayRequestData, MetaData, PaymentMethod } from '../@types';
|
|
2
2
|
export declare const validateSupportedNetworks: (supportedNetworksOptions: Acceptance['supportedSchemes'], merchantSupportedNetworks?: Acceptance['supportedSchemes']) => Acceptance['supportedSchemes'];
|
|
3
|
+
export declare const getApplePayPaymentMethod: (paymentMethods: Array<PaymentMethod>) => PaymentMethod;
|
|
3
4
|
export declare const getApplePayRequest: ({ order, customer, supportedNetworks, merchantCapabilities, countryCode, name }: Pick<ApplePayButtonProps, "order" | "customer"> & {
|
|
4
5
|
supportedNetworks: Acceptance['supportedSchemes'];
|
|
5
6
|
merchantCapabilities: ApplePayRequestData['merchantCapabilities'];
|
|
6
7
|
countryCode: string;
|
|
7
8
|
name: string;
|
|
8
9
|
}) => ApplePayRequestData;
|
|
9
|
-
export declare const getApplePayPaymentMethod: (paymentMethods: Array<PaymentMethod>) => PaymentMethod;
|
|
10
10
|
export declare const rsaSetup: (key: string) => (string: string) => string;
|
|
11
11
|
export declare function generateApplicationHeader(obj: Record<string, string | any>): string;
|
|
12
12
|
export declare const prepareApplePayRequest: ({ payment_options, merchant, order, customer, acceptance }: Pick<MetaData, 'merchant' | 'payment_options'> & Pick<ApplePayButtonProps, 'order' | 'customer' | 'acceptance'>) => ApplePayRequestData;
|
package/build/utils/config.js
CHANGED
|
@@ -16,6 +16,16 @@ export var validateSupportedNetworks = function (supportedNetworksOptions, merch
|
|
|
16
16
|
}
|
|
17
17
|
return supportedNetworks.map(toLowerCase);
|
|
18
18
|
};
|
|
19
|
+
export var getApplePayPaymentMethod = function (paymentMethods) {
|
|
20
|
+
var paymentMethod = paymentMethods.find(function (_a) {
|
|
21
|
+
var name = _a.name, payment_type = _a.payment_type;
|
|
22
|
+
return [name, payment_type].some(function (item) { return item.toLowerCase() === 'apple_pay'; });
|
|
23
|
+
});
|
|
24
|
+
if (!paymentMethod) {
|
|
25
|
+
throw new Error('apple_pay is not configured in your payment options');
|
|
26
|
+
}
|
|
27
|
+
return paymentMethod;
|
|
28
|
+
};
|
|
19
29
|
export var getApplePayRequest = function (_a) {
|
|
20
30
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
21
31
|
var order = _a.order, customer = _a.customer, supportedNetworks = _a.supportedNetworks, merchantCapabilities = _a.merchantCapabilities, countryCode = _a.countryCode, name = _a.name;
|
|
@@ -36,16 +46,6 @@ export var getApplePayRequest = function (_a) {
|
|
|
36
46
|
}
|
|
37
47
|
};
|
|
38
48
|
};
|
|
39
|
-
export var getApplePayPaymentMethod = function (paymentMethods) {
|
|
40
|
-
var paymentMethod = paymentMethods.find(function (_a) {
|
|
41
|
-
var name = _a.name, payment_type = _a.payment_type;
|
|
42
|
-
return [name, payment_type].some(function (item) { return item.toLowerCase() === 'apple_pay'; });
|
|
43
|
-
});
|
|
44
|
-
if (!paymentMethod) {
|
|
45
|
-
throw new Error('Apple Pay is not configured in your payment options');
|
|
46
|
-
}
|
|
47
|
-
return paymentMethod;
|
|
48
|
-
};
|
|
49
49
|
export var rsaSetup = function (key) {
|
|
50
50
|
var rsa = new JSEncrypt();
|
|
51
51
|
rsa.setPublicKey(key);
|
|
@@ -6,6 +6,8 @@ export declare const getDefaultValues: (mainObject: ApplePayButtonProps) => {
|
|
|
6
6
|
theme?: ThemeMode | undefined;
|
|
7
7
|
edges?: Edges | undefined;
|
|
8
8
|
type?: ButtonType | undefined;
|
|
9
|
+
colorStyle?: import("../@types").ColorStyle | undefined;
|
|
10
|
+
loader?: boolean | undefined;
|
|
9
11
|
};
|
|
10
12
|
operator: {
|
|
11
13
|
publicKey: string;
|
package/build/utils/theme.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TapThemeResponse } from '../@types';
|
|
2
|
+
import { ColorStyle, FullThemeMode, Locale, ThemeMode } from '../@types/enums';
|
|
3
|
+
import { ApplePayButtonProps } from '..';
|
|
4
|
+
export declare const mappingInterface: (interfaceParam?: ApplePayButtonProps['interface']) => ApplePayButtonProps['interface'];
|
|
2
5
|
export declare const getDefaultThemeMode: (themeMode?: ThemeMode) => ThemeMode;
|
|
6
|
+
export declare const getDefaultLocale: (locale?: Locale) => Locale;
|
|
7
|
+
export declare const getFullThemeMode: (themeMode?: ThemeMode, colorStyle?: ColorStyle) => FullThemeMode;
|
|
8
|
+
export declare const appendColors: (colors: Record<string, string>) => void;
|
|
9
|
+
export declare const getTapThemeValue: ({ tapTheme, value }: {
|
|
10
|
+
tapTheme: TapThemeResponse | null;
|
|
11
|
+
value?: string | undefined;
|
|
12
|
+
}) => string;
|
package/build/utils/theme.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { ColorStyle, Edges, FullThemeMode, Locale, ThemeMode } from '../@types/enums';
|
|
13
|
+
export var mappingInterface = function (interfaceParam) {
|
|
14
|
+
return __assign(__assign({ edges: Edges.CURVED, colorStyle: ColorStyle.COLORED, loader: true }, interfaceParam), { locale: getDefaultLocale(interfaceParam === null || interfaceParam === void 0 ? void 0 : interfaceParam.locale), theme: getDefaultThemeMode(interfaceParam === null || interfaceParam === void 0 ? void 0 : interfaceParam.theme) });
|
|
15
|
+
};
|
|
2
16
|
export var getDefaultThemeMode = function (themeMode) {
|
|
3
17
|
return themeMode === ThemeMode.DYNAMIC || themeMode === undefined
|
|
4
18
|
? window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
@@ -6,3 +20,42 @@ export var getDefaultThemeMode = function (themeMode) {
|
|
|
6
20
|
: ThemeMode.LIGHT
|
|
7
21
|
: themeMode;
|
|
8
22
|
};
|
|
23
|
+
export var getDefaultLocale = function (locale) {
|
|
24
|
+
var _a;
|
|
25
|
+
return locale === Locale.DYNAMIC || locale === undefined
|
|
26
|
+
? (_a = window.navigator.language.split('-')) === null || _a === void 0 ? void 0 : _a[0]
|
|
27
|
+
: locale;
|
|
28
|
+
};
|
|
29
|
+
export var getFullThemeMode = function (themeMode, colorStyle) {
|
|
30
|
+
var themeModeValue = getDefaultThemeMode(themeMode);
|
|
31
|
+
if (themeModeValue === ThemeMode.DARK) {
|
|
32
|
+
return colorStyle === ColorStyle.MONOCHROME ? FullThemeMode.DARK : FullThemeMode.DARK_COLORED;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return colorStyle === ColorStyle.MONOCHROME ? FullThemeMode.LIGHT_MONO : FullThemeMode.LIGHT;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export var appendColors = function (colors) {
|
|
39
|
+
try {
|
|
40
|
+
var root_1 = document.documentElement;
|
|
41
|
+
Object.entries(colors).forEach(function (_a) {
|
|
42
|
+
var key = _a[0], value = _a[1];
|
|
43
|
+
root_1.style.setProperty("--".concat(key), value);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
throw e;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export var getTapThemeValue = function (_a) {
|
|
51
|
+
var tapTheme = _a.tapTheme, value = _a.value;
|
|
52
|
+
if (!tapTheme)
|
|
53
|
+
return '';
|
|
54
|
+
if (!value)
|
|
55
|
+
return '';
|
|
56
|
+
if (value[0] === '#')
|
|
57
|
+
return value;
|
|
58
|
+
var colorsObject = tapTheme === null || tapTheme === void 0 ? void 0 : tapTheme.GlobalValues.Colors;
|
|
59
|
+
var valueFromGlobalColors = colorsObject === null || colorsObject === void 0 ? void 0 : colorsObject[value];
|
|
60
|
+
return valueFromGlobalColors !== null && valueFromGlobalColors !== void 0 ? valueFromGlobalColors : '';
|
|
61
|
+
};
|