@tagadapay/plugin-sdk 2.3.9 → 2.3.10
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/README.md +623 -623
- package/dist/react/hooks/useApplePay.js +172 -84
- package/dist/react/hooks/usePluginConfig.js +2 -0
- package/dist/react/index.d.ts +1 -2
- package/dist/react/index.js +1 -1
- package/dist/react/providers/TagadaProvider.js +5 -5
- package/dist/react/types/apple-pay.d.ts +9 -11
- package/package.json +83 -83
- package/dist/react/components/ApplePayUniversalButton.d.ts +0 -16
- package/dist/react/components/ApplePayUniversalButton.example.d.ts +0 -3
- package/dist/react/components/ApplePayUniversalButton.example.js +0 -39
- package/dist/react/components/ApplePayUniversalButton.js +0 -62
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { ApplePayUniversalButton } from './ApplePayUniversalButton';
|
|
3
|
-
// Example usage of ApplePayUniversalButton
|
|
4
|
-
export const ApplePayUniversalButtonExample = () => {
|
|
5
|
-
const checkoutSessionId = 'example-session-123';
|
|
6
|
-
const lineItems = [
|
|
7
|
-
{
|
|
8
|
-
label: 'Product 1',
|
|
9
|
-
amount: '29.99',
|
|
10
|
-
type: 'final',
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
label: 'Shipping',
|
|
14
|
-
amount: '5.99',
|
|
15
|
-
type: 'final',
|
|
16
|
-
},
|
|
17
|
-
];
|
|
18
|
-
const total = {
|
|
19
|
-
label: 'Total',
|
|
20
|
-
amount: '35.98',
|
|
21
|
-
type: 'final',
|
|
22
|
-
};
|
|
23
|
-
const config = {
|
|
24
|
-
countryCode: 'US',
|
|
25
|
-
supportedNetworks: ['visa', 'masterCard', 'amex', 'discover'],
|
|
26
|
-
merchantCapabilities: ['supports3DS'],
|
|
27
|
-
};
|
|
28
|
-
const handleSuccess = (payment) => {
|
|
29
|
-
console.log('Payment successful:', payment);
|
|
30
|
-
};
|
|
31
|
-
const handleError = (error) => {
|
|
32
|
-
console.error('Payment error:', error);
|
|
33
|
-
};
|
|
34
|
-
const handleCancel = () => {
|
|
35
|
-
console.log('Payment cancelled');
|
|
36
|
-
};
|
|
37
|
-
return (_jsxs("div", { className: "max-w-md mx-auto p-6 bg-white rounded-lg shadow-lg", children: [_jsx("h2", { className: "text-2xl font-bold mb-4", children: "Apple Pay Universal Button Example" }), _jsxs("div", { className: "space-y-4", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-semibold mb-2", children: "Order Summary:" }), lineItems.map((item, index) => (_jsxs("div", { className: "flex justify-between text-sm", children: [_jsx("span", { children: item.label }), _jsxs("span", { children: ["$", item.amount] })] }, index))), _jsxs("div", { className: "flex justify-between font-bold border-t pt-2 mt-2", children: [_jsx("span", { children: total.label }), _jsxs("span", { children: ["$", total.amount] })] })] }), _jsx(ApplePayUniversalButton, { checkoutSessionId: checkoutSessionId, lineItems: lineItems, total: total, config: config, onSuccess: handleSuccess, onError: handleError, onCancel: handleCancel, className: "w-full" }), _jsxs("div", { className: "text-xs text-gray-500 mt-4", children: [_jsx("p", { children: "This button will:" }), _jsxs("ul", { className: "list-disc list-inside space-y-1", children: [_jsx("li", { children: "Show Apple Pay on supported devices (Safari iOS/macOS)" }), _jsx("li", { children: "Show QR code on other mobile browsers" }), _jsx("li", { children: "Show \"Unavailable\" on unsupported browsers" })] })] })] })] }));
|
|
38
|
-
};
|
|
39
|
-
export default ApplePayUniversalButtonExample;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { useApplePay } from '../hooks/useApplePay';
|
|
4
|
-
export const ApplePayUniversalButton = ({ checkoutSessionId, lineItems, total, config = {}, onSuccess, onError, onCancel, className = '', children, disabled = false, }) => {
|
|
5
|
-
const [showQRCode, setShowQRCode] = useState(false);
|
|
6
|
-
const { handleApplePayClick, processingPayment, applePayError, isApplePayAvailable, shouldShowQRCode, qrCodeData, generateQRCode, } = useApplePay({
|
|
7
|
-
onSuccess,
|
|
8
|
-
onError,
|
|
9
|
-
onCancel,
|
|
10
|
-
config,
|
|
11
|
-
});
|
|
12
|
-
const handleClick = () => {
|
|
13
|
-
if (isApplePayAvailable) {
|
|
14
|
-
handleApplePayClick(checkoutSessionId, lineItems, total, config);
|
|
15
|
-
}
|
|
16
|
-
else if (shouldShowQRCode) {
|
|
17
|
-
setShowQRCode(true);
|
|
18
|
-
// Generate QR code data
|
|
19
|
-
const qrData = {
|
|
20
|
-
checkoutSessionId,
|
|
21
|
-
lineItems,
|
|
22
|
-
total,
|
|
23
|
-
config,
|
|
24
|
-
qrCodeUrl: generateQRCode({ checkoutSessionId, lineItems, total, config }),
|
|
25
|
-
};
|
|
26
|
-
handleApplePayClick(checkoutSessionId, lineItems, total, config);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
onError?.('Apple Pay is not available on this device');
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const getButtonText = () => {
|
|
33
|
-
if (processingPayment)
|
|
34
|
-
return 'Processing...';
|
|
35
|
-
if (isApplePayAvailable)
|
|
36
|
-
return 'Pay with Apple Pay';
|
|
37
|
-
if (shouldShowQRCode)
|
|
38
|
-
return 'Show QR Code';
|
|
39
|
-
return 'Apple Pay Unavailable';
|
|
40
|
-
};
|
|
41
|
-
const getButtonIcon = () => {
|
|
42
|
-
if (isApplePayAvailable) {
|
|
43
|
-
return (_jsx("svg", { className: "h-6 w-6", viewBox: "0 0 24 24", fill: "currentColor", children: _jsx("path", { d: "M18.71 19.5c-.83 1.24-1.71 2.45-3.05 2.47-1.34.03-1.77-.79-3.29-.79-1.53 0-2 .77-3.27.82-1.31.05-2.3-1.32-3.14-2.53C4.25 17 2.94 12.45 4.7 9.39c.87-1.52 2.43-2.48 4.12-2.51 1.28-.02 2.5.87 3.29.87.78 0 2.26-1.07 3.81-.91.65.03 2.47.26 3.64 1.98-.09.06-2.17 1.28-2.15 3.81.03 3.02 2.65 4.03 2.68 4.04-.03.07-.42 1.44-1.38 2.83M13 3.5c.73-.83 1.94-1.46 2.94-1.5.13 1.17-.34 2.35-1.04 3.19-.69.85-1.83 1.51-2.95 1.42-.15-1.15.41-2.35 1.05-3.11z" }) }));
|
|
44
|
-
}
|
|
45
|
-
if (shouldShowQRCode) {
|
|
46
|
-
return (_jsx("svg", { className: "h-6 w-6", viewBox: "0 0 24 24", fill: "currentColor", children: _jsx("path", { d: "M3 3h7v7H3V3zm2 2v3h3V5H5zm8-2h7v7h-7V3zm2 2v3h3V5h-3zM3 13h7v7H3v-7zm2 2v3h3v-3H5zm8-2h7v7h-7v-7zm2 2v3h3v-3h-3z" }) }));
|
|
47
|
-
}
|
|
48
|
-
return (_jsx("svg", { className: "h-6 w-6", viewBox: "0 0 24 24", fill: "currentColor", children: _jsx("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" }) }));
|
|
49
|
-
};
|
|
50
|
-
const getButtonStyle = () => {
|
|
51
|
-
const baseStyle = "h-10 w-full text-base shadow-sm transition-colors duration-200 flex items-center justify-center gap-2";
|
|
52
|
-
if (isApplePayAvailable) {
|
|
53
|
-
return `${baseStyle} bg-black text-white hover:bg-black/80 ${className}`;
|
|
54
|
-
}
|
|
55
|
-
if (shouldShowQRCode) {
|
|
56
|
-
return `${baseStyle} bg-blue-600 text-white hover:bg-blue-700 ${className}`;
|
|
57
|
-
}
|
|
58
|
-
return `${baseStyle} bg-gray-400 text-gray-600 cursor-not-allowed ${className}`;
|
|
59
|
-
};
|
|
60
|
-
return (_jsxs("div", { className: "w-full", children: [_jsxs("button", { onClick: handleClick, disabled: disabled || processingPayment || (!isApplePayAvailable && !shouldShowQRCode), className: getButtonStyle(), style: { margin: 0 }, children: [getButtonIcon(), children || getButtonText()] }), showQRCode && qrCodeData && (_jsx("div", { className: "mt-4 p-4 bg-white border border-gray-200 rounded-lg shadow-sm", children: _jsxs("div", { className: "text-center", children: [_jsx("h3", { className: "text-lg font-medium text-gray-900 mb-2", children: "Scan QR Code to Pay" }), _jsx("p", { className: "text-sm text-gray-600 mb-4", children: "Use your mobile device to scan this QR code and complete your Apple Pay payment" }), _jsx("div", { className: "flex justify-center", children: _jsx("img", { src: qrCodeData.qrCodeUrl, alt: "Apple Pay QR Code", className: "w-48 h-48 border border-gray-200 rounded" }) }), _jsxs("div", { className: "mt-4 text-xs text-gray-500", children: [_jsxs("p", { children: ["Total: ", total.amount, " ", total.label] }), _jsxs("p", { children: ["Session: ", checkoutSessionId.slice(0, 8), "..."] })] }), _jsx("button", { onClick: () => setShowQRCode(false), className: "mt-3 px-4 py-2 text-sm text-gray-600 hover:text-gray-800 underline", children: "Close QR Code" })] }) })), applePayError && (_jsx("div", { className: "mt-2 p-2 bg-red-50 border border-red-200 rounded text-sm text-red-600", children: applePayError }))] }));
|
|
61
|
-
};
|
|
62
|
-
export default ApplePayUniversalButton;
|