Skip to content

Latest commit

 

History

History
64 lines (43 loc) · 2.61 KB

GUIDE.md

File metadata and controls

64 lines (43 loc) · 2.61 KB

Using the BitPay Go Client Library

Prerequisites

You must have a BitPay merchant account to use this library. It's free to sign-up for a BitPay merchant account.

Once you have a BitPay merchant account, you will need a working BitPay Access Token – this can be done either via the library or manually in the BitPay Dashboard.

Quick Start

Installation

go get github.com/bitpay/bitpay-go

Read the documentation on [godoc](http://godoc.org/github.com/bitpay/bitpay-go)

Configuration

The bitpay client creates a cryptographically secure connection to your server by pairing an API code with keys generated by the library. The client can be initialized with pre-existing keys, or with pre-existing keys and a pre-existing token.

Pairing

Most calls to the BitPay REST API require that your client is paired with the bitpay.com server. To pair with bitpay.com you need to have an approved merchant account.

The BitPay test helper is probably the easi

Pairing Programatically

If you are developing a client with built-in pairing capability, you can pair programattically.

`*Client.PairWithCode(<pairing code>)` will complete a server-initiated pairing, when provided a pre-generated pairing code from https://bitpay.com/dashboard/merchant/api-tokens.  In this case, the `pos` facade will be automatically assigned.

The example below demonstrates this, assuming that the bitpay-go client is imported as gc and the key_utils as ku, and that the user has retrieved a code and assigned it to the variable pairingcode.

pemString := ku.GeneratePem()
id := ku.GenerateSinFromPem(pemString)
apiUri := "https://bitpay.com"
webClient := Client{ApiUri: apiUri, Pem: pemString, ClientId: id}
token := webClient.PairWithCode(pairingCode)
webClient.Token = token

Create a new bitcoin invoice

Once you have paired the client as above, you can use the client to create invoices:

invoice := webClient.CreateInvoice(123.00, "USD")

This returns an invoice type struct.

Get invoice status

The go library provides one method for fetching an existing invoice:

client.GetInvoice('PvVhgBfA7wKPWhuVC24rJo')

Testnet Usage

During development and testing, take advantage of the Bitcoin TestNet by creating a client with the ApiUri value "https://test.bitpay.com"

Note that in order to pair with testnet, you will need a pairing code from test.bitpay.com.

API Documentation

API Documentation is available on the BitPay site.