hellovoid / orangepay-php
Orangepay API 的 PHP 库。
1.0.0
2018-06-05 15:01 UTC
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^4.7
This package is not auto-updated.
Last update: 2024-09-19 10:08:11 UTC
README
Orangepay PHP API 客户端库
这是 Orangepay API 的客户端库。
安装
使用 Composer 安装库。如果您不熟悉 Composer 或一般依赖管理器,请阅读 Composer 文档。
composer require hellovoid/orangepay-php
身份验证
使用 API 密钥访问您的 Orangepay 账户。
use Hellovoid\Orangepay\Client; use Hellovoid\Orangepay\Configuration; $client = \Hellovoid\Orangepay\Client::create( \Hellovoid\Orangepay\Configuration::apiKey( $apiKey, $apiUrl ) );
响应
每个成功的请求都会返回解码后的 JSON 数组。
异常
建议在出现问题时处理异常。示例
use Hellovoid\Orangepay\Client; use Hellovoid\Orangepay\Configuration; use Hellovoid\Orangepay\Exception\UnauthorizedException; use Hellovoid\Orangepay\Exception\ValidationException; use Hellovoid\Orangepay\Exception\NotFoundException; use Hellovoid\Orangepay\Exception\RateLimitException; use Hellovoid\Orangepay\Exception\InternalServerException; use Hellovoid\Orangepay\Exception\HttpException; $client = \Hellovoid\Orangepay\Client::create( \Hellovoid\Orangepay\Configuration::apiKey( $apiKey, $apiUrl ) ); try { $charge = $client->initializeCharge([ 'amount' => 10.00, 'currency' => 'USD', 'pay_method' => 'card', 'description' => 'Test description', 'reference_id' => 'my_unique_reference_id', 'email' => 'client@domain.ltd', ]); } catch (UnauthorizedException $exception) { } catch (ValidationException $exception) { } catch (NotFoundException $exception) { } catch (RateLimitException $exception) { } catch (InternalServerException $exception) { } catch (HttpException $exception) { }
检索钱包余额 #ref
$client->getBalance();
费用 #ref
列出费用
检索每页最多 200 项的费用分页。
$client->getCharges([ 'pay_method' => 'card', 'start_date' => '2018-01-01', 'end_date' => '2018-01-02', ]);
费用详情 #ref
检索费用详情
$client->getCharge($chargeId);
初始化 #ref
创建付款发票。
$client->initializeCharge([ 'amount' => 10.00, 'currency' => 'USD', 'pay_method' => 'card', 'description' => 'Test description', 'reference_id' => 'my-unique-reference-id', 'email' => 'client@domain.ltd', 'return_success_url' => 'https://my-site.ltd/payment-gateway-success', 'return_error_url' => 'https://my-site.ltd/payment-gateway-error', 'callback_url' => 'https://my-site.ltd/payment-gateway-callback', ]);
退款 #ref
创建退款请求
以付款货币返回指定金额给付款人。
$client->refund([ 'charge_id' => '1499ae90-f860-11e6-a8b6-e74ae337c2e8', 'amount' => 10.00 ]);
转账
列出转账
检索每页最多 200 项的转账分页。
$client->getTransfers([ 'pay_method' => 'card', 'start_date' => '2018-01-01', 'end_date' => '2018-01-02', ]);
转账详情 #ref
检索转账详情
$client->getTransfer($transferId);
转账到卡片 #ref
$client->transferToCard([ 'reference_id' => 'my-unique-reference-id', // can be used as [#idempotency key](https://en.wikipedia.org/wiki/Idempotence) 'amount' => 10.00, 'currency' => 'USD', 'description' => 'Test description', 'name' => 'John Doe', 'card_number' => '4111111111111111', 'card_expiry_month' => '02', 'card_expiry_year' => '19', 'address_country' => 'US', 'address_city' => 'New York', 'address_line1' => '123 East 169th Street Apt. 2A Bronx, NY 10456', 'callback_url' => 'https://my-site.ltd/payment-gateway-callback' ]);
有机会使用 charge_id 将转账给之前已付款的付款人
$client->transferToCard([ 'charge_id' => '1173157c-db4d-11e7-9296-cec278b6b50a', 'reference_id' => 'my-unique-reference-id', 'amount' => 10.00, 'currency' => 'USD', 'description' => 'Test description', 'address_country' => 'US', 'address_city' => 'New York', 'address_line1' => '123 East 169th Street Apt. 2A Bronx, NY 10456', ]);
转账到比特币地址 #ref
金额必须以 satoshi 表示(1 BTC = 100,000,000 satoshis)。
$client->transferToBitcoinAddress([ 'reference_id' => 'my-unique-reference-id', 'amount' => 10000000, // 0.1 BTC 'currency' => 'BTC', 'description' => 'Test description', 'address' => '3**********FR', ]);
汇率 #ref
检索汇率
$client->rates('BTC-EUR');