@appfunnel-dev/sdk 2.0.0-canary.1 → 2.0.0-canary.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/capabilities-7_hy5f5G.d.cts +114 -0
- package/dist/capabilities-7_hy5f5G.d.ts +114 -0
- package/dist/checkout-7Dy6IedP.d.ts +320 -0
- package/dist/checkout-Dz8cGkB_.d.cts +320 -0
- package/dist/chunk-AKO6XKXP.js +466 -0
- package/dist/chunk-AKO6XKXP.js.map +1 -0
- package/dist/chunk-CY4VBSMX.cjs +106 -0
- package/dist/chunk-CY4VBSMX.cjs.map +1 -0
- package/dist/chunk-JSRKA375.cjs +497 -0
- package/dist/chunk-JSRKA375.cjs.map +1 -0
- package/dist/chunk-LJYLGLFS.cjs +153 -0
- package/dist/chunk-LJYLGLFS.cjs.map +1 -0
- package/dist/chunk-M6U3FNRW.js +99 -0
- package/dist/chunk-M6U3FNRW.js.map +1 -0
- package/dist/chunk-YY375F2B.js +140 -0
- package/dist/chunk-YY375F2B.js.map +1 -0
- package/dist/driver-paddle.cjs +814 -0
- package/dist/driver-paddle.cjs.map +1 -0
- package/dist/driver-paddle.d.cts +10 -0
- package/dist/driver-paddle.d.ts +10 -0
- package/dist/driver-paddle.js +811 -0
- package/dist/driver-paddle.js.map +1 -0
- package/dist/driver-stripe.cjs +2253 -0
- package/dist/driver-stripe.cjs.map +1 -0
- package/dist/driver-stripe.d.cts +8 -0
- package/dist/driver-stripe.d.ts +8 -0
- package/dist/driver-stripe.js +2247 -0
- package/dist/driver-stripe.js.map +1 -0
- package/dist/index.cjs +1962 -811
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +183 -933
- package/dist/index.d.ts +183 -933
- package/dist/index.js +1683 -653
- package/dist/index.js.map +1 -1
- package/dist/manifest-Cr2y1op6.d.cts +814 -0
- package/dist/manifest-Cr2y1op6.d.ts +814 -0
- package/dist/manifest-entry.cjs +312 -0
- package/dist/manifest-entry.cjs.map +1 -0
- package/dist/manifest-entry.d.cts +209 -0
- package/dist/manifest-entry.d.ts +209 -0
- package/dist/manifest-entry.js +198 -0
- package/dist/manifest-entry.js.map +1 -0
- package/package.json +37 -4
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
|
|
31
|
+
// src/commerce/capabilities.ts
|
|
32
|
+
var INLINE_SURFACES = /* @__PURE__ */ new Set([
|
|
33
|
+
"express",
|
|
34
|
+
"element",
|
|
35
|
+
"embedded"
|
|
36
|
+
]);
|
|
37
|
+
function isInlineSurface(surface) {
|
|
38
|
+
return INLINE_SURFACES.has(surface);
|
|
39
|
+
}
|
|
40
|
+
var ON = { purchase: true, wallets: true, offSession: "reliable" };
|
|
41
|
+
var MANAGED = { purchase: true, wallets: true, offSession: "conditional" };
|
|
42
|
+
var ROUTED = { purchase: true, wallets: true, offSession: "conditional" };
|
|
43
|
+
var ALL_UPSELLS = ["subscription", "one-time", "upgrade"];
|
|
44
|
+
var PROVIDER_PROFILES = {
|
|
45
|
+
// PSP; you hold the PaymentMethod and fire your own off-session PaymentIntent on
|
|
46
|
+
// the Elements surfaces (reliable). **Managed** Checkout (`embedded`/`redirect`)
|
|
47
|
+
// upsells too, but as a direct charge against Stripe's vaulted card → conditional.
|
|
48
|
+
// No provider "popup" surface.
|
|
49
|
+
stripe: {
|
|
50
|
+
isMoR: false,
|
|
51
|
+
offSessionUpsells: ALL_UPSELLS,
|
|
52
|
+
tokenModel: "merchant",
|
|
53
|
+
orchestrator: false,
|
|
54
|
+
status: "full",
|
|
55
|
+
surfaces: { express: ON, element: ON, sheet: ON, embedded: MANAGED, redirect: MANAGED }
|
|
56
|
+
},
|
|
57
|
+
// Merchant-of-Record; card entry is always Paddle's frame → no own element/sheet/
|
|
58
|
+
// express. Off-session via subscription one-time charge / collection_mode, but
|
|
59
|
+
// **no 2nd concurrent subscription** (upgrade + one-time only), provider-initiated.
|
|
60
|
+
paddle: {
|
|
61
|
+
isMoR: true,
|
|
62
|
+
offSessionUpsells: ["one-time", "upgrade"],
|
|
63
|
+
tokenModel: "provider",
|
|
64
|
+
orchestrator: false,
|
|
65
|
+
status: "full",
|
|
66
|
+
surfaces: { embedded: ON, popup: ON, redirect: ON }
|
|
67
|
+
},
|
|
68
|
+
// Merchant-of-Record; iframe-only (no raw card field). Off-session works
|
|
69
|
+
// (provider-initiated, async via webhooks). `sheet` = our chrome hosting their embed.
|
|
70
|
+
whop: {
|
|
71
|
+
isMoR: true,
|
|
72
|
+
offSessionUpsells: ALL_UPSELLS,
|
|
73
|
+
tokenModel: "provider",
|
|
74
|
+
orchestrator: false,
|
|
75
|
+
status: "planned",
|
|
76
|
+
surfaces: { embedded: ON, redirect: ON, sheet: ON }
|
|
77
|
+
},
|
|
78
|
+
// Pure orchestrator (PSP-side); Headless renders express/element/sheet/embedded.
|
|
79
|
+
// No hosted redirect page, no popup checkout. Off-session is PSP-conditional —
|
|
80
|
+
// the vault lives with whichever processor Primer routed to (data matches this
|
|
81
|
+
// comment as of 2026-07-02; it previously said conditional but coded reliable).
|
|
82
|
+
primer: {
|
|
83
|
+
isMoR: false,
|
|
84
|
+
offSessionUpsells: ALL_UPSELLS,
|
|
85
|
+
tokenModel: "merchant",
|
|
86
|
+
orchestrator: true,
|
|
87
|
+
status: "planned",
|
|
88
|
+
surfaces: { express: ROUTED, element: ROUTED, sheet: ROUTED, embedded: ROUTED }
|
|
89
|
+
},
|
|
90
|
+
// PSP **and** orchestrator (own acquiring + connectors routing across Stripe/Adyen/
|
|
91
|
+
// PayPal). One Payment Form (element/sheet/embedded) + hosted page + wallet button.
|
|
92
|
+
// Strong native off-session (Recurring API). No popup.
|
|
93
|
+
solidgate: {
|
|
94
|
+
isMoR: false,
|
|
95
|
+
offSessionUpsells: ALL_UPSELLS,
|
|
96
|
+
tokenModel: "merchant",
|
|
97
|
+
orchestrator: true,
|
|
98
|
+
status: "planned",
|
|
99
|
+
surfaces: { express: ON, element: ON, sheet: ON, embedded: ON, redirect: ON }
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
function surfacesFor(provider) {
|
|
103
|
+
return Object.keys(PROVIDER_PROFILES[provider]?.surfaces ?? {});
|
|
104
|
+
}
|
|
105
|
+
function isMerchantOfRecord(provider) {
|
|
106
|
+
return PROVIDER_PROFILES[provider]?.isMoR ?? false;
|
|
107
|
+
}
|
|
108
|
+
function isOrchestrator(provider) {
|
|
109
|
+
return PROVIDER_PROFILES[provider]?.orchestrator ?? false;
|
|
110
|
+
}
|
|
111
|
+
function validateCheckout(provider, surface) {
|
|
112
|
+
const cap = PROVIDER_PROFILES[provider]?.surfaces[surface];
|
|
113
|
+
if (!cap) return { ok: false, reason: `${provider} has no '${surface}' surface` };
|
|
114
|
+
return cap.purchase ? { ok: true } : { ok: false, reason: `'${surface}' can't take a purchase on ${provider}` };
|
|
115
|
+
}
|
|
116
|
+
function validateUpsell(provider, paywallSurface, kind = "subscription") {
|
|
117
|
+
const profile = PROVIDER_PROFILES[provider];
|
|
118
|
+
if (!profile) return { ok: false, reason: `unknown provider '${provider}'` };
|
|
119
|
+
if (!profile.offSessionUpsells.includes(kind)) {
|
|
120
|
+
const can = profile.offSessionUpsells.length ? ` (it supports: ${profile.offSessionUpsells.join(", ")})` : "";
|
|
121
|
+
return { ok: false, reason: `${provider} can't charge a '${kind}' upsell off-session${can}` };
|
|
122
|
+
}
|
|
123
|
+
const cap = profile.surfaces[paywallSurface];
|
|
124
|
+
if (!cap) return { ok: false, reason: `${provider} has no '${paywallSurface}' surface to upsell after` };
|
|
125
|
+
if (cap.offSession === "none") {
|
|
126
|
+
return { ok: false, reason: `a purchase on '${paywallSurface}' retains no chargeable method for an upsell` };
|
|
127
|
+
}
|
|
128
|
+
if (cap.offSession === "conditional") {
|
|
129
|
+
return { ok: true, note: `off-session upsell after ${provider} '${paywallSurface}' may decline \u2014 prefer a reliable surface or wire an on-session fallback` };
|
|
130
|
+
}
|
|
131
|
+
return { ok: true };
|
|
132
|
+
}
|
|
133
|
+
function checkoutError(category, message, extra = {}) {
|
|
134
|
+
const retryable = extra.retryable ?? (category === "authentication_required" || category === "requires_payment_method" || category === "processing_error");
|
|
135
|
+
return { category, message, declineCode: extra.declineCode, retryable };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { INLINE_SURFACES, PROVIDER_PROFILES, __commonJS, __export, __toESM, checkoutError, isInlineSurface, isMerchantOfRecord, isOrchestrator, surfacesFor, validateCheckout, validateUpsell };
|
|
139
|
+
//# sourceMappingURL=chunk-YY375F2B.js.map
|
|
140
|
+
//# sourceMappingURL=chunk-YY375F2B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commerce/capabilities.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBO,IAAM,eAAA,uBAAoD,GAAA,CAAqB;AAAA,EACpF,SAAA;AAAA,EACA,SAAA;AAAA,EACA;AACF,CAAC;AAEM,SAAS,gBAAgB,OAAA,EAAmC;AACjE,EAAA,OAAO,eAAA,CAAgB,IAAI,OAAO,CAAA;AACpC;AAgDA,IAAM,KAAwB,EAAE,QAAA,EAAU,MAAM,OAAA,EAAS,IAAA,EAAM,YAAY,UAAA,EAAW;AAEtF,IAAM,UAA6B,EAAE,QAAA,EAAU,MAAM,OAAA,EAAS,IAAA,EAAM,YAAY,aAAA,EAAc;AAE9F,IAAM,SAA4B,EAAE,QAAA,EAAU,MAAM,OAAA,EAAS,IAAA,EAAM,YAAY,aAAA,EAAc;AAC7F,IAAM,WAAA,GAA4B,CAAC,cAAA,EAAgB,UAAA,EAAY,SAAS,CAAA;AAmBjE,IAAM,iBAAA,GAA+D;AAAA;AAAA;AAAA;AAAA;AAAA,EAK1E,MAAA,EAAQ;AAAA,IACN,KAAA,EAAO,KAAA;AAAA,IAAO,iBAAA,EAAmB,WAAA;AAAA,IAAa,UAAA,EAAY,UAAA;AAAA,IAAY,YAAA,EAAc,KAAA;AAAA,IAAO,MAAA,EAAQ,MAAA;AAAA,IACnG,QAAA,EAAU,EAAE,OAAA,EAAS,EAAA,EAAI,OAAA,EAAS,EAAA,EAAI,KAAA,EAAO,EAAA,EAAI,QAAA,EAAU,OAAA,EAAS,QAAA,EAAU,OAAA;AAAQ,GACxF;AAAA;AA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provider capability matrix + checkout error taxonomy — the PURE half of the\n * checkout seam, extracted from checkout.tsx so it ships through the **manifest\n * entry** (no React): the API's publish validation, the editor, AI authoring, and\n * local dev all run the SAME checks the runtime primitives use (phase-3 §3.1b —\n * \"the SDK ships this as data\"). The React half (driver seam, `useCheckout`,\n * `<Checkout>`/`<Upsell>`) stays in ./checkout, which re-exports everything here.\n */\n\nexport type CheckoutSurface =\n | 'express' // wallet quick-buttons (Apple/Google Pay) — inline\n | 'element' // inline card form — inline\n | 'embedded' // provider-managed inline checkout — inline\n | 'sheet' // bottom-sheet popup — opens on click\n | 'popup' // provider-hosted overlay — opens on click\n | 'redirect' // provider-hosted page — opens on click\n\nexport type CheckoutProvider = 'stripe' | 'paddle' | 'whop' | 'primer' | 'solidgate'\nexport type CheckoutIntent = 'purchase' | 'upsell'\n\n/** Surfaces that render inline (vs. those that open on click). */\nexport const INLINE_SURFACES: ReadonlySet<CheckoutSurface> = new Set<CheckoutSurface>([\n 'express',\n 'element',\n 'embedded',\n])\n\nexport function isInlineSurface(surface: CheckoutSurface): boolean {\n return INLINE_SURFACES.has(surface)\n}\n\n/**\n * The kind of off-session upsell (researched against Funnelfox's changelog, which\n * ships these as distinct features). The discriminating real-world constraint is\n * **stacking a 2nd concurrent subscription** — Paddle can't, SolidGate/Stripe can.\n */\nexport type UpsellKind =\n | 'subscription' // charge a NEW, 2nd concurrent subscription off-session (stacking)\n | 'one-time' // charge a one-time add-on off-session\n | 'upgrade' // change the existing subscription's plan\n\n/** Reliability of an off-session upsell charge AFTER a purchase on a surface. */\nexport type OffSessionReliability =\n | 'reliable' // we hold the saved method (Stripe Elements / SolidGate) or the provider charges it (Paddle / Whop API)\n | 'conditional' // possible but may decline — Stripe **managed** checkout (vault charge, SCA not guaranteed) or an orchestrator's PSP-dependent routing (Primer)\n | 'none'\n\nexport interface SurfaceCapability {\n purchase: boolean\n /** Apple/Google Pay available on this surface. */\n wallets: boolean\n /** Reliability of an off-session upsell after a purchase on this surface. */\n offSession: OffSessionReliability\n}\n\nexport interface ProviderProfile {\n /** Merchant-of-Record (handles tax/compliance) vs. a PSP you settle through. */\n isMoR: boolean\n /** Upsell kinds this provider can charge off-session (one-click, no re-entry). */\n offSessionUpsells: UpsellKind[]\n /** Who charges the saved method off-session: you (PSP) or the provider (MoR/managed). */\n tokenModel: 'merchant' | 'provider'\n /** Routes across multiple processors (Primer; SolidGate also offers this) vs. a single acquirer. */\n orchestrator: boolean\n /**\n * Driver tier (Wave-4 decision, Simon 2026-07-02): `full` = a real driver ships\n * (Stripe, Paddle); `planned` = profile only — authoring/publish validate against\n * it, but no charge path exists yet (Whop, Primer, SolidGate). A new provider\n * becomes buildable by writing a driver; its profile already gates what authors\n * can express, so funnels written today stay valid when the driver lands.\n */\n status: 'full' | 'planned'\n /** Supported surfaces → per-surface capabilities. **Absent = not supported.** */\n surfaces: Partial<Record<CheckoutSurface, SurfaceCapability>>\n}\n\n/** Reliable off-session after this surface (we/the provider hold a chargeable method). */\nconst ON: SurfaceCapability = { purchase: true, wallets: true, offSession: 'reliable' }\n/** Stripe-managed checkout: a purchase works, but the off-session upsell may decline. */\nconst MANAGED: SurfaceCapability = { purchase: true, wallets: true, offSession: 'conditional' }\n/** Orchestrator-routed (Primer): off-session depends on which PSP vaulted the method. */\nconst ROUTED: SurfaceCapability = { purchase: true, wallets: true, offSession: 'conditional' }\nconst ALL_UPSELLS: UpsellKind[] = ['subscription', 'one-time', 'upgrade']\n\n/**\n * Provider capabilities (researched 2026-06-23 against provider docs + Funnelfox;\n * trial mechanics re-verified 2026-07-02, doc 09 §4.4).\n *\n * Three real-world corrections to the naive model:\n * 1. **Off-session upsell support is per-provider by *kind*** (`offSessionUpsells`):\n * Paddle can't stack a 2nd concurrent subscription (upgrade + one-time only);\n * Stripe/SolidGate/Whop/Primer can do all kinds.\n * 2. **Off-session *reliability* varies by the paywall surface** (`SurfaceCapability.\n * offSession`): Stripe **managed** checkout (`embedded`/`redirect`) upsells as a\n * direct charge against Stripe's vault → `conditional` (may decline); Elements\n * surfaces are `reliable`. Primer is `conditional` everywhere (PSP-dependent).\n * 3. **Surface availability is a hard constraint.** MoR/managed providers can't\n * expose a raw card field to your own UI: Paddle has no `express`/`element`/your\n * `sheet`; Whop has no raw `element`/`express`; Primer has no hosted `redirect`;\n * Stripe/SolidGate have no `popup`. A missing entry means \"not possible.\"\n */\nexport const PROVIDER_PROFILES: Record<CheckoutProvider, ProviderProfile> = {\n // PSP; you hold the PaymentMethod and fire your own off-session PaymentIntent on\n // the Elements surfaces (reliable). **Managed** Checkout (`embedded`/`redirect`)\n // upsells too, but as a direct charge against Stripe's vaulted card → conditional.\n // No provider \"popup\" surface.\n stripe: {\n isMoR: false, offSessionUpsells: ALL_UPSELLS, tokenModel: 'merchant', orchestrator: false, status: 'full',\n surfaces: { express: ON, element: ON, sheet: ON, embedded: MANAGED, redirect: MANAGED },\n },\n // Merchant-of-Record; card entry is always Paddle's frame → no own element/sheet/\n // express. Off-session via subscription one-time charge / collection_mode, but\n // **no 2nd concurrent subscription** (upgrade + one-time only), provider-initiated.\n paddle: {\n isMoR: true, offSessionUpsells: ['one-time', 'upgrade'], tokenModel: 'provider', orchestrator: false, status: 'full',\n surfaces: { embedded: ON, popup: ON, redirect: ON },\n },\n // Merchant-of-Record; iframe-only (no raw card field). Off-session works\n // (provider-initiated, async via webhooks). `sheet` = our chrome hosting their embed.\n whop: {\n isMoR: true, offSessionUpsells: ALL_UPSELLS, tokenModel: 'provider', orchestrator: false, status: 'planned',\n surfaces: { embedded: ON, redirect: ON, sheet: ON },\n },\n // Pure orchestrator (PSP-side); Headless renders express/element/sheet/embedded.\n // No hosted redirect page, no popup checkout. Off-session is PSP-conditional —\n // the vault lives with whichever processor Primer routed to (data matches this\n // comment as of 2026-07-02; it previously said conditional but coded reliable).\n primer: {\n isMoR: false, offSessionUpsells: ALL_UPSELLS, tokenModel: 'merchant', orchestrator: true, status: 'planned',\n surfaces: { express: ROUTED, element: ROUTED, sheet: ROUTED, embedded: ROUTED },\n },\n // PSP **and** orchestrator (own acquiring + connectors routing across Stripe/Adyen/\n // PayPal). One Payment Form (element/sheet/embedded) + hosted page + wallet button.\n // Strong native off-session (Recurring API). No popup.\n solidgate: {\n isMoR: false, offSessionUpsells: ALL_UPSELLS, tokenModel: 'merchant', orchestrator: true, status: 'planned',\n surfaces: { express: ON, element: ON, sheet: ON, embedded: ON, redirect: ON },\n },\n}\n\nexport interface ValidationResult {\n ok: boolean\n reason?: string\n /** Non-fatal caveat (e.g. Paddle upgrade-only). */\n note?: string\n}\n\n/** Surfaces a provider supports, for the editor/AI to steer authors. */\nexport function surfacesFor(provider: CheckoutProvider): CheckoutSurface[] {\n return Object.keys(PROVIDER_PROFILES[provider]?.surfaces ?? {}) as CheckoutSurface[]\n}\n\n/** Whether a provider is a Merchant of Record (it owns tax/compliance). */\nexport function isMerchantOfRecord(provider: CheckoutProvider): boolean {\n return PROVIDER_PROFILES[provider]?.isMoR ?? false\n}\n\n/** Whether a provider routes across multiple processors (Primer, SolidGate). */\nexport function isOrchestrator(provider: CheckoutProvider): boolean {\n return PROVIDER_PROFILES[provider]?.orchestrator ?? false\n}\n\n/**\n * Validate a (provider, surface) for a **purchase**: the surface must exist for\n * the provider and accept a payment. Surface availability is the real constraint\n * (e.g. Paddle has no `element`).\n */\nexport function validateCheckout(provider: CheckoutProvider, surface: CheckoutSurface): ValidationResult {\n const cap = PROVIDER_PROFILES[provider]?.surfaces[surface]\n if (!cap) return { ok: false, reason: `${provider} has no '${surface}' surface` }\n return cap.purchase ? { ok: true } : { ok: false, reason: `'${surface}' can't take a purchase on ${provider}` }\n}\n\n/**\n * Validate an **off-session upsell** of `kind` after a purchase made on\n * `paywallSurface`. Combines provider support for the kind (Paddle can't stack a\n * 2nd subscription) with the paywall surface's off-session reliability (Stripe\n * managed checkout is `conditional` — returned as a `note`, not a hard block).\n */\nexport function validateUpsell(\n provider: CheckoutProvider,\n paywallSurface: CheckoutSurface,\n kind: UpsellKind = 'subscription',\n): ValidationResult {\n const profile = PROVIDER_PROFILES[provider]\n if (!profile) return { ok: false, reason: `unknown provider '${provider}'` }\n if (!profile.offSessionUpsells.includes(kind)) {\n const can = profile.offSessionUpsells.length ? ` (it supports: ${profile.offSessionUpsells.join(', ')})` : ''\n return { ok: false, reason: `${provider} can't charge a '${kind}' upsell off-session${can}` }\n }\n const cap = profile.surfaces[paywallSurface]\n if (!cap) return { ok: false, reason: `${provider} has no '${paywallSurface}' surface to upsell after` }\n if (cap.offSession === 'none') {\n return { ok: false, reason: `a purchase on '${paywallSurface}' retains no chargeable method for an upsell` }\n }\n if (cap.offSession === 'conditional') {\n return { ok: true, note: `off-session upsell after ${provider} '${paywallSurface}' may decline — prefer a reliable surface or wire an on-session fallback` }\n }\n return { ok: true }\n}\n\n// ── Checkout error taxonomy (pure — drivers + server both normalize into it) ──\n\n/**\n * Normalized failure category — the driver/platform maps each provider's decline\n * codes into one of these so funnels can route/recover by reason. `authentication_\n * required` (3DS/SCA) and `requires_payment_method` are the cases an **off-session**\n * upsell can't satisfy → recover on-session (re-collect a card).\n */\nexport type CheckoutErrorCategory =\n | 'card_declined'\n | 'insufficient_funds'\n | 'expired_card'\n | 'prepaid_card' // card funding is prepaid — trials/subscriptions commonly decline; route to a real-card recapture page\n | 'authentication_required' // SCA/3DS needed — off-session can't challenge\n | 'requires_payment_method' // no usable saved method\n | 'processing_error'\n | 'canceled'\n | 'unknown'\n\nexport interface CheckoutError {\n category: CheckoutErrorCategory\n message: string\n /** Raw provider decline code, if any (e.g. Stripe `card_declined`/`insufficient_funds`). */\n declineCode?: string\n /** Whether re-attempting (e.g. an on-session re-collection) may succeed. */\n retryable: boolean\n}\n\n/** Build a {@link CheckoutError} (driver/test helper). */\nexport function checkoutError(\n category: CheckoutErrorCategory,\n message: string,\n extra: { declineCode?: string; retryable?: boolean } = {},\n): CheckoutError {\n const retryable = extra.retryable ?? (category === 'authentication_required' || category === 'requires_payment_method' || category === 'processing_error')\n return { category, message, declineCode: extra.declineCode, retryable }\n}\n"]}
|