Golang Coinpayments wrapper library
NOTE: This project started as a fork of jeffwalsh/go-coinpayments project, but rapidly evolved to its own. While we thank and credit original creator for the job so far, we are going separate ways for the time being.
This is the only coinpayments golang wrapper library officially supported and maintained by Tryvium Travels LTD
Coinpayments Golang wrapper. To use, instantiate a *coinpayments.Client
by calling the coinpayments.NewClient
function. You will need to pass in a valid instance of
the *coinpayments.Config
struct, consisting of your private and public keys, as well as an instance of your desired http client.
This looks like:
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 {
}
}
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:
import (
"github.com/tryvium-travels/go-coinpayments"
)
func main() {
clientConfig := ...
httpClient := ...
client, err := coinpayments.NewClient(clientConfig, httpClient)
if err != nil {
}
resp, err := client.CallCreateTransaction(
&coinpayments.TransactionRequest{
Amount: "1",
Currency1: "USD",
Currency2: "BTC",
BuyerEmail: "test@email.com",
}
)
if err != nil {
}
}
Usage
You can use Call to call any command directly.
You just need to build out your own data with an url.Values
, and create an instance of the responsestruct expected by your command, then pass in the relevant
command from the coinpayments package, ie, coinpayments.CmdCreateTransaction
.
Here is an example of getting the deposit address:
import (
"net/url"
"github.com/tryvium-travels/go-coinpayments"
)
func main() {
clientConfig := ...
httpClient := ...
client, err := coinpayments.NewClient(clientConfig, httpClient)
if err != nil {
}
var data url.Values
data.Add("currency", "USD")
var resp coinpayments.DepositAddressResponse
err := c.Call(coinpayments.CmdGetDepositAddress, data, &resp)
if err != nil {
}
}
Testing the library
You need to export two environment variables for the tests to run - your public key, and private key.
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.
export COINPAYMENTS_PBN_TAG="your-pbn-tag-here"
How to contribute
First of all, thank you for that ❤️
If you want to contribute, just make a PR against the main
branch of this repo.
The PR name must state which issue is solved and a description of your changes.
Please do not close 2 issues with the same commit, do 2 separate commits or more.
Implemented Methods
Information Commands
Receiving Payments
Withdrawals / Transfers
$PayByName ( PBN )