UNPKG

nowpayments-api

Version:

NOWPayments API client for Node.js with WebSocket support

246 lines (245 loc) 9.01 kB
export = NowPaymentsAPI; /** * NOWPayments API Client for cryptocurrency payment processing * @see {@link https://documenter.getpostman.com/view/7907941/2s93JusNJt API Documentation} * * @class NowPaymentsAPI * @typedef {import('../types').APIConfig} APIConfig * @typedef {import('../types').PaymentStatus} PaymentStatus * @typedef {import('../types').Currency} Currency * @typedef {import('../types').EstimatePrice} EstimatePrice * @typedef {import('../types').Invoice} Invoice * @typedef {import('../types').Payout} Payout * @typedef {import('../types').CreatePaymentParams} CreatePaymentParams * @typedef {import('../types').CreateInvoiceParams} CreateInvoiceParams * @typedef {import('../types').CreatePayoutParams} CreatePayoutParams * @typedef {import('../types').GetPaymentsParams} GetPaymentsParams * @typedef {import('../types').PaginationResponse} PaginationResponse * @typedef {import('../types').MinimumPaymentAmount} MinimumPaymentAmount * @typedef {import('../types/advanced').PaymentStatusExtended} PaymentStatusExtended * @typedef {import('../types/advanced').BatchPayoutParams} BatchPayoutParams * @typedef {import('../types/advanced').PaymentFlow} PaymentFlow */ declare class NowPaymentsAPI { /** * Creates a new NOWPayments API client instance * @param {APIConfig} config - API configuration options * @throws {ValidationError} When API key is missing */ constructor(config: APIConfig); apiKey: any; ipnSecret: any; baseURL: string; rateLimiter: RateLimiter; client: any; /** * Setup axios interceptors for request/response handling * @private */ private _setupInterceptors; /** * Log API request details * @private * @param {Object} config - Request configuration * @param {number} duration - Request duration in ms */ private _logRequest; /** * Makes an API request with rate limiting * @private * @param {Object} config - Axios request configuration * @returns {Promise<any>} API response data * @throws {APIError} When request fails */ private _makeRequest; /** * Retries failed requests with exponential backoff * @private * @param {Object} config - Request configuration * @param {number} [retries=3] - Maximum retry attempts * @returns {Promise<any>} API response data */ private _retryRequest; /** * Get API status * @returns {Promise<{message: string}>} API status response * @throws {APIError} When API request fails */ getStatus(): Promise<{ message: string; }>; /** * Get list of available cryptocurrencies * @returns {Promise<Currency[]>} List of available currencies * @throws {APIError} When API request fails */ getCurrencies(): Promise<Currency[]>; /** * Get estimated price for currency conversion * @param {Object} params - Estimation parameters * @param {number} params.amount - Amount to convert * @param {string} params.currency_from - Source currency code * @param {string} params.currency_to - Target currency code * @returns {Promise<EstimatePrice>} Price estimation * @throws {APIError} When API request fails */ getEstimatePrice(params: { amount: number; currency_from: string; currency_to: string; }): Promise<EstimatePrice>; /** * Create new cryptocurrency payment * @param {CreatePaymentParams} payment - Payment creation parameters * @returns {Promise<PaymentStatus>} Created payment details * @throws {ValidationError} When parameters are invalid * @throws {APIError} When API request fails */ createPayment(payment: CreatePaymentParams): Promise<PaymentStatus>; /** * Get payment status by ID * @param {string} paymentId - Payment identifier * @returns {Promise<PaymentStatus>} Payment status details * @throws {APIError} When payment not found or API error */ getPaymentStatus(paymentId: string): Promise<PaymentStatus>; /** * Get minimum payment amount for currency * @param {string} currency - Currency code * @returns {Promise<MinimumPaymentAmount>} Minimum amount info * @throws {APIError} When API request fails */ getMinimumPaymentAmount(currency: string): Promise<MinimumPaymentAmount>; /** * Create payment invoice * @param {CreateInvoiceParams} invoice - Invoice creation parameters * @returns {Promise<Invoice>} Created invoice details * @throws {ValidationError} When parameters are invalid * @throws {APIError} When API request fails */ createInvoice(invoice: CreateInvoiceParams): Promise<Invoice>; /** * Get payments list with pagination * @param {GetPaymentsParams} [params] - Query parameters * @returns {Promise<PaginationResponse<PaymentStatus>>} Paginated payments list * @throws {APIError} When API request fails */ getPayments(params?: GetPaymentsParams): Promise<PaginationResponse<PaymentStatus>>; /** * Create cryptocurrency payout * @param {CreatePayoutParams} payout - Payout creation parameters * @returns {Promise<Payout>} Created payout details * @throws {ValidationError} When parameters are invalid * @throws {APIError} When API request fails */ createPayout(payout: CreatePayoutParams): Promise<Payout>; /** * Create batch cryptocurrency payout * @param {BatchPayoutParams} params - Batch payout parameters * @returns {Promise<Payout[]>} Created payouts details * @throws {ValidationError} When parameters are invalid * @throws {APIError} When API request fails */ createBatchPayout(params: BatchPayoutParams): Promise<Payout[]>; /** * Get detailed payment flow * @param {string} paymentId - Payment identifier * @returns {Promise<PaymentFlow>} Payment flow details * @throws {APIError} When payment not found or API error */ getPaymentFlow(paymentId: string): Promise<PaymentFlow>; /** * Verify IPN callback signature * @param {Object} ipnData - IPN payload * @param {string} signature - X-NOWPayments-Sig header * @returns {boolean} Signature validity * @throws {Error} When IPN secret not configured */ verifyIPN(ipnData: Object, signature: string): boolean; /** * Sleep utility for retry delay * @private * @param {number} ms - Milliseconds to sleep * @returns {Promise<void>} */ private _sleep; /** * Checks if error is retryable * @private * @param {Error} error - Error to check * @returns {boolean} Whether error is retryable */ private _isRetryable; /** * Validates request data against schema * @private * @param {Object} data - Data to validate * @param {Object} schema - Validation schema * @throws {ValidationError} When validation fails */ private _validateSchema; } declare namespace NowPaymentsAPI { export { APIConfig, PaymentStatus, Currency, EstimatePrice, Invoice, Payout, CreatePaymentParams, CreateInvoiceParams, CreatePayoutParams, GetPaymentsParams, PaginationResponse, MinimumPaymentAmount, PaymentStatusExtended, BatchPayoutParams, PaymentFlow }; } import { RateLimiter } from "limiter/dist/cjs/RateLimiter"; /** * NOWPayments API Client for cryptocurrency payment processing */ type APIConfig = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type PaymentStatus = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type Currency = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type EstimatePrice = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type Invoice = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type Payout = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type CreatePaymentParams = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type CreateInvoiceParams = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type CreatePayoutParams = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type GetPaymentsParams = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type PaginationResponse = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type MinimumPaymentAmount = any; /** * NOWPayments API Client for cryptocurrency payment processing */ type PaymentStatusExtended = import("../types/advanced").PaymentStatusExtended; /** * NOWPayments API Client for cryptocurrency payment processing */ type BatchPayoutParams = import("../types/advanced").BatchPayoutParams; /** * NOWPayments API Client for cryptocurrency payment processing */ type PaymentFlow = import("../types/advanced").PaymentFlow;