Skip to content

Commit

Permalink
Add V2 taxes
Browse files Browse the repository at this point in the history
  • Loading branch information
szeber committed Oct 15, 2017
1 parent 26ee921 commit f3856db
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/ShoppinPal/Vend/Api/V2/Taxes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace ShoppinPal\Vend\Api\V2;

use ShoppinPal\Vend\DataObject\Entity\V2\CollectionResult;
use ShoppinPal\Vend\DataObject\Entity\V2\Tax;
use YapepBase\Communication\CurlHttpRequest;

/**
* Implements the V2 Tax API
*/
class Taxes extends V2ApiAbstract
{

/**
* Returns a collection of taxes.
*
* @param int $pageSize The number of items to return per page.
* @param null $before The version to succeed the last returned version.
* @param null $after The version to precede the first returned version
* @param bool $includeDeleted If TRUE, deleted items will be returned as well. (required to synchronise deletions)
*
* @return CollectionResult
*/
public function getCollection(
$pageSize = 50,
$before = null,
$after = null,
$includeDeleted = false
)
{
$params = [
'page_size' => $pageSize,
];

if (!empty($before)) {
$params['before'] = $before;
}

if (!empty($after)) {
$params['after'] = $after;
}

if ($includeDeleted) {
$params['deleted'] = 1;
}

$request = $this->getAuthenticatedRequestForUri('api/2.0/taxes', $params);
$request->setMethod(CurlHttpRequest::METHOD_GET);

$result = $this->sendRequest($request, 'tax get collection');

$taxes = [];

foreach ($result['data'] as $tax) {
$taxes[] = new Tax($tax, Tax::UNKNOWN_PROPERTY_IGNORE, true);
}

return new CollectionResult(
$result['version']['min'], $result['version']['max'], $taxes
);
}
}
29 changes: 29 additions & 0 deletions src/ShoppinPal/Vend/DataObject/Entity/V2/Tax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace ShoppinPal\Vend\DataObject\Entity\V2;

use ShoppinPal\Vend\DataObject\Entity\EntityDoAbstract;

class Tax extends EntityDoAbstract
{
protected $subEntities = [
'rates' => [
self::SUB_ENTITY_KEY_TYPE => self::SUB_ENTITY_TYPE_COLLECTION,
self::SUB_ENTITY_KEY_CLASS => TaxRate::class,
],
];

public $id;

public $name;

public $isDefault;

public $displayName;

public $rates = [];

public $deletedAt;

public $version;
}
16 changes: 16 additions & 0 deletions src/ShoppinPal/Vend/DataObject/Entity/V2/TaxRate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace ShoppinPal\Vend\DataObject\Entity\V2;

use ShoppinPal\Vend\DataObject\Entity\EntityDoAbstract;

class TaxRate extends EntityDoAbstract
{
public $id;

public $name;

public $rate;

public $displayName;
}
4 changes: 4 additions & 0 deletions src/ShoppinPal/Vend/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use ShoppinPal\Vend\Api\V2\Products as ProductsV2;
use ShoppinPal\Vend\Api\V2\Registers as RegistersV2;
use ShoppinPal\Vend\Api\V2\Sales as SalesV2;
use ShoppinPal\Vend\Api\V2\Taxes as TaxesV2;
use ShoppinPal\Vend\Api\V2\Versions as VersionsV2;
use ShoppinPal\Vend\Auth\AuthHelper;
use ShoppinPal\Vend\Auth\OAuth;
Expand Down Expand Up @@ -341,6 +342,9 @@ public function getTaxesApi($version)
case self::API_VERSION_0:
return new TaxesV0($this->getAuthHelper(), $this->getDomainPrefix());

case self::API_VERSION_2:
return new TaxesV2($this->getAuthHelper(), $this->getDomainPrefix());

default:
throw new ParameterException('Unknown version: ' . $version);
}
Expand Down

0 comments on commit f3856db

Please sign in to comment.