-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
4 changed files
with
112 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,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 | ||
); | ||
} | ||
} |
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,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; | ||
} |
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,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; | ||
} |
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