@funnelsgrove/payments 0.1.42 → 0.1.44
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.d.ts +2 -0
- package/dist/components/shared/SharedStripeCheckoutV2Dialog.js +20 -3
- package/dist/components/shared/StripeCheckoutExpressCheckoutButton.d.ts +3 -1
- package/dist/components/shared/StripeCheckoutExpressCheckoutButton.js +14 -1
- package/dist/components/shared/checkoutCountries.d.ts +7 -0
- package/dist/components/shared/checkoutCountries.js +25 -0
- package/dist/services/stripe.service.d.ts +1 -1
- package/dist/services/stripe.service.js +11 -3
- package/package.json +1 -1
|
@@ -42,10 +42,12 @@ export type SharedStripeCheckoutV2DialogProps = {
|
|
|
42
42
|
satisfactionPercent: string;
|
|
43
43
|
stripePromise: Promise<Stripe | null>;
|
|
44
44
|
summaryLabel?: string;
|
|
45
|
+
supportedCountries?: readonly string[];
|
|
45
46
|
themeColor: string;
|
|
46
47
|
title: string;
|
|
47
48
|
totalLabel: string;
|
|
48
49
|
totalValue: string;
|
|
50
|
+
unsupportedCountryMessage?: string;
|
|
49
51
|
walletButtonLabel: string;
|
|
50
52
|
originalPriceLabel: string;
|
|
51
53
|
originalPriceValue: string;
|
|
@@ -15,6 +15,7 @@ import { useEffect, useMemo, useState, } from 'react';
|
|
|
15
15
|
import { CheckoutProvider, PaymentElement, useCheckout, } from '@stripe/react-stripe-js/checkout';
|
|
16
16
|
import { PaymentBrandMark, SecurityLockIcon } from './CheckoutBrandAssets.js';
|
|
17
17
|
import { StripeCheckoutExpressCheckoutButton } from './StripeCheckoutExpressCheckoutButton.js';
|
|
18
|
+
import { getUnsupportedCheckoutCountryMessage, normalizeSupportedCheckoutCountries, } from './checkoutCountries.js';
|
|
18
19
|
import { isInactiveCheckoutSessionError } from '../../providers/stripe/useStripeSubscriptionCheckoutSession.js';
|
|
19
20
|
import { getStripeWalletPaymentMethodOrder, usePlatformWalletPaymentMethods, } from './walletPlatform.js';
|
|
20
21
|
import { trackPaidStripeSubscriptionCheckoutCompleted, trackStripeSubscriptionCheckoutStarted, } from '../../services/checkoutCompletionAnalytics.service.js';
|
|
@@ -53,7 +54,7 @@ function getFriendlyCardErrorMessage(error) {
|
|
|
53
54
|
? error.message
|
|
54
55
|
: 'Payment failed. Please review your card details and try again.';
|
|
55
56
|
}
|
|
56
|
-
function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel, closeAriaLabel, countdownLabel, checkoutAnalytics, checkoutSessionId, customerEmail, customerEmailEditable = false, customerEmailLabel = 'Email', customerEmailPlaceholder = 'Enter your email', customerEmailInvalidMessage = 'Enter a valid email address.', customerName, discountAmountLabel, discountLabel, discountPercent, initialWalletAvailable, onClose, onCustomerEmailChange, onCustomerEmailCommit, onError, onInactiveCheckoutSession, onPaymentInfoSubmitted, onSuccess, paymentMethodLabels = defaultPaymentMethodLabels, promoActive, processingLabel, promoCode, promoCodeLabel, remainingSeconds, returnUrl, savedLabel, secureLabel, satisfactionLabel, satisfactionPercent, summaryLabel, themeColor, title, totalLabel, totalValue, walletButtonLabel, originalPriceLabel, originalPriceValue, }) {
|
|
57
|
+
function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel, closeAriaLabel, countdownLabel, checkoutAnalytics, checkoutSessionId, customerEmail, customerEmailEditable = false, customerEmailLabel = 'Email', customerEmailPlaceholder = 'Enter your email', customerEmailInvalidMessage = 'Enter a valid email address.', customerName, discountAmountLabel, discountLabel, discountPercent, initialWalletAvailable, onClose, onCustomerEmailChange, onCustomerEmailCommit, onError, onInactiveCheckoutSession, onPaymentInfoSubmitted, onSuccess, paymentMethodLabels = defaultPaymentMethodLabels, promoActive, processingLabel, promoCode, promoCodeLabel, remainingSeconds, returnUrl, savedLabel, secureLabel, satisfactionLabel, satisfactionPercent, summaryLabel, supportedCountries, themeColor, title, totalLabel, totalValue, unsupportedCountryMessage, walletButtonLabel, originalPriceLabel, originalPriceValue, }) {
|
|
57
58
|
const checkoutState = useCheckout();
|
|
58
59
|
const walletPaymentMethods = usePlatformWalletPaymentMethods();
|
|
59
60
|
const [selectedMethod, setSelectedMethod] = useState('wallet');
|
|
@@ -63,8 +64,10 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
63
64
|
: walletAvailable;
|
|
64
65
|
const [submitting, setSubmitting] = useState(false);
|
|
65
66
|
const [error, setError] = useState(null);
|
|
67
|
+
const [billingCountry, setBillingCountry] = useState(null);
|
|
66
68
|
const initialCustomerEmail = (customerEmail === null || customerEmail === void 0 ? void 0 : customerEmail.trim()) || '';
|
|
67
69
|
const [emailDraft, setEmailDraft] = useState(initialCustomerEmail);
|
|
70
|
+
const normalizedSupportedCountries = useMemo(() => normalizeSupportedCheckoutCountries(supportedCountries), [supportedCountries]);
|
|
68
71
|
const cardBrandLabels = useMemo(() => paymentMethodLabels.length > 0 ? paymentMethodLabels : defaultPaymentMethodLabels, [paymentMethodLabels]);
|
|
69
72
|
const normalizedPromoCode = promoCode.trim();
|
|
70
73
|
const showPromo = promoActive !== null && promoActive !== void 0 ? promoActive : (discountPercent > 0 && normalizedPromoCode.length > 0);
|
|
@@ -158,6 +161,15 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
158
161
|
setSelectedMethod('card');
|
|
159
162
|
}
|
|
160
163
|
};
|
|
164
|
+
const getBillingCountryError = (country) => getUnsupportedCheckoutCountryMessage({
|
|
165
|
+
billingCountry: country,
|
|
166
|
+
message: unsupportedCountryMessage,
|
|
167
|
+
supportedCountries: normalizedSupportedCountries,
|
|
168
|
+
});
|
|
169
|
+
const handlePaymentElementChange = (event) => {
|
|
170
|
+
var _a, _b;
|
|
171
|
+
setBillingCountry((_b = (_a = event.value.billingDetails) === null || _a === void 0 ? void 0 : _a.address.country) !== null && _b !== void 0 ? _b : null);
|
|
172
|
+
};
|
|
161
173
|
const trackCheckoutSuccess = async () => {
|
|
162
174
|
if (checkoutAnalytics) {
|
|
163
175
|
await trackPaidStripeSubscriptionCheckoutCompleted(Object.assign({ checkoutSessionId }, checkoutAnalytics));
|
|
@@ -210,6 +222,11 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
210
222
|
if (submitting) {
|
|
211
223
|
return;
|
|
212
224
|
}
|
|
225
|
+
const billingCountryError = getBillingCountryError(billingCountry);
|
|
226
|
+
if (billingCountryError) {
|
|
227
|
+
setSharedError(billingCountryError);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
213
230
|
if (checkoutState.type !== 'success') {
|
|
214
231
|
setSharedError(checkoutState.type === 'error'
|
|
215
232
|
? checkoutState.error.message
|
|
@@ -267,7 +284,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
267
284
|
effectiveSelectedMethod === 'wallet' ? 'is-visible' : '',
|
|
268
285
|
]
|
|
269
286
|
.filter(Boolean)
|
|
270
|
-
.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: false, customerEmail: resolvedCustomerEmail, customerName: customerName, initialAvailable: initialWalletAvailable, keepInitialAvailableOnReady: initialWalletAvailable === true, onAvailabilityChange: handleWalletAvailabilityChange, onError: setSharedError, onPaymentInfoSubmitted: onPaymentInfoSubmitted, onSuccess: trackCheckoutSuccess, options: expressCheckoutOptions, returnUrl: returnUrl, summaryLabel: expressCheckoutSummaryLabel }), _jsx("span", { className: 'shared-checkout-v2-sr-only', children: walletAriaLabel })] })] }), _jsxs("div", { hidden: effectiveSelectedMethod !== 'card', className: [
|
|
287
|
+
.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: false, customerEmail: resolvedCustomerEmail, customerName: customerName, initialAvailable: initialWalletAvailable, keepInitialAvailableOnReady: initialWalletAvailable === true, onAvailabilityChange: handleWalletAvailabilityChange, onError: setSharedError, onPaymentInfoSubmitted: onPaymentInfoSubmitted, onSuccess: trackCheckoutSuccess, options: expressCheckoutOptions, returnUrl: returnUrl, summaryLabel: expressCheckoutSummaryLabel, supportedCountries: normalizedSupportedCountries, unsupportedCountryMessage: unsupportedCountryMessage }), _jsx("span", { className: 'shared-checkout-v2-sr-only', children: walletAriaLabel })] })] }), _jsxs("div", { hidden: effectiveSelectedMethod !== 'card', className: [
|
|
271
288
|
'shared-checkout-v2-card-panel',
|
|
272
289
|
effectiveSelectedMethod === 'card' ? 'is-visible' : '',
|
|
273
290
|
]
|
|
@@ -278,7 +295,7 @@ function SharedStripeCheckoutV2Form({ amountCents, buttonColor, cardSubmitLabel,
|
|
|
278
295
|
}
|
|
279
296
|
setEmailDraft(event.target.value);
|
|
280
297
|
onCustomerEmailChange === null || onCustomerEmailChange === void 0 ? void 0 : onCustomerEmailChange(event.target.value);
|
|
281
|
-
} }) })] }), _jsx(PaymentElement, { options: paymentElementOptions })] }), visibleError ? _jsx("p", { className: 'shared-checkout-v2-error', children: visibleError }) : null, _jsxs("button", { type: 'submit', className: 'shared-checkout-v2-card-submit', disabled: submitting, children: [_jsx(SecurityLockIcon, { className: 'shared-checkout-v2-card-submit-icon' }), submitting ? processingLabel : cardSubmitLabel] }), _jsx("div", { className: 'shared-checkout-v2-card-brands', "aria-hidden": 'true', children: cardBrandLabels.map((label) => (_jsx(PaymentBrandMark, { label: label, className: 'shared-checkout-v2-card-brand' }, label))) }), _jsxs("p", { className: 'shared-checkout-v2-secure-pill shared-checkout-v2-secure-pill--card', children: [_jsx(SecurityLockIcon, { className: 'shared-checkout-v2-secure-pill-icon' }), secureLabel] })] })] })] }));
|
|
298
|
+
} }) })] }), _jsx(PaymentElement, { options: paymentElementOptions, onChange: handlePaymentElementChange })] }), visibleError ? _jsx("p", { className: 'shared-checkout-v2-error', children: visibleError }) : null, _jsxs("button", { type: 'submit', className: 'shared-checkout-v2-card-submit', disabled: submitting, children: [_jsx(SecurityLockIcon, { className: 'shared-checkout-v2-card-submit-icon' }), submitting ? processingLabel : cardSubmitLabel] }), _jsx("div", { className: 'shared-checkout-v2-card-brands', "aria-hidden": 'true', children: cardBrandLabels.map((label) => (_jsx(PaymentBrandMark, { label: label, className: 'shared-checkout-v2-card-brand' }, label))) }), _jsxs("p", { className: 'shared-checkout-v2-secure-pill shared-checkout-v2-secure-pill--card', children: [_jsx(SecurityLockIcon, { className: 'shared-checkout-v2-secure-pill-icon' }), secureLabel] })] })] })] }));
|
|
282
299
|
}
|
|
283
300
|
export function SharedStripeCheckoutV2Dialog(_a) {
|
|
284
301
|
var { checkoutAnalytics, checkoutSessionId, clientSecret, onClose, stripePromise } = _a, props = __rest(_a, ["checkoutAnalytics", "checkoutSessionId", "clientSecret", "onClose", "stripePromise"]);
|
|
@@ -16,11 +16,13 @@ export type StripeCheckoutExpressCheckoutButtonProps = {
|
|
|
16
16
|
initialAvailable?: boolean | null;
|
|
17
17
|
keepInitialAvailableOnReady?: boolean;
|
|
18
18
|
serverUpdateKey?: string | null;
|
|
19
|
+
supportedCountries?: readonly string[];
|
|
19
20
|
onServerUpdate?: () => Promise<boolean>;
|
|
20
21
|
onAvailabilityChange?: (available: boolean) => void;
|
|
21
22
|
onCancel?: () => void;
|
|
22
23
|
onError?: (message: string | null) => void;
|
|
23
24
|
onPaymentInfoSubmitted?: () => void | Promise<void>;
|
|
24
25
|
onSuccess?: () => void | Promise<void>;
|
|
26
|
+
unsupportedCountryMessage?: string;
|
|
25
27
|
};
|
|
26
|
-
export declare function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAnalytics, checkoutSessionId, returnUrl, confirmEmail, customerEmail, className, options, availabilityPaymentMethods, initialAvailable, keepInitialAvailableOnReady, serverUpdateKey, onServerUpdate, onAvailabilityChange, onCancel, onError, onPaymentInfoSubmitted, onSuccess, }: StripeCheckoutExpressCheckoutButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
export declare function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAnalytics, checkoutSessionId, returnUrl, confirmEmail, customerEmail, className, options, availabilityPaymentMethods, initialAvailable, keepInitialAvailableOnReady, serverUpdateKey, supportedCountries, onServerUpdate, onAvailabilityChange, onCancel, onError, onPaymentInfoSubmitted, onSuccess, unsupportedCountryMessage, }: StripeCheckoutExpressCheckoutButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
3
3
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { ExpressCheckoutElement, useCheckout, } from '@stripe/react-stripe-js/checkout';
|
|
5
5
|
import { trackPaidStripeSubscriptionCheckoutCompleted, trackStripeSubscriptionCheckoutStarted, } from '../../services/checkoutCompletionAnalytics.service.js';
|
|
6
|
+
import { getUnsupportedCheckoutCountryMessage, normalizeSupportedCheckoutCountries, } from './checkoutCountries.js';
|
|
6
7
|
const ExpressCheckoutElementWithCancel = ExpressCheckoutElement;
|
|
7
8
|
const buildDefaultOptions = () => ({
|
|
8
9
|
buttonHeight: 55,
|
|
@@ -27,7 +28,7 @@ const buildDefaultOptions = () => ({
|
|
|
27
28
|
paypal: 'never',
|
|
28
29
|
},
|
|
29
30
|
});
|
|
30
|
-
export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAnalytics, checkoutSessionId, returnUrl, confirmEmail = true, customerEmail, className, options, availabilityPaymentMethods = ['applePay'], initialAvailable, keepInitialAvailableOnReady = false, serverUpdateKey, onServerUpdate, onAvailabilityChange, onCancel, onError, onPaymentInfoSubmitted, onSuccess, }) {
|
|
31
|
+
export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAnalytics, checkoutSessionId, returnUrl, confirmEmail = true, customerEmail, className, options, availabilityPaymentMethods = ['applePay'], initialAvailable, keepInitialAvailableOnReady = false, serverUpdateKey, supportedCountries, onServerUpdate, onAvailabilityChange, onCancel, onError, onPaymentInfoSubmitted, onSuccess, unsupportedCountryMessage, }) {
|
|
31
32
|
const checkoutState = useCheckout();
|
|
32
33
|
const appliedServerUpdateKeyRef = useRef('');
|
|
33
34
|
const serverUpdatePromiseRef = useRef(null);
|
|
@@ -37,6 +38,7 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
37
38
|
? true
|
|
38
39
|
: walletAvailable;
|
|
39
40
|
const baseOptions = useMemo(() => buildDefaultOptions(), []);
|
|
41
|
+
const normalizedSupportedCountries = useMemo(() => normalizeSupportedCheckoutCountries(supportedCountries), [supportedCountries]);
|
|
40
42
|
const resolvedOptions = useMemo(() => {
|
|
41
43
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
42
44
|
return Object.assign(Object.assign(Object.assign({}, baseOptions), (options !== null && options !== void 0 ? options : {})), { buttonTheme: Object.assign(Object.assign({}, ((_a = baseOptions.buttonTheme) !== null && _a !== void 0 ? _a : {})), ((_b = options === null || options === void 0 ? void 0 : options.buttonTheme) !== null && _b !== void 0 ? _b : {})), buttonType: Object.assign(Object.assign({}, ((_c = baseOptions.buttonType) !== null && _c !== void 0 ? _c : {})), ((_d = options === null || options === void 0 ? void 0 : options.buttonType) !== null && _d !== void 0 ? _d : {})), layout: Object.assign(Object.assign({}, ((_e = baseOptions.layout) !== null && _e !== void 0 ? _e : {})), ((_f = options === null || options === void 0 ? void 0 : options.layout) !== null && _f !== void 0 ? _f : {})), paymentMethods: Object.assign(Object.assign({}, ((_g = baseOptions.paymentMethods) !== null && _g !== void 0 ? _g : {})), ((_h = options === null || options === void 0 ? void 0 : options.paymentMethods) !== null && _h !== void 0 ? _h : {})), paymentMethodOrder: (_j = options === null || options === void 0 ? void 0 : options.paymentMethodOrder) !== null && _j !== void 0 ? _j : baseOptions.paymentMethodOrder });
|
|
@@ -94,6 +96,7 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
94
96
|
await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess());
|
|
95
97
|
};
|
|
96
98
|
const handleConfirm = async (event) => {
|
|
99
|
+
var _a, _b, _c;
|
|
97
100
|
if (checkoutState.type !== 'success') {
|
|
98
101
|
const message = checkoutState.type === 'error'
|
|
99
102
|
? checkoutState.error.message
|
|
@@ -103,6 +106,16 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
103
106
|
return;
|
|
104
107
|
}
|
|
105
108
|
onError === null || onError === void 0 ? void 0 : onError(null);
|
|
109
|
+
const unsupportedCountryError = getUnsupportedCheckoutCountryMessage({
|
|
110
|
+
billingCountry: (_c = (_b = (_a = event.billingDetails) === null || _a === void 0 ? void 0 : _a.address) === null || _b === void 0 ? void 0 : _b.country) !== null && _c !== void 0 ? _c : null,
|
|
111
|
+
message: unsupportedCountryMessage,
|
|
112
|
+
supportedCountries: normalizedSupportedCountries,
|
|
113
|
+
});
|
|
114
|
+
if (unsupportedCountryError) {
|
|
115
|
+
onError === null || onError === void 0 ? void 0 : onError(unsupportedCountryError);
|
|
116
|
+
event.paymentFailed({ reason: 'invalid_billing_address', message: unsupportedCountryError });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
106
119
|
const updated = await ensureServerUpdated();
|
|
107
120
|
if (!updated) {
|
|
108
121
|
const message = 'Unable to update checkout session.';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const defaultUnsupportedCheckoutCountryMessage = "Payment is not available for the selected billing country.";
|
|
2
|
+
export declare function normalizeSupportedCheckoutCountries(countries?: readonly string[] | null): string[];
|
|
3
|
+
export declare function getUnsupportedCheckoutCountryMessage({ billingCountry, message, supportedCountries, }: {
|
|
4
|
+
billingCountry?: string | null;
|
|
5
|
+
message?: string;
|
|
6
|
+
supportedCountries: readonly string[];
|
|
7
|
+
}): string | null;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const defaultUnsupportedCheckoutCountryMessage = 'Payment is not available for the selected billing country.';
|
|
2
|
+
const normalizeCheckoutCountryCode = (countryCode) => {
|
|
3
|
+
const normalizedCountryCode = (countryCode === null || countryCode === void 0 ? void 0 : countryCode.trim().toUpperCase()) || '';
|
|
4
|
+
return /^[A-Z]{2}$/.test(normalizedCountryCode) ? normalizedCountryCode : null;
|
|
5
|
+
};
|
|
6
|
+
export function normalizeSupportedCheckoutCountries(countries) {
|
|
7
|
+
const normalizedCountries = new Set();
|
|
8
|
+
for (const country of countries !== null && countries !== void 0 ? countries : []) {
|
|
9
|
+
const normalizedCountry = normalizeCheckoutCountryCode(country);
|
|
10
|
+
if (normalizedCountry) {
|
|
11
|
+
normalizedCountries.add(normalizedCountry);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return Array.from(normalizedCountries);
|
|
15
|
+
}
|
|
16
|
+
export function getUnsupportedCheckoutCountryMessage({ billingCountry, message = defaultUnsupportedCheckoutCountryMessage, supportedCountries, }) {
|
|
17
|
+
if (supportedCountries.length === 0) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const normalizedBillingCountry = normalizeCheckoutCountryCode(billingCountry);
|
|
21
|
+
if (!normalizedBillingCountry) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return supportedCountries.includes(normalizedBillingCountry) ? null : message;
|
|
25
|
+
}
|
|
@@ -45,7 +45,7 @@ export declare function resolvePaywallPlansFromProjectPlans(projectPlans: readon
|
|
|
45
45
|
export declare function getPaywallPlans(mode: RuntimeMode, planCatalog?: BillingPlanInputCatalog | readonly BillingFallbackPlanConfig[], options?: PaywallPlanResolutionOptions): Promise<readonly PaywallPlan[]>;
|
|
46
46
|
export declare function isStripeConfigured(mode: RuntimeMode): boolean;
|
|
47
47
|
export declare function getStripePromise(mode: RuntimeMode, runtimePublishableKey?: string | null): Promise<Stripe | null> | null;
|
|
48
|
-
type CheckoutSessionPlanInput = Pick<PaywallPlan, 'amountCents' | 'billingInterval' | 'billingIntervalCount' | 'description' | 'id' | 'providerPlanId' | 'title'>;
|
|
48
|
+
type CheckoutSessionPlanInput = Pick<PaywallPlan, 'amountCents' | 'analyticsPurchaseValue' | 'billingInterval' | 'billingIntervalCount' | 'description' | 'id' | 'providerPlanId' | 'title'>;
|
|
49
49
|
type CheckoutPlanRecurringConfig = {
|
|
50
50
|
interval: BillingPlanInterval;
|
|
51
51
|
intervalCount: number;
|
|
@@ -585,6 +585,14 @@ const normalizeAnalyticsMetadata = (metadata) => {
|
|
|
585
585
|
const withCheckoutUrl = checkoutUrl ? Object.assign(Object.assign({}, normalized), { url: checkoutUrl }) : normalized;
|
|
586
586
|
return Object.keys(withCheckoutUrl).length > 0 ? withCheckoutUrl : undefined;
|
|
587
587
|
};
|
|
588
|
+
const normalizeCheckoutAnalyticsMetadata = (metadata, plan) => {
|
|
589
|
+
const normalized = normalizeAnalyticsMetadata(metadata);
|
|
590
|
+
const analyticsPurchaseValue = asNonNegativeNumberOrNull(plan.analyticsPurchaseValue);
|
|
591
|
+
if (analyticsPurchaseValue === null) {
|
|
592
|
+
return normalized;
|
|
593
|
+
}
|
|
594
|
+
return Object.assign(Object.assign({}, (normalized !== null && normalized !== void 0 ? normalized : {})), { analyticsPurchaseValue });
|
|
595
|
+
};
|
|
588
596
|
export async function createStripePaymentIntent(input) {
|
|
589
597
|
var _a, _b;
|
|
590
598
|
const runtimeConfig = resolveStripeRuntimeConfig(input.runtimeConfig);
|
|
@@ -664,7 +672,7 @@ export async function createStripeSubscriptionCheckout(input) {
|
|
|
664
672
|
billingInterval: recurring.interval,
|
|
665
673
|
billingIntervalCount: recurring.intervalCount,
|
|
666
674
|
couponId: ((_c = input.couponId) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
667
|
-
analyticsMetadata:
|
|
675
|
+
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
668
676
|
customerEmail: ((_d = input.customerEmail) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
669
677
|
returnUrl: input.returnUrl,
|
|
670
678
|
user_id: ((_e = input.user_id) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
@@ -702,7 +710,7 @@ export async function updateStripeSubscriptionCheckoutPlan(input) {
|
|
|
702
710
|
billingInterval: recurring.interval,
|
|
703
711
|
billingIntervalCount: recurring.intervalCount,
|
|
704
712
|
couponId: ((_c = input.couponId) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
705
|
-
analyticsMetadata:
|
|
713
|
+
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
706
714
|
customerEmail: ((_d = input.customerEmail) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
707
715
|
user_id: ((_e = input.user_id) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
708
716
|
environment: input.environment || undefined,
|
|
@@ -763,7 +771,7 @@ export async function createStripeCheckoutSession(input) {
|
|
|
763
771
|
billingInterval: recurring.interval,
|
|
764
772
|
billingIntervalCount: recurring.intervalCount,
|
|
765
773
|
couponId: ((_c = input.couponId) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
766
|
-
analyticsMetadata:
|
|
774
|
+
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
767
775
|
successUrl: input.successUrl,
|
|
768
776
|
cancelUrl: input.cancelUrl,
|
|
769
777
|
customerEmail: ((_d = input.customerEmail) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|