clicksports / lex-office-api
1.5.0
2024-07-24 21:16 UTC
Requires
- php: ^8.1
- ext-json: *
- guzzlehttp/psr7: ^2.0
- psr/http-client: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.57
- guzzlehttp/guzzle: ^7.8
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^10.5
- psalm/plugin-phpunit: ^0.19
- vimeo/psalm: ^5.24
Suggests
README
需求
PHP: >= 8.1
扩展
安装
composer
composer require sysix/lex-office-api
使用方法
基础
// store keys in .env file $apiKey = getenv('LEXOFFICE_API_KEY'); // in this example we are using guzzlehttp/guzzle package, it can be any PSR-18 HTTP Client // see: https://packagist.org.cn/providers/psr/http-client-implementation $httpClient = \GuzzleHttp\Client(); $api = new \Sysix\LexOffice\Api($apiKey, $httpClient);
优化您的 HTTP 客户端
此库只为 HTTP 客户端准备 \Psr\Http\Message\RequestInterface
并返回其响应。
错误检查、缓存和速率限制几乎不存在。您应该使用支持处理的 PSR-18 HTTP 客户端。
以下是一个使用 guzzlehttp/guzzle
、kevinrob/guzzle-cache-middleware
和 spatie/guzzle-rate-limiter-middleware
的示例
$apiKey = getenv('LEXOFFICE_API_KEY'); $stack = \GuzzleHttp\HandlerStack(); $stack->push(new \Kevinrob\GuzzleCache\CacheMiddleware\CacheMiddleware(), 'cache'); $stack->push(\Spatie\GuzzleRateLimiterMiddleware\RateLimiterMiddleware\RateLimiterMiddleware::perSecond(2)); $httpClient = \GuzzleHttp\Client(['handler' => $stack]); $api = new \Sysix\LexOffice\Api($apiKey, $httpClient);
端点
文章端点
/** @var \Sysix\LexOffice\Api $api */ $client = $api->article(); // filters $client->size = 100; $client->sortDirection = 'DESC'; $client->articleNumber = 'LXW-BUHA-2024-001'; $client->gtin = '9783648170632'; $client->type = 'PRODUCT'; // get a page $response = $client->getPage(0); // other methods $response = $client->get($entityId); $response = $client->create($data); $response = $client->update($entityId, $data); $response = $client->delete($entityId);
联系端点
$client = $api->contact(); // filters $client->size = 100; $client->email = 'john.doe@example.com'; $client->name = 'John Doe'; $client->number = 123456; $client->customer = true; $client->vendor = false; // get a page $response = $client->getPage(0); // other methods $response = $client->get($entityId); $response = $client->create($data); $response = $client->update($entityId, $data);
国家端点
$response = $api->country()->getAll();
信用笔记端点
$voucherList = $api->creditNote()->getVoucherListClient(); // see VoucherlistClient Documentation $response = $api->creditNote()->get($entityId); $response = $api->creditNote()->create($data); $response = $api->creditNote()->create($data, true); // finalized $response = $api->creditNote()->pursue($precedingSalesVoucherId, $data); $response = $api->creditNote()->pursue($precedingSalesVoucherId, $data, true); // finalized $response = $api->creditNote()->document($entityId); // get document ID $response = $api->creditNote()->document($entityId, true); // get file content $response = $api->creditNote()->document($entityId, true, 'image/*'); // accept only images
发货单端点
$voucherList = $api->deliveryNote()->getVoucherListClient(); // see VoucherlistClient Documentation $response = $api->deliveryNote()->get($entityId); $response = $api->deliveryNote()->create($data); $response = $api->deliveryNote()->pursue($precedingSalesVoucherId, $data); $response = $api->deliveryNote()->document($entityId); // get document ID $response = $api->deliveryNote()->document($entityId, true); // get file content $response = $api->deliveryNote()->document($entityId, true, 'image/*'); // accept only images
预付款发票端点
$voucherList = $api->downPaymentInvoice()->getVoucherListClient(); // see VoucherlistClient Documentation $response = $api->downPaymentInvoice()->get($entityId); $response = $api->downPaymentInvoice()->create($data); $response = $api->downPaymentInvoice()->document($entityId); // get document ID $response = $api->downPaymentInvoice()->document($entityId, true); // get file content $response = $api->downPaymentInvoice()->document($entityId, true, 'image/*'); // accept only images
催款单端点
$response = $api->dunning()->get($entityId); $response = $api->dunning()->pursue($precedingSalesVoucherId, $data); $response = $api->dunning()->document($entityId); // get document ID $response = $api->dunning()->document($entityId, true); // get file content $response = $api->dunning()->document($entityId, true, 'image/*'); // accept only images
事件订阅端点
$response = $api->event()->get($entityId); $response = $api->event()->create($data); $response = $api->event()->delete($entityId); $response = $api->event()->getAll();
文件端点
$response = $api->file()->upload($filePath, $voucherType); $response = $api->file()->get($entityId); // accept every file $response = $api->file()->get($entityId, 'image/*'); // accept only images $response = $api->file()->get($entityId, 'application/xml'); // get XRechung XML File (if possible)
发票端点
$voucherList = $api->invoice()->getVoucherListClient(); // see VoucherlistClient Documentation $response = $api->invoice()->get($entityId); $response = $api->invoice()->create($data); $response = $api->invoice()->create($data, true); // finalized $response = $api->invoice()->pursue($precedingSalesVoucherId, $data); $response = $api->invoice()->pursue($precedingSalesVoucherId, $data, true); // finalized $response = $api->invoice()->document($entityId); // get document ID $response = $api->invoice()->document($entityId, true); // get file content $response = $api->invoice()->document($entityId, true, 'image/*'); // accept only images $response = $api->invoice()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible)
订单确认端点
$voucherList = $api->orderConfirmation()->getVoucherListClient(); // see VoucherlistClient Documentation $response = $api->orderConfirmation()->get($entityId); $response = $api->orderConfirmation()->create($data); $response = $api->orderConfirmation()->pursue($precedingSalesVoucherId, $data); $response = $api->orderConfirmation()->document($entityId); // get document ID $response = $api->orderConfirmation()->document($entityId, true); // get file content $response = $api->orderConfirmation()->document($entityId, true, 'image/*'); // accept only images
支付端点
$response = $api->payment()->get($entityId);
支付条款端点
$response = $api->paymentCondition()->getAll();
发布类别端点
$response = $api->postingCategory()->getAll();
打印布局端点
$response = $api->printLayout()->getAll();
配置文件端点
$response = $api->profile()->get();
报价单端点
$voucherList = $api->quotation()->getVoucherListClient(); // see VoucherlistClient Documentation $response = $api->quotation()->get($entityId); $response = $api->quotation()->create($data); $response = $api->quotation()->create($data, true); // finalized $response = $api->quotation()->document($entityId); // get document ID $response = $api->quotation()->document($entityId, true); // get file content $response = $api->quotation()->document($entityId, true, 'image/*'); // accept only images
重复模板端点
$client = $api->recurringTemplate(); // filters $client->size = 100; $client->sortDirection = 'DESC'; $client->sortColumn = 'updatedDate'; // get a page $response = $client->getPage(0); // other methods $response = $api->recurringTemplate()->get($entityId);
优惠券端点
$response = $api->voucher()->get($entityId); $response = $api->voucher()->create($data); $response = $api->voucher()->update($entityId, $data); $response = $api->voucher()->document($entityId); // get document ID $response = $api->voucher()->document($entityId, true); // get file content $response = $api->voucher()->document($entityId, true, 'image/*'); // accept only images $response = $api->voucher()->document($entityId, true, 'application/xml'); // get XRechung XML File (if possible) $response = $api->voucher()->upload($entitiyId, $filepath);
优惠券列表端点
$client = $api->voucherlist(); $client->size = 100; $client->sortDirection = 'DESC'; $client->sortColumn = 'voucherNumber'; // filters required $client->types = [ 'salesinvoice', 'salescreditnote', 'purchaseinvoice', 'purchasecreditnote', 'invoice', 'downpaymentinvoice', 'creditnote', 'orderconfirmation', 'quotation' ]; $client->statuses = [ 'draft', 'open', 'paid', 'paidoff', 'voided', //'overdue', overdue can only be fetched alone 'accepted', 'rejected' ]; // filters optional $client->archived = true; $client->contactId = 'some-uuid-string'; $client->voucherDateFrom = new \DateTime('2023-12-01'); $client->voucherDateTo = new \DateTime('2023-12-01'); $client->createdDateFrom = new \DateTime('2023-12-01');; $client->createdDateTo = new \DateTime('2023-12-01'); $client->updatedDateFrom = new \DateTime('2023-12-01'); $client->updatedDateTo = new \DateTime('2023-12-01'); // get a page $response = $client->getPage(0);
工具
从成功和错误响应中获取 JSON
// can be possible null because the response body can be empty $json = \Sysix\LexOffice\Utils::getJsonFromResponse($response); // as object $json = \Sysix\LexOffice\Utils::getJsonFromResponse($response, true); // as associative array