[BREAKGLASS] Append-only mirror of github.com/btcpayserver/ruby-client
Go to file
Paul Daigle df063e35a2 Modified name of gemfile to bitpay-sdk
bitpay-client will be used for the command line tool that requires this
gem, and the name 'bitpay' was already taken by a dead project.
2015-01-05 16:04:35 -05:00
config Remove bitpay client. 2014-12-29 17:06:28 -05:00
features Remove bitpay client. 2014-12-29 17:06:28 -05:00
lib Merge pull request#29 'philosodad-separated_client' 2014-12-29 17:35:39 -05:00
spec Remove bitpay client. 2014-12-29 17:06:28 -05:00
.gitignore Changes for the 2.0.0 version. Detailed changes are on the 2.0.0 branch. 2014-10-08 13:21:00 -04:00
.travis.yml Changes for the 2.0.0 version. Detailed changes are on the 2.0.0 branch. 2014-10-08 13:21:00 -04:00
bitpay-sdk.gemspec Modified name of gemfile to bitpay-sdk 2015-01-05 16:04:35 -05:00
Gemfile initial commit 2013-11-01 11:51:01 -07:00
LICENSE.md Changes for the 2.0.0 version. Detailed changes are on the 2.0.0 branch. 2014-10-08 13:21:00 -04:00
Rakefile Remove bitpay client. 2014-12-29 17:06:28 -05:00
README.md Merge branch 'separated_client' of https://github.com/philosodad/ruby-client into philosodad-separated_client 2014-12-29 17:23:11 -05:00

BitPay Library for Ruby

Powerful, flexible, lightweight interface to the BitPay Bitcoin Payment Gateway API.

Installation

gem install bitpay

In your Gemfile:

gem 'bitpay', :require => 'bitpay'

Or directly:

require 'bitpay'

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 passed in as a pem file, or paired if initialized with a pem file and a tokens hash. Examples can be found in the cucumber step helpers.

Basic Usage

Pairing with Bitpay.com

To pair with bitpay.com you need to have an approved merchant account.

  1. Login to your account

  2. Navigate to bitpay.com/api-tokens (Dashboard > My Account > API Tokens)

  3. Create a new token and copy the pairing code.

    client = BitPay::Client.new client.pair_pos_client(<pairing_code>) invoice = client.create_invoice (price: , currency: )

With invoice creation, price and currency are the only required fields. If you are sending a customer from your website to make a purchase, setting redirectURL will redirect the customer to your website when the invoice is paid.

Response will be a hash with information on your newly created invoice. Send your customer to the url to complete payment:

{
  "id"             => "DGrAEmbsXe9bavBPMJ8kuk", 
  "url"            => "https://bitpay.com/invoice?id=DGrAEmbsXe9bavBPMJ8kuk",
  "status"         => "new",
  "btcPrice"       => "0.0495",
  "price"          => 10,
  "currency"       => "USD",
  "invoiceTime"    => 1383265343674,
  "expirationTime" => 1383266243674,
  "currentTime"    => 1383265957613
}

There are many options available when creating invoices, which are listed in the BitPay API documentation.

To get updated information on this invoice, make a get call with the id returned:

invoice = client.get_public_invoice(id: 'DGrAEmbsXe9bavBPMJ8kuk')

Testnet Usage

During development and testing, take advantage of the Bitcoin TestNet by passing a custom api_uri option on initialization:

BitPay::Client.new(api_uri: "https://test.bitpay.com/api")

API Documentation

API Documentation is available on the BitPay site.

Running the Tests

In order to run the tests, you must have phantomjs installed and on your PATH.

The tests require that environment variables be set for the bitpay server, user name, and password. First run:

$ source ./spec/set_constants.sh https://test.bitpay.com <yourusername> <yourpassword>
$ bundle install
$ bundle exec rake

Tests are likely to run up against rate limiters on test.bitpay.com if used too frequently. Rake tasks which interact directly with BitPay will not run for the general public.

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.