Skip to content

jon4hz/go-btcpay

Repository files navigation

Go-BTCPay

License: MIT testing

-- Work in progress --

A Golang SDK for the BTCPay Server Greenfield API v1.

💡 About

This package provies full access to the Greenfield API v1 from a BTCPayServer. Every API call returns, if available, a corresponding go struct, a HTTP status code and an error.

It's possible to control the individual calls by passing a context for each function and method.

🚀 Getting started

🧑‍💻 Create a client

You can create a client either by using basic authentication or by using an API Key.

package main

import (
    "context"
    "fmt"
    "github.com/jon4hz/go-btcpay"
)

func main() {
    // create empty context interface
    ctx := context.Background()

    // Create a basicAuth client
    client := btcpay.NewBasicClient("https://mybtcpayserver.com", "myUsername", "myPassword")

    // Print informations about the server, etc
    fmt.Println(client.GetServerInfo(ctx))

    // Does the same but with an APIKey instead of basicAuth
    // Create a client with an APIKey
    client2 := btcpay.NewClient("https://mybtcpayserver.com", btcpay.APIKey("myAPIKey")

    // Print informations about the server, etc again but use the APIKey based client
    fmt.Println(client2.GetServerInfo(ctx))
}

📝 Create an invoice

You can create an invoice by using the previously created client.

// assign a store to the client
client.Store.ID = btcpay.StoreID("YourStoreID")

// create the invoice
invoice, _, err := client.CreateInvoice(context.TODO(), &client.Store.ID, &btcpay.InvoiceRequest{
    Amount:   "10",
    Currency: "USD",
})
if err != nil {
   fmt.Println(err)
} else {
    fmt.Println(invoice) // invoice has type *btcpay.InvoiceResponse
}

Calling the method CreateInvoice() works for variable of type *btcpay.Store, too.

// by passing the store from the previously created client, the new store (*btcpay.Store) contains 
// a pointer  back to the initial client 
store = client.Store
// assign a storeID to the store
store.ID = btcpay.StoreID("YourStoreID")

// create the invoice
invoice, _, err := store.CreateInvoice(context.TODO(), &btcpay.InvoiceRequest{
    Amount:   "10",
    Currency: "USD",
})
if err != nil {
   fmt.Println(err)
} else {
    fmt.Println(invoice) // invoice has type *btcpay.InvoiceResponse
}

[more examples will follow soon]

initialented endpoints.

Endpoint Status
/api/v1/api-keys ✅ Fully implemented
/api-keys/authorize ⚡️ Testing required
/api/v1/health ✅ Fully implemented
/api/v1/server/info ✅ Fully implemented
/api/v1/users ✅ Fully implemented
/api/v1/users/me/notifications ✅ Fully implemented
/api/v1/stores ⚠️ Partially implemented
/api/v1/stores/{storeId}/invoices ✅ Fully implemented
/api/v1/stores/{storeId}/payment-requests ✅ Fully implemented
/api/v1/stores/{storeId}/pull-payments ✅ Fully implemented
/api/v1/stores/{storeId}/payment-methods/OnChain/{cryptoCode}/wallet ⏳ Work in progress
/misc/lang ✅ Fully implemented
/i ✅ Fully implemented
/api/v1/pull-payments ✅ Fully implemented

📜 Licensing

This SDK is released under the MIT-License found in the LICENSE file.