Skip to content

Commit

Permalink
docs: 📝 Added new documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
saniales committed Jan 4, 2024
1 parent e3dbb43 commit 2226603
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 27 deletions.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2018 Jeffery Robert Walsh
Copyright (c) 2024 Tryvium Travels LTD

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
95 changes: 68 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,55 @@ the `*coinpayments.Config` struct, consisting of your private and public keys, a

This looks like:
``` go
clientConfig := &coinpayments.Config{
PublicKey: "yourpublickey",
PrivateKey: "yourprivatekey",
}
httpClient := &http.Client{
Timeout: 10 * time.Second,
}
client, err := coinpayments.NewClient(clientConfig, httpClient)
if err != nil {
// handle error...
import (
"github.com/tryvium-travels/go-coinpayments"
)

func main() {
clientConfig := &coinpayments.Config{
PublicKey: "your-public-key",
PrivateKey: "your-private-key",
}
httpClient := &http.Client{
Timeout: 10 * time.Second,
}

client, err := coinpayments.NewClient(clientConfig, httpClient)
if err != nil {
// handle error...
}

// ...
}
```

Once instantiated, you can use the client to make API calls. Each call has their own Request struct, and returns it's own Response struct.

An example of the `create_transaction` command being called:
``` go
resp, err := client.CallCreateTransaction(
&coinpayments.TransactionRequest{
Amount: "1", // the amount is the value of the fiat currency you wish to receive
Currency1: "USD", // currency that amount is specified in (USD, CAD, JPY, etc)
Currency2: "BTC", // currency in crypto that you wish to receive (BTC, ETC, LTC, etc)
BuyerEmail: "[email protected]", // our client requires the buyer email address
}
import (
"github.com/tryvium-travels/go-coinpayments"
)
if err != nil {
// handle error...

func main() {
clientConfig := ...
httpClient := ...
client, err := coinpayments.NewClient(clientConfig, httpClient)
if err != nil {
// handle error...
}

resp, err := client.CallCreateTransaction(
&coinpayments.TransactionRequest{
Amount: "1", // the amount is the value of the fiat currency you wish to receive
Currency1: "USD", // currency that amount is specified in (USD, CAD, JPY, etc)
Currency2: "BTC", // currency in crypto that you wish to receive (BTC, ETC, LTC, etc)
BuyerEmail: "[email protected]", // our client requires the buyer email address
}
)
if err != nil {
// handle error...
}
}
```

Expand All @@ -50,27 +72,46 @@ command from the coinpayments package, ie, `coinpayments.CmdCreateTransaction`.
Here is an example of getting the deposit address:

``` go
var data url.Values
data.Add("currency", "USD")
import (
"net/url"

var resp coinpayments.DepositAddressResponse
err := c.Call(coinpayments.CmdGetDepositAddress, data, &resp)
"github.com/tryvium-travels/go-coinpayments"
)

func main() {
clientConfig := ...
httpClient := ...
client, err := coinpayments.NewClient(clientConfig, httpClient)
if err != nil {
// handle error...
}

var data url.Values
data.Add("currency", "USD")

var resp coinpayments.DepositAddressResponse
err := c.Call(coinpayments.CmdGetDepositAddress, data, &resp)
if err != nil {
// handle error...
}
}
```

# Testing the library

You need to export two environment variables for the tests to run - your public key, and private key.
You need to export two environment variables for the tests to run - your public key, and private key.

``` bash
export COINPAYMENTS_PUBLIC_KEY=yourpublickeyhere
export COINPAYMENTS_PRIVATE_KEY=yourprivatekeyhere
export COINPAYMENTS_PUBLIC_KEY="your-public-key-here"
export COINPAYMENTS_PRIVATE_KEY="your-private-key-here"

go test ./...
```

If you want to run the PBN Tag tests and have purchased a PBN Tag, you can also export it, and those tests will run. Otherwise, they will be ignored.

``` bash
export COINPAYMENTS_PBN_TAG=yourpbntaghere
export COINPAYMENTS_PBN_TAG="your-pbn-tag-here"
```

# How to contribute
Expand Down
3 changes: 3 additions & 0 deletions coinpayments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package coinpayments implements a Golang client of the
// coinpayments.net API
package coinpayments

0 comments on commit 2226603

Please sign in to comment.