globalis / chargebee-php-sdk
Chargebee API PHP 客户端(适用于 API 版本 2 和产品目录版本 2.0)
1.0.2
2022-02-18 10:05 UTC
Requires
- php: ^7.4 || ^8.0 || ^8.1
- globalis/wp-cubi-helpers: ^1.0
- http-interop/http-factory-guzzle: ^1.0
- league/event: ^3.0
- php-http/client-common: ^2.1
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.7
- php-http/message: ^1.7
- php-http/message-factory: ^1.0
- php-http/multipart-stream-builder: ^1.0
- psr/http-client: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.4.1
- guzzlehttp/psr7: ^2.1.0
- php-http/guzzle7-adapter: ^1.0.0
- php-http/mock-client: ^1.3
- phpunit/phpunit: ^9.5.13
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2024-09-18 16:07:21 UTC
README
概述
此包提供了 Chargebee 订阅管理服务的 API 客户端。
它连接到以下版本的 Chargebee REST API
- Chargebee API : 版本 2 (查看官方 API 文档)
- 产品目录: 版本 2.0 (查看官方 API 文档)
如果你的 Chargebee 网站使用的是产品目录版本 1.0,你可以使用我们的 product_catalog_v1 分支。它的工作方式大致相同,但请注意,它既未维护也未编写文档。
安装
composer require globalis/chargebee-php-sdk php-http/guzzle7-adapter
基本用法
<?php use Globalis\Chargebee\Client as ChargebeeClient; use Http\Client\Exception\HttpException; $chargebee = new ChargebeeClient('{site}', '{site_api_key}'); try { // List last created subscription: $response = $chargebee->subscription()->list([ "limit" => 1, "sort_by[desc]" => "created_at", "status[is]" => "active", ]); } catch (HttpException $e) { // Get API error details: $response = json_decode($e->getResponse()->getBody(), true); echo sprintf("Error: (%s) %s", $response["api_error_code"], $response["message"]); }
事件
API 客户端在 API 响应上产生事件。你可以监听这些事件并在它们上连接任何可调用函数。
这些事件实现了来自 league/event PSR-14 包的 Psr\EventDispatcher\StoppableEventInterface。
<?php use Globalis\Chargebee\Client as Chargebee; use Globalis\Chargebee\Events\EventChargebeeApiResponseSuccess as EventResponseSuccess; use Globalis\Chargebee\Events\EventChargebeeApiResponseError as EventResponseError; Chargebee::onApiResponseSuccess(function (EventResponseSuccess $event) { // $event contains data about the API request and response // do something }); Chargebee::onApiResponseError(function (EventResponseError $event) { // $event contains data about the API request and response // do something });
集成
- WordPress: globalis/chargebee-php-sdk-wp 将 PSR-14 事件转换为 WordPress 钩子,并连接到 query-monitor 以调试你的 API 请求。
历史
此项目是基于 nathandunn/chargebee-php-sdk 包的分支。我们将其分支以便我们可以实现 产品目录 2.0 更改。我们还添加了 PSR-14 事件,并修复了一些错误。
文档
我们还没有完整的文档。
你可以在原始的 README.md 和 wiki 上找到有关使用 HTTPlug 和 HttpClient.Builder 的更多详细信息。