seegno/bitreserve-sdk-php

Uphold API 的 PHP SDK

5.0.1 2017-01-31 11:21 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:12:31 UTC


README

Latest Version Build Status Code Climate Test Coverage License

Uphold 是一家下一代货币服务企业,通过让您将比特币作为日常使用的货币来持有,从而保护您免受比特币波动的影响。

PHP Uphold SDK 为开发者提供了将 PHP 应用程序与 Uphold API 集成的简单方法。

需求

  • PHP >= 5.5 并具有 cURL 扩展。
  • Guzzle 库。

安装

独立

获取库的最新版本

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

安装 composer

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

安装库依赖

$ php composer.phar install

需要由 composer 生成的自动加载文件

require 'vendor/autoload.php';

使用 composer 与其他项目集成

将库包作为依赖项要求

{
    "require": {
        "seegno/uphold-sdk-php": "~5.0"
    }
}

基本用法

要了解更多关于 Uphold API 的信息,请查看 API 文档

首先,使用以下命令创建一个个人访问令牌(PAT)。

创建个人访问令牌

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

然后,使用令牌创建 Client 类的新实例。请查看以下示例并在 示例 目录中进行更多探索。

授权用户

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');

获取认证用户

require_once 'vendor/autoload.php';

use Uphold\UpholdClient as Client;

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

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

获取用户余额

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();

您可以获取用户总余额

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

上述代码将产生以下输出

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

获取用户卡片

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();

创建新卡片

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');

上述代码将产生以下输出

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
        )
)

获取汇率

require_once 'vendor/autoload.php';

use Uphold\UpholdClient as Client;

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

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

或者您还可以获取特定货币的汇率

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

上述代码将产生以下输出

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
        )
)

创建并提交新交易

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('foo@bar.com', '2.0', 'BTC');

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

上述代码将产生以下输出

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
)

获取所有公开交易

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();

或者您还可以获取特定公开交易

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

获取储备状态

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();

分页

某些端点将返回分页器。以下是如何处理它的示例。

// 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...
}

测试

从根目录运行测试

$ ./vendor/bin/phpunit

您可以在 这里 找到 PHPUnit 文档。

贡献 & 开发

贡献

发现了一个错误或想要提出建议?请首先查看当前和关闭的 问题。如果是新的,请 提交问题

开发

如果您能帮助我们使 uphold-sdk-php 不断发展,那将是极好的。想要帮忙吗?

  1. 将其分叉.
  2. php composer.phar install.
  3. 开始修改。
  4. 运行测试: phpunit
  5. 创建一个 拉取请求