UNPKG

shora-ai-payment-sdk

Version:

The first open-source payment SDK designed specifically for AI agents and chatbots - ACP Compatible

294 lines 10.1 kB
import { PaymentService, PaymentRequest, PaymentResponse, ACPCheckoutRequest, ACPCheckoutResponse } from './payments'; import { MandateRequest, MandateResponse, TokenRequest, TokenResponse, AgentPaymentRequest, AgentPaymentResponse } from './auth'; import { ShoraAP2Adapter, AP2PaymentIntent, AP2PaymentResult, AP2AgentCapabilities } from './shora_ap2_adapter'; import { ShoraA2AAdapter, A2APaymentResponse, A2ASignatureData } from './shora_a2a_x402'; import { ShoraZen7Coordinator, AgentIntent, MultiAgentPayment } from './shora_zen7_coordinator'; import { ShoraCoralServer, CoralThread, CoralMessage, CoralFeed, CoralPaymentContext } from './shora_coral_server'; import { SecurityEnhancement, EncryptedToken, AuditLogEntry } from './security_enhance'; export interface ShoraConfig { apiKey: string; baseUrl?: string; environment?: 'sandbox' | 'production'; timeout?: number; tenantId?: string; tapTrustEnabled?: boolean; gaslessEnabled?: boolean; pspFallbackEnabled?: boolean; acpBridgeEnabled?: boolean; feedEnabled?: boolean; encryptionKey?: string; enableAuditLogging?: boolean; auditLogEndpoint?: string; } export { PaymentRequest, PaymentResponse, ACPCheckoutRequest, ACPCheckoutResponse } from './payments'; export { MandateRequest, MandateResponse, TokenRequest, TokenResponse, AgentPaymentRequest, AgentPaymentResponse } from './auth'; export { AP2PaymentIntent, AP2PaymentResult, AP2AgentCapabilities } from './shora_ap2_adapter'; export { A2APaymentRequest, A2APaymentResponse, A2ASignatureData } from './shora_a2a_x402'; export { AgentIntent, NegotiationResult, MultiAgentPayment } from './shora_zen7_coordinator'; export { CoralThread, CoralMessage, CoralFeed, CoralPaymentContext } from './shora_coral_server'; export { EncryptedToken, AuditLogEntry, createSecurityEnhancement, generateEncryptionKey } from './security_enhance'; declare class ShoraSDK { private client; private config; payments: PaymentService; agents: { createMandate: (request: MandateRequest) => Promise<MandateResponse>; generateToken: (request: TokenRequest) => Promise<TokenResponse>; pay: (request: AgentPaymentRequest) => Promise<AgentPaymentResponse>; }; ap2: ShoraAP2Adapter; a2a: ShoraA2AAdapter; zen7: ShoraZen7Coordinator; coral: ShoraCoralServer; security: SecurityEnhancement; constructor(config: ShoraConfig); /** * Perform a health check on the API. */ healthCheck(): Promise<{ status: string; }>; /** * Create an ACP-compatible checkout session */ createACPCheckout(request: ACPCheckoutRequest): Promise<ACPCheckoutResponse>; /** * Create a payment session for regular payments * Enhanced with automatic retry logic (3 attempts with exponential backoff) * * @example * ```typescript * const payment = await sdk.createPaymentSession({ * amount: 100, * currency: 'TRY', * description: 'Test payment', * customer: { email: 'test@example.com' } * }); * ``` */ createPaymentSession(request: PaymentRequest): Promise<PaymentResponse>; /** * Process a payment using a payment session * Enhanced with automatic retry logic (3 attempts with exponential backoff) * * @example * ```typescript * const result = await sdk.processPayment('session_123', 'card', 'tok_123'); * ``` */ processPayment(sessionId: string, paymentMethod: string, cardToken?: string): Promise<PaymentResponse>; /** * Pay with AP2 (Agentic Commerce Protocol v2) * Modern agent-to-agent payment with TAP trust */ payWithAP2(intent: Omit<AP2PaymentIntent, 'id' | 'createdAt'>, paymentMethod: string, additionalData?: Record<string, any>): Promise<AP2PaymentResult>; /** * Pay with A2A (Account-to-Account) gasless EIP-712 * Gasless blockchain payments with PSP fallback */ payWithA2A(from: string, to: string, amount: string, currency: string, signature: string, nonce: string, deadline: number, metadata?: Record<string, any>): Promise<A2APaymentResponse>; /** * Multi-agent payment negotiation with Zen7 * Intelligent agent coordination for complex payments */ payWithMultiAgent(intents: AgentIntent[], totalAmount: number, currency: string): Promise<MultiAgentPayment>; /** * Create payment communication thread with Coral * Real-time messaging for payment visibility */ createPaymentThread(participants: string[], paymentContext?: CoralPaymentContext): Promise<CoralThread>; /** * Send payment message to thread */ sendPaymentMessage(threadId: string, senderId: string, content: string, type?: CoralMessage['type'], metadata?: Record<string, any>): Promise<CoralMessage>; /** * Get agent capabilities for AP2 */ getAgentCapabilities(agentId: string): Promise<AP2AgentCapabilities>; /** * Create EIP-712 signature data for A2A */ createA2ASignatureData(from: string, to: string, amount: string, currency: string, nonce: string, deadline: number): A2ASignatureData; /** * Get available agents for multi-agent coordination */ getAvailableAgents(capabilities?: string[]): Promise<{ agents: Array<{ agentId: string; capabilities: string[]; status: string; load: number; rating: number; }>; totalCount: number; }>; /** * Create payment feed for visibility */ createPaymentFeed(name: string, description?: string, visibility?: CoralFeed['visibility']): Promise<CoralFeed>; /** * Get comprehensive payment analytics */ getPaymentAnalytics(timeRange?: { start: string; end: string; }): Promise<{ ap2: { totalPayments: number; successRate: number; averageAmount: number; }; a2a: { gaslessPayments: number; pspFallbacks: number; gasSaved: string; }; zen7: { negotiations: number; successRate: number; averageAgents: number; }; coral: { activeThreads: number; messagesSent: number; engagementScore: number; }; }>; /** * Handle MCP thread message (store then fetch status) */ messageHandler(threadId: string, message: { senderId: string; content: string; type?: 'text' | 'payment' | 'system' | 'error'; metadata?: Record<string, any>; }): Promise<{ stored: boolean; status: any; }>; /** * Create gasless EIP-712 signature (server-assisted) and store it */ gaslessSign(intent: { from: string; to: string; amount: string; currency: string; nonce: string; deadline: number; }, token: string): Promise<{ signature: string; recordId: string; }>; /** * Agent flow payment (AP2/ACP) via unified pay endpoint */ agentPay(intent: { amount: number; currency: string; description?: string; metadata?: Record<string, any>; }, agentId: string): Promise<{ transactionId: string; status: string; }>; /** * Crypto payment (x402) with PSP fallback when on-chain not available */ cryptoPay(network: string, amount: { value: string; currency: string; }, options?: { to?: string; pspFallback?: boolean; }): Promise<{ status: string; txHash?: string; fallback?: { psp: string; transactionId: string; }; }>; /** * Get thread messages (MCP) */ getThreadMessages(threadId: string, limit?: number, offset?: number): Promise<{ messages: Array<{ messageId: string; content: string; }>; totalCount: number; }>; /** * Fetch service status (for coordination health) */ fetchStatus(): Promise<any>; /** * Store a precomputed signature record */ storeSignature(payload: { intent: any; signature: string; address?: string; }): Promise<{ id: string; }>; /** * Validate EIP-712 signature */ validateSignature(signature: string, message: Record<string, any>, address: string): Promise<{ valid: boolean; recoveredAddress?: string; }>; /** * Encrypt sensitive token with AES-256 * Production-tested for enterprise security */ encryptToken(token: string, additionalData?: string): EncryptedToken; /** * Decrypt token with tenant validation * Ensures multi-tenant security isolation */ decryptToken(encryptedToken: EncryptedToken): string | null; /** * Generate secure payment token * Combines encryption with audit logging */ generateSecurePaymentToken(paymentData: { amount: number; currency: string; userId: string; agentId?: string; }): EncryptedToken; /** * Validate payment token with audit trail */ validatePaymentToken(encryptedToken: EncryptedToken): { valid: boolean; data?: any; error?: string; }; /** * Get audit logs for tenant * Filtered by tenant ID for security */ getAuditLogs(startDate?: string, endDate?: string, action?: string): AuditLogEntry[]; /** * WooCommerce ACP integration * Real-world e-commerce payment processing */ payWithACP(wooData: { woo_product_id: number; amount: number; currency: string; customer_email: string; order_id?: string; }): Promise<{ paymentId: string; status: string; wooOrderId: string; acpCheckoutUrl?: string; }>; } export default ShoraSDK; //# sourceMappingURL=index.d.ts.map