@tap-payments/apple-pay-button 0.0.56-development → 0.0.57-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 +3 -3
- package/build/components/PayButton/PayButton.d.ts +0 -7
- package/build/components/PayButton/PayButton.js +2 -2
- package/build/features/ApplePayButton/ApplePayButton.js +5 -21
- package/build/hooks/useApplePay.d.ts +87 -7
- package/build/hooks/useApplePay.js +91 -11
- 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,14 @@ 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
53
|
color: textColor
|
|
54
|
-
} }, sx), disabled: disabled
|
|
54
|
+
} }, sx), disabled: disabled, rounded: rounded, onClick: onClick }, rest, { children: children })));
|
|
55
55
|
}
|
|
56
56
|
ActionButton.defaultProps = {
|
|
57
57
|
children: 'Pay',
|
|
@@ -10,13 +10,6 @@ export interface PayButtonProps {
|
|
|
10
10
|
edges?: Edges;
|
|
11
11
|
titleAsset?: string;
|
|
12
12
|
onClick: () => void;
|
|
13
|
-
showDisabledButton: boolean;
|
|
14
|
-
disableButton: {
|
|
15
|
-
text: string;
|
|
16
|
-
font: string | undefined;
|
|
17
|
-
color: string;
|
|
18
|
-
backgroundColor: string;
|
|
19
|
-
};
|
|
20
13
|
}
|
|
21
14
|
declare const _default: React.NamedExoticComponent<PayButtonProps>;
|
|
22
15
|
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, 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, style: {
|
|
37
37
|
borderRadius: edges === Edges.STRAIGHT ? '0px' : '30px'
|
|
38
38
|
} }, { children: renderButtonLabel() })) })));
|
|
39
39
|
};
|
|
@@ -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;
|
|
23
|
+
var _d = useApplePay({ buttonProps: props }), onClick = _d.onClick, loading = _d.loading, onApplePayButtonClicked = _d.onApplePayButtonClicked, disabled = _d.disabled, applePayRequestData = _d.applePayRequestData, isIframeIntegration = _d.isIframeIntegration, applePayRequestConfiguration = _d.applePayRequestConfiguration, mappedProps = _d.mappedProps, theme = _d.theme, isRounded = _d.isRounded, success = _d.success, error = _d.error, backgroundColor = _d.backgroundColor, gradientColor = _d.gradientColor, titleAsset = _d.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: (_a = mappedProps.interface) === null || _a === void 0 ? void 0 : _a.theme, edges: (_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.edges })) : (_jsx(
|
|
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' }, { children: loading ? (_jsx(InitialLoader, { open: true, themeMode: (_a = mappedProps.interface) === null || _a === void 0 ? void 0 : _a.theme, edges: (_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.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: (_c = mappedProps.interface) === null || _c === void 0 ? void 0 : _c.edges, onClick: onClick }) })) })));
|
|
46
30
|
});
|
|
47
31
|
export function ApplePayButton(props) {
|
|
48
32
|
return _jsx(ApplePay, __assign({}, props));
|
|
@@ -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,20 +45,29 @@ 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;
|
|
62
71
|
useMerchantApplePay({
|
|
63
72
|
isIframeIntegration: integration === 'iframe',
|
|
64
73
|
onError: onError,
|
|
@@ -73,6 +82,48 @@ export var useApplePay = function (_a) {
|
|
|
73
82
|
post: post,
|
|
74
83
|
redirect: redirect
|
|
75
84
|
});
|
|
85
|
+
var lang = (_c = (_b = mappedProps.interface) === null || _b === void 0 ? void 0 : _b.locale) !== null && _c !== void 0 ? _c : 'en';
|
|
86
|
+
var theme = getDefaultThemeMode((_d = mappedProps.interface) === null || _d === void 0 ? void 0 : _d.theme);
|
|
87
|
+
var isIframeIntegration = buttonProps.integration === 'iframe';
|
|
88
|
+
var applePayPaymentMethodOptions = useMemo(function () {
|
|
89
|
+
if (!profileData)
|
|
90
|
+
return null;
|
|
91
|
+
return getApplePayPaymentMethod(profileData.payment_options.payment_methods || []);
|
|
92
|
+
}, [profileData]);
|
|
93
|
+
var gradientColor = useMemo(function () {
|
|
94
|
+
var _a, _b, _c;
|
|
95
|
+
if (!applePayPaymentMethodOptions)
|
|
96
|
+
return undefined;
|
|
97
|
+
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;
|
|
98
|
+
if (backgroundColor.length > 1)
|
|
99
|
+
return "linear-gradient(-90deg,".concat(backgroundColor.join(','), ")");
|
|
100
|
+
return backgroundColor[0];
|
|
101
|
+
}, [applePayPaymentMethodOptions, buttonProps]);
|
|
102
|
+
var backgroundColor = useMemo(function () {
|
|
103
|
+
var _a, _b;
|
|
104
|
+
if (!applePayPaymentMethodOptions)
|
|
105
|
+
return undefined;
|
|
106
|
+
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;
|
|
107
|
+
}, [applePayPaymentMethodOptions, buttonProps]);
|
|
108
|
+
var titleAsset = useMemo(function () {
|
|
109
|
+
var _a, _b, _c;
|
|
110
|
+
if (!applePayPaymentMethodOptions)
|
|
111
|
+
return undefined;
|
|
112
|
+
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;
|
|
113
|
+
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);
|
|
114
|
+
var titleAsset = (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.replace('{theme}', theme).replace('{lang}', lang)) + '.svg';
|
|
115
|
+
return titleAsset;
|
|
116
|
+
}, [
|
|
117
|
+
applePayPaymentMethodOptions,
|
|
118
|
+
lang,
|
|
119
|
+
profileData === null || profileData === void 0 ? void 0 : profileData.payment_options.payment_methods,
|
|
120
|
+
(_e = buttonProps.interface) === null || _e === void 0 ? void 0 : _e.colorStyle,
|
|
121
|
+
(_f = buttonProps.interface) === null || _f === void 0 ? void 0 : _f.theme
|
|
122
|
+
]);
|
|
123
|
+
var showLoader = useMemo(function () {
|
|
124
|
+
var _a;
|
|
125
|
+
return ((_a = mappedProps.interface) === null || _a === void 0 ? void 0 : _a.loader) !== false;
|
|
126
|
+
}, [mappedProps]);
|
|
76
127
|
var initialize = function (metaData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
77
128
|
var merchantProfile, payment_options, headers_1, data, err_1;
|
|
78
129
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
@@ -160,9 +211,6 @@ export var useApplePay = function (_a) {
|
|
|
160
211
|
}
|
|
161
212
|
});
|
|
162
213
|
}); };
|
|
163
|
-
useEffect(function () {
|
|
164
|
-
initialize(metaData);
|
|
165
|
-
}, []);
|
|
166
214
|
var onApplePayButtonClicked = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
167
215
|
var ApplePaySession, session_1;
|
|
168
216
|
var _a;
|
|
@@ -297,11 +345,43 @@ export var useApplePay = function (_a) {
|
|
|
297
345
|
return [2];
|
|
298
346
|
});
|
|
299
347
|
}); };
|
|
348
|
+
var handleClick = useCallback(function () {
|
|
349
|
+
var _a, _b;
|
|
350
|
+
if (isIframeIntegration) {
|
|
351
|
+
(_a = buttonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(buttonProps, __assign(__assign({}, applePayRequestConfiguration), { applePayRequestData: applePayRequestData }));
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
onApplePayButtonClicked();
|
|
355
|
+
(_b = buttonProps.onClick) === null || _b === void 0 ? void 0 : _b.call(buttonProps);
|
|
356
|
+
}, [applePayRequestConfiguration, applePayRequestData, buttonProps, isIframeIntegration, onApplePayButtonClicked]);
|
|
357
|
+
useEffect(function () {
|
|
358
|
+
initialize(metaData);
|
|
359
|
+
}, []);
|
|
360
|
+
useEffect(function () {
|
|
361
|
+
if (!error)
|
|
362
|
+
return;
|
|
363
|
+
var timer = setTimeout(function () {
|
|
364
|
+
setError(false);
|
|
365
|
+
setLoading(false);
|
|
366
|
+
setIsRounded(false);
|
|
367
|
+
}, 2000);
|
|
368
|
+
return function () { return clearTimeout(timer); };
|
|
369
|
+
}, [error]);
|
|
300
370
|
return {
|
|
371
|
+
onClick: handleClick,
|
|
301
372
|
loading: loading,
|
|
373
|
+
isIframeIntegration: isIframeIntegration,
|
|
302
374
|
onApplePayButtonClicked: onApplePayButtonClicked,
|
|
303
375
|
disabled: !profileData || disabled || !applePayRequestData,
|
|
304
376
|
applePayRequestData: applePayRequestData,
|
|
305
|
-
applePayRequestConfiguration: applePayRequestConfiguration
|
|
377
|
+
applePayRequestConfiguration: applePayRequestConfiguration,
|
|
378
|
+
mappedProps: mappedProps,
|
|
379
|
+
theme: theme,
|
|
380
|
+
isRounded: isRounded,
|
|
381
|
+
success: success,
|
|
382
|
+
error: error,
|
|
383
|
+
backgroundColor: backgroundColor,
|
|
384
|
+
gradientColor: gradientColor,
|
|
385
|
+
titleAsset: titleAsset
|
|
306
386
|
};
|
|
307
387
|
};
|
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
|
+
};
|