import { IContractV2List, IContractV2Response } from '../../types/contract.types'; import { ICustomer, ICustomerPaymentMethodsList } from '../../types/customer.types'; import { IInvoicesList } from '../../types/invoice.types'; import { IPaymentsList } from '../../types/payments.types'; import { ServiceParams } from '../../types/types'; export declare const DEFAULT_PAGINATION_LIMIT = 5; type Customer = ICustomer; type PaymentMethodsList = ICustomerPaymentMethodsList; type InvoicesList = IInvoicesList; type PaymentsList = IPaymentsList; type ContractList = IContractV2List; type Contract = IContractV2Response; /** * Customer service hook providing static methods for customer-related operations. * * These methods return raw data without React Query caching or loading states, * allowing clients to manage state using their preferred approach (useState, Zustand, React Query, etc.). * * @returns Object containing customer service methods: * - details: Fetches customer billing information and details. * - paymentMethods: Fetches all payment methods associated with the customer from the payment provider. * - invoices: Fetches paginated invoices for the customer with statuses PAID, APPROVED, or PARTIALLY_PAID. * - payments: Fetches paginated payment history for the customer, including various payment statuses. * - contracts: Fetches paginated contracts for the customer. * - contractById: Fetches a single contract by ID for the customer. * - transactions: (Deprecated) Alias for payments(), will be removed in v1.0.0. * * @example * ```typescript * const customerService = useCustomerService() * * // Get customer details * const { data: customer } = await customerService.details() * * // Get payment methods * const { data: paymentMethods } = await customerService.paymentMethods() * * // Get invoices * const { data: invoices } = await customerService.invoices({ limit: 10 }) * * // Get payments * const { data: payments } = await customerService.payments({ limit: 10 }) * ``` */ export declare const useCustomerService: () => { /** * Get customer billing information and details. * * Fetches the latest customer data from the API to ensure data consistency. * * @returns Promise resolving to an object with customer data. * * @example * ```typescript * try { * const { data: customer } = await customerService.details() * console.log('Customer email:', customer.email) * } catch (error) { * console.error('Failed to get customer details:', error.message) * } * ``` */ details: () => Promise<{ data: Customer; }>; /** * Update customer details. * * Updates the customer details. * * @param payload - The payload to update the customer details. * @returns Promise resolving to an object with the updated customer details. * * @example * ```typescript * try { * const { data: customer } = await customerService.updateCustomerDetails({ * email: 'newemail@example.com', * }) * console.log('Customer updated:', customer) * } catch (error) { * console.error('Failed to update customer details:', error.message) * } * ``` */ updateCustomerDetails: (payload: Customer) => Promise<{ data: Customer; }>; /** * Add a new customer. * * Adds a new customer. * * @param payload - The payload to add the customer. * @returns Promise resolving to an object with the added customer details. * * @example * ```typescript * try { * const { data: customer } = await customerService.addCustomer({ * email: 'newemail@example.com', * }) * console.log('Customer added:', customer) * } catch (error) { * console.error('Failed to add customer:', error.message) * } * ``` */ addCustomer: (payload: Customer) => Promise<{ data: Customer; }>; /** * Get customer payment methods from the payment provider. * * Fetches all payment methods associated with the customer * from the configured payment provider (e.g., Stripe). * * @returns Promise resolving to an object with an array of payment methods. * * @example * ```typescript * try { * const { data: paymentMethods } = await customerService.paymentMethods() * paymentMethods.forEach(method => { * console.log(`${method.type} ending in ${method.last4}`) * }) * } catch (error) { * console.error('Failed to fetch payment methods:', error.message) * } * ``` */ paymentMethods: () => Promise<{ data: PaymentMethodsList; }>; /** * Set the default payment method for the customer. * * Sets the default payment method for the customer. * * @param paymentMethodId - The ID of the payment method to set as default. * @returns Promise resolving to an object with a message. * * @example * ```typescript * try { * const { data: message } = await customerService.setDefaultPaymentMethod('pm_1234567890') * console.log('Default payment method set:', message) * } catch (error) { * console.error('Failed to set default payment method:', error.message) * } * ``` */ setDefaultPaymentMethod: (paymentMethodId: string) => Promise<{ data: { message: string; }; }>; /** * Get customer invoices with pagination. * * Fetches invoices for the customer with specific statuses * (PAID, APPROVED, PARTIALLY_PAID) and pagination support. * Supports cursor-based pagination and sorting. * * @param params - Pagination and sorting parameters. * @returns Promise resolving to an object with paginated invoice results. * * @example * ```typescript * try { * const { data: invoiceData } = await customerService.invoices({ limit: 10, cursor: 'cursor_string' }) * console.log(`Found ${invoiceData.results.length} invoices`) * invoiceData.results.forEach(invoice => { * console.log(`Invoice ${invoice.invoice_number}: $${invoice.total_amount}`) * }) * } catch (error) { * console.error('Failed to fetch invoices:', error.message) * } * ``` */ invoices: (params?: ServiceParams) => Promise<{ data: InvoicesList; }>; /** * Get customer payment history with pagination. * * Fetches payment history for the customer including various payment statuses * (in_progress, authorized, success, failed, refunded, partially_refunded). * Supports cursor-based pagination and sorting. * * @param params - Pagination and sorting parameters. * @returns Promise resolving to an object with paginated payment results. * * @example * ```typescript * try { * const { data: paymentData } = await customerService.payments({ limit: 10, cursor: 'cursor_string' }) * console.log(`Found ${paymentData.results.length} payments`) * paymentData.results.forEach(payment => { * console.log(`Payment ${payment.id}: $${payment.amount} - ${payment.status}`) * }) * } catch (error) { * console.error('Failed to fetch payments:', error.message) * } * ``` */ payments: (params?: ServiceParams) => Promise<{ data: PaymentsList; }>; /** * Get customer contracts with pagination. * * Fetches all contracts belonging to the customer with optional pagination and sorting. * Uses cursor-based pagination for efficient data retrieval. * * @param params - Pagination and sorting parameters. * @returns Promise resolving to an object with paginated contract results. * * @example * ```typescript * try { * const { data: contractData } = await customerService.contracts({ limit: 10, cursor: 'cursor_string' }) * console.log(`Found ${contractData.total_count} contracts`) * contractData.results.forEach(contract => { * console.log(`Contract ${contract.name}: ${contract.status}`) * }) * } catch (error) { * console.error('Failed to fetch contracts:', error.message) * } * ``` */ contracts: (params?: ServiceParams) => Promise<{ data: ContractList; }>; /** * Get a single contract by ID for the customer. * * Fetches detailed information for a specific contract. The contract must belong * to the authenticated customer, otherwise returns 404. * * @param contractId - The UUID of the contract to retrieve. * @returns Promise resolving to an object with contract data. * * @example * ```typescript * try { * const { data: contract } = await customerService.contractById('contract-uuid-123') * console.log('Contract name:', contract.name) * console.log('Contract status:', contract.status) * console.log('Customer:', contract.customer.customer_name) * } catch (error) { * console.error('Failed to get contract:', error.message) * } * ``` */ contractById: (contractId: string) => Promise<{ data: Contract; }>; /** * @deprecated Use `payments()` instead. This method will be removed in v1.0.0. * * Get customer payment history with pagination. * This is a deprecated alias for the `payments()` method. * * @param params - Pagination and sorting parameters. * @returns Promise resolving to an object with paginated payment results. * * @example Migration * ```typescript * // Old * const { data } = await customerService.transactions() * * // New * const { data } = await customerService.payments() * ``` */ transactions: (params?: ServiceParams) => Promise<{ data: PaymentsList; }>; }; /** * Type definitions for customer service methods. * These can be used by clients for better type safety and IDE support. */ export type CustomerServiceMethods = ReturnType; export {};