From 6947dfe08cd87dd80ba52c1fce3309050cb51c81 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 20 Dec 2017 16:56:50 +0300 Subject: [PATCH] couriers, legal entities and costs references methods --- lib/RetailCrm/Methods/V5/References.php | 206 ++++++++++++++++++ .../Version5/ApiClientReferenceTest.php | 3 + 2 files changed, 209 insertions(+) diff --git a/lib/RetailCrm/Methods/V5/References.php b/lib/RetailCrm/Methods/V5/References.php index a51e72e..bfb6cda 100644 --- a/lib/RetailCrm/Methods/V5/References.php +++ b/lib/RetailCrm/Methods/V5/References.php @@ -30,4 +30,210 @@ use RetailCrm\Methods\V4\References as Previous; trait References { use Previous; + + /** + * Get costs groups + * + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function costGroups() + { + return $this->client->makeRequest( + '/reference/cost-groups', + "GET" + ); + } + + /** + * Edit costs groups + * + * @param array $data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function costGroupsEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "name" parameter.' + ); + } + + if (!array_key_exists('color', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "color" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/cost-groups/%s/edit', $data['code']), + "POST", + ['costGroup' => json_encode($data)] + ); + } + + /** + * Get costs items + * + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function costItems() + { + return $this->client->makeRequest( + '/reference/cost-items', + "GET" + ); + } + + /** + * Edit costs items + * + * @param array $data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function costItemsEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + if (!array_key_exists('name', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "name" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/cost-items/%s/edit', $data['code']), + "POST", + ['costItem' => json_encode($data)] + ); + } + + /** + * Get legal entities + * + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function legalEntities() + { + return $this->client->makeRequest( + '/reference/legal-entities', + "GET" + ); + } + + /** + * Edit legal entity + * + * @param array $data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function legalEntitiesEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/legal-entities/%s/edit', $data['code']), + "POST", + ['legalEntity' => json_encode($data)] + ); + } + + /** + * Get couriers + * + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function couriersList() + { + return $this->client->makeRequest( + '/reference/couriers', + "GET" + ); + } + + /** + * Create courier + * + * @param array $courier + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function couriersCreate(array $courier) + { + return $this->client->makeRequest( + '/reference/couriers/create', + "POST", + ['courier' => json_encode($courier)] + ); + } + + /** + * Edit courier + * + * @param array $courier + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function couriersEdit(array $courier) + { + if (!array_key_exists('id', $courier)) { + throw new \InvalidArgumentException( + 'Data must contain "id" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/couriers/%s/edit', $courier['id']), + "POST", + ['courier' => json_encode($courier)] + ); + } } diff --git a/tests/RetailCrm/Tests/Methods/Version5/ApiClientReferenceTest.php b/tests/RetailCrm/Tests/Methods/Version5/ApiClientReferenceTest.php index 646e34a..1a08b74 100644 --- a/tests/RetailCrm/Tests/Methods/Version5/ApiClientReferenceTest.php +++ b/tests/RetailCrm/Tests/Methods/Version5/ApiClientReferenceTest.php @@ -38,6 +38,7 @@ class ApiClientReferenceTest extends TestCase $client = static::getApiClient(); $method = $name . 'List'; + echo $method; $response = $client->request->$method(); /* @var \RetailCrm\Response\ApiResponse $response */ @@ -153,6 +154,8 @@ class ApiClientReferenceTest extends TestCase ['statuses'], ['sites'], ['stores'], + ['couriers'], + ['costs'] ]; }