GithubHelp home page GithubHelp logo

isabella232 / elixir-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bitpay/elixir-client

0.0 0.0 0.0 382 KB

Elixir core library for connecting to bitpay.com

License: MIT License

Elixir 99.46% Shell 0.54%

elixir-client's Introduction

GitHub license Travis Hex.pm Coveralls

BitPay Library for Elixir or Erlang

Powerful, flexible, lightweight interface to the BitPay Bitcoin Payment Gateway API. Can be used in an Elixir project or directly in an Erlang project as described in the Elixir Crash Course. This document assumes that you are using Elixir.

Installation

using hex, add to mixfile: { :bitpay, "~> 0.2.4" }

otherwise: { :bitpay, github: "bitpay/elixir-client", tag: "v0.2.4" }

Basic Usage

The bitpay library allows authenticating with BitPay, creating invoices, and retrieving invoices.

Pairing with Bitpay.com

Before pairing with BitPay.com, you'll need to log in to your BitPay account and navigate to /api-tokens. Generate a new pairing code and use it in the next step. If you want to test against

> pem = BitPay.KeyUtils.generate_pem
> webclient = %BitPay.WebClient{pem: pem} #or %BitPay.WebClient{pem: pem, uri: "https://test.bitpay.com"}
> token = BitPay.WebClient.pair_pos_client(pairingcode, webclient)

You'll need to know the pem file and the token in order to create invoices.

To create an invoice with a paired client:

Assuming that you have both a token object and a webclient as shown in the last step:

> webclient = %BitPay.WebClient{pem: pem, uri: "https://test.bitpay.com"}
> params = %{price: 100, currency: "USD", token: token.pos}
> invoice = BitPay.WebClient.create_invoice(params, webclient)

That will return a map representing the invoice, and create an invoice on BitPays servers. Other parameters can be sent, see the BitPay REST API documentation for details.

Testnet Usage

To use testnet, add a uri parameter when creating the webclient struct %BitPay.WebClient{uri: "https://test.bitpay.com"}

API Documentation

API Documentation is available on the BitPay site.

Running the Tests

The tests depend on a custom fork of elixir-webdriver and require that you have phantomjs installed.

Before running the tests, get a test.bitpay.com account. After this, you'll need to use the shell to approve a merchant token. Using iex -S mix:

(iex 1)> pem = BitPay.KeyUtils.generate_pem
(iex 2)> api = "https://test.bitpay.com"
(iex 3)> client = %BitPay.WebClient{pem: pem, uri: api}
(iex 4)> {:ok, pairingCode} = BitPay.WebClient.get_pairing_code(client)

Then log in to your dashboard and use the pairing code to create a "merchant" token. Once this is set, you'll need to create two environment variables, BITPAYPEM and BITPAYAPI, set to the values you used in the shell session. It's a good idea to save the pem to a file so that you can retrieve it later, the tests don't take care of that for you.

Once that's done you should be able to run: mix test and see the tests run.

Found a bug?

Let us know! Send a pull request or a patch. Questions? Ask! We're here to help. We will respond to all filed issues.

Contributors

Click here to see a list of the contributors to this library.

elixir-client's People

Contributors

philosodad avatar lowks avatar ionux avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.