/coinpayments

Ruby client for the CoinPayments.net API

Primary LanguageRubyMIT LicenseMIT

CoinPayments.net API Client

Gem Version Build Status Code Climate

CoinPayments | API Documentation | Usage

CoinPayments.net is a payment gateway that can allow you to accept Bitcoin, Litecoin, Ether and over 50 other popular cryptocurrencies directly on your website.

This gem will let you to easily communicate with their API directly from your Ruby application. Want to accept Doge, Dash, START, or other less popular cryptocurrency? Search no more!

Installation

Add this line to your application's Gemfile:

gem 'coinpayments'

And then execute:

$ bundle

Or install it yourself as:

$ gem install coinpayments

Configuration

Before using this gem you will have to create an account on Coinpayments website. After that you can access your Merchant ID and generate public/private API key pair needed for this gem to work.

If you are using Rails, simply generate a new config file, like so:

$ rails generate coinpayments:install

Configuration file can now be accessed at config/initializers/coinpayments.rb:

Coinpayments.configure do |config|
  config.merchant_id     = ''
  config.public_api_key  = ''
  config.private_api_key = ''
  config.secret_phrase   = ''
end

Usage

Coinpayments is a singleton class with method names mimicking the command names of CP API.

Common required fields are automatically appended to each call. Other of the required parameters must be passed in as method attributes. You can add some optional parameters too.

For your convenience response fields can be accessed as method calls.

For example, to quickly access current BTC/USD exchange rate, use:

Coinpayments.rates.USD.rate_btc

Examples

  • Check current exchange rates:

Coinpayments.rates

  • Check for cryptocurrencies you accept on your account:

Coinpayments.rates(accepted: 1).delete_if { |_k, v| v["accepted"] == 0 }.keys

  • Create a transaction for $10 that must be payed using BTC, and display an address to the user:
transaction = Coinpayments.create_transaction(10, 'USD', 'BTC')
@address = transaction.address
  • You can recieve IPN callbacks after payments on API-generated addresses. Coinpayments server generates signature based on your secret phrase and row body of POST request to your custom API. You can easily compare signatures to verify callback using
Coinpayments.sign('IPN POST request row body')

Contributing

  1. Fork it ( https://github.com/Salet/coinpayments/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request