chibka/ccloud
Composer 安装命令:
composer require chibka/ccloud
包简介
A PHP library which implements the complete functionality of v2 of the The Currency Cloud API.
README 文档
README
Currencycloud API v2 PHP client
Version: 0.14.0
This is the official PHP SDK for the Currencycloud API. Additional documentation for each API endpoint can be found at developer.currencycloud.com.
If you have any queries or you require support, please contact our sales team at sales@currencycloud.com. Please quote your login id in any correspondence as this makes it simpler for us to locate your account and give you the support you need.
Prerequisites
Composer (optional, but highly recommended)
CurrencyCloud-PHP is a Composer project. While using Composer is not strictly required, it will be far easier to simply make use of Composer to do the dependency management and autoloading for you.
Supported PHP version
This library aims to support and is tested against PHP 5.5 and greater.
Installation
The recommended way to install Currencycloud SDK is through Composer.
If you do not have composer installed check Composer installation guide.
Assuming you have composer installed globally you can require Currencycloud SDK into you project by executing:
composer require currency-cloud/client
After installing, you need to require Composer's autoloader if you did not require it before:
require 'vendor/autoload.php';
Usage
You can register for demo API key at developer.currencycloud.com.
An example in PHP 5.5:
use CurrencyCloud\CurrencyCloud; use CurrencyCloud\Session; require_once __DIR__ . '/vendor/autoload.php'; $session = new Session( Session::ENVIRONMENT_DEMONSTRATION, '<user-id>', '<api-key>' ); $client = CurrencyCloud::createDefault($session); //Authenticate $client->authenticate() ->login(); //Get available currencies $currencies = $client->reference() ->availableCurrencies(); echo "Supproted currencies:\n"; foreach ($currencies as $currency) { printf( "Currency: %s; Code: %s; Decimal places: %d\n", $currency->getName(), $currency->getCode(), $currency->getDecimalPlaces() ); } echo "Balances:\n"; //Find balances $balances = $client->balances() ->find(); foreach ($balances->getBalances() as $balance) { printf( "Balance ID: %s; Currency: %s; Amount: %s\n", $balance->getId(), $balance->getCurrency(), $balance->getAmount() ); } //Close session $client->authenticate()->close();
For a slightly longer example, see cook-book.php, which is an implementation of the Cookbook from the documentation.
Common Patterns
Reusing client for multiple requests
Authentication tokens are long-livedand are meant to be reused for multiple requests. This will improve performance of calls through the api.
On Behalf Of
If you want to make calls on behalf of another user (e.g. someone who is your end-client), you can execute certain commands 'on behalf of' the user's contact id. Here is an example:
$client->onBehalfOf('c6ece846-6df1-461d-acaa-b42a6aa74045', function (CurrencyCloud $client) { $balances = $client->balances() ->find(); foreach ($balances->getBalances() as $balance) { printf( "Balance ID: %s; Currency: %s; Amount: %s\n", $balance->getId(), $balance->getCurrency(), $balance->getAmount() ); } });
Each of the above transactions will be executed in scope of the limits for that contact and linked to that contact. Note that the real user who executed the transaction will also be stored.
Errors
When an error occurs in the API, the library aims to give us much information
as possible. A CurrencyCloudException will be thrown that contains much useful information
that you can access via its methods.
When the exception converted to string, it will provide information such as the following:
BadRequestException --- platform: 'PHP 5.6.14-1+deb.sury.org~trusty+1' request: parameters: { } verb: get url: 'https://devapi.currencycloud.com/v2/rates/detailed?buy_currency=EUR&sell_currency=GBP&fixed_side=buy&amount=10000.00' response: status_code: 400 date: 'Sun, 06 Nov 2015 18:22:47 GMT' request_id: '2915002181730358306' errors: - field: base code: rate_could_not_be_retrieved message: 'Rate could not be retrieved' params: { }
This is split into 5 sections:
- Error Type: In this case
BadRequestExceptionrepresents an HTTP 400 error - Platform: The PHP implementation that was used in the client
- Request: Details about the HTTP request that was made, e.g. the POST parameters
- Response: Details about the HTTP response that was returned, e.g. HTTP status code
- Errors: A list of errors that provide additional information
The final section contains valuable information:
- Field: The parameter that the error is linked to
- Code: A code representing this error
- Message: A human readable message that explains the error
- Params: A map that contains dynamic parts of the error message for building custom error messages
When troubleshooting API calls with Currencycloud support, including the full error in any correspondence can be very helpful.
Development
Testing
Test cases can be run with vendor/bin/phpunit.
Dependencies
Versioning
This project uses semantic versioning. You can safely express a dependency on a major version and expect all minor and patch versions to be backwards compatible.
Copyright
Copyright (c) 2018 Currencycloud. See LICENSE for details.
chibka/ccloud 适用场景与选型建议
chibka/ccloud 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 104 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 03 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「currency」 「cloud」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chibka/ccloud 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chibka/ccloud 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chibka/ccloud 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
UCloud Resource (Cloud) Storage SDK for PHP
The flysystem adapter for yandex disk rest api.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
非官方云小票机SDK,支持飞鹅云,芯烨云,易联云,快递100,映美云,中午云,佳博云,优声云,365智能云打印等
统计信息
- 总下载量: 104
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-06