node-nowpayments-api
Version:
Node NowPayments API client
253 lines (243 loc) • 7.9 kB
TypeScript
import { AxiosRequestConfig } from 'axios';
interface GetApiStatusResult {
message: string;
}
type GetAvailableCurrenciesParams = {
fixed_rate: boolean;
};
type GetAvailableCheckedCoinsParams = {
fixed_rate: boolean;
};
type GetAvailableCurrencies = GetAvailableCurrenciesNotFixed | GetAvailableCurrenciesFixed;
interface GetAvailableCurrenciesNotFixed {
currencies: string[];
}
interface GetAvailableCurrenciesFixed {
currencies: FixedRateCurrency[];
}
interface FixedRateCurrency {
min_amount: number;
max_amount: number;
currency: string;
}
interface FullCurrency {
id: number;
code: string;
name: string;
enable: boolean;
wallet_regex: string;
priority: number;
extra_id_exists: boolean;
extra_id_regex?: string;
logo_url: string;
track: boolean;
cg_id: string;
is_maxlimit: boolean;
network: string;
smart_contract?: string;
network_precision?: string;
explorer_link_hash?: string;
precision: string;
is_defi: boolean;
is_popular: boolean;
is_stable: boolean;
available_for_to_conversion: boolean;
}
interface GetAvailableFullCurrencies {
currencies: FullCurrency[];
}
interface GetAvailableCheckedCoins {
selectedCurrencies: string[];
}
interface GetEstimatedPriceParams {
amount: number;
currency_from: string;
currency_to: string;
}
interface GetEstimatedPriceResult {
currency_from: string;
amount_from: number;
currency_to: string;
estimated_amount: number;
}
interface CreatePaymentParams {
price_amount: number;
price_currency: string;
pay_amount?: number;
pay_currency: string;
ipn_callback_url?: string;
order_id?: string;
order_description?: string;
purchase_id?: string;
payout_address?: string;
payout_currency?: string;
payout_extra_id?: string;
fixed_rate?: boolean;
is_fee_paid_by_user?: boolean;
}
interface CreatePaymentResult {
payment_id: string;
payment_status: string;
pay_address: string;
price_amount: number;
price_currency: string;
pay_amount: number;
amount_received: number;
pay_currency: string;
order_id: string;
order_description: string;
ipn_callback_url: string;
created_at: string;
updated_at: string;
purchase_id: string;
smart_contract?: any;
network: string;
network_precision?: any;
time_limit?: any;
burning_percent?: any;
expiration_estimate_date: string;
is_fixed_rate: boolean;
is_fee_paid_by_user: boolean;
valid_until: string;
type: string;
}
interface PayoutAuthenticationParams {
email: string;
password: string;
}
interface PayoutAuthenticationResult {
token: string;
}
interface GetBalanceResult {
[currency: string]: {
amount: number;
pendingAmount: number;
};
}
interface GetPayoutStatusParams {
payout_id: string;
}
interface PayoutStatusWithdrawal {
id?: string;
batch_withdrawal_id: string;
status: string;
error?: string;
currency: string;
amount: string;
address: string;
extra_id?: string;
hash: string;
ipn_callback_url?: string;
payout_description?: string;
is_request_payouts?: boolean;
unique_external_id?: string;
created_at?: string;
updated_at: string;
requested_at: string;
}
interface GetPayoutStatusResult {
id: string;
createdAt: string;
withdrawals: PayoutStatusWithdrawal[];
}
interface PayoutWithdrawal {
address: string;
currency: string;
amount: number;
ipn_callback_url?: string;
}
interface CreatePayoutParams {
ipn_callback_url?: string;
withdrawals: PayoutWithdrawal[];
}
interface CreatePayoutWithdrawal {
is_request_payouts: boolean;
id: string;
address: string;
currency: string;
amount: string;
ipn_callback_url: string;
batch_withdrawal_id: string;
status: string;
error?: string;
extra_id?: string;
hash?: string;
payout_description?: string;
unique_external_id?: string;
created_at: string;
requested_at?: string;
updated_at?: string;
}
interface CreatePayoutResult {
id: string;
withdrawals: CreatePayoutWithdrawal[];
}
interface VerifyPayoutParams {
payout_id: string;
verification_code: string;
}
interface WebhookPaymentBody {
payment_id: number;
invoice_id?: number;
payment_status: PaymentStatus;
pay_address: string;
price_amount: number;
price_currency: string;
pay_amount: number;
actually_paid: number;
actually_paid_at_fiat: number;
pay_currency: string;
order_id: string;
order_description: string;
purchase_id: string;
created_at: string;
updated_at: string;
outcome_amount: number;
outcome_currency: string;
}
interface WebhookPayoutBody {
id: string;
batch_withdrawal_id: string;
status: PayoutStatus;
error?: string;
currency: string;
amount: string;
address: string;
extra_id?: string;
hash?: string;
ipn_callback_url: string;
created_at: string;
requested_at?: string;
updated_at?: string;
}
type VerifyWebhookResult = {
isVerified: true;
typedBody: WebhookPaymentBody | WebhookPayoutBody;
} | {
isVerified: false;
error: "NO_SIGNATURE" | "INVALID_SIGNATURE";
};
type Result<T> = {
result?: T;
error?: unknown;
};
type PaymentStatus = "waiting" | "confirming" | "confirmed" | "sending" | "partially_paid" | "finished" | "failed" | "refunded" | "expired";
type PayoutStatus = "CREATING" | "WAITING" | "PROCESSING" | "SENDING" | "FINISHED" | "FAILED" | "REJECTED";
declare class NowPaymentsClient {
private axiosInstance;
private globalRequestOptions;
constructor(apiKey: string, requestOptions?: AxiosRequestConfig);
getApiStatus(): Promise<Result<GetApiStatusResult>>;
getAvailableCurrencies(params: GetAvailableCurrenciesParams): Promise<Result<GetAvailableCurrencies>>;
getAvailableFullCurrencies(): Promise<Result<GetAvailableFullCurrencies>>;
getAvailableCheckedCoins(params: GetAvailableCheckedCoinsParams): Promise<Result<GetAvailableCheckedCoins>>;
getEstimatedPrice(params: GetEstimatedPriceParams): Promise<Result<GetEstimatedPriceResult>>;
createPayment(params: CreatePaymentParams): Promise<Result<CreatePaymentResult>>;
payoutAuthentication(params: PayoutAuthenticationParams): Promise<Result<PayoutAuthenticationResult>>;
getBalance(): Promise<Result<GetBalanceResult>>;
getPayoutStatus(params: GetPayoutStatusParams): Promise<Result<GetPayoutStatusResult>>;
createPayout(params: CreatePayoutParams, authorization: string): Promise<Result<CreatePayoutResult>>;
verifyPayout(params: VerifyPayoutParams, authorization: string): Promise<Result<string>>;
}
declare const verifyWebhook: (rawBody: any, signature: string | string[] | undefined, ipnSecret: string) => VerifyWebhookResult;
export { CreatePaymentParams, CreatePaymentResult, CreatePayoutParams, CreatePayoutResult, CreatePayoutWithdrawal, FixedRateCurrency, FullCurrency, GetApiStatusResult, GetAvailableCheckedCoins, GetAvailableCheckedCoinsParams, GetAvailableCurrencies, GetAvailableCurrenciesFixed, GetAvailableCurrenciesNotFixed, GetAvailableCurrenciesParams, GetAvailableFullCurrencies, GetBalanceResult, GetEstimatedPriceParams, GetEstimatedPriceResult, GetPayoutStatusParams, GetPayoutStatusResult, NowPaymentsClient, PaymentStatus, PayoutAuthenticationParams, PayoutAuthenticationResult, PayoutStatus, PayoutStatusWithdrawal, PayoutWithdrawal, Result, VerifyPayoutParams, VerifyWebhookResult, WebhookPaymentBody, WebhookPayoutBody, verifyWebhook };