@funnelsgrove/payments 0.40.0 → 0.42.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 +24 -0
- package/dist/components/CreatorCodeField.d.ts +18 -0
- package/dist/components/CreatorCodeField.js +41 -0
- package/dist/components/CreatorDealBanner.d.ts +26 -0
- package/dist/components/CreatorDealBanner.js +21 -0
- package/dist/components/CreatorDealBanner.styles.d.ts +1 -0
- package/dist/components/CreatorDealBanner.styles.js +160 -0
- package/dist/generated/package-version.d.ts +1 -1
- package/dist/generated/package-version.js +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/providers/stripe/services/shared/checkoutMetadata.js +4 -1
- package/dist/services/creatorDeal.service.d.ts +57 -0
- package/dist/services/creatorDeal.service.js +66 -0
- package/dist/services/creatorReferral.d.ts +16 -0
- package/dist/services/creatorReferral.js +55 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -134,6 +134,30 @@ For example, `--checkout-email-button-background: var(--color-primary)` uses the
|
|
|
134
134
|
funnel accent. Set foreground/background pairs together for custom dark surfaces.
|
|
135
135
|
Existing `dialog.checkout-email-dialog` CSS overrides continue to work.
|
|
136
136
|
|
|
137
|
+
## Influencers Store creator deals
|
|
138
|
+
|
|
139
|
+
A buyer who opens a funnel from an Influencers Store creator page arrives with
|
|
140
|
+
`?is_ref=<referral id>`. `useCreatorDeal({ apiBaseUrl, funnelId })` reads that referral
|
|
141
|
+
(remembered for 30 days, so later steps keep it) and loads the deal from
|
|
142
|
+
`GET /sdk/public/funnels/:funnelId/creator-deal`. Show it with `CreatorDealBanner` above the
|
|
143
|
+
plan, and pass `deal.couponId` and `deal.discountPercent` to `buildDiscountedPaywallPlans` and
|
|
144
|
+
`deal.couponId` as the checkout `couponId`, so the plan, the checkout summary and the charge
|
|
145
|
+
agree:
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
const { deal } = useCreatorDeal(checkoutRuntimeConfig);
|
|
149
|
+
const display = buildDiscountedPaywallPlans({ plans, couponId: deal?.couponId ?? null, discountPercent: deal?.discountPercent ?? 0 })[0];
|
|
150
|
+
{deal ? <CreatorDealBanner deal={deal} price={{ original: display.oldPriceLabel, discounted: display.priceLabel }} /> : null}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The API applies the same coupon on its own when a referred buyer checks out without one, so a
|
|
154
|
+
funnel that never shows the banner still charges the deal.
|
|
155
|
+
|
|
156
|
+
For buyers who heard about the app from a creator without a link, add `CreatorCodeField` near the
|
|
157
|
+
plans. A working code opens a referral, remembers it like an `is_ref` visit and calls `onApplied`
|
|
158
|
+
with the deal (pass it to `applyDeal` from `useCreatorDeal`). Checkout metadata carries the
|
|
159
|
+
remembered referral as `is_ref` automatically.
|
|
160
|
+
|
|
137
161
|
## Advanced Wallet Primitives
|
|
138
162
|
|
|
139
163
|
`ApplePaySubscriptionCheckoutSlot`, `GooglePaySubscriptionCheckoutSlot`, and `WalletSubscriptionCheckoutSlot` stay exported and runtime-compatible. They are backward-compatible advanced low-level primitives: reach for them only when a placement needs wiring the shared wallet surfaces do not cover. Never share one checkout hook result across placements; give each visible placement its own session.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type CreatorCodeResult } from '../services/creatorDeal.service.js';
|
|
2
|
+
export type CreatorCodeFieldProps = {
|
|
3
|
+
apiBaseUrl: string | null | undefined;
|
|
4
|
+
funnelId: string | null | undefined;
|
|
5
|
+
/** Called after a code works; pass `deal` to `buildDiscountedPaywallPlans` and checkout. */
|
|
6
|
+
onApplied?: (result: Extract<CreatorCodeResult, {
|
|
7
|
+
ok: true;
|
|
8
|
+
}>) => void;
|
|
9
|
+
labels?: Partial<{
|
|
10
|
+
toggle: string;
|
|
11
|
+
placeholder: string;
|
|
12
|
+
apply: string;
|
|
13
|
+
applied: string;
|
|
14
|
+
}>;
|
|
15
|
+
className?: string;
|
|
16
|
+
};
|
|
17
|
+
/** "Have a creator code?" on a paywall: buyers who heard about the app from a creator type their code. */
|
|
18
|
+
export declare function CreatorCodeField({ apiBaseUrl, funnelId, onApplied, labels, className }: CreatorCodeFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { redeemCreatorCode } from '../services/creatorDeal.service.js';
|
|
5
|
+
const styles = `
|
|
6
|
+
.creator-code { font-family: var(--font-family-base, Inter, sans-serif); color: var(--color-text, #262729); font-size: 14px; }
|
|
7
|
+
.creator-code-toggle { background: none; border: 0; padding: 4px 0; color: inherit; opacity: 0.75; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font: inherit; }
|
|
8
|
+
.creator-code-form { display: flex; gap: 8px; margin-top: 6px; }
|
|
9
|
+
.creator-code-input { flex: 1; min-width: 0; height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid color-mix(in srgb, currentColor 22%, transparent); background: var(--color-surface, #fff); color: inherit; font: inherit; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
10
|
+
.creator-code-apply { height: 44px; padding: 0 18px; border-radius: 12px; border: 0; background: var(--color-primary, #4db53f); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
|
|
11
|
+
.creator-code-apply:disabled { opacity: 0.5; cursor: default; }
|
|
12
|
+
.creator-code-error { margin: 6px 0 0; color: #b42318; font-size: 13px; }
|
|
13
|
+
.creator-code-done { display: flex; align-items: center; gap: 8px; margin: 0; }
|
|
14
|
+
.creator-code-check { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 999px; background: var(--color-primary, #4db53f); color: #fff; flex: none; }
|
|
15
|
+
`;
|
|
16
|
+
const defaults = { toggle: 'Have a creator code?', placeholder: 'Creator code', apply: 'Apply', applied: 'Code {code} applied' };
|
|
17
|
+
/** "Have a creator code?" on a paywall: buyers who heard about the app from a creator type their code. */
|
|
18
|
+
export function CreatorCodeField({ apiBaseUrl, funnelId, onApplied, labels, className }) {
|
|
19
|
+
const text = Object.assign(Object.assign({}, defaults), labels);
|
|
20
|
+
const [open, setOpen] = useState(false);
|
|
21
|
+
const [code, setCode] = useState('');
|
|
22
|
+
const [pending, setPending] = useState(false);
|
|
23
|
+
const [error, setError] = useState(null);
|
|
24
|
+
const [applied, setApplied] = useState(null);
|
|
25
|
+
const submit = async (event) => {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
if (!apiBaseUrl || !funnelId || code.trim().length < 3)
|
|
28
|
+
return;
|
|
29
|
+
setPending(true);
|
|
30
|
+
setError(null);
|
|
31
|
+
const result = await redeemCreatorCode({ apiBaseUrl, funnelId, code: code.trim() });
|
|
32
|
+
setPending(false);
|
|
33
|
+
if (!result.ok) {
|
|
34
|
+
setError(result.message);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
setApplied({ code: code.trim().toUpperCase(), deal: result.deal, creator: result.creator });
|
|
38
|
+
onApplied === null || onApplied === void 0 ? void 0 : onApplied(result);
|
|
39
|
+
};
|
|
40
|
+
return (_jsxs("div", { className: ['creator-code', className !== null && className !== void 0 ? className : ''].filter(Boolean).join(' '), children: [_jsx("style", { children: styles }), applied ? (_jsxs("p", { className: 'creator-code-done', role: 'status', children: [_jsx("span", { className: 'creator-code-check', "aria-hidden": 'true', children: _jsx("svg", { width: '10', height: '10', viewBox: '0 0 12 12', fill: 'none', children: _jsx("path", { d: 'M2.5 6.2 5 8.5l4.5-5', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round' }) }) }), text.applied.replace('{code}', applied.code), applied.deal ? ` · −${applied.deal.discountPercent}%` : ''] })) : !open ? (_jsx("button", { type: 'button', className: 'creator-code-toggle', onClick: () => setOpen(true), children: text.toggle })) : (_jsxs("form", { className: 'creator-code-form', onSubmit: submit, noValidate: true, children: [_jsx("input", { className: 'creator-code-input', "aria-label": text.placeholder, placeholder: text.placeholder, value: code, maxLength: 40, autoCapitalize: 'characters', autoComplete: 'off', spellCheck: false, onChange: (event) => { setCode(event.target.value); setError(null); } }), _jsx("button", { type: 'submit', className: 'creator-code-apply', disabled: pending || code.trim().length < 3, children: text.apply })] })), error ? _jsx("p", { className: 'creator-code-error', role: 'alert', children: error }) : null] }));
|
|
41
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CreatorDeal } from '../services/creatorDeal.service.js';
|
|
2
|
+
export type CreatorDealBannerLabels = {
|
|
3
|
+
/** Above the title, e.g. "Sam Lee's pick". `{name}` and `{handle}` are replaced. */
|
|
4
|
+
eyebrow: string;
|
|
5
|
+
/** e.g. "25% off your first payment". `{percent}` is replaced. */
|
|
6
|
+
title: string;
|
|
7
|
+
/** Under the price, e.g. "Discount applied automatically at checkout". */
|
|
8
|
+
applied: string;
|
|
9
|
+
/** Savings pill, e.g. "You save $10.00". `{amount}` is replaced. */
|
|
10
|
+
save: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const defaultCreatorDealBannerLabels: CreatorDealBannerLabels;
|
|
13
|
+
export type CreatorDealBannerProps = {
|
|
14
|
+
deal: CreatorDeal;
|
|
15
|
+
/** Plan prices after `buildDiscountedPaywallPlans`; omit to show the deal without a price. */
|
|
16
|
+
price?: {
|
|
17
|
+
original: string | null;
|
|
18
|
+
discounted: string;
|
|
19
|
+
savings?: string | null;
|
|
20
|
+
} | null;
|
|
21
|
+
labels?: Partial<CreatorDealBannerLabels>;
|
|
22
|
+
variant?: 'card' | 'compact';
|
|
23
|
+
className?: string;
|
|
24
|
+
};
|
|
25
|
+
/** Who recommended the app and what their audience gets, shown above the plan on a paywall. */
|
|
26
|
+
export declare function CreatorDealBanner({ deal, price, labels, variant, className }: CreatorDealBannerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/* eslint-disable @next/next/no-img-element -- package components cannot depend on next/image */
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { creatorDealBannerStyles } from './CreatorDealBanner.styles.js';
|
|
6
|
+
export const defaultCreatorDealBannerLabels = {
|
|
7
|
+
eyebrow: "{name}'s exclusive deal",
|
|
8
|
+
title: '{percent}% off your first payment',
|
|
9
|
+
applied: 'Applied automatically at checkout',
|
|
10
|
+
save: 'You save {amount}',
|
|
11
|
+
};
|
|
12
|
+
const fill = (template, values) => template.replace(/\{(\w+)\}/g, (match, key) => { var _a; return (_a = values[key]) !== null && _a !== void 0 ? _a : match; });
|
|
13
|
+
const initials = (name) => name.replace(/^@/, '').split(/\s+/).map((part) => { var _a; return (_a = part[0]) !== null && _a !== void 0 ? _a : ''; }).join('').slice(0, 2).toUpperCase();
|
|
14
|
+
/** Who recommended the app and what their audience gets, shown above the plan on a paywall. */
|
|
15
|
+
export function CreatorDealBanner({ deal, price, labels, variant = 'card', className }) {
|
|
16
|
+
const text = Object.assign(Object.assign({}, defaultCreatorDealBannerLabels), labels);
|
|
17
|
+
const values = { name: deal.creator.name, handle: `@${deal.creator.handle}`, percent: String(deal.discountPercent) };
|
|
18
|
+
const [avatarFailed, setAvatarFailed] = useState(false);
|
|
19
|
+
const compact = variant === 'compact';
|
|
20
|
+
return (_jsxs("section", { className: ['creator-deal', compact ? 'is-compact' : '', className !== null && className !== void 0 ? className : ''].filter(Boolean).join(' '), "aria-label": `${fill(text.eyebrow, values)}: ${fill(text.title, values)}`, "data-testid": 'creator-deal', children: [_jsx("style", { children: creatorDealBannerStyles }), _jsxs("div", { className: 'creator-deal-head', children: [deal.creator.avatarUrl && !avatarFailed ? (_jsx("img", { className: 'creator-deal-avatar', src: deal.creator.avatarUrl, alt: '', referrerPolicy: 'no-referrer', onError: () => setAvatarFailed(true) })) : (_jsx("span", { className: 'creator-deal-avatar creator-deal-initials', "aria-hidden": 'true', children: initials(deal.creator.name) })), _jsxs("div", { className: 'creator-deal-who', children: [compact ? null : _jsx("p", { className: 'creator-deal-eyebrow', children: fill(text.eyebrow, values) }), _jsx("p", { className: 'creator-deal-title', children: fill(text.title, values) })] }), _jsxs("span", { className: 'creator-deal-badge', children: ["\u2212", deal.discountPercent, "%"] })] }), !compact && price ? (_jsxs("div", { className: 'creator-deal-price', children: [price.original ? _jsx("span", { className: 'creator-deal-price-old', children: price.original }) : null, _jsx("span", { className: 'creator-deal-price-new', children: price.discounted }), price.savings ? _jsx("span", { className: 'creator-deal-save', children: fill(text.save, { amount: price.savings }) }) : null] })) : null, compact ? null : (_jsxs("p", { className: 'creator-deal-applied', children: [_jsx("span", { className: 'creator-deal-check', "aria-hidden": 'true', children: _jsx("svg", { width: '10', height: '10', viewBox: '0 0 12 12', fill: 'none', children: _jsx("path", { d: 'M2.5 6.2 5 8.5l4.5-5', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round' }) }) }), fill(text.applied, values)] }))] }));
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const creatorDealBannerStyles = "\n.creator-deal {\n --creator-deal-accent: var(--color-primary, #4db53f);\n position: relative;\n box-sizing: border-box;\n width: 100%;\n padding: 14px 16px;\n border-radius: 16px;\n border: 1px solid color-mix(in srgb, var(--creator-deal-accent) 35%, transparent);\n background:\n linear-gradient(135deg, color-mix(in srgb, var(--creator-deal-accent) 12%, var(--color-surface, #fff)) 0%, var(--color-surface, #fff) 70%);\n color: var(--color-text, #262729);\n font-family: var(--font-family-base, Inter, sans-serif);\n animation: creator-deal-in 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both;\n}\n\n.creator-deal-head {\n display: flex;\n align-items: center;\n gap: 12px;\n}\n\n.creator-deal-avatar {\n flex: none;\n width: 40px;\n height: 40px;\n border-radius: 999px;\n object-fit: cover;\n box-shadow: 0 0 0 2px var(--color-surface, #fff), 0 0 0 4px color-mix(in srgb, var(--creator-deal-accent) 55%, transparent);\n}\n\n.creator-deal-initials {\n display: grid;\n place-items: center;\n background: var(--creator-deal-accent);\n color: #fff;\n font-weight: 700;\n font-size: 15px;\n}\n\n.creator-deal-who {\n min-width: 0;\n flex: 1;\n}\n\n.creator-deal-eyebrow {\n margin: 0;\n font-size: 12px;\n line-height: 16px;\n opacity: 0.7;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\n.creator-deal-title {\n margin: 1px 0 0;\n font-size: 15px;\n line-height: 20px;\n font-weight: 700;\n}\n\n.creator-deal-badge {\n flex: none;\n padding: 6px 10px;\n border-radius: 999px;\n background: var(--creator-deal-accent);\n color: #fff;\n font-size: 15px;\n line-height: 18px;\n font-weight: 800;\n letter-spacing: -0.01em;\n font-variant-numeric: tabular-nums;\n transform: rotate(-3deg);\n box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--creator-deal-accent) 70%, transparent);\n}\n\n.creator-deal-price {\n display: flex;\n flex-wrap: wrap;\n align-items: baseline;\n gap: 4px 10px;\n margin-top: 12px;\n font-variant-numeric: tabular-nums;\n}\n\n.creator-deal-price-old {\n font-size: 15px;\n opacity: 0.55;\n text-decoration: line-through;\n text-decoration-thickness: 1.5px;\n}\n\n.creator-deal-price-new {\n font-size: 22px;\n line-height: 26px;\n font-weight: 800;\n letter-spacing: -0.02em;\n}\n\n.creator-deal-save {\n padding: 2px 8px;\n border-radius: 999px;\n background: color-mix(in srgb, var(--creator-deal-accent) 16%, transparent);\n color: color-mix(in srgb, var(--creator-deal-accent) 80%, #000);\n font-size: 12px;\n font-weight: 700;\n}\n\n.creator-deal-applied {\n display: flex;\n align-items: center;\n gap: 6px;\n margin: 10px 0 0;\n font-size: 13px;\n line-height: 18px;\n opacity: 0.8;\n}\n\n.creator-deal-check {\n display: grid;\n place-items: center;\n flex: none;\n width: 16px;\n height: 16px;\n border-radius: 999px;\n background: var(--creator-deal-accent);\n color: #fff;\n}\n\n.creator-deal.is-compact {\n padding: 8px 10px 8px 8px;\n border-radius: 999px;\n}\n\n.creator-deal.is-compact .creator-deal-avatar {\n width: 28px;\n height: 28px;\n}\n\n.creator-deal.is-compact .creator-deal-title {\n font-size: 13px;\n line-height: 18px;\n}\n\n.creator-deal.is-compact .creator-deal-badge {\n padding: 3px 8px;\n font-size: 13px;\n transform: none;\n}\n\n@keyframes creator-deal-in {\n from { opacity: 0; transform: translateY(6px) scale(0.98); }\n to { opacity: 1; transform: none; }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .creator-deal { animation: none; }\n}\n";
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
export const creatorDealBannerStyles = `
|
|
2
|
+
.creator-deal {
|
|
3
|
+
--creator-deal-accent: var(--color-primary, #4db53f);
|
|
4
|
+
position: relative;
|
|
5
|
+
box-sizing: border-box;
|
|
6
|
+
width: 100%;
|
|
7
|
+
padding: 14px 16px;
|
|
8
|
+
border-radius: 16px;
|
|
9
|
+
border: 1px solid color-mix(in srgb, var(--creator-deal-accent) 35%, transparent);
|
|
10
|
+
background:
|
|
11
|
+
linear-gradient(135deg, color-mix(in srgb, var(--creator-deal-accent) 12%, var(--color-surface, #fff)) 0%, var(--color-surface, #fff) 70%);
|
|
12
|
+
color: var(--color-text, #262729);
|
|
13
|
+
font-family: var(--font-family-base, Inter, sans-serif);
|
|
14
|
+
animation: creator-deal-in 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.creator-deal-head {
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
gap: 12px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.creator-deal-avatar {
|
|
24
|
+
flex: none;
|
|
25
|
+
width: 40px;
|
|
26
|
+
height: 40px;
|
|
27
|
+
border-radius: 999px;
|
|
28
|
+
object-fit: cover;
|
|
29
|
+
box-shadow: 0 0 0 2px var(--color-surface, #fff), 0 0 0 4px color-mix(in srgb, var(--creator-deal-accent) 55%, transparent);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.creator-deal-initials {
|
|
33
|
+
display: grid;
|
|
34
|
+
place-items: center;
|
|
35
|
+
background: var(--creator-deal-accent);
|
|
36
|
+
color: #fff;
|
|
37
|
+
font-weight: 700;
|
|
38
|
+
font-size: 15px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.creator-deal-who {
|
|
42
|
+
min-width: 0;
|
|
43
|
+
flex: 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.creator-deal-eyebrow {
|
|
47
|
+
margin: 0;
|
|
48
|
+
font-size: 12px;
|
|
49
|
+
line-height: 16px;
|
|
50
|
+
opacity: 0.7;
|
|
51
|
+
white-space: nowrap;
|
|
52
|
+
overflow: hidden;
|
|
53
|
+
text-overflow: ellipsis;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.creator-deal-title {
|
|
57
|
+
margin: 1px 0 0;
|
|
58
|
+
font-size: 15px;
|
|
59
|
+
line-height: 20px;
|
|
60
|
+
font-weight: 700;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.creator-deal-badge {
|
|
64
|
+
flex: none;
|
|
65
|
+
padding: 6px 10px;
|
|
66
|
+
border-radius: 999px;
|
|
67
|
+
background: var(--creator-deal-accent);
|
|
68
|
+
color: #fff;
|
|
69
|
+
font-size: 15px;
|
|
70
|
+
line-height: 18px;
|
|
71
|
+
font-weight: 800;
|
|
72
|
+
letter-spacing: -0.01em;
|
|
73
|
+
font-variant-numeric: tabular-nums;
|
|
74
|
+
transform: rotate(-3deg);
|
|
75
|
+
box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--creator-deal-accent) 70%, transparent);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.creator-deal-price {
|
|
79
|
+
display: flex;
|
|
80
|
+
flex-wrap: wrap;
|
|
81
|
+
align-items: baseline;
|
|
82
|
+
gap: 4px 10px;
|
|
83
|
+
margin-top: 12px;
|
|
84
|
+
font-variant-numeric: tabular-nums;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.creator-deal-price-old {
|
|
88
|
+
font-size: 15px;
|
|
89
|
+
opacity: 0.55;
|
|
90
|
+
text-decoration: line-through;
|
|
91
|
+
text-decoration-thickness: 1.5px;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.creator-deal-price-new {
|
|
95
|
+
font-size: 22px;
|
|
96
|
+
line-height: 26px;
|
|
97
|
+
font-weight: 800;
|
|
98
|
+
letter-spacing: -0.02em;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.creator-deal-save {
|
|
102
|
+
padding: 2px 8px;
|
|
103
|
+
border-radius: 999px;
|
|
104
|
+
background: color-mix(in srgb, var(--creator-deal-accent) 16%, transparent);
|
|
105
|
+
color: color-mix(in srgb, var(--creator-deal-accent) 80%, #000);
|
|
106
|
+
font-size: 12px;
|
|
107
|
+
font-weight: 700;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.creator-deal-applied {
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
gap: 6px;
|
|
114
|
+
margin: 10px 0 0;
|
|
115
|
+
font-size: 13px;
|
|
116
|
+
line-height: 18px;
|
|
117
|
+
opacity: 0.8;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.creator-deal-check {
|
|
121
|
+
display: grid;
|
|
122
|
+
place-items: center;
|
|
123
|
+
flex: none;
|
|
124
|
+
width: 16px;
|
|
125
|
+
height: 16px;
|
|
126
|
+
border-radius: 999px;
|
|
127
|
+
background: var(--creator-deal-accent);
|
|
128
|
+
color: #fff;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.creator-deal.is-compact {
|
|
132
|
+
padding: 8px 10px 8px 8px;
|
|
133
|
+
border-radius: 999px;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.creator-deal.is-compact .creator-deal-avatar {
|
|
137
|
+
width: 28px;
|
|
138
|
+
height: 28px;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.creator-deal.is-compact .creator-deal-title {
|
|
142
|
+
font-size: 13px;
|
|
143
|
+
line-height: 18px;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.creator-deal.is-compact .creator-deal-badge {
|
|
147
|
+
padding: 3px 8px;
|
|
148
|
+
font-size: 13px;
|
|
149
|
+
transform: none;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@keyframes creator-deal-in {
|
|
153
|
+
from { opacity: 0; transform: translateY(6px) scale(0.98); }
|
|
154
|
+
to { opacity: 1; transform: none; }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@media (prefers-reduced-motion: reduce) {
|
|
158
|
+
.creator-deal { animation: none; }
|
|
159
|
+
}
|
|
160
|
+
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PAYMENTS_PACKAGE_VERSION = "0.
|
|
1
|
+
export declare const PAYMENTS_PACKAGE_VERSION = "0.42.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.42.0";
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export * from './services/runtimeBillingPlanCatalog.service.js';
|
|
|
7
7
|
export * from './services/publishedBillingRuntime.service.js';
|
|
8
8
|
export * from './services/usePinnedPublishedBillingRuntime.js';
|
|
9
9
|
export * from './services/paywallOffer.service.js';
|
|
10
|
+
export * from './services/creatorDeal.service.js';
|
|
11
|
+
export type { StorageLike as CreatorReferralStorage } from './services/creatorReferral.js';
|
|
10
12
|
export * from './services/paymentMethodAnalytics.service.js';
|
|
11
13
|
export * from './services/checkoutObservability.service.js';
|
|
12
14
|
export * from './providers/paymentProvider.types.js';
|
|
@@ -15,6 +17,8 @@ export * from './providers/solidgate/index.js';
|
|
|
15
17
|
export { ManageSubscriptionScreen, type ManageSubscriptionContent, type ManageSubscriptionScreenProps, type ManageSubscriptionLabels, } from './components/ManageSubscriptionScreen.js';
|
|
16
18
|
export { isCheckoutEmailError, isValidCheckoutEmail } from './services/checkoutEmail.js';
|
|
17
19
|
export * from './components/CheckoutEmailDialog.js';
|
|
20
|
+
export * from './components/CreatorDealBanner.js';
|
|
21
|
+
export * from './components/CreatorCodeField.js';
|
|
18
22
|
export { PayPalCheckoutDialog } from './providers/paypal/PayPalCheckoutDialog.js';
|
|
19
23
|
export { PayPalCheckout, type PayPalCheckoutProps } from './providers/paypal/PayPalCheckout.js';
|
|
20
24
|
export { readPendingPayPalCheckout } from './providers/paypal/paypalCheckout.service.js';
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from './services/runtimeBillingPlanCatalog.service.js';
|
|
|
8
8
|
export * from './services/publishedBillingRuntime.service.js';
|
|
9
9
|
export * from './services/usePinnedPublishedBillingRuntime.js';
|
|
10
10
|
export * from './services/paywallOffer.service.js';
|
|
11
|
+
export * from './services/creatorDeal.service.js';
|
|
11
12
|
export * from './services/paymentMethodAnalytics.service.js';
|
|
12
13
|
export * from './services/checkoutObservability.service.js';
|
|
13
14
|
export * from './providers/paymentProvider.types.js';
|
|
@@ -18,6 +19,8 @@ export * from './providers/solidgate/index.js';
|
|
|
18
19
|
export { ManageSubscriptionScreen, } from './components/ManageSubscriptionScreen.js';
|
|
19
20
|
export { isCheckoutEmailError, isValidCheckoutEmail } from './services/checkoutEmail.js';
|
|
20
21
|
export * from './components/CheckoutEmailDialog.js';
|
|
22
|
+
export * from './components/CreatorDealBanner.js';
|
|
23
|
+
export * from './components/CreatorCodeField.js';
|
|
21
24
|
export { PayPalCheckoutDialog } from './providers/paypal/PayPalCheckoutDialog.js';
|
|
22
25
|
export { PayPalCheckout } from './providers/paypal/PayPalCheckout.js';
|
|
23
26
|
export { readPendingPayPalCheckout } from './providers/paypal/paypalCheckout.service.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readCreatorReferralId } from '../../../../services/creatorReferral.js';
|
|
1
2
|
const isRecord = (value) => {
|
|
2
3
|
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
3
4
|
};
|
|
@@ -94,7 +95,9 @@ export const normalizeAnalyticsMetadata = (metadata) => {
|
|
|
94
95
|
asTrimmedStringOrNull(normalized._fbp) ||
|
|
95
96
|
readMetaCookieValue('_fbp');
|
|
96
97
|
const checkoutUrl = sanitizeCheckoutUrl(normalized.url) || currentCheckoutUrl();
|
|
97
|
-
|
|
98
|
+
// Influencers Store: a creator referral from the URL or a redeemed creator code earns its creator.
|
|
99
|
+
const creatorReferralId = asTrimmedStringOrNull(normalized.is_ref) || readCreatorReferralId();
|
|
100
|
+
const withCheckoutUrl = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, normalized), (fbc ? { fbc } : {})), (fbp ? { fbp } : {})), (checkoutUrl ? { url: checkoutUrl } : {})), (creatorReferralId ? { is_ref: creatorReferralId } : {}));
|
|
98
101
|
return Object.keys(withCheckoutUrl).length > 0 ? withCheckoutUrl : undefined;
|
|
99
102
|
};
|
|
100
103
|
export const normalizeCheckoutAnalyticsMetadata = (metadata, plan) => {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type StorageLike } from './creatorReferral.js';
|
|
2
|
+
export { CREATOR_REFERRAL_PARAM, readCreatorReferralId, rememberCreatorReferralId } from './creatorReferral.js';
|
|
3
|
+
/**
|
|
4
|
+
* Influencers Store creator deals. A buyer who opens a funnel from a creator page arrives with
|
|
5
|
+
* `?is_ref=<referral id>`. The funnel shows that creator's deal (who recommended the app and the
|
|
6
|
+
* discount) and passes `couponId` to checkout; the API also applies it on its own, so the deal
|
|
7
|
+
* holds even if a funnel never shows it.
|
|
8
|
+
*/
|
|
9
|
+
export type CreatorDeal = {
|
|
10
|
+
referralId: string;
|
|
11
|
+
couponId: string;
|
|
12
|
+
discountPercent: number;
|
|
13
|
+
appName: string;
|
|
14
|
+
creator: {
|
|
15
|
+
name: string;
|
|
16
|
+
handle: string;
|
|
17
|
+
avatarUrl: string | null;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/** Reads the creator deal from the FunnelsGrove API; null when there is none or the request fails. */
|
|
21
|
+
export declare const fetchCreatorDeal: (input: {
|
|
22
|
+
apiBaseUrl: string;
|
|
23
|
+
funnelId: string;
|
|
24
|
+
referralId: string;
|
|
25
|
+
fetchImpl?: typeof fetch;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
}) => Promise<CreatorDeal | null>;
|
|
28
|
+
export type CreatorCodeResult = {
|
|
29
|
+
ok: true;
|
|
30
|
+
referralId: string;
|
|
31
|
+
creator: CreatorDeal['creator'];
|
|
32
|
+
deal: CreatorDeal | null;
|
|
33
|
+
} | {
|
|
34
|
+
ok: false;
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* A creator's promo code typed on the paywall. On success the referral is remembered, so checkout
|
|
39
|
+
* credits the creator and applies their deal, exactly like arriving from their page.
|
|
40
|
+
*/
|
|
41
|
+
export declare const redeemCreatorCode: (input: {
|
|
42
|
+
apiBaseUrl: string;
|
|
43
|
+
funnelId: string;
|
|
44
|
+
code: string;
|
|
45
|
+
fetchImpl?: typeof fetch;
|
|
46
|
+
storage?: StorageLike | null;
|
|
47
|
+
}) => Promise<CreatorCodeResult>;
|
|
48
|
+
export type CreatorDealState = {
|
|
49
|
+
deal: CreatorDeal | null;
|
|
50
|
+
loading: boolean;
|
|
51
|
+
applyDeal: (deal: CreatorDeal | null) => void;
|
|
52
|
+
};
|
|
53
|
+
/** The creator deal for this visit, loaded once in the browser. */
|
|
54
|
+
export declare const useCreatorDeal: (input: {
|
|
55
|
+
apiBaseUrl: string | null | undefined;
|
|
56
|
+
funnelId: string | null | undefined;
|
|
57
|
+
}) => CreatorDealState;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import { readCreatorReferralId, rememberCreatorReferralId } from './creatorReferral.js';
|
|
4
|
+
export { CREATOR_REFERRAL_PARAM, readCreatorReferralId, rememberCreatorReferralId } from './creatorReferral.js';
|
|
5
|
+
const isDeal = (value) => {
|
|
6
|
+
const deal = value;
|
|
7
|
+
return Boolean(deal) && typeof deal.couponId === 'string' && typeof deal.discountPercent === 'number'
|
|
8
|
+
&& deal.discountPercent > 0 && Boolean(deal.creator) && typeof deal.creator.handle === 'string';
|
|
9
|
+
};
|
|
10
|
+
/** Reads the creator deal from the FunnelsGrove API; null when there is none or the request fails. */
|
|
11
|
+
export const fetchCreatorDeal = async (input) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const url = `${input.apiBaseUrl.replace(/\/+$/, '')}/sdk/public/funnels/${encodeURIComponent(input.funnelId)}/creator-deal?ref=${encodeURIComponent(input.referralId)}`;
|
|
14
|
+
try {
|
|
15
|
+
const response = await ((_a = input.fetchImpl) !== null && _a !== void 0 ? _a : fetch)(url, { signal: input.signal, credentials: 'omit' });
|
|
16
|
+
if (!response.ok)
|
|
17
|
+
return null;
|
|
18
|
+
const body = (await response.json());
|
|
19
|
+
return isDeal(body.deal) ? body.deal : null;
|
|
20
|
+
}
|
|
21
|
+
catch (_b) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A creator's promo code typed on the paywall. On success the referral is remembered, so checkout
|
|
27
|
+
* credits the creator and applies their deal, exactly like arriving from their page.
|
|
28
|
+
*/
|
|
29
|
+
export const redeemCreatorCode = async (input) => {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
const url = `${input.apiBaseUrl.replace(/\/+$/, '')}/sdk/public/funnels/${encodeURIComponent(input.funnelId)}/creator-code`;
|
|
32
|
+
try {
|
|
33
|
+
const response = await ((_a = input.fetchImpl) !== null && _a !== void 0 ? _a : fetch)(url, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: { 'content-type': 'application/json' },
|
|
36
|
+
body: JSON.stringify({ code: input.code }),
|
|
37
|
+
credentials: 'omit',
|
|
38
|
+
});
|
|
39
|
+
const body = (await response.json().catch(() => ({})));
|
|
40
|
+
if (!response.ok || typeof body.referralId !== 'string') {
|
|
41
|
+
const message = typeof ((_b = body.error) === null || _b === void 0 ? void 0 : _b.message) === 'string' ? body.error.message : typeof body.message === 'string' ? body.message : 'This code does not work';
|
|
42
|
+
return { ok: false, message };
|
|
43
|
+
}
|
|
44
|
+
rememberCreatorReferralId(body.referralId, { storage: input.storage });
|
|
45
|
+
return { ok: true, referralId: body.referralId, creator: body.creator, deal: isDeal(body.deal) ? body.deal : null };
|
|
46
|
+
}
|
|
47
|
+
catch (_c) {
|
|
48
|
+
return { ok: false, message: 'Could not check the code. Try again.' };
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
/** The creator deal for this visit, loaded once in the browser. */
|
|
52
|
+
export const useCreatorDeal = (input) => {
|
|
53
|
+
const [state, setState] = useState({ deal: null, loading: true });
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const referralId = readCreatorReferralId();
|
|
56
|
+
const controller = new AbortController();
|
|
57
|
+
const load = referralId && input.apiBaseUrl && input.funnelId
|
|
58
|
+
? fetchCreatorDeal({ apiBaseUrl: input.apiBaseUrl, funnelId: input.funnelId, referralId, signal: controller.signal })
|
|
59
|
+
: Promise.resolve(null);
|
|
60
|
+
void load.then((deal) => { if (!controller.signal.aborted)
|
|
61
|
+
setState({ deal, loading: false }); });
|
|
62
|
+
return () => controller.abort();
|
|
63
|
+
}, [input.apiBaseUrl, input.funnelId]);
|
|
64
|
+
const applyDeal = useCallback((deal) => setState({ deal, loading: false }), []);
|
|
65
|
+
return Object.assign(Object.assign({}, state), { applyDeal });
|
|
66
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const CREATOR_REFERRAL_PARAM = "is_ref";
|
|
2
|
+
export type StorageLike = Pick<Storage, 'getItem' | 'setItem'>;
|
|
3
|
+
/**
|
|
4
|
+
* The referral from the current URL, else the one remembered from an earlier page of the funnel
|
|
5
|
+
* (last click wins, kept 30 days). Null outside the browser or without a referral.
|
|
6
|
+
*/
|
|
7
|
+
export declare const readCreatorReferralId: (input?: {
|
|
8
|
+
search?: string;
|
|
9
|
+
storage?: StorageLike | null;
|
|
10
|
+
now?: number;
|
|
11
|
+
}) => string | null;
|
|
12
|
+
/** Remembers a referral (from a redeemed creator code) like an `is_ref` link visit. */
|
|
13
|
+
export declare const rememberCreatorReferralId: (referralId: string, input?: {
|
|
14
|
+
storage?: StorageLike | null;
|
|
15
|
+
now?: number;
|
|
16
|
+
}) => void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Influencers Store referral memory, shared by the creator deal hook and checkout metadata.
|
|
3
|
+
* No React here: checkout code imports it on the server too.
|
|
4
|
+
*/
|
|
5
|
+
export const CREATOR_REFERRAL_PARAM = 'is_ref';
|
|
6
|
+
const STORAGE_KEY = 'fg_creator_ref';
|
|
7
|
+
const REMEMBER_MS = 30 * 24 * 60 * 60 * 1000;
|
|
8
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
9
|
+
const browserStorage = () => {
|
|
10
|
+
try {
|
|
11
|
+
return typeof window === 'undefined' ? null : window.localStorage;
|
|
12
|
+
}
|
|
13
|
+
catch (_a) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The referral from the current URL, else the one remembered from an earlier page of the funnel
|
|
19
|
+
* (last click wins, kept 30 days). Null outside the browser or without a referral.
|
|
20
|
+
*/
|
|
21
|
+
export const readCreatorReferralId = (input = {}) => {
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
23
|
+
// Never let referral memory break a checkout: partial browser globals read as no referral.
|
|
24
|
+
const search = (_a = input.search) !== null && _a !== void 0 ? _a : (typeof window === 'undefined' ? '' : (_c = (_b = window.location) === null || _b === void 0 ? void 0 : _b.search) !== null && _c !== void 0 ? _c : '');
|
|
25
|
+
const storage = input.storage === undefined ? browserStorage() : input.storage;
|
|
26
|
+
const now = (_d = input.now) !== null && _d !== void 0 ? _d : Date.now();
|
|
27
|
+
const fromUrl = (_f = (_e = new URLSearchParams(search).get(CREATOR_REFERRAL_PARAM)) === null || _e === void 0 ? void 0 : _e.trim()) !== null && _f !== void 0 ? _f : '';
|
|
28
|
+
if (UUID.test(fromUrl)) {
|
|
29
|
+
try {
|
|
30
|
+
storage === null || storage === void 0 ? void 0 : storage.setItem(STORAGE_KEY, JSON.stringify({ id: fromUrl, at: now }));
|
|
31
|
+
}
|
|
32
|
+
catch ( /* storage full or blocked */_h) { /* storage full or blocked */ }
|
|
33
|
+
return fromUrl;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const stored = JSON.parse((_g = storage === null || storage === void 0 ? void 0 : storage.getItem(STORAGE_KEY)) !== null && _g !== void 0 ? _g : 'null');
|
|
37
|
+
return stored && typeof stored.id === 'string' && UUID.test(stored.id) && typeof stored.at === 'number' && now - stored.at < REMEMBER_MS
|
|
38
|
+
? stored.id
|
|
39
|
+
: null;
|
|
40
|
+
}
|
|
41
|
+
catch (_j) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/** Remembers a referral (from a redeemed creator code) like an `is_ref` link visit. */
|
|
46
|
+
export const rememberCreatorReferralId = (referralId, input = {}) => {
|
|
47
|
+
var _a;
|
|
48
|
+
const storage = input.storage === undefined ? browserStorage() : input.storage;
|
|
49
|
+
if (!UUID.test(referralId))
|
|
50
|
+
return;
|
|
51
|
+
try {
|
|
52
|
+
storage === null || storage === void 0 ? void 0 : storage.setItem(STORAGE_KEY, JSON.stringify({ id: referralId, at: (_a = input.now) !== null && _a !== void 0 ? _a : Date.now() }));
|
|
53
|
+
}
|
|
54
|
+
catch ( /* storage full or blocked */_b) { /* storage full or blocked */ }
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funnelsgrove/payments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.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.33.0",
|
|
50
|
+
"@funnelsgrove/analytics": "0.15.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@funnelsgrove/runtime": "^0.
|
|
54
|
-
"@funnelsgrove/analytics": "^0.
|
|
53
|
+
"@funnelsgrove/runtime": "^0.33.0",
|
|
54
|
+
"@funnelsgrove/analytics": "^0.15.0"
|
|
55
55
|
}
|
|
56
56
|
}
|