import type { BillingAdapter, BillingConfig } from "./types.js"; export type SavedCard = { id: string; /** "visa" | "mastercard" | "amex" | … as Stripe reports it. */ brand: string; last4: string; expMonth: number; expYear: number; /** "credit" | "debit" | "prepaid" | "unknown" — Stripe's funding type. */ funding: string; /** Charged by future invoices. */ isDefault: boolean; /** Two-letter country of the billing address, when one was collected. */ country: string | null; }; /** * Cards saved against the org's customer, default first. * * Returns an empty array (never throws) when the org has no Stripe customer * yet, which is the normal state for a workspace that has never paid. */ export declare function listPaymentMethods(adapter: BillingAdapter, orgId: string): Promise; /** * A SetupIntent for adding a card without charging it. * * `usage: "off_session"` is what makes the saved card usable for later * invoices; with the default (`on_session`) a renewal would fail * authentication with nobody there to complete it. * * Needs an existing customer — call `ensureStripeCustomer` first if the org * might not have one. */ export declare function createCardSetupIntent(adapter: BillingAdapter, orgId: string, opts?: { /** * A payment-method configuration id (see `ensurePaymentMethodConfig`). * * The ONLY way to keep Link out of this form. `payment_method_types: ["card"]` * removes Link as a payment METHOD but not its inline signup ("Save my info * for faster checkout"), which the Payment Element draws from the account's * Link setting. Mutually exclusive with `payment_method_types`, so passing * this replaces it. * * Omit it and the library provisions its own (card + the wallets, no Link) — * `defaultPaymentMethodConfig`. Pass one only to offer something else. */ paymentMethodConfiguration?: string; /** Config, read for `paymentMethods.link`. */ config?: BillingConfig; }): Promise<{ clientSecret: string; customerId: string; }>; /** * A Checkout Session in `mode: "setup"` — saves a card, charges nothing. * * Same job as `createCardSetupIntent`, different UI. A SetupIntent is mounted with * `BillingPaymentForm`, which renders Stripe's plain `AddressElement`: six prefilled * address inputs. A Checkout Session is mounted with `BillingCheckoutSessionForm`, * which renders `BillingAddressElement` — the collapsed "name / street / city" * summary with a change link, and the saved cards the customer already has. That * collapsed box CANNOT be had from the SetupIntent path at any configuration, so a * surface that must look like the subscription checkout or a top-up has to be a * session. Use this one there, and `createCardSetupIntent` for a plain * "add a card" screen where matching a payment flow doesn't matter. * * `currency` is required by Stripe in setup mode before it will offer the wallets — * a session without it silently drops Apple Pay and Google Pay. * * Returns the id as well as the secret, because a setup session carries its result * in a SetupIntent the browser never sees: read the saved card back with * `savedCardFromCheckoutSession(sessionId)` once the form confirms. */ export declare function createCardSetupCheckoutSession(adapter: BillingAdapter, orgId: string, opts: { /** Where Stripe returns after an off-site step (3DS). Must be absolute. */ returnUrl: string; /** Three-letter code. Needed for the wallets — see above. */ currency: string; paymentMethodConfiguration?: string; config?: BillingConfig; }): Promise<{ clientSecret: string; sessionId: string; }>; /** * The card a confirmed setup session saved, or null if it saved none. * * The browser only learns that confirmation succeeded, so the id has to be read * here — from the session's SetupIntent, not by listing the customer's cards and * taking the newest, which is a race the moment two tabs are open. */ export declare function savedCardFromCheckoutSession(sessionId: string): Promise; /** Make a saved card the one future invoices charge. */ export declare function setDefaultPaymentMethod(adapter: BillingAdapter, orgId: string, paymentMethodId: string): Promise; /** * Remove a saved card. * * Refuses to remove the default while another card exists, because Stripe does * not promote a replacement — the customer would silently be left with cards on * file and no default, and the next invoice would fail. Removing the LAST card * is allowed: that is a deliberate "I'm done here", not an accident. */ export declare function detachPaymentMethod(adapter: BillingAdapter, orgId: string, paymentMethodId: string): Promise; /** * Record that a card was just charged. * * Written to the PaymentMethod's own metadata rather than a table: it is a fact about the * card, it survives every path that charges one (an app, the dashboard, a future service), * and it cannot drift from the card's lifetime — a detached card takes its stamp with it. */ export declare function touchPaymentMethod(paymentMethodId: string): Promise; /** * How many cards a customer keeps, by default. * * Not a Stripe limit — measured: 105 cards attached to one customer with no error. It is a * product rule, to keep the list a list, and Stripe's own list call pages at 100, so an * unbounded list would need pagination to stay honest. Override per deployment with * `config.paymentMethods.maxCards`. */ export declare const DEFAULT_MAX_CARDS = 3; /** * Keep the newest cards and drop the stalest, so paying with a new card does not need the * customer to go and delete an old one first. * * WHICH card goes: the LEAST recently used one that is not the default. Least recently used, * not most — the point is to evict the card nobody reaches for. Ranked by the `last_used_at` * stamp `touchPaymentMethod` writes, falling back to Stripe's `created` for a card never * charged, so a never-used card is always evicted before a used one. * * The DEFAULT is never evicted at any count: it is what every invoice and every auto-reload * charges, and dropping it would leave a customer with cards on file and no way to bill them. * * Returns the ids actually detached — the caller decides whether to mention it. */ export declare function prunePaymentMethods(adapter: BillingAdapter, orgId: string, max?: number): Promise; /** * The FIRST card a customer saves becomes the default, asked for or not. * * Not a convenience: a customer with exactly one card and no default has a card on file * and nothing to charge — every invoice and every auto-reload reads the default, so the * quiet failure is a payment that never happens. Saving a second card changes nothing * unless `setDefault` says so. */ export declare function attachedPaymentMethod(adapter: BillingAdapter, orgId: string, paymentMethodId: string, opts?: { setDefault?: boolean; }): Promise<{ madeDefault: boolean; }>; //# sourceMappingURL=payment-methods.d.ts.map