import type { ClaimFeesRequest, ClaimFeesResponse, CreatePayOrderMode, CreateWebhookRequest, GetFeeBalancesResponse, OrderStatusSocket, PaymentDetails, PaymentDetailsParams, PaymentMethodsResponse, PayOrderParams, PayOrderQuoteParams, RouteQuote, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, SwapQuoteResponse, UpdateWebhookRequest, WebhookResponse } from "../types/api"; import type { PayOrder } from "../types/model"; import { type APIEnvironment } from "./config"; import { type APIResponse } from "./fetcher"; type Opts = { headers?: Record; }; export declare class ApiClient { private readonly apiKey; private readonly environment; private readonly sessionId?; private readonly version?; constructor({ apiKey, sessionId, environment, version, }: { apiKey: string; sessionId?: string; environment?: APIEnvironment; version?: string; }); private request; private withAuthorizationSignature; private getErrorMessage; private createBadRequestResponse; private validatePayOrderParams; /** * Fetches a PayOrder by its ID. * * Retrieves a PayOrder object from the API using the provided payOrderId. * This function requires an API key for authentication. * * @param {string} payOrderId - The unique identifier of the PayOrder. * @returns {Promise>} - The PayOrder object wrapped in an API response if the request is successful. * * @example * const { data: payOrder, error } = await getPayOrder('123456'); */ getPayOrder(payOrderId: string): Promise>; /** * Fetches payment method availability for a PayOrder. * * Retrieves the currently available payment methods for the provided PayOrder ID, * including optional availability reasons and minimum fiat amounts. * * @param {string} payOrderId - The unique identifier of the PayOrder. * @param {Opts} [opts] - Optional parameters for the request, such as additional headers. * @returns {Promise>} - Payment method availability wrapped in an API response. */ getPayOrderPaymentMethods(payOrderId: string, opts?: Opts): Promise>; /** * Creates a `DEPOSIT` PayOrder. * * Creates a PayOrder of type `DEPOSIT` with the provided parameters. * * @param {PayOrderParams} params - Parameters required to create a deposit PayOrder. * @param {Opts} [opts] - Optional parameters for the request, such as additional headers. * @returns {Promise>} - The PayOrder object wrapped in an API response if the request is successful. * * @example * const depositOrderParams = { * intent: { * asset: { chain_id: 1, address: null }, * amount: { token_amount: 100 }, * receiving_address: '0x1234...abcd' * }, * metadata: { description: 'Deposit for account' } * }; * const { data, error } = await createDepositPayOrder(depositOrderParams); * if (data) { * console.log('Deposit PayOrder created:', data); * } */ createDepositPayOrder(params: PayOrderParams, opts?: Opts): Promise>; /** * Creates a `SALE` PayOrder. * * Creates a PayOrder with mode `SALE` with the provided params. * * Requires a valid HMAC-SHA256 signature generated by `generateAuthorizationSignature`. * * @param {SalePayOrderParams} params - Params required to create a sale PayOrder. * @param {string} apiSecret - API secret used to generate the authorization signature. * @param {Opts} [opts] - Optional parameters for the request. * @returns {Promise>} - A PayOrder object wrapped in an API response if the request was successful. * * @example * const apiSecret = 'yourApiSecret'; * const response = await createSalePayOrder({ * intent: { * asset: { chain_id: 1, address: null }, * amount: { * fiat: { * amount: 200, * unit: "USD" * }, * }, * metadata: { * items: [ * { * name: "t-shirt", * description: "a nice t-shirt", * image: "https://example.com/tshirt.jpg", * quantity: 1, * unit_price: 200, * currency: "USD" * } * ] * } * }, apiSecret); * if (response.data) { * console.log('Sale PayOrder created:', response.data); * } */ createSalePayOrder(params: PayOrderParams, apiSecret: string, opts?: Opts): Promise>; /** * Creates a `REFUND` PayOrder. * * Creates a PayOrder with mode `REFUND` with the provided params. * * Requires a valid HMAC-SHA256 signature generated by `generateAuthorizationSignature`. * * @param {string} payOrderId - The unique identifier of the PayOrder to be refunded. * @param {PayOrderParams} params - Params required to create a refund PayOrder. * @param {string} apiSecret - API secret used to generate the authorization signature. * @param {Opts} [opts] - Optional parameters for the request. * @returns {Promise>} - A PayOrder object wrapped in an API response if the request was successful. * * @example * const apiSecret = 'yourApiSecret'; * const response = await createRefundPayOrder(refundOrderId, { * intent: { * asset: { chain_id: 1, address: null }, * receiving_address: '0x5678...efgh', * amount: { * fiat: { * value: 100, * unit: "USD" * } * } * }, * metadata: { * items: [ * { * name: "refund", * description: "Refund for t-shirt purchase", * unit_price: 100, * currency: "USD" * } * ] * } * }, apiSecret); * if (response.data) { * console.log('Refund PayOrder created:', response.data); * } */ createRefundPayOrder(payOrderId: string, params: PayOrderParams, apiSecret: string, opts?: Opts): Promise>; createPayOrder(params: PayOrderParams, mode: CreatePayOrderMode, signature?: string, opts?: Opts): Promise>; /** * Generates a PayOrder Quote. * * Creates a PayOrder Quote for an existing PayOrder by providing wallet information and chain details. * This function requires an API key for authentication. * * @param {string} orderId - The unique identifier of the PayOrder for which the quote is requested. * @param {PayOrderQuoteParams} quoteParams - Contains `wallet_address`, `chain_type`, and optional `chain_ids`. * @param {Opts} [opts] - Optional parameters for the request. * @returns {Promise>} - An array of PayTokens wrapped in an API response if the request was successful. * * @example * const orderId = 'existingOrderId'; * const quoteParams = { * wallet_address: '0x1234...abcd', * chain_type: ChainType.EVM, * chain_ids: [1, 10, 137] * }; * * const response = await payOrderQuote(orderId, quoteParams); * if (response.data) { * console.log('Available tokens:', response.data); * } */ payOrderQuote(orderId: string, quoteParams: PayOrderQuoteParams, opts?: Opts): Promise>; /** * Retrieves payment details for a specific PayOrder. * * This function fetches payment details associated with a specific PayOrder ID. * It allows specifying the token and blockchain network (via `token_address` and `chain_id`) * to retrieve source currency information, as well as a refund address for the transaction. * Alternative you can provide a `quote_id` to retrieve the payment details for a specific quote associated with the PayOrder. * * The request is authenticated using the provided API key in the headers. * * @param {PaymentDetailsParams} params - Parameters to retrieve the payment details. * @param {string} params.payorder_id - The unique identifier of the PayOrder for which payment details are fetched. * @param {PaymentRail} [params.payment_rail] - (Optional) The payment rail for which to fetch the payment details. default: CRYPTO. * @param {CurrencyBase} [params.source_currency] - (Optional) The source currency information. * @param {string} [params.quote_id] - (Optional) The quote ID for the PayOrder. * @param {string} [params.refund_address] - (Optional) The address where funds will be refunded in case of a failed transaction. * @param {Opts} [opts] - Optional parameters for the request, such as additional headers. * * @returns {Promise>} - The payment details object wrapped in an API response if the request is successful. * * @example * const response = await payOrderPaymentDetails({ * payorder_id: '12345', * source_currency: { chain_id: 1, address: '0x1234567890abcdef1234567890abcdef12345678' }, * refund_address: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd', * }); * * if (response.data) { * console.log('Payment details:', response.data); * } */ payOrderPaymentDetails(params: PaymentDetailsParams, opts?: Opts): Promise>; /** * Retrieves the claimable fee balances for the authenticated organization. * * @param {string} apiSecret - API secret used to generate the authorization signature. * @param {Opts} [opts] - Optional parameters for the request, such as additional headers. * @returns {Promise>} - Fee balances wrapped in an API response. */ getFeeBalances(apiSecret: string, opts?: Opts): Promise>; /** * Claims accrued fees for the authenticated organization. * * @param {ClaimFeesRequest} params - Parameters for claiming fees. * @param {string} apiSecret - API secret used to generate the authorization signature. * @param {Opts} [opts] - Options for the request, such as additional headers. * @returns {Promise>} - Claim result wrapped in an API response. */ claimFees(params: ClaimFeesRequest, apiSecret: string, opts?: Opts): Promise>; /** * Retrieves all webhooks for the authenticated organization. * * @param {string} apiSecret - API secret used to generate the authorization signature. * @param {Opts} [opts] - Options for the request, such as additional headers. * @returns {Promise>} - List of webhooks wrapped in an API response. */ listWebhooks(apiSecret: string, opts?: Opts): Promise>; /** * Creates a new webhook for the authenticated organization. * * @param {CreateWebhookRequest} params - Parameters for creating the webhook. * @param {string} apiSecret - API secret used to generate the authorization signature. * @param {Opts} [opts] - Optional parameters for the request, such as additional headers. * @returns {Promise>} - Created webhook wrapped in an API response. */ createWebhook(params: CreateWebhookRequest, apiSecret: string, opts?: Opts): Promise>; /** * Updates an existing webhook for the authenticated organization. * * @param {string} webhookId - The unique identifier of the webhook to update. * @param {UpdateWebhookRequest} params - Parameters for updating the webhook. * @param {string} apiSecret - API secret used to generate the authorization signature. * @param {Opts} [opts] - Optional parameters for the request, such as additional headers. * @returns {Promise>} - Updated webhook wrapped in an API response. */ updateWebhook(webhookId: string, params: UpdateWebhookRequest, apiSecret: string, opts?: Opts): Promise>; /** * Deletes an existing webhook for the authenticated organization. * * @param {string} webhookId - The unique identifier of the webhook to delete. * @param {string} apiSecret - API secret used to generate the authorization signature. * @param {Opts} [opts] - Optional parameters for the request, such as additional headers. * @returns {Promise>} - Empty response on success. */ deleteWebhook(webhookId: string, apiSecret: string, opts?: Opts): Promise>; /** * Gets a quote for swapping between two currencies. * * @param {SwapQuoteRequest} params - Parameters for the swap quote. * @param {Opts} [opts] - Optional parameters for the request, such as additional headers. * @returns {Promise>} - Swap quote wrapped in an API response. */ swapQuote(params: SwapQuoteRequest, opts?: Opts): Promise>; /** * Gets transaction data for executing a swap. * * @param {SwapDataRequest} params - Parameters for the swap data. * @param {Opts} [opts] - Optional parameters for the request, such as additional headers. * @returns {Promise>} - Swap data wrapped in an API response. */ swapData(params: SwapDataRequest, opts?: Opts): Promise>; /** * Opens a WebSocket connection to receive real-time order status events. * * Subscribe to an order's events after the connection is open: * ```ts * const socket = apiClient.subscribeOrderStatus() * socket.onOpen(() => socket.subscribe(orderId)) * socket.onMessage((msg) => { * if (msg.type === 'event') console.log(msg.data) * }) * ``` * * @returns {OrderStatusSocket} - Handle for subscribing, receiving messages, and closing the connection. */ subscribeOrderStatus(): OrderStatusSocket; /** * Generates an authorization signature for API requests using HMAC-SHA256. * * ⚠️ **Warning:** This function should only be run on the server. * It uses the API secret, which must remain confidential. Running this * code in a client-side environment risks exposing sensitive information * to end users or malicious actors. * * This function creates a signed authorization string using HMAC-SHA256. * The signature is computed over: method + path + timestamp, using the secret as the HMAC key. * * @param {string} apiSecret - The API secret used as the HMAC key. * @param {string} method - The HTTP method (e.g., "POST", "GET"). * @param {string} path - The request path (e.g., "/pay-orders"). * @returns {string} - A formatted authorization string in the format: * `APIKey=,signature=,timestamp=`. * * @example * const apiSecret = 'yourApiSecret'; * const authSignature = apiClient.generateAuthorizationSignature(apiSecret, 'POST', '/pay-orders'); * console.log(authSignature); * // Example output: * // APIKey=yourApiKey,signature=a1b2c3d4...,timestamp=1737106896 */ generateAuthorizationSignature(apiSecret: string, method: string, path: string): string; } export {};