UNPKG

@splito/sdk

Version:

Official JavaScript/TypeScript SDK for Splito - Split payments across multiple recipients

152 lines (147 loc) 3.9 kB
type PaymentIntentStatus = 'requires_recipients' | 'processing' | 'succeeded' | 'failed'; interface PaymentIntent { id: string; organizationId: string; productId?: string; amount: number; currency: string; status: PaymentIntentStatus; hostedToken: string; hostedUrl: string; metadata?: Record<string, any>; createdAt: string; updatedAt: string; } interface CreatePaymentIntentRequest { amount: number; currency?: string; product_id?: string; max_participants?: number; expires_in_hours?: number; metadata?: Record<string, any>; } interface CreatePaymentIntentResponse { id: string; hosted_url: string; splitting_token: string; } interface CreateSubscriptionRequest { amount: number; currency: string; interval: 'week' | 'month' | 'year'; metadata?: Record<string, any>; } interface CreateSubscriptionResponse { id: string; hosted_url: string; } declare function openSplitModal(token: string, baseUrl?: string): void; interface SplitoConfig { apiKey: string; timeout?: number; } declare class Splito { private baseUrl; private apiKey; private timeout; constructor(config: SplitoConfig); private makeRequest; /** * Create a new payment intent */ createPaymentIntent(data: CreatePaymentIntentRequest): Promise<CreatePaymentIntentResponse>; /** * Create a new subscription */ createSubscription(data: CreateSubscriptionRequest): Promise<CreateSubscriptionResponse>; /** * Get a payment intent by ID */ getPaymentIntent(id: string): Promise<PaymentIntent>; /** * Send a test webhook event */ sendTestWebhook(webhookUrl: string, webhookSecret?: string): Promise<{ success: boolean; message: string; status?: number; error?: string; }>; /** * Get events with optional filtering */ getEvents(params?: { type?: string; limit?: number; }): Promise<unknown>; /** * Create a new product and open split modal */ createProductWithModal(data: { name: string; description?: string; price: number; currency?: string; metadata?: any; external_product_id?: string; }, callbacks?: { onLoading?: () => void; onError?: (error: Error) => void; onSuccess?: (product: any, token: string) => void; }): Promise<{ product: any; paymentIntent: CreatePaymentIntentResponse; splitting_token: string; }>; /** * Create a new product */ createProduct(data: { name: string; description?: string; price: number; currency?: string; metadata?: any; external_product_id?: string; }): Promise<unknown>; /** * Get a product by external product ID */ getProductByExternalId(externalProductId: string): Promise<any>; /** * List payment intents with filtering */ listPaymentIntents(params?: { limit?: number; offset?: number; status?: string; product_id?: string; }): Promise<unknown>; /** * List products with filtering */ listProducts(params?: { limit?: number; offset?: number; search?: string; is_active?: boolean; external_product_id?: string; }): Promise<unknown>; /** * List recipients with filtering */ listRecipients(params?: { limit?: number; offset?: number; search?: string; status?: string; }): Promise<unknown>; /** * Get analytics data with date filtering */ getAnalytics(params?: { start_date?: string; end_date?: string; }): Promise<unknown>; } export { Splito, type SplitoConfig, Splito as default, openSplitModal };