Coder Social home page Coder Social logo

uphold-sdk-php's Introduction

Uphold SDK for PHP

Latest Version Build Status Code Climate Test Coverage License

Uphold 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 Uphold SDK for PHP provides an easy way for developers to integrate PHP applications with the Uphold API.

Requirements

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

Installation

Standalone

Grab the latest version of the library:

$ git clone https://github.com/seegno/uphold-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/uphold-sdk-php": "~5.0"
    }
}

Basic usage

In order to learn more about the Uphold API, please check out the API documentation.

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

Create a Personal Access Token

$ php lib/Uphold/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.

Authorize user

require_once 'vendor/autoload.php';

use Uphold\UpholdClient as Client;

// Initialize the client.
$client = new Client(array(
  'client_id' => 'APPLICATION_CLIENT_ID',
  'client_secret' => 'APPLICATION_CLIENT_SECRET',
));

// Authorize user using the code parameter from the application redirect url.
$user = $client->authorizeUser('CODE');

// Get the Bearer token.
$bearer = $user->getClient()->getOption('bearer');

Get authenticated user

require_once 'vendor/autoload.php';

use Uphold\UpholdClient as Client;

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

// Get user.
$user = $client->getUser('AUTHORIZATION_TOKEN');

Get user balances

require_once 'vendor/autoload.php';

use Uphold\UpholdClient as Client;

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

// Get user.
$user = $client->getUser('AUTHORIZATION_TOKEN');

// 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 Uphold\UpholdClient as Client;

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

// Get user.
$user = $client->getUser('AUTHORIZATION_TOKEN');

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

Create new card

require_once 'vendor/autoload.php';

use Uphold\UpholdClient as Client;

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

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

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

The above produces the output shown below:

Uphold\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 rates

require_once 'vendor/autoload.php';

use Uphold\UpholdClient as Client;

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

// Get rates (public endpoint).
$rates = $client->getRates();

Or you could get rates for a specific currency:

// Get rates for BTC.
$rates = $client->getRatesByCurrency('BTC');

The above produces the output shown below:

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

    [1] => Uphold\Model\Rate 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 Uphold\UpholdClient as Client;

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

// Get user.
$user = $client->getUser('AUTHORIZATION_TOKEN');

// Get a specific card by id.
$card = $user->getCardById('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:

Uphold\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 \Uphold\UpholdClient as Client;

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

// Get all public transactions (public endpoint).
$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 \Uphold\UpholdClient as Client;

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

// Get the reserve summary of all the obligations and assets within it (public endpoint).
$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...
}

Tests

Run the tests from the root directory:

$ ./vendor/bin/phpunit

You can find PHPUnit documentation here.

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 uphold-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.

uphold-sdk-php's People

Contributors

arevalomalina avatar byrnereese avatar fixe avatar joaonice avatar kratos-42 avatar nunofgs avatar nunorafaelrocha avatar ruimarinho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uphold-sdk-php's Issues

Issue when adding to composer.

: composer update

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- The requested package seegno/uphold-sdk-php could not be found in any version, there may ypo in the package name.

Potential causes:

Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

I wasn't sure if there was an issue or if the package is available via composer. Thanks!

Bad response from createCard()

Hi, I do not know why, but I am getting a different response from Uphold.

When I use createCard() method, I get this response:

[{"params":[],"normalized":[{"available":"0.00","balance":"0.00","currency":"USD"}],"wire":[{"accountName":"UPHOLD LDA","address":{"line1":"Rua Tenente Valadim 284","line2":"4100-476 Porto, Portugal"},"currency":"EUR","bic":"BBPIPTPL","iban":"PT50 0010 0000 5108 8690 0026 9","name":"Banco BPI"},{"accountName":"UPHOLD LDA","address":{"line1":"Rua Tenente Valadim 284","line2":"4100-476 Porto, Portugal"},"bic":"BBPIPTPL","currency":"GBP","iban":"PT50 0010 9999 5108 8690 6028 9","name":"Banco BPI"},{"accountName":"Uphold HQ, Inc.","accountNumber":"1463721","address":{"line1":"900 Broad Street","line2":"Newark, NJ 07102"},"bic":"CNNJUS33","currency":"USD","name":"City National Bank of New Jersey"}]}]

What can I do @nunorafaelrocha ? Thanks

Error in example: "Create and commit a new transaction"

Hi, in Readme says getCardsById('ade869d8-7913-4f67-bb4d-72719f0a2be0'); but I think that it would say getCardById('ade869d8-7913-4f67-bb4d-72719f0a2be0'); (no s in getCardById).

It would be useful to add the possibility to get a card using its address too.

Add support for pagination

All collection endpoints will support Range Pagination Headers using Range & Content-Range entity-headers.

Model/User.php getTransactions() does not get transactions

object(Uphold\Paginator\Paginator)#91 (8) {
["client":protected]=>
object(Uphold\UpholdClient)#63 (3) {
["httpClient":"Uphold\UpholdClient":private]=>
object(Uphold\HttpClient\HttpClient)#64 (4) {
["client":protected]=>
object(GuzzleHttp\Client)#68 (5) {
["messageFactory":"GuzzleHttp\Client":private]=>
object(Uphold\HttpClient\Message\MessageFactory)#65 (3) {
["errorPlugin":"GuzzleHttp\Message\MessageFactory":private]=>
object(GuzzleHttp\Subscriber\HttpError)#66 (0) {
}
["redirectPlugin":"GuzzleHttp\Message\MessageFactory":private]=>
object(GuzzleHttp\Subscriber\Redirect)#67 (0) {
}
["customOptions":"GuzzleHttp\Message\MessageFactory":private]=>
array(0) {
}
}
["baseUrl":"GuzzleHttp\Client":private]=>
object(GuzzleHttp\Url)#69 (8) {
["scheme":"GuzzleHttp\Url":private]=>
string(5) "https"
["host":"GuzzleHttp\Url":private]=>
string(14) "api.uphold.com"
["port":"GuzzleHttp\Url":private]=>
NULL
["username":"GuzzleHttp\Url":private]=>
NULL
["password":"GuzzleHttp\Url":private]=>
NULL
["path":"GuzzleHttp\Url":private]=>
string(1) "/"
["fragment":"GuzzleHttp\Url":private]=>
NULL
["query":"GuzzleHttp\Url":private]=>
NULL
}
["defaults":"GuzzleHttp\Client":private]=>
array(5) {
["allow_redirects"]=>
bool(true)
["exceptions"]=>
bool(true)
["decode_content"]=>
bool(true)
["verify"]=>
bool(true)
["headers"]=>
array(1) {
["User-Agent"]=>
string(46) "Guzzle/5.3.0 curl/7.35.0 PHP/5.5.9-1ubuntu4.12"
}
}
["fsm":"GuzzleHttp\Client":private]=>
object(GuzzleHttp\RequestFsm)#77 (3) {
["handler":"GuzzleHttp\RequestFsm":private]=>
object(Closure)#76 (2) {
["static"]=>
array(2) {
["default"]=>
object(Closure)#75 (2) {
["static"]=>
array(2) {
["default"]=>
object(GuzzleHttp\Ring\Client\CurlHandler)#70 (4) {
["factory":"GuzzleHttp\Ring\Client\CurlHandler":private]=>
object(GuzzleHttp\Ring\Client\CurlFactory)#71 (0) {
}
["handles":"GuzzleHttp\Ring\Client\CurlHandler":private]=>
array(1) {
[4]=>
resource(4) of type (curl)
}
["ownedHandles":"GuzzleHttp\Ring\Client\CurlHandler":private]=>
array(1) {
[4]=>
bool(false)
}
["maxHandles":"GuzzleHttp\Ring\Client\CurlHandler":private]=>
int(5)
}
["streaming"]=>
object(GuzzleHttp\Ring\Client\StreamHandler)#74 (2) {
["options":"GuzzleHttp\Ring\Client\StreamHandler":private]=>
array(0) {
}
["lastHeaders":"GuzzleHttp\Ring\Client\StreamHandler":private]=>
NULL
}
}
["parameter"]=>
array(1) {
["$request"]=>
string(10) ""
}
}
["future"]=>
object(GuzzleHttp\Ring\Client\CurlMultiHandler)#72 (6) {
["factory":"GuzzleHttp\Ring\Client\CurlMultiHandler":private]=>
object(GuzzleHttp\Ring\Client\CurlFactory)#73 (0) {
}
["selectTimeout":"GuzzleHttp\Ring\Client\CurlMultiHandler":private]=>
int(1)
["active":"GuzzleHttp\Ring\Client\CurlMultiHandler":private]=>
NULL
["handles":"GuzzleHttp\Ring\Client\CurlMultiHandler":private]=>
array(0) {
}
["delays":"GuzzleHttp\Ring\Client\CurlMultiHandler":private]=>
array(0) {
}
["maxHandles":"GuzzleHttp\Ring\Client\CurlMultiHandler":private]=>
int(100)
}
}
["parameter"]=>
array(1) {
["$request"]=>
string(10) ""
}
}
["mf":"GuzzleHttp\RequestFsm":private]=>
object(Uphold\HttpClient\Message\MessageFactory)#65 (3) {
["errorPlugin":"GuzzleHttp\Message\MessageFactory":private]=>
object(GuzzleHttp\Subscriber\HttpError)#66 (0) {
}
["redirectPlugin":"GuzzleHttp\Message\MessageFactory":private]=>
object(GuzzleHttp\Subscriber\Redirect)#67 (0) {
}
["customOptions":"GuzzleHttp\Message\MessageFactory":private]=>
array(0) {
}
}
["maxTransitions":"GuzzleHttp\RequestFsm":private]=>
int(200)
}
["emitter":"GuzzleHttp\Client":private]=>
object(GuzzleHttp\Event\Emitter)#62 (2) {
["listeners":"GuzzleHttp\Event\Emitter":private]=>
array(0) {
}
["sorted":"GuzzleHttp\Event\Emitter":private]=>
array(0) {
}
}
}
["errorHandler":"Uphold\HttpClient\HttpClient":private]=>
object(Uphold\HttpClient\Handler\ErrorHandler)#78 (1) {
["options":"Uphold\HttpClient\Handler\ErrorHandler":private]=>
array(8) {
["message_factory"]=>
object(Uphold\HttpClient\Message\MessageFactory)#65 (3) {
["errorPlugin":"GuzzleHttp\Message\MessageFactory":private]=>
object(GuzzleHttp\Subscriber\HttpError)#66 (0) {
}
["redirectPlugin":"GuzzleHttp\Message\MessageFactory":private]=>
object(GuzzleHttp\Subscriber\Redirect)#67 (0) {
}
["customOptions":"GuzzleHttp\Message\MessageFactory":private]=>
array(0) {
}
}
["api_version"]=>
string(2) "v0"
["base_url"]=>
string(23) "https://api.uphold.com/"
["debug"]=>
bool(false)
["timeout"]=>
int(10)
["user_agent"]=>
string(67) "uphold-sdk-php {version} (https://github.com/seegno/uphold-sdk-php)"
["version"]=>
string(5) "4.0.0"
["bearer"]=>
string(40) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
}
["headers":protected]=>
array(0) {
}
["options":protected]=>
array(8) {
["message_factory"]=>
object(Uphold\HttpClient\Message\MessageFactory)#65 (3) {
["errorPlugin":"GuzzleHttp\Message\MessageFactory":private]=>
object(GuzzleHttp\Subscriber\HttpError)#66 (0) {
}
["redirectPlugin":"GuzzleHttp\Message\MessageFactory":private]=>
object(GuzzleHttp\Subscriber\Redirect)#67 (0) {
}
["customOptions":"GuzzleHttp\Message\MessageFactory":private]=>
array(0) {
}
}
["api_version"]=>
string(2) "v0"
["base_url"]=>
string(23) "https://api.uphold.com/"
["debug"]=>
bool(false)
["timeout"]=>
int(10)
["user_agent"]=>
string(67) "uphold-sdk-php {version} (https://github.com/seegno/uphold-sdk-php)"
["version"]=>
string(5) "4.0.0"
["bearer"]=>
string(40) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
}
["reserve":"Uphold\UpholdClient":private]=>
NULL
["options":"Uphold\UpholdClient":private]=>
array(7) {
["api_version"]=>
string(2) "v0"
["base_url"]=>
string(23) "https://api.uphold.com/"
["debug"]=>
bool(false)
["timeout"]=>
int(10)
["user_agent"]=>
string(67) "uphold-sdk-php {version} (https://github.com/seegno/uphold-sdk-php)"
["version"]=>
string(5) "4.0.0"
["bearer"]=>
string(40) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
}
["count":protected]=>
NULL
["model":protected]=>
string(24) "Uphold\Model\Transaction"
["path":protected]=>
string(16) "/me/transactions"
["parameters":protected]=>
array(0) {
}
["headers":protected]=>
array(0) {
}
["offset":protected]=>
int(0)
["limit":protected]=>
NULL
}

I'm not sure why it's not working. I have tested with card transactions as well and have the same issue. I can verify that transactions do exist and that they have been commited and filled. Please let me know if you need anything else. (I've removed my bearer key)

FATAL Error

I am getting this error at Mamp php 5.5.23
PHP Fatal error: Class 'GuzzleHttp\Message\MessageFactory' not found in ..... /lib/Uphold/HttpClient/Message/MessageFactory.php on line 13

I have tried "composer install -o" but didn't fix it. Could someone help me out?

Implement access token on user model

We need to move the place where we keep the access token. Instead of saving the access token on the BitreserveClient, we need to keep the access token on the user model.

That way we can only use one instance of BitreserveClient with multiple users and the access token will be in a place where it makes more sense.

PHP Fatal error:

I am now getting this:

PHP Fatal error: Uncaught exception 'Uphold\Exception\ConnectException' with message 'cURL error 35: error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error' in /lib/Uphold/HttpClient/Handler/ErrorHandler.php:49
Stack trace:
#0 lib/Uphold/HttpClient/HttpClient.php(142): Uphold\HttpClient\Handler\ErrorHandler->onException(Object(GuzzleHttp\Exception\ConnectException))
#1 lib/Uphold/HttpClient/HttpClient.php(87): Uphold\HttpClient\HttpClient->request('v0/ticker', NULL, 'GET', Array, Array)
#2 /lib/Uphold/UpholdClient.php(313): Uphold\HttpClient\HttpClient->get('v0/ticker', Array, Array)
#3 /lib/Uphold/UpholdClient.php(152): Uphold\UpholdClient->get('/ticker')
#4 /examples/Ticker.php(11): Uphold\UpholdClient->getRates()
#5 {main}

th in /lib/Uphold/HttpClient/Handler/ErrorHandler.php on line 49

Guzzle 6 support

  • seegno/uphold-sdk-php 5.0.1 requires guzzlehttp/guzzle ~5.1 -> satisfiable by guzzlehttp/guzzle[5.1.0, 5.2.0, 5.3.0, 5.3.1, 5.3.2, 5.3.x-dev] but these conflict with your requirements or minimum-stability.

cURL error 35: SSL connect error

Hi, I need help please! I am getting this error and I don't know how to solve it. Thanks

in ErrorHandler.php line 49
at ErrorHandler->onException(object(ConnectException)) in HttpClient.php line 142
at HttpClient->request('v0/me', null, 'GET', array('Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => 'uphold-sdk-php v4.0.3 (https://github.com/seegno/uphold-sdk-php)', 'Authorization' => 'Bearer '), array('query' => array())) in HttpClient.php line 87
at HttpClient->get('v0/me', array(), array('Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => 'uphold-sdk-php v4.0.3 (https://github.com/seegno/uphold-sdk-php)', 'Authorization' => 'Bearer ')) in UpholdClient.php line 313
at UpholdClient->get('/me') in UpholdClient.php line 228

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.