diff --git a/.travis.yml b/.travis.yml index 37b543d..7790a8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ cache: - $HOME/.composer/cache php: - - '5.3' - '5.4' - '5.5' - '5.6' @@ -14,6 +13,6 @@ php: before_script: - flags="--prefer-dist --no-dev -o" - composer install $flags - - wget -c -O phpunit.xml https://goo.gl/yZHStN + - cp phpunit.xml.dist phpunit.xml script: phpunit diff --git a/composer.json b/composer.json index 135ed47..b24fdf3 100644 --- a/composer.json +++ b/composer.json @@ -8,11 +8,11 @@ "authors": [ { "name": "retailCRM", - "email": "support@retailcrm.pro" + "email": "support@retailcrm.ru" } ], "require": { - "php": ">=5.3.0", + "php": ">=5.4.0", "ext-curl": "*" }, "require-dev": { diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index 73cca2e..0886aea 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -1,7 +1,7 @@ client = new Client($url, array('apiKey' => $apiKey)); - $this->siteCode = $site; - } - - /** - * Returns users list - * - * @param array $filter - * @param null $page - * @param null $limit - * - * @throws \RetailCrm\Exception\InvalidJsonException - * @throws \RetailCrm\Exception\CurlException - * @throws \InvalidArgumentException - * - * @return ApiResponse - */ - public function usersList(array $filter = array(), $page = null, $limit = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/users', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Get user groups - * - * @param null $page - * @param null $limit - * - * @throws \RetailCrm\Exception\InvalidJsonException - * @throws \RetailCrm\Exception\CurlException - * - * @return ApiResponse - */ - public function usersGroups($page = null, $limit = null) - { - $parameters = array(); - - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/user-groups', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Returns user data - * - * @param integer $id user ID - * - * @throws \RetailCrm\Exception\InvalidJsonException - * @throws \RetailCrm\Exception\CurlException - * @throws \InvalidArgumentException - * - * @return ApiResponse - */ - public function usersGet($id) - { - return $this->client->makeRequest("/users/$id", Client::METHOD_GET); - } - - /** - * Change user status - * - * @param integer $id user ID - * @param string $status user status - * - * @return ApiResponse - */ - public function usersStatus($id, $status) - { - $statuses = array("free", "busy", "dinner", "break"); - - if (empty($status) || !in_array($status, $statuses)) { - throw new \InvalidArgumentException( - 'Parameter `status` must be not empty & must be equal one of these values: free|busy|dinner|break' - ); - } - - return $this->client->makeRequest( - "/users/$id/status", - Client::METHOD_POST, - array('status' => $status) - ); - } - - /** - * Returns filtered orders list - * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersList(array $filter = array(), $page = null, $limit = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/orders', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Combine orders - * - * @param string $technique - * @param array $order - * @param array $resultOrder - * - * @return ApiResponse - */ - public function ordersCombine($order, $resultOrder, $technique = 'ours') - { - $techniques = array('ours', 'summ', 'theirs'); - - if (!count($order) || !count($resultOrder)) { - throw new \InvalidArgumentException( - 'Parameters `order` & `resultOrder` must contains a data' - ); - } - - if (!in_array($technique, $techniques)) { - throw new \InvalidArgumentException( - 'Parameter `technique` must be on of ours|summ|theirs' - ); - } - - return $this->client->makeRequest( - '/orders/combine', - Client::METHOD_POST, - array( - 'technique' => $technique, - 'order' => json_encode($order), - 'resultOrder' => json_encode($resultOrder) - ) - ); - } - - /** - * Create an order - * - * @param array $order order data - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersCreate(array $order, $site = null) - { - if (!count($order)) { - throw new \InvalidArgumentException( - 'Parameter `order` must contains a data' - ); - } - - return $this->client->makeRequest( - '/orders/create', - Client::METHOD_POST, - $this->fillSite($site, array('order' => json_encode($order))) - ); - } - - /** - * Save order IDs' (id and externalId) association into CRM - * - * @param array $ids order identificators - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersFixExternalIds(array $ids) - { - if (! count($ids)) { - throw new \InvalidArgumentException( - 'Method parameter must contains at least one IDs pair' - ); - } - - return $this->client->makeRequest( - '/orders/fix-external-ids', - Client::METHOD_POST, - array('orders' => json_encode($ids) - ) - ); - } - - /** - * Returns statuses of the orders - * - * @param array $ids (default: array()) - * @param array $externalIds (default: array()) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersStatuses(array $ids = array(), array $externalIds = array()) - { - $parameters = array(); - - if (count($ids)) { - $parameters['ids'] = $ids; - } - if (count($externalIds)) { - $parameters['externalIds'] = $externalIds; - } - - return $this->client->makeRequest( - '/orders/statuses', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Upload array of the orders - * - * @param array $orders array of orders - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersUpload(array $orders, $site = null) - { - if (!count($orders)) { - throw new \InvalidArgumentException( - 'Parameter `orders` must contains array of the orders' - ); - } - - return $this->client->makeRequest( - '/orders/upload', - Client::METHOD_POST, - $this->fillSite($site, array('orders' => json_encode($orders))) - ); - } - - /** - * Get order by id or externalId - * - * @param string $id order identificator - * @param string $by (default: 'externalId') - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersGet($id, $by = 'externalId', $site = null) - { - $this->checkIdParameter($by); - - return $this->client->makeRequest( - "/orders/$id", - Client::METHOD_GET, - $this->fillSite($site, array('by' => $by)) - ); - } - - /** - * Edit an order - * - * @param array $order order data - * @param string $by (default: 'externalId') - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersEdit(array $order, $by = 'externalId', $site = null) - { - if (!count($order)) { - throw new \InvalidArgumentException( - 'Parameter `order` must contains a data' - ); - } - - $this->checkIdParameter($by); - - if (!array_key_exists($by, $order)) { - throw new \InvalidArgumentException( - sprintf('Order array must contain the "%s" parameter.', $by) - ); - } - - return $this->client->makeRequest( - sprintf('/orders/%s/edit', $order[$by]), - Client::METHOD_POST, - $this->fillSite( - $site, - array('order' => json_encode($order), 'by' => $by) - ) - ); - } - - /** - * Get orders history - * @param array $filter - * @param null $page - * @param null $limit - * - * @return ApiResponse - */ - public function ordersHistory(array $filter = array(), $page = null, $limit = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/orders/history', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Create an order payment - * - * @param array $payment order data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersPaymentCreate(array $payment) - { - if (!count($payment)) { - throw new \InvalidArgumentException( - 'Parameter `payment` must contains a data' - ); - } - - return $this->client->makeRequest( - '/orders/payments/create', - Client::METHOD_POST, - array('payment' => json_encode($payment)) - ); - } - - /** - * Edit an order payment - * - * @param array $payment order data - * @param string $by by key - * @param null $site site code - * - * @return ApiResponse - */ - public function ordersPaymentEdit(array $payment, $by = 'id', $site = null) - { - if (!count($payment)) { - throw new \InvalidArgumentException( - 'Parameter `payment` must contains a data' - ); - } - - $this->checkIdParameter($by); - - if (!array_key_exists($by, $payment)) { - throw new \InvalidArgumentException( - sprintf('Order array must contain the "%s" parameter.', $by) - ); - } - - return $this->client->makeRequest( - sprintf('/orders/payments/%s/edit', $payment[$by]), - Client::METHOD_POST, - $this->fillSite( - $site, - array('payment' => json_encode($payment), 'by' => $by) - ) - ); - } - - /** - * Returns filtered customers list - * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function customersList(array $filter = array(), $page = null, $limit = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/customers', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Combine customers - * - * @param array $customers - * @param array $resultCustomer - * - * @return ApiResponse - */ - public function customersCombine(array $customers, $resultCustomer) - { - - if (!count($customers) || !count($resultCustomer)) { - throw new \InvalidArgumentException( - 'Parameters `customers` & `resultCustomer` must contains a data' - ); - } - - return $this->client->makeRequest( - '/customers/combine', - Client::METHOD_POST, - array( - 'customers' => json_encode($customers), - 'resultCustomer' => json_encode($resultCustomer) - ) - ); - } - - /** - * Create a customer - * - * @param array $customer customer data - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function customersCreate(array $customer, $site = null) - { - if (! count($customer)) { - throw new \InvalidArgumentException( - 'Parameter `customer` must contains a data' - ); - } - - return $this->client->makeRequest( - '/customers/create', - Client::METHOD_POST, - $this->fillSite($site, array('customer' => json_encode($customer))) - ); - } - - /** - * Save customer IDs' (id and externalId) association in the CRM - * - * @param array $ids ids mapping - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function customersFixExternalIds(array $ids) - { - if (! count($ids)) { - throw new \InvalidArgumentException( - 'Method parameter must contains at least one IDs pair' - ); - } - - return $this->client->makeRequest( - '/customers/fix-external-ids', - Client::METHOD_POST, - array('customers' => json_encode($ids)) - ); - } - - /** - * Upload array of the customers - * - * @param array $customers array of customers - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function customersUpload(array $customers, $site = null) - { - if (! count($customers)) { - throw new \InvalidArgumentException( - 'Parameter `customers` must contains array of the customers' - ); - } - - return $this->client->makeRequest( - '/customers/upload', - Client::METHOD_POST, - $this->fillSite($site, array('customers' => json_encode($customers))) - ); - } - - /** - * Get customer by id or externalId - * - * @param string $id customer identificator - * @param string $by (default: 'externalId') - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function customersGet($id, $by = 'externalId', $site = null) - { - $this->checkIdParameter($by); - - return $this->client->makeRequest( - "/customers/$id", - Client::METHOD_GET, - $this->fillSite($site, array('by' => $by)) - ); - } - - /** - * Edit a customer - * - * @param array $customer customer data - * @param string $by (default: 'externalId') - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function customersEdit(array $customer, $by = 'externalId', $site = null) - { - if (!count($customer)) { - throw new \InvalidArgumentException( - 'Parameter `customer` must contains a data' - ); - } - - $this->checkIdParameter($by); - - if (!array_key_exists($by, $customer)) { - throw new \InvalidArgumentException( - sprintf('Customer array must contain the "%s" parameter.', $by) - ); - } - - return $this->client->makeRequest( - sprintf('/customers/%s/edit', $customer[$by]), - Client::METHOD_POST, - $this->fillSite( - $site, - array('customer' => json_encode($customer), 'by' => $by) - ) - ); - } - - /** - * Get customers history - * @param array $filter - * @param null $page - * @param null $limit - * - * @return ApiResponse - */ - public function customersHistory(array $filter = array(), $page = null, $limit = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/customers/history', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Get orders assembly list - * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersPacksList(array $filter = array(), $page = null, $limit = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/orders/packs', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Create orders assembly - * - * @param array $pack pack data - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersPacksCreate(array $pack, $site = null) - { - if (!count($pack)) { - throw new \InvalidArgumentException( - 'Parameter `pack` must contains a data' - ); - } - - return $this->client->makeRequest( - '/orders/packs/create', - Client::METHOD_POST, - $this->fillSite($site, array('pack' => json_encode($pack))) - ); - } - - /** - * Get orders assembly history - * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersPacksHistory(array $filter = array(), $page = null, $limit = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/orders/packs/history', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Get orders assembly by id - * - * @param string $id pack identificator - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersPacksGet($id) - { - if (empty($id)) { - throw new \InvalidArgumentException('Parameter `id` must be set'); - } - - return $this->client->makeRequest( - "/orders/packs/$id", - Client::METHOD_GET - ); - } - - /** - * Delete orders assembly by id - * - * @param string $id pack identificator - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersPacksDelete($id) - { - if (empty($id)) { - throw new \InvalidArgumentException('Parameter `id` must be set'); - } - - return $this->client->makeRequest( - sprintf('/orders/packs/%s/delete', $id), - Client::METHOD_POST - ); - } - - /** - * Edit orders assembly - * - * @param array $pack pack data - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function ordersPacksEdit(array $pack, $site = null) - { - if (!count($pack) || empty($pack['id'])) { - throw new \InvalidArgumentException( - 'Parameter `pack` must contains a data & pack `id` must be set' - ); - } - - return $this->client->makeRequest( - sprintf('/orders/packs/%s/edit', $pack['id']), - Client::METHOD_POST, - $this->fillSite($site, array('pack' => json_encode($pack))) - ); - } - - /** - * Get purchace prices & stock balance - * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function storeInventories(array $filter = array(), $page = null, $limit = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/store/inventories', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Get store settings - * - * @param string $code get settings code - * - * @return ApiResponse - * @throws \RetailCrm\Exception\InvalidJsonException - * @throws \RetailCrm\Exception\CurlException - * @throws \InvalidArgumentException - * - * @return ApiResponse - */ - public function storeSettingsGet($code) - { - if (empty($code)) { - throw new \InvalidArgumentException('Parameter `code` must be set'); - } - - return $this->client->makeRequest( - "/store/setting/$code", - Client::METHOD_GET - ); - } - - /** - * Edit store configuration - * - * @param array $configuration - * - * @throws \RetailCrm\Exception\InvalidJsonException - * @throws \RetailCrm\Exception\CurlException - * @throws \InvalidArgumentException - * - * @return ApiResponse - */ - public function storeSettingsEdit(array $configuration) - { - if (!count($configuration) || empty($configuration['code'])) { - throw new \InvalidArgumentException( - 'Parameter `configuration` must contains a data & configuration `code` must be set' - ); - } - - return $this->client->makeRequest( - sprintf('/store/setting/%s/edit', $configuration['code']), - Client::METHOD_POST, - array('configuration' => json_encode($configuration)) - ); - } - - /** - * Upload store inventories - * - * @param array $offers offers data - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function storeInventoriesUpload(array $offers, $site = null) - { - if (!count($offers)) { - throw new \InvalidArgumentException( - 'Parameter `offers` must contains array of the offers' - ); - } - - return $this->client->makeRequest( - '/store/inventories/upload', - Client::METHOD_POST, - $this->fillSite($site, array('offers' => json_encode($offers))) - ); - } - - /** - * Upload store prices - * - * @param array $prices prices data - * @param string $site default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function storePricesUpload(array $prices, $site = null) - { - if (!count($prices)) { - throw new \InvalidArgumentException( - 'Parameter `prices` must contains array of the prices' - ); - } - - return $this->client->makeRequest( - '/store/prices/upload', - Client::METHOD_POST, - $this->fillSite($site, array('prices' => json_encode($prices))) - ); - } - - /** - * Get products - * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function storeProducts(array $filter = array(), $page = null, $limit = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/store/products', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Get products groups - * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function storeProductsGroups(array $filter = array(), $page = null, $limit = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/store/product-groups', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Get delivery settings - * - * @param string $code - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function deliverySettingsGet($code) - { - if (empty($code)) { - throw new \InvalidArgumentException('Parameter `code` must be set'); - } - - return $this->client->makeRequest( - "/delivery/generic/setting/$code", - Client::METHOD_GET - ); - } - - /** - * Edit delivery configuration - * - * @param array $configuration - * - * @throws \RetailCrm\Exception\InvalidJsonException - * @throws \RetailCrm\Exception\CurlException - * @throws \InvalidArgumentException - * - * @return ApiResponse - */ - public function deliverySettingsEdit(array $configuration) - { - if (!count($configuration) || empty($configuration['code'])) { - throw new \InvalidArgumentException( - 'Parameter `configuration` must contains a data & configuration `code` must be set' - ); - } - - return $this->client->makeRequest( - sprintf('/delivery/generic/setting/%s/edit', $configuration['code']), - Client::METHOD_POST, - array('configuration' => json_encode($configuration)) - ); - } - - /** - * Delivery tracking update - * - * @param string $code - * @param array $statusUpdate - * - * @throws \RetailCrm\Exception\InvalidJsonException - * @throws \RetailCrm\Exception\CurlException - * @throws \InvalidArgumentException - * - * @return ApiResponse - */ - public function deliveryTracking($code, array $statusUpdate) - { - if (empty($code)) { - throw new \InvalidArgumentException('Parameter `code` must be set'); - } - - if (!count($statusUpdate)) { - throw new \InvalidArgumentException( - 'Parameter `statusUpdate` must contains a data' - ); - } - - return $this->client->makeRequest( - sprintf('/delivery/generic/%s/tracking', $code), - Client::METHOD_POST, - array('statusUpdate' => json_encode($statusUpdate)) - ); - } - - /** - * Returns available county list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function countriesList() - { - return $this->client->makeRequest( - '/reference/countries', - Client::METHOD_GET - ); - } - - /** - * Returns deliveryServices list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function deliveryServicesList() - { - return $this->client->makeRequest( - '/reference/delivery-services', - Client::METHOD_GET - ); - } - - /** - * Edit deliveryService - * - * @param array $data delivery service data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function deliveryServicesEdit(array $data) - { - if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( - 'Data must contain "code" parameter.' - ); - } - - return $this->client->makeRequest( - sprintf('/reference/delivery-services/%s/edit', $data['code']), - Client::METHOD_POST, - array('deliveryService' => json_encode($data)) - ); - } - - /** - * Returns deliveryTypes list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function deliveryTypesList() - { - return $this->client->makeRequest( - '/reference/delivery-types', - Client::METHOD_GET - ); - } - - /** - * Edit deliveryType - * - * @param array $data delivery type data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function deliveryTypesEdit(array $data) - { - if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( - 'Data must contain "code" parameter.' - ); - } - - return $this->client->makeRequest( - sprintf('/reference/delivery-types/%s/edit', $data['code']), - Client::METHOD_POST, - array('deliveryType' => json_encode($data)) - ); - } - - /** - * Returns orderMethods list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function orderMethodsList() - { - return $this->client->makeRequest( - '/reference/order-methods', - Client::METHOD_GET - ); - } - - /** - * Edit orderMethod - * - * @param array $data order method data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function orderMethodsEdit(array $data) - { - if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( - 'Data must contain "code" parameter.' - ); - } - - return $this->client->makeRequest( - sprintf('/reference/order-methods/%s/edit', $data['code']), - Client::METHOD_POST, - array('orderMethod' => json_encode($data)) - ); - } - - /** - * Returns orderTypes list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function orderTypesList() - { - return $this->client->makeRequest( - '/reference/order-types', - Client::METHOD_GET - ); - } - - /** - * Edit orderType - * - * @param array $data order type data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function orderTypesEdit(array $data) - { - if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( - 'Data must contain "code" parameter.' - ); - } - - return $this->client->makeRequest( - sprintf('/reference/order-types/%s/edit', $data['code']), - Client::METHOD_POST, - array('orderType' => json_encode($data)) - ); - } - - /** - * Returns paymentStatuses list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function paymentStatusesList() - { - return $this->client->makeRequest( - '/reference/payment-statuses', - Client::METHOD_GET - ); - } - - /** - * Edit paymentStatus - * - * @param array $data payment status data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function paymentStatusesEdit(array $data) - { - if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( - 'Data must contain "code" parameter.' - ); - } - - return $this->client->makeRequest( - sprintf('/reference/payment-statuses/%s/edit', $data['code']), - Client::METHOD_POST, - array('paymentStatus' => json_encode($data)) - ); - } - - /** - * Returns paymentTypes list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function paymentTypesList() - { - return $this->client->makeRequest( - '/reference/payment-types', - Client::METHOD_GET - ); - } - - /** - * Edit paymentType - * - * @param array $data payment type data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function paymentTypesEdit(array $data) - { - if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( - 'Data must contain "code" parameter.' - ); - } - - return $this->client->makeRequest( - sprintf('/reference/payment-types/%s/edit', $data['code']), - Client::METHOD_POST, - array('paymentType' => json_encode($data)) - ); - } - - /** - * Returns productStatuses list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function productStatusesList() - { - return $this->client->makeRequest( - '/reference/product-statuses', - Client::METHOD_GET - ); - } - - /** - * Edit productStatus - * - * @param array $data product status data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function productStatusesEdit(array $data) - { - if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( - 'Data must contain "code" parameter.' - ); - } - - return $this->client->makeRequest( - sprintf('/reference/product-statuses/%s/edit', $data['code']), - Client::METHOD_POST, - array('productStatus' => json_encode($data)) - ); - } - - /** - * Returns sites list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function sitesList() - { - return $this->client->makeRequest( - '/reference/sites', - Client::METHOD_GET - ); - } - - /** - * Edit site - * - * @param array $data site data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function sitesEdit(array $data) - { - if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( - 'Data must contain "code" parameter.' - ); - } - - return $this->client->makeRequest( - sprintf('/reference/sites/%s/edit', $data['code']), - Client::METHOD_POST, - array('site' => json_encode($data)) - ); - } - - /** - * Returns statusGroups list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function statusGroupsList() - { - return $this->client->makeRequest( - '/reference/status-groups', - Client::METHOD_GET - ); - } - - /** - * Returns statuses list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function statusesList() - { - return $this->client->makeRequest( - '/reference/statuses', - Client::METHOD_GET - ); - } - - /** - * Edit order status - * - * @param array $data status data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function statusesEdit(array $data) - { - if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( - 'Data must contain "code" parameter.' - ); - } - - return $this->client->makeRequest( - sprintf('/reference/statuses/%s/edit', $data['code']), - Client::METHOD_POST, - array('status' => json_encode($data)) - ); - } - - /** - * Returns stores list - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function storesList() - { - return $this->client->makeRequest( - '/reference/stores', - Client::METHOD_GET - ); - } - - /** - * Edit store - * - * @param array $data site data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function storesEdit(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/stores/%s/edit', $data['code']), - Client::METHOD_POST, - array('store' => json_encode($data)) - ); - } - - /** - * Get prices types - * - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function pricesTypes() - { - return $this->client->makeRequest( - '/reference/price-types', - Client::METHOD_GET - ); - } - - /** - * Edit price type - * - * @param array $data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function pricesEdit(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/price-types/%s/edit', $data['code']), - Client::METHOD_POST, - array('priceType' => json_encode($data)) - ); - } - - /** - * Get telephony settings - * - * @param string $code - * - * @throws \RetailCrm\Exception\InvalidJsonException - * @throws \RetailCrm\Exception\CurlException - * @throws \InvalidArgumentException - * - * @return ApiResponse - */ - public function telephonySettingsGet($code) - { - if (empty($code)) { - throw new \InvalidArgumentException('Parameter `code` must be set'); - } - - return $this->client->makeRequest( - "/telephony/setting/$code", - Client::METHOD_GET - ); - } - - /** - * Edit telephony settings - * - * @param string $code symbolic code - * @param string $clientId client id - * @param boolean $active telephony activity - * @param mixed $name service name - * @param mixed $makeCallUrl service init url - * @param mixed $image service logo url(svg file) - * - * @param array $additionalCodes - * @param array $externalPhones - * @param bool $allowEdit - * @param bool $inputEventSupported - * @param bool $outputEventSupported - * @param bool $hangupEventSupported - * @param bool $changeUserStatusUrl - * - * @return ApiResponse - */ - public function telephonySettingsEdit( - $code, - $clientId, - $active = false, - $name = false, - $makeCallUrl = false, - $image = false, - $additionalCodes = array(), - $externalPhones = array(), - $allowEdit = false, - $inputEventSupported = false, - $outputEventSupported = false, - $hangupEventSupported = false, - $changeUserStatusUrl = false - ) { - if (!isset($code)) { - throw new \InvalidArgumentException('Code must be set'); - } - - $parameters['code'] = $code; - - if (!isset($clientId)) { - throw new \InvalidArgumentException('client id must be set'); - } - - $parameters['clientId'] = $clientId; - - if (!isset($active)) { - $parameters['active'] = false; - } else { - $parameters['active'] = $active; - } - - if (!isset($name)) { - throw new \InvalidArgumentException('name must be set'); - } - - if (isset($name)) { - $parameters['name'] = $name; - } - - if (isset($makeCallUrl)) { - $parameters['makeCallUrl'] = $makeCallUrl; - } - - if (isset($image)) { - $parameters['image'] = $image; - } - - if (isset($additionalCodes)) { - $parameters['additionalCodes'] = $additionalCodes; - } - - if (isset($externalPhones)) { - $parameters['externalPhones'] = $externalPhones; - } - - if (isset($allowEdit)) { - $parameters['allowEdit'] = $allowEdit; - } - - if (isset($inputEventSupported)) { - $parameters['inputEventSupported'] = $inputEventSupported; - } - - if (isset($outputEventSupported)) { - $parameters['outputEventSupported'] = $outputEventSupported; - } - - if (isset($hangupEventSupported)) { - $parameters['hangupEventSupported'] = $hangupEventSupported; - } - - if (isset($changeUserStatusUrl)) { - $parameters['changeUserStatusUrl'] = $changeUserStatusUrl; - } - - return $this->client->makeRequest( - "/telephony/setting/$code/edit", - Client::METHOD_POST, - array('configuration' => json_encode($parameters)) - ); - } - - /** - * Call event - * - * @param string $phone phone number - * @param string $type call type - * @param array $codes - * @param string $hangupStatus - * @param string $externalPhone - * @param array $webAnalyticsData - * - * @return ApiResponse - * @internal param string $code additional phone code - * @internal param string $status call status - * - */ - public function telephonyCallEvent( - $phone, - $type, - $codes, - $hangupStatus, - $externalPhone = null, - $webAnalyticsData = array() - ) { - if (!isset($phone)) { - throw new \InvalidArgumentException('Phone number must be set'); - } - - if (!isset($type)) { - throw new \InvalidArgumentException('Type must be set (in|out|hangup)'); - } - - if (empty($codes)) { - throw new \InvalidArgumentException('Codes array must be set'); - } - - $parameters['phone'] = $phone; - $parameters['type'] = $type; - $parameters['codes'] = $codes; - $parameters['hangupStatus'] = $hangupStatus; - $parameters['callExternalId'] = $externalPhone; - $parameters['webAnalyticsData'] = $webAnalyticsData; - - - return $this->client->makeRequest( - '/telephony/call/event', - Client::METHOD_POST, - array('event' => json_encode($parameters)) - ); - } - - /** - * Upload calls - * - * @param array $calls calls data - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function telephonyCallsUpload(array $calls) - { - if (!count($calls)) { - throw new \InvalidArgumentException( - 'Parameter `calls` must contains array of the calls' - ); - } - - return $this->client->makeRequest( - '/telephony/calls/upload', - Client::METHOD_POST, - array('calls' => json_encode($calls)) - ); - } - - /** - * Get call manager - * - * @param string $phone phone number - * @param bool $details detailed information - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function telephonyCallManager($phone, $details) - { - if (!isset($phone)) { - throw new \InvalidArgumentException('Phone number must be set'); - } - - $parameters['phone'] = $phone; - $parameters['details'] = isset($details) ? $details : 0; - - return $this->client->makeRequest( - '/telephony/manager', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Edit marketplace configuration - * - * @param array $configuration - * - * @throws \RetailCrm\Exception\InvalidJsonException - * @throws \RetailCrm\Exception\CurlException - * @throws \InvalidArgumentException - * - * @return ApiResponse - */ - public function marketplaceSettingsEdit(array $configuration) - { - if (!count($configuration) || empty($configuration['code'])) { - throw new \InvalidArgumentException( - 'Parameter `configuration` must contains a data & configuration `code` must be set' - ); - } - - return $this->client->makeRequest( - sprintf('/marketplace/external/setting/%s/edit', $configuration['code']), - Client::METHOD_POST, - array('configuration' => json_encode($configuration)) - ); - } - - /** - * Update CRM basic statistic - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException - * - * @return ApiResponse - */ - public function statisticUpdate() - { - return $this->client->makeRequest( - '/statistic/update', - Client::METHOD_GET - ); - } - - /** - * Get custom fields list - * - * @param array $filter - * @param null $limit - * @param null $page - * - * @return ApiResponse - */ - public function customFieldsList(array $filter = array(), $limit = null, $page = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/custom-fields', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Create custom field - * - * @param $entity - * @param $customField - * - * @return ApiResponse - */ - public function customFieldsCreate($entity, $customField) - { - if (!count($customField) || - empty($customField['code']) || - empty($customField['name']) || - empty($customField['type']) - ) { - throw new \InvalidArgumentException( - 'Parameter `customField` must contain a data & fields `code`, `name` & `type` must be set' - ); - } - - if (empty($entity) || $entity != 'customer' || $entity != 'order') { - throw new \InvalidArgumentException( - 'Parameter `entity` must contain a data & value must be `order` or `customer`' - ); - } - - return $this->client->makeRequest( - "/custom-fields/$entity/create", - Client::METHOD_POST, - array('customField' => json_encode($customField)) - ); - } - - /** - * Edit custom field - * - * @param $entity - * @param $customField - * - * @return ApiResponse - */ - public function customFieldsEdit($entity, $customField) - { - if (!count($customField) || empty($customField['code'])) { - throw new \InvalidArgumentException( - 'Parameter `customField` must contain a data & fields `code` must be set' - ); - } - - if (empty($entity) || $entity != 'customer' || $entity != 'order') { - throw new \InvalidArgumentException( - 'Parameter `entity` must contain a data & value must be `order` or `customer`' - ); - } - - return $this->client->makeRequest( - "/custom-fields/$entity/edit/{$customField['code']}", - Client::METHOD_POST, - array('customField' => json_encode($customField)) - ); - } - - /** - * Get custom field - * - * @param $entity - * @param $code - * - * @return ApiResponse - */ - public function customFieldsGet($entity, $code) - { - if (empty($code)) { - throw new \InvalidArgumentException( - 'Parameter `code` must be not empty' - ); - } - - if (empty($entity) || $entity != 'customer' || $entity != 'order') { - throw new \InvalidArgumentException( - 'Parameter `entity` must contain a data & value must be `order` or `customer`' - ); - } - - return $this->client->makeRequest( - "/custom-fields/$entity/$code", - Client::METHOD_GET - ); - } - - /** - * Get custom dictionaries list - * - * @param array $filter - * @param null $limit - * @param null $page - * - * @return ApiResponse - */ - public function customDictionariesList(array $filter = array(), $limit = null, $page = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/custom-fields/dictionaries', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Create custom dictionary - * - * @param $customDictionary - * - * @return ApiResponse - */ - public function customDictionariesCreate($customDictionary) - { - if (!count($customDictionary) || - empty($customDictionary['code']) || - empty($customDictionary['elements']) - ) { - throw new \InvalidArgumentException( - 'Parameter `dictionary` must contain a data & fields `code` & `elemets` must be set' - ); - } - - return $this->client->makeRequest( - "/custom-fields/dictionaries/{$customDictionary['code']}/create", - Client::METHOD_POST, - array('customDictionary' => json_encode($customDictionary)) - ); - } - - /** - * Edit custom dictionary - * - * @param $customDictionary - * - * @return ApiResponse - */ - public function customDictionariesEdit($customDictionary) - { - if (!count($customDictionary) || - empty($customDictionary['code']) || - empty($customDictionary['elements']) - ) { - throw new \InvalidArgumentException( - 'Parameter `dictionary` must contain a data & fields `code` & `elemets` must be set' - ); - } - - return $this->client->makeRequest( - "/custom-fields/dictionaries/{$customDictionary['code']}/edit", - Client::METHOD_POST, - array('customDictionary' => json_encode($customDictionary)) - ); - } - - /** - * Get custom dictionary - * - * @param $code - * - * @return ApiResponse - */ - public function customDictionariesGet($code) - { - if (empty($code)) { - throw new \InvalidArgumentException( - 'Parameter `code` must be not empty' - ); - } - - return $this->client->makeRequest( - "/custom-fields/dictionaries/$code", - Client::METHOD_GET - ); - } - - /** - * Get segments list - * - * @param array $filter - * @param null $limit - * @param null $page - * - * @return ApiResponse - */ - public function segmentsList(array $filter = array(), $limit = null, $page = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/segments', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Get tasks list - * - * @param array $filter - * @param null $limit - * @param null $page - * - * @return ApiResponse - */ - public function tasksList(array $filter = array(), $limit = null, $page = null) - { - $parameters = array(); - - if (count($filter)) { - $parameters['filter'] = $filter; - } - if (null !== $page) { - $parameters['page'] = (int) $page; - } - if (null !== $limit) { - $parameters['limit'] = (int) $limit; - } - - return $this->client->makeRequest( - '/tasks', - Client::METHOD_GET, - $parameters - ); - } - - /** - * Create task - * - * @param array $task - * @param null $site - * - * @return ApiResponse - * - */ - public function tasksCreate($task, $site = null) - { - if (!count($task)) { - throw new \InvalidArgumentException( - 'Parameter `task` must contain a data' - ); - } - - return $this->client->makeRequest( - "/tasks/create", - Client::METHOD_POST, - $this->fillSite( - $site, - array('task' => json_encode($task)) - ) - ); - } - - /** - * Edit task - * - * @param array $task - * @param null $site - * - * @return ApiResponse - * - */ - public function tasksEdit($task, $site = null) - { - if (!count($task)) { - throw new \InvalidArgumentException( - 'Parameter `task` must contain a data' - ); - } - - return $this->client->makeRequest( - "/tasks/{$task['id']}/edit", - Client::METHOD_POST, - $this->fillSite( - $site, - array('task' => json_encode($task)) - ) - ); - } - - /** - * Get custom dictionary - * - * @param $id - * - * @return ApiResponse - */ - public function tasksGet($id) - { - if (empty($id)) { - throw new \InvalidArgumentException( - 'Parameter `id` must be not empty' - ); - } - - return $this->client->makeRequest( - "/tasks/$id", - Client::METHOD_GET - ); - } - - /** - * Return current site - * - * @return string - */ - public function getSite() - { - return $this->siteCode; - } - - /** - * Set site - * - * @param string $site site code - * - * @return void - */ - public function setSite($site) - { - $this->siteCode = $site; - } + public $request; /** - * Check ID parameter - * - * @param string $by identify by + * Init version based client * - * @throws \InvalidArgumentException + * @param string $url api url + * @param string $apiKey api key + * @param string $version api version + * @param string $site site code * - * @return bool */ - protected function checkIdParameter($by) + public function __construct($url, $apiKey, $version = 'v5', $site = null) { - $allowedForBy = array( - 'externalId', - 'id' - ); - - if (!in_array($by, $allowedForBy, false)) { - throw new \InvalidArgumentException( - sprintf( - 'Value "%s" for "by" param is not valid. Allowed values are %s.', - $by, - implode(', ', $allowedForBy) - ) - ); + switch ($version) { + case 'v5': + $this->request = new V5($url, $apiKey, $version, $site); + break; + case 'v4': + $this->request = new V4($url, $apiKey, $version, $site); + break; } - - return true; } - /** - * Fill params by site value - * - * @param string $site site code - * @param array $params input parameters - * - * @return array - */ - protected function fillSite($site, array $params) - { - if ($site) { - $params['site'] = $site; - } elseif ($this->siteCode) { - $params['site'] = $this->siteCode; - } - - return $params; - } + use CoreTrait; + use StatisticTrait; } diff --git a/lib/RetailCrm/Client/V4/Loader.php b/lib/RetailCrm/Client/V4/Loader.php new file mode 100644 index 0000000..bb749b7 --- /dev/null +++ b/lib/RetailCrm/Client/V4/Loader.php @@ -0,0 +1,68 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Client\V4; + +use RetailCrm\Http\Client; +use RetailCrm\Response\ApiResponse; +use RetailCrm\Traits\CoreTrait; +use RetailCrm\Traits\StatisticTrait; +use RetailCrm\Traits\V4; + +/** + * PHP version 5.4 + * + * API client class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +class Loader +{ + protected $siteCode; + protected $client; + + /** + * Init version based client + * + * @param string $url api url + * @param string $apiKey api key + * @param string $site site code + * + */ + public function __construct($url, $apiKey, $site = null) + { + if ('/' !== $url[strlen($url) - 1]) { + $url .= '/'; + } + + $url = $url . 'api/v4'; + + $this->client = new Client($url, ['apiKey' => $apiKey]); + $this->siteCode = $site; + } + + use V4\CustomersTrait; + use V4\DeliveryTrait; + use V4\MarketplaceTrait; + use V4\OrdersTrait; + use V4\PacksTrait; + use V4\ReferencesTrait; + use V4\StoresTrait; + use V4\TelephonyTrait; + use V4\UsersTrait; +} diff --git a/lib/RetailCrm/Client/V5/Loader.php b/lib/RetailCrm/Client/V5/Loader.php new file mode 100644 index 0000000..7e52a71 --- /dev/null +++ b/lib/RetailCrm/Client/V5/Loader.php @@ -0,0 +1,72 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Client\V5; + +use RetailCrm\Http\Client; +use RetailCrm\Response\ApiResponse; +use RetailCrm\Traits\CoreTrait; +use RetailCrm\Traits\StatisticTrait; +use RetailCrm\Traits\V5; + +/** + * PHP version 5.4 + * + * API client class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +class Loader +{ + protected $siteCode; + protected $client; + + /** + * Init version based client + * + * @param string $url api url + * @param string $apiKey api key + * @param string $site site code + * + */ + public function __construct($url, $apiKey, $site = null) + { + if ('/' !== $url[strlen($url) - 1]) { + $url .= '/'; + } + + $url = $url . 'api/v5'; + + $this->client = new Client($url, ['apiKey' => $apiKey]); + $this->siteCode = $site; + } + + + use V5\CustomersTrait; + use V5\CustomFieldsTrait; + use V5\DeliveryTrait; + use V5\MarketplaceTrait; + use V5\OrdersTrait; + use V5\PacksTrait; + use V5\ReferencesTrait; + use V5\SegmentsTrait; + use V5\StoresTrait; + use V5\TasksTrait; + use V5\TelephonyTrait; + use V5\UsersTrait; +} diff --git a/lib/RetailCrm/Exception/CurlException.php b/lib/RetailCrm/Exception/CurlException.php index 2524b4f..922a810 100644 --- a/lib/RetailCrm/Exception/CurlException.php +++ b/lib/RetailCrm/Exception/CurlException.php @@ -1,7 +1,7 @@ + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits; + +/** + * PHP version 5.4 + * + * CoreTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait CoreTrait +{ + /** + * Return current site + * + * @return string + */ + public function getSite() + { + return $this->siteCode; + } + + /** + * Set site + * + * @param string $site site code + * + * @return void + */ + public function setSite($site) + { + $this->siteCode = $site; + } + + /** + * Check ID parameter + * + * @param string $by identify by + * + * @throws \InvalidArgumentException + * + * @return bool + */ + protected function checkIdParameter($by) + { + $allowedForBy = [ + 'externalId', + 'id' + ]; + + if (!in_array($by, $allowedForBy, false)) { + throw new \InvalidArgumentException( + sprintf( + 'Value "%s" for "by" param is not valid. Allowed values are %s.', + $by, + implode(', ', $allowedForBy) + ) + ); + } + + return true; + } + + /** + * Fill params by site value + * + * @param string $site site code + * @param array $params input parameters + * + * @return array + */ + protected function fillSite($site, array $params) + { + if ($site) { + $params['site'] = $site; + } elseif ($this->siteCode) { + $params['site'] = $this->siteCode; + } + + return $params; + } +} diff --git a/lib/RetailCrm/Traits/StatisticTrait.php b/lib/RetailCrm/Traits/StatisticTrait.php new file mode 100644 index 0000000..657fbe6 --- /dev/null +++ b/lib/RetailCrm/Traits/StatisticTrait.php @@ -0,0 +1,48 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits; + +use RetailCrm\Response\ApiResponse; + +/** + * PHP version 5.4 + * + * StatisticTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait StatisticTrait +{ + /** + * Update CRM basic statistic + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function statisticUpdate() + { + return $this->client->makeRequest( + '/statistic/update', + $this->client::METHOD_GET + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/CustomersTrait.php b/lib/RetailCrm/Traits/V4/CustomersTrait.php new file mode 100644 index 0000000..5760a97 --- /dev/null +++ b/lib/RetailCrm/Traits/V4/CustomersTrait.php @@ -0,0 +1,235 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V4; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait CustomersTrait +{ + /** + * Returns filtered customers list + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function customersList(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/customers', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Create a customer + * + * @param array $customer customer data + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function customersCreate(array $customer, $site = null) + { + if (! count($customer)) { + throw new \InvalidArgumentException( + 'Parameter `customer` must contains a data' + ); + } + + return $this->client->makeRequest( + '/customers/create', + $this->client::METHOD_POST, + $this->fillSite($site, ['customer' => json_encode($customer)]) + ); + } + + /** + * Save customer IDs' (id and externalId) association in the CRM + * + * @param array $ids ids mapping + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function customersFixExternalIds(array $ids) + { + if (! count($ids)) { + throw new \InvalidArgumentException( + 'Method parameter must contains at least one IDs pair' + ); + } + + return $this->client->makeRequest( + '/customers/fix-external-ids', + $this->client::METHOD_POST, + ['customers' => json_encode($ids)] + ); + } + + /** + * Upload array of the customers + * + * @param array $customers array of customers + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function customersUpload(array $customers, $site = null) + { + if (! count($customers)) { + throw new \InvalidArgumentException( + 'Parameter `customers` must contains array of the customers' + ); + } + + return $this->client->makeRequest( + '/customers/upload', + $this->client::METHOD_POST, + $this->fillSite($site, ['customers' => json_encode($customers)]) + ); + } + + /** + * Get customer by id or externalId + * + * @param string $id customer identificator + * @param string $by (default: 'externalId') + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function customersGet($id, $by = 'externalId', $site = null) + { + $this->checkIdParameter($by); + + return $this->client->makeRequest( + "/customers/$id", + $this->client::METHOD_GET, + $this->fillSite($site, ['by' => $by]) + ); + } + + /** + * Edit a customer + * + * @param array $customer customer data + * @param string $by (default: 'externalId') + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function customersEdit(array $customer, $by = 'externalId', $site = null) + { + if (!count($customer)) { + throw new \InvalidArgumentException( + 'Parameter `customer` must contains a data' + ); + } + + $this->checkIdParameter($by); + + if (!array_key_exists($by, $customer)) { + throw new \InvalidArgumentException( + sprintf('Customer array must contain the "%s" parameter.', $by) + ); + } + + return $this->client->makeRequest( + sprintf('/customers/%s/edit', $customer[$by]), + $this->client::METHOD_POST, + $this->fillSite( + $site, + ['customer' => json_encode($customer), 'by' => $by] + ) + ); + } + + /** + * Get customers history + * @param array $filter + * @param null $page + * @param null $limit + * + * @return ApiResponse + */ + public function customersHistory(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/customers/history', + $this->client::METHOD_GET, + $parameters + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/DeliveryTrait.php b/lib/RetailCrm/Traits/V4/DeliveryTrait.php new file mode 100644 index 0000000..de1071a --- /dev/null +++ b/lib/RetailCrm/Traits/V4/DeliveryTrait.php @@ -0,0 +1,109 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V4; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait DeliveryTrait +{ + /** + * Get delivery settings + * + * @param string $code + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function deliverySettingsGet($code) + { + if (empty($code)) { + throw new \InvalidArgumentException('Parameter `code` must be set'); + } + + return $this->client->makeRequest( + "/delivery/generic/setting/$code", + $this->client::METHOD_GET + ); + } + + /** + * Edit delivery configuration + * + * @param array $configuration + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function deliverySettingsEdit(array $configuration) + { + if (!count($configuration) || empty($configuration['code'])) { + throw new \InvalidArgumentException( + 'Parameter `configuration` must contains a data & configuration `code` must be set' + ); + } + + return $this->client->makeRequest( + sprintf('/delivery/generic/setting/%s/edit', $configuration['code']), + $this->client::METHOD_POST, + ['configuration' => json_encode($configuration)] + ); + } + + /** + * Delivery tracking update + * + * @param string $code + * @param array $statusUpdate + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function deliveryTracking($code, array $statusUpdate) + { + if (empty($code)) { + throw new \InvalidArgumentException('Parameter `code` must be set'); + } + + if (!count($statusUpdate)) { + throw new \InvalidArgumentException( + 'Parameter `statusUpdate` must contains a data' + ); + } + + return $this->client->makeRequest( + sprintf('/delivery/generic/%s/tracking', $code), + $this->client::METHOD_POST, + ['statusUpdate' => json_encode($statusUpdate)] + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/MarketplaceTrait.php b/lib/RetailCrm/Traits/V4/MarketplaceTrait.php new file mode 100644 index 0000000..4249ae9 --- /dev/null +++ b/lib/RetailCrm/Traits/V4/MarketplaceTrait.php @@ -0,0 +1,56 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V4;; + +/** + * PHP version 5.4 + * + * MarketplaceTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait MarketplaceTrait +{ + + /** + * Edit marketplace configuration + * + * @param array $configuration + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function marketplaceSettingsEdit(array $configuration) + { + if (!count($configuration) || empty($configuration['code'])) { + throw new \InvalidArgumentException( + 'Parameter `configuration` must contains a data & configuration `code` must be set' + ); + } + + return $this->client->makeRequest( + sprintf('/marketplace/external/setting/%s/edit', $configuration['code']), + $this->client::METHOD_POST, + ['configuration' => json_encode($configuration)] + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/OrdersTrait.php b/lib/RetailCrm/Traits/V4/OrdersTrait.php new file mode 100644 index 0000000..b3a20bc --- /dev/null +++ b/lib/RetailCrm/Traits/V4/OrdersTrait.php @@ -0,0 +1,267 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V4; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait OrdersTrait +{ + + /** + * Returns filtered orders list + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersList(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/orders', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Create an order + * + * @param array $order order data + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersCreate(array $order, $site = null) + { + if (!count($order)) { + throw new \InvalidArgumentException( + 'Parameter `order` must contains a data' + ); + } + + return $this->client->makeRequest( + '/orders/create', + $this->client::METHOD_POST, + $this->fillSite($site, ['order' => json_encode($order)]) + ); + } + + /** + * Save order IDs' (id and externalId) association into CRM + * + * @param array $ids order identificators + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersFixExternalIds(array $ids) + { + if (! count($ids)) { + throw new \InvalidArgumentException( + 'Method parameter must contains at least one IDs pair' + ); + } + + return $this->client->makeRequest( + '/orders/fix-external-ids', + $this->client::METHOD_POST, + ['orders' => json_encode($ids) + ] + ); + } + + /** + * Returns statuses of the orders + * + * @param array $ids (default: array()) + * @param array $externalIds (default: array()) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersStatuses(array $ids = [], array $externalIds = []) + { + $parameters = []; + + if (count($ids)) { + $parameters['ids'] = $ids; + } + if (count($externalIds)) { + $parameters['externalIds'] = $externalIds; + } + + return $this->client->makeRequest( + '/orders/statuses', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Upload array of the orders + * + * @param array $orders array of orders + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersUpload(array $orders, $site = null) + { + if (!count($orders)) { + throw new \InvalidArgumentException( + 'Parameter `orders` must contains array of the orders' + ); + } + + return $this->client->makeRequest( + '/orders/upload', + $this->client::METHOD_POST, + $this->fillSite($site, ['orders' => json_encode($orders)]) + ); + } + + /** + * Get order by id or externalId + * + * @param string $id order identificator + * @param string $by (default: 'externalId') + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersGet($id, $by = 'externalId', $site = null) + { + $this->checkIdParameter($by); + + return $this->client->makeRequest( + "/orders/$id", + $this->client::METHOD_GET, + $this->fillSite($site, ['by' => $by]) + ); + } + + /** + * Edit an order + * + * @param array $order order data + * @param string $by (default: 'externalId') + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersEdit(array $order, $by = 'externalId', $site = null) + { + if (!count($order)) { + throw new \InvalidArgumentException( + 'Parameter `order` must contains a data' + ); + } + + $this->checkIdParameter($by); + + if (!array_key_exists($by, $order)) { + throw new \InvalidArgumentException( + sprintf('Order array must contain the "%s" parameter.', $by) + ); + } + + return $this->client->makeRequest( + sprintf('/orders/%s/edit', $order[$by]), + $this->client::METHOD_POST, + $this->fillSite( + $site, + ['order' => json_encode($order), 'by' => $by] + ) + ); + } + + /** + * Get orders history + * @param array $filter + * @param null $page + * @param null $limit + * + * @return ApiResponse + */ + public function ordersHistory(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/orders/history', + $this->client::METHOD_GET, + $parameters + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/PacksTrait.php b/lib/RetailCrm/Traits/V4/PacksTrait.php new file mode 100644 index 0000000..ab16954 --- /dev/null +++ b/lib/RetailCrm/Traits/V4/PacksTrait.php @@ -0,0 +1,197 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V4; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait PacksTrait +{ + /** + * Get orders assembly list + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersPacksList(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/orders/packs', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Create orders assembly + * + * @param array $pack pack data + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersPacksCreate(array $pack, $site = null) + { + if (!count($pack)) { + throw new \InvalidArgumentException( + 'Parameter `pack` must contains a data' + ); + } + + return $this->client->makeRequest( + '/orders/packs/create', + $this->client::METHOD_POST, + $this->fillSite($site, ['pack' => json_encode($pack)]) + ); + } + + /** + * Get orders assembly history + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersPacksHistory(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/orders/packs/history', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Get orders assembly by id + * + * @param string $id pack identificator + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersPacksGet($id) + { + if (empty($id)) { + throw new \InvalidArgumentException('Parameter `id` must be set'); + } + + return $this->client->makeRequest( + "/orders/packs/$id", + $this->client::METHOD_GET + ); + } + + /** + * Delete orders assembly by id + * + * @param string $id pack identificator + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersPacksDelete($id) + { + if (empty($id)) { + throw new \InvalidArgumentException('Parameter `id` must be set'); + } + + return $this->client->makeRequest( + sprintf('/orders/packs/%s/delete', $id), + $this->client::METHOD_POST + ); + } + + /** + * Edit orders assembly + * + * @param array $pack pack data + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersPacksEdit(array $pack, $site = null) + { + if (!count($pack) || empty($pack['id'])) { + throw new \InvalidArgumentException( + 'Parameter `pack` must contains a data & pack `id` must be set' + ); + } + + return $this->client->makeRequest( + sprintf('/orders/packs/%s/edit', $pack['id']), + $this->client::METHOD_POST, + $this->fillSite($site, ['pack' => json_encode($pack)]) + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/ReferencesTrait.php b/lib/RetailCrm/Traits/V4/ReferencesTrait.php new file mode 100644 index 0000000..d36c017 --- /dev/null +++ b/lib/RetailCrm/Traits/V4/ReferencesTrait.php @@ -0,0 +1,547 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V4; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait ReferencesTrait +{ + /** + * Returns available county list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function countriesList() + { + return $this->client->makeRequest( + '/reference/countries', + $this->client::METHOD_GET + ); + } + + /** + * Returns deliveryServices list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function deliveryServicesList() + { + return $this->client->makeRequest( + '/reference/delivery-services', + $this->client::METHOD_GET + ); + } + + /** + * Edit deliveryService + * + * @param array $data delivery service data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function deliveryServicesEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/delivery-services/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['deliveryService' => json_encode($data)] + ); + } + + /** + * Returns deliveryTypes list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function deliveryTypesList() + { + return $this->client->makeRequest( + '/reference/delivery-types', + $this->client::METHOD_GET + ); + } + + /** + * Edit deliveryType + * + * @param array $data delivery type data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function deliveryTypesEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/delivery-types/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['deliveryType' => json_encode($data)] + ); + } + + /** + * Returns orderMethods list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function orderMethodsList() + { + return $this->client->makeRequest( + '/reference/order-methods', + $this->client::METHOD_GET + ); + } + + /** + * Edit orderMethod + * + * @param array $data order method data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function orderMethodsEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/order-methods/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['orderMethod' => json_encode($data)] + ); + } + + /** + * Returns orderTypes list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function orderTypesList() + { + return $this->client->makeRequest( + '/reference/order-types', + $this->client::METHOD_GET + ); + } + + /** + * Edit orderType + * + * @param array $data order type data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function orderTypesEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/order-types/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['orderType' => json_encode($data)] + ); + } + + /** + * Returns paymentStatuses list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function paymentStatusesList() + { + return $this->client->makeRequest( + '/reference/payment-statuses', + $this->client::METHOD_GET + ); + } + + /** + * Edit paymentStatus + * + * @param array $data payment status data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function paymentStatusesEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/payment-statuses/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['paymentStatus' => json_encode($data)] + ); + } + + /** + * Returns paymentTypes list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function paymentTypesList() + { + return $this->client->makeRequest( + '/reference/payment-types', + $this->client::METHOD_GET + ); + } + + /** + * Edit paymentType + * + * @param array $data payment type data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function paymentTypesEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/payment-types/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['paymentType' => json_encode($data)] + ); + } + + /** + * Returns productStatuses list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function productStatusesList() + { + return $this->client->makeRequest( + '/reference/product-statuses', + $this->client::METHOD_GET + ); + } + + /** + * Edit productStatus + * + * @param array $data product status data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function productStatusesEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/product-statuses/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['productStatus' => json_encode($data)] + ); + } + + /** + * Returns sites list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function sitesList() + { + return $this->client->makeRequest( + '/reference/sites', + $this->client::METHOD_GET + ); + } + + /** + * Edit site + * + * @param array $data site data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function sitesEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/sites/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['site' => json_encode($data)] + ); + } + + /** + * Returns statusGroups list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function statusGroupsList() + { + return $this->client->makeRequest( + '/reference/status-groups', + $this->client::METHOD_GET + ); + } + + /** + * Returns statuses list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function statusesList() + { + return $this->client->makeRequest( + '/reference/statuses', + $this->client::METHOD_GET + ); + } + + /** + * Edit order status + * + * @param array $data status data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function statusesEdit(array $data) + { + if (!array_key_exists('code', $data)) { + throw new \InvalidArgumentException( + 'Data must contain "code" parameter.' + ); + } + + return $this->client->makeRequest( + sprintf('/reference/statuses/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['status' => json_encode($data)] + ); + } + + /** + * Returns stores list + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function storesList() + { + return $this->client->makeRequest( + '/reference/stores', + $this->client::METHOD_GET + ); + } + + /** + * Edit store + * + * @param array $data site data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function storesEdit(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/stores/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['store' => json_encode($data)] + ); + } + + /** + * Get prices types + * + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function pricesTypes() + { + return $this->client->makeRequest( + '/reference/price-types', + $this->client::METHOD_GET + ); + } + + /** + * Edit price type + * + * @param array $data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function pricesEdit(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/price-types/%s/edit', $data['code']), + $this->client::METHOD_POST, + ['priceType' => json_encode($data)] + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/StoresTrait.php b/lib/RetailCrm/Traits/V4/StoresTrait.php new file mode 100644 index 0000000..8e3d8a4 --- /dev/null +++ b/lib/RetailCrm/Traits/V4/StoresTrait.php @@ -0,0 +1,201 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V4; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait StoresTrait +{ + /** + * Get purchace prices & stock balance + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function storeInventories(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/store/inventories', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Get store settings + * + * @param string $code get settings code + * + * @return ApiResponse + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function storeSettingsGet($code) + { + if (empty($code)) { + throw new \InvalidArgumentException('Parameter `code` must be set'); + } + + return $this->client->makeRequest( + "/store/setting/$code", + $this->client::METHOD_GET + ); + } + + /** + * Edit store configuration + * + * @param array $configuration + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function storeSettingsEdit(array $configuration) + { + if (!count($configuration) || empty($configuration['code'])) { + throw new \InvalidArgumentException( + 'Parameter `configuration` must contains a data & configuration `code` must be set' + ); + } + + return $this->client->makeRequest( + sprintf('/store/setting/%s/edit', $configuration['code']), + $this->client::METHOD_POST, + ['configuration' => json_encode($configuration)] + ); + } + + /** + * Upload store inventories + * + * @param array $offers offers data + * @param string $site (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function storeInventoriesUpload(array $offers, $site = null) + { + if (!count($offers)) { + throw new \InvalidArgumentException( + 'Parameter `offers` must contains array of the offers' + ); + } + + return $this->client->makeRequest( + '/store/inventories/upload', + $this->client::METHOD_POST, + $this->fillSite($site, ['offers' => json_encode($offers)]) + ); + } + + /** + * Upload store prices + * + * @param array $prices prices data + * @param string $site default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function storePricesUpload(array $prices, $site = null) + { + if (!count($prices)) { + throw new \InvalidArgumentException( + 'Parameter `prices` must contains array of the prices' + ); + } + + return $this->client->makeRequest( + '/store/prices/upload', + $this->client::METHOD_POST, + $this->fillSite($site, ['prices' => json_encode($prices)]) + ); + } + + /** + * Get products + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function storeProducts(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/store/products', + $this->client::METHOD_GET, + $parameters + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/TelephonyTrait.php b/lib/RetailCrm/Traits/V4/TelephonyTrait.php new file mode 100644 index 0000000..81ae7ad --- /dev/null +++ b/lib/RetailCrm/Traits/V4/TelephonyTrait.php @@ -0,0 +1,260 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V4; + +/** + * PHP version 5.4 + * + * TelephonyTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait TelephonyTrait +{ + /** + * Get telephony settings + * + * @param string $code + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function telephonySettingsGet($code) + { + if (empty($code)) { + throw new \InvalidArgumentException('Parameter `code` must be set'); + } + + return $this->client->makeRequest( + "/telephony/setting/$code", + $this->client::METHOD_GET + ); + } + + /** + * Edit telephony settings + * + * @param string $code symbolic code + * @param string $clientId client id + * @param boolean $active telephony activity + * @param mixed $name service name + * @param mixed $makeCallUrl service init url + * @param mixed $image service logo url(svg file) + * + * @param array $additionalCodes + * @param array $externalPhones + * @param bool $allowEdit + * @param bool $inputEventSupported + * @param bool $outputEventSupported + * @param bool $hangupEventSupported + * @param bool $changeUserStatusUrl + * + * @return ApiResponse + */ + public function telephonySettingsEdit( + $code, + $clientId, + $active = false, + $name = false, + $makeCallUrl = false, + $image = false, + $additionalCodes = [], + $externalPhones = [], + $allowEdit = false, + $inputEventSupported = false, + $outputEventSupported = false, + $hangupEventSupported = false, + $changeUserStatusUrl = false + ) { + if (!isset($code)) { + throw new \InvalidArgumentException('Code must be set'); + } + + $parameters['code'] = $code; + + if (!isset($clientId)) { + throw new \InvalidArgumentException('client id must be set'); + } + + $parameters['clientId'] = $clientId; + + if (!isset($active)) { + $parameters['active'] = false; + } else { + $parameters['active'] = $active; + } + + if (!isset($name)) { + throw new \InvalidArgumentException('name must be set'); + } + + if (isset($name)) { + $parameters['name'] = $name; + } + + if (isset($makeCallUrl)) { + $parameters['makeCallUrl'] = $makeCallUrl; + } + + if (isset($image)) { + $parameters['image'] = $image; + } + + if (isset($additionalCodes)) { + $parameters['additionalCodes'] = $additionalCodes; + } + + if (isset($externalPhones)) { + $parameters['externalPhones'] = $externalPhones; + } + + if (isset($allowEdit)) { + $parameters['allowEdit'] = $allowEdit; + } + + if (isset($inputEventSupported)) { + $parameters['inputEventSupported'] = $inputEventSupported; + } + + if (isset($outputEventSupported)) { + $parameters['outputEventSupported'] = $outputEventSupported; + } + + if (isset($hangupEventSupported)) { + $parameters['hangupEventSupported'] = $hangupEventSupported; + } + + if (isset($changeUserStatusUrl)) { + $parameters['changeUserStatusUrl'] = $changeUserStatusUrl; + } + + return $this->client->makeRequest( + "/telephony/setting/$code/edit", + $this->client::METHOD_POST, + ['configuration' => json_encode($parameters)] + ); + } + + /** + * Call event + * + * @param string $phone phone number + * @param string $type call type + * @param array $codes + * @param string $hangupStatus + * @param string $externalPhone + * @param array $webAnalyticsData + * + * @return ApiResponse + * @internal param string $code additional phone code + * @internal param string $status call status + * + */ + public function telephonyCallEvent( + $phone, + $type, + $codes, + $hangupStatus, + $externalPhone = null, + $webAnalyticsData = [] + ) { + if (!isset($phone)) { + throw new \InvalidArgumentException('Phone number must be set'); + } + + if (!isset($type)) { + throw new \InvalidArgumentException('Type must be set (in|out|hangup)'); + } + + if (empty($codes)) { + throw new \InvalidArgumentException('Codes array must be set'); + } + + $parameters['phone'] = $phone; + $parameters['type'] = $type; + $parameters['codes'] = $codes; + $parameters['hangupStatus'] = $hangupStatus; + $parameters['callExternalId'] = $externalPhone; + $parameters['webAnalyticsData'] = $webAnalyticsData; + + + return $this->client->makeRequest( + '/telephony/call/event', + $this->client::METHOD_POST, + ['event' => json_encode($parameters)] + ); + } + + /** + * Upload calls + * + * @param array $calls calls data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function telephonyCallsUpload(array $calls) + { + if (!count($calls)) { + throw new \InvalidArgumentException( + 'Parameter `calls` must contains array of the calls' + ); + } + + return $this->client->makeRequest( + '/telephony/calls/upload', + $this->client::METHOD_POST, + ['calls' => json_encode($calls)] + ); + } + + /** + * Get call manager + * + * @param string $phone phone number + * @param bool $details detailed information + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function telephonyCallManager($phone, $details) + { + if (!isset($phone)) { + throw new \InvalidArgumentException('Phone number must be set'); + } + + $parameters['phone'] = $phone; + $parameters['details'] = isset($details) ? $details : 0; + + return $this->client->makeRequest( + '/telephony/manager', + $this->client::METHOD_GET, + $parameters + ); + } +} diff --git a/lib/RetailCrm/Traits/V4/UsersTrait.php b/lib/RetailCrm/Traits/V4/UsersTrait.php new file mode 100644 index 0000000..1f20c75 --- /dev/null +++ b/lib/RetailCrm/Traits/V4/UsersTrait.php @@ -0,0 +1,108 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V4; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait UsersTrait +{ + /** + * Returns users list + * + * @param array $filter + * @param null $page + * @param null $limit + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function usersList(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int)$page; + } + if (null !== $limit) { + $parameters['limit'] = (int)$limit; + } + + return $this->client->makeRequest( + '/users', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Get user groups + * + * @param null $page + * @param null $limit + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * + * @return ApiResponse + */ + public function usersGroups($page = null, $limit = null) + { + $parameters = []; + + if (null !== $page) { + $parameters['page'] = (int)$page; + } + if (null !== $limit) { + $parameters['limit'] = (int)$limit; + } + + return $this->client->makeRequest( + '/user-groups', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Returns user data + * + * @param integer $id user ID + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return ApiResponse + */ + public function usersGet($id) + { + return $this->client->makeRequest("/users/$id", $this->client::METHOD_GET); + } +} diff --git a/lib/RetailCrm/Traits/V5/CustomFieldsTrait.php b/lib/RetailCrm/Traits/V5/CustomFieldsTrait.php new file mode 100644 index 0000000..693ecef --- /dev/null +++ b/lib/RetailCrm/Traits/V5/CustomFieldsTrait.php @@ -0,0 +1,250 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +/** + * PHP version 5.4 + * + * CustomFieldsTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait CustomFieldsTrait +{ + /** + * Get custom fields list + * + * @param array $filter + * @param null $limit + * @param null $page + * + * @return ApiResponse + */ + public function customFieldsList(array $filter = [], $limit = null, $page = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/custom-fields', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Create custom field + * + * @param $entity + * @param $customField + * + * @return ApiResponse + */ + public function customFieldsCreate($entity, $customField) + { + if (!count($customField) || + empty($customField['code']) || + empty($customField['name']) || + empty($customField['type']) + ) { + throw new \InvalidArgumentException( + 'Parameter `customField` must contain a data & fields `code`, `name` & `type` must be set' + ); + } + + if (empty($entity) || $entity != 'customer' || $entity != 'order') { + throw new \InvalidArgumentException( + 'Parameter `entity` must contain a data & value must be `order` or `customer`' + ); + } + + return $this->client->makeRequest( + "/custom-fields/$entity/create", + $this->client::METHOD_POST, + ['customField' => json_encode($customField)] + ); + } + + /** + * Edit custom field + * + * @param $entity + * @param $customField + * + * @return ApiResponse + */ + public function customFieldsEdit($entity, $customField) + { + if (!count($customField) || empty($customField['code'])) { + throw new \InvalidArgumentException( + 'Parameter `customField` must contain a data & fields `code` must be set' + ); + } + + if (empty($entity) || $entity != 'customer' || $entity != 'order') { + throw new \InvalidArgumentException( + 'Parameter `entity` must contain a data & value must be `order` or `customer`' + ); + } + + return $this->client->makeRequest( + "/custom-fields/$entity/edit/{$customField['code']}", + $this->client::METHOD_POST, + ['customField' => json_encode($customField)] + ); + } + + /** + * Get custom field + * + * @param $entity + * @param $code + * + * @return ApiResponse + */ + public function customFieldsGet($entity, $code) + { + if (empty($code)) { + throw new \InvalidArgumentException( + 'Parameter `code` must be not empty' + ); + } + + if (empty($entity) || $entity != 'customer' || $entity != 'order') { + throw new \InvalidArgumentException( + 'Parameter `entity` must contain a data & value must be `order` or `customer`' + ); + } + + return $this->client->makeRequest( + "/custom-fields/$entity/$code", + $this->client::METHOD_GET + ); + } + + /** + * Get custom dictionaries list + * + * @param array $filter + * @param null $limit + * @param null $page + * + * @return ApiResponse + */ + public function customDictionariesList(array $filter = [], $limit = null, $page = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/custom-fields/dictionaries', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Create custom dictionary + * + * @param $customDictionary + * + * @return ApiResponse + */ + public function customDictionariesCreate($customDictionary) + { + if (!count($customDictionary) || + empty($customDictionary['code']) || + empty($customDictionary['elements']) + ) { + throw new \InvalidArgumentException( + 'Parameter `dictionary` must contain a data & fields `code` & `elemets` must be set' + ); + } + + return $this->client->makeRequest( + "/custom-fields/dictionaries/{$customDictionary['code']}/create", + $this->client::METHOD_POST, + ['customDictionary' => json_encode($customDictionary)] + ); + } + + /** + * Edit custom dictionary + * + * @param $customDictionary + * + * @return ApiResponse + */ + public function customDictionariesEdit($customDictionary) + { + if (!count($customDictionary) || + empty($customDictionary['code']) || + empty($customDictionary['elements']) + ) { + throw new \InvalidArgumentException( + 'Parameter `dictionary` must contain a data & fields `code` & `elemets` must be set' + ); + } + + return $this->client->makeRequest( + "/custom-fields/dictionaries/{$customDictionary['code']}/edit", + $this->client::METHOD_POST, + ['customDictionary' => json_encode($customDictionary)] + ); + } + + /** + * Get custom dictionary + * + * @param $code + * + * @return ApiResponse + */ + public function customDictionariesGet($code) + { + if (empty($code)) { + throw new \InvalidArgumentException( + 'Parameter `code` must be not empty' + ); + } + + return $this->client->makeRequest( + "/custom-fields/dictionaries/$code", + $this->client::METHOD_GET + ); + } +} diff --git a/lib/RetailCrm/Traits/V5/CustomersTrait.php b/lib/RetailCrm/Traits/V5/CustomersTrait.php new file mode 100644 index 0000000..6d53080 --- /dev/null +++ b/lib/RetailCrm/Traits/V5/CustomersTrait.php @@ -0,0 +1,60 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +use RetailCrm\Traits\V4\CustomersTrait as Previous; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait CustomersTrait +{ + use Previous; + + /** + * Combine customers + * + * @param array $customers + * @param array $resultCustomer + * + * @return ApiResponse + */ + public function customersCombine(array $customers, $resultCustomer) + { + + if (!count($customers) || !count($resultCustomer)) { + throw new \InvalidArgumentException( + 'Parameters `customers` & `resultCustomer` must contains a data' + ); + } + + return $this->client->makeRequest( + '/customers/combine', + $this->client::METHOD_POST, + [ + 'customers' => json_encode($customers), + 'resultCustomer' => json_encode($resultCustomer) + ] + ); + } +} diff --git a/lib/RetailCrm/Traits/V5/DeliveryTrait.php b/lib/RetailCrm/Traits/V5/DeliveryTrait.php new file mode 100644 index 0000000..e66cf2c --- /dev/null +++ b/lib/RetailCrm/Traits/V5/DeliveryTrait.php @@ -0,0 +1,33 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +use RetailCrm\Traits\V4\DeliveryTrait as Previous; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait DeliveryTrait +{ + use Previous; +} diff --git a/lib/RetailCrm/Traits/V5/MarketplaceTrait.php b/lib/RetailCrm/Traits/V5/MarketplaceTrait.php new file mode 100644 index 0000000..48d4faf --- /dev/null +++ b/lib/RetailCrm/Traits/V5/MarketplaceTrait.php @@ -0,0 +1,33 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +use RetailCrm\Traits\V4\MarketplaceTrait as Previous; + +/** + * PHP version 5.4 + * + * MarketplaceTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait MarketplaceTrait +{ + use Previous; +} diff --git a/lib/RetailCrm/Traits/V5/OrdersTrait.php b/lib/RetailCrm/Traits/V5/OrdersTrait.php new file mode 100644 index 0000000..b8db295 --- /dev/null +++ b/lib/RetailCrm/Traits/V5/OrdersTrait.php @@ -0,0 +1,131 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +use RetailCrm\Response\ApiResponse; +use RetailCrm\Traits\V4\OrdersTrait as Previous; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait OrdersTrait +{ + use Previous; + + /** + * Combine orders + * + * @param string $technique + * @param array $order + * @param array $resultOrder + * + * @return ApiResponse + */ + public function ordersCombine($order, $resultOrder, $technique = 'ours') + { + $techniques = ['ours', 'summ', 'theirs']; + + if (!count($order) || !count($resultOrder)) { + throw new \InvalidArgumentException( + 'Parameters `order` & `resultOrder` must contains a data' + ); + } + + if (!in_array($technique, $techniques)) { + throw new \InvalidArgumentException( + 'Parameter `technique` must be on of ours|summ|theirs' + ); + } + + return $this->client->makeRequest( + '/orders/combine', + $this->client::METHOD_POST, + [ + 'technique' => $technique, + 'order' => json_encode($order), + 'resultOrder' => json_encode($resultOrder) + ] + ); + } + + /** + * Create an order payment + * + * @param array $payment order data + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function ordersPaymentCreate(array $payment) + { + if (!count($payment)) { + throw new \InvalidArgumentException( + 'Parameter `payment` must contains a data' + ); + } + + return $this->client->makeRequest( + '/orders/payments/create', + $this->client::METHOD_POST, + ['payment' => json_encode($payment)] + ); + } + + /** + * Edit an order payment + * + * @param array $payment order data + * @param string $by by key + * @param null $site site code + * + * @return ApiResponse + */ + public function ordersPaymentEdit(array $payment, $by = 'id', $site = null) + { + if (!count($payment)) { + throw new \InvalidArgumentException( + 'Parameter `payment` must contains a data' + ); + } + + $this->checkIdParameter($by); + + if (!array_key_exists($by, $payment)) { + throw new \InvalidArgumentException( + sprintf('Order array must contain the "%s" parameter.', $by) + ); + } + + return $this->client->makeRequest( + sprintf('/orders/payments/%s/edit', $payment[$by]), + $this->client::METHOD_POST, + $this->fillSite( + $site, + ['payment' => json_encode($payment), 'by' => $by] + ) + ); + } +} diff --git a/lib/RetailCrm/Traits/V5/PacksTrait.php b/lib/RetailCrm/Traits/V5/PacksTrait.php new file mode 100644 index 0000000..fd36cfe --- /dev/null +++ b/lib/RetailCrm/Traits/V5/PacksTrait.php @@ -0,0 +1,33 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +use RetailCrm\Traits\V4\PacksTrait as Previous; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait PacksTrait +{ + use Previous; +} diff --git a/lib/RetailCrm/Traits/V5/ReferencesTrait.php b/lib/RetailCrm/Traits/V5/ReferencesTrait.php new file mode 100644 index 0000000..58f576b --- /dev/null +++ b/lib/RetailCrm/Traits/V5/ReferencesTrait.php @@ -0,0 +1,33 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +use RetailCrm\Traits\V4\ReferencesTrait as Previous; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait ReferencesTrait +{ + use Previous; +} diff --git a/lib/RetailCrm/Traits/V5/SegmentsTrait.php b/lib/RetailCrm/Traits/V5/SegmentsTrait.php new file mode 100644 index 0000000..d481fda --- /dev/null +++ b/lib/RetailCrm/Traits/V5/SegmentsTrait.php @@ -0,0 +1,59 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +/** + * PHP version 5.4 + * + * SegmentsTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait SegmentsTrait +{ + /** + * Get segments list + * + * @param array $filter + * @param null $limit + * @param null $page + * + * @return ApiResponse + */ + public function segmentsList(array $filter = [], $limit = null, $page = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/segments', + $this->client::METHOD_GET, + $parameters + ); + } +} diff --git a/lib/RetailCrm/Traits/V5/StoresTrait.php b/lib/RetailCrm/Traits/V5/StoresTrait.php new file mode 100644 index 0000000..c6f8fe6 --- /dev/null +++ b/lib/RetailCrm/Traits/V5/StoresTrait.php @@ -0,0 +1,67 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +use RetailCrm\Traits\V4\StoresTrait as Previous; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait StoresTrait +{ + use Previous; + + /** + * Get products groups + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * + * @throws \InvalidArgumentException + * @throws \RetailCrm\Exception\CurlException + * @throws \RetailCrm\Exception\InvalidJsonException + * + * @return ApiResponse + */ + public function storeProductsGroups(array $filter = [], $page = null, $limit = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/store/product-groups', + $this->client::METHOD_GET, + $parameters + ); + } +} diff --git a/lib/RetailCrm/Traits/V5/TasksTrait.php b/lib/RetailCrm/Traits/V5/TasksTrait.php new file mode 100644 index 0000000..6d9850e --- /dev/null +++ b/lib/RetailCrm/Traits/V5/TasksTrait.php @@ -0,0 +1,134 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait TasksTrait +{ + /** + * Get tasks list + * + * @param array $filter + * @param null $limit + * @param null $page + * + * @return ApiResponse + */ + public function tasksList(array $filter = [], $limit = null, $page = null) + { + $parameters = []; + + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest( + '/tasks', + $this->client::METHOD_GET, + $parameters + ); + } + + /** + * Create task + * + * @param array $task + * @param null $site + * + * @return ApiResponse + * + */ + public function tasksCreate($task, $site = null) + { + if (!count($task)) { + throw new \InvalidArgumentException( + 'Parameter `task` must contain a data' + ); + } + + return $this->client->makeRequest( + "/tasks/create", + $this->client::METHOD_POST, + $this->fillSite( + $site, + ['task' => json_encode($task)] + ) + ); + } + + /** + * Edit task + * + * @param array $task + * @param null $site + * + * @return ApiResponse + * + */ + public function tasksEdit($task, $site = null) + { + if (!count($task)) { + throw new \InvalidArgumentException( + 'Parameter `task` must contain a data' + ); + } + + return $this->client->makeRequest( + "/tasks/{$task['id']}/edit", + $this->client::METHOD_POST, + $this->fillSite( + $site, + ['task' => json_encode($task)] + ) + ); + } + + /** + * Get custom dictionary + * + * @param $id + * + * @return ApiResponse + */ + public function tasksGet($id) + { + if (empty($id)) { + throw new \InvalidArgumentException( + 'Parameter `id` must be not empty' + ); + } + + return $this->client->makeRequest( + "/tasks/$id", + $this->client::METHOD_GET + ); + } +} diff --git a/lib/RetailCrm/Traits/V5/TelephonyTrait.php b/lib/RetailCrm/Traits/V5/TelephonyTrait.php new file mode 100644 index 0000000..08e7f7d --- /dev/null +++ b/lib/RetailCrm/Traits/V5/TelephonyTrait.php @@ -0,0 +1,33 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +use RetailCrm\Traits\V4\TelephonyTrait as Previous; + +/** + * PHP version 5.4 + * + * TelephonyTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait TelephonyTrait +{ + use Previous; +} diff --git a/lib/RetailCrm/Traits/V5/UsersTrait.php b/lib/RetailCrm/Traits/V5/UsersTrait.php new file mode 100644 index 0000000..64560fa --- /dev/null +++ b/lib/RetailCrm/Traits/V5/UsersTrait.php @@ -0,0 +1,59 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Traits\V5; + +use RetailCrm\Response\ApiResponse; +use RetailCrm\Traits\V4\UsersTrait as Previous; + +/** + * PHP version 5.4 + * + * TaskTrait class + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +trait UsersTrait +{ + use Previous; + + /** + * Change user status + * + * @param integer $id user ID + * @param string $status user status + * + * @return ApiResponse + */ + public function usersStatus($id, $status) + { + $statuses = ["free", "busy", "dinner", "break"]; + + if (empty($status) || !in_array($status, $statuses)) { + throw new \InvalidArgumentException( + 'Parameter `status` must be not empty & must be equal one of these values: free|busy|dinner|break' + ); + } + + return $this->client->makeRequest( + "/users/$id/status", + $this->client::METHOD_POST, + ['status' => $status] + ); + } +} diff --git a/tests/RetailCrm/Test/TestCase.php b/tests/RetailCrm/Test/TestCase.php index c623330..69c16a0 100644 --- a/tests/RetailCrm/Test/TestCase.php +++ b/tests/RetailCrm/Test/TestCase.php @@ -1,7 +1,7 @@ array_key_exists('apiKey', $defaultParameters) ? $defaultParameters['apiKey'] : $_SERVER['CRM_API_KEY'] - ) + ] ); } } diff --git a/tests/RetailCrm/Tests/ApiClientCustomersTest.php b/tests/RetailCrm/Tests/ApiClientCustomersTest.php index 476654a..de5f06f 100644 --- a/tests/RetailCrm/Tests/ApiClientCustomersTest.php +++ b/tests/RetailCrm/Tests/ApiClientCustomersTest.php @@ -1,7 +1,7 @@ customersCreate(array( + $response = $client->customersCreate([ 'firstName' => self::FIRST_NAME, 'externalId' => $externalId, - )); + ]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(201, $response->getStatusCode()); static::assertTrue(is_int($response['id'])); - return array( + return [ 'id' => $response['id'], 'externalId' => $externalId, - ); + ]; } /** @@ -61,7 +61,7 @@ class ApiClientCustomersTest extends TestCase public function testCreateExceptionEmpty() { $client = static::getApiClient(); - $client->customersCreate(array()); + $client->customersCreate([]); } /** @@ -115,19 +115,19 @@ class ApiClientCustomersTest extends TestCase $client = static::getApiClient(); $response = $client->customersEdit( - array( + [ 'id' => 22342134, 'lastName' => '12345', - ), + ], 'id' ); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(404, $response->getStatusCode()); - $response = $client->customersEdit(array( + $response = $client->customersEdit([ 'externalId' => $ids['externalId'], 'lastName' => '12345', - )); + ]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(200, $response->getStatusCode()); static::assertTrue($response->isSuccessful()); @@ -140,7 +140,7 @@ class ApiClientCustomersTest extends TestCase public function testCustomersEditExceptionEmpty() { $client = static::getApiClient(); - $client->customersEdit(array(), 'asdf'); + $client->customersEdit([], 'asdf'); } /** @@ -150,7 +150,7 @@ class ApiClientCustomersTest extends TestCase public function testCustomersEditException() { $client = static::getApiClient(); - $client->customersEdit(array('id' => 678678678), 'asdf'); + $client->customersEdit(['id' => 678678678], 'asdf'); } /** @@ -165,14 +165,14 @@ class ApiClientCustomersTest extends TestCase static::assertTrue($response->isSuccessful()); static::assertTrue(isset($response['customers'])); - $response = $client->customersList(array(), 1, 300); + $response = $client->customersList([], 1, 300); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertFalse( $response->isSuccessful(), 'Pagination error' ); - $response = $client->customersList(array('maxOrdersCount' => 10), 1); + $response = $client->customersList(['maxOrdersCount' => 10], 1); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertTrue( $response->isSuccessful(), @@ -187,7 +187,7 @@ class ApiClientCustomersTest extends TestCase public function testCustomersFixExternalIdsException() { $client = static::getApiClient(); - $client->customersFixExternalIds(array()); + $client->customersFixExternalIds([]); } /** @@ -197,9 +197,9 @@ class ApiClientCustomersTest extends TestCase { $client = static::getApiClient(); - $response = $client->ordersCreate(array( + $response = $client->ordersCreate([ 'firstName' => 'Aaa111', - )); + ]); static::assertTrue( $response->isSuccessful(), @@ -215,9 +215,9 @@ class ApiClientCustomersTest extends TestCase $id = $response['order']['customer']['id']; $externalId = 'asdf' . time(); - $response = $client->customersFixExternalIds(array( - array('id' => $id, 'externalId' => $externalId) - )); + $response = $client->customersFixExternalIds([ + ['id' => $id, 'externalId' => $externalId] + ]); static::assertTrue( $response->isSuccessful(), @@ -248,7 +248,7 @@ class ApiClientCustomersTest extends TestCase public function testCustomersUploadExceptionEmpty() { $client = static::getApiClient(); - $client->customersUpload(array()); + $client->customersUpload([]); } /** @@ -261,16 +261,16 @@ class ApiClientCustomersTest extends TestCase $externalIdA = 'upload-a-' . time(); $externalIdB = 'upload-b-' . time(); - $response = $client->customersUpload(array( - array( + $response = $client->customersUpload([ + [ 'externalId' => $externalIdA, 'firstName' => 'Aaa', - ), - array( + ], + [ 'externalId' => $externalIdB, 'lastName' => 'Bbb', - ), - )); + ], + ]); static::assertTrue( $response->isSuccessful(), 'Got customer' @@ -292,41 +292,41 @@ class ApiClientCustomersTest extends TestCase { $client = static::getApiClient(); - $responseCreateFirst = $client->customersCreate(array( + $responseCreateFirst = $client->customersCreate([ 'firstName' => 'Aaa111', 'externalId' => 'AA-' . time(), - 'phones' => array( - array( + 'phones' => [ + [ 'number' => '+79999999990' - ) - ) - )); + ] + ] + ]); static::assertTrue( $responseCreateFirst->isSuccessful(), 'Got customer' ); - $responseCreateSecond = $client->customersCreate(array( + $responseCreateSecond = $client->customersCreate([ 'firstName' => 'Aaa222', 'externalId' => 'BB-' . time(), - 'phones' => array( - array( + 'phones' => [ + [ 'number' => '+79999999991' - ) - ) - )); + ] + ] + ]); static::assertTrue( $responseCreateSecond->isSuccessful(), 'Got customer' ); - $customers = array( - array('id' => $responseCreateFirst['id']) - ); + $customers = [ + ['id' => $responseCreateFirst['id']] + ]; - $resultCustomer = array('id' => $responseCreateSecond['id']); + $resultCustomer = ['id' => $responseCreateSecond['id']]; $response = $client->customersCombine($customers, $resultCustomer); diff --git a/tests/RetailCrm/Tests/ApiClientMarketplaceTest.php b/tests/RetailCrm/Tests/ApiClientMarketplaceTest.php index 9378bb2..ce225ef 100644 --- a/tests/RetailCrm/Tests/ApiClientMarketplaceTest.php +++ b/tests/RetailCrm/Tests/ApiClientMarketplaceTest.php @@ -1,7 +1,7 @@ marketplaceSettingsEdit( - array( + [ 'name' => self::SNAME, 'code' => self::SCODE, 'logo' => 'http://download.retailcrm.pro/logos/setup.svg', 'active' => 'true' - ) + ] ); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - static::assertTrue(in_array($response->getStatusCode(), array(200, 201))); + static::assertTrue(in_array($response->getStatusCode(), [200, 201])); static::assertTrue($response->isSuccessful()); } } diff --git a/tests/RetailCrm/Tests/ApiClientOrdersTest.php b/tests/RetailCrm/Tests/ApiClientOrdersTest.php index ca406be..7bfad5b 100644 --- a/tests/RetailCrm/Tests/ApiClientOrdersTest.php +++ b/tests/RetailCrm/Tests/ApiClientOrdersTest.php @@ -1,7 +1,7 @@ ordersCreate(array( + $response = $client->ordersCreate([ 'firstName' => self::FIRST_NAME, 'externalId' => $externalId, - )); + ]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(201, $response->getStatusCode()); static::assertTrue(is_int($response['id'])); - return array( + return [ 'id' => $response['id'], 'externalId' => $externalId, - ); + ]; } /** @@ -59,7 +59,7 @@ class ApiClientOrdersTest extends TestCase public function testOrdersCreateExceptionEmpty() { $client = static::getApiClient(); - $client->ordersCreate(array()); + $client->ordersCreate([]); } /** @@ -77,14 +77,14 @@ class ApiClientOrdersTest extends TestCase static::assertEquals(400, $response->getStatusCode()); static::assertFalse($response->isSuccessful()); - $response = $client->ordersStatuses(array(), array('asdf')); + $response = $client->ordersStatuses([], ['asdf']); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(200, $response->getStatusCode()); static::assertTrue($response->isSuccessful()); $orders = $response['orders']; static::assertEquals(0, sizeof($orders)); - $response = $client->ordersStatuses(array(), array($ids['externalId'])); + $response = $client->ordersStatuses([], [$ids['externalId']]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(200, $response->getStatusCode()); static::assertTrue($response->isSuccessful()); @@ -92,14 +92,14 @@ class ApiClientOrdersTest extends TestCase static::assertEquals(1, sizeof($orders)); static::assertEquals('new', $orders[0]['status']); - $response = $client->ordersStatuses(array($ids['id']), array($ids['externalId'])); + $response = $client->ordersStatuses([$ids['id']], [$ids['externalId']]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(200, $response->getStatusCode()); static::assertTrue($response->isSuccessful()); $orders = $response['orders']; static::assertEquals(1, sizeof($orders)); - $response = $client->ordersStatuses(array($ids['id'])); + $response = $client->ordersStatuses([$ids['id']]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(200, $response->getStatusCode()); static::assertTrue($response->isSuccessful()); @@ -158,19 +158,19 @@ class ApiClientOrdersTest extends TestCase $client = static::getApiClient(); $response = $client->ordersEdit( - array( + [ 'id' => 22342134, 'lastName' => '12345', - ), + ], 'id' ); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(404, $response->getStatusCode()); - $response = $client->ordersEdit(array( + $response = $client->ordersEdit([ 'externalId' => $ids['externalId'], 'lastName' => '12345', - )); + ]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(200, $response->getStatusCode()); static::assertTrue($response->isSuccessful()); @@ -183,7 +183,7 @@ class ApiClientOrdersTest extends TestCase public function testOrdersEditExceptionEmpty() { $client = static::getApiClient(); - $client->ordersEdit(array(), 'asdf'); + $client->ordersEdit([], 'asdf'); } /** @@ -193,7 +193,7 @@ class ApiClientOrdersTest extends TestCase public function testOrdersEditException() { $client = static::getApiClient(); - $client->ordersEdit(array('id' => 678678678), 'asdf'); + $client->ordersEdit(['id' => 678678678], 'asdf'); } /** @@ -221,14 +221,14 @@ class ApiClientOrdersTest extends TestCase static::assertTrue($response->isSuccessful()); static::assertTrue(isset($response['orders'])); - $response = $client->ordersList(array(), 1, 300); + $response = $client->ordersList([], 1, 300); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertFalse( $response->isSuccessful(), 'Pagination error' ); - $response = $client->ordersList(array('paymentStatus' => 'paid'), 1); + $response = $client->ordersList(['paymentStatus' => 'paid'], 1); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); } @@ -239,7 +239,7 @@ class ApiClientOrdersTest extends TestCase public function testOrdersFixExternalIdsException() { $client = static::getApiClient(); - $client->ordersFixExternalIds(array()); + $client->ordersFixExternalIds([]); } /** @@ -249,9 +249,9 @@ class ApiClientOrdersTest extends TestCase { $client = static::getApiClient(); - $response = $client->ordersCreate(array( + $response = $client->ordersCreate([ 'firstName' => 'Aaa', - )); + ]); static::assertTrue( $response->isSuccessful(), 'Order created' @@ -260,9 +260,9 @@ class ApiClientOrdersTest extends TestCase $id = $response['id']; $externalId = 'asdf' . time(); - $response = $client->ordersFixExternalIds(array( - array('id' => $id, 'externalId' => $externalId) - )); + $response = $client->ordersFixExternalIds([ + ['id' => $id, 'externalId' => $externalId] + ]); static::assertTrue( $response->isSuccessful(), @@ -293,7 +293,7 @@ class ApiClientOrdersTest extends TestCase public function testOrdersUploadExceptionEmpty() { $client = static::getApiClient(); - $client->ordersUpload(array()); + $client->ordersUpload([]); } /** @@ -306,16 +306,16 @@ class ApiClientOrdersTest extends TestCase $externalIdA = 'upload-a-' . time(); $externalIdB = 'upload-b-' . time(); - $response = $client->ordersUpload(array( - array( + $response = $client->ordersUpload([ + [ 'externalId' => $externalIdA, 'firstName' => 'Aaa', - ), - array( + ], + [ 'externalId' => $externalIdB, 'lastName' => 'Bbb', - ), - )); + ], + ]); static::assertTrue( $response->isSuccessful(), 'Got order' @@ -385,14 +385,14 @@ class ApiClientOrdersTest extends TestCase 'Got order' ); - $payment = array( + $payment = [ 'externalId' => $externalId, - 'order' => array('id' => $responseCreateFirst['id']), + 'order' => ['id' => $responseCreateFirst['id']], 'amount' => 1200, 'comment' => 'test payment', 'type' => 'cash', 'status' => 'paid' - ); + ]; $response = $client->ordersPaymentCreate($payment); @@ -401,14 +401,14 @@ class ApiClientOrdersTest extends TestCase 'Got payment' ); - $paymentEdit = array( + $paymentEdit = [ 'id' => $response['id'], 'externalId' => $externalId, 'amount' => 1500, 'comment' => 'test payment!', 'type' => 'cash', 'status' => 'paid' - ); + ]; $responseAgain = $client->ordersPaymentEdit($paymentEdit); diff --git a/tests/RetailCrm/Tests/ApiClientPacksTest.php b/tests/RetailCrm/Tests/ApiClientPacksTest.php index 1acbde6..b6a1842 100644 --- a/tests/RetailCrm/Tests/ApiClientPacksTest.php +++ b/tests/RetailCrm/Tests/ApiClientPacksTest.php @@ -1,7 +1,7 @@ 12, 'store' => 'test', 'quantity' => 2 - ); + ]; $response = $client->ordersPacksCreate($pack); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); diff --git a/tests/RetailCrm/Tests/ApiClientPricesTest.php b/tests/RetailCrm/Tests/ApiClientPricesTest.php index 649c215..e688ba8 100644 --- a/tests/RetailCrm/Tests/ApiClientPricesTest.php +++ b/tests/RetailCrm/Tests/ApiClientPricesTest.php @@ -1,7 +1,7 @@ pricesEdit( - array( + [ 'code' => $this->code, 'name' => $this->code, 'ordering' => 500, 'active' => true - ) + ] ); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); @@ -94,7 +94,7 @@ class ApiClientPricesTest extends TestCase public function testPricesUploadExceptionEmpty() { $client = static::getApiClient(); - $client->storePricesUpload(array()); + $client->storePricesUpload([]); } /** @@ -107,26 +107,26 @@ class ApiClientPricesTest extends TestCase $xmlIdA = 'upload-a-' . time(); $xmlIdB = 'upload-b-' . time(); - $response = $client->storePricesUpload(array( - array( + $response = $client->storePricesUpload([ + [ 'xmlId' => $xmlIdA, - 'prices' => array( - array( + 'prices' => [ + [ 'code' => $this->code, 'price' => 1700 - ) - ) - ), - array( + ] + ] + ], + [ 'xmlId' => $xmlIdB, - 'prices' => array( - array( + 'prices' => [ + [ 'code' => $this->code, 'price' => 1500 - ) - ) - ), - )); + ] + ] + ], + ]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(200, $response->getStatusCode()); diff --git a/tests/RetailCrm/Tests/ApiClientReferenceTest.php b/tests/RetailCrm/Tests/ApiClientReferenceTest.php index cfbc75b..aacf540 100644 --- a/tests/RetailCrm/Tests/ApiClientReferenceTest.php +++ b/tests/RetailCrm/Tests/ApiClientReferenceTest.php @@ -1,7 +1,7 @@ $method(array()); + $client->$method([]); } /** @@ -74,11 +74,11 @@ class ApiClientReferenceTest extends TestCase $code = 'dict-' . strtolower($name) . '-' . time(); $method = $name . 'Edit'; - $params = array( + $params = [ 'code' => $code, 'name' => 'Aaa' . $code, 'active' => false - ); + ]; if ($name == 'statuses') { $params['group'] = 'new'; } @@ -86,15 +86,15 @@ class ApiClientReferenceTest extends TestCase $response = $client->$method($params); /* @var \RetailCrm\Response\ApiResponse $response */ - static::assertTrue(in_array($response->getStatusCode(), array(200, 201))); + static::assertTrue(in_array($response->getStatusCode(), [200, 201])); - $response = $client->$method(array( + $response = $client->$method([ 'code' => $code, 'name' => 'Bbb' . $code, 'active' => false - )); + ]); - static::assertTrue(in_array($response->getStatusCode(), array(200, 201))); + static::assertTrue(in_array($response->getStatusCode(), [200, 201])); } /** @@ -108,11 +108,11 @@ class ApiClientReferenceTest extends TestCase $code = 'dict-' . strtolower($name) . '-' . time(); $method = $name . 'Edit'; - $params = array( + $params = [ 'code' => $code, 'name' => 'Aaa', 'active' => false - ); + ]; $response = $client->$method($params); /* @var \RetailCrm\Response\ApiResponse $response */ @@ -121,11 +121,11 @@ class ApiClientReferenceTest extends TestCase if ($code == $client->getSite()) { $method = $name . 'Edit'; - $params = array( + $params = [ 'code' => $code, 'name' => 'Aaa' . time(), 'active' => false - ); + ]; $response = $client->$method($params); static::assertEquals(200, $response->getStatusCode()); @@ -137,18 +137,18 @@ class ApiClientReferenceTest extends TestCase */ public function getListDictionaries() { - return array( - array('deliveryServices'), - array('deliveryTypes'), - array('orderMethods'), - array('orderTypes'), - array('paymentStatuses'), - array('paymentTypes'), - array('productStatuses'), - array('statusGroups'), - array('statuses'), - array('sites'), - ); + return [ + ['deliveryServices'], + ['deliveryTypes'], + ['orderMethods'], + ['orderTypes'], + ['paymentStatuses'], + ['paymentTypes'], + ['productStatuses'], + ['statusGroups'], + ['statuses'], + ['sites'], + ]; } /** @@ -156,15 +156,15 @@ class ApiClientReferenceTest extends TestCase */ public function getEditDictionaries() { - return array( - array('deliveryServices'), - array('deliveryTypes'), - array('orderMethods'), - array('orderTypes'), - array('paymentStatuses'), - array('paymentTypes'), - array('productStatuses'), - array('statuses'), - ); + return [ + ['deliveryServices'], + ['deliveryTypes'], + ['orderMethods'], + ['orderTypes'], + ['paymentStatuses'], + ['paymentTypes'], + ['productStatuses'], + ['statuses'], + ]; } } diff --git a/tests/RetailCrm/Tests/ApiClientStoreTest.php b/tests/RetailCrm/Tests/ApiClientStoreTest.php index 118ab83..f3855d4 100644 --- a/tests/RetailCrm/Tests/ApiClientStoreTest.php +++ b/tests/RetailCrm/Tests/ApiClientStoreTest.php @@ -1,7 +1,7 @@ storesEdit(array('name' => self::SNAME, 'code' => self::SCODE)); + $response = $client->storesEdit(['name' => self::SNAME, 'code' => self::SCODE]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - static::assertTrue(in_array($response->getStatusCode(), array(200, 201))); + static::assertTrue(in_array($response->getStatusCode(), [200, 201])); static::assertTrue($response->isSuccessful()); } @@ -67,7 +67,7 @@ class ApiClientStoreTest extends TestCase public function testInventoriesException() { $client = static::getApiClient(); - $client->storeInventoriesUpload(array()); + $client->storeInventoriesUpload([]); } /** @@ -77,28 +77,28 @@ class ApiClientStoreTest extends TestCase { $client = static::getApiClient(); - $response = $client->storeInventoriesUpload(array( - array( + $response = $client->storeInventoriesUpload([ + [ 'externalId' => 'pTKIKAeghYzX21HTdzFCe1', - 'stores' => array( - array( + 'stores' => [ + [ 'code' => self::SCODE, 'available' => 10, 'purchasePrice' => 1700 - ) - ) - ), - array( + ] + ] + ], + [ 'externalId' => 'JQIvcrCtiSpOV3AAfMiQB3', - 'stores' => array( - array( + 'stores' => [ + [ 'code' => self::SCODE, 'available' => 20, 'purchasePrice' => 1500 - ) - ) - ), - )); + ] + ] + ], + ]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertTrue($response->isSuccessful()); @@ -114,18 +114,18 @@ class ApiClientStoreTest extends TestCase $externalIdA = 'upload-a-' . time(); $externalIdB = 'upload-b-' . time(); - $response = $client->storeInventoriesUpload(array( - array( + $response = $client->storeInventoriesUpload([ + [ 'externalId' => $externalIdA, 'available' => 10, 'purchasePrice' => 1700 - ), - array( + ], + [ 'externalId' => $externalIdB, 'available' => 20, 'purchasePrice' => 1500 - ), - )); + ], + ]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); static::assertEquals(400, $response->getStatusCode()); static::assertTrue(isset($response['errorMsg']), $response['errorMsg']); diff --git a/tests/RetailCrm/Tests/ApiClientTasksTest.php b/tests/RetailCrm/Tests/ApiClientTasksTest.php index bb21b2c..6b85389 100644 --- a/tests/RetailCrm/Tests/ApiClientTasksTest.php +++ b/tests/RetailCrm/Tests/ApiClientTasksTest.php @@ -1,7 +1,7 @@ tasksCreate(array()); + $client->tasksCreate([]); } public function testTasksCRU() { $client = static::getApiClient(); - $task = array( + $task = [ 'text' => 'test task', 'commentary' => 'test task commentary', 'performerId' => $_SERVER['CRM_USER_ID'], 'complete' => false - ); + ]; $responseCreate = $client->tasksCreate($task); diff --git a/tests/RetailCrm/Tests/ApiClientTelephonyTest.php b/tests/RetailCrm/Tests/ApiClientTelephonyTest.php index 88c650b..48c4b1b 100644 --- a/tests/RetailCrm/Tests/ApiClientTelephonyTest.php +++ b/tests/RetailCrm/Tests/ApiClientTelephonyTest.php @@ -1,7 +1,7 @@ $_SERVER['CRM_USER_ID'], 'code' => '101')), - array(array('siteCode' => 'api-client-php', 'externalPhone' => '+74950000000')) + [['userId' => $_SERVER['CRM_USER_ID'], 'code' => '101']], + [['siteCode' => 'api-client-php', 'externalPhone' => '+74950000000']] ); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - static::assertTrue(in_array($response->getStatusCode(), array(200, 201))); + static::assertTrue(in_array($response->getStatusCode(), [200, 201])); static::assertTrue($response->isSuccessful()); } @@ -89,7 +89,7 @@ class ApiClientTelephonyTest extends TestCase $response = $client->telephonyCallEvent( '+79999999999', 'in', - array('101'), + ['101'], 'failed', '+74950000000' @@ -112,8 +112,8 @@ class ApiClientTelephonyTest extends TestCase $client = static::getApiClient(); $response = $client->telephonyCallsUpload( - array( - array( + [ + [ 'date' => '2016-07-22 00:18:00', 'type' => 'in', 'phone' => '+79999999999', @@ -121,8 +121,8 @@ class ApiClientTelephonyTest extends TestCase 'result' => 'answered', 'externalId' => rand(10, 100), 'recordUrl' => 'http://download.retailcrm.pro/api-client-files/beep1.mp3' - ), - array( + ], + [ 'date' => '2016-07-22 00:24:00', 'type' => 'in', 'phone' => '+79999999999', @@ -130,8 +130,8 @@ class ApiClientTelephonyTest extends TestCase 'result' => 'answered', 'externalId' => rand(10, 100), 'recordUrl' => 'http://download.retailcrm.pro/api-client-files/beep2.mp3' - ) - ) + ] + ] ); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); diff --git a/tests/RetailCrm/Tests/ApiClientTest.php b/tests/RetailCrm/Tests/ApiClientTest.php index 1bc5d6e..fccb99d 100644 --- a/tests/RetailCrm/Tests/ApiClientTest.php +++ b/tests/RetailCrm/Tests/ApiClientTest.php @@ -1,7 +1,7 @@ usersList(); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - static::assertTrue(in_array($response->getStatusCode(), array(200, 201))); + static::assertTrue(in_array($response->getStatusCode(), [200, 201])); static::assertTrue($response->isSuccessful()); } @@ -49,7 +49,7 @@ class ApiClientUsersTest extends TestCase $response = $client->usersGet($_SERVER["CRM_USER_ID"]); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - static::assertTrue(in_array($response->getStatusCode(), array(200, 201))); + static::assertTrue(in_array($response->getStatusCode(), [200, 201])); static::assertTrue($response->isSuccessful()); } @@ -62,7 +62,7 @@ class ApiClientUsersTest extends TestCase $response = $client->usersStatus($_SERVER["CRM_USER_ID"], 'dinner'); static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response); - static::assertTrue(in_array($response->getStatusCode(), array(200, 201))); + static::assertTrue(in_array($response->getStatusCode(), [200, 201])); static::assertTrue($response->isSuccessful()); } } diff --git a/tests/RetailCrm/Tests/Http/ClientTest.php b/tests/RetailCrm/Tests/Http/ClientTest.php index 28f4d10..36b3bd7 100644 --- a/tests/RetailCrm/Tests/Http/ClientTest.php +++ b/tests/RetailCrm/Tests/Http/ClientTest.php @@ -1,7 +1,7 @@ '123')); + $client = new Client('http://demo.retailcrm.ru/api/' . ApiClient::VERSION, ['apiKey' => '123']); return $client; } @@ -65,8 +65,8 @@ class ClientTest extends TestCase */ public function testRequestWrongUrl() { - $client = new Client('https://asdf.df', array()); - $client->makeRequest('/a', Client::METHOD_GET, array()); + $client = new Client('https://asdf.df', []); + $client->makeRequest('/a', Client::METHOD_GET, []); } /** diff --git a/tests/RetailCrm/Tests/Response/ApiResponseTest.php b/tests/RetailCrm/Tests/Response/ApiResponseTest.php index 80bc6dc..c5ebf41 100644 --- a/tests/RetailCrm/Tests/Response/ApiResponseTest.php +++ b/tests/RetailCrm/Tests/Response/ApiResponseTest.php @@ -1,7 +1,7 @@