/** * Types for the DeroPay Gateway HTTP client. * * These types represent the JSON API surface of a running DeroPay gateway. * Platform adapters (Medusa, Shopify, etc.) and external integrations use * this client to create invoices, check status, and manage payments. */ /** Invoice as returned by the gateway API (JSON-serialized) */ type GatewayInvoice = { id: string; name: string; description: string; status: "created" | "pending" | "confirming" | "completed" | "expired" | "partial"; /** Amount in atomic units (string for JSON serialization) */ amount: string; /** Amount received so far (string for JSON serialization) */ amountReceived: string; /** The integrated address for payment */ integratedAddress: string; /** Base wallet address */ baseAddress: string; /** When the invoice was created (ISO 8601) */ createdAt: string; /** When the invoice expires (ISO 8601) */ expiresAt: string; /** When the invoice was completed (ISO 8601, null if pending) */ completedAt: string | null; /** TTL in seconds */ ttlSeconds: number; /** Required confirmations */ requiredConfirmations: number; /** Payment transactions */ payments: GatewayPayment[]; /** Arbitrary merchant metadata */ metadata: Record; /** Escrow data if present */ escrow: GatewayEscrow | null; }; /** A payment transaction */ type GatewayPayment = { txid: string; amount: string; height: number; topoHeight: number; confirmations: number; status: "detected" | "confirming" | "confirmed"; detectedAt: string; }; /** Escrow data */ type GatewayEscrow = { scid: string; deployTxid: string; escrowStatus: string; sellerAddress: string; arbitratorAddress: string; feeBasisPoints: number; blockExpiration: number; buyerAddress: string | null; depositHeight: number | null; disputedAt: string | null; resolution: string | null; }; /** Input for creating an invoice */ type CreateInvoiceInput = { /** Amount in atomic units (for DERO-denominated invoices) */ amount?: number | bigint; /** Fiat amount in smallest currency unit (e.g., cents for USD) */ fiatAmount?: number; /** Currency code (e.g., "USD", "EUR"). If provided with fiatAmount, gateway converts to DERO */ currency?: string; /** Human-readable invoice name */ name?: string; /** Description */ description?: string; /** TTL in seconds (default: 900) */ ttlSeconds?: number; /** Required confirmations (default: 3) */ requiredConfirmations?: number; /** Arbitrary metadata to attach */ metadata?: Record; /** Webhook URL for this specific invoice (overrides gateway default) */ callbackUrl?: string; /** Escrow parameters */ escrow?: { sellerAddress: string; arbitratorAddress?: string; feeBasisPoints?: number; blockExpiration?: number; }; }; /** Gateway client configuration */ type GatewayClientConfig = { /** Base URL of the DeroPay gateway (e.g., "https://pay.example.com") */ gatewayUrl: string; /** API key for authentication */ apiKey: string; /** Request timeout in milliseconds (default: 30000) */ timeoutMs?: number; /** Custom fetch implementation (for testing or custom environments) */ fetch?: typeof globalThis.fetch; }; /** Gateway error response */ type GatewayError = { error: string; code?: string; details?: Record; }; /** Gateway health/info response */ type GatewayInfo = { version: string; chainId: "dero-mainnet" | "dero-testnet"; walletConnected: boolean; daemonConnected: boolean; blockHeight: number; }; /** * HTTP client for external platforms to interact with a DeroPay gateway. * * This is the universal client that platform adapters (Medusa, Shopify, etc.) * use to create invoices, check status, and manage payments via HTTP. * * @example * ```ts * import { GatewayClient } from "dero-pay/gateway"; * * const client = new GatewayClient({ * gatewayUrl: "https://pay.example.com", * apiKey: "sk_live_...", * }); * * const invoice = await client.createInvoice({ * amount: 5_000_000_000_000n, // 5 DERO * name: "Order #123", * }); * * console.log(invoice.integratedAddress); * ``` */ declare class GatewayClientError extends Error { readonly code: string; readonly statusCode: number; readonly details?: Record; constructor(message: string, code: string, statusCode: number, details?: Record); } declare class GatewayClient { private readonly gatewayUrl; private readonly apiKey; private readonly timeoutMs; private readonly fetch; constructor(config: GatewayClientConfig); /** * Make an authenticated request to the gateway. */ private request; /** * Create a new invoice. * * @param input - Invoice creation parameters * @returns The created invoice */ createInvoice(input: CreateInvoiceInput): Promise; /** * Get the current status of an invoice. * * @param invoiceId - The invoice ID * @returns The invoice with current status */ getInvoice(invoiceId: string): Promise; /** * Alias for getInvoice (backward compatibility). */ getStatus(invoiceId: string): Promise; /** * List invoices with optional filters. * * @param options - Filter options * @returns Array of invoices */ listInvoices(options?: { status?: string; limit?: number; offset?: number; }): Promise; /** * Get gateway health and info. * * @returns Gateway status information */ getInfo(): Promise; /** * Check if the gateway is reachable and healthy. * * @returns true if healthy, false otherwise */ isHealthy(): Promise; } export { type CreateInvoiceInput, GatewayClient, type GatewayClientConfig, GatewayClientError, type GatewayError, type GatewayEscrow, type GatewayInfo, type GatewayInvoice, type GatewayPayment };