Home

Awesome

NOWPayments Go Library

Go Reference Go Report Card codecov

This is an unofficial Go library for the crypto NOWPayments API version 1.

Note that the current implementation mostly focuses on the payments API for now:

TopicEndpointPackage.MethodImplemented
Recurring paymentsNo
Billing (sub-partner)No
PaymentsYes
Get estimated pricepayments.EstimatedPrice(...):heavy_check_mark:
Get the minimum payment amountpayments.MinimumAmount(...):heavy_check_mark:
Get payment statuspayments.Status():heavy_check_mark:
Get list of paymentspayments.List(...):heavy_check_mark:
Get/Update payment estimatepayments.RefreshEstimatedPrice(...):heavy_check_mark:
Create invoicepayments.NewInvoice(...):heavy_check_mark:
Create paymentpayments.New(...):heavy_check_mark:
Create payment from invoicepayments.NewFromInvoice(...):heavy_check_mark:
CurrenciesYes
Get available currenciescurrencies.All():heavy_check_mark:
Get available checked currenciescurrencies.Selected():heavy_check_mark:
PayoutsNo
API statusYes
Get API statuscore.Status():heavy_check_mark:
AuthenticationYes
Authenticationcore.Authenticate(...):heavy_check_mark:

Installation

$ go get github.com/matm/go-nowpayments@v1.0.4

Usage

Just load the config with all the credentials from a file or using a Reader then display the NOWPayments' API status and the last 2 payments made with:

package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/matm/go-nowpayments/config"
	"github.com/matm/go-nowpayments/core"
	"github.com/matm/go-nowpayments/payments"
)

func main() {
      // Load sandbox's credentials.
	err := config.Load(strings.NewReader(`
{
      "server": "https://api-sandbox.nowpayments.io/v1",
      "login": "some_email@domain.tld",
      "password": "some_password",
      "apiKey": "some_api_key"
}
`))
	if err != nil {
		log.Fatal(err)
	}

	// Use the server URL defined above.
	core.UseBaseURL(core.BaseURL(config.Server()))
	// Use default HTTP client.
	core.UseClient(core.NewHTTPClient())

	st, err := core.Status()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("API status:", st)

	const limit = 2
	ps, err := payments.List(&payments.ListOption{
		Limit: limit,
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Last %d payments: %v\n", limit, ps)
}

CLI Tool

A np tool is available to easily play with the payments API from the command line. Please make sure to target the sandbox API server in this case.

Can be installed with:

$ go install github.com/matm/go-nowpayments/cmd/np@latest

The following commands are available:

Usage of np:
  -a float
        pay amount for new payment/invoice (default 2)
  -c    show list of selected currencies
  -case string
        payment's case (sandbox only) (default "success")
  -debug
        turn debugging on
  -f string
        JSON config file to use
  -i    new invoice
  -l    list all payments
  -n    new payment
  -p string
        status of payment ID
  -pc string
        crypto currency to pay in (default "xmr")
  -pi string
        new payment from invoice ID

In order to work, np expects a JSON config file provided as an argument, like

$ np -f conf.json -c

to list all crypto currencies available for payments.

The JSON config file looks like

{
  "server": "https://api-sandbox.nowpayments.io/v1",
  "login": "your_email_adresse",
  "password": "some_password",
  "apiKey": "the API key to use"
}