Skip to content

Commit

Permalink
Merge branch 'dev-1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
tgeorgel committed Apr 19, 2023
2 parents 081b11b + f98417d commit e50a911
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 19 deletions.
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
## Introduction
<a name="introduction"></a>

This package is PHP client for the Sellsy API. It's a light wrapper around the Guzzle HTTP client. It's designed to be as simple as possible to use, while being robust.
This package is a PHP client for the Sellsy API. It's a light wrapper around the Guzzle HTTP client. It's designed to be as simple as possible to use, while being robust.

The client **only supports the V2 of Sellsy API**. If you're looking for a V1 client, checkout [TeknooSoftware/sellsy-client](https://github.com/TeknooSoftware/sellsy-client) instead.

Expand Down Expand Up @@ -50,16 +50,12 @@ $contact = new Entities\Contact([
$api = new Api\ContactsApi();
$response = $api->store($contact);

if (!$response->failed()) {
// request failed
}

var_dump(
$response->json()
);
```

This also means you will get back DTO entities from the Sellsy API when performing GET requests :
This also mean you will get back DTO entities from the Sellsy API when performing GET requests :

```php
$api = new Bluerock\Sellsy\Api\CompaniesApi();
Expand All @@ -71,9 +67,9 @@ $company = $api->find("123")->entity();
$companies = $api->index()->entities();
```

If you're unfamiliar with DTOs or need more details, make sure to have a look at the [spatie/data-transfer-object](https://github.com/spatie/data-transfer-object) package, used by this client.
If you're unfamiliar with DTOs or need some documentation on it, make sure to have a look at the [spatie/data-transfer-object](https://github.com/spatie/data-transfer-object) package, used by this client.

Please keep in mind that this package is still in development process. If you're missing an [endpoint implementation](#dev_status), do not hesitate to [contribute](#contribute) or open an issue on this repository.
Please keep in mind that this package is still in development. If you're missing an [endpoint implementation](#dev_status), do not hesitate to [contribute](#contribute) or open an issue on this repository.

## Installation
<a name="installation"></a>
Expand Down Expand Up @@ -119,7 +115,7 @@ Learn more about Sellsy API v2 credentials on the [official documentation](https
### The basics
<a name="usage_query_basic"></a>

Each API domain is represented by a plurialized class (eg: `Contacts`, `Items`, `Taxes`). Each class contains methods used to perform requests agaisn't domain endpoints.
Each API domain is represented by a plurialized class (eg: `Contacts`, `Items`, `Taxes`). Each class contains methods used to perform requests agaisn't the domain's endpoints.

The easiest way to start querying the API is by initializing the corresponding class :

Expand Down Expand Up @@ -160,9 +156,9 @@ This client is using the Laravel CRUD operations keywords to name methods :
| DELETE | `destroy` | Delete a single resource. |
| GET | `search` | Search resources. |

Any additional method available in Sellsy API would follow the camel case convention. For example, additional Companies methods would look like this :
Any additional method described in the domain's documentation would follow the camel case convention. For example, additional [Companies](https://api.sellsy.com/doc/v2/#tag/Companies) methods would look like this :

| Sellsy Company operation | Client Method |
| Operation | Client Method |
|---|---|
| Get a company address. | `CompaniesApi::showAddress(...)` |
| Update a company address. | `CompaniesApi::updateAddress(...)` |
Expand Down Expand Up @@ -195,7 +191,7 @@ $response->header($header): string;
$response->headers(): array;
```

By default, the Request will throw a `\Illuminate\Http\Client\RequestException` if the request returns an error status code (`4xx``5xx`).
By default, the Request will throw a `RequestException` if the request returns an error (status code `4xx —> 5xx`). You can easily catch this exception and handle it as you wish :

```php
/**
Expand All @@ -208,15 +204,14 @@ public function maybeFindMyContact($contact_id)
return Bluerock\Sellsy\Core\Client::contacts()
->show($contact_id)
->entity();

# catch the RequestException
} catch (\Illuminate\Http\Client\RequestException $e) {
# return false if the contact is not found (404 error).
if ($e->response->status() === 404) {
if ($e->response->clientError() && $e->response->status() === 404) {
return false;
}

throw $e;
# throw the exception for any other status code.
throw $e;
}
}
```
Expand Down Expand Up @@ -455,9 +450,10 @@ $contactsApi->delete(123)->json();
| **Catalog** | Units ||
| **Catalog** | Taxes ||
| **Invoicing** | Accounting | 🅾️ |
| **Invoicing** | Rate Categories ||
| **Invoicing** | Purchase (OCR) | 🅾️ |
| **Invoicing** | Payments | 🅾️ |
| **Invoicing** | Invoices | 🅾️ |
| **Invoicing** | Invoices | 🆚️ |
| **Invoicing** | Credit Notes | 🅾️ |
| **Account** | Currencies | 🅾️ |
| **Account** | Custom Fields | 🅾️ |
Expand Down
65 changes: 65 additions & 0 deletions src/Api/InvoicesApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Bluerock\Sellsy\Api;

use Bluerock\Sellsy\Entities\Invoice;
use Bluerock\Sellsy\Collections\InvoiceCollection;
use Bluerock\Sellsy\Core\Response;

/**
* The API client for the `rate-categories` namespace.
*
* @package bluerock/sellsy-client
* @author Thomas <[email protected]>
* @version 1.1
* @access public
* @see https://api.sellsy.com/doc/v2/#tag/Invoices
*/
class InvoicesApi extends AbstractApi
{
/**
* @inheritdoc
*/
public function __construct()
{
parent::__construct();

$this->entity = Invoice::class;
$this->collection = InvoiceCollection::class;
}

/**
* List all invoices.
*
* @param array $query Query parameters.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/get-invoice
*/
public function index(array $query = []): Response
{
$response = $this->connection
->request('invoices')
->get($query);

return $this->prepareResponse($response);
}

/**
* Show a single invoice by id.
*
* @param string $id The invoice id to retrieve.
* @param array $query Query parameters.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/get-invoice
*/
public function show(string $id, array $query = []): Response
{
$response = $this->connection
->request("invoices/{$id}")
->get($query);

return $this->prepareResponse($response);
}
}
2 changes: 1 addition & 1 deletion src/Api/ItemsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* The API client for the `items` namespace.
*
* @package cedricWebsenso/sellsy-client
* @package bluerock/sellsy-client
* @author Cédric <[email protected]>
* @version 1.0
* @access public
Expand Down
124 changes: 124 additions & 0 deletions src/Api/RateCategoriesApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace Bluerock\Sellsy\Api;

use Bluerock\Sellsy\Entities\RateCategory;
use Bluerock\Sellsy\Collections\RateCategoryCollection;
use Bluerock\Sellsy\Core\Response;

/**
* The API client for the `rate-categories` namespace.
*
* @package bluerock/sellsy-client
* @author Thomas <[email protected]>
* @version 1.1
* @access public
* @see https://api.sellsy.com/doc/v2/#tag/Rate-Categories
*/
class RateCategoriesApi extends AbstractApi
{
/**
* @inheritdoc
*/
public function __construct()
{
parent::__construct();

$this->entity = RateCategory::class;
$this->collection = RateCategoryCollection::class;
}

/**
* List all rate categories.
*
* @param array $query Query parameters.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/get-rate-categories
*/
public function index(array $query = []): Response
{
$response = $this->connection
->request('rate-categories')
->get($query);

return $this->prepareResponse($response);
}

/**
* Show a single rate category by id.
*
* @param string $id The rate category id to retrieve.
* @param array $query Query parameters.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/get-rate-category
*/
public function show(string $id, array $query = []): Response
{
$response = $this->connection
->request("rate-categories/{$id}")
->get($query);

return $this->prepareResponse($response);
}

/**
* Store (create) a rate category.
*
* @param RateCategory $rateCategory The rate category entity to store.
* @param array $query Query parameters.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/create-rate-category
*/
public function store(RateCategory $rateCategory, array $query = []): Response
{
$body = $rateCategory->except('id')
->toArray();

$response = $this->connection
->request('rate-categories')
->post(array_filter($body) + $query);

return $this->prepareResponse($response);
}

/**
* Update an existing rate category.
*
* @param RateCategory $rateCategory The rate category entity to store.
* @param array $query Query parameters.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/update-rate-category
*/
public function update(RateCategory $rateCategory, array $query = []): Response
{
$body = $rateCategory->except('id')
->toArray();

$response = $this->connection
->request("rate-categories/{$rateCategory->id}")
->put(array_filter($body) + $query);

return $this->prepareResponse($response);
}

/**
* Delete an existing rate category.
*
* @param int $id The rate category id to be deleted.
*
* @return \Bluerock\Sellsy\Core\Response
* @see https://api.sellsy.com/doc/v2/#operation/delete-rate-category
*/
public function destroy(int $id): Response
{
$response = $this->connection
->request("rate-categories/{$id}")
->delete();

return $this->prepareResponse($response);
}
}
25 changes: 25 additions & 0 deletions src/Collections/RateCategoryCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Bluerock\Sellsy\Collections;

use Bluerock\Sellsy\Entities\RateCategory;
use Bluerock\Sellsy\Contracts\EntityCollectionContract;
use Spatie\DataTransferObject\DataTransferObjectCollection;

/**
* The RateCategory Entity collection.
*
* @package bluerock/sellsy-client
* @author Thomas <[email protected]>
* @version 1.1
* @access public
*
* @method \Bluerock\Sellsy\Entities\RateCategory current
*/
class RateCategoryCollection extends DataTransferObjectCollection implements EntityCollectionContract
{
public static function create(array $data): RateCategoryCollection
{
return new static(RateCategory::arrayOf($data));
}
}
26 changes: 26 additions & 0 deletions src/Entities/Accounting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Bluerock\Sellsy\Entities;

use Bluerock\Sellsy\Entities\Entity;

/**
* The Accounting Entity.
*
* @package bluerock/sellsy-client
* @author Thomas <[email protected]>
* @version 1.1
* @access public
*/
class Accounting extends Entity
{
/**
* Accounting code ID.
*/
public ?int $accounting_code_id;

/**
* Discount accounting code ID.
*/
public ?int $discount_accounting_code_id;
}
Loading

0 comments on commit e50a911

Please sign in to comment.