BitPay.WebClient

Convenience methods for the BitPay REST API.

Summary

The module struct contains two fields:

Sends a post request to the server that creates a new invoice

Generic Get method to the WebClient endpoint + path Input:

  • the path (string)
  • params for the request (as map)
  • WebClient struct

Retrieves an invoice from the BitPay server

initiates a ‘client side’ pairing

creates a token on the server corresponding to the WebClients public and private keys

Generic post method to the WebClient endpoint + path Input:

  • the path (string)
  • params for the request (as map)
  • WebClient struct

Functions

__struct__()

Specs

__struct__ :: %BitPay.WebClient{pem: term, uri: term}

The module struct contains two fields:

  • uri: the api uri, which defaults to https://bitpay.com
  • pem: a pem file containing the public and private keys, which can be generated from the BitPay.KeyUtils module.
create_invoice(params, webclient)

Sends a post request to the server that creates a new invoice.

Input:

  • a params map that must contain a price and a currency
  • a WebClient struct. The web client struct must be paired with BitPay.

Response: A map corresponding to the data section of the JSON response from the server.

get(path, webclient)

Generic Get method to the WebClient endpoint + path Input:

  • the path (string)
  • params for the request (as map)
  • WebClient struct

    Response: a map containing the response code, successe status as true or false, and the body of the http response

get_invoice(id, webclient)

Retrieves an invoice from the BitPay server.

Input:

  • an invoice id
  • a WebClient

Response: a map corresponding to the data section of the JSON response from the server.

get_pairing_code(client)

initiates a ‘client side’ pairing.

Input: a WebClient

Response: {:ok, <pairingCode> }

The pairingCode can then be used at /dashboard/merchant/api-tokens to authenticate the token

get_pairing_code(client, facade)
pair_pos_client(code, client)

creates a token on the server corresponding to the WebClients public and private keys

Input:

  • a pairing code from the server
  • a WebClient

Response: a key/value pair such as %{pos: 92hgkeit92392gjgj}

post(path, params, webclient)
post(arg1, path, params, webclient)

Generic post method to the WebClient endpoint + path Input:

  • the path (string)
  • params for the request (as map)
  • WebClient struct

    Response: a map containing the response code, successe status as true or false, and the body of the http response