interface VouchConfig { apiKey: string; /** API base including `/api/v1`. Omit only for local dev (see `DEFAULT_DEV_BASE_URL`). */ baseUrl?: string; version?: string; /** When true, {@link Vouch.vouchers.shouldShowUI} requires spendable balance. */ showVoucherOnlyWithBalance?: boolean; } interface Meta { request_id: string; timestamp: string; api_version: string; } interface ApiResponse { data: T; meta: Meta; } interface ApiListResponse { data: T[]; meta: Meta; pagination?: { total: number; page: number; page_size: number; has_more: boolean; }; } interface ApiError { error: { code: string; message: string; details?: unknown; request_id: string; }; } interface Program { id: string; slug: string; name: string; description: string; currency: string; currencySymbol: string; defaultLocale: string; supportedLocales: string; createdAt: string; updatedAt: string; } interface ProgramStats { totalBeneficiaries: number; activeVouchers: number; treasuryBalance: number; redemptionRate: number; settlementRate: number; } interface Beneficiary { id: string; childName: string; phone: string; enrolledAt: string; } interface PaymentIntent { id: string; intentId: string; merchantId: string; totalAmount: number; eligibleAmount: number; status: string; createdAt: string; } interface Merchant { id: string; name: string; merchantType: string | null; active: boolean; } interface Voucher { valid: boolean; tokenId: string; value: number; remaining: number; state: string; expiry: string; } interface VoucherBalanceStatus { normalizedPhone: string; beneficiaryId: string | null; programId: string; programSlug?: string | null; hasVoucher: boolean; hasBalance: boolean; tokenId: number | null; status: string | null; remainingBalanceMinor: number; currency: string; currencySymbol: string; expiresAt: string | null; } interface UPIData { type: "upi"; raw: string; upiId: string; merchantName?: string; amount?: string; /** Merchant Category Code from UPI QR (4-digit ISO 18245), if present */ mcc?: string; } interface UPIScheme { pa?: string; pn?: string; am?: string; cu?: string; tn?: string; tr?: string; url?: string; mc?: string; } interface UPIIntentResponse { intentId: string; status: string; totalAmount: number; eligibleAmount: number; tokenId: number | null; upiId: string; merchantId: string | null; merchantName: string | null; /** "registered" if merchant is in the platform DB, "open_network" if unregistered UPI merchant */ merchantResolution: "registered" | "open_network"; /** "onchain" | "fiat" — how this payment will be settled */ settlementRail: string; /** When true, partner moves the money; Vouch records ledger settlement but skips the UPI payout engine. */ externalSettlement: boolean; currency: string; currencySymbol: string; expiresAt: string; } interface AuthorizeEligibleItem { name: string; nameHi?: string | null; qty: number; lineTotal: number; categoryCode: string; } interface AuthorizeResponse { success: true; authId: string; intentId: string; approvedAmount: number; rejectedAmount: number; merchantName: string; merchantId: string; programId: string | null; currency: string; currencySymbol: string; minorUnit: number; status: "AUTHORIZED"; eligibleItems: AuthorizeEligibleItem[]; } interface IntentSettlement { chainStatus: string; redeemTxHash: string | null; releaseTxHash: string | null; } interface IntentAuthorization { authId: string; approvedAmount: number; rejectedAmount: number; status: string; settlement: IntentSettlement | null; } interface IntentStatusResponse { success: true; intentId: string; merchantName: string; totalAmount: number; eligibleAmount: number; status: string; expiresAt: string; items: unknown[]; authorization: IntentAuthorization | null; } interface UPIScannerOptions { container: string | HTMLElement; onScan: (data: UPIData) => void; onError?: (error: Error) => void; width?: number; height?: number; fps?: number; debounceMs?: number; } declare class Vouch { private apiKey; private baseUrl; private version; readonly showVoucherOnlyWithBalance: boolean; constructor(config: VouchConfig); private request; programs: { list: () => Promise<{ programs: Program[]; }>; get: (slug: string) => Promise<{ program: Program; }>; create: (params: { slug: string; name: string; currency?: string; currencySymbol?: string; description?: string; defaultLocale?: string; supportedLocales?: string[]; }) => Promise>; stats: (slug: string) => Promise>; enrol: (slug: string, params: { phone: string; fields?: Record; }, options?: { idempotencyKey?: string; }) => Promise>; }; payments: { createIntent: (params: { merchantId: string; items: Array<{ sku: string; name: string; categoryCode: string; qty: number; unitPrice: number; }>; programId?: string; }) => Promise>; quote: (params: { intentId: string; tokenId: number; }) => Promise>; authorize: (params: { intentId: string; }) => Promise; /** * Initiate a payment from a scanned UPI QR code. * * Resolves the merchant by UPI ID, looks up the beneficiary's voucher * (via tokenId + programId, or via the authenticated session), creates * a PaymentIntent, and auto-quotes if a matching voucher is found. * * For partner integrations using API key auth, pass `beneficiaryPhone` * or `beneficiaryId` to identify the beneficiary without a session. * * Set `externalSettlement: true` when your platform moves the money itself * (open-network UPI). Settlement then records the voucher ledger entry and * marks the payment SETTLED, but Vouch does NOT call the UPI rail engine to * perform/confirm the payout. Optionally pass your own `payoutReference`. */ initiateUPI: (params: { upiData: UPIData; tokenId?: number; programId: string; beneficiaryPhone?: string; beneficiaryId?: string; externalSettlement?: boolean; payoutReference?: string; }) => Promise; getIntent: (intentId: string) => Promise; }; vouchers: { verify: (token: string, programId?: string) => Promise>; getBalance: (params: { beneficiaryPhone: string; programId: string; }) => Promise<{ success: true; } & VoucherBalanceStatus>; shouldShowUI: (params: { beneficiaryPhone: string; programId: string; }) => Promise; }; merchants: { list: (programId?: string) => Promise>; }; } declare class VouchError extends Error { code: string; statusCode: number; requestId?: string; constructor(code: string, message: string, statusCode: number, requestId?: string); } /** Origin of the local Vouch backend (no path). */ declare const DEFAULT_DEV_BACKEND_ORIGIN = "http://localhost:9393"; /** Default API base when {@link VouchConfig.baseUrl} is omitted (local dev only). */ declare const DEFAULT_DEV_BASE_URL = "http://localhost:9393/api/v1"; /** Resolve API base URL: explicit config → `VOUCH_BASE_URL` (Node) → local dev default. */ declare function resolveBaseUrl(explicit?: string): string; /** * Parse a UPI payment scheme string. * * Supports: * - `upi://pay?pa=merchant@upi&pn=Merchant+Name&am=100.00` * - Raw UPI IDs like `merchant@upi` * * Returns `null` if the input is not recognisable as UPI. */ declare function parseUPIScheme(raw: string): UPIData | null; /** * Extract all UPI query parameters from a raw UPI scheme string. * Useful if you need fields beyond the common ones (e.g. `mc`, `tr`, `tn`). */ declare function parseUPISchemeFull(raw: string): UPIScheme | null; /** * Framework-agnostic UPI QR scanner. * * Works in any browser environment — vanilla JS, React, Vue, Svelte, etc. * Dynamically loads `html5-qrcode` on first use. * * @example * ```ts * const scanner = new UPIScanner({ * container: "#scanner", * onScan: (upi) => console.log(upi.upiId), * onError: (err) => alert(err.message), * }); * await scanner.start(); * // later... * await scanner.stop(); * ``` */ declare class UPIScanner { private options; private scanner; private lastScan; private _started; private containerEl; constructor(options: UPIScannerOptions); private resolveContainer; /** * Start the camera and begin scanning for UPI QR codes. */ start(): Promise; /** * Stop the camera and release resources. */ stop(): Promise; /** Whether the scanner is currently active. */ isStarted(): boolean; private handleScan; } export { type ApiError, type ApiListResponse, type ApiResponse, type AuthorizeEligibleItem, type AuthorizeResponse, type Beneficiary, DEFAULT_DEV_BACKEND_ORIGIN, DEFAULT_DEV_BASE_URL, type IntentAuthorization, type IntentSettlement, type IntentStatusResponse, type Merchant, type PaymentIntent, type Program, type ProgramStats, type UPIData, type UPIIntentResponse, UPIScanner, type UPIScannerOptions, type UPIScheme, Vouch, type VouchConfig, VouchError, type Voucher, type VoucherBalanceStatus, parseUPIScheme, parseUPISchemeFull, resolveBaseUrl };