@funnelsgrove/payments 0.1.44 → 0.1.45
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.
|
@@ -63,5 +63,5 @@ export type SharedCheckoutSpecialOfferDialogProps = {
|
|
|
63
63
|
themeColor: string;
|
|
64
64
|
title: string;
|
|
65
65
|
};
|
|
66
|
-
export declare function SharedStripeCheckoutV2Dialog({ checkoutAnalytics, checkoutSessionId, clientSecret, onClose, stripePromise, ...props }: SharedStripeCheckoutV2DialogProps): import("react/jsx-runtime").JSX.Element;
|
|
66
|
+
export declare function SharedStripeCheckoutV2Dialog({ checkoutAnalytics, checkoutSessionId, clientSecret, onClose, stripePromise, supportedCountries, ...props }: SharedStripeCheckoutV2DialogProps): import("react/jsx-runtime").JSX.Element;
|
|
67
67
|
export declare function SharedCheckoutSpecialOfferDialog({ buttonColor, buttonLabel, description, discountLabel, imageAlt, imageSrc, onAccept, themeColor, title, }: SharedCheckoutSpecialOfferDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -49,6 +49,7 @@ const formatCountdown = (remainingSeconds) => {
|
|
|
49
49
|
const seconds = normalizedSeconds % 60;
|
|
50
50
|
return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
|
51
51
|
};
|
|
52
|
+
const getFixedSupportedBillingCountry = (supportedCountries) => supportedCountries.length === 1 ? supportedCountries[0] : null;
|
|
52
53
|
function getFriendlyCardErrorMessage(error) {
|
|
53
54
|
return error instanceof Error && error.message
|
|
54
55
|
? error.message
|
|
@@ -68,6 +69,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
68
69
|
const initialCustomerEmail = (customerEmail === null || customerEmail === void 0 ? void 0 : customerEmail.trim()) || '';
|
|
69
70
|
const [emailDraft, setEmailDraft] = useState(initialCustomerEmail);
|
|
70
71
|
const normalizedSupportedCountries = useMemo(() => normalizeSupportedCheckoutCountries(supportedCountries), [supportedCountries]);
|
|
72
|
+
const fixedBillingCountry = getFixedSupportedBillingCountry(normalizedSupportedCountries);
|
|
71
73
|
const cardBrandLabels = useMemo(() => paymentMethodLabels.length > 0 ? paymentMethodLabels : defaultPaymentMethodLabels, [paymentMethodLabels]);
|
|
72
74
|
const normalizedPromoCode = promoCode.trim();
|
|
73
75
|
const showPromo = promoActive !== null && promoActive !== void 0 ? promoActive : (discountPercent > 0 && normalizedPromoCode.length > 0);
|
|
@@ -125,7 +127,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
125
127
|
name: 'never',
|
|
126
128
|
email: 'never',
|
|
127
129
|
address: {
|
|
128
|
-
country: 'auto',
|
|
130
|
+
country: fixedBillingCountry ? 'never' : 'auto',
|
|
129
131
|
},
|
|
130
132
|
},
|
|
131
133
|
},
|
|
@@ -136,7 +138,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
136
138
|
link: 'never',
|
|
137
139
|
},
|
|
138
140
|
};
|
|
139
|
-
}, []);
|
|
141
|
+
}, [fixedBillingCountry]);
|
|
140
142
|
const handleInactiveCheckoutSession = () => {
|
|
141
143
|
setError(null);
|
|
142
144
|
onInactiveCheckoutSession === null || onInactiveCheckoutSession === void 0 ? void 0 : onInactiveCheckoutSession();
|
|
@@ -168,7 +170,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
168
170
|
});
|
|
169
171
|
const handlePaymentElementChange = (event) => {
|
|
170
172
|
var _a, _b;
|
|
171
|
-
setBillingCountry((_b = (_a = event.value.billingDetails) === null || _a === void 0 ? void 0 : _a.address.country) !== null && _b !== void 0 ? _b :
|
|
173
|
+
setBillingCountry((_b = (_a = event.value.billingDetails) === null || _a === void 0 ? void 0 : _a.address.country) !== null && _b !== void 0 ? _b : fixedBillingCountry);
|
|
172
174
|
};
|
|
173
175
|
const trackCheckoutSuccess = async () => {
|
|
174
176
|
if (checkoutAnalytics) {
|
|
@@ -222,7 +224,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
222
224
|
if (submitting) {
|
|
223
225
|
return;
|
|
224
226
|
}
|
|
225
|
-
const billingCountryError = getBillingCountryError(billingCountry);
|
|
227
|
+
const billingCountryError = getBillingCountryError(billingCountry !== null && billingCountry !== void 0 ? billingCountry : fixedBillingCountry);
|
|
226
228
|
if (billingCountryError) {
|
|
227
229
|
setSharedError(billingCountryError);
|
|
228
230
|
return;
|
|
@@ -298,13 +300,22 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
298
300
|
} }) })] }), _jsx(PaymentElement, { options: paymentElementOptions, onChange: handlePaymentElementChange })] }), visibleError ? _jsx("p", { className: 'shared-checkout-v2-error', children: visibleError }) : null, _jsxs("button", { type: 'submit', className: 'shared-checkout-v2-card-submit', disabled: submitting, children: [_jsx(SecurityLockIcon, { className: 'shared-checkout-v2-card-submit-icon' }), submitting ? processingLabel : cardSubmitLabel] }), _jsx("div", { className: 'shared-checkout-v2-card-brands', "aria-hidden": 'true', children: cardBrandLabels.map((label) => (_jsx(PaymentBrandMark, { label: label, className: 'shared-checkout-v2-card-brand' }, label))) }), _jsxs("p", { className: 'shared-checkout-v2-secure-pill shared-checkout-v2-secure-pill--card', children: [_jsx(SecurityLockIcon, { className: 'shared-checkout-v2-secure-pill-icon' }), secureLabel] })] })] })] }));
|
|
299
301
|
}
|
|
300
302
|
export function SharedStripeCheckoutV2Dialog(_a) {
|
|
301
|
-
var { checkoutAnalytics, checkoutSessionId, clientSecret, onClose, stripePromise } = _a, props = __rest(_a, ["checkoutAnalytics", "checkoutSessionId", "clientSecret", "onClose", "stripePromise"]);
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
var { checkoutAnalytics, checkoutSessionId, clientSecret, onClose, stripePromise, supportedCountries } = _a, props = __rest(_a, ["checkoutAnalytics", "checkoutSessionId", "clientSecret", "onClose", "stripePromise", "supportedCountries"]);
|
|
304
|
+
const normalizedSupportedCountries = useMemo(() => normalizeSupportedCheckoutCountries(supportedCountries), [supportedCountries]);
|
|
305
|
+
const fixedBillingCountry = getFixedSupportedBillingCountry(normalizedSupportedCountries);
|
|
306
|
+
const checkoutProviderOptions = useMemo(() => (Object.assign(Object.assign({ clientSecret }, (fixedBillingCountry
|
|
307
|
+
? {
|
|
308
|
+
defaultValues: {
|
|
309
|
+
billingAddress: {
|
|
310
|
+
address: {
|
|
311
|
+
country: fixedBillingCountry,
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
}
|
|
316
|
+
: {})), { elementsOptions: {
|
|
305
317
|
appearance: stripeCheckoutV2Appearance,
|
|
306
|
-
},
|
|
307
|
-
}), [clientSecret]);
|
|
318
|
+
} })), [clientSecret, fixedBillingCountry]);
|
|
308
319
|
useEffect(() => {
|
|
309
320
|
if (!checkoutAnalytics) {
|
|
310
321
|
return;
|
|
@@ -320,7 +331,7 @@ export function SharedStripeCheckoutV2Dialog(_a) {
|
|
|
320
331
|
window.addEventListener('keydown', handleKeyDown);
|
|
321
332
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
322
333
|
}, [onClose]);
|
|
323
|
-
return (_jsxs(_Fragment, { children: [_jsx("div", { className: 'shared-checkout-v2-overlay', children: _jsx("div", { className: 'shared-checkout-v2-dialog', role: 'dialog', "aria-modal": 'true', "aria-labelledby": 'shared-checkout-v2-title', children: _jsx(CheckoutProvider, { stripe: stripePromise, options: checkoutProviderOptions, children: _jsx(SharedStripeCheckoutV2Form, Object.assign({}, props, { checkoutAnalytics: checkoutAnalytics, checkoutSessionId: checkoutSessionId, clientSecret: clientSecret, onClose: onClose })) }, clientSecret) }) }), _jsx("style", { children: sharedStripeCheckoutV2Styles })] }));
|
|
334
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { className: 'shared-checkout-v2-overlay', children: _jsx("div", { className: 'shared-checkout-v2-dialog', role: 'dialog', "aria-modal": 'true', "aria-labelledby": 'shared-checkout-v2-title', children: _jsx(CheckoutProvider, { stripe: stripePromise, options: checkoutProviderOptions, children: _jsx(SharedStripeCheckoutV2Form, Object.assign({}, props, { checkoutAnalytics: checkoutAnalytics, checkoutSessionId: checkoutSessionId, clientSecret: clientSecret, onClose: onClose, supportedCountries: normalizedSupportedCountries })) }, clientSecret) }) }), _jsx("style", { children: sharedStripeCheckoutV2Styles })] }));
|
|
324
335
|
}
|
|
325
336
|
function SharedCheckoutSpecialOfferGift({ discountLabel, imageAlt, imageSrc, }) {
|
|
326
337
|
if (imageSrc) {
|