@funnelsgrove/payments 0.68.0 → 0.70.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/README.md +31 -14
- package/dist/components/CheckoutErrorOverlay.d.ts +37 -0
- package/dist/components/CheckoutErrorOverlay.js +67 -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/providers/stripe/components/SharedStripeCheckoutV2Dialog.d.ts +13 -4
- package/dist/providers/stripe/components/SharedStripeCheckoutV2Dialog.js +93 -88
- package/dist/providers/stripe/components/StripeCheckoutDialog.d.ts +31 -0
- package/dist/providers/stripe/components/StripeCheckoutDialog.js +179 -0
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.d.ts +81 -7
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.js +204 -56
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.options.d.ts +10 -2
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.options.js +4 -6
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.styles.d.ts +1 -1
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.styles.js +11 -1
- package/dist/providers/stripe/components/WalletButton.d.ts +3 -1
- package/dist/providers/stripe/components/WalletButton.js +3 -3
- package/dist/providers/stripe/components/checkout-v2.content.d.ts +3 -0
- package/dist/providers/stripe/components/index.d.ts +1 -0
- package/dist/providers/stripe/components/index.js +1 -0
- package/dist/providers/stripe/components/useCheckoutEmail.internal.d.ts +3 -1
- package/dist/providers/stripe/components/useCheckoutEmail.internal.js +8 -3
- package/dist/providers/stripe/hooks/checkoutPageAttention.d.ts +3 -0
- package/dist/providers/stripe/hooks/checkoutPageAttention.js +54 -0
- package/dist/providers/stripe/hooks/checkoutPreparationBackoff.d.ts +1 -0
- package/dist/providers/stripe/hooks/checkoutPreparationBackoff.js +5 -7
- package/dist/providers/stripe/hooks/useStripeSubscriptionCheckoutSession.js +39 -2
- package/package.json +1 -1
- package/dist/providers/stripe/components/SharedCheckoutPaymentMethods.internal.d.ts +0 -18
- package/dist/providers/stripe/components/SharedCheckoutPaymentMethods.internal.js +0 -15
- package/dist/providers/stripe/components/SharedStripeCheckoutV2Form.internal.d.ts +0 -7
- package/dist/providers/stripe/components/SharedStripeCheckoutV2Form.internal.js +0 -328
- package/dist/providers/stripe/components/SharedStripeCheckoutV2Summary.internal.d.ts +0 -7
- 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
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
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 = (
|
|
90
|
-
const
|
|
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 = (
|
|
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 [confirmedPayment, setConfirmedPayment] = 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
|
+
setConfirmedPayment(null);
|
|
158
|
+
setCompleted(false);
|
|
112
159
|
}
|
|
113
160
|
const paymentStatus = completed ? copy.paymentConfirmed : confirmed ? copy.verifyingPayment : null;
|
|
114
161
|
const status = {
|
|
@@ -117,56 +164,130 @@ export function StripeWalletFirstCheckout(props) {
|
|
|
117
164
|
locked: Boolean(paymentStatus) && !error,
|
|
118
165
|
error,
|
|
119
166
|
setBusy,
|
|
120
|
-
markConfirmed: () => setConfirmed(true),
|
|
167
|
+
markConfirmed: (payment) => { setConfirmed(true); setConfirmedPayment(payment); },
|
|
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
|
|
131
191
|
onError === null || onError === void 0 ? void 0 : onError(message);
|
|
132
192
|
},
|
|
133
|
-
trackSuccess: async (
|
|
193
|
+
trackSuccess: async (payment, embedded = false) => {
|
|
134
194
|
if (checkoutAnalytics)
|
|
135
|
-
await trackPaidStripeSubscriptionCheckoutCompleted(Object.assign(Object.assign({}, checkoutAnalytics), { checkoutSessionId:
|
|
195
|
+
await trackPaidStripeSubscriptionCheckoutCompleted(Object.assign(Object.assign({}, checkoutAnalytics), { checkoutSessionId: payment.checkoutSessionId }));
|
|
136
196
|
if (embedded)
|
|
137
197
|
return false;
|
|
138
|
-
return (await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess())) === true;
|
|
198
|
+
return (await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(payment))) === true;
|
|
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
|
|
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,
|
|
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') {
|
|
221
|
+
const walletPayment = { checkoutSessionId, paymentMethod: wallet === 'applePay' ? 'apple_pay' : 'google_pay' };
|
|
158
222
|
const WalletMark = wallet === 'applePay' ? ApplePayMark : GooglePayMark;
|
|
159
223
|
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(
|
|
224
|
+
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 () => {
|
|
225
|
+
setBusy(true);
|
|
226
|
+
if (!emailController)
|
|
227
|
+
return props.customerEmail || null;
|
|
228
|
+
const confirmedEmail = await email.ensureCustomerEmail();
|
|
229
|
+
if (!confirmedEmail)
|
|
230
|
+
setBusy(false);
|
|
231
|
+
return confirmedEmail;
|
|
232
|
+
}, 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(walletPayment); }, onVerificationPending: () => status.markConfirmed(walletPayment), 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
233
|
}
|
|
162
234
|
if (block.kind === 'card') {
|
|
163
|
-
|
|
164
|
-
|
|
235
|
+
const brands = ((_a = props.cardBrandLabels) === null || _a === void 0 ? void 0 : _a.length)
|
|
236
|
+
? _jsx("span", { className: 'wfc-card-marks', "aria-hidden": 'true', children: props.cardBrandLabels.map((label) => _jsx(PaymentBrandMark, { label: label, className: 'wfc-brand' }, label)) })
|
|
237
|
+
: _jsx(CardBrandMarks, {});
|
|
238
|
+
return (_jsx(MethodCard, { checked: checked, disabled: disabled, label: copy.cardLabel, onSelect: () => select('card'), header: brands, children: live
|
|
239
|
+
? _jsx(MethodForm, Object.assign({}, formProps, { blockId: 'card', checkoutSessionId: checkoutSessionId, failureStage: 'card_form', paymentElementOptions: cardPaymentElementOptions, paymentMethod: 'card', selected: checked, startSource: 'card_form_open' }))
|
|
165
240
|
: _jsx(FormPlaceholder, {}) }, 'card'));
|
|
166
241
|
}
|
|
242
|
+
if (block.kind === 'paypal') {
|
|
243
|
+
const label = (_b = props.paypalLabel) !== null && _b !== void 0 ? _b : 'PayPal';
|
|
244
|
+
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'));
|
|
245
|
+
}
|
|
167
246
|
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
247
|
};
|
|
169
|
-
|
|
248
|
+
// A confirmed payment that failed to verify is checked again, never paid again.
|
|
249
|
+
const checkPaymentStatus = async () => {
|
|
250
|
+
var _a;
|
|
251
|
+
const payment = confirmedPayment !== null && confirmedPayment !== void 0 ? confirmedPayment : { checkoutSessionId, paymentMethod: null };
|
|
252
|
+
const paidSessionId = payment.checkoutSessionId;
|
|
253
|
+
const context = { blockId: (_a = failure === null || failure === void 0 ? void 0 : failure.blockId) !== null && _a !== void 0 ? _a : 'card', checkoutSessionId: paidSessionId, failureStage: 'verification' };
|
|
254
|
+
status.showError(null, context);
|
|
255
|
+
setBusy(true);
|
|
256
|
+
try {
|
|
257
|
+
if (await completePaywallCheckout('stripe', paidSessionId || '', {
|
|
258
|
+
beforeNotify: async () => { setCompleted(true); await status.trackSuccess(payment, true); },
|
|
259
|
+
}))
|
|
260
|
+
return;
|
|
261
|
+
if (await status.trackSuccess(payment))
|
|
262
|
+
return;
|
|
263
|
+
window.location.assign(resolveCheckoutReturnUrl(props.returnUrl, paidSessionId));
|
|
264
|
+
}
|
|
265
|
+
catch (verifyError) {
|
|
266
|
+
status.showError(verifyError instanceof Error && verifyError.message ? verifyError.message : copy.paymentFailed, context, undefined, true);
|
|
267
|
+
}
|
|
268
|
+
finally {
|
|
269
|
+
setBusy(false);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
// A field the form can mark keeps its error inline; any other failure lies over the blocks.
|
|
273
|
+
// After a confirmation every failure lies over the blocks: the only action left is checking the payment.
|
|
274
|
+
const overlayFailure = error && failure && (confirmed || failure.details.category !== 'validation_failure') ? failure : null;
|
|
275
|
+
const dismissFailure = () => status.showError(null, { blockId: activeId !== null && activeId !== void 0 ? activeId : 'card', checkoutSessionId, failureStage: 'dismiss' });
|
|
276
|
+
// Only a method this browser can pay with is offered as the way out of a decline.
|
|
277
|
+
const alternativeBlock = !confirmed && (overlayFailure === null || overlayFailure === void 0 ? void 0 : overlayFailure.details.category) === 'payment_rejection'
|
|
278
|
+
? blocks.find((block) => block.id === (overlayFailure.blockId === 'card' ? 'wallet' : 'card')
|
|
279
|
+
&& !(block.kind === 'wallet' && walletAvailable === false))
|
|
280
|
+
: undefined;
|
|
281
|
+
const blockLabel = (block) => {
|
|
282
|
+
var _a;
|
|
283
|
+
return block.kind === 'wallet' ? copy.walletLabels[wallet]
|
|
284
|
+
: block.kind === 'card' ? copy.cardLabel
|
|
285
|
+
: block.kind === 'paypal' ? (_a = props.paypalLabel) !== null && _a !== void 0 ? _a : 'PayPal'
|
|
286
|
+
: block.types.map((type) => methodLabel(type, copy)).join(' · ');
|
|
287
|
+
};
|
|
288
|
+
const layout = (_jsxs("div", { className: 'wfc', style: style, children: [renderedBlocks.map((block) => block.kind === 'wallet' && walletHidden
|
|
289
|
+
? _jsx("div", { hidden: true, children: renderBlock(block) }, 'wallet')
|
|
290
|
+
: 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
291
|
return (_jsxs(_Fragment, { children: [options && stripePromise ? (_jsx(CheckoutProvider, { stripe: stripePromise, options: options, children: layout }, options.clientSecret)) : layout, _jsx("style", { children: stripeWalletFirstCheckoutStyles })] }));
|
|
171
292
|
}
|
|
172
293
|
/** Stripe collects what each other method needs (e.g. the CPF for Pix); only the card form restricts its fields. */
|
|
@@ -189,19 +310,23 @@ function SessionMethodBlock(_a) {
|
|
|
189
310
|
}, [activeClientSecret, checked, prepareCardCheckout]);
|
|
190
311
|
const options = useMemo(() => activeClientSecret ? buildWalletFirstCheckoutOptions(activeClientSecret, themeColor) : null, [activeClientSecret, themeColor]);
|
|
191
312
|
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] }));
|
|
313
|
+
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
314
|
}
|
|
194
315
|
/** 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, }) {
|
|
316
|
+
function MethodForm({ blockId, checkoutAnalytics, checkoutSessionId, copy, countries, customerEmail, email, engaged, failureStage, onEngage, onPaymentInfoSubmitted, paymentElementOptions, paymentMethod, returnUrl, selected, startSource, status, }) {
|
|
317
|
+
var _a, _b;
|
|
196
318
|
const checkoutState = useCheckout();
|
|
197
319
|
const [paymentElementReady, setPaymentElementReady] = useState(false);
|
|
198
320
|
const [paymentElementComplete, setPaymentElementComplete] = useState(false);
|
|
199
321
|
const [pickedMethod, setPickedMethod] = useState(undefined);
|
|
322
|
+
const [billingCountry, setBillingCountry] = useState(null);
|
|
200
323
|
const [submitting, setSubmitting] = useState(false);
|
|
201
324
|
// Confirmation belongs to this session: a replaced session confirms again.
|
|
202
325
|
const [providerConfirmed, setProviderConfirmed] = useState(false);
|
|
203
326
|
const submitInFlight = useRef(false);
|
|
204
327
|
const method = paymentMethod !== null && paymentMethod !== void 0 ? paymentMethod : pickedMethod;
|
|
328
|
+
// A saved email change replaces the session; this form waits for the new one.
|
|
329
|
+
const emailPending = Boolean(email && (email.emailSaving || email.emailSessionChanged));
|
|
205
330
|
// The checkout starts when the visitor opens the form, or, when it opens preselected, on their first input into it.
|
|
206
331
|
useEffect(() => {
|
|
207
332
|
if (!checkoutAnalytics || !selected || !engaged)
|
|
@@ -215,22 +340,30 @@ function MethodForm({ checkoutAnalytics, checkoutSessionId, copy, customerEmail,
|
|
|
215
340
|
const timer = window.setTimeout(() => window.dispatchEvent(new Event('resize')), 0);
|
|
216
341
|
return () => window.clearTimeout(timer);
|
|
217
342
|
}, [selected]);
|
|
218
|
-
const failure = { checkoutSessionId, failureStage, paymentMethod: method };
|
|
343
|
+
const failure = { blockId, checkoutSessionId, failureStage, paymentMethod: method };
|
|
219
344
|
const showError = (message, details, alreadyTracked = false) => status.showError(message, failure, details, alreadyTracked);
|
|
345
|
+
const payment = { checkoutSessionId, paymentMethod: method !== null && method !== void 0 ? method : null };
|
|
220
346
|
const finishPaidCheckout = async () => {
|
|
221
347
|
if (await completePaywallCheckout('stripe', checkoutSessionId || '', {
|
|
222
|
-
beforeNotify: async () => { status.markCompleted(); await status.trackSuccess(
|
|
348
|
+
beforeNotify: async () => { status.markCompleted(); await status.trackSuccess(payment, true); },
|
|
223
349
|
}))
|
|
224
350
|
return;
|
|
225
|
-
if (await status.trackSuccess(
|
|
351
|
+
if (await status.trackSuccess(payment))
|
|
226
352
|
return;
|
|
227
|
-
window.location.assign(returnUrl);
|
|
353
|
+
window.location.assign(resolveCheckoutReturnUrl(returnUrl, checkoutSessionId));
|
|
228
354
|
};
|
|
229
355
|
const submit = async (event) => {
|
|
230
356
|
event.preventDefault();
|
|
231
|
-
if (submitInFlight.current)
|
|
357
|
+
if (submitInFlight.current || (emailPending && !providerConfirmed))
|
|
232
358
|
return;
|
|
233
359
|
if (!providerConfirmed) {
|
|
360
|
+
const countryError = getUnsupportedCheckoutCountryMessage({
|
|
361
|
+
billingCountry: billingCountry !== null && billingCountry !== void 0 ? billingCountry : countries.fixed, message: countries.message, supportedCountries: countries.supported,
|
|
362
|
+
});
|
|
363
|
+
if (countryError) {
|
|
364
|
+
showError(countryError, validationFailure(countryError, method));
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
234
367
|
if (checkoutState.type !== 'success') {
|
|
235
368
|
showError(checkoutState.type === 'error' ? checkoutState.error.message : copy.formNotReady);
|
|
236
369
|
return;
|
|
@@ -244,61 +377,76 @@ function MethodForm({ checkoutAnalytics, checkoutSessionId, copy, customerEmail,
|
|
|
244
377
|
setSubmitting(true);
|
|
245
378
|
status.setBusy(true);
|
|
246
379
|
showError(null);
|
|
380
|
+
const stopSubmitting = () => {
|
|
381
|
+
submitInFlight.current = false;
|
|
382
|
+
setSubmitting(false);
|
|
383
|
+
status.setBusy(false);
|
|
384
|
+
};
|
|
247
385
|
let confirmed = providerConfirmed;
|
|
248
386
|
try {
|
|
249
387
|
if (!providerConfirmed && checkoutState.type === 'success') {
|
|
250
388
|
const { checkout } = checkoutState;
|
|
251
|
-
|
|
252
|
-
|
|
389
|
+
const payerEmail = email ? await email.ensureCustomerEmail() : customerEmail;
|
|
390
|
+
// A missing or just-saved email needs a fresh action on the replaced session.
|
|
391
|
+
if (email && !payerEmail) {
|
|
392
|
+
stopSubmitting();
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (!checkout.email && payerEmail) {
|
|
396
|
+
const updated = await checkout.updateEmail(payerEmail);
|
|
253
397
|
if (updated.type === 'error')
|
|
254
398
|
throw new Error(updated.error.message);
|
|
255
399
|
}
|
|
256
|
-
if (paymentElementComplete
|
|
257
|
-
|
|
400
|
+
if (paymentElementComplete) {
|
|
401
|
+
if (checkoutAnalytics) {
|
|
402
|
+
await trackStripeSubscriptionPaymentInfoSubmitted(Object.assign(Object.assign({}, checkoutAnalytics), { checkoutSessionId })).catch(() => 'analytics_rejected');
|
|
403
|
+
}
|
|
404
|
+
await (onPaymentInfoSubmitted === null || onPaymentInfoSubmitted === void 0 ? void 0 : onPaymentInfoSubmitted());
|
|
258
405
|
}
|
|
259
406
|
const result = await checkout.confirm({ redirect: 'if_required' });
|
|
260
407
|
if (result.type === 'error' && !isStripeCheckoutAlreadyPaidError(result.error)) {
|
|
261
408
|
const message = result.error.message || copy.paymentFailed;
|
|
262
409
|
showError(message, normalizeStripeCheckoutError(message, result.error, method));
|
|
263
|
-
|
|
264
|
-
setSubmitting(false);
|
|
265
|
-
status.setBusy(false);
|
|
410
|
+
stopSubmitting();
|
|
266
411
|
return;
|
|
267
412
|
}
|
|
268
413
|
confirmed = true;
|
|
269
414
|
setProviderConfirmed(true);
|
|
270
|
-
status.markConfirmed();
|
|
415
|
+
status.markConfirmed(payment);
|
|
271
416
|
}
|
|
272
417
|
await finishPaidCheckout();
|
|
273
418
|
}
|
|
274
419
|
catch (submitError) {
|
|
275
420
|
showError(submitError instanceof Error && submitError.message ? submitError.message : copy.paymentFailed, undefined, confirmed);
|
|
276
|
-
|
|
277
|
-
setSubmitting(false);
|
|
278
|
-
status.setBusy(false);
|
|
421
|
+
stopSubmitting();
|
|
279
422
|
}
|
|
280
423
|
};
|
|
281
424
|
// After a successful confirmation the form stays in place and reports progress
|
|
282
425
|
// where the customer paid, until the success screen takes over.
|
|
283
426
|
const { locked } = status;
|
|
284
|
-
|
|
285
|
-
|
|
427
|
+
const showEmailField = Boolean(email && email.customerEmailEditable);
|
|
428
|
+
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) => {
|
|
429
|
+
var _a, _b, _c, _d, _e;
|
|
286
430
|
setPaymentElementComplete(event.complete);
|
|
287
431
|
setPickedMethod((_a = event.value) === null || _a === void 0 ? void 0 : _a.type);
|
|
432
|
+
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
433
|
if (!event.empty)
|
|
289
434
|
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 })] }));
|
|
435
|
+
}, 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
436
|
}
|
|
437
|
+
/** A failure the visitor fixes in a field: shown next to the form, not over it. */
|
|
438
|
+
const validationFailure = (message, paymentMethod) => (Object.assign(Object.assign({}, normalizeStripeCheckoutError(message, undefined, paymentMethod)), { category: 'validation_failure' }));
|
|
292
439
|
function FormPlaceholder() {
|
|
293
440
|
return _jsx("span", { className: 'wfc-progress wfc-progress--form', "aria-hidden": 'true' });
|
|
294
441
|
}
|
|
295
|
-
function resolveCardPaymentElementOptions(overrides) {
|
|
442
|
+
function resolveCardPaymentElementOptions(overrides, fixedCountry) {
|
|
296
443
|
var _a;
|
|
297
444
|
const billingDetails = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.fields) === null || _a === void 0 ? void 0 : _a.billingDetails;
|
|
298
445
|
return Object.assign(Object.assign(Object.assign({}, methodPaymentElementOptions), overrides), { fields: {
|
|
299
446
|
billingDetails: typeof billingDetails === 'string' ? billingDetails : Object.assign({ name: 'never', email: 'never',
|
|
300
447
|
// US banks match the postal code against the cardholder's; without it they decline more as fraud.
|
|
301
|
-
|
|
448
|
+
// A single accepted country is filled in through the session's default billing address.
|
|
449
|
+
address: { country: fixedCountry ? 'never' : 'auto', postalCode: 'auto' } }, billingDetails),
|
|
302
450
|
} });
|
|
303
451
|
}
|
|
304
452
|
function CheckIcon() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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(
|
|
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;
|