npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nowpayments-api

v1.0.1

Published

NOWPayments API client for Node.js with WebSocket support

Downloads

113

Readme

NOWPayments API Client for Node.js

This code generated by Cody AI

Node.js client for the NOWPayments cryptocurrency payment gateway API with WebSocket support for real-time payment updates.

npm version License: MIT

Features

  • 🚀 Complete NOWPayments API integration
  • ⚡ Real-time payment updates via WebSocket
  • 🔒 Strong TypeScript support
  • ✅ Input validation
  • 🔄 Automatic retries with exponential backoff
  • ⚖️ Rate limiting
  • 🏦 Sandbox environment support
  • 📝 Comprehensive documentation

Installation

npm install nowpayments-api

Quick Start

const { createClient, createWebSocketClient } = require("nowpayments-api");

// Initialize API client
const client = createClient({
  apiKey: "YOUR_API_KEY",
  ipnSecret: "YOUR_IPN_SECRET", // Optional
  sandbox: false, // Optional, defaults to false
});

// Create payment
const payment = await client.createPayment({
  price_amount: 100,
  price_currency: "USD",
  pay_currency: "BTC",
});

// Initialize WebSocket client for real-time updates
const ws = createWebSocketClient("YOUR_API_KEY");

ws.on("payment_update", (update) => {
  console.log("Payment update received:", update);
});

ws.connect();

API Methods

Payments

// Create payment
const payment = await client.createPayment({
  price_amount: 100,
  price_currency: "USD",
  pay_currency: "BTC",
});

// Get payment status
const status = await client.getPaymentStatus("payment_id");

// Get payments list
const payments = await client.getPayments({
  limit: 50,
  page: 1,
});

Invoices

// Create invoice
const invoice = await client.createInvoice({
  price_amount: 100,
  price_currency: "USD",
});

Currencies & Estimates

// Get available currencies
const currencies = await client.getCurrencies();

// Get price estimate
const estimate = await client.getEstimatePrice({
  amount: 100,
  currency_from: "USD",
  currency_to: "BTC",
});

Payouts

// Create payout
const payout = await client.createPayout({
  address: "crypto_address",
  amount: 1.5,
  currency: "BTC",
});

WebSocket Events

const ws = createWebSocketClient("YOUR_API_KEY");

ws.on("connected", () => {
  console.log("Connected to WebSocket");
});

ws.on("payment_update", (update) => {
  console.log("Payment update:", update);
});

ws.on("error", (error) => {
  console.error("WebSocket error:", error);
});

ws.on("disconnected", (reason) => {
  console.log("Disconnected:", reason);
});

Error Handling

const { errors } = require('nowpayments-api');

try {
  await client.createPayment({...});
} catch (error) {
  if (error instanceof errors.ValidationError) {
    console.error('Invalid input:', error.details);
  } else if (error instanceof errors.APIError) {
    console.error('API error:', error.message);
  }
}

IPN Verification

// Verify IPN callback signature
const isValid = client.verifyIPN(ipnData, signature);

Available Methods

Payment Operations

  • createPayment(params) - Create new cryptocurrency payment
  • getPaymentStatus(paymentId) - Get payment status by ID
  • getPayments(params) - Get paginated list of payments
  • getPaymentFlow(paymentId) - Get detailed payment processing flow
  • getMinimumPaymentAmount(currency) - Get minimum payment amount for currency

Invoice Operations

  • createInvoice(params) - Create payment invoice
  • getInvoicePaymentStatus(invoiceId) - Get invoice payment status

Currency Operations

  • getCurrencies() - Get list of available cryptocurrencies
  • getEstimatePrice(params) - Get estimated price for currency conversion

Payout Operations

  • createPayout(params) - Create cryptocurrency payout
  • createBatchPayout(params) - Create batch cryptocurrency payout

Verification

  • verifyIPN(ipnData, signature) - Verify IPN callback signature
  • getStatus() - Check API availability

WebSocket Methods

  • connect() - Establish WebSocket connection
  • close() - Close WebSocket connection
  • getState() - Get current connection state

WebSocket Events

  • connected - Connection established
  • disconnected - Connection closed
  • payment_update - Payment status update received
  • error - Error occurred
  • reconnecting - Attempting to reconnect
  • pong - Heartbeat response received

TypeScript Support

The package includes comprehensive TypeScript definitions:

import NowPaymentsAPI, { CreatePaymentParams, PaymentStatus } from "nowpayments-api";

const client = new NowPaymentsAPI({
  apiKey: "YOUR_API_KEY",
});

const payment: PaymentStatus = await client.createPayment({
  price_amount: 100,
  price_currency: "USD",
  pay_currency: "BTC",
} as CreatePaymentParams);

Documentation

For detailed API documentation, visit:

Key Resources:

License

This project is licensed under the MIT License - see the LICENSE file for details.