@funnelsgrove/payments 0.15.0 → 0.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/providers/stripe/components/StripeCheckoutExpressCheckoutButton.js +27 -1
- package/dist/providers/stripe/hooks/useStripeOneTimeCheckoutSession.js +1 -0
- package/dist/providers/stripe/hooks/useStripeSubscriptionCheckoutSession.js +2 -0
- package/dist/providers/stripe/services/stripeCheckoutFailure.d.ts +1 -0
- package/dist/providers/stripe/services/stripeCheckoutFailure.js +3 -4
- package/dist/services/checkoutObservability.service.d.ts +1 -0
- package/dist/services/checkoutObservability.service.js +6 -1
- package/package.json +3 -3
|
@@ -53,6 +53,15 @@ const normalizeStripeCheckoutProviderError = (error) => {
|
|
|
53
53
|
};
|
|
54
54
|
export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAnalytics, checkoutSessionId, returnUrl, confirmEmail = true, customerEmail, className, options, availabilityPaymentMethods = ['applePay'], initialAvailable, keepInitialAvailableOnReady = false, serverUpdateKey, supportedCountries, onServerUpdate, onAvailabilityChange, onCancel, onError, onPaymentInfoSubmitted, onPaymentRejected, onSuccess, unsupportedCountryMessage, }) {
|
|
55
55
|
const checkoutState = useCheckout();
|
|
56
|
+
const [loadRetry, setLoadRetry] = useState(0);
|
|
57
|
+
const loadRetryUsedRef = useRef(false);
|
|
58
|
+
const walletReadyRef = useRef(false);
|
|
59
|
+
const loadRetryTimerRef = useRef(null);
|
|
60
|
+
useEffect(() => () => {
|
|
61
|
+
if (loadRetryTimerRef.current !== null) {
|
|
62
|
+
clearTimeout(loadRetryTimerRef.current);
|
|
63
|
+
}
|
|
64
|
+
}, []);
|
|
56
65
|
const appliedServerUpdateKeyRef = useRef('');
|
|
57
66
|
const [appliedServerUpdateKey, setAppliedServerUpdateKey] = useState('');
|
|
58
67
|
const serverUpdatePromiseRef = useRef(null);
|
|
@@ -312,10 +321,27 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
312
321
|
]
|
|
313
322
|
.filter(Boolean)
|
|
314
323
|
.join(' '), children: _jsx(ExpressCheckoutElementWithCancel, { options: resolvedOptions, onCancel: handleCancel, onClick: handleClick, onConfirm: (event) => void handleConfirm(event), onLoadError: ({ error }) => {
|
|
324
|
+
if (loadRetryTimerRef.current !== null) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (!walletReadyRef.current && !loadRetryUsedRef.current) {
|
|
328
|
+
loadRetryUsedRef.current = true;
|
|
329
|
+
// Replace only the failed Element, retaining the Checkout Session.
|
|
330
|
+
loadRetryTimerRef.current = setTimeout(() => {
|
|
331
|
+
loadRetryTimerRef.current = null;
|
|
332
|
+
setLoadRetry(1);
|
|
333
|
+
}, 1000);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
315
336
|
setWalletAvailable(false);
|
|
316
337
|
onAvailabilityChange === null || onAvailabilityChange === void 0 ? void 0 : onAvailabilityChange(false);
|
|
317
338
|
reportFailure(error.message || 'Unable to load wallet checkout.', 'wallet_load');
|
|
318
339
|
}, onReady: ({ availablePaymentMethods: availablePaymentMethodsMap }) => {
|
|
340
|
+
walletReadyRef.current = true;
|
|
341
|
+
if (loadRetryTimerRef.current !== null) {
|
|
342
|
+
clearTimeout(loadRetryTimerRef.current);
|
|
343
|
+
loadRetryTimerRef.current = null;
|
|
344
|
+
}
|
|
319
345
|
const available = Boolean(availabilityPaymentMethods.some((paymentMethod) => availablePaymentMethodsMap === null || availablePaymentMethodsMap === void 0 ? void 0 : availablePaymentMethodsMap[paymentMethod]));
|
|
320
346
|
const resolvedAvailable = available || (keepInitialAvailableOnReady && initialAvailable === true);
|
|
321
347
|
setWalletAvailable(resolvedAvailable);
|
|
@@ -323,7 +349,7 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
323
349
|
if (resolvedAvailable) {
|
|
324
350
|
onError === null || onError === void 0 ? void 0 : onError(null);
|
|
325
351
|
}
|
|
326
|
-
} }) })), _jsx("style", { children: stripeExpressCheckoutButtonStyles })] }));
|
|
352
|
+
} }, loadRetry) })), _jsx("style", { children: stripeExpressCheckoutButtonStyles })] }));
|
|
327
353
|
}
|
|
328
354
|
const stripeExpressCheckoutButtonStyles = `
|
|
329
355
|
.stripe-express-checkout-button {
|
|
@@ -239,6 +239,7 @@ export function useStripeOneTimeCheckoutSession({ runtimeConfigRevisionId, payme
|
|
|
239
239
|
paymentMethod: options.paymentMethod,
|
|
240
240
|
provider: 'stripe',
|
|
241
241
|
providerErrorCode: failure.providerErrorCode,
|
|
242
|
+
checkoutRequestId: failure.checkoutRequestId,
|
|
242
243
|
});
|
|
243
244
|
}
|
|
244
245
|
setError(message);
|
|
@@ -259,6 +259,7 @@ export function useStripeSubscriptionCheckoutSession({ checkoutMode, analyticsMe
|
|
|
259
259
|
paymentMethod: options.paymentMethod,
|
|
260
260
|
provider: 'stripe',
|
|
261
261
|
providerErrorCode: failure.providerErrorCode,
|
|
262
|
+
checkoutRequestId: failure.checkoutRequestId,
|
|
262
263
|
});
|
|
263
264
|
}
|
|
264
265
|
setError(message);
|
|
@@ -380,6 +381,7 @@ export function useStripeSubscriptionCheckoutSession({ checkoutMode, analyticsMe
|
|
|
380
381
|
failureStage: 'checkout_session_update',
|
|
381
382
|
provider: 'stripe',
|
|
382
383
|
providerErrorCode: failure.providerErrorCode,
|
|
384
|
+
checkoutRequestId: failure.checkoutRequestId,
|
|
383
385
|
});
|
|
384
386
|
}
|
|
385
387
|
setError(message);
|
|
@@ -14,9 +14,8 @@ export const describeStripeCheckoutFailure = (error) => {
|
|
|
14
14
|
: rawMessage === 'Internal server error'
|
|
15
15
|
? 'Unable to initialize checkout. Stripe settings may be missing for this funnel.'
|
|
16
16
|
: rawMessage;
|
|
17
|
-
return {
|
|
18
|
-
errorCode,
|
|
17
|
+
return Object.assign(Object.assign({}, (error instanceof FunnelSdkHttpError && error.checkoutRequestId
|
|
18
|
+
? { checkoutRequestId: error.checkoutRequestId } : {})), { errorCode,
|
|
19
19
|
message,
|
|
20
|
-
providerErrorCode
|
|
21
|
-
};
|
|
20
|
+
providerErrorCode });
|
|
22
21
|
};
|
|
@@ -23,6 +23,7 @@ type CheckoutObservabilityInput = {
|
|
|
23
23
|
provider: 'solidgate' | 'stripe';
|
|
24
24
|
};
|
|
25
25
|
type CheckoutFailureShownInput = CheckoutObservabilityInput & {
|
|
26
|
+
checkoutRequestId?: string;
|
|
26
27
|
errorCode?: string | null;
|
|
27
28
|
errorMessage: string;
|
|
28
29
|
providerDeclineCode?: string | null;
|
|
@@ -96,6 +96,7 @@ const reportCheckoutObservability = (input) => {
|
|
|
96
96
|
: buildSdkHeaders({ 'Content-Type': 'application/json' }),
|
|
97
97
|
body: JSON.stringify({
|
|
98
98
|
checkoutSessionId: input.checkoutSessionId || undefined,
|
|
99
|
+
checkoutRequestId: input.checkoutRequestId,
|
|
99
100
|
environment,
|
|
100
101
|
errorCode: input.errorCode,
|
|
101
102
|
errorMessage: input.errorMessage,
|
|
@@ -134,7 +135,7 @@ const resolveErrorCode = (message, requestedCode) => {
|
|
|
134
135
|
const emitCheckoutObservability = (eventType, input, failure) => {
|
|
135
136
|
var _a, _b, _c, _d;
|
|
136
137
|
const paymentMethod = toAnalyticsPaymentMethod(input.paymentMethod);
|
|
137
|
-
const metadata = Object.assign(Object.assign({}, ((_a = input.analytics.metadata) !== null && _a !== void 0 ? _a : {})), { checkout_session_id: ((_b = input.checkoutSessionId) === null || _b === void 0 ? void 0 : _b.trim()) || undefined, checkout_failure_stage: input.failureStage, payment_provider: input.provider, payment_method: paymentMethod || undefined, error_code: failure === null || failure === void 0 ? void 0 : failure.errorCode, error_message: failure === null || failure === void 0 ? void 0 : failure.errorMessage, checkout_failure_category: (_c = failure === null || failure === void 0 ? void 0 : failure.failureCategory) !== null && _c !== void 0 ? _c : (eventType === 'checkout_canceled' ? 'user_canceled' : undefined), provider_decline_code: failure === null || failure === void 0 ? void 0 : failure.providerDeclineCode, provider_error_code: failure === null || failure === void 0 ? void 0 : failure.providerErrorCode, provider_error_type: failure === null || failure === void 0 ? void 0 : failure.providerErrorType });
|
|
138
|
+
const metadata = Object.assign(Object.assign({}, ((_a = input.analytics.metadata) !== null && _a !== void 0 ? _a : {})), { checkout_session_id: ((_b = input.checkoutSessionId) === null || _b === void 0 ? void 0 : _b.trim()) || undefined, checkout_request_id: failure === null || failure === void 0 ? void 0 : failure.checkoutRequestId, checkout_failure_stage: input.failureStage, payment_provider: input.provider, payment_method: paymentMethod || undefined, error_code: failure === null || failure === void 0 ? void 0 : failure.errorCode, error_message: failure === null || failure === void 0 ? void 0 : failure.errorMessage, checkout_failure_category: (_c = failure === null || failure === void 0 ? void 0 : failure.failureCategory) !== null && _c !== void 0 ? _c : (eventType === 'checkout_canceled' ? 'user_canceled' : undefined), provider_decline_code: failure === null || failure === void 0 ? void 0 : failure.providerDeclineCode, provider_error_code: failure === null || failure === void 0 ? void 0 : failure.providerErrorCode, provider_error_type: failure === null || failure === void 0 ? void 0 : failure.providerErrorType });
|
|
138
139
|
const eventId = publicAnalyticsSdk.track({
|
|
139
140
|
eventType,
|
|
140
141
|
environment: input.analytics.environment,
|
|
@@ -151,6 +152,7 @@ const emitCheckoutObservability = (eventType, input, failure) => {
|
|
|
151
152
|
void reportCheckoutObservability({
|
|
152
153
|
analytics: input.analytics,
|
|
153
154
|
checkoutSessionId: input.checkoutSessionId,
|
|
155
|
+
checkoutRequestId: failure === null || failure === void 0 ? void 0 : failure.checkoutRequestId,
|
|
154
156
|
errorCode: failure === null || failure === void 0 ? void 0 : failure.errorCode,
|
|
155
157
|
errorMessage: failure === null || failure === void 0 ? void 0 : failure.errorMessage,
|
|
156
158
|
failureCategory: (_d = failure === null || failure === void 0 ? void 0 : failure.failureCategory) !== null && _d !== void 0 ? _d : (eventType === 'checkout_canceled' ? 'user_canceled' : undefined),
|
|
@@ -184,6 +186,9 @@ export const trackCheckoutFailureShown = (input) => {
|
|
|
184
186
|
});
|
|
185
187
|
const paymentRejected = failureCategory === 'payment_rejection';
|
|
186
188
|
return emitCheckoutObservability(paymentRejected ? 'checkout_payment_rejected' : 'checkout_failure_shown', input, {
|
|
189
|
+
checkoutRequestId: input.checkoutRequestId
|
|
190
|
+
&& /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(input.checkoutRequestId)
|
|
191
|
+
? input.checkoutRequestId : undefined,
|
|
187
192
|
errorCode: paymentRejected
|
|
188
193
|
? providerDeclineCode || providerErrorCode || 'payment_rejected'
|
|
189
194
|
: resolveErrorCode(errorMessage, input.errorCode),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funnelsgrove/payments",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"test:run": "vitest run --passWithNoTests"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@funnelsgrove/analytics": "^0.1.
|
|
36
|
-
"@funnelsgrove/runtime": "
|
|
35
|
+
"@funnelsgrove/analytics": "^0.1.100",
|
|
36
|
+
"@funnelsgrove/runtime": "0.14.0",
|
|
37
37
|
"@solidgate/react-sdk": "1.34.0",
|
|
38
38
|
"@stripe/react-stripe-js": "^5.6.0",
|
|
39
39
|
"@stripe/stripe-js": "^8.7.0",
|