@funnelsgrove/payments 0.64.0 → 0.66.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.
- package/dist/components/CheckoutSheet.d.ts +44 -0
- package/dist/components/CheckoutSheet.js +96 -0
- package/dist/components/CheckoutSheet.styles.d.ts +2 -0
- package/dist/components/CheckoutSheet.styles.js +241 -0
- package/dist/components/walletFirstParts.d.ts +16 -0
- package/dist/components/walletFirstParts.js +22 -0
- package/dist/generated/package-version.d.ts +1 -1
- package/dist/generated/package-version.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/providers/solidgate/components/SolidgateCheckoutDialog.d.ts +1 -1
- package/dist/providers/solidgate/components/SolidgateCheckoutDialog.js +26 -12
- package/dist/providers/solidgate/components/SolidgateCheckoutDialog.styles.d.ts +1 -1
- package/dist/providers/solidgate/components/SolidgateCheckoutDialog.styles.js +4 -0
- package/dist/providers/solidgate/components/SolidgateCheckoutDialog.types.d.ts +21 -2
- package/dist/providers/solidgate/components/SolidgateCheckoutSheetLayout.d.ts +17 -0
- package/dist/providers/solidgate/components/SolidgateCheckoutSheetLayout.js +36 -0
- package/dist/providers/solidgate/components/SolidgatePaymentForm.d.ts +14 -1
- package/dist/providers/solidgate/components/SolidgatePaymentForm.js +62 -39
- package/dist/providers/stripe/components/SharedCheckoutPaymentMethods.internal.d.ts +3 -1
- package/dist/providers/stripe/components/SharedCheckoutPaymentMethods.internal.js +3 -3
- package/dist/providers/stripe/components/SharedStripeCheckoutV2.styles.d.ts +1 -1
- package/dist/providers/stripe/components/SharedStripeCheckoutV2.styles.js +25 -0
- package/dist/providers/stripe/components/SharedStripeCheckoutV2Dialog.js +9 -0
- package/dist/providers/stripe/components/SharedStripeCheckoutV2Form.internal.js +53 -19
- package/dist/providers/stripe/components/StripeCheckoutSheet.d.ts +16 -0
- package/dist/providers/stripe/components/StripeCheckoutSheet.js +27 -0
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.d.ts +1 -1
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.js +2 -19
- package/dist/providers/stripe/components/index.d.ts +1 -0
- package/dist/providers/stripe/components/index.js +1 -0
- package/dist/providers/stripe/hooks/useStripeSubscriptionCheckoutSession.js +8 -6
- package/dist/providers/stripe/services/checkout/types.d.ts +1 -0
- package/dist/providers/stripe/services/checkoutSessionPaymentMethods.d.ts +2 -0
- package/dist/providers/stripe/services/checkoutSessionPaymentMethods.js +10 -0
- package/package.json +5 -5
|
@@ -16,6 +16,7 @@ import { isStripeCheckoutAlreadyPaidError, normalizeStripeCheckoutError } from '
|
|
|
16
16
|
import { SharedCheckoutPaymentMethods } from './SharedCheckoutPaymentMethods.internal.js';
|
|
17
17
|
import { SharedStripeCheckoutV2Summary } from './SharedStripeCheckoutV2Summary.internal.js';
|
|
18
18
|
import { useCheckoutEmail } from './useCheckoutEmail.internal.js';
|
|
19
|
+
import { getCheckoutSessionPaymentMethodTypes } from '../services/checkoutSessionPaymentMethods.js';
|
|
19
20
|
import { defaultCheckoutV2Copy } from './checkout-v2.content.js';
|
|
20
21
|
const defaultPaymentMethodLabels = ['Visa', 'Mastercard', 'Maestro', 'Discover'];
|
|
21
22
|
export const getFixedSupportedBillingCountry = (supportedCountries) => supportedCountries.length === 1 ? supportedCountries[0] : null;
|
|
@@ -40,6 +41,11 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
40
41
|
const submitInFlightRef = useRef(false);
|
|
41
42
|
const [paymentElementReady, setPaymentElementReady] = useState(false);
|
|
42
43
|
const [paymentElementComplete, setPaymentElementComplete] = useState(false);
|
|
44
|
+
const paymentElementRef = useRef(null);
|
|
45
|
+
const [stripeMethodType, setStripeMethodType] = useState('card');
|
|
46
|
+
const [accordionExpanded, setAccordionExpanded] = useState(null);
|
|
47
|
+
// CHECKOUT-BR-010: a session with methods beyond cards shows Stripe's accordion next to the wallet option.
|
|
48
|
+
const accordionLayout = getCheckoutSessionPaymentMethodTypes(checkoutSessionId).some((type) => type !== 'card');
|
|
43
49
|
const [error, setError] = useState(null);
|
|
44
50
|
const [billingCountry, setBillingCountry] = useState(null);
|
|
45
51
|
const { initialCustomerEmail, resolvedCustomerEmail, customerEmailEditable, emailDraft, setEmailDraft, rejectedEmail, setRejectedEmail, emailSaving, emailSessionChanged, commitEmailDraftIfValid, ensureCustomerEmail } = useCheckoutEmail({
|
|
@@ -104,8 +110,7 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
104
110
|
};
|
|
105
111
|
}, [walletPaymentMethods]);
|
|
106
112
|
const paymentElementOptions = useMemo(() => {
|
|
107
|
-
return {
|
|
108
|
-
fields: {
|
|
113
|
+
return Object.assign(Object.assign({ fields: {
|
|
109
114
|
billingDetails: {
|
|
110
115
|
name: 'never',
|
|
111
116
|
email: 'never',
|
|
@@ -113,15 +118,27 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
113
118
|
country: fixedBillingCountry ? 'never' : 'auto',
|
|
114
119
|
},
|
|
115
120
|
},
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
|
|
121
|
+
}, layout: accordionLayout
|
|
122
|
+
? {
|
|
123
|
+
type: 'accordion',
|
|
124
|
+
defaultCollapsed: effectiveSelectedMethod === 'wallet',
|
|
125
|
+
radios: true,
|
|
126
|
+
spacedAccordionItems: true,
|
|
127
|
+
visibleAccordionItemsCount: 0,
|
|
128
|
+
}
|
|
129
|
+
: 'tabs' }, (accordionLayout ? { paymentMethodOrder: ['card'] } : {})), { wallets: {
|
|
119
130
|
applePay: 'never',
|
|
120
131
|
googlePay: 'never',
|
|
121
132
|
link: 'never',
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
} });
|
|
134
|
+
// The initial collapsed state is read once when Stripe mounts the element.
|
|
135
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
136
|
+
}, [accordionLayout, fixedBillingCountry]);
|
|
137
|
+
const accordionStartsExpanded = typeof paymentElementOptions.layout === 'object'
|
|
138
|
+
&& paymentElementOptions.layout.defaultCollapsed === false;
|
|
139
|
+
const showCardForm = accordionLayout
|
|
140
|
+
? (accordionExpanded !== null && accordionExpanded !== void 0 ? accordionExpanded : accordionStartsExpanded) && effectiveSelectedMethod === 'card'
|
|
141
|
+
: true;
|
|
125
142
|
const handleInactiveCheckoutSession = () => {
|
|
126
143
|
setError(null);
|
|
127
144
|
onInactiveCheckoutSession === null || onInactiveCheckoutSession === void 0 ? void 0 : onInactiveCheckoutSession();
|
|
@@ -146,8 +163,11 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
146
163
|
onError === null || onError === void 0 ? void 0 : onError(message);
|
|
147
164
|
};
|
|
148
165
|
const selectWalletMethod = () => {
|
|
166
|
+
var _a;
|
|
149
167
|
if (showWalletMethod && !paypalPending && !submitting) {
|
|
150
168
|
setSelectedMethod('wallet');
|
|
169
|
+
if (accordionLayout)
|
|
170
|
+
(_a = paymentElementRef.current) === null || _a === void 0 ? void 0 : _a.collapse();
|
|
151
171
|
}
|
|
152
172
|
};
|
|
153
173
|
const selectCardMethod = () => { if (!paypalPending && !submitting)
|
|
@@ -164,9 +184,19 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
164
184
|
supportedCountries: normalizedSupportedCountries,
|
|
165
185
|
});
|
|
166
186
|
const handlePaymentElementChange = (event) => {
|
|
167
|
-
var _a, _b;
|
|
187
|
+
var _a, _b, _c;
|
|
168
188
|
setPaymentElementComplete(event.complete);
|
|
169
|
-
|
|
189
|
+
setStripeMethodType(event.value.type);
|
|
190
|
+
if (accordionLayout)
|
|
191
|
+
setAccordionExpanded(!event.collapsed);
|
|
192
|
+
if (accordionLayout && !event.collapsed) {
|
|
193
|
+
// While a wallet or PayPal payment is in flight the wallet option stays selected.
|
|
194
|
+
if (paypalPending || walletConfirming)
|
|
195
|
+
(_a = paymentElementRef.current) === null || _a === void 0 ? void 0 : _a.collapse();
|
|
196
|
+
else
|
|
197
|
+
setSelectedMethod('card');
|
|
198
|
+
}
|
|
199
|
+
setBillingCountry((_c = (_b = event.value.billingDetails) === null || _b === void 0 ? void 0 : _b.address.country) !== null && _c !== void 0 ? _c : fixedBillingCountry);
|
|
170
200
|
};
|
|
171
201
|
const trackCheckoutSuccess = async (embedded = false) => {
|
|
172
202
|
if (checkoutAnalytics) {
|
|
@@ -262,12 +292,18 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
262
292
|
finishSubmitting();
|
|
263
293
|
}
|
|
264
294
|
};
|
|
295
|
+
const emailField = (_jsxs("label", { className: emailFieldClassName, children: [_jsx("span", { className: 'shared-checkout-v2-email-label', children: customerEmailLabel }), _jsx("span", { className: 'shared-checkout-v2-email-control', children: _jsx("input", { type: 'email', autoComplete: 'email', className: 'shared-checkout-v2-email-input', disabled: !customerEmailEditable || emailSaving, inputMode: 'email', readOnly: !customerEmailEditable, value: customerEmailEditable ? emailDraft : initialCustomerEmail, placeholder: customerEmailPlaceholder, onBlur: (event) => commitEmailDraftIfValid(event.currentTarget.value), onChange: (event) => {
|
|
296
|
+
if (!customerEmailEditable) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
setEmailDraft(event.target.value);
|
|
300
|
+
} }) })] }));
|
|
265
301
|
const visibleError = error;
|
|
266
302
|
if (providerConfirmed && !completed)
|
|
267
303
|
return _jsxs("form", { onSubmit: handleSubmit, className: 'shared-checkout-v2-verifying', style: checkoutStyle, children: [_jsx("p", { role: error ? 'alert' : 'status', children: error || copy.verifyingPayment }), _jsx("button", { type: 'submit', disabled: submitting, className: 'shared-checkout-v2-status-button', children: copy.checkPaymentStatus })] });
|
|
268
304
|
if (completed)
|
|
269
305
|
return _jsx("div", { role: 'status', className: 'shared-checkout-v2-confirmed', style: checkoutStyle, children: copy.paymentConfirmed });
|
|
270
|
-
return (_jsxs("div", { className: 'shared-checkout-v2-shell', "data-variant": variant, style: checkoutStyle, children: [presentation === 'dialog' ? _jsxs(_Fragment, { children: [_jsxs("header", { className: 'shared-checkout-v2-header', children: [_jsx("button", { type: 'button', className: 'shared-checkout-v2-close', onClick: onClose, "aria-label": closeAriaLabel, children: _jsx("span", { "aria-hidden": 'true' }) }), _jsx("h2", { id: 'shared-checkout-v2-title', children: title })] }), !(showPayPalMethod && effectiveSelectedMethod === 'wallet') ? _jsx(SharedStripeCheckoutV2Summary, { countdownUnit: copy.countdownUnit, discountPercent, countdownLabel, remainingSeconds, variant, satisfactionPercent, satisfactionLabel, originalPriceLabel, originalPriceValue, discountLabel, discountAmountLabel, promoCodeLabel, promoCode, totalLabel, totalValue, savedLabel, showPromo }) : null] }) : null, _jsxs("form", { className: 'shared-checkout-v2-payment', onSubmit: (event) => void handleSubmit(event), children: [showWalletMethod || showPayPalMethod ? (_jsx(SharedCheckoutPaymentMethods, { showWalletMethod: showWalletMethod, showPayPalMethod: showPayPalMethod, selectedMethod: effectiveSelectedMethod, disabled: paypalPending || submitting || walletConfirming, paymentMethodLabel: copy.paymentMethodLabel, cardLabel: copy.cardLabel, walletAriaLabel: walletAriaLabel, walletPaymentMethods: walletPaymentMethods, cardBrandLabels: cardBrandLabels, onWalletSelect: selectWalletMethod, onCardSelect: selectCardMethod })) : null, presentation === 'dialog' ? _jsxs("div", { hidden: effectiveSelectedMethod !== 'wallet', className: [
|
|
306
|
+
return (_jsxs("div", { className: 'shared-checkout-v2-shell', "data-variant": variant, style: checkoutStyle, children: [presentation === 'dialog' ? _jsxs(_Fragment, { children: [_jsxs("header", { className: 'shared-checkout-v2-header', children: [_jsx("button", { type: 'button', className: 'shared-checkout-v2-close', onClick: onClose, "aria-label": closeAriaLabel, children: _jsx("span", { "aria-hidden": 'true' }) }), _jsx("h2", { id: 'shared-checkout-v2-title', children: title })] }), !(showPayPalMethod && effectiveSelectedMethod === 'wallet') ? _jsx(SharedStripeCheckoutV2Summary, { countdownUnit: copy.countdownUnit, discountPercent, countdownLabel, remainingSeconds, variant, satisfactionPercent, satisfactionLabel, originalPriceLabel, originalPriceValue, discountLabel, discountAmountLabel, promoCodeLabel, promoCode, totalLabel, totalValue, savedLabel, showPromo }) : null] }) : null, _jsxs("form", { className: 'shared-checkout-v2-payment', onSubmit: (event) => void handleSubmit(event), children: [showWalletMethod || showPayPalMethod ? (_jsx(SharedCheckoutPaymentMethods, { showWalletMethod: showWalletMethod, showPayPalMethod: showPayPalMethod, selectedMethod: effectiveSelectedMethod, disabled: paypalPending || submitting || walletConfirming, layout: accordionLayout ? 'accordion' : 'tabs', paymentMethodLabel: copy.paymentMethodLabel, cardLabel: copy.cardLabel, walletAriaLabel: walletAriaLabel, walletPaymentMethods: walletPaymentMethods, cardBrandLabels: cardBrandLabels, onWalletSelect: selectWalletMethod, onCardSelect: selectCardMethod })) : null, presentation === 'dialog' ? _jsxs("div", { hidden: effectiveSelectedMethod !== 'wallet', className: [
|
|
271
307
|
'shared-checkout-v2-wallet-panel',
|
|
272
308
|
effectiveSelectedMethod === 'wallet' ? 'is-visible' : '',
|
|
273
309
|
]
|
|
@@ -280,15 +316,13 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
280
316
|
if (!email)
|
|
281
317
|
setWalletConfirming(false);
|
|
282
318
|
return email;
|
|
283
|
-
}, checkoutAnalytics: checkoutAnalytics, checkoutSessionId: checkoutSessionId, className: 'shared-checkout-v2-express-buttons', confirmEmail: false, customerEmail: resolvedCustomerEmail, customerName: customerName, initialAvailable: initialWalletAvailable, keepInitialAvailableOnReady: initialWalletAvailable === true, onAvailabilityChange: handleWalletAvailabilityChange, onCancel: () => { setWalletConfirming(false); onWalletCancel === null || onWalletCancel === void 0 ? void 0 : onWalletCancel(); }, onError: (message, details) => setSharedError(message, true, details), onPaymentInfoSubmitted: onPaymentInfoSubmitted, onPaymentRejected: () => { setWalletConfirming(false); setSelectedMethod('card'); }, onSuccess: () => trackCheckoutSuccess(), onEmbeddedComplete: () => setCompleted(true), onVerificationPending: () => setProviderConfirmed(true), options: expressCheckoutOptions, returnUrl: returnUrl, summaryLabel: expressCheckoutSummaryLabel, supportedCountries: normalizedSupportedCountries, unsupportedCountryMessage: unsupportedCountryMessage }), _jsx("span", { className: 'shared-checkout-v2-sr-only', children: walletAriaLabel })] })] }) : null, _jsxs("div", { hidden: effectiveSelectedMethod !== 'card', className: [
|
|
319
|
+
}, checkoutAnalytics: checkoutAnalytics, checkoutSessionId: checkoutSessionId, className: 'shared-checkout-v2-express-buttons', confirmEmail: false, customerEmail: resolvedCustomerEmail, customerName: customerName, initialAvailable: initialWalletAvailable, keepInitialAvailableOnReady: initialWalletAvailable === true, onAvailabilityChange: handleWalletAvailabilityChange, onCancel: () => { setWalletConfirming(false); onWalletCancel === null || onWalletCancel === void 0 ? void 0 : onWalletCancel(); }, onError: (message, details) => setSharedError(message, true, details), onPaymentInfoSubmitted: onPaymentInfoSubmitted, onPaymentRejected: () => { setWalletConfirming(false); setSelectedMethod('card'); }, onSuccess: () => trackCheckoutSuccess(), onEmbeddedComplete: () => setCompleted(true), onVerificationPending: () => setProviderConfirmed(true), options: expressCheckoutOptions, returnUrl: returnUrl, summaryLabel: expressCheckoutSummaryLabel, supportedCountries: normalizedSupportedCountries, unsupportedCountryMessage: unsupportedCountryMessage }), _jsx("span", { className: 'shared-checkout-v2-sr-only', children: walletAriaLabel })] })] }) : null, _jsxs("div", { hidden: !accordionLayout && effectiveSelectedMethod !== 'card', className: [
|
|
284
320
|
'shared-checkout-v2-card-panel',
|
|
285
|
-
effectiveSelectedMethod === 'card' ? 'is-visible' : '',
|
|
321
|
+
accordionLayout || effectiveSelectedMethod === 'card' ? 'is-visible' : '',
|
|
286
322
|
]
|
|
287
323
|
.filter(Boolean)
|
|
288
|
-
.join(' '), children: [_jsxs("div", { className: 'shared-checkout-v2-card-box', children: [
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
setEmailDraft(event.target.value);
|
|
293
|
-
} }) })] }), _jsx(PaymentElement, { options: paymentElementOptions, onChange: handlePaymentElementChange, onReady: () => setPaymentElementReady(true) }), fixedBillingCountry && fixedBillingCountryLabel ? (_jsxs("label", { className: 'shared-checkout-v2-country-field', children: [_jsx("span", { className: 'shared-checkout-v2-country-label', children: copy.billingCountryLabel }), _jsx("span", { className: 'shared-checkout-v2-country-control', children: _jsx("select", { "aria-label": copy.billingCountryLabel, 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 || emailSaving || emailSessionChanged || !paymentElementReady, children: [_jsx(SecurityLockIcon, { className: 'shared-checkout-v2-card-submit-icon' }), submitting || emailSaving || emailSessionChanged ? 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] })] })] })] }));
|
|
324
|
+
.join(' '), children: [_jsxs("div", { className: 'shared-checkout-v2-card-box', children: [accordionLayout ? null : emailField, _jsx(PaymentElement, { options: paymentElementOptions, onChange: handlePaymentElementChange, onReady: (element) => {
|
|
325
|
+
paymentElementRef.current = element;
|
|
326
|
+
setPaymentElementReady(true);
|
|
327
|
+
} }), accordionLayout && showCardForm ? emailField : null, fixedBillingCountry && fixedBillingCountryLabel ? (_jsxs("label", { className: 'shared-checkout-v2-country-field', children: [_jsx("span", { className: 'shared-checkout-v2-country-label', children: copy.billingCountryLabel }), _jsx("span", { className: 'shared-checkout-v2-country-control', children: _jsx("select", { "aria-label": copy.billingCountryLabel, 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, showCardForm ? _jsxs(_Fragment, { children: [_jsxs("button", { type: 'submit', className: 'shared-checkout-v2-card-submit', disabled: submitting || emailSaving || emailSessionChanged || !paymentElementReady, children: [_jsx(SecurityLockIcon, { className: 'shared-checkout-v2-card-submit-icon' }), submitting || emailSaving || emailSessionChanged ? processingLabel : cardSubmitLabel] }), stripeMethodType === 'card' ? _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))) }) : null, _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] })] }) : null] })] })] }));
|
|
294
328
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bottom-sheet subscription checkout: CheckoutSheet's order summary over the
|
|
3
|
+
* wallet-first Stripe methods. The caller owns the Checkout Session; pass its
|
|
4
|
+
* `clientSecret` as soon as it exists (it may be prepared before `open`) so the
|
|
5
|
+
* wallet button is ready when the sheet opens.
|
|
6
|
+
*/
|
|
7
|
+
import { type CheckoutSheetProps } from '../../../components/CheckoutSheet.js';
|
|
8
|
+
import { type StripeWalletFirstCheckoutProps } from './StripeWalletFirstCheckout.js';
|
|
9
|
+
export type StripeCheckoutSheetProps = Omit<StripeWalletFirstCheckoutProps, 'themeColor'> & Omit<CheckoutSheetProps, 'children' | 'visible'> & {
|
|
10
|
+
open: boolean;
|
|
11
|
+
/** Wallet-first radio and focus color; defaults to the sheet's `selectedColor`. */
|
|
12
|
+
themeColor?: string;
|
|
13
|
+
/** Shown under the payment methods, e.g. a failed checkout session. */
|
|
14
|
+
error?: string | null;
|
|
15
|
+
};
|
|
16
|
+
export declare function StripeCheckoutSheet({ open, title, closeAriaLabel, closeDisabled, onClose, summary, guaranteeLabel, accentColor, selectedColor, themeColor, error, ...checkout }: StripeCheckoutSheetProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
/**
|
|
15
|
+
* Bottom-sheet subscription checkout: CheckoutSheet's order summary over the
|
|
16
|
+
* wallet-first Stripe methods. The caller owns the Checkout Session; pass its
|
|
17
|
+
* `clientSecret` as soon as it exists (it may be prepared before `open`) so the
|
|
18
|
+
* wallet button is ready when the sheet opens.
|
|
19
|
+
*/
|
|
20
|
+
import { CheckoutSheet } from '../../../components/CheckoutSheet.js';
|
|
21
|
+
import { StripeWalletFirstCheckout } from './StripeWalletFirstCheckout.js';
|
|
22
|
+
export function StripeCheckoutSheet(_a) {
|
|
23
|
+
var { open, title, closeAriaLabel, closeDisabled, onClose, summary, guaranteeLabel, accentColor, selectedColor = '#4db53f', themeColor, error } = _a, checkout = __rest(_a, ["open", "title", "closeAriaLabel", "closeDisabled", "onClose", "summary", "guaranteeLabel", "accentColor", "selectedColor", "themeColor", "error"]);
|
|
24
|
+
if (!open)
|
|
25
|
+
return null;
|
|
26
|
+
return (_jsxs(CheckoutSheet, { visible: true, title: title, closeAriaLabel: closeAriaLabel, closeDisabled: closeDisabled, onClose: onClose, summary: summary, guaranteeLabel: guaranteeLabel, accentColor: accentColor, selectedColor: selectedColor, children: [_jsx(StripeWalletFirstCheckout, Object.assign({}, checkout, { themeColor: themeColor !== null && themeColor !== void 0 ? themeColor : selectedColor })), error ? _jsx("p", { className: 'fg-sheet-error', role: 'alert', children: error }) : null] }));
|
|
27
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Stripe, StripeCheckoutPaymentElementOptions } from '@stripe/stripe-js';
|
|
2
|
-
import {
|
|
2
|
+
import type { PlatformWalletPaymentMethod } from './walletPlatform.js';
|
|
3
3
|
import { type StripeSubscriptionCheckoutAnalyticsContext } from '../services/checkoutCompletionAnalytics.service.js';
|
|
4
4
|
import { type StripeCheckoutErrorDetails } from '../services/stripeCheckoutError.js';
|
|
5
5
|
export type StripeWalletFirstCheckoutCopy = {
|
|
@@ -18,11 +18,11 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
18
18
|
* The caller owns the subscription Checkout Session (`clientSecret`), the copy
|
|
19
19
|
* and what happens after `onSuccess`.
|
|
20
20
|
*/
|
|
21
|
-
import { useEffect, useMemo, useRef, useState
|
|
21
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
22
22
|
import { CheckoutProvider, PaymentElement, useCheckout } from '@stripe/react-stripe-js/checkout';
|
|
23
23
|
import { completePaywallCheckout } from '@funnelsgrove/runtime';
|
|
24
24
|
import { StripeCheckoutExpressCheckoutButton } from './StripeCheckoutExpressCheckoutButton.js';
|
|
25
|
-
import {
|
|
25
|
+
import { ApplePayMark, CardBrandMarks, GooglePayMark, MethodCard, usePlatformWallet } from '../../../components/walletFirstParts.js';
|
|
26
26
|
import { stripeWalletFirstCheckoutStyles } from './StripeWalletFirstCheckout.styles.js';
|
|
27
27
|
import { queueStripeSubscriptionCheckoutStarted, trackPaidStripeSubscriptionCheckoutCompleted, trackStripeCheckoutShown, trackStripeSubscriptionPaymentInfoSubmitted, } from '../services/checkoutCompletionAnalytics.service.js';
|
|
28
28
|
import { trackCheckoutFailureShown } from '../../../services/checkoutObservability.service.js';
|
|
@@ -196,23 +196,6 @@ function CheckoutLayout({ cardBody, copy, disabled, footer, onSelect, selected,
|
|
|
196
196
|
const WalletMark = wallet === 'applePay' ? ApplePayMark : GooglePayMark;
|
|
197
197
|
return (_jsxs("div", { className: 'wfc', style: style, children: [_jsxs(MethodCard, { checked: selected === 'wallet', disabled: disabled, label: copy.walletLabels[wallet], onSelect: () => onSelect('wallet'), header: _jsx(WalletMark, {}), children: [_jsx("ul", { className: 'wfc-benefits', children: copy.walletBenefits[wallet].map(item => _jsxs("li", { children: [_jsx(CheckIcon, {}), item] }, item)) }), _jsx("div", { className: 'wfc-wallet-slot', children: walletSlot }), _jsx("p", { className: walletNote ? 'wfc-secure is-status' : 'wfc-secure', role: walletNote ? 'status' : undefined, children: walletNote || copy.secureNote })] }), _jsx(MethodCard, { checked: selected === 'card', disabled: disabled, label: copy.cardLabel, onSelect: () => onSelect('card'), header: _jsx(CardBrandMarks, {}), children: cardBody }), footer] }));
|
|
198
198
|
}
|
|
199
|
-
function MethodCard({ checked, children, disabled, header, label, onSelect }) {
|
|
200
|
-
return (_jsxs("section", { className: 'wfc-method', "data-checked": checked, children: [_jsxs("button", { type: 'button', role: 'radio', "aria-checked": checked, "aria-label": label, className: 'wfc-method-head', disabled: disabled, onClick: onSelect, children: [_jsx("span", { className: 'wfc-radio', "aria-hidden": 'true' }), header] }), _jsx("div", { className: 'wfc-method-body', "data-open": checked, inert: !checked, "aria-hidden": !checked, children: _jsx("div", { className: 'wfc-method-clip', children: _jsx("div", { className: 'wfc-method-content', children: children }) }) })] }));
|
|
201
|
-
}
|
|
202
199
|
function CheckIcon() {
|
|
203
200
|
return _jsx("svg", { className: 'wfc-check', viewBox: '0 0 16 16', "aria-hidden": 'true', children: _jsx("path", { d: 'M3 8.5 6.5 12 13 4.5', fill: 'none', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round' }) });
|
|
204
201
|
}
|
|
205
|
-
function ApplePayMark() {
|
|
206
|
-
return (_jsxs("svg", { className: 'wfc-mark wfc-mark--apple', viewBox: '0 0 64 26', role: 'img', "aria-label": 'Apple Pay', children: [_jsx("path", { d: 'M14.6 13.6c0-2.6 2.1-3.8 2.2-3.9-1.2-1.8-3.1-2-3.7-2-1.6-.2-3.1.9-3.9.9-.8 0-2-.9-3.4-.9-1.7 0-3.3 1-4.2 2.6-1.8 3.1-.5 7.7 1.3 10.2.9 1.2 1.9 2.6 3.2 2.6 1.3-.1 1.8-.8 3.3-.8 1.6 0 2 .8 3.4.8s2.3-1.3 3.1-2.5c1-1.4 1.4-2.8 1.4-2.9 0 0-2.7-1-2.7-4.1ZM12.1 6c.7-.9 1.2-2 1-3.2-1 0-2.3.7-3 1.6-.7.8-1.3 2-1.1 3.1 1.1.1 2.3-.6 3.1-1.5Z', fill: 'currentColor' }), _jsx("text", { x: '22', y: '20', fontSize: '17', fontWeight: '600', fill: 'currentColor', fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif', children: "Pay" })] }));
|
|
207
|
-
}
|
|
208
|
-
function GooglePayMark() {
|
|
209
|
-
return (_jsxs("svg", { className: 'wfc-mark wfc-mark--google', viewBox: '0 0 64 26', role: 'img', "aria-label": 'Google Pay', children: [_jsx("path", { d: 'M19.6 13.2c0-.6-.1-1.2-.2-1.8h-8.6v3.4h4.9a4.2 4.2 0 0 1-1.8 2.8v2.3h2.9c1.7-1.6 2.8-3.9 2.8-6.7Z', fill: '#4285F4' }), _jsx("path", { d: 'M10.8 22c2.4 0 4.5-.8 6-2.2l-2.9-2.3c-.8.6-1.9.9-3.1.9-2.4 0-4.4-1.6-5.1-3.7h-3v2.3A9 9 0 0 0 10.8 22Z', fill: '#34A853' }), _jsx("path", { d: 'M5.7 14.7a5.4 5.4 0 0 1 0-3.4V9H2.7a9 9 0 0 0 0 8l3-2.3Z', fill: '#FBBC04' }), _jsx("path", { d: 'M10.8 7.6c1.3 0 2.5.5 3.5 1.4l2.6-2.6A9 9 0 0 0 2.7 9l3 2.3c.7-2.1 2.7-3.7 5.1-3.7Z', fill: '#EA4335' }), _jsx("text", { x: '23', y: '20', fontSize: '17', fontWeight: '500', fill: '#3c4043', fontFamily: '"Google Sans", Roboto, -apple-system, sans-serif', children: "Pay" })] }));
|
|
210
|
-
}
|
|
211
|
-
function CardBrandMarks() {
|
|
212
|
-
return (_jsxs("span", { className: 'wfc-card-marks', "aria-hidden": 'true', children: [_jsx("svg", { viewBox: '0 0 48 30', className: 'wfc-brand', children: _jsx("text", { x: '24', y: '21', textAnchor: 'middle', fontSize: '17', fontWeight: '800', fontStyle: 'italic', fill: '#1a1f71', fontFamily: 'Arial, sans-serif', children: "VISA" }) }), _jsxs("svg", { viewBox: '0 0 48 30', className: 'wfc-brand', children: [_jsx("circle", { cx: '19', cy: '15', r: '10', fill: '#eb001b' }), _jsx("circle", { cx: '29', cy: '15', r: '10', fill: '#f79e1b', fillOpacity: '.9' })] }), _jsxs("svg", { viewBox: '0 0 48 30', className: 'wfc-brand wfc-brand--box', style: { background: '#1b4fa0' }, children: [_jsx("circle", { cx: '19', cy: '15', r: '9', fill: '#0099df' }), _jsx("circle", { cx: '29', cy: '15', r: '9', fill: '#e60014', fillOpacity: '.85' })] }), _jsx("svg", { viewBox: '0 0 48 30', className: 'wfc-brand wfc-brand--box', style: { background: '#2e77bc' }, children: _jsx("text", { x: '24', y: '19', textAnchor: 'middle', fontSize: '10', fontWeight: '800', fill: '#fff', fontFamily: 'Arial, sans-serif', children: "AMEX" }) })] }));
|
|
213
|
-
}
|
|
214
|
-
/** Google Pay on Android, Apple Pay everywhere else — read synchronously from the browser. */
|
|
215
|
-
function usePlatformWallet() {
|
|
216
|
-
const platform = useSyncExternalStore(() => () => undefined, () => resolveWalletPlatform({ maxTouchPoints: navigator.maxTouchPoints, userAgent: navigator.userAgent }), () => 'ios');
|
|
217
|
-
return platform === 'android' ? 'googlePay' : 'applePay';
|
|
218
|
-
}
|
|
@@ -11,5 +11,6 @@ export * from './StripeOneTimeWalletSurface.js';
|
|
|
11
11
|
export * from './StripePlanSelector.js';
|
|
12
12
|
export * from './StripeSubscriptionWalletSurface.js';
|
|
13
13
|
export * from './StripeWalletFirstCheckout.js';
|
|
14
|
+
export * from './StripeCheckoutSheet.js';
|
|
14
15
|
export * from './WalletSubscriptionCheckoutSlot.js';
|
|
15
16
|
export * from './walletPlatform.js';
|
|
@@ -11,5 +11,6 @@ export * from './StripeOneTimeWalletSurface.js';
|
|
|
11
11
|
export * from './StripePlanSelector.js';
|
|
12
12
|
export * from './StripeSubscriptionWalletSurface.js';
|
|
13
13
|
export * from './StripeWalletFirstCheckout.js';
|
|
14
|
+
export * from './StripeCheckoutSheet.js';
|
|
14
15
|
export * from './WalletSubscriptionCheckoutSlot.js';
|
|
15
16
|
export * from './walletPlatform.js';
|
|
@@ -14,6 +14,7 @@ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } f
|
|
|
14
14
|
import { createEmptyCheckoutPreparationLoading, } from '../../paymentProvider.types.js';
|
|
15
15
|
import { createStripeSubscriptionCheckout, getStripePromise, isStripeConfigured, updateStripeSubscriptionCheckoutPlan, } from '../services/stripe.service.js';
|
|
16
16
|
import { describeStripeCheckoutFailure } from '../services/stripeCheckoutFailure.js';
|
|
17
|
+
import { rememberCheckoutSessionPaymentMethodTypes } from '../services/checkoutSessionPaymentMethods.js';
|
|
17
18
|
import { toAnalyticsPaymentMethod } from '../../../services/paymentMethodAnalytics.service.js';
|
|
18
19
|
import { resolveCheckoutObservabilityAnalyticsContext, trackCheckoutFailureShown, } from '../../../services/checkoutObservability.service.js';
|
|
19
20
|
import { resolveStripeCheckoutAttempt, } from './checkoutAttempt.js';
|
|
@@ -241,7 +242,7 @@ export function useStripeSubscriptionCheckoutSession({ checkoutMode: nextCheckou
|
|
|
241
242
|
const requestId = requestIdRef.current + 1;
|
|
242
243
|
requestIdRef.current = requestId;
|
|
243
244
|
const subscriptionRequest = (async () => {
|
|
244
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
245
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
245
246
|
try {
|
|
246
247
|
const response = await createStripeSubscriptionCheckout({
|
|
247
248
|
plan,
|
|
@@ -271,13 +272,14 @@ export function useStripeSubscriptionCheckoutSession({ checkoutMode: nextCheckou
|
|
|
271
272
|
preparationFailureRef.current = null;
|
|
272
273
|
setClientSecret(response.clientSecret);
|
|
273
274
|
setClientSecretIntentKey(requestKey);
|
|
274
|
-
|
|
275
|
+
rememberCheckoutSessionPaymentMethodTypes((_e = response.checkoutSessionId) === null || _e === void 0 ? void 0 : _e.trim(), response.paymentMethodTypes);
|
|
276
|
+
setCheckoutSessionId(((_f = response.checkoutSessionId) === null || _f === void 0 ? void 0 : _f.trim()) || null);
|
|
275
277
|
setClientSecretPlanKey(requestPlanKey);
|
|
276
278
|
return response.clientSecret;
|
|
277
279
|
}
|
|
278
280
|
catch (subscriptionError) {
|
|
279
|
-
if (((
|
|
280
|
-
((
|
|
281
|
+
if (((_g = creatingIntentRef.current) === null || _g === void 0 ? void 0 : _g.key) === requestKey &&
|
|
282
|
+
((_h = creatingIntentRef.current) === null || _h === void 0 ? void 0 : _h.id) === requestId) {
|
|
281
283
|
const failure = describeStripeCheckoutFailure(subscriptionError);
|
|
282
284
|
const message = failure.message;
|
|
283
285
|
const observabilityAnalytics = resolveCheckoutObservabilityAnalyticsContext({
|
|
@@ -305,8 +307,8 @@ export function useStripeSubscriptionCheckoutSession({ checkoutMode: nextCheckou
|
|
|
305
307
|
return null;
|
|
306
308
|
}
|
|
307
309
|
finally {
|
|
308
|
-
if (((
|
|
309
|
-
((
|
|
310
|
+
if (((_j = creatingIntentRef.current) === null || _j === void 0 ? void 0 : _j.key) === requestKey &&
|
|
311
|
+
((_k = creatingIntentRef.current) === null || _k === void 0 ? void 0 : _k.id) === requestId) {
|
|
310
312
|
creatingIntentRef.current = null;
|
|
311
313
|
}
|
|
312
314
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const rememberCheckoutSessionPaymentMethodTypes: (checkoutSessionId: string | null | undefined, paymentMethodTypes: readonly string[] | null | undefined) => void;
|
|
2
|
+
export declare const getCheckoutSessionPaymentMethodTypes: (checkoutSessionId: string | null | undefined) => readonly string[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// CHECKOUT-BR-010: the checkout hook records each session's Stripe-resolved method types so the
|
|
2
|
+
// shared V2 form can switch layouts from its existing `checkoutSessionId` prop.
|
|
3
|
+
const paymentMethodTypesBySession = new Map();
|
|
4
|
+
const cardOnly = ['card'];
|
|
5
|
+
export const rememberCheckoutSessionPaymentMethodTypes = (checkoutSessionId, paymentMethodTypes) => {
|
|
6
|
+
if (checkoutSessionId && (paymentMethodTypes === null || paymentMethodTypes === void 0 ? void 0 : paymentMethodTypes.length)) {
|
|
7
|
+
paymentMethodTypesBySession.set(checkoutSessionId, paymentMethodTypes);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export const getCheckoutSessionPaymentMethodTypes = (checkoutSessionId) => (checkoutSessionId && paymentMethodTypesBySession.get(checkoutSessionId)) || cardOnly;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funnelsgrove/payments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.66.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"jsdom": "20.0.3",
|
|
47
47
|
"typescript": "^5",
|
|
48
48
|
"vitest": "^3.2.4",
|
|
49
|
-
"@funnelsgrove/runtime": "0.
|
|
50
|
-
"@funnelsgrove/analytics": "0.
|
|
49
|
+
"@funnelsgrove/runtime": "0.43.0",
|
|
50
|
+
"@funnelsgrove/analytics": "0.26.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@funnelsgrove/runtime": "^0.
|
|
54
|
-
"@funnelsgrove/analytics": "^0.
|
|
53
|
+
"@funnelsgrove/runtime": "^0.43.0",
|
|
54
|
+
"@funnelsgrove/analytics": "^0.26.0"
|
|
55
55
|
}
|
|
56
56
|
}
|