-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0cf1c91
Showing
30 changed files
with
1,836 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Exbil Bilgisayar | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
# 💾 Lexoffice PHP API | ||
|
||
<div align="center"> | ||
<a href="https://www.exbil.net"><img src="https://vweb01.exbil.net/images/logos/ylx31Wjx3YY.png" width="546" alt="discord.js" /></a> | ||
</div> | ||
|
||
![visitors](https://visitor-badge.laobi.icu/badge?page_id=exbil.lexoffice-php-api) | ||
![](https://img.shields.io/badge/stable-v.1.0-informational?style=flat&logoColor=white&color=6aa6f8) | ||
![](https://img.shields.io/badge/license-MIT-informational?style=flat&logoColor=white&color=6aa6f8) | ||
|
||
# Getting Started | ||
### Requirements | ||
* [**PHP 7.4+**](https://www.php.net/downloads.php) | ||
* Extensions: [Composer](https://getcomposer.org/), [PHP-JSON](https://www.php.net/manual/en/book.json.php) | ||
|
||
# ⚒️ Install | ||
```bash | ||
composer require exbil/lexoffice-php-api | ||
``` | ||
|
||
# 📑 Usage | ||
|
||
Search for the official API Documentation [here](https://developers.lexoffice.io/docs/). | ||
You need an [API Key](https://app.lexoffice.de/addons/public-api) for that. | ||
|
||
### 🗃️ Basic | ||
|
||
```php | ||
$apiKey = getenv('LEX_OFFICE_API_KEY'); // store keys in .env file | ||
$api = new \exbil\LexOffice\LexOfficeClient($apiKey); | ||
``` | ||
|
||
### 🗃️ set cache | ||
|
||
```php | ||
// can be any PSR-6 compatibly cache handler | ||
// in this example we are using symfony/cache | ||
$cacheInterface = new \Symfony\Component\Cache\Adapter\FilesystemAdapter( | ||
'lexoffice', | ||
3600, | ||
__DIR__ . '/cache' | ||
); | ||
|
||
$api->setCacheInterface($cacheInterface); | ||
``` | ||
|
||
### 🔚 Contact Endpoint | ||
|
||
```php | ||
|
||
// get a page | ||
/** @var \exbil\LexOffice\LexOfficeClient $api */ | ||
$client = $api->contact(); | ||
|
||
$client->size = 100; | ||
$client->sortDirection = 'ASC'; | ||
$client->sortProperty = 'name'; | ||
|
||
// get a page | ||
$response = $client->getPage(0); | ||
|
||
//get all | ||
$response = $client->getAll(); | ||
|
||
// other methods | ||
$response = $client->get($entityId); | ||
$response = $client->create($data); | ||
``` | ||
|
||
### 🗺️ Country Endpoint | ||
```php | ||
$response = $api->country()->getAll(); | ||
``` | ||
|
||
### 🔚 Invoices Endpoint | ||
```php | ||
$response = $api->invoice()->getAll(); | ||
$response = $api->invoice()->get($entityId); | ||
$response = $api->invoice()->create($data); | ||
$response = $api->invoice()->document($entityId); // get document ID | ||
$response = $api->invoice()->document($entityId, true); // get file content | ||
``` | ||
|
||
### 🔚 Down Payment Invoices Endpoint | ||
```php | ||
$response = $api->downPaymentInvoice()->getAll(); | ||
$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 | ||
``` | ||
|
||
### 💵 Order Confirmation Endpoint | ||
```php | ||
$response = $api->orderConfirmation()->getAll(); | ||
$response = $api->orderConfirmation()->get($entityId); | ||
$response = $api->orderConfirmation()->create($data); | ||
$response = $api->orderConfirmation()->document($entityId); // get document ID | ||
$response = $api->orderConfirmation()->document($entityId, true); // get file content | ||
``` | ||
|
||
### 📃 Quotation Endpoint | ||
```php | ||
$response = $api->quotation()->getAll(); | ||
$response = $api->quotation()->get($entityId); | ||
$response = $api->quotation()->create($data); | ||
$response = $api->quotation()->document($entityId); // get document ID | ||
$response = $api->quotation()->document($entityId, true); // get file content | ||
``` | ||
|
||
### 📄 Voucher Endpoint | ||
```php | ||
$response = $api->voucher()->getAll(); | ||
$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 | ||
``` | ||
|
||
|
||
### 💵 Credit Notes Endpoint | ||
```php | ||
$response = $api->creditNote()->getAll(); | ||
$response = $api->creditNote()->get($entityId); | ||
$response = $api->creditNote()->create($data); | ||
$response = $api->creditNote()->document($entityId); // get document ID | ||
$response = $api->creditNote()->document($entityId, true); // get file content | ||
``` | ||
|
||
### 💵 Payment Endpoint | ||
```php | ||
$response = $api->payment()->get($entityId); | ||
``` | ||
|
||
### 💵 Payment Conditions Endpoint | ||
```php | ||
$response = $api->paymentCondition()->getAll(); | ||
``` | ||
|
||
### 🗂️ Posting Categories Endpoint | ||
```php | ||
$response = $api->postingCategory()->getAll(); | ||
``` | ||
|
||
### 🧑🏻 Profile Endpoint | ||
```php | ||
$response = $api->profile()->get(); | ||
``` | ||
|
||
### 📜 Recurring Templates Endpoint | ||
```php | ||
|
||
// get single entitiy | ||
$response = $api->recurringTemplate()->get($entityId); | ||
|
||
// use pagination | ||
$client = $api->recurringTemplate(); | ||
$client->size = 100; | ||
|
||
|
||
// get a page | ||
$response = $client->getPage(0); | ||
|
||
//get all | ||
$response = $client->getAll(); | ||
``` | ||
|
||
|
||
### 🔚 Voucherlist Endpoint | ||
```php | ||
$client = $api->voucherlist(); | ||
|
||
$client->size = 100; | ||
$client->sortDirection = 'DESC'; | ||
$client->sortColumn = 'voucherNumber'; | ||
$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' | ||
]; | ||
|
||
// get everything what we can, not recommend: | ||
//$client->setToEverything() | ||
|
||
// get a page | ||
$response = $client->getPage(0); | ||
|
||
//get all | ||
$response = $client->getAll(); | ||
``` | ||
|
||
### 📁 File Endpoint | ||
```php | ||
$response = $api->file()->upload($filePath, $voucherType); | ||
$response = $api->file()->get($entityId); | ||
``` | ||
|
||
|
||
### ⚒️ Get JSON from Response | ||
|
||
```php | ||
$json = $api->*()->getAsJson($response); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "exbil/lexoffice-php-api", | ||
"type": "library", | ||
"description": "Simple API Integration for Lex-Office", | ||
"keywords": [ | ||
"lex-office", | ||
"lexoffice", | ||
"rest", | ||
"api" | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"php": "^7.4 | ^8", | ||
"ext-json": "*", | ||
"ext-curl": "*", | ||
"guzzlehttp/guzzle": "^6.2 | ^7.0", | ||
"psr/cache": "^1.0 | ^2.0 | ^3.0" | ||
}, | ||
"require-dev": { | ||
"fzaninotto/faker": "^1.9.1", | ||
"phpunit/phpunit": "^9.0", | ||
"symfony/cache": "^5.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Exbil\\LexOffice\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Exbil\\LexOffice\\Tests\\": "tests/" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="true" | ||
colors="true" | ||
executionOrder="random" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
|
||
namespace Exbil\LexOffice; | ||
|
||
use GuzzleHttp\Psr7\MultipartStream; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
|
||
abstract class BaseClient implements ClientInterface | ||
{ | ||
protected string $resource; | ||
/** | ||
* @var LexOfficeClient $api | ||
*/ | ||
protected LexOfficeClient $api; | ||
|
||
public function __construct(LexOfficeClient $lexOffice) | ||
{ | ||
$this->api = $lexOffice; | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* @return ResponseInterface | ||
* @throws Exceptions\CacheException | ||
* @throws Exceptions\LexOfficeApiException | ||
*/ | ||
public function create(array $data) | ||
{ | ||
$api = $this->api->newRequest('POST', $this->resource); | ||
|
||
$api->request = $api->request->withBody($this->createStream($data)); | ||
|
||
return $api->getResponse(); | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* @param array $data | ||
* @return void | ||
* @throws Exception | ||
*/ | ||
public function update(string $id, array $data) | ||
{ | ||
throw new Exceptions\BadMethodCallException('method update is not defined for ' . $this->resource); | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* @return ResponseInterface | ||
* @throws Exceptions\CacheException | ||
* @throws Exceptions\LexOfficeApiException | ||
*/ | ||
public function get(string $id) | ||
{ | ||
return $this->api->newRequest('GET', $this->resource . '/' . $id) | ||
->getResponse(); | ||
} | ||
|
||
/** | ||
* @param ResponseInterface $response | ||
* @return object | ||
*/ | ||
public function getAsJson(ResponseInterface $response) | ||
{ | ||
$body = $response->getBody()->__toString(); | ||
|
||
return Utils::jsonDecode($body); | ||
} | ||
|
||
/** | ||
* @param mixed $content | ||
* @return StreamInterface | ||
*/ | ||
protected function createStream($content): StreamInterface | ||
{ | ||
return Utils::streamFor( | ||
Utils::jsonEncode($content) | ||
); | ||
} | ||
|
||
/** | ||
* @param array $content | ||
* @param string|null $boundary | ||
* @return MultipartStream | ||
*/ | ||
protected function createMultipartStream(array $content, string $boundary = null): MultipartStream | ||
{ | ||
$stream = []; | ||
$boundary = $boundary ?: '--lexoffice'; | ||
|
||
foreach ($content as $key => $value) { | ||
$stream[] = [ | ||
'name' => $key, | ||
'contents' => $value | ||
]; | ||
} | ||
|
||
return new MultipartStream($stream, $boundary); | ||
} | ||
} |
Oops, something went wrong.