Skip to content

NdoleStudio/coinpayments-go

Repository files navigation

coinpayments-go

Build codecov Scrutinizer Code Quality Go Report Card GitHub contributors GitHub license PkgGoDev

This package provides a generic go client template for the CoinPayments HTTP API

Installation

coinpayments-go is compatible with modern Go releases in module mode, with Go installed:

go get github.com/NdoleStudio/coinpayments-go

Alternatively the same can be achieved if you use import in a package:

import "github.com/NdoleStudio/coinpayments-go"

Implemented

  • Payments
    • create_transaction: Create Transaction

Usage

Initializing the Client

An instance of the client can be created using New().

package main

import (
	"github.com/NdoleStudio/coinpayments-go"
)

func main()  {
    client := coinpayments.New(
        coinpayments.WithAPIKey(/* API Key */),
        coinpayments.WithAPISecret(/* API Secret */),
    )
}

Error handling

All API calls return an error as the last return object. All successful calls will return a nil error.

status, response, err := client.Payments.CreatePayment(context.Background())
if err != nil {
    //handle error
}

Payments

create_transaction: Create Transaction

transaction, response, err := client.Payments.CreatePayment(context.Background(), &CreatePaymentRequest{
        Amount:           "1.00000000",
        OriginalCurrency: "USD",
        SendingCurrency:  "USD",
        BuyerEmail:       "[email protected]",
    }
)

if err != nil {
    log.Fatal(err)
}

log.Println(transaction.Error) // ok

Testing

You can run the unit tests for this client from the root directory using the command below:

go test -v

License

This project is licensed under the MIT License - see the LICENSE file for details