@funnelsgrove/payments 0.68.0 → 0.69.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.
Files changed (30) hide show
  1. package/README.md +31 -14
  2. package/dist/components/CheckoutErrorOverlay.d.ts +37 -0
  3. package/dist/components/CheckoutErrorOverlay.js +67 -0
  4. package/dist/generated/package-version.d.ts +1 -1
  5. package/dist/generated/package-version.js +1 -1
  6. package/dist/index.d.ts +1 -0
  7. package/dist/providers/stripe/components/SharedStripeCheckoutV2Dialog.d.ts +13 -4
  8. package/dist/providers/stripe/components/SharedStripeCheckoutV2Dialog.js +93 -88
  9. package/dist/providers/stripe/components/StripeCheckoutDialog.d.ts +31 -0
  10. package/dist/providers/stripe/components/StripeCheckoutDialog.js +179 -0
  11. package/dist/providers/stripe/components/StripeWalletFirstCheckout.d.ts +68 -4
  12. package/dist/providers/stripe/components/StripeWalletFirstCheckout.js +196 -51
  13. package/dist/providers/stripe/components/StripeWalletFirstCheckout.options.d.ts +10 -2
  14. package/dist/providers/stripe/components/StripeWalletFirstCheckout.options.js +4 -6
  15. package/dist/providers/stripe/components/StripeWalletFirstCheckout.styles.d.ts +1 -1
  16. package/dist/providers/stripe/components/StripeWalletFirstCheckout.styles.js +11 -1
  17. package/dist/providers/stripe/components/WalletButton.d.ts +3 -1
  18. package/dist/providers/stripe/components/WalletButton.js +3 -3
  19. package/dist/providers/stripe/components/checkout-v2.content.d.ts +3 -0
  20. package/dist/providers/stripe/components/index.d.ts +1 -0
  21. package/dist/providers/stripe/components/index.js +1 -0
  22. package/dist/providers/stripe/components/useCheckoutEmail.internal.d.ts +3 -1
  23. package/dist/providers/stripe/components/useCheckoutEmail.internal.js +8 -3
  24. package/package.json +1 -1
  25. package/dist/providers/stripe/components/SharedCheckoutPaymentMethods.internal.d.ts +0 -18
  26. package/dist/providers/stripe/components/SharedCheckoutPaymentMethods.internal.js +0 -15
  27. package/dist/providers/stripe/components/SharedStripeCheckoutV2Form.internal.d.ts +0 -7
  28. package/dist/providers/stripe/components/SharedStripeCheckoutV2Form.internal.js +0 -328
  29. package/dist/providers/stripe/components/SharedStripeCheckoutV2Summary.internal.d.ts +0 -7
  30. package/dist/providers/stripe/components/SharedStripeCheckoutV2Summary.internal.js +0 -19
@@ -19,17 +19,20 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
19
19
  * Apple Pay everywhere else, shown with Stripe's own wallet button. Card
20
20
  * payment is the last method. Between them, every other method the offer
21
21
  * supports (Pix, Klarna, …) forms one block, or its own block when `methods`
22
- * names it. The wallet and the card share the caller's Checkout Session; every
23
- * other block owns a Checkout Session restricted to its methods, created when
24
- * the block is selected. The whole layout renders immediately, even before the
25
- * checkout session exists; the wallet slot holds a progress bar at the exact
26
- * button height until Stripe's button replaces it, so nothing moves. Where the
27
- * wallet cannot pay, the same slot explains that. The card form has no email or
28
- * terms text: the session carries the email. Stripe asks for the postal code
29
- * only for card countries that use it (US, CA, UK). `paymentElementOptions`
30
- * overrides these card form defaults. `initialMethod` opens another block
31
- * first, e.g. `'card'` for a bottom-of-page "complete your order" block; the
32
- * wallet stays one tap away.
22
+ * names it; a native PayPal checkout passed as `paypalCheckout` follows the
23
+ * wallet. The wallet and the card share the caller's Checkout Session; every
24
+ * other Stripe block owns a Checkout Session restricted to its methods, created
25
+ * when the block is selected. The whole layout renders immediately, even before
26
+ * the checkout session exists; the wallet slot holds a progress bar at the
27
+ * exact button height until Stripe's button replaces it, so nothing moves.
28
+ * Where the wallet cannot pay, the same slot explains that (or the block hides
29
+ * with `hideUnavailableWallet`). The card form has no email or terms text: the
30
+ * session carries the email, unless `email` asks the visitor for it. Stripe
31
+ * asks for the postal code only for card countries that use it (US, CA, UK).
32
+ * `paymentElementOptions` overrides these card form defaults. `initialMethod`
33
+ * opens another block first, e.g. `'card'` for a bottom-of-page "complete your
34
+ * order" block; the wallet stays one tap away. A failed payment lies over the
35
+ * blocks (CheckoutErrorOverlay), so nothing below moves.
33
36
  *
34
37
  * The caller owns the card Checkout Session (`clientSecret`, created with
35
38
  * `paymentMethodTypes: ['card']` so its form never shows another method), the
@@ -40,18 +43,24 @@ import { CheckoutProvider, PaymentElement, useCheckout } from '@stripe/react-str
40
43
  import { completePaywallCheckout } from '@funnelsgrove/runtime';
41
44
  import { ApplePayMark, CardBrandMarks, GooglePayMark, MethodCard, usePlatformWallet } from '../../../components/walletFirstParts.js';
42
45
  import { stripeWalletFirstCheckoutStyles } from './StripeWalletFirstCheckout.styles.js';
46
+ import { CheckoutErrorOverlay } from '../../../components/CheckoutErrorOverlay.js';
47
+ import { PaymentBrandMark } from './CheckoutBrandAssets.js';
43
48
  import { WalletButton } from './WalletButton.js';
44
49
  import { buildWalletFirstCheckoutOptions } from './StripeWalletFirstCheckout.options.js';
50
+ import { getUnsupportedCheckoutCountryMessage, normalizeSupportedCheckoutCountries } from './checkoutCountries.js';
51
+ import { useCheckoutEmail } from './useCheckoutEmail.internal.js';
52
+ import { isCheckoutEmailError, isValidCheckoutEmail } from '../../../services/checkoutEmail.js';
53
+ import { resolveCheckoutReturnUrl } from '../services/checkout/checkoutReturnUrl.js';
45
54
  import { getCheckoutSessionPaymentMethodTypes } from '../services/checkoutSessionPaymentMethods.js';
46
55
  import { queueStripeSubscriptionCheckoutStarted, trackPaidStripeSubscriptionCheckoutCompleted, trackStripeCheckoutShown, trackStripeSubscriptionPaymentInfoSubmitted, } from '../services/checkoutCompletionAnalytics.service.js';
47
56
  import { trackCheckoutFailureShown } from '../../../services/checkoutObservability.service.js';
48
57
  import { useCheckoutShownOnce } from '../hooks/useCheckoutShownOnce.js';
49
- import { useStripeSubscriptionCheckoutSession } from '../hooks/useStripeSubscriptionCheckoutSession.js';
58
+ import { isInactiveCheckoutSessionError, useStripeSubscriptionCheckoutSession, } from '../hooks/useStripeSubscriptionCheckoutSession.js';
50
59
  import { isStripeCheckoutAlreadyPaidError, normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
51
60
  const DEFAULT_METHODS = ['wallet', 'other', 'card'];
52
- const RESERVED_METHODS = new Set(['wallet', 'card', 'other']);
61
+ const RESERVED_METHODS = new Set(['wallet', 'card', 'other', 'paypal']);
53
62
  /** Only methods the offer supports become blocks; unnamed extras share the `'other'` block. */
54
- function resolveMethodBlocks(methods, availablePaymentMethodTypes, canCreateSessions) {
63
+ function resolveMethodBlocks(methods, availablePaymentMethodTypes, canCreateSessions, hasPayPal) {
55
64
  const extras = (availablePaymentMethodTypes !== null && availablePaymentMethodTypes !== void 0 ? availablePaymentMethodTypes : []).filter((type) => type !== 'card');
56
65
  const named = methods.filter((method) => !RESERVED_METHODS.has(method));
57
66
  const blocks = [];
@@ -62,6 +71,10 @@ function resolveMethodBlocks(methods, availablePaymentMethodTypes, canCreateSess
62
71
  else if (method === 'card') {
63
72
  blocks.push({ id: 'card', kind: 'card' });
64
73
  }
74
+ else if (method === 'paypal') {
75
+ if (hasPayPal)
76
+ blocks.push({ id: 'paypal', kind: 'paypal' });
77
+ }
65
78
  else if (!canCreateSessions) {
66
79
  continue;
67
80
  }
@@ -74,23 +87,53 @@ function resolveMethodBlocks(methods, availablePaymentMethodTypes, canCreateSess
74
87
  blocks.push({ id: method, kind: 'session', types: [method] });
75
88
  }
76
89
  }
90
+ if (hasPayPal && !methods.includes('paypal')) {
91
+ blocks.splice(blocks.findIndex((block) => block.kind === 'wallet') + 1, 0, { id: 'paypal', kind: 'paypal' });
92
+ }
77
93
  return blocks;
78
94
  }
79
95
  const methodLabel = (type, copy) => { var _a, _b; return (_b = (_a = copy.methodLabels) === null || _a === void 0 ? void 0 : _a[type]) !== null && _b !== void 0 ? _b : type.replace(/_/g, ' ').replace(/^./, (first) => first.toUpperCase()); };
80
96
  export function StripeWalletFirstCheckout(props) {
81
- var _a, _b, _c, _d;
82
- const { availablePaymentMethodTypes, buttonColor, checkoutAnalytics, checkoutSessionId, clientSecret, copy, initialMethod = 'wallet', methods = DEFAULT_METHODS, methodSessionInput, onError, onSuccess, stripePromise, themeColor, } = props;
97
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
98
+ const { availablePaymentMethodTypes, buttonColor, checkoutAnalytics, checkoutSessionId, clientSecret, copy, initialMethod = 'wallet', methods = DEFAULT_METHODS, methodSessionInput, onError, onSuccess, stripePromise, themeColor, paypalPending = false, } = props;
83
99
  const wallet = usePlatformWallet();
100
+ const [error, setError] = useState(null);
101
+ const [failure, setFailure] = useState(null);
102
+ const email = useCheckoutEmail({
103
+ customerEmail: props.customerEmail,
104
+ allowEmailEditing: Boolean((_a = props.email) === null || _a === void 0 ? void 0 : _a.editable),
105
+ customerEmailInvalidMessage: (_c = (_b = props.email) === null || _b === void 0 ? void 0 : _b.invalidMessage) !== null && _c !== void 0 ? _c : 'Enter a valid email address.',
106
+ onCustomerEmailCommit: (_d = props.email) === null || _d === void 0 ? void 0 : _d.onCommit,
107
+ onCustomerEmailChange: (_e = props.email) === null || _e === void 0 ? void 0 : _e.onChange,
108
+ // The visitor fixes the email in its field, so the message stays next to the form.
109
+ onError: (message) => status.showError(message, { blockId: 'card', checkoutSessionId, failureStage: 'card_form' }, validationFailure(message)),
110
+ sessionKey: clientSecret,
111
+ });
112
+ const emailController = props.email ? Object.assign(Object.assign({}, email), { field: props.email }) : null;
113
+ // Wallets confirm with the session's email, so they show only while the visitor keeps it.
114
+ const walletEmailReady = !emailController || (!email.emailSessionChanged && isValidCheckoutEmail(email.initialCustomerEmail)
115
+ && email.rejectedEmail === null && email.resolvedCustomerEmail === email.initialCustomerEmail);
116
+ const [walletAvailable, setWalletAvailable] = useState((_f = props.initialWalletAvailable) !== null && _f !== void 0 ? _f : null);
117
+ // A wallet this browser cannot use stays mounted but hidden, so a later availability report brings it back.
118
+ const walletHidden = Boolean(props.hideUnavailableWallet && walletAvailable === false);
119
+ const supportedCountriesKey = (_h = (_g = props.supportedCountries) === null || _g === void 0 ? void 0 : _g.join(',')) !== null && _h !== void 0 ? _h : '';
120
+ const countries = useMemo(() => {
121
+ const supported = normalizeSupportedCheckoutCountries(supportedCountriesKey.split(','));
122
+ return { supported, fixed: supported.length === 1 ? supported[0] : null, message: props.unsupportedCountryMessage };
123
+ }, [supportedCountriesKey, props.unsupportedCountryMessage]);
84
124
  // A card session that offers other methods itself shows them in its form; other blocks would repeat them.
85
125
  const cardSessionCardsOnly = getCheckoutSessionPaymentMethodTypes(checkoutSessionId).every((type) => type === 'card');
86
126
  const canCreateSessions = Boolean(methodSessionInput) && cardSessionCardsOnly;
127
+ const hasPayPal = Boolean(props.paypalCheckout);
87
128
  // Keyed by content so inline arrays from the caller keep each block's `types` identity stable.
88
129
  const methodsKey = methods.join(',');
89
- const availableKey = (_a = availablePaymentMethodTypes === null || availablePaymentMethodTypes === void 0 ? void 0 : availablePaymentMethodTypes.join(',')) !== null && _a !== void 0 ? _a : null;
90
- const blocks = useMemo(() => resolveMethodBlocks(methodsKey.split(',').filter(Boolean), availableKey === null ? null : availableKey.split(',').filter(Boolean), canCreateSessions), [methodsKey, availableKey, canCreateSessions]);
130
+ const availableKey = (_j = availablePaymentMethodTypes === null || availablePaymentMethodTypes === void 0 ? void 0 : availablePaymentMethodTypes.join(',')) !== null && _j !== void 0 ? _j : null;
131
+ const allBlocks = useMemo(() => resolveMethodBlocks(methodsKey.split(',').filter(Boolean), availableKey === null ? null : availableKey.split(',').filter(Boolean), canCreateSessions, hasPayPal), [methodsKey, availableKey, canCreateSessions, hasPayPal]);
132
+ const renderedBlocks = walletEmailReady ? allBlocks : allBlocks.filter((block) => block.kind !== 'wallet');
133
+ const blocks = walletHidden ? renderedBlocks.filter((block) => block.kind !== 'wallet') : renderedBlocks;
91
134
  const [selected, setSelected] = useState(initialMethod);
92
135
  // A method inside the other block selects that block; a hidden block gives way to the first one.
93
- const activeId = (_d = ((_c = (_b = blocks.find((block) => block.id === selected)) !== null && _b !== void 0 ? _b : blocks.find((block) => block.kind === 'session' && block.types.includes(selected))) !== null && _c !== void 0 ? _c : blocks[0])) === null || _d === void 0 ? void 0 : _d.id;
136
+ const activeId = paypalPending && hasPayPal ? 'paypal' : (_m = ((_l = (_k = blocks.find((block) => block.id === selected)) !== null && _k !== void 0 ? _k : blocks.find((block) => block.kind === 'session' && block.types.includes(selected))) !== null && _l !== void 0 ? _l : blocks[0])) === null || _m === void 0 ? void 0 : _m.id;
94
137
  // A form that is open on mount has not been opened by the visitor yet.
95
138
  const [engaged, setEngaged] = useState(initialMethod === 'wallet');
96
139
  const select = (id) => {
@@ -101,14 +144,18 @@ export function StripeWalletFirstCheckout(props) {
101
144
  const engage = () => setEngaged(true);
102
145
  const [busy, setBusy] = useState(false);
103
146
  const [confirmed, setConfirmed] = useState(false);
147
+ const [confirmedSessionId, setConfirmedSessionId] = useState(null);
104
148
  const [completed, setCompleted] = useState(false);
105
- const [error, setError] = useState(null);
106
149
  // A replaced card session starts clean, as its remounted form did before.
107
150
  const [seenClientSecret, setSeenClientSecret] = useState(clientSecret);
108
151
  if (seenClientSecret !== clientSecret) {
109
152
  setSeenClientSecret(clientSecret);
110
153
  setError(null);
154
+ setFailure(null);
111
155
  setBusy(false);
156
+ setConfirmed(false);
157
+ setConfirmedSessionId(null);
158
+ setCompleted(false);
112
159
  }
113
160
  const paymentStatus = completed ? copy.paymentConfirmed : confirmed ? copy.verifyingPayment : null;
114
161
  const status = {
@@ -117,14 +164,27 @@ export function StripeWalletFirstCheckout(props) {
117
164
  locked: Boolean(paymentStatus) && !error,
118
165
  error,
119
166
  setBusy,
120
- markConfirmed: () => setConfirmed(true),
167
+ markConfirmed: (confirmedId) => { setConfirmed(true); setConfirmedSessionId(confirmedId); },
121
168
  markCompleted: () => setCompleted(true),
122
169
  showError: (message, context, details, alreadyTracked = false) => {
170
+ // An expired session is replaced by the caller; Stripe's stale-session message never shows.
171
+ if (message && props.onInactiveCheckoutSession && isInactiveCheckoutSessionError(message)) {
172
+ setError(null);
173
+ setFailure(null);
174
+ props.onInactiveCheckoutSession();
175
+ return;
176
+ }
123
177
  const errorDetails = message ? details !== null && details !== void 0 ? details : normalizeStripeCheckoutError(message, undefined, context.paymentMethod) : undefined;
178
+ // Stripe rejected the session's email: the visitor corrects it in the card form.
179
+ if (emailController && message && (isCheckoutEmailError({ code: errorDetails === null || errorDetails === void 0 ? void 0 : errorDetails.providerErrorCode }) || isCheckoutEmailError(message))) {
180
+ email.setRejectedEmail(email.initialCustomerEmail);
181
+ setSelected('card');
182
+ }
124
183
  if (message && checkoutAnalytics && !alreadyTracked) {
125
184
  trackCheckoutFailureShown(Object.assign({ analytics: checkoutAnalytics, checkoutSessionId: context.checkoutSessionId, errorMessage: message, failureStage: context.failureStage, provider: 'stripe' }, errorDetails));
126
185
  }
127
186
  setError(message);
187
+ setFailure(message && errorDetails ? { blockId: context.blockId, details: errorDetails } : null);
128
188
  if (message)
129
189
  onError === null || onError === void 0 ? void 0 : onError(message, errorDetails);
130
190
  else
@@ -139,34 +199,93 @@ export function StripeWalletFirstCheckout(props) {
139
199
  },
140
200
  };
141
201
  // Once any block confirmed a payment, no other block may start a second one.
142
- const disabled = busy || confirmed;
202
+ const disabled = busy || confirmed || paypalPending;
143
203
  const style = { '--wfc-theme': themeColor, '--wfc-button': buttonColor };
144
- const options = useMemo(() => clientSecret ? buildWalletFirstCheckoutOptions(clientSecret, themeColor) : null, [clientSecret, themeColor]);
204
+ const options = useMemo(() => clientSecret ? buildWalletFirstCheckoutOptions(clientSecret, themeColor, countries.fixed) : null, [clientSecret, themeColor, countries.fixed]);
145
205
  // The whole layout shows on mount, so one mount is one show.
206
+ const checkoutSurface = (_o = props.checkoutSurface) !== null && _o !== void 0 ? _o : 'inline';
146
207
  useCheckoutShownOnce(Boolean(checkoutAnalytics), () => {
147
208
  if (checkoutAnalytics)
148
- trackStripeCheckoutShown(Object.assign(Object.assign({}, checkoutAnalytics), { checkoutSessionId, checkoutSurface: 'inline' }));
209
+ trackStripeCheckoutShown(Object.assign(Object.assign({}, checkoutAnalytics), { checkoutSessionId, checkoutSurface }));
149
210
  });
150
- const cardPaymentElementOptions = useMemo(() => resolveCardPaymentElementOptions(props.paymentElementOptions), [props.paymentElementOptions]);
211
+ const cardPaymentElementOptions = useMemo(() => resolveCardPaymentElementOptions(props.paymentElementOptions, countries.fixed), [props.paymentElementOptions, countries.fixed]);
151
212
  const live = Boolean(options && stripePromise);
152
213
  const formProps = {
153
- checkoutAnalytics, copy, customerEmail: props.customerEmail, engaged, onEngage: engage, returnUrl: props.returnUrl, status,
214
+ checkoutAnalytics, copy, countries, customerEmail: props.customerEmail, email: emailController, engaged,
215
+ onEngage: engage, onPaymentInfoSubmitted: props.onPaymentInfoSubmitted, returnUrl: props.returnUrl, status,
154
216
  };
155
217
  const renderBlock = (block) => {
218
+ var _a, _b;
156
219
  const checked = activeId === block.id;
157
220
  if (block.kind === 'wallet') {
158
221
  const WalletMark = wallet === 'applePay' ? ApplePayMark : GooglePayMark;
159
222
  const walletNote = checked ? status.paymentStatus : null;
160
- return (_jsxs(MethodCard, { checked: checked, disabled: disabled, label: copy.walletLabels[wallet], onSelect: () => select('wallet'), header: _jsx(WalletMark, {}), children: [_jsx("ul", { className: 'wfc-benefits', children: copy.walletBenefits[wallet].map((item) => _jsxs("li", { children: [_jsx(CheckIcon, {}), item] }, item)) }), live ? _jsx(WalletButton, { amountCents: props.amountCents, beforeConfirm: async () => { setBusy(true); return props.customerEmail || null; }, checkoutAnalytics: checkoutAnalytics, checkoutSessionId: checkoutSessionId, customerEmail: props.customerEmail, customerName: props.customerName, onCancel: () => { var _a; setBusy(false); (_a = props.onCancel) === null || _a === void 0 ? void 0 : _a.call(props); }, onEmbeddedComplete: () => setCompleted(true), onError: (message, details) => { setBusy(false); status.showError(message, { checkoutSessionId, failureStage: 'wallet', paymentMethod: wallet }, details, true); }, onPaymentRejected: () => { setBusy(false); select('card'); }, onSuccess: async () => { await status.trackSuccess(checkoutSessionId); }, onVerificationPending: () => setConfirmed(true), processingLabel: copy.processingLabel, returnUrl: props.returnUrl, summaryLabel: props.summaryLabel, unavailableNote: copy.walletUnavailableNote.replace('{wallet}', copy.walletLabels[wallet]), wallet: wallet }) : _jsx("div", { className: 'wfc-wallet-slot', children: _jsx("span", { className: 'wfc-progress', role: 'status', "aria-label": copy.processingLabel }) }), _jsx("p", { className: walletNote ? 'wfc-secure is-status' : 'wfc-secure', role: walletNote ? 'status' : undefined, children: walletNote || copy.secureNote })] }, 'wallet'));
223
+ return (_jsxs(MethodCard, { checked: checked, disabled: disabled, label: copy.walletLabels[wallet], onSelect: () => select('wallet'), header: _jsx(WalletMark, {}), children: [_jsx("ul", { className: 'wfc-benefits', children: copy.walletBenefits[wallet].map((item) => _jsxs("li", { children: [_jsx(CheckIcon, {}), item] }, item)) }), live ? _jsx("div", { className: 'wfc-wallet-confirm', inert: confirmed || completed, children: _jsx(WalletButton, { amountCents: props.amountCents, beforeConfirm: async () => {
224
+ setBusy(true);
225
+ if (!emailController)
226
+ return props.customerEmail || null;
227
+ const confirmedEmail = await email.ensureCustomerEmail();
228
+ if (!confirmedEmail)
229
+ setBusy(false);
230
+ return confirmedEmail;
231
+ }, checkoutAnalytics: checkoutAnalytics, checkoutSessionId: checkoutSessionId, customerEmail: emailController ? email.resolvedCustomerEmail : props.customerEmail, customerName: props.customerName, initialAvailable: props.initialWalletAvailable, onAvailabilityChange: setWalletAvailable, onCancel: () => { var _a; setBusy(false); (_a = props.onCancel) === null || _a === void 0 ? void 0 : _a.call(props); }, onEmbeddedComplete: () => setCompleted(true), onError: (message, details) => { setBusy(false); status.showError(message, { blockId: 'wallet', checkoutSessionId, failureStage: 'wallet', paymentMethod: wallet }, details, true); }, onPaymentInfoSubmitted: props.onPaymentInfoSubmitted, onPaymentRejected: () => { setBusy(false); select('card'); }, onSuccess: async () => { await status.trackSuccess(checkoutSessionId); }, onVerificationPending: () => status.markConfirmed(checkoutSessionId), processingLabel: copy.processingLabel, returnUrl: props.returnUrl, summaryLabel: props.summaryLabel, supportedCountries: countries.supported, unavailableNote: copy.walletUnavailableNote.replace('{wallet}', copy.walletLabels[wallet]), unsupportedCountryMessage: countries.message, wallet: wallet }) }) : _jsx("div", { className: 'wfc-wallet-slot', children: _jsx("span", { className: 'wfc-progress', role: 'status', "aria-label": copy.processingLabel }) }), _jsx("p", { className: walletNote ? 'wfc-secure is-status' : 'wfc-secure', role: walletNote ? 'status' : undefined, children: walletNote || copy.secureNote })] }, 'wallet'));
161
232
  }
162
233
  if (block.kind === 'card') {
163
- return (_jsx(MethodCard, { checked: checked, disabled: disabled, label: copy.cardLabel, onSelect: () => select('card'), header: _jsx(CardBrandMarks, {}), children: live
164
- ? _jsx(MethodForm, Object.assign({}, formProps, { checkoutSessionId: checkoutSessionId, failureStage: 'card_form', paymentElementOptions: cardPaymentElementOptions, paymentMethod: 'card', selected: checked, startSource: 'card_form_open' }))
234
+ const brands = ((_a = props.cardBrandLabels) === null || _a === void 0 ? void 0 : _a.length)
235
+ ? _jsx("span", { className: 'wfc-card-marks', "aria-hidden": 'true', children: props.cardBrandLabels.map((label) => _jsx(PaymentBrandMark, { label: label, className: 'wfc-brand' }, label)) })
236
+ : _jsx(CardBrandMarks, {});
237
+ return (_jsx(MethodCard, { checked: checked, disabled: disabled, label: copy.cardLabel, onSelect: () => select('card'), header: brands, children: live
238
+ ? _jsx(MethodForm, Object.assign({}, formProps, { blockId: 'card', checkoutSessionId: checkoutSessionId, failureStage: 'card_form', paymentElementOptions: cardPaymentElementOptions, paymentMethod: 'card', selected: checked, startSource: 'card_form_open' }))
165
239
  : _jsx(FormPlaceholder, {}) }, 'card'));
166
240
  }
241
+ if (block.kind === 'paypal') {
242
+ const label = (_b = props.paypalLabel) !== null && _b !== void 0 ? _b : 'PayPal';
243
+ return (_jsx(MethodCard, { checked: checked, disabled: disabled, label: label, onSelect: () => select('paypal'), header: _jsx(PaymentBrandMark, { label: 'PayPal', className: 'wfc-brand wfc-brand--paypal' }), children: _jsx("div", { className: 'wfc-paypal', inert: busy || confirmed, children: checked ? props.paypalCheckout : null }) }, 'paypal'));
244
+ }
167
245
  return methodSessionInput ? (_jsx(SessionMethodBlock, Object.assign({}, formProps, { block: block, checked: checked, disabled: disabled, onSelect: () => select(block.id), sessionInput: methodSessionInput, themeColor: themeColor }), block.id)) : null;
168
246
  };
169
- const layout = (_jsxs("div", { className: 'wfc', style: style, children: [blocks.map(renderBlock), error ? _jsx("p", { className: 'wfc-error', role: 'alert', children: error }) : null] }));
247
+ // A confirmed payment that failed to verify is checked again, never paid again.
248
+ const checkPaymentStatus = async () => {
249
+ var _a;
250
+ const paidSessionId = confirmedSessionId !== null && confirmedSessionId !== void 0 ? confirmedSessionId : checkoutSessionId;
251
+ const context = { blockId: (_a = failure === null || failure === void 0 ? void 0 : failure.blockId) !== null && _a !== void 0 ? _a : 'card', checkoutSessionId: paidSessionId, failureStage: 'verification' };
252
+ status.showError(null, context);
253
+ setBusy(true);
254
+ try {
255
+ if (await completePaywallCheckout('stripe', paidSessionId || '', {
256
+ beforeNotify: async () => { setCompleted(true); await status.trackSuccess(paidSessionId, true); },
257
+ }))
258
+ return;
259
+ if (await status.trackSuccess(paidSessionId))
260
+ return;
261
+ window.location.assign(resolveCheckoutReturnUrl(props.returnUrl, paidSessionId));
262
+ }
263
+ catch (verifyError) {
264
+ status.showError(verifyError instanceof Error && verifyError.message ? verifyError.message : copy.paymentFailed, context, undefined, true);
265
+ }
266
+ finally {
267
+ setBusy(false);
268
+ }
269
+ };
270
+ // A field the form can mark keeps its error inline; any other failure lies over the blocks.
271
+ // After a confirmation every failure lies over the blocks: the only action left is checking the payment.
272
+ const overlayFailure = error && failure && (confirmed || failure.details.category !== 'validation_failure') ? failure : null;
273
+ const dismissFailure = () => status.showError(null, { blockId: activeId !== null && activeId !== void 0 ? activeId : 'card', checkoutSessionId, failureStage: 'dismiss' });
274
+ // Only a method this browser can pay with is offered as the way out of a decline.
275
+ const alternativeBlock = !confirmed && (overlayFailure === null || overlayFailure === void 0 ? void 0 : overlayFailure.details.category) === 'payment_rejection'
276
+ ? blocks.find((block) => block.id === (overlayFailure.blockId === 'card' ? 'wallet' : 'card')
277
+ && !(block.kind === 'wallet' && walletAvailable === false))
278
+ : undefined;
279
+ const blockLabel = (block) => {
280
+ var _a;
281
+ return block.kind === 'wallet' ? copy.walletLabels[wallet]
282
+ : block.kind === 'card' ? copy.cardLabel
283
+ : block.kind === 'paypal' ? (_a = props.paypalLabel) !== null && _a !== void 0 ? _a : 'PayPal'
284
+ : block.types.map((type) => methodLabel(type, copy)).join(' · ');
285
+ };
286
+ const layout = (_jsxs("div", { className: 'wfc', style: style, children: [renderedBlocks.map((block) => block.kind === 'wallet' && walletHidden
287
+ ? _jsx("div", { hidden: true, children: renderBlock(block) }, 'wallet')
288
+ : renderBlock(block)), error && !overlayFailure ? _jsx("p", { className: 'wfc-error', role: 'alert', children: error }) : null, overlayFailure && error ? (_jsx(CheckoutErrorOverlay, { category: overlayFailure.details.category, copy: copy.errors, message: error, onDismiss: dismissFailure, title: confirmed ? copy.verifyingPayment : undefined, dismissible: !confirmed, primary: confirmed ? { label: (_q = (_p = copy.errors) === null || _p === void 0 ? void 0 : _p.checkStatusLabel) !== null && _q !== void 0 ? _q : 'Check payment status', onClick: () => void checkPaymentStatus() } : undefined, alternative: alternativeBlock ? { label: blockLabel(alternativeBlock), onSelect: () => { select(alternativeBlock.id); dismissFailure(); } } : null }, `${overlayFailure.blockId}:${error}`)) : null] }));
170
289
  return (_jsxs(_Fragment, { children: [options && stripePromise ? (_jsx(CheckoutProvider, { stripe: stripePromise, options: options, children: layout }, options.clientSecret)) : layout, _jsx("style", { children: stripeWalletFirstCheckoutStyles })] }));
171
290
  }
172
291
  /** Stripe collects what each other method needs (e.g. the CPF for Pix); only the card form restricts its fields. */
@@ -189,19 +308,23 @@ function SessionMethodBlock(_a) {
189
308
  }, [activeClientSecret, checked, prepareCardCheckout]);
190
309
  const options = useMemo(() => activeClientSecret ? buildWalletFirstCheckoutOptions(activeClientSecret, themeColor) : null, [activeClientSecret, themeColor]);
191
310
  const label = block.types.map((type) => methodLabel(type, form.copy)).join(' · ');
192
- return (_jsxs(MethodCard, { checked: checked, disabled: disabled, label: label, onSelect: onSelect, header: _jsx("span", { className: 'wfc-method-label', children: label }), children: [options && session.stripePromise ? (_jsx(CheckoutProvider, { stripe: session.stripePromise, options: options, children: _jsx(MethodForm, Object.assign({}, form, { checkoutSessionId: session.checkoutSessionId, failureStage: 'method_form', paymentElementOptions: methodPaymentElementOptions, paymentMethod: block.types.length === 1 ? block.types[0] : undefined, selected: checked, startSource: 'method_form_open' })) }, options.clientSecret)) : _jsx(FormPlaceholder, {}), session.error ? _jsx("p", { className: 'wfc-error', role: 'alert', children: session.error }) : null] }));
311
+ return (_jsxs(MethodCard, { checked: checked, disabled: disabled, label: label, onSelect: onSelect, header: _jsx("span", { className: 'wfc-method-label', children: label }), children: [options && session.stripePromise ? (_jsx(CheckoutProvider, { stripe: session.stripePromise, options: options, children: _jsx(MethodForm, Object.assign({}, form, { blockId: block.id, checkoutSessionId: session.checkoutSessionId, failureStage: 'method_form', paymentElementOptions: methodPaymentElementOptions, paymentMethod: block.types.length === 1 ? block.types[0] : undefined, selected: checked, startSource: 'method_form_open' })) }, options.clientSecret)) : _jsx(FormPlaceholder, {}), session.error ? _jsx("p", { className: 'wfc-error', role: 'alert', children: session.error }) : null] }));
193
312
  }
194
313
  /** Stripe's Payment Element for one Checkout Session plus the submit button; must render inside that session's `CheckoutProvider`. */
195
- function MethodForm({ checkoutAnalytics, checkoutSessionId, copy, customerEmail, engaged, failureStage, onEngage, paymentElementOptions, paymentMethod, returnUrl, selected, startSource, status, }) {
314
+ function MethodForm({ blockId, checkoutAnalytics, checkoutSessionId, copy, countries, customerEmail, email, engaged, failureStage, onEngage, onPaymentInfoSubmitted, paymentElementOptions, paymentMethod, returnUrl, selected, startSource, status, }) {
315
+ var _a, _b;
196
316
  const checkoutState = useCheckout();
197
317
  const [paymentElementReady, setPaymentElementReady] = useState(false);
198
318
  const [paymentElementComplete, setPaymentElementComplete] = useState(false);
199
319
  const [pickedMethod, setPickedMethod] = useState(undefined);
320
+ const [billingCountry, setBillingCountry] = useState(null);
200
321
  const [submitting, setSubmitting] = useState(false);
201
322
  // Confirmation belongs to this session: a replaced session confirms again.
202
323
  const [providerConfirmed, setProviderConfirmed] = useState(false);
203
324
  const submitInFlight = useRef(false);
204
325
  const method = paymentMethod !== null && paymentMethod !== void 0 ? paymentMethod : pickedMethod;
326
+ // A saved email change replaces the session; this form waits for the new one.
327
+ const emailPending = Boolean(email && (email.emailSaving || email.emailSessionChanged));
205
328
  // The checkout starts when the visitor opens the form, or, when it opens preselected, on their first input into it.
206
329
  useEffect(() => {
207
330
  if (!checkoutAnalytics || !selected || !engaged)
@@ -215,7 +338,7 @@ function MethodForm({ checkoutAnalytics, checkoutSessionId, copy, customerEmail,
215
338
  const timer = window.setTimeout(() => window.dispatchEvent(new Event('resize')), 0);
216
339
  return () => window.clearTimeout(timer);
217
340
  }, [selected]);
218
- const failure = { checkoutSessionId, failureStage, paymentMethod: method };
341
+ const failure = { blockId, checkoutSessionId, failureStage, paymentMethod: method };
219
342
  const showError = (message, details, alreadyTracked = false) => status.showError(message, failure, details, alreadyTracked);
220
343
  const finishPaidCheckout = async () => {
221
344
  if (await completePaywallCheckout('stripe', checkoutSessionId || '', {
@@ -224,13 +347,20 @@ function MethodForm({ checkoutAnalytics, checkoutSessionId, copy, customerEmail,
224
347
  return;
225
348
  if (await status.trackSuccess(checkoutSessionId))
226
349
  return;
227
- window.location.assign(returnUrl);
350
+ window.location.assign(resolveCheckoutReturnUrl(returnUrl, checkoutSessionId));
228
351
  };
229
352
  const submit = async (event) => {
230
353
  event.preventDefault();
231
- if (submitInFlight.current)
354
+ if (submitInFlight.current || (emailPending && !providerConfirmed))
232
355
  return;
233
356
  if (!providerConfirmed) {
357
+ const countryError = getUnsupportedCheckoutCountryMessage({
358
+ billingCountry: billingCountry !== null && billingCountry !== void 0 ? billingCountry : countries.fixed, message: countries.message, supportedCountries: countries.supported,
359
+ });
360
+ if (countryError) {
361
+ showError(countryError, validationFailure(countryError, method));
362
+ return;
363
+ }
234
364
  if (checkoutState.type !== 'success') {
235
365
  showError(checkoutState.type === 'error' ? checkoutState.error.message : copy.formNotReady);
236
366
  return;
@@ -244,61 +374,76 @@ function MethodForm({ checkoutAnalytics, checkoutSessionId, copy, customerEmail,
244
374
  setSubmitting(true);
245
375
  status.setBusy(true);
246
376
  showError(null);
377
+ const stopSubmitting = () => {
378
+ submitInFlight.current = false;
379
+ setSubmitting(false);
380
+ status.setBusy(false);
381
+ };
247
382
  let confirmed = providerConfirmed;
248
383
  try {
249
384
  if (!providerConfirmed && checkoutState.type === 'success') {
250
385
  const { checkout } = checkoutState;
251
- if (!checkout.email && customerEmail) {
252
- const updated = await checkout.updateEmail(customerEmail);
386
+ const payerEmail = email ? await email.ensureCustomerEmail() : customerEmail;
387
+ // A missing or just-saved email needs a fresh action on the replaced session.
388
+ if (email && !payerEmail) {
389
+ stopSubmitting();
390
+ return;
391
+ }
392
+ if (!checkout.email && payerEmail) {
393
+ const updated = await checkout.updateEmail(payerEmail);
253
394
  if (updated.type === 'error')
254
395
  throw new Error(updated.error.message);
255
396
  }
256
- if (paymentElementComplete && checkoutAnalytics) {
257
- await trackStripeSubscriptionPaymentInfoSubmitted(Object.assign(Object.assign({}, checkoutAnalytics), { checkoutSessionId })).catch(() => 'analytics_rejected');
397
+ if (paymentElementComplete) {
398
+ if (checkoutAnalytics) {
399
+ await trackStripeSubscriptionPaymentInfoSubmitted(Object.assign(Object.assign({}, checkoutAnalytics), { checkoutSessionId })).catch(() => 'analytics_rejected');
400
+ }
401
+ await (onPaymentInfoSubmitted === null || onPaymentInfoSubmitted === void 0 ? void 0 : onPaymentInfoSubmitted());
258
402
  }
259
403
  const result = await checkout.confirm({ redirect: 'if_required' });
260
404
  if (result.type === 'error' && !isStripeCheckoutAlreadyPaidError(result.error)) {
261
405
  const message = result.error.message || copy.paymentFailed;
262
406
  showError(message, normalizeStripeCheckoutError(message, result.error, method));
263
- submitInFlight.current = false;
264
- setSubmitting(false);
265
- status.setBusy(false);
407
+ stopSubmitting();
266
408
  return;
267
409
  }
268
410
  confirmed = true;
269
411
  setProviderConfirmed(true);
270
- status.markConfirmed();
412
+ status.markConfirmed(checkoutSessionId);
271
413
  }
272
414
  await finishPaidCheckout();
273
415
  }
274
416
  catch (submitError) {
275
417
  showError(submitError instanceof Error && submitError.message ? submitError.message : copy.paymentFailed, undefined, confirmed);
276
- submitInFlight.current = false;
277
- setSubmitting(false);
278
- status.setBusy(false);
418
+ stopSubmitting();
279
419
  }
280
420
  };
281
421
  // After a successful confirmation the form stays in place and reports progress
282
422
  // where the customer paid, until the success screen takes over.
283
423
  const { locked } = status;
284
- return (_jsxs("form", { className: 'wfc-card-form', onSubmit: (event) => void submit(event), children: [_jsx(PaymentElement, { options: paymentElementOptions, onChange: (event) => {
285
- var _a;
424
+ const showEmailField = Boolean(email && email.customerEmailEditable);
425
+ return (_jsxs("form", { className: 'wfc-card-form', onSubmit: (event) => void submit(event), children: [email && showEmailField ? (_jsxs("label", { className: 'wfc-email', children: [_jsx("span", { className: 'wfc-email-label', children: (_a = email.field.label) !== null && _a !== void 0 ? _a : 'Email' }), _jsx("input", { type: 'email', autoComplete: 'email', inputMode: 'email', className: 'wfc-email-input', disabled: email.emailSaving || locked, placeholder: (_b = email.field.placeholder) !== null && _b !== void 0 ? _b : 'Enter your email', value: email.emailDraft, onBlur: (event) => email.commitEmailDraftIfValid(event.currentTarget.value), onChange: (event) => { email.setEmailDraft(event.target.value); onEngage(); } })] })) : null, _jsx(PaymentElement, { options: paymentElementOptions, onChange: (event) => {
426
+ var _a, _b, _c, _d, _e;
286
427
  setPaymentElementComplete(event.complete);
287
428
  setPickedMethod((_a = event.value) === null || _a === void 0 ? void 0 : _a.type);
429
+ setBillingCountry((_e = (_d = (_c = (_b = event.value) === null || _b === void 0 ? void 0 : _b.billingDetails) === null || _c === void 0 ? void 0 : _c.address) === null || _d === void 0 ? void 0 : _d.country) !== null && _e !== void 0 ? _e : countries.fixed);
288
430
  if (!event.empty)
289
431
  onEngage();
290
- }, onReady: () => setPaymentElementReady(true) }), _jsx("button", { type: 'submit', className: 'wfc-submit', disabled: locked || submitting || !paymentElementReady, "aria-live": 'polite', children: locked && status.paymentStatus ? status.paymentStatus : submitting ? copy.processingLabel : copy.cardSubmitLabel }), _jsx("p", { className: 'wfc-secure', children: copy.secureNote })] }));
432
+ }, onReady: () => setPaymentElementReady(true) }), _jsx("button", { type: 'submit', className: 'wfc-submit', disabled: locked || submitting || emailPending || !paymentElementReady, "aria-live": 'polite', children: locked && status.paymentStatus ? status.paymentStatus : submitting || emailPending ? copy.processingLabel : copy.cardSubmitLabel }), _jsx("p", { className: 'wfc-secure', children: copy.secureNote })] }));
291
433
  }
434
+ /** A failure the visitor fixes in a field: shown next to the form, not over it. */
435
+ const validationFailure = (message, paymentMethod) => (Object.assign(Object.assign({}, normalizeStripeCheckoutError(message, undefined, paymentMethod)), { category: 'validation_failure' }));
292
436
  function FormPlaceholder() {
293
437
  return _jsx("span", { className: 'wfc-progress wfc-progress--form', "aria-hidden": 'true' });
294
438
  }
295
- function resolveCardPaymentElementOptions(overrides) {
439
+ function resolveCardPaymentElementOptions(overrides, fixedCountry) {
296
440
  var _a;
297
441
  const billingDetails = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.fields) === null || _a === void 0 ? void 0 : _a.billingDetails;
298
442
  return Object.assign(Object.assign(Object.assign({}, methodPaymentElementOptions), overrides), { fields: {
299
443
  billingDetails: typeof billingDetails === 'string' ? billingDetails : Object.assign({ name: 'never', email: 'never',
300
444
  // US banks match the postal code against the cardholder's; without it they decline more as fraud.
301
- address: { country: 'auto', postalCode: 'auto' } }, billingDetails),
445
+ // A single accepted country is filled in through the session's default billing address.
446
+ address: { country: fixedCountry ? 'never' : 'auto', postalCode: 'auto' } }, billingDetails),
302
447
  } });
303
448
  }
304
449
  function CheckIcon() {
@@ -1,5 +1,5 @@
1
- export declare function buildWalletFirstCheckoutOptions(clientSecret: string, themeColor?: string): {
2
- clientSecret: string;
1
+ /** `fixedBillingCountry` fills in the only billing country the offer accepts. */
2
+ export declare function buildWalletFirstCheckoutOptions(clientSecret: string, themeColor?: string, fixedBillingCountry?: string | null): {
3
3
  elementsOptions: {
4
4
  appearance: {
5
5
  variables: {
@@ -13,4 +13,12 @@ export declare function buildWalletFirstCheckoutOptions(clientSecret: string, th
13
13
  labels: "above";
14
14
  };
15
15
  };
16
+ defaultValues?: {
17
+ billingAddress: {
18
+ address: {
19
+ country: string;
20
+ };
21
+ };
22
+ } | undefined;
23
+ clientSecret: string;
16
24
  };
@@ -9,11 +9,9 @@ const appearance = {
9
9
  spacingUnit: '4px',
10
10
  },
11
11
  };
12
- export function buildWalletFirstCheckoutOptions(clientSecret, themeColor) {
13
- return {
14
- clientSecret,
15
- elementsOptions: {
12
+ /** `fixedBillingCountry` fills in the only billing country the offer accepts. */
13
+ export function buildWalletFirstCheckoutOptions(clientSecret, themeColor, fixedBillingCountry) {
14
+ return Object.assign(Object.assign({ clientSecret }, (fixedBillingCountry ? { defaultValues: { billingAddress: { address: { country: fixedBillingCountry } } } } : {})), { elementsOptions: {
16
15
  appearance: Object.assign(Object.assign({}, appearance), { variables: Object.assign(Object.assign({}, appearance.variables), (themeColor ? { colorPrimary: themeColor } : {})) }),
17
- },
18
- };
16
+ } });
19
17
  }
@@ -1,4 +1,4 @@
1
1
  /** Wallet slot of WalletButton: progress bar, Stripe's wallet button and the unavailable note share one height. */
2
2
  export declare const walletButtonStyles = "\n.wfc-wallet-slot { position:relative; height:55px; }\n.wfc-wallet-button { height:55px; overflow:hidden; border-radius:12px; }\n.wfc-progress { position:relative; display:block; height:100%; overflow:hidden; border-radius:12px; background:#eef0f6; }\n.wfc-progress::after { content:''; position:absolute; inset:0; background:linear-gradient(90deg, transparent, rgba(255,255,255,.75), transparent); transform:translateX(-100%); animation:wfc-sheen 1.3s ease-in-out infinite; }\n.wfc-progress--overlay { position:absolute; inset:0; z-index:1; }\n@keyframes wfc-sheen { to { transform:translateX(100%); } }\n@media (prefers-reduced-motion: reduce) { .wfc-progress::after { animation:none; } }\n.wfc-wallet-unavailable { position:absolute; inset:0; z-index:1; display:flex; align-items:center; justify-content:center; margin:0; padding:0 16px; border-radius:12px; background:#f4f5f8; color:#6b6773; font-size:14px; line-height:1.35; text-align:center; }\n";
3
3
  /** Styles for StripeWalletFirstCheckout; colors come from its `themeColor` and `buttonColor` props. */
4
- export declare const stripeWalletFirstCheckoutStyles = "\n.wfc { display:grid; gap:12px; }\n/* The radio marks the choice; every card keeps the same quiet border. */\n.wfc-method { border-radius:16px; background:#fff; box-shadow:0 0 0 1.5px #e6e6ec; }\n.wfc-method-head { display:flex; align-items:center; gap:14px; width:100%; min-height:60px; padding:14px 16px; border:0; background:transparent; color:inherit; text-align:left; cursor:pointer; border-radius:16px; }\n.wfc-method-head:disabled { cursor:default; }\n.wfc-method-head:focus-visible { outline:3px solid var(--wfc-theme); outline-offset:2px; }\n.wfc-radio { flex:none; width:24px; height:24px; border-radius:50%; border:2px solid #b8bac4; background:#fff; transition:border-color .2s ease, box-shadow .2s ease; }\n.wfc-method[data-checked='true'] .wfc-radio { border-color:var(--wfc-theme); box-shadow:inset 0 0 0 4px #fff, inset 0 0 0 12px var(--wfc-theme); }\n.wfc-method-body { display:grid; grid-template-rows:0fr; opacity:0; transition:grid-template-rows .34s cubic-bezier(.25,.8,.25,1), opacity .22s ease; }\n.wfc-method-body[data-open='true'] { grid-template-rows:1fr; opacity:1; transition:grid-template-rows .34s cubic-bezier(.25,.8,.25,1), opacity .28s ease .08s; }\n.wfc-method-clip { min-height:0; overflow:hidden; }\n.wfc-method-content { padding:0 16px 16px; }\n@media (prefers-reduced-motion: reduce) { .wfc-method-body, .wfc-method-body[data-open='true'] { transition:none; } }\n.wfc-mark { height:30px; width:auto; color:#000; }\n.wfc-card-marks { display:flex; gap:6px; align-items:center; }\n.wfc-brand { width:40px; height:26px; border-radius:4px; }\n.wfc-benefits { margin:0 0 16px; padding:0; list-style:none; display:grid; gap:10px; font-size:15px; line-height:1.4; color:#303136; }\n.wfc-benefits li { display:flex; gap:10px; align-items:flex-start; }\n.wfc-check { flex:none; width:16px; height:16px; margin-top:2px; color:var(--wfc-theme); }\n\n.wfc-wallet-slot { position:relative; height:55px; }\n.wfc-wallet-button { height:55px; overflow:hidden; border-radius:12px; }\n.wfc-progress { position:relative; display:block; height:100%; overflow:hidden; border-radius:12px; background:#eef0f6; }\n.wfc-progress::after { content:''; position:absolute; inset:0; background:linear-gradient(90deg, transparent, rgba(255,255,255,.75), transparent); transform:translateX(-100%); animation:wfc-sheen 1.3s ease-in-out infinite; }\n.wfc-progress--overlay { position:absolute; inset:0; z-index:1; }\n@keyframes wfc-sheen { to { transform:translateX(100%); } }\n@media (prefers-reduced-motion: reduce) { .wfc-progress::after { animation:none; } }\n.wfc-wallet-unavailable { position:absolute; inset:0; z-index:1; display:flex; align-items:center; justify-content:center; margin:0; padding:0 16px; border-radius:12px; background:#f4f5f8; color:#6b6773; font-size:14px; line-height:1.35; text-align:center; }\n\n.wfc-progress--form { height:320px; }\n.wfc-method-label { font-size:17px; font-weight:600; line-height:1.2; color:#303136; }\n.wfc-secure { margin:16px 0 0; text-align:center; font-size:14px; line-height:1.45; color:#8c909a; }\n.wfc-card-form { display:grid; gap:14px; }\n.wfc-card-form .wfc-secure { margin-top:0; }\n.wfc-submit { min-height:52px; border:0; border-radius:12px; background:var(--wfc-button); color:#fff; font:600 17px/1.2 inherit; cursor:pointer; }\n.wfc-submit:disabled { opacity:.6; cursor:default; }\n.wfc-error { margin:0; color:#c62828; font-size:14px; text-align:center; }\n.wfc-secure.is-status { color:var(--wfc-theme); font-weight:600; }\n";
4
+ export declare const stripeWalletFirstCheckoutStyles = "\n.wfc { position:relative; display:grid; gap:12px; }\n/* The radio marks the choice; every card keeps the same quiet border. */\n.wfc-method { border-radius:16px; background:#fff; box-shadow:0 0 0 1.5px #e6e6ec; }\n.wfc-method-head { display:flex; align-items:center; gap:14px; width:100%; min-height:60px; padding:14px 16px; border:0; background:transparent; color:inherit; text-align:left; cursor:pointer; border-radius:16px; }\n.wfc-method-head:disabled { cursor:default; }\n.wfc-method-head:focus-visible { outline:3px solid var(--wfc-theme); outline-offset:2px; }\n.wfc-radio { flex:none; width:24px; height:24px; border-radius:50%; border:2px solid #b8bac4; background:#fff; transition:border-color .2s ease, box-shadow .2s ease; }\n.wfc-method[data-checked='true'] .wfc-radio { border-color:var(--wfc-theme); box-shadow:inset 0 0 0 4px #fff, inset 0 0 0 12px var(--wfc-theme); }\n.wfc-method-body { display:grid; grid-template-rows:0fr; opacity:0; transition:grid-template-rows .34s cubic-bezier(.25,.8,.25,1), opacity .22s ease; }\n.wfc-method-body[data-open='true'] { grid-template-rows:1fr; opacity:1; transition:grid-template-rows .34s cubic-bezier(.25,.8,.25,1), opacity .28s ease .08s; }\n.wfc-method-clip { min-height:0; overflow:hidden; }\n.wfc-method-content { padding:0 16px 16px; }\n@media (prefers-reduced-motion: reduce) { .wfc-method-body, .wfc-method-body[data-open='true'] { transition:none; } }\n.wfc-mark { height:30px; width:auto; color:#000; }\n.wfc-card-marks { display:flex; gap:6px; align-items:center; }\n.wfc-brand { width:40px; height:26px; border-radius:4px; }\n.wfc-benefits { margin:0 0 16px; padding:0; list-style:none; display:grid; gap:10px; font-size:15px; line-height:1.4; color:#303136; }\n.wfc-benefits li { display:flex; gap:10px; align-items:flex-start; }\n.wfc-check { flex:none; width:16px; height:16px; margin-top:2px; color:var(--wfc-theme); }\n\n.wfc-wallet-slot { position:relative; height:55px; }\n.wfc-wallet-button { height:55px; overflow:hidden; border-radius:12px; }\n.wfc-progress { position:relative; display:block; height:100%; overflow:hidden; border-radius:12px; background:#eef0f6; }\n.wfc-progress::after { content:''; position:absolute; inset:0; background:linear-gradient(90deg, transparent, rgba(255,255,255,.75), transparent); transform:translateX(-100%); animation:wfc-sheen 1.3s ease-in-out infinite; }\n.wfc-progress--overlay { position:absolute; inset:0; z-index:1; }\n@keyframes wfc-sheen { to { transform:translateX(100%); } }\n@media (prefers-reduced-motion: reduce) { .wfc-progress::after { animation:none; } }\n.wfc-wallet-unavailable { position:absolute; inset:0; z-index:1; display:flex; align-items:center; justify-content:center; margin:0; padding:0 16px; border-radius:12px; background:#f4f5f8; color:#6b6773; font-size:14px; line-height:1.35; text-align:center; }\n\n.wfc-progress--form { height:320px; }\n.wfc-method-label { font-size:17px; font-weight:600; line-height:1.2; color:#303136; }\n.wfc-secure { margin:16px 0 0; text-align:center; font-size:14px; line-height:1.45; color:#8c909a; }\n.wfc-card-form { display:grid; gap:14px; }\n.wfc-card-form .wfc-secure { margin-top:0; }\n.wfc-submit { min-height:52px; border:0; border-radius:12px; background:var(--wfc-button); color:#fff; font:600 17px/1.2 inherit; cursor:pointer; }\n.wfc-submit:disabled { opacity:.6; cursor:default; }\n.wfc-error { margin:0; color:#c62828; font-size:14px; text-align:center; }\n.wfc-secure:empty { display:none; }\n.wfc-email { display:grid; gap:6px; }\n.wfc-email-label { font-size:14px; line-height:1.3; color:#303136; }\n.wfc-email-input { box-sizing:border-box; width:100%; min-height:44px; padding:10px 12px; border:1px solid #e0e0e6; border-radius:12px; background:#fff; color:#303136; font:inherit; font-size:16px; }\n.wfc-email-input:focus { outline:none; border-color:var(--wfc-theme); box-shadow:0 0 0 3px color-mix(in srgb, var(--wfc-theme) 22%, transparent); }\n.wfc-email-input:disabled { opacity:.6; }\n.wfc-card-marks .wfc-brand { display:inline-flex; }\n.wfc-card-marks .wfc-brand svg, .wfc-brand--paypal svg { width:100%; height:100%; }\n.wfc-brand--paypal { display:inline-flex; width:64px; height:26px; }\n.wfc-paypal { min-height:55px; }\n.wfc-secure.is-status { color:var(--wfc-theme); font-weight:600; }\n";
@@ -11,7 +11,7 @@ export const walletButtonStyles = `
11
11
  `;
12
12
  /** Styles for StripeWalletFirstCheckout; colors come from its `themeColor` and `buttonColor` props. */
13
13
  export const stripeWalletFirstCheckoutStyles = `
14
- .wfc { display:grid; gap:12px; }
14
+ .wfc { position:relative; display:grid; gap:12px; }
15
15
  /* The radio marks the choice; every card keeps the same quiet border. */
16
16
  .wfc-method { border-radius:16px; background:#fff; box-shadow:0 0 0 1.5px #e6e6ec; }
17
17
  .wfc-method-head { display:flex; align-items:center; gap:14px; width:100%; min-height:60px; padding:14px 16px; border:0; background:transparent; color:inherit; text-align:left; cursor:pointer; border-radius:16px; }
@@ -39,5 +39,15 @@ ${walletButtonStyles}
39
39
  .wfc-submit { min-height:52px; border:0; border-radius:12px; background:var(--wfc-button); color:#fff; font:600 17px/1.2 inherit; cursor:pointer; }
40
40
  .wfc-submit:disabled { opacity:.6; cursor:default; }
41
41
  .wfc-error { margin:0; color:#c62828; font-size:14px; text-align:center; }
42
+ .wfc-secure:empty { display:none; }
43
+ .wfc-email { display:grid; gap:6px; }
44
+ .wfc-email-label { font-size:14px; line-height:1.3; color:#303136; }
45
+ .wfc-email-input { box-sizing:border-box; width:100%; min-height:44px; padding:10px 12px; border:1px solid #e0e0e6; border-radius:12px; background:#fff; color:#303136; font:inherit; font-size:16px; }
46
+ .wfc-email-input:focus { outline:none; border-color:var(--wfc-theme); box-shadow:0 0 0 3px color-mix(in srgb, var(--wfc-theme) 22%, transparent); }
47
+ .wfc-email-input:disabled { opacity:.6; }
48
+ .wfc-card-marks .wfc-brand { display:inline-flex; }
49
+ .wfc-card-marks .wfc-brand svg, .wfc-brand--paypal svg { width:100%; height:100%; }
50
+ .wfc-brand--paypal { display:inline-flex; width:64px; height:26px; }
51
+ .wfc-paypal { min-height:55px; }
42
52
  .wfc-secure.is-status { color:var(--wfc-theme); font-weight:600; }
43
53
  `;
@@ -8,7 +8,9 @@ export type WalletButtonSession = {
8
8
  /** Stripe's `colorPrimary`, e.g. the funnel's theme color. */
9
9
  themeColor?: string;
10
10
  };
11
- export type WalletButtonProps = Pick<StripeCheckoutExpressCheckoutButtonProps, 'amountCents' | 'beforeConfirm' | 'checkoutAnalytics' | 'checkoutSessionId' | 'customerEmail' | 'customerName' | 'onAvailabilityChange' | 'onCancel' | 'onEmbeddedComplete' | 'onError' | 'onPaymentRejected' | 'onSuccess' | 'onVerificationPending' | 'returnUrl' | 'summaryLabel'> & {
11
+ export type WalletButtonProps = Pick<StripeCheckoutExpressCheckoutButtonProps, 'amountCents' | 'beforeConfirm' | 'checkoutAnalytics' | 'checkoutSessionId' | 'customerEmail' | 'customerName' | 'onAvailabilityChange' | 'onCancel' | 'onEmbeddedComplete' | 'onError' | 'onPaymentInfoSubmitted' | 'onPaymentRejected' | 'onSuccess' | 'onVerificationPending' | 'returnUrl' | 'summaryLabel' | 'supportedCountries' | 'unsupportedCountryMessage'> & {
12
+ /** Availability known from an earlier render: the button shows without the progress bar. */
13
+ initialAvailable?: boolean | null;
12
14
  wallet: PlatformWalletPaymentMethod;
13
15
  /** Accessible name of the progress bar. */
14
16
  processingLabel: string;
@@ -34,9 +34,9 @@ export function WalletButton(_a) {
34
34
  return (_jsxs(_Fragment, { children: [session.clientSecret && session.stripePromise ? (_jsx(CheckoutProvider, { stripe: session.stripePromise, options: buildWalletFirstCheckoutOptions(session.clientSecret, session.themeColor), children: _jsx(WalletSlot, Object.assign({}, slot)) }, session.clientSecret)) : (_jsx("div", { className: 'wfc-wallet-slot', children: _jsx("span", { className: 'wfc-progress', role: 'status', "aria-label": slot.processingLabel }) })), _jsx("style", { children: walletButtonStyles })] }));
35
35
  }
36
36
  function WalletSlot(_a) {
37
- var { onAvailabilityChange, processingLabel, unavailableNote, wallet } = _a, button = __rest(_a, ["onAvailabilityChange", "processingLabel", "unavailableNote", "wallet"]);
37
+ var { initialAvailable = null, onAvailabilityChange, processingLabel, unavailableNote, wallet } = _a, button = __rest(_a, ["initialAvailable", "onAvailabilityChange", "processingLabel", "unavailableNote", "wallet"]);
38
38
  // null until Stripe answers; the slot shows progress at the button's height meanwhile.
39
- const [available, setAvailable] = useState(null);
39
+ const [available, setAvailable] = useState(initialAvailable);
40
40
  const options = {
41
41
  buttonHeight: 55,
42
42
  buttonTheme: { applePay: 'black', googlePay: 'black' },
@@ -48,5 +48,5 @@ function WalletSlot(_a) {
48
48
  googlePay: wallet === 'googlePay' ? 'always' : 'never',
49
49
  },
50
50
  };
51
- return (_jsxs("div", { className: 'wfc-wallet-slot', children: [_jsx("div", { className: 'wfc-wallet-button', "data-ready": available === true, children: _jsx(StripeCheckoutExpressCheckoutButton, Object.assign({}, button, { availabilityPaymentMethods: [wallet], confirmEmail: false, onAvailabilityChange: (value) => { setAvailable(value); onAvailabilityChange === null || onAvailabilityChange === void 0 ? void 0 : onAvailabilityChange(value); }, options: options })) }), available === null ? _jsx("span", { className: 'wfc-progress wfc-progress--overlay', role: 'status', "aria-label": processingLabel }) : null, available === false ? _jsx("p", { className: 'wfc-wallet-unavailable', role: 'status', children: unavailableNote }) : null] }));
51
+ return (_jsxs("div", { className: 'wfc-wallet-slot', children: [_jsx("div", { className: 'wfc-wallet-button', "data-ready": available === true, children: _jsx(StripeCheckoutExpressCheckoutButton, Object.assign({}, button, { availabilityPaymentMethods: [wallet], confirmEmail: false, initialAvailable: initialAvailable, keepInitialAvailableOnReady: initialAvailable === true, onAvailabilityChange: (value) => { setAvailable(value); onAvailabilityChange === null || onAvailabilityChange === void 0 ? void 0 : onAvailabilityChange(value); }, options: options })) }), available === null ? _jsx("span", { className: 'wfc-progress wfc-progress--overlay', role: 'status', "aria-label": processingLabel }) : null, available === false ? _jsx("p", { className: 'wfc-wallet-unavailable', role: 'status', children: unavailableNote }) : null] }));
52
52
  }
@@ -1,3 +1,4 @@
1
+ import type { CheckoutErrorOverlayCopy } from '../../../components/CheckoutErrorOverlay.js';
1
2
  export type SharedStripeCheckoutV2Copy = {
2
3
  paymentMethodLabel: string;
3
4
  countdownUnit: string;
@@ -10,5 +11,7 @@ export type SharedStripeCheckoutV2Copy = {
10
11
  paymentConfirmed: string;
11
12
  billingCountryLabel: string;
12
13
  countryNames: Readonly<Record<string, string>>;
14
+ /** Titles and buttons of the payment error panel; English defaults. `checkPaymentStatus` labels its status check. */
15
+ errors?: CheckoutErrorOverlayCopy;
13
16
  };
14
17
  export declare const defaultCheckoutV2Copy: SharedStripeCheckoutV2Copy;
@@ -12,6 +12,7 @@ export * from './StripePlanSelector.js';
12
12
  export * from './StripeSubscriptionWalletSurface.js';
13
13
  export * from './StripeWalletFirstCheckout.js';
14
14
  export * from './StripeCheckoutSheet.js';
15
+ export * from './StripeCheckoutDialog.js';
15
16
  export * from './WalletButton.js';
16
17
  export * from './WalletSubscriptionCheckoutSlot.js';
17
18
  export * from './walletPlatform.js';