NOWPayments Go Library
January 24, 2023 ยท View on GitHub
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(...) | :heavy_check_mark: | |
| Get the minimum payment amount | payments.MinimumAmount(...) | :heavy_check_mark: | |
| Get payment status | payments.Status() | :heavy_check_mark: | |
| Get list of payments | payments.List(...) | :heavy_check_mark: | |
| Get/Update payment estimate | payments.RefreshEstimatedPrice(...) | :heavy_check_mark: | |
| Create invoice | payments.NewInvoice(...) | :heavy_check_mark: | |
| Create payment | payments.New(...) | :heavy_check_mark: | |
| Create payment from invoice | payments.NewFromInvoice(...) | :heavy_check_mark: | |
| Currencies | Yes | ||
| Get available currencies | currencies.All() | :heavy_check_mark: | |
| Get available checked currencies | currencies.Selected() | :heavy_check_mark: | |
| Payouts | No | ||
| API status | Yes | ||
| Get API status | core.Status() | :heavy_check_mark: | |
| Authentication | Yes | ||
| Authentication | core.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"
}
serveris the path to the API server, i.e. one of- sandbox:
https://api-sandbox.nowpayments.io/v1 - production:
https://api.nowpayments.io/v1
- sandbox:
loginandpasswordare your NOWPayments credentialsapiKeyis one API key generated in your admin account