Coder Social home page Coder Social logo

bitreserve-sdk-php's Introduction

Bitreserve SDK for PHP

Latest Version Build Status Code Climate Test Coverage License

Bitreserve is a next generation money service business that shields you from bitcoin volatility by enabling you to hold bitcoin as the money you use every day.

The Bitreserve SDK for PHP provides an easy way for developers to integrate PHP applications with the Bitreserve API.

Requirements

  • PHP >= 5.4.4 with the cURL extension.
  • Guzzle library.

Installation

Standalone

Grab the latest version of the library:

$ git clone https://github.com/seegno/bitreserve-sdk-php.git

Install composer:

$ curl -s https://getcomposer.org/installer | php

Install the library dependencies:

$ php composer.phar install

Require the autoloader file generated by composer:

require 'vendor/autoload.php';

Integrating with another project using composer

Require the library package as a dependency:

{
    "require": {
        "seegno/bitreserve-sdk-php": "2.0.*"
    }
}

Basic usage

In order to learn more about the Bitreserve API, please check out the developer website.

First, create a Personal Access Token (PAT) using the command described below.

Create a Personal Access Token

$ php lib/Bitreserve/console.php tokens:create

Then, create a new instance of the Client class with token. Take a look at the following examples and explore more on the examples directory.

Get authenticated user

require_once 'vendor/autoload.php';

use Bitreserve\BitreserveClient as Client;

// Initialize the client.
$client = new Client('AUTHORIZATION_TOKEN');

// Get the current user.
$user = $client->getUser();

Get user balances

require_once 'vendor/autoload.php';

use Bitreserve\BitreserveClient as Client;

// Initialize the client.
$client = new Client('AUTHORIZATION_TOKEN');

// Get the current user.
$user = $client->getUser();

// Get user balances for all currencies.
$balances = $user->getBalances();

You could get user total balance:

// Get user total balance.
$balance = $user->getTotalBalance();

The above produces the output shown below:

Array
(
    [amount] => 3.14
    [currency] => BTC
)

Get user cards

require_once 'vendor/autoload.php';

use Bitreserve\BitreserveClient as Client;

// Initialize the client.
$client = new Client('AUTHORIZATION_TOKEN');

// Get the current user.
$user = $client->getUser();

// Get current user cards.
$cards = $user->getCards();

Create new card

require_once 'vendor/autoload.php';

use Bitreserve\BitreserveClient as Client;

// Initialize the client.
$client = new Client('AUTHORIZATION_TOKEN');

// Get the current user.
$user = $client->getUser();

// Create a new 'BTC' card.
$card = $user->createCard('My new card', 'BTC');

The above produces the output shown below:

Bitreserve\Model\Card Object
(
    [id:protected] => ade869d8-7913-4f67-bb4d-72719f0a2be0
    [address:protected] => Array
        (
            [bitcoin] => 1GpBtJXXa1NdG94cYPGZTc3DfRY2P7EwzH
        )

    [addresses:protected] => Array
        (
            [0] => Array
                (
                    [id] => 1GpBtJXXa1NdG94cYPGZTc3DfRY2P7EwzH
                    [network] => bitcoin
                )

        )

    [available:protected] => 0.00
    [balance:protected] => 0.00
    [currency:protected] => BTC
    [label:protected] => My new card
    [lastTransactionAt:protected] =>
    [transactions:protected] =>
    [settings] => Array
        (
            [position] => 10
        )
)

Get ticker

require_once 'vendor/autoload.php';

use Bitreserve\BitreserveClient as Client;

// Initialize the client. In this case, we don't need an
// AUTHORIZATION_TOKEN because the Ticker endpoint is public.
$client = new Client();

// Get tickers.
$tickers = $client->getTicker();

Or you could get a ticker for a specific currency:

// Get tickers for BTC.
$tickers = $client->getTickerByCurrency('BTC');

The above produces the output shown below:

Array
(
    [0] => Bitreserve\Model\Ticker Object
        (
            [ask:protected] => 1
            [bid:protected] => 1
            [currency:protected] => BTC
            [pair:protected] => BTCBTC
        )

    [1] => Bitreserve\Model\Ticker Object
        (
            [ask:protected] => 234.89
            [bid:protected] => 234.8
            [currency:protected] => USD
            [pair:protected] => BTCUSD
        )
)

Create and commit a new transaction

require_once 'vendor/autoload.php';

use Bitreserve\BitreserveClient as Client;

// Initialize the client.
$client = new Client('AUTHORIZATION_TOKEN');

// Get the current user.
$user = $client->getUser();

// Get a specific card by id.
$card = $user->getCardsById('ade869d8-7913-4f67-bb4d-72719f0a2be0');

// Create a new transaction.
$transaction = $card->createTransaction('[email protected]', '2.0', 'BTC');

// Commit the transaction.
$transaction->commit();

The above produces the output shown below:

Bitreserve\Model\Transaction Object
(
    [id:protected] => a97bb994-6e24-4a89-b653-e0a6d0bcf634
    [createdAt:protected] => 2015-01-30T11:46:11.439Z
    [denomination:protected] => Array
        (
            [pair] => BTCBTC
            [rate] => 1
            [amount] => 2.0
            [currency] => BTC
        )
    [destination:protected] => <snip>
    [message:protected] =>
    [origin:protected] => <snip>
    [params:protected] => <snip>
    [refundedById:protected] =>
    [status:protected] => completed
    [type] => transfer
)

Get all public transactions

require_once 'vendor/autoload.php';

use \Bitreserve\BitreserveClient as Client;

// Initialize the client. In this case, we don't need an
// AUTHORIZATION_TOKEN because the Ticker endpoint is public.
$client = new Client();

// Get all public transactions.
$pager = $client->getReserve()->getTransactions();

// Get next page of transactions.
$transactions = $pager->getNext();

Or you could get a specific public transaction:

// Get one public transaction.
$transaction = $client->getReserve()->getTransactionById('a97bb994-6e24-4a89-b653-e0a6d0bcf634');

Get reserve status

require_once 'vendor/autoload.php';

use \Bitreserve\BitreserveClient as Client;

// Initialize the client. In this case, we don't need an
// AUTHORIZATION_TOKEN because the Ticker endpoint is public.
$client = new Client();

// Get the reserve summary of all the obligations and assets within it.
$statistics = $client->getReserve()->getStatistics();

Pagination

Some endpoints will return a paginator. Here is some examples on how you can handle it.

// Get public transactions.
$pager = $client->getReserve()->getTransactions();

// Check whether the paginator has a valid next page.
while($pager->hasNext()) {
    // Get next page with results.
    $transactions = $pager->getNext();

    // Do something...
}

Contributing & Development

Contributing

Found a bug or want to suggest something? Take a look first on the current and closed issues. If it is something new, please submit an issue.

Develop

It will be awesome if you can help us evolve bitreserve-sdk-php. Want to help?

  1. Fork it.
  2. php composer.phar install.
  3. Hack away.
  4. Run the tests: phpunit.
  5. Create a Pull Request.

bitreserve-sdk-php's People

Contributors

fixe avatar nunofgs avatar nunorafaelrocha avatar ruimarinho avatar

Watchers

 avatar

Forkers

byrnereese

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.