@funnelsgrove/payments 0.42.0 → 0.43.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/dist/generated/package-version.d.ts +1 -1
- package/dist/generated/package-version.js +1 -1
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.d.ts +2 -0
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.js +20 -8
- package/dist/services/paywallOffer.service.d.ts +3 -1
- package/dist/services/paywallOffer.service.js +11 -2
- package/dist/services/paywallPlans/types.d.ts +4 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PAYMENTS_PACKAGE_VERSION = "0.
|
|
1
|
+
export declare const PAYMENTS_PACKAGE_VERSION = "0.43.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.43.0";
|
|
@@ -34,5 +34,7 @@ export type StripeWalletFirstCheckoutProps = {
|
|
|
34
34
|
stripePromise: Promise<Stripe | null> | null;
|
|
35
35
|
summaryLabel: string;
|
|
36
36
|
themeColor: string;
|
|
37
|
+
/** The method selected on mount; defaults to the platform wallet. */
|
|
38
|
+
initialMethod?: 'wallet' | 'card';
|
|
37
39
|
};
|
|
38
40
|
export declare function StripeWalletFirstCheckout(props: StripeWalletFirstCheckoutProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -10,6 +10,8 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
10
10
|
* bar at the exact button height until Stripe's button replaces it, so nothing
|
|
11
11
|
* moves. Where the wallet cannot pay, the same slot explains that. The card
|
|
12
12
|
* form has no email, ZIP or terms text: the session carries the email.
|
|
13
|
+
* `initialMethod: 'card'` opens the card form first, e.g. for a bottom-of-page
|
|
14
|
+
* "complete your order" block; the wallet stays one tap away.
|
|
13
15
|
*
|
|
14
16
|
* The caller owns the subscription Checkout Session (`clientSecret`), the copy
|
|
15
17
|
* and what happens after `onSuccess`.
|
|
@@ -34,9 +36,17 @@ const appearance = {
|
|
|
34
36
|
},
|
|
35
37
|
};
|
|
36
38
|
export function StripeWalletFirstCheckout(props) {
|
|
37
|
-
const { buttonColor, checkoutAnalytics, checkoutSessionId, clientSecret, copy, stripePromise, themeColor } = props;
|
|
39
|
+
const { buttonColor, checkoutAnalytics, checkoutSessionId, clientSecret, copy, initialMethod = 'wallet', stripePromise, themeColor } = props;
|
|
38
40
|
const wallet = usePlatformWallet();
|
|
39
|
-
const [selected, setSelected] = useState(
|
|
41
|
+
const [selected, setSelected] = useState(initialMethod);
|
|
42
|
+
// A card form that is open on mount has not been opened by the visitor yet.
|
|
43
|
+
const [cardEngaged, setCardEngaged] = useState(initialMethod !== 'card');
|
|
44
|
+
const select = (method) => {
|
|
45
|
+
if (method === 'card')
|
|
46
|
+
setCardEngaged(true);
|
|
47
|
+
setSelected(method);
|
|
48
|
+
};
|
|
49
|
+
const engageCard = () => setCardEngaged(true);
|
|
40
50
|
const style = { '--wfc-theme': themeColor, '--wfc-button': buttonColor };
|
|
41
51
|
const options = useMemo(() => clientSecret ? {
|
|
42
52
|
clientSecret,
|
|
@@ -47,15 +57,16 @@ export function StripeWalletFirstCheckout(props) {
|
|
|
47
57
|
if (checkoutAnalytics)
|
|
48
58
|
trackStripeCheckoutShown(Object.assign(Object.assign({}, checkoutAnalytics), { checkoutSessionId, checkoutSurface: 'inline' }));
|
|
49
59
|
});
|
|
50
|
-
// Session creation is preparation; the card checkout starts when the visitor opens the card form
|
|
60
|
+
// Session creation is preparation; the card checkout starts when the visitor opens the card form,
|
|
61
|
+
// or, when it opens preselected, on their first input into it.
|
|
51
62
|
useEffect(() => {
|
|
52
|
-
if (!checkoutAnalytics || !clientSecret || selected !== 'card')
|
|
63
|
+
if (!checkoutAnalytics || !clientSecret || selected !== 'card' || !cardEngaged)
|
|
53
64
|
return;
|
|
54
65
|
queueStripeSubscriptionCheckoutStarted(Object.assign(Object.assign({}, checkoutAnalytics), { checkoutSessionId, checkoutStartSource: 'card_form_open', paymentMethod: 'card' }));
|
|
55
|
-
}, [checkoutAnalytics, checkoutSessionId, clientSecret, selected]);
|
|
56
|
-
return (_jsxs(_Fragment, { children: [options && stripePromise ? (_jsx(CheckoutProvider, { stripe: stripePromise, options: options, children: _jsx(StripeWalletFirstCheckoutForm, Object.assign({}, props, { wallet: wallet, selected: selected, onSelect:
|
|
66
|
+
}, [checkoutAnalytics, checkoutSessionId, clientSecret, selected, cardEngaged]);
|
|
67
|
+
return (_jsxs(_Fragment, { children: [options && stripePromise ? (_jsx(CheckoutProvider, { stripe: stripePromise, options: options, children: _jsx(StripeWalletFirstCheckoutForm, Object.assign({}, props, { wallet: wallet, selected: selected, onSelect: select, onCardEngaged: engageCard, style: style })) }, options.clientSecret)) : (_jsx(CheckoutLayout, { copy: copy, wallet: wallet, selected: selected, onSelect: select, disabled: false, style: style, walletSlot: _jsx("span", { className: 'wfc-progress', role: 'status', "aria-label": copy.processingLabel }), cardBody: _jsx("span", { className: 'wfc-progress wfc-progress--form', "aria-hidden": 'true' }) })), _jsx("style", { children: stripeWalletFirstCheckoutStyles })] }));
|
|
57
68
|
}
|
|
58
|
-
function StripeWalletFirstCheckoutForm({ amountCents, checkoutAnalytics, checkoutSessionId, copy, customerEmail, customerName, onCancel, onError, onSuccess, returnUrl, summaryLabel, wallet, selected, onSelect, style, }) {
|
|
69
|
+
function StripeWalletFirstCheckoutForm({ amountCents, checkoutAnalytics, checkoutSessionId, copy, customerEmail, customerName, onCancel, onError, onSuccess, returnUrl, summaryLabel, wallet, selected, onSelect, onCardEngaged, style, }) {
|
|
59
70
|
const checkoutState = useCheckout();
|
|
60
71
|
// null until Stripe answers; the slot shows progress at the button's height meanwhile.
|
|
61
72
|
const [walletAvailable, setWalletAvailable] = useState(null);
|
|
@@ -167,7 +178,8 @@ function StripeWalletFirstCheckoutForm({ amountCents, checkoutAnalytics, checkou
|
|
|
167
178
|
// where the customer paid, until the success screen takes over.
|
|
168
179
|
const paymentStatus = completed ? copy.paymentConfirmed : providerConfirmed ? copy.verifyingPayment : null;
|
|
169
180
|
const locked = Boolean(paymentStatus) && !error;
|
|
170
|
-
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, undefined, true); }, onPaymentRejected: () => { setWalletConfirming(false); onSelect('card'); }, onSuccess: () => 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)
|
|
181
|
+
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, undefined, true); }, onPaymentRejected: () => { setWalletConfirming(false); onSelect('card'); }, onSuccess: () => 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)
|
|
182
|
+
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 }));
|
|
171
183
|
}
|
|
172
184
|
/** Shared by the loading and live states so switching between them moves nothing. */
|
|
173
185
|
function CheckoutLayout({ cardBody, copy, disabled, footer, onSelect, selected, style, wallet, walletNote, walletSlot }) {
|
|
@@ -63,7 +63,9 @@ export declare const buildDiscountedPaywallPlans: (input: {
|
|
|
63
63
|
}) => PaywallDisplayPlan[];
|
|
64
64
|
export declare const getPaywallPromoDisplayName: (referenceMs: number) => string;
|
|
65
65
|
export declare const buildPaywallRenewalDisclaimer: (input: {
|
|
66
|
-
plan: Pick<PaywallPlan, "priceLabel" | "billingInterval" | "billingIntervalCount">;
|
|
66
|
+
plan: Pick<PaywallPlan, "priceLabel" | "billingInterval" | "billingIntervalCount" | "followUpPriceLabel" | "followUpBillingInterval" | "followUpBillingIntervalCount">;
|
|
67
67
|
hasActiveDiscount: boolean;
|
|
68
68
|
productName?: string;
|
|
69
69
|
}) => string;
|
|
70
|
+
/** A plan with a follow-up price renews at that price, not at its intro price. */
|
|
71
|
+
export declare const getPaywallRenewalTerms: (plan: Pick<PaywallPlan, "priceLabel" | "billingInterval" | "billingIntervalCount" | "followUpPriceLabel" | "followUpBillingInterval" | "followUpBillingIntervalCount">) => Pick<PaywallPlan, "priceLabel" | "billingInterval" | "billingIntervalCount">;
|
|
@@ -285,7 +285,7 @@ export const buildDiscountedPaywallPlans = (input) => {
|
|
|
285
285
|
? discountedMoney
|
|
286
286
|
? formatProviderMoney(discountedMoney, locale)
|
|
287
287
|
: formatMoneyFromCents(discountedAmountCents, planCurrency, locale)
|
|
288
|
-
: plan.priceLabel, oldPriceLabel: hasActiveDiscount ? plan.priceLabel :
|
|
288
|
+
: plan.priceLabel, oldPriceLabel: hasActiveDiscount ? plan.priceLabel : plan.priceBeforeDiscount, perDayAmount: hasActiveDiscount ? discountedPerDayAmount : plan.perDayAmount, baseAmountCents: plan.amountCents, basePriceLabel: plan.priceLabel, basePerDayAmount: plan.perDayAmount, oldPerDayAmount: hasActiveDiscount ? plan.perDayAmount : null, couponId: hasActiveDiscount ? input.couponId : null, hasActiveDiscount });
|
|
289
289
|
});
|
|
290
290
|
};
|
|
291
291
|
export const getPaywallPromoDisplayName = (referenceMs) => {
|
|
@@ -314,5 +314,14 @@ export const buildPaywallRenewalDisclaimer = (input) => {
|
|
|
314
314
|
var _a;
|
|
315
315
|
const introLabel = input.hasActiveDiscount ? 'discounted intro plan' : 'selected plan';
|
|
316
316
|
const productPrefix = ((_a = input.productName) === null || _a === void 0 ? void 0 : _a.trim()) ? `${input.productName.trim()} ` : '';
|
|
317
|
-
|
|
317
|
+
const renewal = getPaywallRenewalTerms(input.plan);
|
|
318
|
+
return `Without cancellation, before the ${introLabel} ends, I accept that ${productPrefix}will automatically charge ${renewal.priceLabel} ${formatRecurringCadence(renewal)} until I cancel. Cancel online via the profile on the website or app.`;
|
|
318
319
|
};
|
|
320
|
+
/** A plan with a follow-up price renews at that price, not at its intro price. */
|
|
321
|
+
export const getPaywallRenewalTerms = (plan) => (plan.followUpPriceLabel
|
|
322
|
+
? {
|
|
323
|
+
priceLabel: plan.followUpPriceLabel,
|
|
324
|
+
billingInterval: plan.followUpBillingInterval,
|
|
325
|
+
billingIntervalCount: plan.followUpBillingIntervalCount,
|
|
326
|
+
}
|
|
327
|
+
: plan);
|
|
@@ -11,6 +11,8 @@ export type PaywallPlan = {
|
|
|
11
11
|
providerPlanId?: string;
|
|
12
12
|
priceLabel: string;
|
|
13
13
|
oldPriceLabel?: string;
|
|
14
|
+
/** Display-only price shown crossed out when no coupon discount is active. */
|
|
15
|
+
priceBeforeDiscount?: string;
|
|
14
16
|
featuredTag?: string;
|
|
15
17
|
perDayAmount: string;
|
|
16
18
|
perDayLabel: string;
|
|
@@ -27,6 +29,8 @@ export type PaywallPlan = {
|
|
|
27
29
|
followUpPlanTitle?: string;
|
|
28
30
|
followUpBillingInterval?: BillingPlanInterval;
|
|
29
31
|
followUpBillingIntervalCount?: number;
|
|
32
|
+
/** Renewal amount of the follow-up price, shown in the auto-renewal disclaimer. */
|
|
33
|
+
followUpPriceLabel?: string;
|
|
30
34
|
introIterations?: number;
|
|
31
35
|
source: 'stripe' | 'config';
|
|
32
36
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funnelsgrove/payments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"jsdom": "20.0.3",
|
|
47
47
|
"typescript": "^5",
|
|
48
48
|
"vitest": "^3.2.4",
|
|
49
|
-
"@funnelsgrove/runtime": "0.
|
|
50
|
-
"@funnelsgrove/analytics": "0.
|
|
49
|
+
"@funnelsgrove/runtime": "0.34.0",
|
|
50
|
+
"@funnelsgrove/analytics": "0.16.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@funnelsgrove/runtime": "^0.
|
|
54
|
-
"@funnelsgrove/analytics": "^0.
|
|
53
|
+
"@funnelsgrove/runtime": "^0.34.0",
|
|
54
|
+
"@funnelsgrove/analytics": "^0.16.0"
|
|
55
55
|
}
|
|
56
56
|
}
|