@funnelsgrove/payments 0.1.44 → 0.1.46
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,11 @@ 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;
|
|
53
|
+
const checkoutCountryLabels = {
|
|
54
|
+
US: 'United States',
|
|
55
|
+
};
|
|
56
|
+
const getCheckoutCountryLabel = (countryCode) => { var _a; return (_a = checkoutCountryLabels[countryCode]) !== null && _a !== void 0 ? _a : countryCode; };
|
|
52
57
|
function getFriendlyCardErrorMessage(error) {
|
|
53
58
|
return error instanceof Error && error.message
|
|
54
59
|
? error.message
|
|
@@ -68,6 +73,10 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
68
73
|
const initialCustomerEmail = (customerEmail === null || customerEmail === void 0 ? void 0 : customerEmail.trim()) || '';
|
|
69
74
|
const [emailDraft, setEmailDraft] = useState(initialCustomerEmail);
|
|
70
75
|
const normalizedSupportedCountries = useMemo(() => normalizeSupportedCheckoutCountries(supportedCountries), [supportedCountries]);
|
|
76
|
+
const fixedBillingCountry = getFixedSupportedBillingCountry(normalizedSupportedCountries);
|
|
77
|
+
const fixedBillingCountryLabel = fixedBillingCountry
|
|
78
|
+
? getCheckoutCountryLabel(fixedBillingCountry)
|
|
79
|
+
: null;
|
|
71
80
|
const cardBrandLabels = useMemo(() => paymentMethodLabels.length > 0 ? paymentMethodLabels : defaultPaymentMethodLabels, [paymentMethodLabels]);
|
|
72
81
|
const normalizedPromoCode = promoCode.trim();
|
|
73
82
|
const showPromo = promoActive !== null && promoActive !== void 0 ? promoActive : (discountPercent > 0 && normalizedPromoCode.length > 0);
|
|
@@ -125,7 +134,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
125
134
|
name: 'never',
|
|
126
135
|
email: 'never',
|
|
127
136
|
address: {
|
|
128
|
-
country: 'auto',
|
|
137
|
+
country: fixedBillingCountry ? 'never' : 'auto',
|
|
129
138
|
},
|
|
130
139
|
},
|
|
131
140
|
},
|
|
@@ -136,7 +145,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
136
145
|
link: 'never',
|
|
137
146
|
},
|
|
138
147
|
};
|
|
139
|
-
}, []);
|
|
148
|
+
}, [fixedBillingCountry]);
|
|
140
149
|
const handleInactiveCheckoutSession = () => {
|
|
141
150
|
setError(null);
|
|
142
151
|
onInactiveCheckoutSession === null || onInactiveCheckoutSession === void 0 ? void 0 : onInactiveCheckoutSession();
|
|
@@ -168,7 +177,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
168
177
|
});
|
|
169
178
|
const handlePaymentElementChange = (event) => {
|
|
170
179
|
var _a, _b;
|
|
171
|
-
setBillingCountry((_b = (_a = event.value.billingDetails) === null || _a === void 0 ? void 0 : _a.address.country) !== null && _b !== void 0 ? _b :
|
|
180
|
+
setBillingCountry((_b = (_a = event.value.billingDetails) === null || _a === void 0 ? void 0 : _a.address.country) !== null && _b !== void 0 ? _b : fixedBillingCountry);
|
|
172
181
|
};
|
|
173
182
|
const trackCheckoutSuccess = async () => {
|
|
174
183
|
if (checkoutAnalytics) {
|
|
@@ -222,7 +231,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
222
231
|
if (submitting) {
|
|
223
232
|
return;
|
|
224
233
|
}
|
|
225
|
-
const billingCountryError = getBillingCountryError(billingCountry);
|
|
234
|
+
const billingCountryError = getBillingCountryError(billingCountry !== null && billingCountry !== void 0 ? billingCountry : fixedBillingCountry);
|
|
226
235
|
if (billingCountryError) {
|
|
227
236
|
setSharedError(billingCountryError);
|
|
228
237
|
return;
|
|
@@ -295,16 +304,25 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
295
304
|
}
|
|
296
305
|
setEmailDraft(event.target.value);
|
|
297
306
|
onCustomerEmailChange === null || onCustomerEmailChange === void 0 ? void 0 : onCustomerEmailChange(event.target.value);
|
|
298
|
-
} }) })] }), _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] })] })] })] }));
|
|
307
|
+
} }) })] }), _jsx(PaymentElement, { options: paymentElementOptions, onChange: handlePaymentElementChange }), fixedBillingCountry && fixedBillingCountryLabel ? (_jsxs("label", { className: 'shared-checkout-v2-country-field', children: [_jsx("span", { className: 'shared-checkout-v2-country-label', children: "Country" }), _jsx("span", { className: 'shared-checkout-v2-country-control', children: _jsx("select", { "aria-label": 'Country', className: 'shared-checkout-v2-country-select', value: fixedBillingCountry, onChange: () => setBillingCountry(fixedBillingCountry), children: _jsx("option", { value: fixedBillingCountry, children: fixedBillingCountryLabel }) }) })] })) : null] }), 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
308
|
}
|
|
300
309
|
export function SharedStripeCheckoutV2Dialog(_a) {
|
|
301
|
-
var { checkoutAnalytics, checkoutSessionId, clientSecret, onClose, stripePromise } = _a, props = __rest(_a, ["checkoutAnalytics", "checkoutSessionId", "clientSecret", "onClose", "stripePromise"]);
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
310
|
+
var { checkoutAnalytics, checkoutSessionId, clientSecret, onClose, stripePromise, supportedCountries } = _a, props = __rest(_a, ["checkoutAnalytics", "checkoutSessionId", "clientSecret", "onClose", "stripePromise", "supportedCountries"]);
|
|
311
|
+
const normalizedSupportedCountries = useMemo(() => normalizeSupportedCheckoutCountries(supportedCountries), [supportedCountries]);
|
|
312
|
+
const fixedBillingCountry = getFixedSupportedBillingCountry(normalizedSupportedCountries);
|
|
313
|
+
const checkoutProviderOptions = useMemo(() => (Object.assign(Object.assign({ clientSecret }, (fixedBillingCountry
|
|
314
|
+
? {
|
|
315
|
+
defaultValues: {
|
|
316
|
+
billingAddress: {
|
|
317
|
+
address: {
|
|
318
|
+
country: fixedBillingCountry,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
}
|
|
323
|
+
: {})), { elementsOptions: {
|
|
305
324
|
appearance: stripeCheckoutV2Appearance,
|
|
306
|
-
},
|
|
307
|
-
}), [clientSecret]);
|
|
325
|
+
} })), [clientSecret, fixedBillingCountry]);
|
|
308
326
|
useEffect(() => {
|
|
309
327
|
if (!checkoutAnalytics) {
|
|
310
328
|
return;
|
|
@@ -320,7 +338,7 @@ export function SharedStripeCheckoutV2Dialog(_a) {
|
|
|
320
338
|
window.addEventListener('keydown', handleKeyDown);
|
|
321
339
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
322
340
|
}, [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 })] }));
|
|
341
|
+
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
342
|
}
|
|
325
343
|
function SharedCheckoutSpecialOfferGift({ discountLabel, imageAlt, imageSrc, }) {
|
|
326
344
|
if (imageSrc) {
|
|
@@ -802,6 +820,58 @@ const sharedStripeCheckoutV2Styles = `
|
|
|
802
820
|
box-shadow: none;
|
|
803
821
|
}
|
|
804
822
|
|
|
823
|
+
.shared-checkout-v2-country-field {
|
|
824
|
+
box-sizing: border-box;
|
|
825
|
+
display: flex;
|
|
826
|
+
flex-direction: column;
|
|
827
|
+
gap: 7px;
|
|
828
|
+
margin: 14px 0 0;
|
|
829
|
+
color: #303136;
|
|
830
|
+
font-size: 14px;
|
|
831
|
+
font-weight: 400;
|
|
832
|
+
line-height: 1.2;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
.shared-checkout-v2-country-label {
|
|
836
|
+
padding: 0 14px;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
.shared-checkout-v2-country-control {
|
|
840
|
+
position: relative;
|
|
841
|
+
display: block;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
.shared-checkout-v2-country-control::after {
|
|
845
|
+
position: absolute;
|
|
846
|
+
right: 17px;
|
|
847
|
+
top: 50%;
|
|
848
|
+
width: 8px;
|
|
849
|
+
height: 8px;
|
|
850
|
+
border-right: 2px solid #6f7380;
|
|
851
|
+
border-bottom: 2px solid #6f7380;
|
|
852
|
+
content: '';
|
|
853
|
+
pointer-events: none;
|
|
854
|
+
transform: translateY(-65%) rotate(45deg);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
.shared-checkout-v2-country-select {
|
|
858
|
+
width: 100%;
|
|
859
|
+
min-height: 50px;
|
|
860
|
+
box-sizing: border-box;
|
|
861
|
+
appearance: none;
|
|
862
|
+
border: 1px solid #dedede;
|
|
863
|
+
border-radius: 0;
|
|
864
|
+
background: #fff;
|
|
865
|
+
box-shadow: 0 1px 2px rgb(16 24 40 / 8%);
|
|
866
|
+
color: #303136;
|
|
867
|
+
font: inherit;
|
|
868
|
+
font-size: 18px;
|
|
869
|
+
font-weight: 400;
|
|
870
|
+
line-height: 1.2;
|
|
871
|
+
outline: none;
|
|
872
|
+
padding: 0 44px 0 14px;
|
|
873
|
+
}
|
|
874
|
+
|
|
805
875
|
.shared-checkout-v2-error {
|
|
806
876
|
margin: 0;
|
|
807
877
|
color: #c43737;
|