billbee / billbee-api
官方Billbee API SDK for PHP
v2.2.1
2023-10-10 09:50 UTC
Requires
- php-64bit: ^7.3 || ^8.0
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: ^7.4.0
- jms/serializer: ^3.18
- psr/log: ^1.1.0 || ^2.0.0 || ^3.0.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- phpstan/phpstan: ^1.8.2
- phpunit/phpunit: ^9.4.1
This package is auto-updated.
Last update: 2024-09-10 11:55:50 UTC
README
Billbee API
使用此包,您可以在您的应用程序中实现官方Billbee API。
先决条件
- 要访问Billbee API,您需要一个API密钥。要获取API密钥,请发送邮件至support@billbee.de,并给我们发送一条简短的说明,说明您正在构建什么。
- 必须在账户中激活API模块(https://app.billbee.io/app_v2/settings/api/general)
安装
您可以将此包作为composer依赖项添加
$ composer require billbee/billbee-api
官方API文档
https://app.billbee.io/swagger/ui/index
用法
简单实例化一个客户端对象以访问API
<?php use BillbeeDe\BillbeeAPI\Client; $user = 'Your Billbee username'; $apiPassword = 'Your Billbee API Password'; // https://app.billbee.io/de/settings/api $apiKey = 'Your Billbee API Key'; $client = new Client($user, $apiPassword, $apiKey);
示例:检索产品列表
<?php use BillbeeDe\BillbeeAPI\Client; $user = 'Your Billbee username'; $apiPassword = 'Your Billbee API Password'; // https://app.billbee.io/de/settings/api $apiKey = 'Your Billbee API Key'; $client = new Client($user, $apiPassword, $apiKey); /** @var \BillbeeDe\BillbeeAPI\Response\GetProductsResponse $productsResponse */ $productsResponse = $client->products()->getProducts($page = 1, $pageSize = 10); /** @var \BillbeeDe\BillbeeAPI\Model\Product $product */ foreach ($productsResponse->data as $product) { echo sprintf("Id: %s, SKU: %s, Price: %f\n", $product->id, $product->sku, $product->price); }
示例:批量请求
<?php use BillbeeDe\BillbeeAPI\Client; use BillbeeDe\BillbeeAPI\Response; $user = 'Your Billbee username'; $apiPassword = 'Your Billbee API Password'; // https://app.billbee.io/de/settings/api $apiKey = 'Your Billbee API Key'; $client = new Client($user, $apiPassword, $apiKey); $client->enableBatchMode(); $client->products()->getProducts(1, 1); # Adds the request to the batch pool / returns null $client->orders()->getOrders(1, 1); # Adds the request to the batch pool / returns null $client->events()->getEvents(1, 1); # Adds the request to the batch pool / returns null $results = $client->executeBatch(); # Results contain all responses in the added order /** @var Response\GetProductsResponse $productsResult */ $productsResult = $results[0]; /** @var Response\GetOrdersResponse $ordersResult */ $ordersResult = $results[1]; /** @var Response\GetEventsResponse $eventsResult */ $eventsResult = $results[2];
测试
运行phpunit
贡献
请随意fork存储库并创建pull-requests