@tagadapay/plugin-sdk 2.3.14 → 2.4.0

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.
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { CheckoutData } from '../hooks/useCheckout';
3
+ interface ApplePayButtonProps {
4
+ className?: string;
5
+ disabled?: boolean;
6
+ onSuccess?: (payment: any) => void;
7
+ onError?: (error: string) => void;
8
+ onCancel?: () => void;
9
+ storeName?: string;
10
+ currencyCode?: string;
11
+ variant?: 'default' | 'outline' | 'ghost';
12
+ size?: 'sm' | 'md' | 'lg';
13
+ checkout: CheckoutData | null;
14
+ }
15
+ export declare const ApplePayButton: React.FC<ApplePayButtonProps>;
16
+ export default ApplePayButton;
@@ -0,0 +1,53 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useApplePay } from '../hooks/useApplePay';
3
+ import { Button } from './Button';
4
+ export const ApplePayButton = ({ className = '', disabled = false, onSuccess, onError, onCancel, storeName, currencyCode = 'USD', variant = 'outline', size = 'lg', checkout, }) => {
5
+ // Use the Apple Pay hook
6
+ const { handleApplePayClick, processingPayment, applePayError, isApplePayAvailable } = useApplePay({
7
+ onSuccess,
8
+ onError,
9
+ onCancel,
10
+ checkoutSessionId: checkout?.checkoutSession?.id,
11
+ customerId: checkout?.checkoutSession?.customerId,
12
+ });
13
+ // Apple Pay button click handler
14
+ const handleClick = () => {
15
+ if (processingPayment || !isApplePayAvailable || !checkout)
16
+ return;
17
+ const { summary, checkoutSession } = checkout;
18
+ // Build line items from checkout summary
19
+ const lineItems = summary.items?.map((item) => ({
20
+ label: item.product?.name || item.variant?.name || 'Item',
21
+ amount: (item.adjustedAmount / 100).toFixed(2), // Convert from minor units
22
+ type: 'final',
23
+ })) || [];
24
+ // Add shipping as a line item if present
25
+ if (checkoutSession.shippingRate && checkoutSession.shippingRate.amount > 0) {
26
+ lineItems.push({
27
+ label: checkoutSession.shippingRate.shippingRateName || 'Shipping',
28
+ amount: (checkoutSession.shippingRate.amount / 100).toFixed(2),
29
+ type: 'final',
30
+ });
31
+ }
32
+ // Build total
33
+ const total = {
34
+ label: storeName || checkoutSession.store.name || 'Total',
35
+ amount: (summary.totalAdjustedAmount / 100).toFixed(2),
36
+ type: 'final',
37
+ };
38
+ // Apple Pay configuration
39
+ const config = {
40
+ countryCode: 'US',
41
+ supportedNetworks: ['visa', 'masterCard', 'amex', 'discover'],
42
+ merchantCapabilities: ['supports3DS'],
43
+ };
44
+ // Call the Apple Pay handler
45
+ handleApplePayClick(checkoutSession.id, lineItems, total, config, storeName || checkoutSession.store.name, currencyCode || summary.currency, []);
46
+ };
47
+ // Don't render the button if Apple Pay is not available
48
+ if (!isApplePayAvailable) {
49
+ return null;
50
+ }
51
+ return (_jsxs("div", { className: "w-full", children: [_jsx(Button, { type: "button", variant: variant, size: size, className: `w-full shadow-sm ${className}`, onClick: handleClick, disabled: disabled || processingPayment, children: _jsxs("div", { className: "flex items-center justify-center gap-3", children: [processingPayment ? (_jsx("div", { className: "h-5 w-5 animate-spin rounded-full border-2 border-white border-t-transparent" })) : (_jsx("img", { src: "/brandnetwork/applepay.svg", alt: "Apple Pay", className: "h-6 w-auto" })), _jsx("span", { className: "font-medium", children: processingPayment ? 'Processing...' : 'Pay with Apple Pay' })] }) }), applePayError && (_jsx("div", { className: "mt-2 rounded border border-red-200 bg-red-50 p-2 text-sm text-red-600", children: applePayError }))] }));
52
+ };
53
+ export default ApplePayButton;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
+ variant?: 'default' | 'outline' | 'ghost';
4
+ size?: 'sm' | 'md' | 'lg';
5
+ children: React.ReactNode;
6
+ }
7
+ export declare const Button: React.FC<ButtonProps>;
8
+ export default Button;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export const Button = ({ variant = 'default', size = 'md', className = '', children, ...props }) => {
3
+ // Determine button size classes
4
+ const sizeClasses = {
5
+ sm: 'h-10 px-3 text-sm',
6
+ md: 'h-11 px-4 text-sm',
7
+ lg: 'h-12 px-6 text-base',
8
+ };
9
+ // Determine button variant classes
10
+ const variantClasses = {
11
+ default: 'bg-blue-600 text-white border-blue-600 hover:bg-blue-700 hover:border-blue-700',
12
+ outline: 'border border-gray-300 bg-white text-gray-700 hover:bg-gray-50 hover:border-gray-400',
13
+ ghost: 'bg-transparent text-gray-700 hover:bg-gray-100 border-transparent',
14
+ };
15
+ const baseClasses = 'inline-flex items-center justify-center rounded-md font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50 disabled:pointer-events-none';
16
+ return (_jsx("button", { className: `${baseClasses} ${sizeClasses[size]} ${variantClasses[variant]} ${className}`, ...props, children: children }));
17
+ };
18
+ export default Button;
@@ -1 +1,3 @@
1
1
  export { default as DebugDrawer } from './DebugDrawer';
2
+ export { default as Button } from './Button';
3
+ export { default as ApplePayButton } from './ApplePayButton';
@@ -1 +1,3 @@
1
1
  export { default as DebugDrawer } from './DebugDrawer';
2
+ export { default as Button } from './Button';
3
+ export { default as ApplePayButton } from './ApplePayButton';
@@ -122,30 +122,30 @@ export function useApplePay(options = {}) {
122
122
  const lineItems = [
123
123
  {
124
124
  label: 'Subtotal',
125
- amount: (orderSummary.subtotalAdjustedAmount / 100).toFixed(2),
125
+ amount: orderSummary.subtotalAdjustedAmount > 0 ? (orderSummary.subtotalAdjustedAmount / 100).toFixed(2) : '0.00',
126
126
  type: 'final',
127
127
  },
128
128
  {
129
129
  label: 'Shipping',
130
- amount: (orderSummary.shippingCost / 100).toFixed(2),
130
+ amount: orderSummary.shippingCost > 0 ? (orderSummary.shippingCost / 100).toFixed(2) : '0.00',
131
131
  type: 'final',
132
132
  },
133
133
  {
134
134
  label: 'Tax',
135
- amount: (orderSummary.totalTaxAmount / 100).toFixed(2),
135
+ amount: orderSummary.totalTaxAmount > 0 ? (orderSummary.totalTaxAmount / 100).toFixed(2) : '0.00',
136
136
  type: 'final',
137
137
  },
138
138
  ];
139
139
  // Construct Apple Pay total
140
140
  const total = {
141
141
  label: 'Total',
142
- amount: (orderSummary.totalAdjustedAmount / 100).toFixed(2),
142
+ amount: orderSummary.totalAdjustedAmount > 0 ? (orderSummary.totalAdjustedAmount / 100).toFixed(2) : '0.00',
143
143
  type: 'final',
144
144
  };
145
145
  // Construct Apple Pay shipping methods from shipping rates
146
146
  const shippingMethods = shippingRates?.rates?.map((rate) => ({
147
147
  label: rate.shippingRateName,
148
- amount: (rate.amount / 100).toFixed(2),
148
+ amount: rate.amount > 0 ? (rate.amount / 100).toFixed(2) : '0.00',
149
149
  identifier: rate.id,
150
150
  detail: rate.description || '',
151
151
  })) || [];
@@ -41,4 +41,5 @@ export type { Payment, PaymentPollingHook, PollingOptions } from './hooks/usePay
41
41
  export type { PaymentInstrument, ThreedsChallenge, ThreedsHook, ThreedsOptions, ThreedsProvider, ThreedsSession } from './hooks/useThreeds';
42
42
  export type { ApplePayToken, CardPaymentMethod, PaymentHook, PaymentInstrumentResponse, PaymentOptions, PaymentResponse } from './hooks/usePayment';
43
43
  export type { ApplePayAddress, ApplePayConfig, ApplePayLineItem, ApplePayPaymentAuthorizedEvent, ApplePayPaymentRequest, ApplePayPaymentToken, ApplePayValidateMerchantEvent, BasisTheorySessionRequest, BasisTheoryTokenizeRequest, PayToken, UseApplePayOptions, UseApplePayResult } from './types/apple-pay';
44
+ export { Button, ApplePayButton } from './components';
44
45
  export { convertCurrency, formatMoney, formatMoneyWithoutSymbol, formatSimpleMoney, getCurrencyInfo, minorUnitsToMajorUnits, moneyStringOrNumberToMinorUnits } from './utils/money';
@@ -36,6 +36,6 @@ export { useThreedsModal } from './hooks/useThreedsModal';
36
36
  // Apple Pay hooks exports
37
37
  export { useApplePay } from './hooks/useApplePay';
38
38
  // Component exports
39
- // Apple Pay components removed - use useApplePay hook directly
39
+ export { Button, ApplePayButton } from './components';
40
40
  // Utility exports
41
41
  export { convertCurrency, formatMoney, formatMoneyWithoutSymbol, formatSimpleMoney, getCurrencyInfo, minorUnitsToMajorUnits, moneyStringOrNumberToMinorUnits } from './utils/money';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.3.14",
3
+ "version": "2.4.0",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",