Skip to content

Commit

Permalink
✨ Add taxes endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tgeorgel committed Feb 25, 2022
1 parent f38f715 commit 7b3cb9b
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/Api/TaxesApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Hydrat\Sellsy\Api;

use Hydrat\Sellsy\Entities\Tax;
use Hydrat\Sellsy\Collections\TaxCollection;

/**
* The API client for the `companies` namespace.
*
* @package sellsy-connector
* @author Thomas <thomas@hydrat.agency>
* @version 1.0
* @access public
*/
class TaxesApi extends AbstractApi
{
/**
* @inheritdoc
*/
public function __construct()
{
parent::__construct();

$this->entity = Tax::class;
$this->collection = TaxCollection::class;
}


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

$this->response = $response;
$this->response->throw();

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

namespace Hydrat\Sellsy\Collections;

use Hydrat\Sellsy\Entities\Tax;
use Hydrat\Sellsy\Contracts\EntityCollectionContract;
use Spatie\DataTransferObject\DataTransferObjectCollection;

/**
* The Tax Entity collection.
*
* @package sellsy-connector
* @author Thomas <thomas@hydrat.agency>
* @version 1.0
* @access public
*
* @method \Hydrat\Sellsy\Entities\Tax current
*/
class TaxCollection extends DataTransferObjectCollection implements EntityCollectionContract
{
public static function create(array $data): TaxCollection
{
return new static(Tax::arrayOf($data));
}
}
34 changes: 34 additions & 0 deletions src/Entities/Tax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Hydrat\Sellsy\Entities;

use Hydrat\Sellsy\Contracts\EntityContract;
use Spatie\DataTransferObject\FlexibleDataTransferObject;

/**
* The Tax Entity.
*
* @package sellsy-connector
* @author Thomas <thomas@hydrat.agency>
* @version 1.0
* @access public
*/
class Tax extends FlexibleDataTransferObject implements EntityContract
{
/**
* <READONLY> Tax class ID from Sellsy.
*/
public int $id;

/**
* Tax rate in percentage.
*
* @var int|float|null
*/
public $rate;

/**
* Tax class label.
*/
public ?string $label;
}

0 comments on commit 7b3cb9b

Please sign in to comment.