UNPKG

ws402

Version:

WebSocket implementation of X402 protocol for pay-as-you-go digital resources with automatic refunds

81 lines (80 loc) 2.24 kB
import { PaymentProvider, PaymentVerification } from '../types'; export interface ProxyPaymentProviderConfig { /** Payment gateway server URL */ gatewayUrl: string; /** API key for authentication with gateway */ apiKey: string; /** Request timeout in milliseconds */ timeout?: number; /** Retry failed requests */ retryAttempts?: number; /** Custom headers to send with requests */ customHeaders?: Record<string, string>; } /** * Proxy Payment Provider for WS402 * * Delegates all payment operations to a centralized gateway server. * The gateway handles: * - Payment verification on blockchain * - Refund processing (has private keys) * - Centralized logging and auditing * * Benefits: * - No private keys on WS402 servers * - Multiple WS402 servers can share one gateway * - Centralized payment logic and security * - Easier compliance and auditing */ export declare class ProxyPaymentProvider implements PaymentProvider { private config; constructor(config: ProxyPaymentProviderConfig); /** * Generate payment details by requesting from gateway */ generatePaymentDetails(amount: number): any; /** * Request payment details from gateway (async version for HTTP endpoints) */ requestPaymentDetails(amount: number, resourceId: string, estimatedDuration: number): Promise<any>; /** * Verify payment by delegating to gateway */ verifyPayment(proof: any): Promise<PaymentVerification>; /** * Issue refund by delegating to gateway */ issueRefund(proof: any, amount: number): Promise<void>; /** * Make HTTP request to gateway with retry logic */ private makeRequest; /** * Check if error is retryable */ private isRetryableError; /** * Delay helper for retry logic */ private delay; /** * Validate amount is positive */ private validateAmount; /** * Log activity */ private log; /** * Get gateway info */ getGatewayInfo(): { gatewayUrl: string; timeout: number; retryAttempts: number; }; /** * Health check - ping gateway */ healthCheck(): Promise<boolean>; }