@appfunnel-dev/sdk 2.0.0-canary.7 → 2.0.0-canary.8
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 → capabilities-CsnkVwna.d.cts} +34 -1
- package/dist/{capabilities-7_hy5f5G.d.ts → capabilities-CsnkVwna.d.ts} +34 -1
- package/dist/{checkout-D1NUPv4p.d.ts → checkout-3PkKwPd7.d.ts} +1 -1
- package/dist/{checkout-CMEdxpgo.d.cts → checkout-Cg20l53c.d.cts} +1 -1
- package/dist/{chunk-VAOR77NW.cjs → chunk-FY3TMSRU.cjs} +7 -7
- package/dist/{chunk-VAOR77NW.cjs.map → chunk-FY3TMSRU.cjs.map} +1 -1
- package/dist/{chunk-CFFMZYPE.js → chunk-PWXMQGO6.js} +3 -3
- package/dist/{chunk-CFFMZYPE.js.map → chunk-PWXMQGO6.js.map} +1 -1
- package/dist/{chunk-TNLRQPVY.js → chunk-RVJLR4RS.js} +36 -8
- package/dist/chunk-RVJLR4RS.js.map +1 -0
- package/dist/{chunk-QMAZGLGV.cjs → chunk-RY3LOSVZ.cjs} +37 -7
- package/dist/chunk-RY3LOSVZ.cjs.map +1 -0
- package/dist/{chunk-7YQLPPPG.js → chunk-VW2HVPR4.js} +7 -2
- package/dist/chunk-VW2HVPR4.js.map +1 -0
- package/dist/{chunk-BPOAWI4G.cjs → chunk-Y4YNJ2EX.cjs} +7 -2
- package/dist/chunk-Y4YNJ2EX.cjs.map +1 -0
- package/dist/driver-paddle.cjs +22 -22
- package/dist/driver-paddle.d.cts +2 -2
- package/dist/driver-paddle.d.ts +2 -2
- package/dist/driver-paddle.js +2 -2
- package/dist/driver-stripe.cjs +24 -24
- package/dist/driver-stripe.d.cts +2 -2
- package/dist/driver-stripe.d.ts +2 -2
- package/dist/driver-stripe.js +2 -2
- package/dist/index.cjs +60 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/{manifest-CMe8yVkr.d.cts → manifest-B3Tdab0M.d.cts} +64 -1
- package/dist/{manifest-CMe8yVkr.d.ts → manifest-B3Tdab0M.d.ts} +64 -1
- package/dist/manifest-entry.cjs +100 -31
- package/dist/manifest-entry.cjs.map +1 -1
- package/dist/manifest-entry.d.cts +9 -26
- package/dist/manifest-entry.d.ts +9 -26
- package/dist/manifest-entry.js +64 -3
- package/dist/manifest-entry.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-7YQLPPPG.js.map +0 -1
- package/dist/chunk-BPOAWI4G.cjs.map +0 -1
- package/dist/chunk-QMAZGLGV.cjs.map +0 -1
- package/dist/chunk-TNLRQPVY.js.map +0 -1
|
@@ -26,7 +26,26 @@ interface SurfaceCapability {
|
|
|
26
26
|
wallets: boolean;
|
|
27
27
|
/** Reliability of an off-session upsell after a purchase on this surface. */
|
|
28
28
|
offSession: OffSessionReliability;
|
|
29
|
+
/**
|
|
30
|
+
* Per-surface DRIVER readiness. Absent = renderable now (the provider's driver mounts it).
|
|
31
|
+
* `'planned'` = the provider genuinely ships this surface (cite it in the profile) but OUR
|
|
32
|
+
* driver doesn't render it yet — publish validation FAILS CLOSED on it so we never promise a
|
|
33
|
+
* surface the runtime can't produce. Mirrors the provider-level {@link ProviderProfile.status}
|
|
34
|
+
* seam at surface granularity: implement the driver, drop the flag, and it flips on cleanly.
|
|
35
|
+
*/
|
|
36
|
+
driver?: 'planned';
|
|
29
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* How a provider composes a TRIAL — the scattered provider `if`s made a matrix dimension
|
|
40
|
+
* (§7 item 4). Stripe trials are **composed** (a separate fee/vault step precedes the sub);
|
|
41
|
+
* Paddle trials are **native** (the price itself carries the trial, MoR collects up front):
|
|
42
|
+
* - `paid_composed` — Stripe: trial-fee PaymentIntent → subscription with `trial_period_days`.
|
|
43
|
+
* - `free_vault` — Stripe: SetupIntent vaults the card (no charge) → trial subscription.
|
|
44
|
+
* - `paid_native` — Paddle: the price carries the paid trial; one item, collected up front.
|
|
45
|
+
* - `free_native` — Paddle: native free trial on the price.
|
|
46
|
+
* A provider with an EMPTY `trialShapes` can't run a trial offer (planned providers → fail closed).
|
|
47
|
+
*/
|
|
48
|
+
type TrialShape = 'paid_composed' | 'free_vault' | 'paid_native' | 'free_native';
|
|
30
49
|
interface ProviderProfile {
|
|
31
50
|
/** Merchant-of-Record (handles tax/compliance) vs. a PSP you settle through. */
|
|
32
51
|
isMoR: boolean;
|
|
@@ -44,6 +63,11 @@ interface ProviderProfile {
|
|
|
44
63
|
* can express, so funnels written today stay valid when the driver lands.
|
|
45
64
|
*/
|
|
46
65
|
status: 'full' | 'planned';
|
|
66
|
+
/**
|
|
67
|
+
* TRIAL shapes this provider can run (§7 item 4). Empty = no trial path (fail closed at
|
|
68
|
+
* publish — a paid/free-trial funnel on this provider can't be produced yet).
|
|
69
|
+
*/
|
|
70
|
+
trialShapes: TrialShape[];
|
|
47
71
|
/** Supported surfaces → per-surface capabilities. **Absent = not supported.** */
|
|
48
72
|
surfaces: Partial<Record<CheckoutSurface, SurfaceCapability>>;
|
|
49
73
|
}
|
|
@@ -83,6 +107,15 @@ declare function isOrchestrator(provider: CheckoutProvider): boolean;
|
|
|
83
107
|
* (e.g. Paddle has no `element`).
|
|
84
108
|
*/
|
|
85
109
|
declare function validateCheckout(provider: CheckoutProvider, surface: CheckoutSurface): ValidationResult;
|
|
110
|
+
/** Trial shapes a provider can compose (empty = it can't run a trial offer yet). */
|
|
111
|
+
declare function trialShapesFor(provider: CheckoutProvider): TrialShape[];
|
|
112
|
+
/**
|
|
113
|
+
* Validate that a provider can run a TRIAL (§7 item 4). Pass a specific {@link TrialShape} to
|
|
114
|
+
* check that exact shape; omit it to assert the provider supports *any* trial (the cheap gate
|
|
115
|
+
* check when only the offering's TRIAL-role binding existence is known). A provider with no
|
|
116
|
+
* trial shapes (every planned provider) fails closed.
|
|
117
|
+
*/
|
|
118
|
+
declare function validateTrial(provider: CheckoutProvider, shape?: TrialShape): ValidationResult;
|
|
86
119
|
/**
|
|
87
120
|
* Validate an **off-session upsell** of `kind` after a purchase made on
|
|
88
121
|
* `paywallSurface`. Combines provider support for the kind (Paddle can't stack a
|
|
@@ -111,4 +144,4 @@ declare function checkoutError(category: CheckoutErrorCategory, message: string,
|
|
|
111
144
|
retryable?: boolean;
|
|
112
145
|
}): CheckoutError;
|
|
113
146
|
|
|
114
|
-
export { type CheckoutError as C, INLINE_SURFACES as I, type OffSessionReliability as O, PROVIDER_PROFILES as P, type SurfaceCapability as S, type UpsellKind as U, type ValidationResult as V, type CheckoutErrorCategory as a, type CheckoutIntent as b, type CheckoutProvider as c, type CheckoutSurface as d, type ProviderProfile as e, checkoutError as f, isMerchantOfRecord as g, isOrchestrator as h, isInlineSurface as i, validateUpsell as j, surfacesFor as s, validateCheckout as v };
|
|
147
|
+
export { type CheckoutError as C, INLINE_SURFACES as I, type OffSessionReliability as O, PROVIDER_PROFILES as P, type SurfaceCapability as S, type TrialShape as T, type UpsellKind as U, type ValidationResult as V, type CheckoutErrorCategory as a, type CheckoutIntent as b, type CheckoutProvider as c, type CheckoutSurface as d, type ProviderProfile as e, checkoutError as f, isMerchantOfRecord as g, isOrchestrator as h, isInlineSurface as i, validateUpsell as j, validateTrial as k, surfacesFor as s, trialShapesFor as t, validateCheckout as v };
|
|
@@ -26,7 +26,26 @@ interface SurfaceCapability {
|
|
|
26
26
|
wallets: boolean;
|
|
27
27
|
/** Reliability of an off-session upsell after a purchase on this surface. */
|
|
28
28
|
offSession: OffSessionReliability;
|
|
29
|
+
/**
|
|
30
|
+
* Per-surface DRIVER readiness. Absent = renderable now (the provider's driver mounts it).
|
|
31
|
+
* `'planned'` = the provider genuinely ships this surface (cite it in the profile) but OUR
|
|
32
|
+
* driver doesn't render it yet — publish validation FAILS CLOSED on it so we never promise a
|
|
33
|
+
* surface the runtime can't produce. Mirrors the provider-level {@link ProviderProfile.status}
|
|
34
|
+
* seam at surface granularity: implement the driver, drop the flag, and it flips on cleanly.
|
|
35
|
+
*/
|
|
36
|
+
driver?: 'planned';
|
|
29
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* How a provider composes a TRIAL — the scattered provider `if`s made a matrix dimension
|
|
40
|
+
* (§7 item 4). Stripe trials are **composed** (a separate fee/vault step precedes the sub);
|
|
41
|
+
* Paddle trials are **native** (the price itself carries the trial, MoR collects up front):
|
|
42
|
+
* - `paid_composed` — Stripe: trial-fee PaymentIntent → subscription with `trial_period_days`.
|
|
43
|
+
* - `free_vault` — Stripe: SetupIntent vaults the card (no charge) → trial subscription.
|
|
44
|
+
* - `paid_native` — Paddle: the price carries the paid trial; one item, collected up front.
|
|
45
|
+
* - `free_native` — Paddle: native free trial on the price.
|
|
46
|
+
* A provider with an EMPTY `trialShapes` can't run a trial offer (planned providers → fail closed).
|
|
47
|
+
*/
|
|
48
|
+
type TrialShape = 'paid_composed' | 'free_vault' | 'paid_native' | 'free_native';
|
|
30
49
|
interface ProviderProfile {
|
|
31
50
|
/** Merchant-of-Record (handles tax/compliance) vs. a PSP you settle through. */
|
|
32
51
|
isMoR: boolean;
|
|
@@ -44,6 +63,11 @@ interface ProviderProfile {
|
|
|
44
63
|
* can express, so funnels written today stay valid when the driver lands.
|
|
45
64
|
*/
|
|
46
65
|
status: 'full' | 'planned';
|
|
66
|
+
/**
|
|
67
|
+
* TRIAL shapes this provider can run (§7 item 4). Empty = no trial path (fail closed at
|
|
68
|
+
* publish — a paid/free-trial funnel on this provider can't be produced yet).
|
|
69
|
+
*/
|
|
70
|
+
trialShapes: TrialShape[];
|
|
47
71
|
/** Supported surfaces → per-surface capabilities. **Absent = not supported.** */
|
|
48
72
|
surfaces: Partial<Record<CheckoutSurface, SurfaceCapability>>;
|
|
49
73
|
}
|
|
@@ -83,6 +107,15 @@ declare function isOrchestrator(provider: CheckoutProvider): boolean;
|
|
|
83
107
|
* (e.g. Paddle has no `element`).
|
|
84
108
|
*/
|
|
85
109
|
declare function validateCheckout(provider: CheckoutProvider, surface: CheckoutSurface): ValidationResult;
|
|
110
|
+
/** Trial shapes a provider can compose (empty = it can't run a trial offer yet). */
|
|
111
|
+
declare function trialShapesFor(provider: CheckoutProvider): TrialShape[];
|
|
112
|
+
/**
|
|
113
|
+
* Validate that a provider can run a TRIAL (§7 item 4). Pass a specific {@link TrialShape} to
|
|
114
|
+
* check that exact shape; omit it to assert the provider supports *any* trial (the cheap gate
|
|
115
|
+
* check when only the offering's TRIAL-role binding existence is known). A provider with no
|
|
116
|
+
* trial shapes (every planned provider) fails closed.
|
|
117
|
+
*/
|
|
118
|
+
declare function validateTrial(provider: CheckoutProvider, shape?: TrialShape): ValidationResult;
|
|
86
119
|
/**
|
|
87
120
|
* Validate an **off-session upsell** of `kind` after a purchase made on
|
|
88
121
|
* `paywallSurface`. Combines provider support for the kind (Paddle can't stack a
|
|
@@ -111,4 +144,4 @@ declare function checkoutError(category: CheckoutErrorCategory, message: string,
|
|
|
111
144
|
retryable?: boolean;
|
|
112
145
|
}): CheckoutError;
|
|
113
146
|
|
|
114
|
-
export { type CheckoutError as C, INLINE_SURFACES as I, type OffSessionReliability as O, PROVIDER_PROFILES as P, type SurfaceCapability as S, type UpsellKind as U, type ValidationResult as V, type CheckoutErrorCategory as a, type CheckoutIntent as b, type CheckoutProvider as c, type CheckoutSurface as d, type ProviderProfile as e, checkoutError as f, isMerchantOfRecord as g, isOrchestrator as h, isInlineSurface as i, validateUpsell as j, surfacesFor as s, validateCheckout as v };
|
|
147
|
+
export { type CheckoutError as C, INLINE_SURFACES as I, type OffSessionReliability as O, PROVIDER_PROFILES as P, type SurfaceCapability as S, type TrialShape as T, type UpsellKind as U, type ValidationResult as V, type CheckoutErrorCategory as a, type CheckoutIntent as b, type CheckoutProvider as c, type CheckoutSurface as d, type ProviderProfile as e, checkoutError as f, isMerchantOfRecord as g, isOrchestrator as h, isInlineSurface as i, validateUpsell as j, validateTrial as k, surfacesFor as s, trialShapesFor as t, validateCheckout as v };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode, ComponentType } from 'react';
|
|
2
|
-
import { c as CheckoutProvider, b as CheckoutIntent, d as CheckoutSurface, U as UpsellKind, C as CheckoutError, a as CheckoutErrorCategory } from './capabilities-
|
|
2
|
+
import { c as CheckoutProvider, b as CheckoutIntent, d as CheckoutSurface, U as UpsellKind, C as CheckoutError, a as CheckoutErrorCategory } from './capabilities-CsnkVwna.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* v2 commerce primitives — the two intents from phase-3, made trivial.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode, ComponentType } from 'react';
|
|
2
|
-
import { c as CheckoutProvider, b as CheckoutIntent, d as CheckoutSurface, U as UpsellKind, C as CheckoutError, a as CheckoutErrorCategory } from './capabilities-
|
|
2
|
+
import { c as CheckoutProvider, b as CheckoutIntent, d as CheckoutSurface, U as UpsellKind, C as CheckoutError, a as CheckoutErrorCategory } from './capabilities-CsnkVwna.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* v2 commerce primitives — the two intents from phase-3, made trivial.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkRY3LOSVZ_cjs = require('./chunk-RY3LOSVZ.cjs');
|
|
4
4
|
|
|
5
5
|
// src/drivers/wire.ts
|
|
6
6
|
function endpoint(ctx, path = "") {
|
|
@@ -13,14 +13,14 @@ async function postJson(url, body) {
|
|
|
13
13
|
headers: { "content-type": "application/json" },
|
|
14
14
|
body: JSON.stringify(body)
|
|
15
15
|
});
|
|
16
|
-
if (!res.ok) throw
|
|
16
|
+
if (!res.ok) throw chunkRY3LOSVZ_cjs.checkoutError("processing_error", `checkout request failed (HTTP ${res.status})`);
|
|
17
17
|
return await res.json();
|
|
18
18
|
}
|
|
19
19
|
function toCheckoutError(e) {
|
|
20
20
|
if (e && typeof e === "object" && "category" in e && "message" in e && "retryable" in e) {
|
|
21
21
|
return e;
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return chunkRY3LOSVZ_cjs.checkoutError("processing_error", e instanceof Error ? e.message : "Checkout request failed");
|
|
24
24
|
}
|
|
25
25
|
function postSession(ctx, req, correlationId) {
|
|
26
26
|
const body = {
|
|
@@ -69,7 +69,7 @@ async function completeWithPoll(ctx, correlationId, opts = {}) {
|
|
|
69
69
|
}
|
|
70
70
|
return {
|
|
71
71
|
ok: false,
|
|
72
|
-
error:
|
|
72
|
+
error: chunkRY3LOSVZ_cjs.checkoutError(
|
|
73
73
|
"processing_error",
|
|
74
74
|
opts.timeoutMessage ?? "The payment has not been confirmed yet \u2014 please check back shortly.",
|
|
75
75
|
// `completion_timeout` marks "the poll ran out while the attempt was still
|
|
@@ -87,7 +87,7 @@ function leaveForRedirect(url) {
|
|
|
87
87
|
window.removeEventListener("pageshow", onPageshow);
|
|
88
88
|
resolve({
|
|
89
89
|
ok: false,
|
|
90
|
-
error:
|
|
90
|
+
error: chunkRY3LOSVZ_cjs.checkoutError("canceled", "Returned from the hosted checkout without completing")
|
|
91
91
|
});
|
|
92
92
|
};
|
|
93
93
|
window.addEventListener("pageshow", onPageshow);
|
|
@@ -102,5 +102,5 @@ exports.postComplete = postComplete;
|
|
|
102
102
|
exports.postSession = postSession;
|
|
103
103
|
exports.settlementToResult = settlementToResult;
|
|
104
104
|
exports.toCheckoutError = toCheckoutError;
|
|
105
|
-
//# sourceMappingURL=chunk-
|
|
106
|
-
//# sourceMappingURL=chunk-
|
|
105
|
+
//# sourceMappingURL=chunk-FY3TMSRU.cjs.map
|
|
106
|
+
//# sourceMappingURL=chunk-FY3TMSRU.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/drivers/wire.ts"],"names":["checkoutError"],"mappings":";;;;;AAqBA,SAAS,QAAA,CAAS,GAAA,EAA4B,IAAA,GAAO,EAAA,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A,IAAA,MAAA,CAAO,QAAA,CAAS,OAAO,GAAG,CAAA;AAAA,EAC5B,CAAC,CAAA;AACH","file":"chunk-VAOR77NW.cjs","sourcesContent":["/**\n * Shared wire plumbing for the checkout drivers — the CLIENT half of the v2\n * checkout contract (commerce/checkout-api.ts). Lives under drivers/ (not\n * commerce/) on purpose: it ships only inside the `driver-*` subpath entries,\n * so the core funnel entry never bundles a checkout fetch — the core SDK talks\n * to a {@link CheckoutDriver}, never to the wire.\n *\n * Only `import type` from commerce/checkout(.tsx) here — a runtime import would\n * drag the React checkout primitives into every driver chunk. The one runtime\n * dependency is the pure error taxonomy (capabilities.ts).\n */\nimport type {\n CheckoutCompleteRequest,\n CheckoutCompleteResponse,\n CheckoutSessionRequest,\n CheckoutSessionResponse,\n CheckoutSettlement,\n} from '../commerce/checkout-api'\nimport type { CheckoutDriverContext, CheckoutRequest, CheckoutResult } from '../commerce/checkout'\nimport { checkoutError, type CheckoutError } from '../commerce/capabilities'\n\nfunction endpoint(ctx: CheckoutDriverContext, path = ''): string {\n const base = ctx.apiBase.replace(/\\/+$/, '')\n return `${base}/campaign/${encodeURIComponent(ctx.campaignId)}/v2/checkout${path}`\n}\n\nasync function postJson<T>(url: string, body: unknown): Promise<T> {\n const res = await fetch(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body),\n })\n // The contract speaks in `step` responses, not HTTP errors — a non-2xx means the\n // request never reached the checkout service properly (proxy, deploy, outage).\n if (!res.ok) throw checkoutError('processing_error', `checkout request failed (HTTP ${res.status})`)\n return (await res.json()) as T\n}\n\n/** Normalize any thrown value into the taxonomy (network drops → `processing_error`). */\nexport function toCheckoutError(e: unknown): CheckoutError {\n if (e && typeof e === 'object' && 'category' in e && 'message' in e && 'retryable' in e) {\n return e as CheckoutError\n }\n return checkoutError('processing_error', e instanceof Error ? e.message : 'Checkout request failed')\n}\n\n/**\n * Open a checkout attempt: `POST {apiBase}/campaign/{campaignId}/v2/checkout`.\n * The correlationId is client-minted per ATTEMPT (idempotency key + the id the\n * server stamps into provider metadata) — mint it once, reuse it on retries.\n */\nexport function postSession(\n ctx: CheckoutDriverContext,\n req: CheckoutRequest,\n correlationId: string,\n): Promise<CheckoutSessionResponse> {\n const body: CheckoutSessionRequest = {\n funnelId: ctx.funnelId,\n mode: ctx.mode,\n // The CHARGE identity is the catalog key (resolved from the slot by driverWithCatalog); fall back\n // to `product` for legacy builds where the page named the catalog key directly.\n productKey: req.catalogKey ?? req.product,\n intent: req.intent,\n kind: req.kind,\n // null (not absent) = explicit off-session — the server validates surfaces\n // against the capability matrix, so never let one default in transit.\n surface: req.surface ?? null,\n sessionId: ctx.sessionId ?? undefined,\n visitorId: ctx.visitorId ?? undefined,\n // Buyer email collected by the funnel (user.email) — Stripe Customer creation,\n // receipts, Paddle prefill. Injected at attempt time by the FunnelProvider seam.\n email: req.email,\n correlationId,\n }\n return postJson<CheckoutSessionResponse>(endpoint(ctx), body)\n}\n\n/** Ask the server to VERIFY with the provider and write the money facts (idempotent). */\nexport function postComplete(\n ctx: CheckoutDriverContext,\n correlationId: string,\n providerRef?: string,\n): Promise<CheckoutCompleteResponse> {\n const body: CheckoutCompleteRequest = { providerRef }\n return postJson<CheckoutCompleteResponse>(\n endpoint(ctx, `/${encodeURIComponent(correlationId)}/complete`),\n body,\n )\n}\n\n/** Server settlement → the SDK's CheckoutResult (eventId passes through for pixel dedup). */\nexport function settlementToResult(s: CheckoutSettlement): CheckoutResult {\n return { ok: true, amountMinor: s.amountMinor, currency: s.currency, eventId: s.eventId }\n}\n\nexport interface CompletePollOptions {\n providerRef?: string\n /** Total complete attempts before giving up (default 5). */\n attempts?: number\n /** Delay between attempts (default 2000ms). */\n intervalMs?: number\n /** Error message when the provider hasn't confirmed inside the window (MoR/async). */\n timeoutMessage?: string\n}\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))\n\n/**\n * Complete with a bounded poll. Sync providers (Stripe) settle on the first\n * attempt — the server verifies against the provider inline. MoR/async providers\n * (Paddle) settle via webhook, so `pending` is normal: re-poll a few times, then\n * stop holding the UI hostage — the charge may still land server-side, which is\n * why the timeout error is `retryable` and the message should say the receipt\n * can still arrive (the server's money facts don't depend on this browser).\n */\nexport async function completeWithPoll(\n ctx: CheckoutDriverContext,\n correlationId: string,\n opts: CompletePollOptions = {},\n): Promise<CheckoutResult> {\n const attempts = opts.attempts ?? 5\n const intervalMs = opts.intervalMs ?? 2000\n try {\n for (let i = 0; i < attempts; i++) {\n const res = await postComplete(ctx, correlationId, opts.providerRef)\n if (res.step === 'settled') return settlementToResult(res.result)\n if (res.step === 'failed') return { ok: false, error: res.error }\n if (i < attempts - 1) await sleep(intervalMs)\n }\n } catch (e) {\n return { ok: false, error: toCheckoutError(e) }\n }\n return {\n ok: false,\n error: checkoutError(\n 'processing_error',\n opts.timeoutMessage ?? 'The payment has not been confirmed yet — please check back shortly.',\n // `completion_timeout` marks \"the poll ran out while the attempt was still\n // pending\" — drivers key double-charge guards on it (the attempt may still\n // settle server-side; it was never refused).\n { retryable: true, declineCode: 'completion_timeout' },\n ),\n }\n}\n\n/**\n * The `redirect` step hand-off: navigate to the provider-hosted page and return a\n * promise that settles ONLY if the buyer comes back to this very page. The page\n * is leaving — resolving early would fire `purchase.complete`/navigation for a\n * charge that hasn't happened, and rejecting would flash an error during the\n * (successful) hand-off — so while the navigation proceeds the promise stays\n * pending and `useCheckout` stays in `loading`, the truthful UI for a page\n * mid-navigation. The hosted page's SUCCESS return URL re-enters the funnel with\n * `af_checkout={correlationId}` (a fresh load — this promise is gone; the SDK's\n * resume leg settles the attempt).\n *\n * The one way THIS page comes back to life is a bfcache restore (browser Back\n * from the hosted page): `pageshow` with `persisted: true`. That is a buyer who\n * abandoned the hosted checkout — resolve `canceled` so the trigger re-enables\n * and inline redirect placeholders recover instead of spinning forever.\n */\nexport function leaveForRedirect(url: string): Promise<CheckoutResult> {\n return new Promise<CheckoutResult>((resolve) => {\n if (typeof window !== 'undefined') {\n const onPageshow = (event: PageTransitionEvent) => {\n if (!event.persisted) return\n window.removeEventListener('pageshow', onPageshow)\n resolve({\n ok: false,\n error: checkoutError('canceled', 'Returned from the hosted checkout without completing'),\n })\n }\n window.addEventListener('pageshow', onPageshow)\n }\n window.location.assign(url)\n })\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/drivers/wire.ts"],"names":["checkoutError"],"mappings":";;;;;AAqBA,SAAS,QAAA,CAAS,GAAA,EAA4B,IAAA,GAAO,EAAA,EAAY;AAC/D,EAAA,MAAM,IAAA,GAAO,GAAA,CAAI,OAAA,CAAQ,OAAA,CAAQ,QAAQ,EAAE,CAAA;AAC3C,EAAA,OAAO,CAAA,EAAG,IAAI,CAAA,UAAA,EAAa,kBAAA,CAAmB,IAAI,UAAU,CAAC,eAAe,IAAI,CAAA,CAAA;AAClF;AAEA,eAAe,QAAA,CAAY,KAAa,IAAA,EAA2B;AACjE,EAAA,MAAM,GAAA,GAAM,MAAM,KAAA,CAAM,GAAA,EAAK;AAAA,IAC3B,MAAA,EAAQ,MAAA;AAAA,IACR,OAAA,EAAS,EAAE,cAAA,EAAgB,kBAAA,EAAmB;AAAA,IAC9C,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,IAAI;AAAA,GAC1B,CAAA;AAGD,EAAA,IAAI,CAAC,IAAI,EAAA,EAAI,MAAMA,gCAAc,kBAAA,EAAoB,CAAA,8BAAA,EAAiC,GAAA,CAAI,MAAM,CAAA,CAAA,CAAG,CAAA;AACnG,EAAA,OAAQ,MAAM,IAAI,IAAA,EAAK;AACzB;AAGO,SAAS,gBAAgB,CAAA,EAA2B;AACzD,EAAA,IAAI,CAAA,IAAK,OAAO,CAAA,KAAM,QAAA,IAAY,cAAc,CAAA,IAAK,SAAA,IAAa,CAAA,IAAK,WAAA,IAAe,CAAA,EAAG;AACvF,IAAA,OAAO,CAAA;AAAA,EACT;AACA,EAAA,OAAOA,gCAAc,kBAAA,EAAoB,CAAA,YAAa,KAAA,GAAQ,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AAA,IAAI,CAAC,MAAM,SAAA,EAAW;AACtB,QAAA,MAAA,CAAO,mBAAA,CAAoB,YAAY,UAAU,CAAA;AACjD,QAAA,OAAA,CAAQ;AAAA,UACN,EAAA,EAAI,KAAA;AAAA,UACJ,KAAA,EAAOA,+BAAA,CAAc,UAAA,EAAY,sDAAsD;AAAA,SACxF,CAAA;AAAA,MACH,CAAA;AACA,MAAA,MAAA,CAAO,gBAAA,CAAiB,YAAY,UAAU,CAAA;AAAA,IAChD;AACA,IAAA,MAAA,CAAO,QAAA,CAAS,OAAO,GAAG,CAAA;AAAA,EAC5B,CAAC,CAAA;AACH","file":"chunk-FY3TMSRU.cjs","sourcesContent":["/**\n * Shared wire plumbing for the checkout drivers — the CLIENT half of the v2\n * checkout contract (commerce/checkout-api.ts). Lives under drivers/ (not\n * commerce/) on purpose: it ships only inside the `driver-*` subpath entries,\n * so the core funnel entry never bundles a checkout fetch — the core SDK talks\n * to a {@link CheckoutDriver}, never to the wire.\n *\n * Only `import type` from commerce/checkout(.tsx) here — a runtime import would\n * drag the React checkout primitives into every driver chunk. The one runtime\n * dependency is the pure error taxonomy (capabilities.ts).\n */\nimport type {\n CheckoutCompleteRequest,\n CheckoutCompleteResponse,\n CheckoutSessionRequest,\n CheckoutSessionResponse,\n CheckoutSettlement,\n} from '../commerce/checkout-api'\nimport type { CheckoutDriverContext, CheckoutRequest, CheckoutResult } from '../commerce/checkout'\nimport { checkoutError, type CheckoutError } from '../commerce/capabilities'\n\nfunction endpoint(ctx: CheckoutDriverContext, path = ''): string {\n const base = ctx.apiBase.replace(/\\/+$/, '')\n return `${base}/campaign/${encodeURIComponent(ctx.campaignId)}/v2/checkout${path}`\n}\n\nasync function postJson<T>(url: string, body: unknown): Promise<T> {\n const res = await fetch(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body),\n })\n // The contract speaks in `step` responses, not HTTP errors — a non-2xx means the\n // request never reached the checkout service properly (proxy, deploy, outage).\n if (!res.ok) throw checkoutError('processing_error', `checkout request failed (HTTP ${res.status})`)\n return (await res.json()) as T\n}\n\n/** Normalize any thrown value into the taxonomy (network drops → `processing_error`). */\nexport function toCheckoutError(e: unknown): CheckoutError {\n if (e && typeof e === 'object' && 'category' in e && 'message' in e && 'retryable' in e) {\n return e as CheckoutError\n }\n return checkoutError('processing_error', e instanceof Error ? e.message : 'Checkout request failed')\n}\n\n/**\n * Open a checkout attempt: `POST {apiBase}/campaign/{campaignId}/v2/checkout`.\n * The correlationId is client-minted per ATTEMPT (idempotency key + the id the\n * server stamps into provider metadata) — mint it once, reuse it on retries.\n */\nexport function postSession(\n ctx: CheckoutDriverContext,\n req: CheckoutRequest,\n correlationId: string,\n): Promise<CheckoutSessionResponse> {\n const body: CheckoutSessionRequest = {\n funnelId: ctx.funnelId,\n mode: ctx.mode,\n // The CHARGE identity is the catalog key (resolved from the slot by driverWithCatalog); fall back\n // to `product` for legacy builds where the page named the catalog key directly.\n productKey: req.catalogKey ?? req.product,\n intent: req.intent,\n kind: req.kind,\n // null (not absent) = explicit off-session — the server validates surfaces\n // against the capability matrix, so never let one default in transit.\n surface: req.surface ?? null,\n sessionId: ctx.sessionId ?? undefined,\n visitorId: ctx.visitorId ?? undefined,\n // Buyer email collected by the funnel (user.email) — Stripe Customer creation,\n // receipts, Paddle prefill. Injected at attempt time by the FunnelProvider seam.\n email: req.email,\n correlationId,\n }\n return postJson<CheckoutSessionResponse>(endpoint(ctx), body)\n}\n\n/** Ask the server to VERIFY with the provider and write the money facts (idempotent). */\nexport function postComplete(\n ctx: CheckoutDriverContext,\n correlationId: string,\n providerRef?: string,\n): Promise<CheckoutCompleteResponse> {\n const body: CheckoutCompleteRequest = { providerRef }\n return postJson<CheckoutCompleteResponse>(\n endpoint(ctx, `/${encodeURIComponent(correlationId)}/complete`),\n body,\n )\n}\n\n/** Server settlement → the SDK's CheckoutResult (eventId passes through for pixel dedup). */\nexport function settlementToResult(s: CheckoutSettlement): CheckoutResult {\n return { ok: true, amountMinor: s.amountMinor, currency: s.currency, eventId: s.eventId }\n}\n\nexport interface CompletePollOptions {\n providerRef?: string\n /** Total complete attempts before giving up (default 5). */\n attempts?: number\n /** Delay between attempts (default 2000ms). */\n intervalMs?: number\n /** Error message when the provider hasn't confirmed inside the window (MoR/async). */\n timeoutMessage?: string\n}\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))\n\n/**\n * Complete with a bounded poll. Sync providers (Stripe) settle on the first\n * attempt — the server verifies against the provider inline. MoR/async providers\n * (Paddle) settle via webhook, so `pending` is normal: re-poll a few times, then\n * stop holding the UI hostage — the charge may still land server-side, which is\n * why the timeout error is `retryable` and the message should say the receipt\n * can still arrive (the server's money facts don't depend on this browser).\n */\nexport async function completeWithPoll(\n ctx: CheckoutDriverContext,\n correlationId: string,\n opts: CompletePollOptions = {},\n): Promise<CheckoutResult> {\n const attempts = opts.attempts ?? 5\n const intervalMs = opts.intervalMs ?? 2000\n try {\n for (let i = 0; i < attempts; i++) {\n const res = await postComplete(ctx, correlationId, opts.providerRef)\n if (res.step === 'settled') return settlementToResult(res.result)\n if (res.step === 'failed') return { ok: false, error: res.error }\n if (i < attempts - 1) await sleep(intervalMs)\n }\n } catch (e) {\n return { ok: false, error: toCheckoutError(e) }\n }\n return {\n ok: false,\n error: checkoutError(\n 'processing_error',\n opts.timeoutMessage ?? 'The payment has not been confirmed yet — please check back shortly.',\n // `completion_timeout` marks \"the poll ran out while the attempt was still\n // pending\" — drivers key double-charge guards on it (the attempt may still\n // settle server-side; it was never refused).\n { retryable: true, declineCode: 'completion_timeout' },\n ),\n }\n}\n\n/**\n * The `redirect` step hand-off: navigate to the provider-hosted page and return a\n * promise that settles ONLY if the buyer comes back to this very page. The page\n * is leaving — resolving early would fire `purchase.complete`/navigation for a\n * charge that hasn't happened, and rejecting would flash an error during the\n * (successful) hand-off — so while the navigation proceeds the promise stays\n * pending and `useCheckout` stays in `loading`, the truthful UI for a page\n * mid-navigation. The hosted page's SUCCESS return URL re-enters the funnel with\n * `af_checkout={correlationId}` (a fresh load — this promise is gone; the SDK's\n * resume leg settles the attempt).\n *\n * The one way THIS page comes back to life is a bfcache restore (browser Back\n * from the hosted page): `pageshow` with `persisted: true`. That is a buyer who\n * abandoned the hosted checkout — resolve `canceled` so the trigger re-enables\n * and inline redirect placeholders recover instead of spinning forever.\n */\nexport function leaveForRedirect(url: string): Promise<CheckoutResult> {\n return new Promise<CheckoutResult>((resolve) => {\n if (typeof window !== 'undefined') {\n const onPageshow = (event: PageTransitionEvent) => {\n if (!event.persisted) return\n window.removeEventListener('pageshow', onPageshow)\n resolve({\n ok: false,\n error: checkoutError('canceled', 'Returned from the hosted checkout without completing'),\n })\n }\n window.addEventListener('pageshow', onPageshow)\n }\n window.location.assign(url)\n })\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkoutError } from './chunk-
|
|
1
|
+
import { checkoutError } from './chunk-RVJLR4RS.js';
|
|
2
2
|
|
|
3
3
|
// src/drivers/wire.ts
|
|
4
4
|
function endpoint(ctx, path = "") {
|
|
@@ -95,5 +95,5 @@ function leaveForRedirect(url) {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export { completeWithPoll, leaveForRedirect, postComplete, postSession, settlementToResult, toCheckoutError };
|
|
98
|
-
//# sourceMappingURL=chunk-
|
|
99
|
-
//# sourceMappingURL=chunk-
|
|
98
|
+
//# sourceMappingURL=chunk-PWXMQGO6.js.map
|
|
99
|
+
//# sourceMappingURL=chunk-PWXMQGO6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/drivers/wire.ts"],"names":[],"mappings":";;;AAqBA,SAAS,QAAA,CAAS,GAAA,EAA4B,IAAA,GAAO,EAAA,EAAY;AAC/D,EAAA,MAAM,IAAA,GAAO,GAAA,CAAI,OAAA,CAAQ,OAAA,CAAQ,QAAQ,EAAE,CAAA;AAC3C,EAAA,OAAO,CAAA,EAAG,IAAI,CAAA,UA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v2\n * checkout contract (commerce/checkout-api.ts). Lives under drivers/ (not\n * commerce/) on purpose: it ships only inside the `driver-*` subpath entries,\n * so the core funnel entry never bundles a checkout fetch — the core SDK talks\n * to a {@link CheckoutDriver}, never to the wire.\n *\n * Only `import type` from commerce/checkout(.tsx) here — a runtime import would\n * drag the React checkout primitives into every driver chunk. The one runtime\n * dependency is the pure error taxonomy (capabilities.ts).\n */\nimport type {\n CheckoutCompleteRequest,\n CheckoutCompleteResponse,\n CheckoutSessionRequest,\n CheckoutSessionResponse,\n CheckoutSettlement,\n} from '../commerce/checkout-api'\nimport type { CheckoutDriverContext, CheckoutRequest, CheckoutResult } from '../commerce/checkout'\nimport { checkoutError, type CheckoutError } from '../commerce/capabilities'\n\nfunction endpoint(ctx: CheckoutDriverContext, path = ''): string {\n const base = ctx.apiBase.replace(/\\/+$/, '')\n return `${base}/campaign/${encodeURIComponent(ctx.campaignId)}/v2/checkout${path}`\n}\n\nasync function postJson<T>(url: string, body: unknown): Promise<T> {\n const res = await fetch(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body),\n })\n // The contract speaks in `step` responses, not HTTP errors — a non-2xx means the\n // request never reached the checkout service properly (proxy, deploy, outage).\n if (!res.ok) throw checkoutError('processing_error', `checkout request failed (HTTP ${res.status})`)\n return (await res.json()) as T\n}\n\n/** Normalize any thrown value into the taxonomy (network drops → `processing_error`). */\nexport function toCheckoutError(e: unknown): CheckoutError {\n if (e && typeof e === 'object' && 'category' in e && 'message' in e && 'retryable' in e) {\n return e as CheckoutError\n }\n return checkoutError('processing_error', e instanceof Error ? e.message : 'Checkout request failed')\n}\n\n/**\n * Open a checkout attempt: `POST {apiBase}/campaign/{campaignId}/v2/checkout`.\n * The correlationId is client-minted per ATTEMPT (idempotency key + the id the\n * server stamps into provider metadata) — mint it once, reuse it on retries.\n */\nexport function postSession(\n ctx: CheckoutDriverContext,\n req: CheckoutRequest,\n correlationId: string,\n): Promise<CheckoutSessionResponse> {\n const body: CheckoutSessionRequest = {\n funnelId: ctx.funnelId,\n mode: ctx.mode,\n // The CHARGE identity is the catalog key (resolved from the slot by driverWithCatalog); fall back\n // to `product` for legacy builds where the page named the catalog key directly.\n productKey: req.catalogKey ?? req.product,\n intent: req.intent,\n kind: req.kind,\n // null (not absent) = explicit off-session — the server validates surfaces\n // against the capability matrix, so never let one default in transit.\n surface: req.surface ?? null,\n sessionId: ctx.sessionId ?? undefined,\n visitorId: ctx.visitorId ?? undefined,\n // Buyer email collected by the funnel (user.email) — Stripe Customer creation,\n // receipts, Paddle prefill. Injected at attempt time by the FunnelProvider seam.\n email: req.email,\n correlationId,\n }\n return postJson<CheckoutSessionResponse>(endpoint(ctx), body)\n}\n\n/** Ask the server to VERIFY with the provider and write the money facts (idempotent). */\nexport function postComplete(\n ctx: CheckoutDriverContext,\n correlationId: string,\n providerRef?: string,\n): Promise<CheckoutCompleteResponse> {\n const body: CheckoutCompleteRequest = { providerRef }\n return postJson<CheckoutCompleteResponse>(\n endpoint(ctx, `/${encodeURIComponent(correlationId)}/complete`),\n body,\n )\n}\n\n/** Server settlement → the SDK's CheckoutResult (eventId passes through for pixel dedup). */\nexport function settlementToResult(s: CheckoutSettlement): CheckoutResult {\n return { ok: true, amountMinor: s.amountMinor, currency: s.currency, eventId: s.eventId }\n}\n\nexport interface CompletePollOptions {\n providerRef?: string\n /** Total complete attempts before giving up (default 5). */\n attempts?: number\n /** Delay between attempts (default 2000ms). */\n intervalMs?: number\n /** Error message when the provider hasn't confirmed inside the window (MoR/async). */\n timeoutMessage?: string\n}\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))\n\n/**\n * Complete with a bounded poll. Sync providers (Stripe) settle on the first\n * attempt — the server verifies against the provider inline. MoR/async providers\n * (Paddle) settle via webhook, so `pending` is normal: re-poll a few times, then\n * stop holding the UI hostage — the charge may still land server-side, which is\n * why the timeout error is `retryable` and the message should say the receipt\n * can still arrive (the server's money facts don't depend on this browser).\n */\nexport async function completeWithPoll(\n ctx: CheckoutDriverContext,\n correlationId: string,\n opts: CompletePollOptions = {},\n): Promise<CheckoutResult> {\n const attempts = opts.attempts ?? 5\n const intervalMs = opts.intervalMs ?? 2000\n try {\n for (let i = 0; i < attempts; i++) {\n const res = await postComplete(ctx, correlationId, opts.providerRef)\n if (res.step === 'settled') return settlementToResult(res.result)\n if (res.step === 'failed') return { ok: false, error: res.error }\n if (i < attempts - 1) await sleep(intervalMs)\n }\n } catch (e) {\n return { ok: false, error: toCheckoutError(e) }\n }\n return {\n ok: false,\n error: checkoutError(\n 'processing_error',\n opts.timeoutMessage ?? 'The payment has not been confirmed yet — please check back shortly.',\n // `completion_timeout` marks \"the poll ran out while the attempt was still\n // pending\" — drivers key double-charge guards on it (the attempt may still\n // settle server-side; it was never refused).\n { retryable: true, declineCode: 'completion_timeout' },\n ),\n }\n}\n\n/**\n * The `redirect` step hand-off: navigate to the provider-hosted page and return a\n * promise that settles ONLY if the buyer comes back to this very page. The page\n * is leaving — resolving early would fire `purchase.complete`/navigation for a\n * charge that hasn't happened, and rejecting would flash an error during the\n * (successful) hand-off — so while the navigation proceeds the promise stays\n * pending and `useCheckout` stays in `loading`, the truthful UI for a page\n * mid-navigation. The hosted page's SUCCESS return URL re-enters the funnel with\n * `af_checkout={correlationId}` (a fresh load — this promise is gone; the SDK's\n * resume leg settles the attempt).\n *\n * The one way THIS page comes back to life is a bfcache restore (browser Back\n * from the hosted page): `pageshow` with `persisted: true`. That is a buyer who\n * abandoned the hosted checkout — resolve `canceled` so the trigger re-enables\n * and inline redirect placeholders recover instead of spinning forever.\n */\nexport function leaveForRedirect(url: string): Promise<CheckoutResult> {\n return new Promise<CheckoutResult>((resolve) => {\n if (typeof window !== 'undefined') {\n const onPageshow = (event: PageTransitionEvent) => {\n if (!event.persisted) return\n window.removeEventListener('pageshow', onPageshow)\n resolve({\n ok: false,\n error: checkoutError('canceled', 'Returned from the hosted checkout without completing'),\n })\n }\n window.addEventListener('pageshow', onPagesh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,aAAA,CAAc,UAAA,EAAY,sDAAsD;AAAA,SACxF,CAAA;AAAA,MACH,CAAA;AACA,MAAA,MAAA,CAAO,gBAAA,CAAiB,YAAY,UAAU,CAAA;AAAA,IAChD;AACA,IAAA,MAAA,CAAO,QAAA,CAAS,OAAO,GAAG,CAAA;AAAA,EAC5B,CAAC,CAAA;AACH","file":"chunk-PWXMQGO6.js","sourcesContent":["/**\n * Shared wire plumbing for the checkout drivers — the CLIENT half of the v2\n * checkout contract (commerce/checkout-api.ts). Lives under drivers/ (not\n * commerce/) on purpose: it ships only inside the `driver-*` subpath entries,\n * so the core funnel entry never bundles a checkout fetch — the core SDK talks\n * to a {@link CheckoutDriver}, never to the wire.\n *\n * Only `import type` from commerce/checkout(.tsx) here — a runtime import would\n * drag the React checkout primitives into every driver chunk. The one runtime\n * dependency is the pure error taxonomy (capabilities.ts).\n */\nimport type {\n CheckoutCompleteRequest,\n CheckoutCompleteResponse,\n CheckoutSessionRequest,\n CheckoutSessionResponse,\n CheckoutSettlement,\n} from '../commerce/checkout-api'\nimport type { CheckoutDriverContext, CheckoutRequest, CheckoutResult } from '../commerce/checkout'\nimport { checkoutError, type CheckoutError } from '../commerce/capabilities'\n\nfunction endpoint(ctx: CheckoutDriverContext, path = ''): string {\n const base = ctx.apiBase.replace(/\\/+$/, '')\n return `${base}/campaign/${encodeURIComponent(ctx.campaignId)}/v2/checkout${path}`\n}\n\nasync function postJson<T>(url: string, body: unknown): Promise<T> {\n const res = await fetch(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body),\n })\n // The contract speaks in `step` responses, not HTTP errors — a non-2xx means the\n // request never reached the checkout service properly (proxy, deploy, outage).\n if (!res.ok) throw checkoutError('processing_error', `checkout request failed (HTTP ${res.status})`)\n return (await res.json()) as T\n}\n\n/** Normalize any thrown value into the taxonomy (network drops → `processing_error`). */\nexport function toCheckoutError(e: unknown): CheckoutError {\n if (e && typeof e === 'object' && 'category' in e && 'message' in e && 'retryable' in e) {\n return e as CheckoutError\n }\n return checkoutError('processing_error', e instanceof Error ? e.message : 'Checkout request failed')\n}\n\n/**\n * Open a checkout attempt: `POST {apiBase}/campaign/{campaignId}/v2/checkout`.\n * The correlationId is client-minted per ATTEMPT (idempotency key + the id the\n * server stamps into provider metadata) — mint it once, reuse it on retries.\n */\nexport function postSession(\n ctx: CheckoutDriverContext,\n req: CheckoutRequest,\n correlationId: string,\n): Promise<CheckoutSessionResponse> {\n const body: CheckoutSessionRequest = {\n funnelId: ctx.funnelId,\n mode: ctx.mode,\n // The CHARGE identity is the catalog key (resolved from the slot by driverWithCatalog); fall back\n // to `product` for legacy builds where the page named the catalog key directly.\n productKey: req.catalogKey ?? req.product,\n intent: req.intent,\n kind: req.kind,\n // null (not absent) = explicit off-session — the server validates surfaces\n // against the capability matrix, so never let one default in transit.\n surface: req.surface ?? null,\n sessionId: ctx.sessionId ?? undefined,\n visitorId: ctx.visitorId ?? undefined,\n // Buyer email collected by the funnel (user.email) — Stripe Customer creation,\n // receipts, Paddle prefill. Injected at attempt time by the FunnelProvider seam.\n email: req.email,\n correlationId,\n }\n return postJson<CheckoutSessionResponse>(endpoint(ctx), body)\n}\n\n/** Ask the server to VERIFY with the provider and write the money facts (idempotent). */\nexport function postComplete(\n ctx: CheckoutDriverContext,\n correlationId: string,\n providerRef?: string,\n): Promise<CheckoutCompleteResponse> {\n const body: CheckoutCompleteRequest = { providerRef }\n return postJson<CheckoutCompleteResponse>(\n endpoint(ctx, `/${encodeURIComponent(correlationId)}/complete`),\n body,\n )\n}\n\n/** Server settlement → the SDK's CheckoutResult (eventId passes through for pixel dedup). */\nexport function settlementToResult(s: CheckoutSettlement): CheckoutResult {\n return { ok: true, amountMinor: s.amountMinor, currency: s.currency, eventId: s.eventId }\n}\n\nexport interface CompletePollOptions {\n providerRef?: string\n /** Total complete attempts before giving up (default 5). */\n attempts?: number\n /** Delay between attempts (default 2000ms). */\n intervalMs?: number\n /** Error message when the provider hasn't confirmed inside the window (MoR/async). */\n timeoutMessage?: string\n}\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))\n\n/**\n * Complete with a bounded poll. Sync providers (Stripe) settle on the first\n * attempt — the server verifies against the provider inline. MoR/async providers\n * (Paddle) settle via webhook, so `pending` is normal: re-poll a few times, then\n * stop holding the UI hostage — the charge may still land server-side, which is\n * why the timeout error is `retryable` and the message should say the receipt\n * can still arrive (the server's money facts don't depend on this browser).\n */\nexport async function completeWithPoll(\n ctx: CheckoutDriverContext,\n correlationId: string,\n opts: CompletePollOptions = {},\n): Promise<CheckoutResult> {\n const attempts = opts.attempts ?? 5\n const intervalMs = opts.intervalMs ?? 2000\n try {\n for (let i = 0; i < attempts; i++) {\n const res = await postComplete(ctx, correlationId, opts.providerRef)\n if (res.step === 'settled') return settlementToResult(res.result)\n if (res.step === 'failed') return { ok: false, error: res.error }\n if (i < attempts - 1) await sleep(intervalMs)\n }\n } catch (e) {\n return { ok: false, error: toCheckoutError(e) }\n }\n return {\n ok: false,\n error: checkoutError(\n 'processing_error',\n opts.timeoutMessage ?? 'The payment has not been confirmed yet — please check back shortly.',\n // `completion_timeout` marks \"the poll ran out while the attempt was still\n // pending\" — drivers key double-charge guards on it (the attempt may still\n // settle server-side; it was never refused).\n { retryable: true, declineCode: 'completion_timeout' },\n ),\n }\n}\n\n/**\n * The `redirect` step hand-off: navigate to the provider-hosted page and return a\n * promise that settles ONLY if the buyer comes back to this very page. The page\n * is leaving — resolving early would fire `purchase.complete`/navigation for a\n * charge that hasn't happened, and rejecting would flash an error during the\n * (successful) hand-off — so while the navigation proceeds the promise stays\n * pending and `useCheckout` stays in `loading`, the truthful UI for a page\n * mid-navigation. The hosted page's SUCCESS return URL re-enters the funnel with\n * `af_checkout={correlationId}` (a fresh load — this promise is gone; the SDK's\n * resume leg settles the attempt).\n *\n * The one way THIS page comes back to life is a bfcache restore (browser Back\n * from the hosted page): `pageshow` with `persisted: true`. That is a buyer who\n * abandoned the hosted checkout — resolve `canceled` so the trigger re-enables\n * and inline redirect placeholders recover instead of spinning forever.\n */\nexport function leaveForRedirect(url: string): Promise<CheckoutResult> {\n return new Promise<CheckoutResult>((resolve) => {\n if (typeof window !== 'undefined') {\n const onPageshow = (event: PageTransitionEvent) => {\n if (!event.persisted) return\n window.removeEventListener('pageshow', onPageshow)\n resolve({\n ok: false,\n error: checkoutError('canceled', 'Returned from the hosted checkout without completing'),\n })\n }\n window.addEventListener('pageshow', onPageshow)\n }\n window.location.assign(url)\n })\n}\n"]}
|
|
@@ -10,6 +10,7 @@ function isInlineSurface(surface) {
|
|
|
10
10
|
var ON = { purchase: true, wallets: true, offSession: "reliable" };
|
|
11
11
|
var MANAGED = { purchase: true, wallets: true, offSession: "conditional" };
|
|
12
12
|
var ROUTED = { purchase: true, wallets: true, offSession: "conditional" };
|
|
13
|
+
var PADDLE_EXPRESS = { purchase: true, wallets: true, offSession: "reliable", driver: "planned" };
|
|
13
14
|
var ALL_UPSELLS = ["subscription", "one-time", "upgrade"];
|
|
14
15
|
var PROVIDER_PROFILES = {
|
|
15
16
|
// PSP; you hold the PaymentMethod and fire your own off-session PaymentIntent on
|
|
@@ -22,27 +23,37 @@ var PROVIDER_PROFILES = {
|
|
|
22
23
|
tokenModel: "merchant",
|
|
23
24
|
orchestrator: false,
|
|
24
25
|
status: "full",
|
|
26
|
+
// Composed trials: paid = fee PaymentIntent + sub (trial_period_days); free = SetupIntent vault
|
|
27
|
+
// + trial sub (services/checkout/stripe-trial.ts).
|
|
28
|
+
trialShapes: ["paid_composed", "free_vault"],
|
|
25
29
|
surfaces: { express: ON, element: ON, sheet: ON, embedded: MANAGED, redirect: MANAGED }
|
|
26
30
|
},
|
|
27
|
-
// Merchant-of-Record; card entry is always Paddle's frame → no own element/sheet
|
|
28
|
-
// express
|
|
29
|
-
//
|
|
31
|
+
// Merchant-of-Record; raw card entry is always Paddle's frame → no own element/sheet.
|
|
32
|
+
// `express` IS now present (Apple-Pay-first Express Checkout, shipped 2026-04-27) but is
|
|
33
|
+
// driver-planned (PADDLE_EXPRESS) → publish fails it closed until the driver renders it.
|
|
34
|
+
// Off-session via subscription one-time charge / collection_mode, but **no 2nd concurrent
|
|
35
|
+
// subscription** (upgrade + one-time only), provider-initiated.
|
|
30
36
|
paddle: {
|
|
31
37
|
isMoR: true,
|
|
32
38
|
offSessionUpsells: ["one-time", "upgrade"],
|
|
33
39
|
tokenModel: "provider",
|
|
34
40
|
orchestrator: false,
|
|
35
41
|
status: "full",
|
|
36
|
-
|
|
42
|
+
// Native trials: the price itself carries the trial, Paddle collects up front / vaults
|
|
43
|
+
// (services/checkout/paddle-checkout.ts — "Paddle paid trials are NATIVE").
|
|
44
|
+
trialShapes: ["paid_native", "free_native"],
|
|
45
|
+
surfaces: { embedded: ON, popup: ON, redirect: ON, express: PADDLE_EXPRESS }
|
|
37
46
|
},
|
|
38
47
|
// Merchant-of-Record; iframe-only (no raw card field). Off-session works
|
|
39
48
|
// (provider-initiated, async via webhooks). `sheet` = our chrome hosting their embed.
|
|
49
|
+
// Trial shape not yet researched → empty (fail closed until the driver + profile land).
|
|
40
50
|
whop: {
|
|
41
51
|
isMoR: true,
|
|
42
52
|
offSessionUpsells: ALL_UPSELLS,
|
|
43
53
|
tokenModel: "provider",
|
|
44
54
|
orchestrator: false,
|
|
45
55
|
status: "planned",
|
|
56
|
+
trialShapes: [],
|
|
46
57
|
surfaces: { embedded: ON, redirect: ON, sheet: ON }
|
|
47
58
|
},
|
|
48
59
|
// Pure orchestrator (PSP-side); Headless renders express/element/sheet/embedded.
|
|
@@ -55,6 +66,7 @@ var PROVIDER_PROFILES = {
|
|
|
55
66
|
tokenModel: "merchant",
|
|
56
67
|
orchestrator: true,
|
|
57
68
|
status: "planned",
|
|
69
|
+
trialShapes: [],
|
|
58
70
|
surfaces: { express: ROUTED, element: ROUTED, sheet: ROUTED, embedded: ROUTED }
|
|
59
71
|
},
|
|
60
72
|
// PSP **and** orchestrator (own acquiring + connectors routing across Stripe/Adyen/
|
|
@@ -66,6 +78,7 @@ var PROVIDER_PROFILES = {
|
|
|
66
78
|
tokenModel: "merchant",
|
|
67
79
|
orchestrator: true,
|
|
68
80
|
status: "planned",
|
|
81
|
+
trialShapes: [],
|
|
69
82
|
surfaces: { express: ON, element: ON, sheet: ON, embedded: ON, redirect: ON }
|
|
70
83
|
}
|
|
71
84
|
};
|
|
@@ -81,7 +94,22 @@ function isOrchestrator(provider) {
|
|
|
81
94
|
function validateCheckout(provider, surface) {
|
|
82
95
|
const cap = PROVIDER_PROFILES[provider]?.surfaces[surface];
|
|
83
96
|
if (!cap) return { ok: false, reason: `${provider} has no '${surface}' surface` };
|
|
84
|
-
|
|
97
|
+
if (!cap.purchase) return { ok: false, reason: `'${surface}' can't take a purchase on ${provider}` };
|
|
98
|
+
if (cap.driver === "planned") return { ok: false, reason: `${provider} '${surface}' checkout isn't renderable yet (the provider ships it, but our driver doesn't render it)` };
|
|
99
|
+
return { ok: true };
|
|
100
|
+
}
|
|
101
|
+
function trialShapesFor(provider) {
|
|
102
|
+
return PROVIDER_PROFILES[provider]?.trialShapes ?? [];
|
|
103
|
+
}
|
|
104
|
+
function validateTrial(provider, shape) {
|
|
105
|
+
const profile = PROVIDER_PROFILES[provider];
|
|
106
|
+
if (!profile) return { ok: false, reason: `unknown provider '${provider}'` };
|
|
107
|
+
const shapes = profile.trialShapes;
|
|
108
|
+
if (shapes.length === 0) return { ok: false, reason: `${provider} can't run a trial offer yet` };
|
|
109
|
+
if (shape && !shapes.includes(shape)) {
|
|
110
|
+
return { ok: false, reason: `${provider} doesn't support a '${shape}' trial (it supports: ${shapes.join(", ")})` };
|
|
111
|
+
}
|
|
112
|
+
return { ok: true };
|
|
85
113
|
}
|
|
86
114
|
function validateUpsell(provider, paywallSurface, kind = "subscription") {
|
|
87
115
|
const profile = PROVIDER_PROFILES[provider];
|
|
@@ -105,6 +133,6 @@ function checkoutError(category, message, extra = {}) {
|
|
|
105
133
|
return { category, message, declineCode: extra.declineCode, retryable };
|
|
106
134
|
}
|
|
107
135
|
|
|
108
|
-
export { INLINE_SURFACES, PROVIDER_PROFILES, checkoutError, isInlineSurface, isMerchantOfRecord, isOrchestrator, surfacesFor, validateCheckout, validateUpsell };
|
|
109
|
-
//# sourceMappingURL=chunk-
|
|
110
|
-
//# sourceMappingURL=chunk-
|
|
136
|
+
export { INLINE_SURFACES, PROVIDER_PROFILES, checkoutError, isInlineSurface, isMerchantOfRecord, isOrchestrator, surfacesFor, trialShapesFor, validateCheckout, validateTrial, validateUpsell };
|
|
137
|
+
//# sourceMappingURL=chunk-RVJLR4RS.js.map
|
|
138
|
+
//# sourceMappingURL=chunk-RVJLR4RS.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;AAyEA,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;AAW7F,IAAM,cAAA,GAAoC,EAAE,QAAA,EAAU,IAAA,EAAM,SAAS,IAAA,EAAM,UAAA,EAAY,UAAA,EAAY,MAAA,EAAQ,SAAA,EAAU;AACrH,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,E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AA,EAC7J;AACA,EAAA,OAAO,EAAE,IAAI,IAAA,EAAK;AACpB;AA+BO,SAAS,aAAA,CACd,QAAA,EACA,OAAA,EACA,KAAA,GAAuD,EAAC,EACzC;AACf,EAAA,MAAM,YAAY,KAAA,CAAM,SAAA,KAAc,aAAa,yBAAA,IAA6B,QAAA,KAAa,6BAA6B,QAAA,KAAa,kBAAA,CAAA;AACvI,EAAA,OAAO,EAAE,QAAA,EAAU,OAAA,EAAS,WAAA,EAAa,KAAA,CAAM,aAAa,SAAA,EAAU;AACxE","file":"chunk-RVJLR4RS.js","sourcesContent":["/**\n * The 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 * Per-surface DRIVER readiness. Absent = renderable now (the provider's driver mounts it).\n * `'planned'` = the provider genuinely ships this surface (cite it in the profile) but OUR\n * driver doesn't render it yet — publish validation FAILS CLOSED on it so we never promise a\n * surface the runtime can't produce. Mirrors the provider-level {@link ProviderProfile.status}\n * seam at surface granularity: implement the driver, drop the flag, and it flips on cleanly.\n */\n driver?: 'planned'\n}\n\n/**\n * How a provider composes a TRIAL — the scattered provider `if`s made a matrix dimension\n * (§7 item 4). Stripe trials are **composed** (a separate fee/vault step precedes the sub);\n * Paddle trials are **native** (the price itself carries the trial, MoR collects up front):\n * - `paid_composed` — Stripe: trial-fee PaymentIntent → subscription with `trial_period_days`.\n * - `free_vault` — Stripe: SetupIntent vaults the card (no charge) → trial subscription.\n * - `paid_native` — Paddle: the price carries the paid trial; one item, collected up front.\n * - `free_native` — Paddle: native free trial on the price.\n * A provider with an EMPTY `trialShapes` can't run a trial offer (planned providers → fail closed).\n */\nexport type TrialShape = 'paid_composed' | 'free_vault' | 'paid_native' | 'free_native'\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 /**\n * TRIAL shapes this provider can run (§7 item 4). Empty = no trial path (fail closed at\n * publish — a paid/free-trial funnel on this provider can't be produced yet).\n */\n trialShapes: TrialShape[]\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' }\n/**\n * Paddle **Express Checkout** (Apple-Pay-first mobile variant of Paddle.js checkout, shipped\n * 2026-04-27 — https://developer.paddle.com/changelog/2026/apple-pay-express-checkout/). Paddle\n * genuinely offers it (MoR, so it's their hosted/inline frame surfaced wallet-first, NOT a raw\n * wallet element in our UI), which is why it's a distinct `express` surface here rather than only\n * the `wallets` flag already true on Paddle's embedded/popup. But our Paddle DRIVER doesn't render\n * it yet (drivers/paddle.tsx opens the standard embedded/overlay checkout regardless of surface),\n * so `driver: 'planned'` fails it closed at publish — the matrix records reality without promising\n * a wallet-first render the runtime can't produce. Off-session stays reliable (provider-token, MoR).\n */\nconst PADDLE_EXPRESS: SurfaceCapability = { purchase: true, wallets: true, offSession: 'reliable', driver: 'planned' }\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 // Composed trials: paid = fee PaymentIntent + sub (trial_period_days); free = SetupIntent vault\n // + trial sub (services/checkout/stripe-trial.ts).\n trialShapes: ['paid_composed', 'free_vault'],\n surfaces: { express: ON, element: ON, sheet: ON, embedded: MANAGED, redirect: MANAGED },\n },\n // Merchant-of-Record; raw card entry is always Paddle's frame → no own element/sheet.\n // `express` IS now present (Apple-Pay-first Express Checkout, shipped 2026-04-27) but is\n // driver-planned (PADDLE_EXPRESS) → publish fails it closed until the driver renders it.\n // Off-session via subscription one-time charge / collection_mode, but **no 2nd concurrent\n // subscription** (upgrade + one-time only), provider-initiated.\n paddle: {\n isMoR: true, offSessionUpsells: ['one-time', 'upgrade'], tokenModel: 'provider', orchestrator: false, status: 'full',\n // Native trials: the price itself carries the trial, Paddle collects up front / vaults\n // (services/checkout/paddle-checkout.ts — \"Paddle paid trials are NATIVE\").\n trialShapes: ['paid_native', 'free_native'],\n surfaces: { embedded: ON, popup: ON, redirect: ON, express: PADDLE_EXPRESS },\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 // Trial shape not yet researched → empty (fail closed until the driver + profile land).\n whop: {\n isMoR: true, offSessionUpsells: ALL_UPSELLS, tokenModel: 'provider', orchestrator: false, status: 'planned',\n trialShapes: [],\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 trialShapes: [],\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 trialShapes: [],\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 if (!cap.purchase) return { ok: false, reason: `'${surface}' can't take a purchase on ${provider}` }\n // The provider offers this surface but our driver can't render it yet (e.g. Paddle Express\n // Checkout) → fail closed so publish never promises a surface the runtime can't produce.\n if (cap.driver === 'planned') return { ok: false, reason: `${provider} '${surface}' checkout isn't renderable yet (the provider ships it, but our driver doesn't render it)` }\n return { ok: true }\n}\n\n/** Trial shapes a provider can compose (empty = it can't run a trial offer yet). */\nexport function trialShapesFor(provider: CheckoutProvider): TrialShape[] {\n return PROVIDER_PROFILES[provider]?.trialShapes ?? []\n}\n\n/**\n * Validate that a provider can run a TRIAL (§7 item 4). Pass a specific {@link TrialShape} to\n * check that exact shape; omit it to assert the provider supports *any* trial (the cheap gate\n * check when only the offering's TRIAL-role binding existence is known). A provider with no\n * trial shapes (every planned provider) fails closed.\n */\nexport function validateTrial(provider: CheckoutProvider, shape?: TrialShape): ValidationResult {\n const profile = PROVIDER_PROFILES[provider]\n if (!profile) return { ok: false, reason: `unknown provider '${provider}'` }\n const shapes = profile.trialShapes\n if (shapes.length === 0) return { ok: false, reason: `${provider} can't run a trial offer yet` }\n if (shape && !shapes.includes(shape)) {\n return { ok: false, reason: `${provider} doesn't support a '${shape}' trial (it supports: ${shapes.join(', ')})` }\n }\n return { ok: true }\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"]}
|
|
@@ -12,6 +12,7 @@ function isInlineSurface(surface) {
|
|
|
12
12
|
var ON = { purchase: true, wallets: true, offSession: "reliable" };
|
|
13
13
|
var MANAGED = { purchase: true, wallets: true, offSession: "conditional" };
|
|
14
14
|
var ROUTED = { purchase: true, wallets: true, offSession: "conditional" };
|
|
15
|
+
var PADDLE_EXPRESS = { purchase: true, wallets: true, offSession: "reliable", driver: "planned" };
|
|
15
16
|
var ALL_UPSELLS = ["subscription", "one-time", "upgrade"];
|
|
16
17
|
var PROVIDER_PROFILES = {
|
|
17
18
|
// PSP; you hold the PaymentMethod and fire your own off-session PaymentIntent on
|
|
@@ -24,27 +25,37 @@ var PROVIDER_PROFILES = {
|
|
|
24
25
|
tokenModel: "merchant",
|
|
25
26
|
orchestrator: false,
|
|
26
27
|
status: "full",
|
|
28
|
+
// Composed trials: paid = fee PaymentIntent + sub (trial_period_days); free = SetupIntent vault
|
|
29
|
+
// + trial sub (services/checkout/stripe-trial.ts).
|
|
30
|
+
trialShapes: ["paid_composed", "free_vault"],
|
|
27
31
|
surfaces: { express: ON, element: ON, sheet: ON, embedded: MANAGED, redirect: MANAGED }
|
|
28
32
|
},
|
|
29
|
-
// Merchant-of-Record; card entry is always Paddle's frame → no own element/sheet
|
|
30
|
-
// express
|
|
31
|
-
//
|
|
33
|
+
// Merchant-of-Record; raw card entry is always Paddle's frame → no own element/sheet.
|
|
34
|
+
// `express` IS now present (Apple-Pay-first Express Checkout, shipped 2026-04-27) but is
|
|
35
|
+
// driver-planned (PADDLE_EXPRESS) → publish fails it closed until the driver renders it.
|
|
36
|
+
// Off-session via subscription one-time charge / collection_mode, but **no 2nd concurrent
|
|
37
|
+
// subscription** (upgrade + one-time only), provider-initiated.
|
|
32
38
|
paddle: {
|
|
33
39
|
isMoR: true,
|
|
34
40
|
offSessionUpsells: ["one-time", "upgrade"],
|
|
35
41
|
tokenModel: "provider",
|
|
36
42
|
orchestrator: false,
|
|
37
43
|
status: "full",
|
|
38
|
-
|
|
44
|
+
// Native trials: the price itself carries the trial, Paddle collects up front / vaults
|
|
45
|
+
// (services/checkout/paddle-checkout.ts — "Paddle paid trials are NATIVE").
|
|
46
|
+
trialShapes: ["paid_native", "free_native"],
|
|
47
|
+
surfaces: { embedded: ON, popup: ON, redirect: ON, express: PADDLE_EXPRESS }
|
|
39
48
|
},
|
|
40
49
|
// Merchant-of-Record; iframe-only (no raw card field). Off-session works
|
|
41
50
|
// (provider-initiated, async via webhooks). `sheet` = our chrome hosting their embed.
|
|
51
|
+
// Trial shape not yet researched → empty (fail closed until the driver + profile land).
|
|
42
52
|
whop: {
|
|
43
53
|
isMoR: true,
|
|
44
54
|
offSessionUpsells: ALL_UPSELLS,
|
|
45
55
|
tokenModel: "provider",
|
|
46
56
|
orchestrator: false,
|
|
47
57
|
status: "planned",
|
|
58
|
+
trialShapes: [],
|
|
48
59
|
surfaces: { embedded: ON, redirect: ON, sheet: ON }
|
|
49
60
|
},
|
|
50
61
|
// Pure orchestrator (PSP-side); Headless renders express/element/sheet/embedded.
|
|
@@ -57,6 +68,7 @@ var PROVIDER_PROFILES = {
|
|
|
57
68
|
tokenModel: "merchant",
|
|
58
69
|
orchestrator: true,
|
|
59
70
|
status: "planned",
|
|
71
|
+
trialShapes: [],
|
|
60
72
|
surfaces: { express: ROUTED, element: ROUTED, sheet: ROUTED, embedded: ROUTED }
|
|
61
73
|
},
|
|
62
74
|
// PSP **and** orchestrator (own acquiring + connectors routing across Stripe/Adyen/
|
|
@@ -68,6 +80,7 @@ var PROVIDER_PROFILES = {
|
|
|
68
80
|
tokenModel: "merchant",
|
|
69
81
|
orchestrator: true,
|
|
70
82
|
status: "planned",
|
|
83
|
+
trialShapes: [],
|
|
71
84
|
surfaces: { express: ON, element: ON, sheet: ON, embedded: ON, redirect: ON }
|
|
72
85
|
}
|
|
73
86
|
};
|
|
@@ -83,7 +96,22 @@ function isOrchestrator(provider) {
|
|
|
83
96
|
function validateCheckout(provider, surface) {
|
|
84
97
|
const cap = PROVIDER_PROFILES[provider]?.surfaces[surface];
|
|
85
98
|
if (!cap) return { ok: false, reason: `${provider} has no '${surface}' surface` };
|
|
86
|
-
|
|
99
|
+
if (!cap.purchase) return { ok: false, reason: `'${surface}' can't take a purchase on ${provider}` };
|
|
100
|
+
if (cap.driver === "planned") return { ok: false, reason: `${provider} '${surface}' checkout isn't renderable yet (the provider ships it, but our driver doesn't render it)` };
|
|
101
|
+
return { ok: true };
|
|
102
|
+
}
|
|
103
|
+
function trialShapesFor(provider) {
|
|
104
|
+
return PROVIDER_PROFILES[provider]?.trialShapes ?? [];
|
|
105
|
+
}
|
|
106
|
+
function validateTrial(provider, shape) {
|
|
107
|
+
const profile = PROVIDER_PROFILES[provider];
|
|
108
|
+
if (!profile) return { ok: false, reason: `unknown provider '${provider}'` };
|
|
109
|
+
const shapes = profile.trialShapes;
|
|
110
|
+
if (shapes.length === 0) return { ok: false, reason: `${provider} can't run a trial offer yet` };
|
|
111
|
+
if (shape && !shapes.includes(shape)) {
|
|
112
|
+
return { ok: false, reason: `${provider} doesn't support a '${shape}' trial (it supports: ${shapes.join(", ")})` };
|
|
113
|
+
}
|
|
114
|
+
return { ok: true };
|
|
87
115
|
}
|
|
88
116
|
function validateUpsell(provider, paywallSurface, kind = "subscription") {
|
|
89
117
|
const profile = PROVIDER_PROFILES[provider];
|
|
@@ -114,7 +142,9 @@ exports.isInlineSurface = isInlineSurface;
|
|
|
114
142
|
exports.isMerchantOfRecord = isMerchantOfRecord;
|
|
115
143
|
exports.isOrchestrator = isOrchestrator;
|
|
116
144
|
exports.surfacesFor = surfacesFor;
|
|
145
|
+
exports.trialShapesFor = trialShapesFor;
|
|
117
146
|
exports.validateCheckout = validateCheckout;
|
|
147
|
+
exports.validateTrial = validateTrial;
|
|
118
148
|
exports.validateUpsell = validateUpsell;
|
|
119
|
-
//# sourceMappingURL=chunk-
|
|
120
|
-
//# sourceMappingURL=chunk-
|
|
149
|
+
//# sourceMappingURL=chunk-RY3LOSVZ.cjs.map
|
|
150
|
+
//# sourceMappingURL=chunk-RY3LOSVZ.cjs.map
|