-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
debug: rename -d flag to -debug (#39)
* debug: rename -d flag to -debug Fixes #38 * List 2 payments
- Loading branch information
Showing
3 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,60 @@ Topic|Endpoint|Package.Method|Implemented | |
$ 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: | ||
|
||
```go | ||
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. | ||
|
@@ -51,14 +105,19 @@ Usage of np: | |
-a float | ||
pay amount for new payment/invoice (default 2) | ||
-c show list of selected currencies | ||
-d turn debugging on | ||
-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 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters