@funnelsgrove/payments 0.1.28 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/shared/SharedStripeCheckoutV2Dialog.js +5 -2
- package/dist/config/billing.config.d.ts +1 -0
- package/dist/providers/stripe/useStripeSubscriptionCheckoutSession.js +6 -11
- package/dist/services/stripe.service.d.ts +1 -0
- package/dist/services/stripe.service.js +13 -0
- package/package.json +1 -1
|
@@ -217,7 +217,10 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
217
217
|
setSubmitting(false);
|
|
218
218
|
return;
|
|
219
219
|
}
|
|
220
|
-
const result = await checkoutState.checkout.confirm(
|
|
220
|
+
const result = await checkoutState.checkout.confirm({
|
|
221
|
+
email: syncedEmail || undefined,
|
|
222
|
+
redirect: 'if_required',
|
|
223
|
+
});
|
|
221
224
|
if (result.type === 'error') {
|
|
222
225
|
const message = result.error.message || 'Payment failed.';
|
|
223
226
|
setSharedError(message);
|
|
@@ -257,7 +260,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
257
260
|
effectiveSelectedMethod === 'wallet' ? 'is-visible' : '',
|
|
258
261
|
]
|
|
259
262
|
.filter(Boolean)
|
|
260
|
-
.join(' '), children: [_jsxs("p", { className: 'shared-checkout-v2-secure-pill', children: [_jsx(SecurityLockIcon, { className: 'shared-checkout-v2-secure-pill-icon' }), secureLabel] }), _jsxs("div", { className: 'shared-checkout-v2-wallet-shell', "aria-label": walletAriaLabel, children: [_jsx(StripeCheckoutExpressCheckoutButton, { amountCents: amountCents, availabilityPaymentMethods: walletPaymentMethods, beforeConfirm: ensureCustomerEmail, className: 'shared-checkout-v2-express-buttons', confirmEmail:
|
|
263
|
+
.join(' '), children: [_jsxs("p", { className: 'shared-checkout-v2-secure-pill', children: [_jsx(SecurityLockIcon, { className: 'shared-checkout-v2-secure-pill-icon' }), secureLabel] }), _jsxs("div", { className: 'shared-checkout-v2-wallet-shell', "aria-label": walletAriaLabel, children: [_jsx(StripeCheckoutExpressCheckoutButton, { amountCents: amountCents, availabilityPaymentMethods: walletPaymentMethods, beforeConfirm: ensureCustomerEmail, className: 'shared-checkout-v2-express-buttons', confirmEmail: Boolean(resolvedCustomerEmail), customerEmail: resolvedCustomerEmail, customerName: customerName, initialAvailable: initialWalletAvailable, keepInitialAvailableOnReady: initialWalletAvailable === true, onAvailabilityChange: handleWalletAvailabilityChange, onError: setSharedError, onSuccess: onSuccess, options: expressCheckoutOptions, returnUrl: returnUrl, summaryLabel: expressCheckoutSummaryLabel }), _jsx("span", { className: 'shared-checkout-v2-sr-only', children: walletAriaLabel })] })] }), _jsxs("div", { hidden: effectiveSelectedMethod !== 'card', className: [
|
|
261
264
|
'shared-checkout-v2-card-panel',
|
|
262
265
|
effectiveSelectedMethod === 'card' ? 'is-visible' : '',
|
|
263
266
|
]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useCallback,
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
|
|
3
3
|
import { createEmptyCheckoutPreparationLoading, } from '../paymentProvider.types.js';
|
|
4
4
|
import { createStripeSubscriptionCheckout, getStripePromise, isStripeConfigured, updateStripeSubscriptionCheckoutPlan, } from '../../services/stripe.service.js';
|
|
5
5
|
const getFriendlyStripeCheckoutError = (error) => {
|
|
@@ -23,7 +23,6 @@ export function useStripeSubscriptionCheckoutSession({ checkoutMode, analyticsMe
|
|
|
23
23
|
const [loading, setLoading] = useState(createEmptyCheckoutPreparationLoading);
|
|
24
24
|
const [runtimeStripePublishableKey, setRuntimeStripePublishableKey] = useState(null);
|
|
25
25
|
const creatingIntentRef = useRef(null);
|
|
26
|
-
const lastIntentKeyRef = useRef(null);
|
|
27
26
|
const requestIdRef = useRef(0);
|
|
28
27
|
const runtimeConfigSignature = [
|
|
29
28
|
normalizeRuntimeConfigValue(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.apiBaseUrl),
|
|
@@ -31,6 +30,8 @@ export function useStripeSubscriptionCheckoutSession({ checkoutMode, analyticsMe
|
|
|
31
30
|
normalizeRuntimeConfigValue(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelVersionId),
|
|
32
31
|
normalizeRuntimeConfigValue(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelSdkPublishableKey),
|
|
33
32
|
].join('|');
|
|
33
|
+
const customerEmailSignature = normalizeRuntimeConfigValue(customerEmail);
|
|
34
|
+
const userIdSignature = normalizeRuntimeConfigValue(userId);
|
|
34
35
|
const configured = enabled &&
|
|
35
36
|
(isStripeConfigured(checkoutMode) ||
|
|
36
37
|
Boolean(normalizeRuntimeConfigValue(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelSdkPublishableKey)));
|
|
@@ -38,6 +39,8 @@ export function useStripeSubscriptionCheckoutSession({ checkoutMode, analyticsMe
|
|
|
38
39
|
'stripe',
|
|
39
40
|
checkoutMode,
|
|
40
41
|
runtimeConfigSignature,
|
|
42
|
+
customerEmailSignature,
|
|
43
|
+
userIdSignature,
|
|
41
44
|
(couponId === null || couponId === void 0 ? void 0 : couponId.trim()) || '',
|
|
42
45
|
returnUrl.trim(),
|
|
43
46
|
].join('|');
|
|
@@ -76,15 +79,7 @@ export function useStripeSubscriptionCheckoutSession({ checkoutMode, analyticsMe
|
|
|
76
79
|
setRuntimeStripePublishableKey(null);
|
|
77
80
|
setError(null);
|
|
78
81
|
}, [clearActiveCheckoutSession, setError]);
|
|
79
|
-
|
|
80
|
-
if (lastIntentKeyRef.current === null) {
|
|
81
|
-
lastIntentKeyRef.current = intentKey;
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (lastIntentKeyRef.current === intentKey) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
lastIntentKeyRef.current = intentKey;
|
|
82
|
+
useEffect(() => {
|
|
88
83
|
reset();
|
|
89
84
|
}, [intentKey, reset]);
|
|
90
85
|
const setSourceLoading = useCallback((source, value) => {
|
|
@@ -14,6 +14,7 @@ export type PaywallPlan = {
|
|
|
14
14
|
perDayAmount: string;
|
|
15
15
|
perDayLabel: string;
|
|
16
16
|
amountCents: number;
|
|
17
|
+
analyticsPurchaseValue?: number;
|
|
17
18
|
comparison?: BillingFallbackPlanConfig['comparison'];
|
|
18
19
|
checkoutOriginalAmountCents?: number;
|
|
19
20
|
checkoutSummaryLabel?: string;
|
|
@@ -68,6 +68,17 @@ const asPositiveIntOrNull = (value) => {
|
|
|
68
68
|
}
|
|
69
69
|
return Math.round(numeric);
|
|
70
70
|
};
|
|
71
|
+
const asNonNegativeNumberOrNull = (value) => {
|
|
72
|
+
const numeric = typeof value === 'number'
|
|
73
|
+
? value
|
|
74
|
+
: typeof value === 'string' && value.trim()
|
|
75
|
+
? Number(value.trim())
|
|
76
|
+
: null;
|
|
77
|
+
if (numeric === null || !Number.isFinite(numeric) || numeric < 0) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return Math.round(numeric * 100) / 100;
|
|
81
|
+
};
|
|
71
82
|
const asBillingPlanIntervalOrNull = (value) => {
|
|
72
83
|
var _a;
|
|
73
84
|
const normalized = (_a = asTrimmedStringOrNull(value)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
@@ -230,6 +241,7 @@ const toRemoteProjectBillingPlan = (rawPlan) => {
|
|
|
230
241
|
};
|
|
231
242
|
};
|
|
232
243
|
const toPlanFromRemoteProjectPlan = (rawPlan, options, planIdOverride) => {
|
|
244
|
+
var _a;
|
|
233
245
|
const planId = (planIdOverride === null || planIdOverride === void 0 ? void 0 : planIdOverride.trim()) || rawPlan.id || rawPlan.key || rawPlan.providerPlanId;
|
|
234
246
|
if (!planId) {
|
|
235
247
|
return null;
|
|
@@ -266,6 +278,7 @@ const toPlanFromRemoteProjectPlan = (rawPlan, options, planIdOverride) => {
|
|
|
266
278
|
perDayAmount,
|
|
267
279
|
perDayLabel: 'per day',
|
|
268
280
|
amountCents: amountMinor,
|
|
281
|
+
analyticsPurchaseValue: (_a = asNonNegativeNumberOrNull(metadata.analyticsPurchaseValue)) !== null && _a !== void 0 ? _a : undefined,
|
|
269
282
|
comparison: intervalDays
|
|
270
283
|
? {
|
|
271
284
|
perDay: `${perDayAmount}/day`,
|