@flopay/js 1.14.5 → 1.14.6

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.
@@ -0,0 +1,121 @@
1
+ import type { NormalizedCheckoutSession } from '@flopay/shared';
2
+ import { FloPayError } from '@flopay/shared';
3
+ import type { PaymentAPI } from './payment-api.js';
4
+ /**
5
+ * Outcome the backend's `/3ds/complete` sync resolver returns to the SDK.
6
+ * Mirrors `ThreeDsResolveOutcome` on the backend without importing it. The
7
+ * caller branches on `status`:
8
+ * - `succeeded` → show success
9
+ * - `authorized` → a captured-later authorization (manual capture); as
10
+ * terminal as `succeeded`
11
+ * - `declined` → a decline (the session stays `pending`, so polling
12
+ * session-status would just time out)
13
+ * - `timeout` → the documented 3DS timeout
14
+ * - `pending` / `requires_action` / `no_attempt` → fall back to the
15
+ * session-status poll
16
+ */
17
+ export type SavedCardChallengeOutcome = {
18
+ status: 'succeeded';
19
+ providerIntentId?: string | null;
20
+ } | {
21
+ status: 'authorized';
22
+ providerIntentId?: string | null;
23
+ } | {
24
+ status: 'declined';
25
+ providerIntentId?: string | null;
26
+ declineReason?: string | null;
27
+ gatewayDeclineReason?: string | null;
28
+ } | {
29
+ status: 'requires_action';
30
+ providerIntentId?: string | null;
31
+ nextActionRedirectUrl?: string | null;
32
+ } | {
33
+ status: 'pending';
34
+ providerIntentId?: string | null;
35
+ } | {
36
+ status: 'timeout';
37
+ providerIntentId?: string | null;
38
+ } | {
39
+ status: 'no_attempt';
40
+ } | {
41
+ status: 'unknown';
42
+ };
43
+ /** A `declined` outcome from `/3ds/complete`. */
44
+ export type SavedCardChallengeDecline = Extract<SavedCardChallengeOutcome, {
45
+ status: 'declined';
46
+ }>;
47
+ /** Input for {@link runSavedCardChallenge}. */
48
+ export interface SavedCardChallengeInput {
49
+ billingApiUrl: string;
50
+ sessionId: string;
51
+ /** Session-bound checkout token, sent as `x-checkout-session-token`. */
52
+ nonce: string;
53
+ /** The provider-hosted challenge the backend advertised for the attempt. */
54
+ nextActionRedirectUrl: string;
55
+ /**
56
+ * Legacy flows poll `/3ds/complete` while the challenge is open; provider-neutral
57
+ * saved cards complete once, only after the authenticated return. Defaults to polling.
58
+ */
59
+ pollCompletionEndpoint?: boolean;
60
+ /**
61
+ * Optional cancellation hook. SPA callers pass a signal tied to component
62
+ * unmount / route change so an abandoned challenge tears down its overlay
63
+ * (and rejects the promise) immediately.
64
+ */
65
+ signal?: AbortSignal;
66
+ }
67
+ /** Input for {@link completeSavedCardNextAction}. */
68
+ export interface SavedCardNextActionInput {
69
+ billingApiUrl: string;
70
+ sessionId: string;
71
+ /** Session-bound checkout token, sent as `x-checkout-session-token`. */
72
+ nonce: string;
73
+ /** The provider-hosted challenge the backend advertised for the attempt. */
74
+ nextActionRedirectUrl: string;
75
+ /** Cancels the challenge (component unmount, route change). */
76
+ signal?: AbortSignal;
77
+ /**
78
+ * Builds the error thrown for a `/3ds/complete` decline, so each framework
79
+ * keeps its own decline mapping. Defaults to a `FloPayError` whose `code` is
80
+ * the decline reason.
81
+ */
82
+ createDeclineError?: (decline: SavedCardChallengeDecline) => Error;
83
+ }
84
+ /** The buyer cancelled (or the owning UI unmounted) during a saved-card challenge. */
85
+ export declare function createSavedCardActionAbortedError(cause?: unknown): FloPayError;
86
+ /**
87
+ * Render a provider-hosted 3DS challenge in a full-page overlay iframe and
88
+ * resolve once the buyer completes (or abandons) it. This is the one saved-card
89
+ * challenge runner: `@flopay/react` and `@flopay/vue` both use it.
90
+ *
91
+ * The provider's challenge eventually redirects to `/v1/vault/3ds/return`,
92
+ * which postMessages `flopay-vault-3ds-return` back to the parent (this
93
+ * window). The promise resolves on receipt of that message — but only when it
94
+ * arrives from the challenge iframe (`event.source`) and the billing API
95
+ * origin, so a sibling frame on the merchant page can't dismiss the challenge
96
+ * early by forging the marker string. We then call `/3ds/complete` to drive the
97
+ * backend's sync resolver to write the terminal attempt row.
98
+ *
99
+ * The overlay carries `role="dialog"`/`aria-modal` and moves focus into the
100
+ * iframe on mount, restoring the prior focus target on teardown, so keyboard /
101
+ * screen-reader buyers aren't stranded on the obscured page.
102
+ *
103
+ * Times out after the 3DS challenge window with `three_ds_timeout`; an aborted
104
+ * `signal` rejects with `three_ds_aborted`.
105
+ */
106
+ export declare function runSavedCardChallenge(input: SavedCardChallengeInput): Promise<SavedCardChallengeOutcome>;
107
+ /**
108
+ * Complete a backend-owned saved-card challenge (`ACTION_REQUIRED` with a
109
+ * `nextActionRedirectUrl`) with no browser payment provider: show the
110
+ * challenge, post `/3ds/complete` once after the authenticated return, then
111
+ * reconcile the session through the authenticated `/status` endpoint.
112
+ *
113
+ * The status poll also races the challenge, because a provider sandbox can
114
+ * swallow the return-page message while the signed return endpoint still
115
+ * resolves the attempt server-side.
116
+ *
117
+ * Resolves with the reconciled session. Rejects with a decline (built by
118
+ * `createDeclineError`), `three_ds_timeout`, the status poll's own timeout, or
119
+ * `three_ds_aborted`.
120
+ */
121
+ export declare function completeSavedCardNextAction(input: SavedCardNextActionInput, api: Pick<PaymentAPI, 'waitForCheckoutSessionCompletion'>): Promise<NormalizedCheckoutSession>;
@@ -0,0 +1,9 @@
1
+ export declare const DEFAULT_SESSION_CREATE_TIMEOUT_MS = 12000;
2
+ export declare const SESSION_CREATE_MAX_ATTEMPTS = 3;
3
+ export interface SessionCreateDeadline {
4
+ signal: AbortSignal;
5
+ clear(): void;
6
+ }
7
+ export declare function startSessionCreateDeadline(timeoutMs?: number): SessionCreateDeadline;
8
+ /** Jittered exponential backoff that is bounded by the logical operation signal. */
9
+ export declare function waitForSessionCreateRetry(attempt: number, signal: AbortSignal): Promise<void>;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Client-side cache for display-only checkout fields the backend no longer
3
+ * persists (`overrideAmount`, `totalAmount`, `providerItemName`,
4
+ * `providerPlanName`, per-line `currency`).
5
+ *
6
+ * The cache lives in `sessionStorage` so it survives the navigation from the
7
+ * page that creates the session to the checkout page that fetches it, but
8
+ * dies on tab close. An in-memory fallback keeps the SDK working in Node /
9
+ * SSR contexts where `sessionStorage` is unavailable.
10
+ *
11
+ * Values from the server response always win — cached values fill in only
12
+ * where the server returned `null` or `undefined`.
13
+ */
14
+ /** Display-only fields per product that can be cached and merged back later. */
15
+ export interface SessionDisplayProduct {
16
+ /** Catalog code (match key). */
17
+ code?: string;
18
+ /** Whether this product is a one-time item or a recurring subscription. */
19
+ type?: 'item' | 'subscription';
20
+ /** Display-only name for the product. */
21
+ name?: string | null;
22
+ totalAmount?: number;
23
+ overrideAmount?: number | null;
24
+ currency?: string;
25
+ }
26
+ /** Display-only payload that can be stashed for later merge into a session response. */
27
+ export interface SessionDisplayCacheData {
28
+ /** Session-level currency (falls into the response only when the server omits it). */
29
+ currency?: string;
30
+ products?: SessionDisplayProduct[];
31
+ }
32
+ /**
33
+ * Stash display-only data for a session. Called client-side right after the
34
+ * server returns a session ID, so the values survive the redirect to the
35
+ * checkout page.
36
+ */
37
+ export declare function cacheSessionDisplayData(sessionId: string, data: SessionDisplayCacheData, options?: {
38
+ ttlMs?: number;
39
+ }): void;
40
+ /**
41
+ * Read previously-cached display data for a session, or `null` if nothing
42
+ * is cached (or the TTL has elapsed).
43
+ */
44
+ export declare function getSessionDisplayData(sessionId: string): SessionDisplayCacheData | null;
45
+ /**
46
+ * Drop any cached display data for a session. Call from the success page
47
+ * after the payment completes; otherwise the TTL handles cleanup.
48
+ */
49
+ export declare function clearSessionDisplayData(sessionId: string): void;
@@ -1,6 +1,3 @@
1
- export { C as CardCaptureOperation, P as PaymentAPI, a as PciVaultCardCapture, b as PciVaultCardCaptureConfig } from './pci-vault-card-capture-Dt3F9i7Q.cjs';
2
- import '@flopay/shared';
3
-
4
1
  /**
5
2
  * The Stripe redirect return of a payment-method setup surface. A buyer who
6
3
  * saves a redirect method (a bank or wallet that leaves the page) comes back
@@ -12,13 +9,11 @@ import '@flopay/shared';
12
9
  * Stripe.js.
13
10
  */
14
11
  /** A buyer returning from a wallet/APM redirect (Stripe's standard query params). */
15
- interface SetupRedirectReturn {
12
+ export interface SetupRedirectReturn {
16
13
  /** `redirect_status=failed`: the provider reports the setup failed. */
17
14
  failed: boolean;
18
15
  }
19
16
  /** Read a setup redirect return from the current URL, if this page load is one. */
20
- declare function readSetupRedirectReturn(): SetupRedirectReturn | null;
17
+ export declare function readSetupRedirectReturn(): SetupRedirectReturn | null;
21
18
  /** Drop the redirect-return params so a reload does not replay the outcome. */
22
- declare function clearSetupRedirectParams(): void;
23
-
24
- export { type SetupRedirectReturn, clearSetupRedirectParams, readSetupRedirectReturn };
19
+ export declare function clearSetupRedirectParams(): void;
@@ -0,0 +1,13 @@
1
+ import type { FloPayConfig, PaymentProviderAdapter } from '@flopay/shared';
2
+ export type { StripeSafeAppearance } from '@flopay/shared';
3
+ export { toStripeAppearance, toStripeAppearanceTheme } from '@flopay/shared';
4
+ /** @internal Classifies only the SDK-owned falsey Stripe loader branch. */
5
+ export declare function isInvalidStripeResponse(error: unknown): boolean;
6
+ /** Payment provider adapter backed by Stripe. */
7
+ export declare class StripeAdapter implements PaymentProviderAdapter {
8
+ readonly name = "stripe";
9
+ private stripe;
10
+ initialize(config: FloPayConfig): Promise<void>;
11
+ getRawProvider(): unknown;
12
+ destroy(): void;
13
+ }
@@ -0,0 +1,18 @@
1
+ import type { TelemetryCheckoutContext, TelemetryReporter, TelemetryReporterErrorInput, TelemetryReporterLogInput, TelemetryReporterObservation, TelemetryReporterPerformanceInput, TelemetryReporterTerminalInput } from './telemetry-reporter.js';
2
+ export interface FloPayTelemetryBridge {
3
+ error(input: TelemetryReporterErrorInput): void;
4
+ log(input: TelemetryReporterLogInput): void;
5
+ performance(input: TelemetryReporterPerformanceInput): void;
6
+ terminal(input: TelemetryReporterTerminalInput): void;
7
+ now(): number;
8
+ elapsed(startedAt: number): number;
9
+ setCheckoutContext(context: TelemetryCheckoutContext): void;
10
+ beginCheckout(context?: TelemetryCheckoutContext): number;
11
+ disable(): void;
12
+ subscribe(observer: (event: TelemetryReporterObservation) => void): () => void;
13
+ flush(): Promise<void>;
14
+ }
15
+ /** Attach the non-enumerable bridge consumed by @flopay/react. */
16
+ export declare function attachFloPayTelemetryBridge(target: object, reporter: TelemetryReporter | undefined, fallbackNow: () => number): void;
17
+ /** Read the bridge inside @flopay/js without making it a package export. */
18
+ export declare function getFloPayTelemetryBridge(target: object): FloPayTelemetryBridge | undefined;
@@ -0,0 +1,81 @@
1
+ import type { BuildTelemetryErrorEventInput, BuildTelemetryLogEventInput, BuildTelemetryPerformanceEventInput, BuildTelemetryTerminalEventInput, TelemetryCheckoutMode, TelemetryLayout, TelemetrySdkPackage } from '@flopay/shared';
2
+ export interface TelemetryReporterOptions {
3
+ billingApiUrl: string;
4
+ /** Package that owns every event in this package-homogeneous reporter. */
5
+ sdkPackage?: TelemetrySdkPackage;
6
+ sdkVersion: string;
7
+ enabled?: boolean;
8
+ /** @internal Monotonic clock injection for deterministic SDK tests. */
9
+ clock?: () => number;
10
+ }
11
+ export type TelemetryReporterLogInput = Omit<BuildTelemetryLogEventInput, 'eventId' | 'sequence'>;
12
+ export type TelemetryReporterErrorInput = Omit<BuildTelemetryErrorEventInput, 'eventId' | 'sequence'>;
13
+ export type TelemetryReporterPerformanceInput = Omit<BuildTelemetryPerformanceEventInput, 'eventId' | 'sequence'>;
14
+ export type TelemetryReporterTerminalInput = Omit<BuildTelemetryTerminalEventInput, 'eventId' | 'sequence'>;
15
+ export type TelemetryReporterObservation = ({
16
+ class: 'lifecycle';
17
+ } & TelemetryReporterLogInput) | ({
18
+ class: 'technical_error';
19
+ } & TelemetryReporterErrorInput);
20
+ export interface TelemetryCheckoutContext {
21
+ checkoutMode?: TelemetryCheckoutMode;
22
+ layout?: TelemetryLayout;
23
+ }
24
+ /** Monotonic SDK clock. Telemetry never reads Resource Timing or page URLs. */
25
+ export declare function telemetryNow(): number;
26
+ /**
27
+ * Bounded, best-effort browser telemetry reporter. It accepts only the closed
28
+ * shared contract and never exposes custom event fields or endpoint settings.
29
+ */
30
+ export declare class TelemetryReporter {
31
+ private readonly endpoint;
32
+ private readonly sdkPackage;
33
+ private readonly sdkVersion;
34
+ private readonly correlationId;
35
+ private merchantEnabled;
36
+ private readonly clock;
37
+ private readonly browserTransportAvailable;
38
+ private ingestionDisabled;
39
+ private readonly queue;
40
+ private sequence;
41
+ private flushTimer;
42
+ private flushInFlight;
43
+ private readonly reportedFailures;
44
+ private checkoutContext;
45
+ private checkoutStartedAt;
46
+ private destroyed;
47
+ private readonly observers;
48
+ private readonly pageExitHandler;
49
+ private readonly visibilityHandler;
50
+ private eventCounts;
51
+ constructor(options: TelemetryReporterOptions);
52
+ log(input: TelemetryReporterLogInput): void;
53
+ error(input: TelemetryReporterErrorInput): void;
54
+ performance(input: TelemetryReporterPerformanceInput): void;
55
+ terminal(input: TelemetryReporterTerminalInput): void;
56
+ /** @internal Read the reporter's monotonic clock without Resource Timing. */
57
+ now(): number;
58
+ /** @internal Observe the closed taxonomy without exposing queued event payloads. */
59
+ subscribe(observer: (event: TelemetryReporterObservation) => void): () => void;
60
+ private notify;
61
+ private pruneReportedFailures;
62
+ private rememberReportedFailure;
63
+ /** @internal Add closed checkout dimensions to subsequent SDK events. */
64
+ setCheckoutContext(context: TelemetryCheckoutContext): void;
65
+ /** @internal Start a fresh checkout budget, dedupe window, and total span. */
66
+ beginCheckout(context?: TelemetryCheckoutContext): number;
67
+ private enqueue;
68
+ private canCollect;
69
+ /** Flush one bounded batch. Failures are intentionally dropped. */
70
+ flush(): Promise<void>;
71
+ /** Flush pending work and detach browser lifecycle listeners. */
72
+ destroy(): void;
73
+ /** Permanently honor a merchant opt-out and discard queued events. */
74
+ disable(): void;
75
+ /** Start every bounded keepalive request synchronously before page teardown. */
76
+ private drainQueue;
77
+ private sendBatch;
78
+ private disableFromIngestion;
79
+ private scheduleFlush;
80
+ private clearFlushTimer;
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flopay/js",
3
- "version": "1.14.5",
3
+ "version": "1.14.6",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "publishConfig": {
@@ -31,17 +31,17 @@
31
31
  "dist"
32
32
  ],
33
33
  "dependencies": {
34
- "@flopay/shared": "1.14.5",
34
+ "@flopay/shared": "1.14.6",
35
35
  "@stripe/stripe-js": "^9.17.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "jsdom": "^29.1.1",
39
39
  "tsup": "^8.3.0",
40
- "typescript": "^6.0.3",
40
+ "typescript": "^7.0.2",
41
41
  "vitest": "4.1.12"
42
42
  },
43
43
  "scripts": {
44
- "build": "tsup",
44
+ "build": "tsup && tsc -p tsconfig.build.json",
45
45
  "dev": "tsup --watch",
46
46
  "typecheck": "tsc --noEmit",
47
47
  "test": "vitest run",
package/dist/index.d.cts DELETED
@@ -1,232 +0,0 @@
1
- import { CreateSessionParams, CheckoutSessionResult, PaymentProviderAdapter, FloPayConfig, CaptureMethod, CardCaptureAdapter, CheckoutSession, NormalizedCheckoutSession, FloPayError } from '@flopay/shared';
2
- export { SentryEventLike, SentryStackFrameLike, StripeSafeAppearance, dropThirdPartyOnlyError, toStripeAppearance, toStripeAppearanceTheme } from '@flopay/shared';
3
- import { P as PaymentAPI } from './pci-vault-card-capture-Dt3F9i7Q.cjs';
4
- export { C as CardCaptureOperation, a as PciVaultCardCapture, b as PciVaultCardCaptureConfig, S as SESSION_CREATE_TELEMETRY, c as SessionDisplayCacheData, d as SessionDisplayProduct, e as cacheSessionDisplayData, f as clearSessionDisplayData, g as getSessionDisplayData } from './pci-vault-card-capture-Dt3F9i7Q.cjs';
5
-
6
- declare function createCheckoutSession(options: CreateSessionParams): Promise<CheckoutSessionResult>;
7
- /**
8
- * Creates a checkout session with automatic retry on transient transport,
9
- * timeout/abort, and idempotency-in-progress errors.
10
- *
11
- * Uses jittered exponential backoff under the same total deadline as a single
12
- * create (12 seconds by default, configurable with `timeoutMs`).
13
- *
14
- * The idempotency key (supplied or generated) is resolved **once**, before the
15
- * retry loop, and reused for every attempt — so a timeout, a lost response, or
16
- * a documented in-progress reply all replay the *same* key and cannot mint a
17
- * second checkout session (TeamFloPay/backend#972). A later independent call
18
- * resolves its own fresh key. A payload-conflict (`409`) is surfaced without
19
- * retrying, since only the exact same request may safely replay a key.
20
- */
21
- declare function createCheckoutSessionWithRetries(options: CreateSessionParams & {
22
- maxRetries?: number;
23
- }): Promise<CheckoutSessionResult>;
24
-
25
- /**
26
- * The main FloPay SDK instance.
27
- *
28
- * Created via `loadFloPay(publishableKey)`. Provides hosted card capture,
29
- * raw-provider access, and session retrieval.
30
- */
31
- declare class FloPay {
32
- private readonly provider;
33
- private readonly config;
34
- private readonly telemetryReporter?;
35
- private now;
36
- constructor(provider: PaymentProviderAdapter, config: FloPayConfig);
37
- /**
38
- * Create a {@link CardCaptureAdapter} for collecting card details through the
39
- * backend-rendered hosted vault PCI widget (TeamFloPay/backend#823).
40
- *
41
- * The returned adapter injects the server-supplied widget HTML (the session's
42
- * {@link CheckoutSession.vault} block, or one fetched via
43
- * `PaymentAPI.getVaultCapture`) and relays the widget's terminal outcome. The
44
- * backend owns tokenization, the PaymentIntent, 3DS, and fulfilment — no
45
- * Stripe.js is involved on the card path and PCI-sensitive fields never enter
46
- * the SDK runtime.
47
- */
48
- cardCapture(options?: {
49
- /** Checkout session id to bind the capture to (outcome correlation). */
50
- sessionId?: string;
51
- /** Capture behavior used to classify legacy vault outcomes safely. */
52
- captureMethod?: CaptureMethod;
53
- }): CardCaptureAdapter;
54
- /**
55
- * Retrieves a checkout session by ID via the billing API.
56
- *
57
- * Returns the normalized `CheckoutSession` with amount, currency,
58
- * customer data, and status.
59
- *
60
- * Requires `billingApiUrl` to be set — either via `loadFloPay(key, { billingApiUrl })`
61
- * or passed directly as the second argument.
62
- */
63
- retrieveSession(sessionId: string, billingApiUrl?: string): Promise<CheckoutSession>;
64
- /**
65
- * Retrieves and normalizes a checkout session, including provider-specific
66
- * data (Stripe clientSecret/publishableKey, Chargebee site, etc.).
67
- *
68
- * The billing API URL is resolved from: explicit param → `loadFloPay()` config
69
- * → `NEXT_PUBLIC_FLOPAY_ENV` env var → `configureFlopay()` → staging fallback.
70
- */
71
- retrieveUnifiedSession(sessionId: string, billingApiUrl?: string): Promise<NormalizedCheckoutSession>;
72
- /**
73
- * Returns the raw underlying provider instance (e.g. Stripe object).
74
- * Used internally by components that need direct provider access.
75
- */
76
- getRawProvider(): unknown;
77
- /** Tears down the SDK instance and releases resources. */
78
- destroy(): void;
79
- }
80
-
81
- /**
82
- * Loads and initializes the FloPay SDK.
83
- *
84
- * This is the primary entry point for consumer applications.
85
- * It initializes the underlying payment provider (currently Stripe)
86
- * and returns a ready-to-use `FloPay` instance.
87
- *
88
- * Instances are cached per complete behavior-affecting configuration.
89
- * Matching calls return the same instance; calls with different billing API,
90
- * telemetry, locale, API version, or appearance options receive independent
91
- * instances.
92
- *
93
- * @example
94
- * ```ts
95
- * import { loadFloPay } from '@flopay/js';
96
- *
97
- * const flopay = await loadFloPay('pk_test_...');
98
- * const session = await flopay.retrieveSession('session_uuid');
99
- * console.log(session.status);
100
- * ```
101
- */
102
- declare function loadFloPay(publishableKey: string, options?: Omit<FloPayConfig, 'publishableKey'>): Promise<FloPay>;
103
-
104
- /**
105
- * Outcome the backend's `/3ds/complete` sync resolver returns to the SDK.
106
- * Mirrors `ThreeDsResolveOutcome` on the backend without importing it. The
107
- * caller branches on `status`:
108
- * - `succeeded` → show success
109
- * - `authorized` → a captured-later authorization (manual capture); as
110
- * terminal as `succeeded`
111
- * - `declined` → a decline (the session stays `pending`, so polling
112
- * session-status would just time out)
113
- * - `timeout` → the documented 3DS timeout
114
- * - `pending` / `requires_action` / `no_attempt` → fall back to the
115
- * session-status poll
116
- */
117
- type SavedCardChallengeOutcome = {
118
- status: 'succeeded';
119
- providerIntentId?: string | null;
120
- } | {
121
- status: 'authorized';
122
- providerIntentId?: string | null;
123
- } | {
124
- status: 'declined';
125
- providerIntentId?: string | null;
126
- declineReason?: string | null;
127
- gatewayDeclineReason?: string | null;
128
- } | {
129
- status: 'requires_action';
130
- providerIntentId?: string | null;
131
- nextActionRedirectUrl?: string | null;
132
- } | {
133
- status: 'pending';
134
- providerIntentId?: string | null;
135
- } | {
136
- status: 'timeout';
137
- providerIntentId?: string | null;
138
- } | {
139
- status: 'no_attempt';
140
- } | {
141
- status: 'unknown';
142
- };
143
- /** A `declined` outcome from `/3ds/complete`. */
144
- type SavedCardChallengeDecline = Extract<SavedCardChallengeOutcome, {
145
- status: 'declined';
146
- }>;
147
- /** Input for {@link runSavedCardChallenge}. */
148
- interface SavedCardChallengeInput {
149
- billingApiUrl: string;
150
- sessionId: string;
151
- /** Session-bound checkout token, sent as `x-checkout-session-token`. */
152
- nonce: string;
153
- /** The provider-hosted challenge the backend advertised for the attempt. */
154
- nextActionRedirectUrl: string;
155
- /**
156
- * Legacy flows poll `/3ds/complete` while the challenge is open; provider-neutral
157
- * saved cards complete once, only after the authenticated return. Defaults to polling.
158
- */
159
- pollCompletionEndpoint?: boolean;
160
- /**
161
- * Optional cancellation hook. SPA callers pass a signal tied to component
162
- * unmount / route change so an abandoned challenge tears down its overlay
163
- * (and rejects the promise) immediately.
164
- */
165
- signal?: AbortSignal;
166
- }
167
- /** Input for {@link completeSavedCardNextAction}. */
168
- interface SavedCardNextActionInput {
169
- billingApiUrl: string;
170
- sessionId: string;
171
- /** Session-bound checkout token, sent as `x-checkout-session-token`. */
172
- nonce: string;
173
- /** The provider-hosted challenge the backend advertised for the attempt. */
174
- nextActionRedirectUrl: string;
175
- /** Cancels the challenge (component unmount, route change). */
176
- signal?: AbortSignal;
177
- /**
178
- * Builds the error thrown for a `/3ds/complete` decline, so each framework
179
- * keeps its own decline mapping. Defaults to a `FloPayError` whose `code` is
180
- * the decline reason.
181
- */
182
- createDeclineError?: (decline: SavedCardChallengeDecline) => Error;
183
- }
184
- /** The buyer cancelled (or the owning UI unmounted) during a saved-card challenge. */
185
- declare function createSavedCardActionAbortedError(cause?: unknown): FloPayError;
186
- /**
187
- * Render a provider-hosted 3DS challenge in a full-page overlay iframe and
188
- * resolve once the buyer completes (or abandons) it. This is the one saved-card
189
- * challenge runner: `@flopay/react` and `@flopay/vue` both use it.
190
- *
191
- * The provider's challenge eventually redirects to `/v1/vault/3ds/return`,
192
- * which postMessages `flopay-vault-3ds-return` back to the parent (this
193
- * window). The promise resolves on receipt of that message — but only when it
194
- * arrives from the challenge iframe (`event.source`) and the billing API
195
- * origin, so a sibling frame on the merchant page can't dismiss the challenge
196
- * early by forging the marker string. We then call `/3ds/complete` to drive the
197
- * backend's sync resolver to write the terminal attempt row.
198
- *
199
- * The overlay carries `role="dialog"`/`aria-modal` and moves focus into the
200
- * iframe on mount, restoring the prior focus target on teardown, so keyboard /
201
- * screen-reader buyers aren't stranded on the obscured page.
202
- *
203
- * Times out after the 3DS challenge window with `three_ds_timeout`; an aborted
204
- * `signal` rejects with `three_ds_aborted`.
205
- */
206
- declare function runSavedCardChallenge(input: SavedCardChallengeInput): Promise<SavedCardChallengeOutcome>;
207
- /**
208
- * Complete a backend-owned saved-card challenge (`ACTION_REQUIRED` with a
209
- * `nextActionRedirectUrl`) with no browser payment provider: show the
210
- * challenge, post `/3ds/complete` once after the authenticated return, then
211
- * reconcile the session through the authenticated `/status` endpoint.
212
- *
213
- * The status poll also races the challenge, because a provider sandbox can
214
- * swallow the return-page message while the signed return endpoint still
215
- * resolves the attempt server-side.
216
- *
217
- * Resolves with the reconciled session. Rejects with a decline (built by
218
- * `createDeclineError`), `three_ds_timeout`, the status poll's own timeout, or
219
- * `three_ds_aborted`.
220
- */
221
- declare function completeSavedCardNextAction(input: SavedCardNextActionInput, api: Pick<PaymentAPI, 'waitForCheckoutSessionCompletion'>): Promise<NormalizedCheckoutSession>;
222
-
223
- /** Payment provider adapter backed by Stripe. */
224
- declare class StripeAdapter implements PaymentProviderAdapter {
225
- readonly name = "stripe";
226
- private stripe;
227
- initialize(config: FloPayConfig): Promise<void>;
228
- getRawProvider(): unknown;
229
- destroy(): void;
230
- }
231
-
232
- export { FloPay, PaymentAPI, type SavedCardChallengeDecline, type SavedCardChallengeInput, type SavedCardChallengeOutcome, type SavedCardNextActionInput, StripeAdapter, completeSavedCardNextAction, createCheckoutSession, createCheckoutSessionWithRetries, createSavedCardActionAbortedError, loadFloPay, runSavedCardChallenge };