client

package
v0.0.0-...-1a525eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2014 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package bitpay provides a Go client for the Bitpay REST API

Docs: https://bitpay.com/api

Index

Constants

View Source
const (
	// APIBaseSandBox points to the sandbox (for testing) version of the API
	APIBaseTest = "https://test.bitpay.com"

	// APIBaseLive points to the live version of the API
	APIBaseProd = "https://bitpay.com"
)

Variables

View Source
var (
	// Debug is a flag to enable/disable debug messages
	Debug bool

	FacadePublic   Facade = "public"
	FacadePOS      Facade = "pos"
	FacadeMerchant Facade = "merchant"
)

Functions

This section is empty.

Types

type Application

type Application struct {
	Users []ApplicationUser `json:"users"`
	Orgs  []ApplicationOrg  `json:"orgs"`
}

Application maps to a resource at the applications endpoint

type ApplicationOrg

type ApplicationOrg struct {
	Name         string `json:"name"`
	Address1     string `json:"address1"`
	Address2     string `json:"address2"`
	City         string `json:"city"`
	State        string `json:"state"`
	Zip          string `json:"zip"`
	Country      string `json:"country"`
	IsNonProfit  bool   `json:"isNonProfit,omitempty"`
	USTaxID      string `json:"usTaxId,omitempty"`
	Industry     string `json:"industry"`
	Website      string `json:"website"`
	CartPOS      string `json:"cartPos,omitempty"`
	AffiliateOID string `json:"affiliateOid,omitempty"`
}

type ApplicationUser

type ApplicationUser struct {
	Email            string `json:"email"`
	FirstName        string `json:"firstName"`
	LastName         string `json:"lastName"`
	Phone            string `json:"phone"`
	AgreedToTOSAndPP bool   `json:"agreedToTOSandPP"`
}

type Bill

type Bill struct {
	ID       string     `json:"id,omitempty"`
	Items    []BillItem `json:"items"`
	Currency string     `json:"currency,omitempty"`
	ShowRate string     `json:"showRate,omitempty"`
	Archived string     `json:"archived,omitempty"`
	Name     string     `json:"name,omitempty"`
	Address1 string     `json:"address1,omitempty"`
	Address2 string     `json:"address2,omitempty"`
	City     string     `json:"city,omitempty"`
	State    string     `json:"state,omitempty"`
	Zip      string     `json:"zip,omitempty"`
	Country  string     `json:"country,omitempty"`
	Email    string     `json:"email,omitempty"`
	Phone    string     `json:"phone,omitempty"`
}

Bill maps to a resource at the bills endpoint

type BillItem

type BillItem struct {
	Description string `json:"description"`
	Price       int64  `json:"price"`
	Quantity    int64  `json:"quantity"`
}

BillItem maps to an entry in the items array of Bill

type BitpayClient

type BitpayClient struct {
	ID    string `json:"id"`
	Label string `json:"label"`
}

BitpayClient maps to a resource in clients endpoint

type Buyer

type Buyer struct {
	Name       string `json:"name,omitempty"`
	Address1   string `json:"address1,omitempty"`
	Address2   string `json:"address2,omitempty"`
	Locality   string `json:"locality,omitempty"`
	Region     string `json:"region,omitempty"`
	PostalCode string `json:"postalCode,omitempty"`
	Country    string `json:"country,omitempty"`
	Email      string `json:"email,omitempty"`
	Phone      string `json:"phone,omitempty"`
}

Buyer maps to the buyer object in an Invoice

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a Bitpay REST API Client

func NewClient

func NewClient(APIBase string) *Client

NewClient returns a new Client struct without keys and SIN

func NewClientWithAuth

func NewClientWithAuth(privateKey, token, APIBase string) *Client

NewClientWithAuth returns a new client with keys and SIN

func (*Client) AcceptInvoiceAdjustment

func (c *Client) AcceptInvoiceAdjustment(invoiceID string, adjustment InvoiceAdjustment) (*http.Response, error)

AcceptInvoiceAdjustment accepts the overpayment or underpayment for the invoice.

func (*Client) ClaimToken

func (c *Client) ClaimToken(label, clientID, pairingCode string) (TokenResp, error)

ClaimToken claims a generated token by using pairing code

func (*Client) CreateApplication

func (c *Client) CreateApplication(a Application) (*http.Response, error)

CreateApplication creates an application for a new merchant account

func (*Client) CreateBill

func (c *Client) CreateBill(b Bill) (*http.Response, error)

CreateBill creates a bill for the calling merchant

func (*Client) CreateInvoice

func (c *Client) CreateInvoice(i Invoice) (*http.Response, error)

CreateInvoice creates an invoice for the calling merchant

func (*Client) CreateInvoiceNotification

func (c *Client) CreateInvoiceNotification(invoiceID string) (*http.Response, error)

CreateInvoiceNotification resends the IPN for the specified invoice

func (*Client) CreateInvoiceRefund

func (c *Client) CreateInvoiceRefund(invoiceID string, r InvoiceRefund) (*http.Response, error)

CreateInvoiceRefund creates a refund request for a given invoice

func (*Client) CreatePayout

func (c *Client) CreatePayout(p Payout) (*http.Response, error)

CreatePayout creates a payout batch request.

func (*Client) CreatePayoutsReports

func (c *Client) CreatePayoutsReports() (*http.Response, error)

CreatePayoutsReports creates and returns a payout request report TODO: implement

func (*Client) CreateSession

func (c *Client) CreateSession() (Session, *http.Response, error)

CreateSession creates an API session to protect against replay attacks and ensure requests are received in the same order they are sent.

func (*Client) DeleteInvoiceRefund

func (c *Client) DeleteInvoiceRefund(invoiceID, refundID string) (*http.Response, error)

DeleteInvoiceRefund cancels a pending refund request

func (*Client) DeletePayout

func (c *Client) DeletePayout(payoutID string) (*http.Response, error)

DeletePayout cancels the given payout request if status is still new.

func (*Client) GetBill

func (c *Client) GetBill(ID string) (*Bill, *http.Response, error)

GetBill returns the specified bill by ID

func (*Client) GetInvoice

func (c *Client) GetInvoice(ID string) (*Invoice, *http.Response, error)

GetInvoice returns the specified invoice by ID for the calling merchant

func (*Client) GetInvoiceEvents

func (c *Client) GetInvoiceEvents(ID string) (*EventResp, *http.Response, error)

GetInvoiceEvents returns a bus token which can be used to subscribe to invoice events

func (*Client) GetPayout

func (c *Client) GetPayout(ID string) (*Payout, *http.Response, error)

GetPayout return the specified payout request

func (*Client) GetRateForCurrency

func (c *Client) GetRateForCurrency(currencyCode string) (*Rate, *http.Response, error)

GetRateForCurrency returns the exchange rate for a given currency.

func (*Client) GetUser

func (c *Client) GetUser() (*User, *http.Response, error)

GetUser returns caller's user information.

func (*Client) NewRequest

func (c *Client) NewRequest(method, url string, payload interface{}) (*http.Request, error)

NewRequest constructs a request. If payload is not empty, it will be marshalled into JSON

func (*Client) NewRequestWithAuth

func (c *Client) NewRequestWithAuth(method, endpoint string, payload interface{}) (*http.Request, error)

NewRequestWithAuth constructs a request. Will do the following things: 1. If payload is not empty, it will be marshalled into JSON. 2. Applies signing and auth headers. 3. Add token and guid to the body

func (*Client) NewToken

func (c *Client) NewToken(label, clientID string, facade Facade) (TokenResp, error)

NewToken requests a new token from Bitpay

func (*Client) QueryBills

func (c *Client) QueryBills() ([]Bill, *http.Response, error)

QueryBills returns all of the caller's bills.

func (*Client) QueryCurrencies

func (c *Client) QueryCurrencies() ([]Currency, *http.Response, error)

QueryCurrencies returns the list of supported currencies.

func (*Client) QueryInvoices

func (c *Client) QueryInvoices() ([]Invoice, *http.Response, error)

QueryInvoices returns invoices for the calling merchant filtered by query.

func (*Client) QueryPayouts

func (c *Client) QueryPayouts() ([]Payout, *http.Response, error)

QueryPayouts returns all of the caller's payout requests by status

func (*Client) QueryRates

func (c *Client) QueryRates() ([]Rate, *http.Response, error)

QueryRates returns a list of exchange rates.

func (*Client) Send

func (c *Client) Send(req *http.Request, v interface{}) (*http.Response, error)

Send makes a request to the API, the response body will be unmarshaled into v, or if v is an io.Writer, the response will be written to it without decoding

func (*Client) UpdateBill

func (c *Client) UpdateBill(b Bill) (*http.Response, error)

UpdateBill updates a specified bill by ID

func (*Client) UpdatePayout

func (c *Client) UpdatePayout(p Payout) (*http.Response, error)

UpdatePayout sets the rate for a payout request and/or mark as funded. TODO: Reimplement

func (*Client) UpdateUser

func (c *Client) UpdateUser(u User) (*User, *http.Response, error)

UpdateUser updates caller's user information.

type Currency

type Currency struct {
	Code           string   `json:"code"`
	Symbol         string   `json:"symbol"`
	Precision      int      `json:"precision"`
	ExchangePCTFee int64    `json:"exchangePctFee"`
	PayoutEnabled  bool     `json:"payoutEnabled"`
	Name           string   `json:"name"`
	Plural         string   `json:"plural"`
	Alts           string   `json:"alts"`
	PayoutFields   []string `json:"payoutFields"`
}

Currency maps to a resource at the currencies endpoint

type EventResp

type EventResp struct {
	URL     string   `json:"url"`
	Token   string   `json:"token"`
	Events  []string `json:"events"`
	Actions []string `json:"actions"`
}

EventResp maps to the response from the GET /invoices/:invoiceId/events

type Facade

type Facade string

Facade is a named collection of capabilitites https://test.bitpay.com/api#facades

type Instruction

type Instruction struct {
	Amount  int64  `json:"amount"`
	Address string `json:"address"`
	Label   string `json:"label"`
}

Instruction maps to an item in Instructions field of Payout

type Invoice

type Invoice struct {
	ID                string `json:"id,omitempty"`
	Price             int64  `json:"price"`
	Currency          string `json:"currency"`
	OrderID           string `json:"orderID,omitempty"`
	ItemDesc          string `json:"itemDesc,omitempty"`
	ItemCode          string `json:"itemCode,omitempty"`
	NotificationEmail string `json:"notificationEmail,omitempty"`
	NotificationURL   string `json:"notificationURL,omitempty"`
	RedirectURL       string `json:"redirectURL,omitempty"`
	POSData           string `json:"posData,omitempty"`
	TransactionSpeed  string `json:"transactionSpeed,omitempty"`
	FullNotifications string `json:"fullNotifications,omitempty"`
	Physical          string `json:"physical,omitempty"`
	Buyer             Buyer  `json:"buyer,omitempty"`
}

Invoice maps to a resource at the invoices endpoint

type InvoiceAdjustment

type InvoiceAdjustment string

InvoiceAdjustment is used when accepting the overpayment or underpayment for an invoice.

var (
	InvoiceAdjustmentAcceptUnderpayment InvoiceAdjustment = "acceptUnderpayment"
	InvoiceAdjustmentAcceptOverpayment  InvoiceAdjustment = "acceptOverpayment"
)

type InvoiceRefund

type InvoiceRefund struct {
	RequestID      string `json:"requestID,omitempty"`
	BitcoinAddress string `json:"bitcoinAddress,omitempty"`
	Amount         int64  `json:"amount,omitempty"`
	Currency       string `json:"currency,omitempty"`
}

InvoiceRefund maps to a resource at the invoice refunds endpoint

type Payout

type Payout struct {
	Instructions      []Instruction `json:"instructions"`
	Amount            int64         `json:"amount"`
	Currency          string        `json:"currency"`
	EffectiveDate     time.Time     `json:"effectiveDate"`
	Reference         string        `json:"reference,omitemtpy"`
	PricingMethod     string        `json:"pricingMethod,omitempty"`
	NotificationEmail string        `json:"notificationEmail,omitempty"`
	NotificationURL   string        `json:"notificationURL,omitempty"`
}

Payout maps to a resource at the payouts endpoint

type Policy

type Policy struct {
	Policy string   `json:"policy"`
	Method string   `json:"method"`
	Params []string `json:"params"`
}

type Rate

type Rate struct {
	Code string  `json:"code"`
	Name string  `json:"name"`
	Rate float64 `json:"rate"`
}

Rate maps to a resource at the rates

type Response

type Response struct {
	Error string          `json:"error"`
	Data  json.RawMessage `json:"data"`
}

Response represents a response from Bitpay API, it contains either an error or data

type Session

type Session string

Session is a unique session ID to protect against replay attacks

type TokenResp

type TokenResp struct {
	Policies          []Policy `json:"policies"`
	Token             string   `json:"token"`
	Facade            *Facade  `json:"facade"`
	Label             string   `json:"label"`
	DateCreated       int64    `json:"dateCreated"`
	PairingExpiration int64    `json:"pairingExpiration"`
	PairingCode       string   `json:"pairingCode"`
}

type User

type User struct {
	Name  string `json:"name,omitempty"`
	Phone string `json:"phone,omitempty"`
}

User maps to a resource in the users endpoint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL