import type { FundingSession, OnrampAngle, OnrampMethodId, OnrampQuote, ResolvedFundingMethod, SessionStatus } from './fundingClient.js'; import { type UseFundingOptions } from './useFunding.js'; import type { FundingSessionRef } from './useFundingMethods.js'; export type UseOnrampOptions = UseFundingOptions & { /** * How to present a popup-angle checkout URL: * - 'popup' (default): `window.open` in a new window; the session keeps * polling here, so completion is detected even if the popup never redirects. * - 'redirect': navigate the current page to the provider checkout. * - 'manual': don't present anything — read `url` and render it yourself. */ mode?: 'popup' | 'redirect' | 'manual'; /** Buyer-country override forwarded to commit + quote calls. */ country?: string; }; export type OnrampOpenParams = { /** Fiat amount to prefill in the checkout, human units (e.g. "100.00"). */ sourceAmount?: string; /** ISO-4217 fiat currency for `sourceAmount`. */ sourceCurrency?: string; /** URL the provider redirects back to after checkout. */ redirectUrl?: string; /** * OTP-verified buyer identity — REQUIRED for the native wallet-pay angle * (`apple_pay` / `google_pay`), ignored otherwise. Verify email + phone via * Openfort's own OTP and capture the Coinbase Guest-Checkout consent BEFORE * calling open(); the server rejects the commit if these are missing, * malformed, or past Coinbase's re-verify window. */ walletPay?: { email: string; /** US mobile in E.164, e.g. "+14155550123". */ phoneNumber: string; /** ISO-8601 time the phone OTP was verified (Coinbase's 60-day window). */ phoneNumberVerifiedAt: string; /** ISO-8601 time the buyer accepted Coinbase's Guest Checkout terms. */ agreementAcceptedAt: string; /** Coinbase Verification API record ids (Coinbase-issued OTP). */ smsVerificationId?: string; emailVerificationId?: string; }; /** * Embedded element flow — present when the buyer authenticated with the * provider's embedded auth element and a payment method was collected (the * `embedded` angle). The commit creates a HEADLESS provider session; redeem * its secret afterwards via `sessions.onrampCheckout` inside the * coordinator's performCheckout. */ embedded?: { authIntentId: string; customerRef: string; paymentToken: string; }; }; export type UseOnramp = { /** * Commit the method as the session's payment method and present the checkout. * Resolves when the session reaches a terminal status (`succeeded` / `bounced` * / `expired`) — settlement is provider-webhook-driven, so this is the source * of truth, not the popup closing. */ open: (params?: OnrampOpenParams) => Promise; /** Price the route before committing — same provider the commit would use. */ quote: (params: { sourceAmount: string; sourceCurrency: string; }) => Promise; /** Session lifecycle status; 'idle' before open(). */ status: SessionStatus | 'idle'; /** * The committed checkout URL. For the `popup` angle it's the provider's hosted * page (auto-presented unless mode is 'manual'); for `native` it's the in-page * Pay-button link the caller mounts itself (never auto-presented). Null before * open() / when the provider returns none. */ url: string | null; /** The committed angle — branch on it to mount (`native`) vs open (`popup`). */ angle: OnrampAngle | null; session: FundingSession | null; /** True from open() until the checkout URL is presented (not until settlement). */ loading: boolean; error: Error | null; reset: () => void; /** * The buyer closed the hosted checkout popup while the session was still * non-terminal. NOT an outcome: they may have paid moments before closing (the * provider settles by webhook, which can land after), or they may have * abandoned. Polling continues either way — branch on this to offer "reopen" * / "I've finished" instead of leaving a spinner running against a window that * is no longer there. Always false on the `native` and `embedded` angles, and * when the popup was blocked. */ checkoutClosed: boolean; /** * Re-present the committed hosted checkout in a fresh popup — the same * provider session, so a buyer who closed the window by accident continues * where they left off. No-op unless a `popup`-angle url has been committed. */ present: () => void; }; /** * Execute ONE resolved fiat method against a funding session — the headless * engine behind the modal's card / Apple Pay / Google Pay / bank-transfer rows. * * Angle-agnostic to the caller: `popup` opens the provider's hosted checkout * (popup / redirect / manual); `native` (in-page provider SDK, e.g. Coinbase * wallet pay) commits a provider order from the OTP-verified `walletPay` identity * and surfaces its Pay-button `url` for the caller to mount in-page — the hook * never auto-presents a native url. Under the hood open() = `setPaymentMethod({ * type: 'onramp', method })` — one endpoint and one state machine shared with the * crypto rails, polled here until terminal. * * A funding session accepts a single payment method: after open(), retrying * requires a fresh session (create one per attempt). */ export declare function useOnramp(session: FundingSessionRef | null | undefined, method: ResolvedFundingMethod | OnrampMethodId | null | undefined, options?: UseOnrampOptions): UseOnramp;