@funnelsgrove/payments 0.54.0 → 0.55.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 +8 -0
- package/dist/generated/package-version.d.ts +1 -1
- package/dist/generated/package-version.js +1 -1
- package/dist/providers/stripe/components/SharedStripeCheckoutV2Dialog.d.ts +2 -1
- package/dist/providers/stripe/components/SharedStripeCheckoutV2Form.internal.js +11 -16
- package/dist/providers/stripe/components/StripeCheckoutExpressCheckoutButton.d.ts +2 -1
- package/dist/providers/stripe/components/StripeCheckoutExpressCheckoutButton.js +18 -62
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.d.ts +2 -1
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.js +11 -9
- package/dist/providers/stripe/services/index.d.ts +1 -0
- package/dist/providers/stripe/services/stripeCheckoutError.d.ts +10 -0
- package/dist/providers/stripe/services/stripeCheckoutError.js +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,6 +43,14 @@ elsewhere, preselected, with Stripe's own button, and the card form as the secon
|
|
|
43
43
|
- The card form has no ZIP or terms text.
|
|
44
44
|
- `onCancel` runs when the visitor closes the Apple Pay or Google Pay sheet without paying,
|
|
45
45
|
for example to show an extra discount. The form is unlocked again by then.
|
|
46
|
+
- `onError(message, details?)` preserves the existing message argument and adds exported
|
|
47
|
+
`StripeCheckoutErrorDetails`: `category`, `paymentMethod`, `providerDeclineCode`,
|
|
48
|
+
`providerErrorCode`, and `providerErrorType`. The same callback contract applies to
|
|
49
|
+
`SharedStripeCheckoutV2Dialog` and `StripeCheckoutExpressCheckoutButton`. Provider fields
|
|
50
|
+
and payment method are present when known; clearing calls `onError(null)` without details.
|
|
51
|
+
Use `details.category === 'payment_rejection'` and `details.paymentMethod` to distinguish
|
|
52
|
+
a card, Apple Pay, or Google Pay refusal. Wallet refusals are reported before the existing
|
|
53
|
+
card fallback; wallet cancellation continues through `onCancel`.
|
|
46
54
|
- Where the browser cannot pay with that wallet, the wallet stays first and its slot shows
|
|
47
55
|
`walletUnavailableNote` (`{wallet}` is replaced with the wallet name). The card remains
|
|
48
56
|
one tap away. This is deliberate: the layout must not move.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PAYMENTS_PACKAGE_VERSION = "0.
|
|
1
|
+
export declare const PAYMENTS_PACKAGE_VERSION = "0.55.0";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by scripts/generate-package-version.mjs.
|
|
2
|
-
export const PAYMENTS_PACKAGE_VERSION = "0.
|
|
2
|
+
export const PAYMENTS_PACKAGE_VERSION = "0.55.0";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
import type { StripeCheckoutErrorDetails } from '../services/stripeCheckoutError.js';
|
|
2
3
|
import type { Stripe } from '@stripe/stripe-js';
|
|
3
4
|
import { type StripeSubscriptionCheckoutAnalyticsContext } from '../services/checkoutCompletionAnalytics.service.js';
|
|
4
5
|
import type { SharedStripeCheckoutV2Copy } from './checkout-v2.content.js';
|
|
@@ -33,7 +34,7 @@ export type SharedStripeCheckoutV2DialogProps = {
|
|
|
33
34
|
onWalletCancel?: () => void;
|
|
34
35
|
onCustomerEmailChange?: (value: string) => void;
|
|
35
36
|
onCustomerEmailCommit?: (email: string) => Promise<string | null | void>;
|
|
36
|
-
onError?: (message: string | null) => void;
|
|
37
|
+
onError?: (message: string | null, details?: StripeCheckoutErrorDetails) => void;
|
|
37
38
|
onInactiveCheckoutSession?: () => void;
|
|
38
39
|
onPaymentInfoSubmitted?: () => void | Promise<void>;
|
|
39
40
|
onSuccess?: () => void | Promise<void>;
|
|
@@ -11,6 +11,7 @@ import { isInactiveCheckoutSessionError } from '../hooks/useStripeSubscriptionCh
|
|
|
11
11
|
import { getStripeWalletPaymentMethodOrder, usePlatformWalletPaymentMethods } from './walletPlatform.js';
|
|
12
12
|
import { trackPaidStripeSubscriptionCheckoutCompleted, trackStripeSubscriptionPaymentInfoSubmitted } from '../services/checkoutCompletionAnalytics.service.js';
|
|
13
13
|
import { trackCheckoutFailureShown } from '../../../services/checkoutObservability.service.js';
|
|
14
|
+
import { normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
|
|
14
15
|
import { SharedCheckoutPaymentMethods } from './SharedCheckoutPaymentMethods.internal.js';
|
|
15
16
|
import { SharedStripeCheckoutV2Summary } from './SharedStripeCheckoutV2Summary.internal.js';
|
|
16
17
|
import { useCheckoutEmail } from './useCheckoutEmail.internal.js';
|
|
@@ -124,8 +125,9 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
124
125
|
setError(null);
|
|
125
126
|
onInactiveCheckoutSession === null || onInactiveCheckoutSession === void 0 ? void 0 : onInactiveCheckoutSession();
|
|
126
127
|
};
|
|
127
|
-
const setSharedError = (message, alreadyTracked = false,
|
|
128
|
-
|
|
128
|
+
const setSharedError = (message, alreadyTracked = false, details) => {
|
|
129
|
+
const errorDetails = message ? details !== null && details !== void 0 ? details : normalizeStripeCheckoutError(message, undefined, 'card') : undefined;
|
|
130
|
+
if (isCheckoutEmailError({ code: errorDetails === null || errorDetails === void 0 ? void 0 : errorDetails.providerErrorCode }) || isCheckoutEmailError(message)) {
|
|
129
131
|
setRejectedEmail(initialCustomerEmail);
|
|
130
132
|
setSelectedMethod('card');
|
|
131
133
|
}
|
|
@@ -134,20 +136,13 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
134
136
|
return;
|
|
135
137
|
}
|
|
136
138
|
if (message && checkoutAnalytics && !alreadyTracked) {
|
|
137
|
-
trackCheckoutFailureShown({
|
|
138
|
-
analytics: checkoutAnalytics,
|
|
139
|
-
checkoutSessionId,
|
|
140
|
-
errorMessage: message,
|
|
141
|
-
failureStage: 'card_form',
|
|
142
|
-
paymentMethod: 'card',
|
|
143
|
-
provider: 'stripe',
|
|
144
|
-
providerDeclineCode: providerError === null || providerError === void 0 ? void 0 : providerError.decline_code,
|
|
145
|
-
providerErrorCode: providerError === null || providerError === void 0 ? void 0 : providerError.code,
|
|
146
|
-
providerErrorType: providerError === null || providerError === void 0 ? void 0 : providerError.type,
|
|
147
|
-
});
|
|
139
|
+
trackCheckoutFailureShown(Object.assign({ analytics: checkoutAnalytics, checkoutSessionId, errorMessage: message, failureStage: 'card_form', provider: 'stripe' }, errorDetails));
|
|
148
140
|
}
|
|
149
141
|
setError(message);
|
|
150
|
-
|
|
142
|
+
if (message)
|
|
143
|
+
onError === null || onError === void 0 ? void 0 : onError(message, errorDetails);
|
|
144
|
+
else
|
|
145
|
+
onError === null || onError === void 0 ? void 0 : onError(message);
|
|
151
146
|
};
|
|
152
147
|
const selectWalletMethod = () => {
|
|
153
148
|
if (showWalletMethod && !paypalPending && !submitting) {
|
|
@@ -241,7 +236,7 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
241
236
|
});
|
|
242
237
|
if (result.type === 'error') {
|
|
243
238
|
const message = result.error.message || copy.paymentFailed;
|
|
244
|
-
setSharedError(message, false, result.error);
|
|
239
|
+
setSharedError(message, false, normalizeStripeCheckoutError(message, result.error, 'card'));
|
|
245
240
|
finishSubmitting();
|
|
246
241
|
return;
|
|
247
242
|
}
|
|
@@ -284,7 +279,7 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
284
279
|
if (!email)
|
|
285
280
|
setWalletConfirming(false);
|
|
286
281
|
return email;
|
|
287
|
-
}, checkoutAnalytics: checkoutAnalytics, checkoutSessionId: checkoutSessionId, className: 'shared-checkout-v2-express-buttons', confirmEmail: false, customerEmail: resolvedCustomerEmail, customerName: customerName, initialAvailable: initialWalletAvailable, keepInitialAvailableOnReady: initialWalletAvailable === true, onAvailabilityChange: handleWalletAvailabilityChange, onCancel: () => { setWalletConfirming(false); onWalletCancel === null || onWalletCancel === void 0 ? void 0 : onWalletCancel(); }, onError: (message) => setSharedError(message, true), onPaymentInfoSubmitted: onPaymentInfoSubmitted, onPaymentRejected: () => { setWalletConfirming(false); setSelectedMethod('card'); }, onSuccess: () => trackCheckoutSuccess(), onEmbeddedComplete: () => setCompleted(true), onVerificationPending: () => setProviderConfirmed(true), options: expressCheckoutOptions, returnUrl: returnUrl, summaryLabel: expressCheckoutSummaryLabel, supportedCountries: normalizedSupportedCountries, unsupportedCountryMessage: unsupportedCountryMessage }), _jsx("span", { className: 'shared-checkout-v2-sr-only', children: walletAriaLabel })] })] }) : null, _jsxs("div", { hidden: effectiveSelectedMethod !== 'card', className: [
|
|
282
|
+
}, checkoutAnalytics: checkoutAnalytics, checkoutSessionId: checkoutSessionId, className: 'shared-checkout-v2-express-buttons', confirmEmail: false, customerEmail: resolvedCustomerEmail, customerName: customerName, initialAvailable: initialWalletAvailable, keepInitialAvailableOnReady: initialWalletAvailable === true, onAvailabilityChange: handleWalletAvailabilityChange, onCancel: () => { setWalletConfirming(false); onWalletCancel === null || onWalletCancel === void 0 ? void 0 : onWalletCancel(); }, onError: (message, details) => setSharedError(message, true, details), onPaymentInfoSubmitted: onPaymentInfoSubmitted, onPaymentRejected: () => { setWalletConfirming(false); setSelectedMethod('card'); }, onSuccess: () => trackCheckoutSuccess(), onEmbeddedComplete: () => setCompleted(true), onVerificationPending: () => setProviderConfirmed(true), options: expressCheckoutOptions, returnUrl: returnUrl, summaryLabel: expressCheckoutSummaryLabel, supportedCountries: normalizedSupportedCountries, unsupportedCountryMessage: unsupportedCountryMessage }), _jsx("span", { className: 'shared-checkout-v2-sr-only', children: walletAriaLabel })] })] }) : null, _jsxs("div", { hidden: effectiveSelectedMethod !== 'card', className: [
|
|
288
283
|
'shared-checkout-v2-card-panel',
|
|
289
284
|
effectiveSelectedMethod === 'card' ? 'is-visible' : '',
|
|
290
285
|
]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AvailablePaymentMethods, StripeCheckoutExpressCheckoutElementOptions } from '@stripe/stripe-js';
|
|
2
2
|
import { type StripeSubscriptionCheckoutAnalyticsContext } from '../services/checkoutCompletionAnalytics.service.js';
|
|
3
|
+
import { type StripeCheckoutErrorDetails } from '../services/stripeCheckoutError.js';
|
|
3
4
|
export type StripeWalletCheckoutSuccess = {
|
|
4
5
|
checkoutSessionId: string | null;
|
|
5
6
|
};
|
|
@@ -25,7 +26,7 @@ export type StripeCheckoutExpressCheckoutButtonProps = {
|
|
|
25
26
|
onElementMount?: () => void;
|
|
26
27
|
onElementRetry?: () => void;
|
|
27
28
|
onCancel?: () => void;
|
|
28
|
-
onError?: (message: string | null) => void;
|
|
29
|
+
onError?: (message: string | null, details?: StripeCheckoutErrorDetails) => void;
|
|
29
30
|
onPaymentInfoSubmitted?: () => void | Promise<void>;
|
|
30
31
|
onPaymentRejected?: (input: {
|
|
31
32
|
declineCode?: string;
|
|
@@ -6,8 +6,8 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
|
6
6
|
import { ExpressCheckoutElement, useCheckout, } from '@stripe/react-stripe-js/checkout';
|
|
7
7
|
import { queueStripeSubscriptionCheckoutStarted, trackPaidStripeSubscriptionCheckoutCompleted, trackStripeSubscriptionPaymentInfoSubmitted, } from '../services/checkoutCompletionAnalytics.service.js';
|
|
8
8
|
import { getUnsupportedCheckoutCountryMessage, normalizeSupportedCheckoutCountries, } from './checkoutCountries.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { trackCheckoutCanceled, trackCheckoutFailureShown, } from '../../../services/checkoutObservability.service.js';
|
|
10
|
+
import { normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
|
|
11
11
|
const ExpressCheckoutElementWithCancel = ExpressCheckoutElement;
|
|
12
12
|
const buildDefaultOptions = () => ({
|
|
13
13
|
buttonHeight: 55,
|
|
@@ -32,27 +32,6 @@ const buildDefaultOptions = () => ({
|
|
|
32
32
|
paypal: 'never',
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
|
-
const normalizeStripeCheckoutProviderError = (error) => {
|
|
36
|
-
if (!error || typeof error !== 'object') {
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
const record = error;
|
|
40
|
-
const paymentFailed = record.paymentFailed && typeof record.paymentFailed === 'object'
|
|
41
|
-
? record.paymentFailed
|
|
42
|
-
: null;
|
|
43
|
-
return {
|
|
44
|
-
code: typeof record.code === 'string' ? record.code : undefined,
|
|
45
|
-
decline_code: typeof record.decline_code === 'string' ? record.decline_code : undefined,
|
|
46
|
-
paymentFailed: paymentFailed
|
|
47
|
-
? {
|
|
48
|
-
declineCode: typeof paymentFailed.declineCode === 'string'
|
|
49
|
-
? paymentFailed.declineCode
|
|
50
|
-
: undefined,
|
|
51
|
-
}
|
|
52
|
-
: undefined,
|
|
53
|
-
type: typeof record.type === 'string' ? record.type : undefined,
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
35
|
export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAnalytics, checkoutSessionId, returnUrl, confirmEmail = true, customerEmail, className, options, availabilityPaymentMethods = ['applePay'], initialAvailable, keepInitialAvailableOnReady = false, serverUpdateKey, supportedCountries, onServerUpdate, onAvailabilityChange, onElementMount, onElementRetry, onCancel, onError, onPaymentInfoSubmitted, onPaymentRejected, onSuccess, onEmbeddedComplete, onVerificationPending, unsupportedCountryMessage, }) {
|
|
57
36
|
const checkoutState = useCheckout();
|
|
58
37
|
const [completed, setCompleted] = useState(false);
|
|
@@ -129,17 +108,11 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
129
108
|
return false;
|
|
130
109
|
}
|
|
131
110
|
const message = updateResult.error.message || 'Unable to update checkout session.';
|
|
111
|
+
const details = normalizeStripeCheckoutError(message, updateResult.error, paymentMethod);
|
|
132
112
|
if (checkoutAnalytics) {
|
|
133
|
-
trackCheckoutFailureShown({
|
|
134
|
-
analytics: checkoutAnalytics,
|
|
135
|
-
checkoutSessionId,
|
|
136
|
-
errorMessage: message,
|
|
137
|
-
failureStage: 'wallet_session_update',
|
|
138
|
-
paymentMethod,
|
|
139
|
-
provider: 'stripe',
|
|
140
|
-
});
|
|
113
|
+
trackCheckoutFailureShown(Object.assign({ analytics: checkoutAnalytics, checkoutSessionId, errorMessage: message, failureStage: 'wallet_session_update', provider: 'stripe' }, details));
|
|
141
114
|
}
|
|
142
|
-
onError === null || onError === void 0 ? void 0 : onError(message);
|
|
115
|
+
onError === null || onError === void 0 ? void 0 : onError(message, details);
|
|
143
116
|
return false;
|
|
144
117
|
}
|
|
145
118
|
appliedServerUpdateKeyRef.current = normalizedServerUpdateKey;
|
|
@@ -188,23 +161,14 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
188
161
|
paymentMethod }));
|
|
189
162
|
};
|
|
190
163
|
const reportFailure = (message, failureStage, paymentMethod, providerError) => {
|
|
191
|
-
|
|
164
|
+
const details = normalizeStripeCheckoutError(message, providerError, paymentMethod);
|
|
192
165
|
if (checkoutAnalytics) {
|
|
193
|
-
trackCheckoutFailureShown({
|
|
194
|
-
analytics: checkoutAnalytics,
|
|
195
|
-
checkoutSessionId,
|
|
196
|
-
errorMessage: message,
|
|
197
|
-
failureStage,
|
|
198
|
-
paymentMethod,
|
|
199
|
-
provider: 'stripe',
|
|
200
|
-
providerDeclineCode: (_a = providerError === null || providerError === void 0 ? void 0 : providerError.decline_code) !== null && _a !== void 0 ? _a : (_b = providerError === null || providerError === void 0 ? void 0 : providerError.paymentFailed) === null || _b === void 0 ? void 0 : _b.declineCode,
|
|
201
|
-
providerErrorCode: providerError === null || providerError === void 0 ? void 0 : providerError.code,
|
|
202
|
-
providerErrorType: providerError === null || providerError === void 0 ? void 0 : providerError.type,
|
|
203
|
-
});
|
|
166
|
+
trackCheckoutFailureShown(Object.assign({ analytics: checkoutAnalytics, checkoutSessionId, errorMessage: message, failureStage, provider: 'stripe' }, details));
|
|
204
167
|
}
|
|
205
|
-
onError === null || onError === void 0 ? void 0 : onError(isCheckoutEmailError(providerError) ? 'Enter a valid email address to continue.' : message);
|
|
168
|
+
onError === null || onError === void 0 ? void 0 : onError(isCheckoutEmailError(providerError) ? 'Enter a valid email address to continue.' : message, details);
|
|
169
|
+
return details;
|
|
206
170
|
};
|
|
207
|
-
const verifyPaywall = async () => {
|
|
171
|
+
const verifyPaywall = async (paymentMethod) => {
|
|
208
172
|
if (verificationInFlightRef.current || completedRef.current)
|
|
209
173
|
return true;
|
|
210
174
|
verificationInFlightRef.current = true;
|
|
@@ -220,7 +184,7 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
220
184
|
catch (error) {
|
|
221
185
|
const message = error instanceof Error ? error.message : 'Unable to confirm payment';
|
|
222
186
|
setVerificationError(message);
|
|
223
|
-
onError === null || onError === void 0 ? void 0 : onError(message);
|
|
187
|
+
onError === null || onError === void 0 ? void 0 : onError(message, normalizeStripeCheckoutError(message, error, paymentMethod));
|
|
224
188
|
onVerificationPending === null || onVerificationPending === void 0 ? void 0 : onVerificationPending();
|
|
225
189
|
return true;
|
|
226
190
|
}
|
|
@@ -230,7 +194,7 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
230
194
|
}
|
|
231
195
|
};
|
|
232
196
|
const handleConfirm = async (event) => {
|
|
233
|
-
var _a, _b, _c
|
|
197
|
+
var _a, _b, _c;
|
|
234
198
|
if (completedRef.current)
|
|
235
199
|
return;
|
|
236
200
|
// Checkout Sessions omits the Express Checkout onClick callback. Confirmation
|
|
@@ -294,7 +258,7 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
294
258
|
if ((preparedCustomerEmail === null || preparedCustomerEmail === void 0 ? void 0 : preparedCustomerEmail.trim()) !== (customerEmail === null || customerEmail === void 0 ? void 0 : customerEmail.trim())) {
|
|
295
259
|
const message = 'Your email was updated. Please select your payment method again.';
|
|
296
260
|
event.paymentFailed({ reason: 'invalid_payment_data', message });
|
|
297
|
-
onError === null || onError === void 0 ? void 0 : onError(message);
|
|
261
|
+
onError === null || onError === void 0 ? void 0 : onError(message, normalizeStripeCheckoutError(message, undefined, event.expressPaymentType));
|
|
298
262
|
return;
|
|
299
263
|
}
|
|
300
264
|
if (checkoutAnalytics) {
|
|
@@ -306,20 +270,12 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
306
270
|
: {})), { expressCheckoutConfirmEvent: event, redirect: 'if_required' }));
|
|
307
271
|
if (result.type === 'error') {
|
|
308
272
|
const message = result.error.message || 'Wallet checkout failed.';
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
const declineCode = (_f = (_d = providerError.decline_code) !== null && _d !== void 0 ? _d : (_e = providerError.paymentFailed) === null || _e === void 0 ? void 0 : _e.declineCode) !== null && _f !== void 0 ? _f : undefined;
|
|
312
|
-
if (classifyCheckoutFailure({
|
|
313
|
-
errorMessage: message,
|
|
314
|
-
provider: 'stripe',
|
|
315
|
-
providerDeclineCode: declineCode,
|
|
316
|
-
providerErrorCode: providerError.code,
|
|
317
|
-
providerErrorType: providerError.type,
|
|
318
|
-
}) === 'payment_rejection') {
|
|
273
|
+
const details = reportFailure(message, 'wallet_confirmation', event.expressPaymentType, result.error);
|
|
274
|
+
if (details.category === 'payment_rejection') {
|
|
319
275
|
onPaymentRejected === null || onPaymentRejected === void 0 ? void 0 : onPaymentRejected({
|
|
320
|
-
declineCode,
|
|
276
|
+
declineCode: details.providerDeclineCode,
|
|
321
277
|
message,
|
|
322
|
-
paymentMethod:
|
|
278
|
+
paymentMethod: details.paymentMethod,
|
|
323
279
|
});
|
|
324
280
|
}
|
|
325
281
|
event.paymentFailed({ reason: 'fail', message });
|
|
@@ -327,7 +283,7 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
327
283
|
}
|
|
328
284
|
onError === null || onError === void 0 ? void 0 : onError(null);
|
|
329
285
|
if (typeof window !== 'undefined') {
|
|
330
|
-
if (await verifyPaywall())
|
|
286
|
+
if (await verifyPaywall(event.expressPaymentType))
|
|
331
287
|
return;
|
|
332
288
|
await trackCheckoutSuccess();
|
|
333
289
|
window.location.assign(returnUrl);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Stripe } from '@stripe/stripe-js';
|
|
2
2
|
import { type PlatformWalletPaymentMethod } from './walletPlatform.js';
|
|
3
3
|
import { type StripeSubscriptionCheckoutAnalyticsContext } from '../services/checkoutCompletionAnalytics.service.js';
|
|
4
|
+
import { type StripeCheckoutErrorDetails } from '../services/stripeCheckoutError.js';
|
|
4
5
|
export type StripeWalletFirstCheckoutCopy = {
|
|
5
6
|
/** Benefit bullets under the wallet header, per wallet. */
|
|
6
7
|
walletBenefits: Record<PlatformWalletPaymentMethod, readonly string[]>;
|
|
@@ -28,7 +29,7 @@ export type StripeWalletFirstCheckoutProps = {
|
|
|
28
29
|
customerName?: string | null;
|
|
29
30
|
/** The visitor closed the Apple Pay or Google Pay sheet without paying, e.g. to offer a discount. */
|
|
30
31
|
onCancel?: () => void;
|
|
31
|
-
onError?: (message: string | null) => void;
|
|
32
|
+
onError?: (message: string | null, details?: StripeCheckoutErrorDetails) => void;
|
|
32
33
|
/**
|
|
33
34
|
* Called after a paid checkout. Return `true` when the caller has already moved the visitor on
|
|
34
35
|
* (e.g. client-side navigation to the next step); a card payment then skips the `returnUrl` reload.
|
|
@@ -25,6 +25,7 @@ import { stripeWalletFirstCheckoutStyles } from './StripeWalletFirstCheckout.sty
|
|
|
25
25
|
import { queueStripeSubscriptionCheckoutStarted, trackPaidStripeSubscriptionCheckoutCompleted, trackStripeCheckoutShown, trackStripeSubscriptionPaymentInfoSubmitted, } from '../services/checkoutCompletionAnalytics.service.js';
|
|
26
26
|
import { trackCheckoutFailureShown } from '../../../services/checkoutObservability.service.js';
|
|
27
27
|
import { useCheckoutShownOnce } from '../hooks/useCheckoutShownOnce.js';
|
|
28
|
+
import { normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
|
|
28
29
|
const appearance = {
|
|
29
30
|
labels: 'above',
|
|
30
31
|
variables: {
|
|
@@ -102,16 +103,16 @@ function StripeWalletFirstCheckoutForm({ amountCents, checkoutAnalytics, checkou
|
|
|
102
103
|
const timer = window.setTimeout(() => window.dispatchEvent(new Event('resize')), 0);
|
|
103
104
|
return () => window.clearTimeout(timer);
|
|
104
105
|
}, [selected]);
|
|
105
|
-
const showError = (message,
|
|
106
|
+
const showError = (message, details, alreadyTracked = false) => {
|
|
107
|
+
const errorDetails = message ? details !== null && details !== void 0 ? details : normalizeStripeCheckoutError(message, undefined, 'card') : undefined;
|
|
106
108
|
if (message && checkoutAnalytics && !alreadyTracked) {
|
|
107
|
-
trackCheckoutFailureShown({
|
|
108
|
-
analytics: checkoutAnalytics, checkoutSessionId, errorMessage: message,
|
|
109
|
-
failureStage: 'card_form', paymentMethod: 'card', provider: 'stripe',
|
|
110
|
-
providerDeclineCode: providerError === null || providerError === void 0 ? void 0 : providerError.decline_code, providerErrorCode: providerError === null || providerError === void 0 ? void 0 : providerError.code, providerErrorType: providerError === null || providerError === void 0 ? void 0 : providerError.type,
|
|
111
|
-
});
|
|
109
|
+
trackCheckoutFailureShown(Object.assign({ analytics: checkoutAnalytics, checkoutSessionId, errorMessage: message, failureStage: 'card_form', provider: 'stripe' }, errorDetails));
|
|
112
110
|
}
|
|
113
111
|
setError(message);
|
|
114
|
-
|
|
112
|
+
if (message)
|
|
113
|
+
onError === null || onError === void 0 ? void 0 : onError(message, errorDetails);
|
|
114
|
+
else
|
|
115
|
+
onError === null || onError === void 0 ? void 0 : onError(message);
|
|
115
116
|
};
|
|
116
117
|
/** Resolves true when the caller's onSuccess handled the navigation itself. */
|
|
117
118
|
const trackSuccess = async (embedded = false) => {
|
|
@@ -161,7 +162,8 @@ function StripeWalletFirstCheckoutForm({ amountCents, checkoutAnalytics, checkou
|
|
|
161
162
|
}
|
|
162
163
|
const result = await checkout.confirm({ redirect: 'if_required' });
|
|
163
164
|
if (result.type === 'error') {
|
|
164
|
-
|
|
165
|
+
const message = result.error.message || copy.paymentFailed;
|
|
166
|
+
showError(message, normalizeStripeCheckoutError(message, result.error, 'card'));
|
|
165
167
|
submitInFlight.current = false;
|
|
166
168
|
setSubmitting(false);
|
|
167
169
|
return;
|
|
@@ -181,7 +183,7 @@ function StripeWalletFirstCheckoutForm({ amountCents, checkoutAnalytics, checkou
|
|
|
181
183
|
// where the customer paid, until the success screen takes over.
|
|
182
184
|
const paymentStatus = completed ? copy.paymentConfirmed : providerConfirmed ? copy.verifyingPayment : null;
|
|
183
185
|
const locked = Boolean(paymentStatus) && !error;
|
|
184
|
-
return (_jsx(CheckoutLayout, { copy: copy, wallet: wallet, selected: selected, onSelect: onSelect, disabled: submitting || walletConfirming || locked, style: style, walletNote: selected === 'wallet' ? paymentStatus : null, walletSlot: _jsxs(_Fragment, { children: [_jsx("div", { className: 'wfc-wallet-button', "data-ready": walletAvailable === true, children: _jsx(StripeCheckoutExpressCheckoutButton, { amountCents: amountCents, availabilityPaymentMethods: [wallet], beforeConfirm: async () => { setWalletConfirming(true); return customerEmail || null; }, checkoutAnalytics: checkoutAnalytics, checkoutSessionId: checkoutSessionId, confirmEmail: false, customerEmail: customerEmail, customerName: customerName, onAvailabilityChange: setWalletAvailable, onCancel: () => { setWalletConfirming(false); onCancel === null || onCancel === void 0 ? void 0 : onCancel(); }, onEmbeddedComplete: () => setCompleted(true), onError: message => { setWalletConfirming(false); showError(message,
|
|
186
|
+
return (_jsx(CheckoutLayout, { copy: copy, wallet: wallet, selected: selected, onSelect: onSelect, disabled: submitting || walletConfirming || locked, style: style, walletNote: selected === 'wallet' ? paymentStatus : null, walletSlot: _jsxs(_Fragment, { children: [_jsx("div", { className: 'wfc-wallet-button', "data-ready": walletAvailable === true, children: _jsx(StripeCheckoutExpressCheckoutButton, { amountCents: amountCents, availabilityPaymentMethods: [wallet], beforeConfirm: async () => { setWalletConfirming(true); return customerEmail || null; }, checkoutAnalytics: checkoutAnalytics, checkoutSessionId: checkoutSessionId, confirmEmail: false, customerEmail: customerEmail, customerName: customerName, onAvailabilityChange: setWalletAvailable, onCancel: () => { setWalletConfirming(false); onCancel === null || onCancel === void 0 ? void 0 : onCancel(); }, onEmbeddedComplete: () => setCompleted(true), onError: (message, details) => { setWalletConfirming(false); showError(message, details, true); }, onPaymentRejected: () => { setWalletConfirming(false); onSelect('card'); }, onSuccess: async () => { await trackSuccess(); }, onVerificationPending: () => setProviderConfirmed(true), options: expressOptions, returnUrl: returnUrl, summaryLabel: summaryLabel }) }), walletAvailable === null ? _jsx("span", { className: 'wfc-progress wfc-progress--overlay', role: 'status', "aria-label": copy.processingLabel }) : null, walletAvailable === false ? _jsx("p", { className: 'wfc-wallet-unavailable', role: 'status', children: copy.walletUnavailableNote.replace('{wallet}', copy.walletLabels[wallet]) }) : null] }), cardBody: _jsxs("form", { className: 'wfc-card-form', onSubmit: event => void submitCard(event), children: [_jsx(PaymentElement, { options: paymentElementOptions, onChange: event => { setPaymentElementComplete(event.complete); if (!event.empty)
|
|
185
187
|
onCardEngaged(); }, onReady: () => setPaymentElementReady(true) }), _jsx("button", { type: 'submit', className: 'wfc-submit', disabled: locked || submitting || !paymentElementReady, "aria-live": 'polite', children: locked && paymentStatus ? paymentStatus : submitting ? copy.processingLabel : copy.cardSubmitLabel }), _jsx("p", { className: 'wfc-secure', children: copy.secureNote })] }), footer: error ? _jsx("p", { className: 'wfc-error', role: 'alert', children: error }) : null }));
|
|
186
188
|
}
|
|
187
189
|
/** Shared by the loading and live states so switching between them moves nothing. */
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CheckoutFailureCategory } from '../../../services/checkoutObservability.service.js';
|
|
2
|
+
import { type AnalyticsPaymentMethod } from '../../../services/paymentMethodAnalytics.service.js';
|
|
3
|
+
export type StripeCheckoutErrorDetails = {
|
|
4
|
+
category: CheckoutFailureCategory;
|
|
5
|
+
paymentMethod?: AnalyticsPaymentMethod;
|
|
6
|
+
providerDeclineCode?: string;
|
|
7
|
+
providerErrorCode?: string;
|
|
8
|
+
providerErrorType?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function normalizeStripeCheckoutError(message: string, error?: unknown, paymentMethod?: unknown): StripeCheckoutErrorDetails;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { classifyCheckoutFailure } from '../../../services/checkoutObservability.service.js';
|
|
2
|
+
import { toAnalyticsPaymentMethod } from '../../../services/paymentMethodAnalytics.service.js';
|
|
3
|
+
const asRecord = (value) => value && typeof value === 'object' ? value : {};
|
|
4
|
+
const asCode = (value) => typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
5
|
+
export function normalizeStripeCheckoutError(message, error, paymentMethod) {
|
|
6
|
+
var _a;
|
|
7
|
+
const record = asRecord(error);
|
|
8
|
+
const providerFields = {
|
|
9
|
+
providerDeclineCode: (_a = asCode(record.decline_code)) !== null && _a !== void 0 ? _a : asCode(asRecord(record.paymentFailed).declineCode),
|
|
10
|
+
providerErrorCode: asCode(record.code),
|
|
11
|
+
providerErrorType: asCode(record.type),
|
|
12
|
+
};
|
|
13
|
+
return Object.assign(Object.assign({}, providerFields), { category: classifyCheckoutFailure(Object.assign({ errorMessage: message, provider: 'stripe' }, providerFields)), paymentMethod: toAnalyticsPaymentMethod(paymentMethod) });
|
|
14
|
+
}
|