Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nowpaymentsio/nowpayments-api-js

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nowpaymentsio/nowpayments-api-js

A library for interacting with the NOWPayments API

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
398
decreased by-20.87%
Maintainers
2
Weekly downloads
 
Created
Source

NOWPayments API

Build Status

A library for interacting with the NOWPayments API.

Installation

Using npm:

$ npm install @nowpaymentsio/nowpayments-api-js

Using unpkg CDN:

<script src="https://unpkg.com/@nowpaymentsio/nowpayments-api-js/dist/nowpayments-api-js.min.js"></script>

Examples

Node JS

const NowPaymentsApi = require('@nowpaymentsio/nowpayments-api-js');

const api = new NowPaymentsApi({ apiKey: 'A7M40XV-CG1448Z-KVVED3G-NW3V0TK' }) // your api key
async function logCurrencies() {
  const { currencies } = await api.getCurrencies()
  console.log(currencies)
}
logCurrencies()

React

import React from 'react'
import NowPaymentsApi from '@nowpaymentsio/nowpayments-api-js'

const npApi = new NowPaymentsApi({ apiKey: 'A7M40XV-CG1448Z-KVVED3G-NW3V0TK' }) // your api key

const App = () => {
  const [currenciesArr, setCurrenciesArr] = React.useState([])
  React.useEffect(() => {
    async function fetchCurrencies() {
      const { currencies } = await npApi.getCurrencies()
      setCurrenciesArr(currencies)
    }
    fetchCurrencies()
  }, [])

  return (
    <div>
      <h2>Available currencies</h2>
      <br />
      {currenciesArr.map((currency) => (
        <p>{currency}</p>
      ))}
    </div>
  )
}

export default App

HTML

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>NOWPayments API - HTML Example</title>
  <script src="https://unpkg.com/@nowpaymentsio/nowpayments-api-js/dist/nowpayments-api-js.min.js"></script>
</head>

<body>
  <h4>Available currencies</h4>
  <script>
    const body = document.body;
    const api = new NOWPaymentsApiJS({ apiKey: 'A7M40XV-CG1448Z-KVVED3G-NW3V0TK' }) // your api key

    async function fetchCurrencies() {
      const { currencies } = await api.getCurrencies()
        const selectList = document.createElement("select")
        selectList.id = "mySelect"
        body.appendChild(selectList)

      for (var i = 0; i < currencies.length; i++) {
        const option = document.createElement("option")
        option.value = currencies[i]
        option.text = currencies[i]
        selectList.appendChild(option)
      }
    }
    fetchCurrencies()
  </script>
</body>
</html>

Methods

 

NPApi.status()

Get API status

paramsdefaultrequireddescription
    
NPApi.getCurrencies()

Get available currencies

paramsdefaultrequireddescription
    
NPApi.getEstimatePrice(params)

Get estimated price

paramsdefaultrequireddescription
amountnulltrueInitial cost in the fiat currency
NPApi.createPayment(params)

Create payment

paramsdefaultrequireddescription
price_amountnulltrueFiat equivalent of the price to be paid in crypto
price_currencynulltrueFiat currency in which the price_amount is specified (usd, eur, etc)
pay_amountnullfalseAmount that users have to pay for the order stated in crypto
pay_currencynulltrueCrypto currency in which the pay_amount is specified (btc, eth, etc)
ipn_callback_urlnullfalseUrl to receive callbacks, should contain "http" or "https", eg. "https://nowpayments.io"
order_idnullfalseInner store order ID, e.g. "RGDBP-21314"
order_descriptionnullfalseInner store order description, e.g. "Apple Macbook Pro 2019 x 1"
purchase_idnullfalseId of purchase for which you want to create aother
payout_addressnullfalseUsually the funds will go to the address you specify in your Personal account. In case you want to receive funds on another address, you can specify it in this parameter
payout_currencynullfalseCurrency of your external payout_address, required when payout_adress is specified
payout_extra_idnullfalseExtra id or memo or tag for external payout_address
fixed_ratenullfalseBoolean, can be true or false. Required for fixed-rate exchanges
NPApi.getPaymentStatus(params)

Get payment status

paramsdefaultrequireddescription
payment_idnulltrueID of the payment
NPApi.getMinimumPaymentAmount(params)

Get the minimum payment amount

paramsdefaultrequireddescription
currency_fromnulltrueTicker currency
currency_tonulltrueTicker currency
NPApi.getListPayments(params)

Get list of payments

paramsdefaultrequireddescription
limit10falseNumber of records in one page
page0falsePage number you want to get
sortBycreated_atfalseSort the received list by a paramenter.
orderByascfalseDisplay the list in ascending or descending order
dateFromnullfalseSelect the displayed period start date (date format: YYYY-MM-DD or yy-MM-ddTHH:mm:ss.SSSZ)
dateTonullfalseSelect the displayed period end date (date format: YYYY-MM-DD or yy-MM-ddTHH:mm:ss.SSSZ)
NPApi.createInvoice(params)

Create invoice

paramsdefaultrequireddescription
price_amountnulltrueHe amount that users have to pay for the order stated in fiat currency. In case you do not indicate the price in crypto, our system will automatically convert this fiat amount in crypto equivalent
price_currencynulltrueThe fiat currency in which the price_amount is specified (usd, eur, etc)
pay_currencynullfalseThe crypto currency in which the pay_amount is specified (btc, eth, etc).If not specified, can be choosen on the invoice_url
ipn_callback_urlnullfalseUrl to receive callbacks, should contain "http" or "https", eg. "https://nowpayments.io"
order_idnullfalseInner store order ID, e.g. "RGDBP-21314"
order_descriptionnullfalseInner store order description, e.g. "Apple Macbook Pro 2019 x 1"
success_urlnullfalseUrl where the customer will be redirected after sucesfull payment
cancel_urlnullfalseUrl where the customer will be redirected after failed payment

Resources

Keywords

FAQs

Package last updated on 14 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc