import type { UpdateBillingAutoTopUpRequest } from "@opengeni/contracts"; import { type Database } from "./database.js"; export type AutoTopUpSettingsRow = { account_id: string; enabled: boolean; threshold_micros: number; amount_micros: number; monthly_cap_micros: number; consent_subject: string | null; consent_version: string | null; consent_at: string | null; provider: "stripe:test" | "stripe:live" | null; customer_id: string | null; payment_method_id: string | null; payment_method_brand: string | null; payment_method_last4: string | null; setup_key: string | null; setup_subject: string | null; failure_reason: string | null; cap_required_micros: number | null; revision: string; }; export type AutoTopUpIntent = { provider: "stripe:test" | "stripe:live"; customerId: string; paymentMethodId: string; consentSubject: string; settingsRevision: string; taxCalculationId: string; taxExpiresAt: number; receiptEmail: string | null; }; export type AutoTopUpOperation = { account_id: string; operation_key: string; state: "pending" | "succeeded" | "failed"; reservation_month: string; credit_micros: number; charge_micros: number; intent: AutoTopUpIntent; payment_intent_id: string | null; confirmation_started_at: string | null; charged_at: string | null; failure_reason: string | null; notification_delivered_at: string | null; created_at: string; completed_at: string | null; }; export type AutoTopUpNotification = { accountId: string; kind: "topup_success" | "topup_failed" | "cap_reached"; operationKey: string; amountMicros: number; chargeMicros: number; failureReason?: string; }; /** The notification worker owns delivery/outbox. Enqueue with this transaction and * stable operationKey; never send network email from this callback. */ export type AutoTopUpNotificationPort = (tx: Database, event: AutoTopUpNotification) => Promise; export declare class AutoTopUpStoreError extends Error { readonly status: 403 | 409 | 422; constructor(status: 403 | 409 | 422, message: string); } export declare class AutoTopUpAccountStore { readonly tx: Database; readonly accountId: string; readonly notify?: AutoTopUpNotificationPort | undefined; constructor(tx: Database, accountId: string, notify?: AutoTopUpNotificationPort | undefined); settings(): Promise; clock(): Promise<{ now: string; month: string; }>; spent(): Promise; operation(key: string): Promise; pending(): Promise; assertOwner(subject: string): Promise; update(subject: string, request: UpdateBillingAutoTopUpRequest): Promise; startSetup(subject: string, key: string, provider: AutoTopUpIntent["provider"], customerId: string): Promise; finishSetup(input: { key: string; subject: string; provider: AutoTopUpIntent["provider"]; customerId: string; methodId: string; brand: string; last4: string; }): Promise; customer(provider: string): Promise; balance(): Promise; reserve(input: { key: string; creditMicros: number; chargeMicros: number; intent: AutoTopUpIntent; }): Promise; bind(key: string, paymentIntentId: string): Promise; markConfirmation(key: string): Promise; succeeded(operation: AutoTopUpOperation, chargedAt: string): Promise; failed(operation: AutoTopUpOperation, reason: string): Promise; disable(reason: string): Promise; failBeforePayment(settings: AutoTopUpSettingsRow, reason: string): Promise; deliverOutstanding(): Promise; capReached(settings: AutoTopUpSettingsRow, requiredMicros?: number): Promise; deliver(key: string): Promise; } export declare function autoTopUpCreditKey(operationKey: string): string; export interface AutoTopUpStore { locked(accountId: string, run: (account: AutoTopUpAccountStore) => Promise): Promise; } /** Root handle only: every call is an independent committed recovery checkpoint. */ export declare function billingAutoTopUpStore(db: Database, notify?: AutoTopUpNotificationPort): AutoTopUpStore;