Skip to content

matm/go-nowpayments

Repository files navigation

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:

Topic Endpoint Package.Method Implemented
Recurring payments No
Billing (sub-partner) No
Payments Yes
Get estimated price payments.EstimatedPrice(...) ✔️
Get the minimum payment amount payments.MinimumAmount(...) ✔️
Get payment status payments.Status() ✔️
Get list of payments payments.List(...) ✔️
Get/Update payment estimate payments.RefreshEstimatedPrice(...) ✔️
Create invoice payments.NewInvoice(...) ✔️
Create payment payments.New(...) ✔️
Create payment from invoice payments.NewFromInvoice(...) ✔️
Currencies Yes
Get available currencies currencies.All() ✔️
Get available checked currencies currencies.Selected() ✔️
Payouts No
API status Yes
Get API status core.Status() ✔️
Authentication Yes
Authentication core.Authenticate(...) ✔️

Installation

$ go get github.com/matm/[email protected]

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": "[email protected]",
      "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"
}
  • server is the path to the API server, i.e. one of
    • sandbox: https://api-sandbox.nowpayments.io/v1
    • production: https://api.nowpayments.io/v1
  • login and password are your NOWPayments credentials
  • apiKey is one API key generated in your admin account

About

Go library for the crypto NOWPayments API

Resources

License

Stars

Watchers

Forks

Packages

No packages published