From 4a68135e3323d4a7f5ff8583768db8d7dcaefc50 Mon Sep 17 00:00:00 2001 From: Dima Uryvskiy Date: Fri, 25 Feb 2022 10:40:06 +0300 Subject: [PATCH] Delete deprecated API V4. Refactoring API V5 and history getting method --- CHANGELOG.md | 7 + VERSION | 2 +- .../api/class-wc-retailcrm-client-v4.php | 1867 ----------------- .../api/class-wc-retailcrm-client-v5.php | 342 +-- src/include/class-wc-retailcrm-base.php | 6 +- src/include/class-wc-retailcrm-history.php | 45 +- src/include/class-wc-retailcrm-orders.php | 2 +- src/include/class-wc-retailcrm-plugin.php | 5 +- .../class-wc-retailcrm-paginated-request.php | 121 -- src/readme.txt | 11 +- src/retailcrm.php | 7 +- src/uninstall.php | 2 +- 12 files changed, 229 insertions(+), 2188 deletions(-) delete mode 100644 src/include/api/class-wc-retailcrm-client-v4.php delete mode 100644 src/include/components/class-wc-retailcrm-paginated-request.php diff --git a/CHANGELOG.md b/CHANGELOG.md index eadbc49..674c881 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 2022-02-24 4.4.2 +* Delete deprecated API V4. Refactoring API V5 and history getting method +* Fix bug with use xmlId +* Add order number transfer CMS -> CRM by history +* Add documentation for registering client functionality +* Delete legacy code for update customer name and surname + ## 2022-01-17 4.4.1 * Added functionality to skip some orders statuses * Improved the create/update method when registering customers diff --git a/VERSION b/VERSION index 4f3470c..f939222 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.4.1 \ No newline at end of file +4.4.2 \ No newline at end of file diff --git a/src/include/api/class-wc-retailcrm-client-v4.php b/src/include/api/class-wc-retailcrm-client-v4.php deleted file mode 100644 index 1781e9a..0000000 --- a/src/include/api/class-wc-retailcrm-client-v4.php +++ /dev/null @@ -1,1867 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://retailcrm.ru/docs/Developers/ApiVersion4 - */ - -if (!class_exists('WC_Retailcrm_Request')) { - include_once(WC_Integration_Retailcrm::checkCustomFile('include/api/class-wc-retailcrm-request.php')); -} - -if (!class_exists('WC_Retailcrm_Response')) { - include_once(WC_Integration_Retailcrm::checkCustomFile('include/api/class-wc-retailcrm-response.php')); -} - -class WC_Retailcrm_Client_V4 -{ - protected $client; - - /** - * Site code - */ - protected $siteCode; - - /** - * Client creating - * - * @param string $url api url - * @param string $apiKey api key - * @param string $site site code - * - * @throws \InvalidArgumentException - */ - public function __construct($url, $apiKey, $version = null, $site = null) - { - if ('/' !== $url[strlen($url) - 1]) { - $url .= '/'; - } - - $url = $version == null ? $url . 'api' : $url . 'api/' . $version; - - $this->client = new WC_Retailcrm_Request($url, array('apiKey' => $apiKey)); - $this->siteCode = $site; - } - - /** - * Returns api versions list - * - * @return WC_Retailcrm_Response - */ - public function apiVersions() - { - return $this->client->makeRequest('/api-versions', WC_Retailcrm_Request::METHOD_GET); - } - - /** - * Returns users list - * - * @param array $filter - * @param null $page - * @param null $limit - * - * @throws WC_Retailcrm_Exception_Json - * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_GET, - $parameters - ); - } - - /** - * Get user groups - * - * @param null $page - * @param null $limit - * - * @throws WC_Retailcrm_Exception_Json - * @throws WC_Retailcrm_Exception_Curl - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_GET, - $parameters - ); - } - - /** - * Returns user data - * - * @param integer $id user ID - * - * @throws WC_Retailcrm_Exception_Json - * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException - * - * @return WC_Retailcrm_Response - */ - public function usersGet($id) - { - return $this->client->makeRequest("/users/$id", WC_Retailcrm_Request::METHOD_GET); - } - - /** - * Returns filtered orders list - * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_GET, - $parameters - ); - } - - /** - * Create a order - * - * @param array $order order data - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_POST, - $this->fillSite($site, array('order' => json_encode($order))) - ); - } - - /** - * Save order IDs' (id and externalId) association in the CRM - * - * @param array $ids order identificators - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::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 WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_GET, - $parameters - ); - } - - /** - * Upload array of the orders - * - * @param array $orders array of orders - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::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 WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function ordersGet($id, $by = 'externalId', $site = null) - { - $this->checkIdParameter($by); - - return $this->client->makeRequest( - "/orders/$id", - WC_Retailcrm_Request::METHOD_GET, - $this->fillSite($site, array('by' => $by)) - ); - } - - /** - * Edit a order - * - * @param array $order order data - * @param string $by (default: 'externalId') - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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]), - WC_Retailcrm_Request::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 WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_GET, - $parameters - ); - } - - /** - * Returns filtered customers list - * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_GET, - $parameters - ); - } - - /** - * Create a customer - * - * @param array $customer customer data - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::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 WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::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 WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::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 WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function customersGet($id, $by = 'externalId', $site = null) - { - $this->checkIdParameter($by); - - return $this->client->makeRequest( - "/customers/$id", - WC_Retailcrm_Request::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 WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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]), - WC_Retailcrm_Request::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 WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::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 WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_GET, - $parameters - ); - } - - /** - * Create orders assembly - * - * @param array $pack pack data - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::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 WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_GET, - $parameters - ); - } - - /** - * Get orders assembly by id - * - * @param string $id pack identificator - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function ordersPacksGet($id) - { - if (empty($id)) { - throw new \InvalidArgumentException('Parameter `id` must be set'); - } - - return $this->client->makeRequest( - "/orders/packs/$id", - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Delete orders assembly by id - * - * @param string $id pack identificator - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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), - WC_Retailcrm_Request::METHOD_POST - ); - } - - /** - * Edit orders assembly - * - * @param array $pack pack data - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::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 WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_GET, - $parameters - ); - } - - /** - * Get store settings - * - * @param string $code get settings code - * - * @return WC_Retailcrm_Response - * @throws WC_Retailcrm_Exception_Json - * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException - * - * @return WC_Retailcrm_Response - */ - public function storeSettingsGet($code) - { - if (empty($code)) { - throw new \InvalidArgumentException('Parameter `code` must be set'); - } - - return $this->client->makeRequest( - "/store/setting/$code", - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit store configuration - * - * @param array $configuration - * - * @throws WC_Retailcrm_Exception_Json - * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('configuration' => json_encode($configuration)) - ); - } - - /** - * Upload store inventories - * - * @param array $offers offers data - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::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 WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::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 WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_GET, - $parameters - ); - } - - /** - * Get delivery settings - * - * @param string $code - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function deliverySettingsGet($code) - { - if (empty($code)) { - throw new \InvalidArgumentException('Parameter `code` must be set'); - } - - return $this->client->makeRequest( - "/delivery/generic/setting/$code", - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit delivery configuration - * - * @param array $configuration - * - * @throws WC_Retailcrm_Exception_Json - * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('configuration' => json_encode($configuration)) - ); - } - - /** - * Delivery tracking update - * - * @param string $code - * @param array $statusUpdate - * - * @throws WC_Retailcrm_Exception_Json - * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException - * - * @return WC_Retailcrm_Response - */ - 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), - WC_Retailcrm_Request::METHOD_POST, - array('statusUpdate' => json_encode($statusUpdate)) - ); - } - - /** - * Returns available county list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function countriesList() - { - return $this->client->makeRequest( - '/reference/countries', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Returns deliveryServices list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function deliveryServicesList() - { - return $this->client->makeRequest( - '/reference/delivery-services', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit deliveryService - * - * @param array $data delivery service data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('deliveryService' => json_encode($data)) - ); - } - - /** - * Returns deliveryTypes list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function deliveryTypesList() - { - return $this->client->makeRequest( - '/reference/delivery-types', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit deliveryType - * - * @param array $data delivery type data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('deliveryType' => json_encode($data)) - ); - } - - /** - * Returns orderMethods list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function orderMethodsList() - { - return $this->client->makeRequest( - '/reference/order-methods', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit orderMethod - * - * @param array $data order method data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('orderMethod' => json_encode($data)) - ); - } - - /** - * Returns orderTypes list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function orderTypesList() - { - return $this->client->makeRequest( - '/reference/order-types', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit orderType - * - * @param array $data order type data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('orderType' => json_encode($data)) - ); - } - - /** - * Returns paymentStatuses list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function paymentStatusesList() - { - return $this->client->makeRequest( - '/reference/payment-statuses', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit paymentStatus - * - * @param array $data payment status data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('paymentStatus' => json_encode($data)) - ); - } - - /** - * Returns paymentTypes list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function paymentTypesList() - { - return $this->client->makeRequest( - '/reference/payment-types', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit paymentType - * - * @param array $data payment type data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('paymentType' => json_encode($data)) - ); - } - - /** - * Returns productStatuses list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function productStatusesList() - { - return $this->client->makeRequest( - '/reference/product-statuses', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit productStatus - * - * @param array $data product status data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('productStatus' => json_encode($data)) - ); - } - - /** - * Returns sites list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function sitesList() - { - return $this->client->makeRequest( - '/reference/sites', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit site - * - * @param array $data site data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('site' => json_encode($data)) - ); - } - - /** - * Returns statusGroups list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function statusGroupsList() - { - return $this->client->makeRequest( - '/reference/status-groups', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Returns statuses list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function statusesList() - { - return $this->client->makeRequest( - '/reference/statuses', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit order status - * - * @param array $data status data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('status' => json_encode($data)) - ); - } - - /** - * Returns stores list - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function storesList() - { - return $this->client->makeRequest( - '/reference/stores', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit store - * - * @param array $data site data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('store' => json_encode($data)) - ); - } - - /** - * Get prices types - * - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function pricesTypes() - { - return $this->client->makeRequest( - '/reference/price-types', - WC_Retailcrm_Request::METHOD_GET - ); - } - - /** - * Edit price type - * - * @param array $data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('priceType' => json_encode($data)) - ); - } - - /** - * Get telephony settings - * - * @param string $code - * - * @throws WC_Retailcrm_Exception_Json - * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException - * - * @return WC_Retailcrm_Response - */ - public function telephonySettingsGet($code) - { - if (empty($code)) { - throw new \InvalidArgumentException('Parameter `code` must be set'); - } - - return $this->client->makeRequest( - "/telephony/setting/$code", - WC_Retailcrm_Request::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 WC_Retailcrm_Response - */ - 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", - WC_Retailcrm_Request::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 WC_Retailcrm_Response - * @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', - WC_Retailcrm_Request::METHOD_POST, - array('event' => json_encode($parameters)) - ); - } - - /** - * Upload calls - * - * @param array $calls calls data - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_POST, - array('calls' => json_encode($calls)) - ); - } - - /** - * Get call manager - * - * @param string $phone phone number - * @param bool $details detailed information - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - 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', - WC_Retailcrm_Request::METHOD_GET, - $parameters - ); - } - - /** - * Edit marketplace configuration - * - * @param array $configuration - * - * @throws WC_Retailcrm_Exception_Json - * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException - * - * @return WC_Retailcrm_Response - */ - 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']), - WC_Retailcrm_Request::METHOD_POST, - array('configuration' => json_encode($configuration)) - ); - } - - /** - * Update CRM basic statistic - * - * @throws \InvalidArgumentException - * @throws WC_Retailcrm_Exception_Curl - * @throws WC_Retailcrm_Exception_Json - * - * @return WC_Retailcrm_Response - */ - public function statisticUpdate() - { - return $this->client->makeRequest( - '/statistic/update', - WC_Retailcrm_Request::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; - } - - /** - * Check ID parameter - * - * @param string $by identify by - * - * @throws \InvalidArgumentException - * - * @return bool - */ - protected function checkIdParameter($by) - { - $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) - ) - ); - } - - 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/src/include/api/class-wc-retailcrm-client-v5.php b/src/include/api/class-wc-retailcrm-client-v5.php index 593a043..2065794 100644 --- a/src/include/api/class-wc-retailcrm-client-v5.php +++ b/src/include/api/class-wc-retailcrm-client-v5.php @@ -1,4 +1,5 @@ client = new WC_Retailcrm_Request($url, array('apiKey' => $apiKey)); - $this->unversionedClient = new WC_Retailcrm_Request($unversionedUrl, array('apiKey' => $apiKey)); + $this->client = new WC_Retailcrm_Request($url, ['apiKey' => $apiKey]); + $this->unversionedClient = new WC_Retailcrm_Request($unversionedUrl, ['apiKey' => $apiKey]); $this->siteCode = $site; } @@ -86,9 +87,10 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function customersCorporateList(array $filter= array(), $page = null, $limit = null) + public function customersCorporateList(array $filter = [], $page = null, $limit = null) { - $parameters= array(); + $parameters = []; + if (count($filter)) { $parameters['filter'] = $filter; } @@ -98,10 +100,10 @@ class WC_Retailcrm_Client_V5 if (null !== $limit) { $parameters['limit'] = (int) $limit; } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( '/customers-corporate', - "GET", + 'GET', $parameters ); } @@ -125,11 +127,11 @@ class WC_Retailcrm_Client_V5 'Parameter `customerCorporate` must contains a data' ); } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( '/customers-corporate/create', - "POST", - $this->fillSite($site, array('customerCorporate' => json_encode($customerCorporate))) + 'POST', + $this->fillSite($site, ['customerCorporate' => json_encode($customerCorporate)]) ); } @@ -151,11 +153,11 @@ class WC_Retailcrm_Client_V5 'Method parameter must contains at least one IDs pair' ); } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( '/customers-corporate/fix-external-ids', - "POST", - array('customersCorporate' => json_encode($ids)) + 'POST', + ['customersCorporate' => json_encode($ids)] ); } @@ -176,7 +178,6 @@ class WC_Retailcrm_Client_V5 'filter' => $filter, ]; - /* @noinspection PhpUndefinedMethodInspection */ return $this->client->makeRequest( '/customers-corporate/history', WC_Retailcrm_Request::METHOD_GET, @@ -197,9 +198,10 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function customersCorporateNotesList(array $filter= array(), $page = null, $limit = null) + public function customersCorporateNotesList(array $filter = [], $page = null, $limit = null) { - $parameters= array(); + $parameters = []; + if (count($filter)) { $parameters['filter'] = $filter; } @@ -209,10 +211,10 @@ class WC_Retailcrm_Client_V5 if (null !== $limit) { $parameters['limit'] = (int) $limit; } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( '/customers-corporate/notes', - "GET", + 'GET', $parameters ); } @@ -236,18 +238,18 @@ class WC_Retailcrm_Client_V5 'Customer identifier must be set' ); } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( '/customers-corporate/notes/create', - "POST", - $this->fillSite($site, array('note' => json_encode($note))) + 'POST', + $this->fillSite($site, ['note' => json_encode($note)]) ); } /** * Delete corporate customer note * - * @param integer $id + * @param int $id * * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl @@ -262,10 +264,10 @@ class WC_Retailcrm_Client_V5 'Note id must be set' ); } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( "/customers-corporate/notes/$id/delete", - "POST" + 'POST' ); } @@ -288,11 +290,11 @@ class WC_Retailcrm_Client_V5 'Parameter `customersCorporate` must contains array of the corporate customers' ); } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( '/customers-corporate/upload', - "POST", - $this->fillSite($site, array('customersCorporate' => json_encode($customersCorporate))) + 'POST', + $this->fillSite($site, ['customersCorporate' => json_encode($customersCorporate)]) ); } @@ -312,11 +314,11 @@ class WC_Retailcrm_Client_V5 public function customersCorporateGet($id, $by = 'externalId', $site = null) { $this->checkIdParameter($by); - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( "/customers-corporate/$id", - "GET", - $this->fillSite($site, array('by' => $by)) + 'GET', + $this->fillSite($site, ['by' => $by ]) ); } @@ -338,14 +340,16 @@ class WC_Retailcrm_Client_V5 */ public function customersCorporateAddresses( $id, - array $filter= array(), + array $filter = [], $page = null, $limit = null, $by = 'externalId', $site = null ) { $this->checkIdParameter($by); - $parameters = array('by' => $by); + + $parameters = ['by' => $by]; + if (count($filter)) { $parameters['filter'] = $filter; } @@ -355,10 +359,10 @@ class WC_Retailcrm_Client_V5 if (null !== $limit) { $parameters['limit'] = (int) $limit; } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( "/customers-corporate/$id/addresses", - "GET", + 'GET', $this->fillSite($site, $parameters) ); } @@ -377,13 +381,12 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function customersCorporateAddressesCreate($id, array $address= array(), $by = 'externalId', $site = null) + public function customersCorporateAddressesCreate($id, array $address = [], $by = 'externalId', $site = null) { - /* @noinspection PhpUndefinedMethodInspection */ return $this->client->makeRequest( "/customers-corporate/$id/addresses/create", - "POST", - $this->fillSite($site, array('address' => json_encode($address), 'by' => $by)) + 'POST', + $this->fillSite($site, ['address' => json_encode($address), 'by' => $by ]) ); } @@ -406,13 +409,15 @@ class WC_Retailcrm_Client_V5 public function customersCorporateAddressesEdit( $customerId, $addressId, - array $address= array(), + array $address = [], $customerBy = 'externalId', $addressBy = 'externalId', $site = null ) { $addressFiltered = array_filter($address); - if ((count(array_keys($addressFiltered)) <= 1) + + if ( + (count(array_keys($addressFiltered)) <= 1) && (!isset($addressFiltered['text']) || (isset($addressFiltered['text']) && empty($addressFiltered['text'])) ) @@ -421,15 +426,15 @@ class WC_Retailcrm_Client_V5 'Parameter `address` must contain address text or all other address field' ); } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( "/customers-corporate/$customerId/addresses/$addressId/edit", - "POST", - $this->fillSite($site, array( + 'POST', + $this->fillSite($site, [ 'address' => json_encode($address), 'by' => $customerBy, 'entityBy' => $addressBy - )) + ]) ); } @@ -451,14 +456,16 @@ class WC_Retailcrm_Client_V5 */ public function customersCorporateCompanies( $id, - array $filter= array(), + array $filter = [], $page = null, $limit = null, $by = 'externalId', $site = null ) { $this->checkIdParameter($by); - $parameters = array('by' => $by); + + $parameters = ['by' => $by]; + if (count($filter)) { $parameters['filter'] = $filter; } @@ -468,10 +475,10 @@ class WC_Retailcrm_Client_V5 if (null !== $limit) { $parameters['limit'] = (int) $limit; } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( "/customers-corporate/$id/companies", - "GET", + 'GET', $this->fillSite($site, $parameters) ); } @@ -490,13 +497,12 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function customersCorporateCompaniesCreate($id, array $company= array(), $by = 'externalId', $site = null) + public function customersCorporateCompaniesCreate($id, array $company = [], $by = 'externalId', $site = null) { - /* @noinspection PhpUndefinedMethodInspection */ return $this->client->makeRequest( "/customers-corporate/$id/companies/create", - "POST", - $this->fillSite($site, array('company' => json_encode($company), 'by' => $by)) + 'POST', + $this->fillSite($site, ['company' => json_encode($company), 'by' => $by]) ); } @@ -519,20 +525,19 @@ class WC_Retailcrm_Client_V5 public function customersCorporateCompaniesEdit( $customerId, $companyId, - array $company= array(), + array $company = [], $customerBy = 'externalId', $companyBy = 'externalId', $site = null ) { - /* @noinspection PhpUndefinedMethodInspection */ return $this->client->makeRequest( "/customers-corporate/$customerId/companies/$companyId/edit", - "POST", - $this->fillSite($site, array( + 'POST', + $this->fillSite($site, [ 'company' => json_encode($company), 'by' => $customerBy, 'entityBy' => $companyBy - )) + ]) ); } @@ -554,14 +559,16 @@ class WC_Retailcrm_Client_V5 */ public function customersCorporateContacts( $id, - array $filter= array(), + array $filter = [], $page = null, $limit = null, $by = 'externalId', $site = null ) { $this->checkIdParameter($by); - $parameters = array('by' => $by); + + $parameters = ['by' => $by]; + if (count($filter)) { $parameters['filter'] = $filter; } @@ -571,10 +578,10 @@ class WC_Retailcrm_Client_V5 if (null !== $limit) { $parameters['limit'] = (int) $limit; } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( "/customers-corporate/$id/contacts", - "GET", + 'GET', $this->fillSite($site, $parameters) ); } @@ -593,13 +600,12 @@ class WC_Retailcrm_Client_V5 * * @throws InvalidArgumentException */ - public function customersCorporateContactsCreate($id, array $contact= array(), $by = 'externalId', $site = null) + public function customersCorporateContactsCreate($id, array $contact = [], $by = 'externalId', $site = null) { - /* @noinspection PhpUndefinedMethodInspection */ return $this->client->makeRequest( "/customers-corporate/$id/contacts/create", - "POST", - $this->fillSite($site, array('contact' => json_encode($contact), 'by' => $by)) + 'POST', + $this->fillSite($site, ['contact' => json_encode($contact), 'by' => $by]) ); } @@ -622,20 +628,19 @@ class WC_Retailcrm_Client_V5 public function customersCorporateContactsEdit( $customerId, $contactId, - array $contact= array(), + array $contact = [], $customerBy = 'externalId', $contactBy = 'externalId', $site = null ) { - /* @noinspection PhpUndefinedMethodInspection */ return $this->client->makeRequest( "/customers-corporate/$customerId/contacts/$contactId/edit", - "POST", - $this->fillSite($site, array( + 'POST', + $this->fillSite($site, [ 'contact' => json_encode($contact), 'by' => $customerBy, 'entityBy' => $contactBy - )) + ]) ); } @@ -665,13 +670,13 @@ class WC_Retailcrm_Client_V5 sprintf('Corporate customer array must contain the "%s" parameter.', $by) ); } - /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( sprintf('/customers-corporate/%s/edit', $customerCorporate[$by]), - "POST", + 'POST', $this->fillSite( $site, - array('customerCorporate' => json_encode($customerCorporate), 'by' => $by) + ['customerCorporate' => json_encode($customerCorporate), 'by' => $by] ) ); } @@ -689,9 +694,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function usersList(array $filter = array(), $page = null, $limit = null) + public function usersList(array $filter = [], $page = null, $limit = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; @@ -713,7 +718,7 @@ class WC_Retailcrm_Client_V5 /** * Returns user data * - * @param integer $id user ID + * @param int $id user ID * * @throws WC_Retailcrm_Exception_Json * @throws WC_Retailcrm_Exception_Curl @@ -729,14 +734,14 @@ class WC_Retailcrm_Client_V5 /** * Change user status * - * @param integer $id user ID + * @param int $id user ID * @param string $status user status * * @return WC_Retailcrm_Response */ public function usersStatus($id, $status) { - $statuses = array("free", "busy", "dinner", "break"); + $statuses = ['free', 'busy', 'dinner', 'break']; if (empty($status) || !in_array($status, $statuses)) { throw new InvalidArgumentException( @@ -747,7 +752,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( "/users/$id/status", WC_Retailcrm_Request::METHOD_POST, - array('status' => $status) + ['status' => $status] ); } @@ -760,9 +765,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function segmentsList(array $filter = array(), $limit = null, $page = null) + public function segmentsList(array $filter = [], $limit = null, $page = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; @@ -790,9 +795,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function customFieldsList(array $filter = array(), $limit = null, $page = null) + public function customFieldsList(array $filter = [], $limit = null, $page = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; @@ -821,7 +826,8 @@ class WC_Retailcrm_Client_V5 */ public function customFieldsCreate($entity, $customField) { - if (!count($customField) || + if ( + !count($customField) || empty($customField['code']) || empty($customField['name']) || empty($customField['type']) @@ -840,7 +846,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( "/custom-fields/$entity/create", WC_Retailcrm_Request::METHOD_POST, - array('customField' => json_encode($customField)) + ['customField' => json_encode($customField)] ); } @@ -869,7 +875,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( "/custom-fields/$entity/edit/{$customField['code']}", WC_Retailcrm_Request::METHOD_POST, - array('customField' => json_encode($customField)) + ['customField' => json_encode($customField)] ); } @@ -888,9 +894,9 @@ class WC_Retailcrm_Client_V5 'Parameter `code` must be not empty' ); } - - if (empty($entity) || !in_array($entity, array('customer', 'order', 'customer_corporate', 'company'))) { - throw new \InvalidArgumentException( + + if (empty($entity) || !in_array($entity, ['customer', 'order', 'customer_corporate', 'company'])) { + throw new InvalidArgumentException( sprintf( 'Parameter `entity` must contain a data & value must be %s', '`order`, `customer`, `customer_corporate` or `company`' @@ -913,9 +919,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function customDictionariesList(array $filter = array(), $limit = null, $page = null) + public function customDictionariesList(array $filter = [], $limit = null, $page = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; @@ -943,7 +949,8 @@ class WC_Retailcrm_Client_V5 */ public function customDictionariesCreate($customDictionary) { - if (!count($customDictionary) || + if ( + !count($customDictionary) || empty($customDictionary['code']) || empty($customDictionary['elements']) ) { @@ -955,7 +962,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( "/custom-fields/dictionaries/{$customDictionary['code']}/create", WC_Retailcrm_Request::METHOD_POST, - array('customDictionary' => json_encode($customDictionary)) + ['customDictionary' => json_encode($customDictionary)] ); } @@ -968,7 +975,8 @@ class WC_Retailcrm_Client_V5 */ public function customDictionariesEdit($customDictionary) { - if (!count($customDictionary) || + if ( + !count($customDictionary) || empty($customDictionary['code']) || empty($customDictionary['elements']) ) { @@ -980,7 +988,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( "/custom-fields/dictionaries/{$customDictionary['code']}/edit", WC_Retailcrm_Request::METHOD_POST, - array('customDictionary' => json_encode($customDictionary)) + ['customDictionary' => json_encode($customDictionary)] ); } @@ -1018,9 +1026,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function ordersList(array $filter = array(), $page = null, $limit = null) + public function ordersList(array $filter = [], $page = null, $limit = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; @@ -1040,7 +1048,7 @@ class WC_Retailcrm_Client_V5 } /** - * Create a order + * Create an order * * @param array $order order data * @param string $site (default: null) @@ -1062,7 +1070,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/orders/create', WC_Retailcrm_Request::METHOD_POST, - $this->fillSite($site, array('order' => json_encode($order))) + $this->fillSite($site, ['order' => json_encode($order)]) ); } @@ -1088,8 +1096,9 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/orders/fix-external-ids', WC_Retailcrm_Request::METHOD_POST, - array('orders' => json_encode($ids) - ) + [ + 'orders' => json_encode($ids) + ] ); } @@ -1105,9 +1114,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function ordersStatuses(array $ids = array(), array $externalIds = array()) + public function ordersStatuses(array $ids = [], array $externalIds = []) { - $parameters = array(); + $parameters = []; if (count($ids)) { $parameters['ids'] = $ids; @@ -1146,7 +1155,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/orders/upload', WC_Retailcrm_Request::METHOD_POST, - $this->fillSite($site, array('orders' => json_encode($orders))) + $this->fillSite($site, ['orders' => json_encode($orders)]) ); } @@ -1170,7 +1179,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( "/orders/$id", WC_Retailcrm_Request::METHOD_GET, - $this->fillSite($site, array('by' => $by)) + $this->fillSite($site, ['by' => $by]) ); } @@ -1208,7 +1217,7 @@ class WC_Retailcrm_Client_V5 WC_Retailcrm_Request::METHOD_POST, $this->fillSite( $site, - array('order' => json_encode($order), 'by' => $by) + ['order' => json_encode($order), 'by' => $by] ) ); } @@ -1248,7 +1257,7 @@ class WC_Retailcrm_Client_V5 */ public function ordersCombine($order, $resultOrder, $technique = 'ours') { - $techniques = array('ours', 'summ', 'theirs'); + $techniques = ['ours', 'summ', 'theirs']; if (!count($order) || !count($resultOrder)) { throw new InvalidArgumentException( @@ -1265,11 +1274,11 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/orders/combine', WC_Retailcrm_Request::METHOD_POST, - array( + [ 'technique' => $technique, 'order' => json_encode($order), 'resultOrder' => json_encode($resultOrder) - ) + ] ); } @@ -1295,7 +1304,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/orders/payments/create', WC_Retailcrm_Request::METHOD_POST, - array('payment' => json_encode($payment)) + ['payment' => json_encode($payment)] ); } @@ -1329,7 +1338,7 @@ class WC_Retailcrm_Client_V5 WC_Retailcrm_Request::METHOD_POST, $this->fillSite( $site, - array('payment' => json_encode($payment), 'by' => $by) + ['payment' => json_encode($payment), 'by' => $by] ) ); } @@ -1368,9 +1377,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function customersList(array $filter = array(), $page = null, $limit = null) + public function customersList(array $filter = [], $page = null, $limit = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; @@ -1412,7 +1421,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/customers/create', WC_Retailcrm_Request::METHOD_POST, - $this->fillSite($site, array('customer' => json_encode($customer))) + $this->fillSite($site, ['customer' => json_encode($customer)]) ); } @@ -1438,7 +1447,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/customers/fix-external-ids', WC_Retailcrm_Request::METHOD_POST, - array('customers' => json_encode($ids)) + ['customers' => json_encode($ids)] ); } @@ -1465,7 +1474,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/customers/upload', WC_Retailcrm_Request::METHOD_POST, - $this->fillSite($site, array('customers' => json_encode($customers))) + $this->fillSite($site, ['customers' => json_encode($customers)]) ); } @@ -1489,7 +1498,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( "/customers/$id", WC_Retailcrm_Request::METHOD_GET, - $this->fillSite($site, array('by' => $by)) + $this->fillSite($site, ['by' => $by]) ); } @@ -1527,7 +1536,7 @@ class WC_Retailcrm_Client_V5 WC_Retailcrm_Request::METHOD_POST, $this->fillSite( $site, - array('customer' => json_encode($customer), 'by' => $by) + ['customer' => json_encode($customer), 'by' => $by] ) ); } @@ -1576,10 +1585,10 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/customers/combine', WC_Retailcrm_Request::METHOD_POST, - array( + [ 'customers' => json_encode($customers), 'resultCustomer' => json_encode($resultCustomer) - ) + ] ); } @@ -1596,9 +1605,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function customersNotesList(array $filter = array(), $page = null, $limit = null) + public function customersNotesList(array $filter = [], $page = null, $limit = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; } @@ -1637,14 +1646,14 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/customers/notes/create', WC_Retailcrm_Request::METHOD_POST, - $this->fillSite($site, array('note' => json_encode($note))) + $this->fillSite($site, ['note' => json_encode($note)]) ); } /** * Delete customer note * - * @param integer $id + * @param int $id * * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl @@ -1678,9 +1687,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function ordersPacksList(array $filter = array(), $page = null, $limit = null) + public function ordersPacksList(array $filter = [], $page = null, $limit = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; @@ -1722,7 +1731,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/orders/packs/create', WC_Retailcrm_Request::METHOD_POST, - $this->fillSite($site, array('pack' => json_encode($pack))) + $this->fillSite($site, ['pack' => json_encode($pack)]) ); } @@ -1823,7 +1832,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/orders/packs/%s/edit', $pack['id']), WC_Retailcrm_Request::METHOD_POST, - $this->fillSite($site, array('pack' => json_encode($pack))) + $this->fillSite($site, ['pack' => json_encode($pack)]) ); } @@ -1836,9 +1845,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function tasksList(array $filter = array(), $limit = null, $page = null) + public function tasksList(array $filter = [], $limit = null, $page = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; @@ -1875,11 +1884,11 @@ class WC_Retailcrm_Client_V5 } return $this->client->makeRequest( - "/tasks/create", + '/tasks/create', WC_Retailcrm_Request::METHOD_POST, $this->fillSite( $site, - array('task' => json_encode($task)) + ['task' => json_encode($task)] ) ); } @@ -1906,7 +1915,7 @@ class WC_Retailcrm_Client_V5 WC_Retailcrm_Request::METHOD_POST, $this->fillSite( $site, - array('task' => json_encode($task)) + ['task' => json_encode($task)] ) ); } @@ -1945,9 +1954,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function storeProductsGroups(array $filter = array(), $page = null, $limit = null) + public function storeProductsGroups(array $filter = [], $page = null, $limit = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; @@ -1979,9 +1988,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function storeInventories(array $filter = array(), $page = null, $limit = null) + public function storeInventories(array $filter = [], $page = null, $limit = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; @@ -2073,7 +2082,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/store/inventories/upload', WC_Retailcrm_Request::METHOD_POST, - $this->fillSite($site, array('offers' => json_encode($offers))) + $this->fillSite($site, ['offers' => json_encode($offers)]) ); } @@ -2090,9 +2099,9 @@ class WC_Retailcrm_Client_V5 * * @return WC_Retailcrm_Response */ - public function storeProducts(array $filter = array(), $page = null, $limit = null) + public function storeProducts(array $filter = [], $page = null, $limit = null) { - $parameters = array(); + $parameters = []; if (count($filter)) { $parameters['filter'] = $filter; @@ -2156,7 +2165,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/delivery/generic/setting/%s/edit', $configuration['code']), WC_Retailcrm_Request::METHOD_POST, - array('configuration' => json_encode($configuration)) + ['configuration' => json_encode($configuration)] ); } @@ -2247,7 +2256,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/reference/delivery-services/%s/edit', $data['code']), WC_Retailcrm_Request::METHOD_POST, - array('deliveryService' => json_encode($data)) + ['deliveryService' => json_encode($data)] ); } @@ -2290,7 +2299,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/reference/delivery-types/%s/edit', $data['code']), WC_Retailcrm_Request::METHOD_POST, - array('deliveryType' => json_encode($data)) + ['deliveryType' => json_encode($data)] ); } @@ -2333,7 +2342,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/reference/order-methods/%s/edit', $data['code']), WC_Retailcrm_Request::METHOD_POST, - array('orderMethod' => json_encode($data)) + ['orderMethod' => json_encode($data)] ); } @@ -2376,7 +2385,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/reference/order-types/%s/edit', $data['code']), WC_Retailcrm_Request::METHOD_POST, - array('orderType' => json_encode($data)) + ['orderType' => json_encode($data)] ); } @@ -2419,7 +2428,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/reference/payment-statuses/%s/edit', $data['code']), WC_Retailcrm_Request::METHOD_POST, - array('paymentStatus' => json_encode($data)) + ['paymentStatus' => json_encode($data)] ); } @@ -2462,7 +2471,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/reference/payment-types/%s/edit', $data['code']), WC_Retailcrm_Request::METHOD_POST, - array('paymentType' => json_encode($data)) + ['paymentType' => json_encode($data)] ); } @@ -2505,7 +2514,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/reference/product-statuses/%s/edit', $data['code']), WC_Retailcrm_Request::METHOD_POST, - array('productStatus' => json_encode($data)) + ['productStatus' => json_encode($data)] ); } @@ -2548,7 +2557,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/reference/sites/%s/edit', $data['code']), WC_Retailcrm_Request::METHOD_POST, - array('site' => json_encode($data)) + ['site' => json_encode($data)] ); } @@ -2608,7 +2617,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/reference/statuses/%s/edit', $data['code']), WC_Retailcrm_Request::METHOD_POST, - array('status' => json_encode($data)) + ['status' => json_encode($data)] ); } @@ -2657,7 +2666,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( sprintf('/reference/stores/%s/edit', $data['code']), WC_Retailcrm_Request::METHOD_POST, - array('store' => json_encode($data)) + ['store' => json_encode($data)] ); } @@ -2689,7 +2698,7 @@ class WC_Retailcrm_Client_V5 * * @param string $code symbolic code * @param string $clientId client id - * @param boolean $active telephony activity + * @param bool $active telephony activity * @param mixed $name service name * @param mixed $makeCallUrl service init url * @param mixed $image service logo url(svg file) @@ -2711,15 +2720,14 @@ class WC_Retailcrm_Client_V5 $name = false, $makeCallUrl = false, $image = false, - $additionalCodes = array(), - $externalPhones = array(), + $additionalCodes = [], + $externalPhones = [], $allowEdit = false, $inputEventSupported = false, $outputEventSupported = false, $hangupEventSupported = false, $changeUserStatusUrl = false - ) - { + ) { if (!isset($code)) { throw new InvalidArgumentException('Code must be set'); } @@ -2785,7 +2793,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( "/telephony/setting/$code/edit", WC_Retailcrm_Request::METHOD_POST, - array('configuration' => json_encode($parameters)) + ['configuration' => json_encode($parameters)] ); } @@ -2810,9 +2818,8 @@ class WC_Retailcrm_Client_V5 $codes, $hangupStatus, $externalPhone = null, - $webAnalyticsData = array() - ) - { + $webAnalyticsData = [] + ) { if (!isset($phone)) { throw new InvalidArgumentException('Phone number must be set'); } @@ -2836,7 +2843,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/telephony/call/event', WC_Retailcrm_Request::METHOD_POST, - array('event' => json_encode($parameters)) + ['event' => json_encode($parameters)] ); } @@ -2862,7 +2869,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( '/telephony/calls/upload', WC_Retailcrm_Request::METHOD_POST, - array('calls' => json_encode($calls)) + ['calls' => json_encode($calls)] ); } @@ -2918,7 +2925,7 @@ class WC_Retailcrm_Client_V5 return $this->client->makeRequest( "/integration-modules/$code/edit", WC_Retailcrm_Request::METHOD_POST, - array('integrationModule' => json_encode($configuration)) + ['integrationModule' => json_encode($configuration)] ); } @@ -2964,7 +2971,8 @@ class WC_Retailcrm_Client_V5 $response = $this->credentials(); - if ($response instanceof WC_Retailcrm_Response + if ( + $response instanceof WC_Retailcrm_Response && $response->offsetExists('sitesAvailable') && is_array($response['sitesAvailable']) && !empty($response['sitesAvailable']) @@ -2998,10 +3006,10 @@ class WC_Retailcrm_Client_V5 */ protected function checkIdParameter($by) { - $allowedForBy = array( + $allowedForBy = [ 'externalId', 'id' - ); + ]; if (!in_array($by, $allowedForBy, false)) { throw new InvalidArgumentException( diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 5e7d531..c0fdc7b 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -18,7 +18,7 @@ if (!class_exists('WC_Retailcrm_Base')) { class WC_Retailcrm_Base extends WC_Retailcrm_Abstracts_Settings { - /** @var \WC_Retailcrm_Proxy|WC_Retailcrm_Client_V4|WC_Retailcrm_Client_V5|bool */ + /** @var WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5|bool */ protected $apiClient; /** @var \WC_Retailcrm_Customers */ @@ -33,7 +33,7 @@ if (!class_exists('WC_Retailcrm_Base')) { /** * Init and hook in the integration. * - * @param \WC_Retailcrm_Proxy|WC_Retailcrm_Client_V4|WC_Retailcrm_Client_V5|bool $retailcrm (default = false) + * @param WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5|bool $retailcrm (default = false) */ public function __construct($retailcrm = false) { @@ -631,7 +631,7 @@ if (!class_exists('WC_Retailcrm_Base')) { /** * Get retailcrm api client * - * @return bool|WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V4|\WC_Retailcrm_Client_V5 + * @return bool|WC_Retailcrm_Proxy */ public function getApiClient() { diff --git a/src/include/class-wc-retailcrm-history.php b/src/include/class-wc-retailcrm-history.php index 7ffe18e..0a60c41 100644 --- a/src/include/class-wc-retailcrm-history.php +++ b/src/include/class-wc-retailcrm-history.php @@ -23,7 +23,7 @@ if (!class_exists('WC_Retailcrm_History')) : /** @var array|mixed|void */ protected $retailcrmSettings; - /** @var bool|\WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V4|\WC_Retailcrm_Client_V5 */ + /** @var bool|WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5 */ protected $retailcrm; /** @var array|mixed */ @@ -35,7 +35,7 @@ if (!class_exists('WC_Retailcrm_History')) : /** * WC_Retailcrm_History constructor. * - * @param \WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V4|\WC_Retailcrm_Client_V5|bool $retailcrm (default = false) + * @param WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5|bool $retailcrm (default = false) * * @throws \Exception */ @@ -92,7 +92,6 @@ if (!class_exists('WC_Retailcrm_History')) : protected function customersHistory() { $sinceId = get_option('retailcrm_customers_history_since_id'); - $request = new WC_Retailcrm_Paginated_Request(); $pagination = 1; $filter = !empty($sinceId) @@ -100,13 +99,9 @@ if (!class_exists('WC_Retailcrm_History')) : : ['startDate' => $this->startDate->format('Y-m-d H:i:s')]; do { - $history = $request - ->reset() - ->setApi($this->retailcrm) - ->setMethod('customersHistory') - ->setParams([$filter]) - ->execute() - ->getData(); + $historyResponse = $this->retailcrm->customersHistory($filter); + + $history = $this->getHistoryData($historyResponse); if (!empty($history)) { $builder = new WC_Retailcrm_WC_Customer_Builder(); @@ -195,7 +190,6 @@ if (!class_exists('WC_Retailcrm_History')) : { $options = array_flip(array_filter($this->retailcrmSettings)); $sinceId = get_option('retailcrm_orders_history_since_id'); - $request = new WC_Retailcrm_Paginated_Request(); $pagination = 1; $filter = !empty($sinceId) @@ -203,13 +197,9 @@ if (!class_exists('WC_Retailcrm_History')) : : ['startDate' => $this->startDate->format('Y-m-d H:i:s')]; do { - $history = $request - ->reset() - ->setApi($this->retailcrm) - ->setMethod('ordersHistory') - ->setParams([$filter]) - ->execute() - ->getData(); + $historyResponse = $this->retailcrm->OrdersHistory($filter); + + $history = $this->getHistoryData($historyResponse); if (!empty($history)) { $lastChange = end($history); @@ -1295,6 +1285,25 @@ if (!class_exists('WC_Retailcrm_History')) : return isset($arr[$key]) ? $arr[$key] : $def; } + + /** + * + * Get history data. + * + * @param $historyResponse + * + * @return array + */ + private function getHistoryData($historyResponse) + { + if (!$historyResponse->isSuccessful() || empty($historyResponse['history'])) { + return []; + } + + time_nanosleep(0, 300000000); + + return $historyResponse['history']; + } } endif; diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php index a270605..ff4b0f1 100644 --- a/src/include/class-wc-retailcrm-orders.php +++ b/src/include/class-wc-retailcrm-orders.php @@ -14,7 +14,7 @@ if (!class_exists('WC_Retailcrm_Orders')) : class WC_Retailcrm_Orders { - /** @var bool|WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V5|\WC_Retailcrm_Client_V4 */ + /** @var bool|WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5 */ protected $retailcrm; /** @var array */ diff --git a/src/include/class-wc-retailcrm-plugin.php b/src/include/class-wc-retailcrm-plugin.php index 9c0ae25..b9cc646 100644 --- a/src/include/class-wc-retailcrm-plugin.php +++ b/src/include/class-wc-retailcrm-plugin.php @@ -115,15 +115,14 @@ class WC_Retailcrm_Plugin /** * Edit configuration in CRM * - * @param WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V4|\WC_Retailcrm_Client_V5 $api_client + * @param WC_Retailcrm_Proxy|WC_Retailcrm_Client_V5 $api_client * @param string $client_id * @param bool $active * - * @return boolean + * @return bool */ public static function integration_module($api_client, $client_id, $active = true) { - if (!$api_client instanceof WC_Retailcrm_Proxy) { return false; } diff --git a/src/include/components/class-wc-retailcrm-paginated-request.php b/src/include/components/class-wc-retailcrm-paginated-request.php deleted file mode 100644 index df532f4..0000000 --- a/src/include/components/class-wc-retailcrm-paginated-request.php +++ /dev/null @@ -1,121 +0,0 @@ - - * @license http://retailcrm.ru Proprietary - * @link http://retailcrm.ru - * @see http://help.retailcrm.ru - */ -class WC_Retailcrm_Paginated_Request -{ - /** - * @var \WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V5 - */ - private $api; - - /** - * @var string - */ - private $method; - - /** - * @var array - */ - private $params; - - /** - * @var array - */ - private $data; - - /** - * Sets retailCRM api client to request - * - * @param \WC_Retailcrm_Proxy|\WC_Retailcrm_Client_V5 $api - * - * @return self - */ - public function setApi($api) - { - $this->api = $api; - - return $this; - } - - /** - * Sets API client method to request - * - * @param string $method - * - * @return self - */ - public function setMethod($method) - { - $this->method = $method; - - return $this; - } - - /** - * Sets method params for API client. - * - * @param array $params - * - * @return self - */ - public function setParams($params) - { - $this->params = $params; - - return $this; - } - - /** - * Executes request - * - * @return $this - */ - public function execute() - { - $response = call_user_func_array( - [$this->api, $this->method], - $this->params - ); - - if ($response->isSuccessful() && !empty($response['history'])) { - $this->data = array_merge($this->data, $response['history']); - } - - time_nanosleep(0, 300000000); - - return $this; - } - - /** - * Returns data - * - * @return array - */ - public function getData() - { - return $this->data; - } - - /** - * Reset paginated request - * - * @return $this - */ - public function reset() - { - $this->data = []; - $this->method = ''; - - return $this; - } -} diff --git a/src/readme.txt b/src/readme.txt index 1b40f73..46259fc 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -4,8 +4,8 @@ Donate link: https://www.simla.com Tags: Интеграция, Simla.com, simla Requires PHP: 5.6 Requires at least: 5.3 -Tested up to: 5.8 -Stable tag: 4.4.1 +Tested up to: 5.9 +Stable tag: 4.4.2 License: GPLv1 or later License URI: http://www.gnu.org/licenses/gpl-1.0.html @@ -82,6 +82,13 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i == Changelog == += 4.4.2 = +* Delete deprecated API V4. Refactoring API V5 and history getting method +* Fix bug with use xmlId +* Add order number transfer CMS -> CRM by history +* Add documentation for registering client functionality +* Delete legacy code for update customer name and surname + = 4.4.1 = * Added functionality to skip some orders statuses * Improved the create/update method when registering customers diff --git a/src/retailcrm.php b/src/retailcrm.php index 0dbd5ec..b9ad29e 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -5,10 +5,10 @@ * Description: Integration plugin for WooCommerce & Simla.com * Author: RetailDriver LLC * Author URI: http://retailcrm.pro/ - * Version: 4.4.1 - * Tested up to: 5.8 + * Version: 4.4.2 + * Tested up to: 5.9 * WC requires at least: 5.4 - * WC tested up to: 5.8 + * WC tested up to: 6.2 * Text Domain: retailcrm */ @@ -104,7 +104,6 @@ if (!class_exists( 'WC_Integration_Retailcrm')) : require_once(self::checkCustomFile('include/models/class-wc-retailcrm-customer-switcher-result.php')); require_once(self::checkCustomFile('include/components/class-wc-retailcrm-logger.php')); require_once(self::checkCustomFile('include/components/class-wc-retailcrm-history-assembler.php')); - require_once(self::checkCustomFile('include/components/class-wc-retailcrm-paginated-request.php')); require_once(self::checkCustomFile('include/components/class-wc-retailcrm-customer-switcher.php')); require_once(self::checkCustomFile('include/abstracts/class-wc-retailcrm-abstract-builder.php')); require_once(self::checkCustomFile('include/abstracts/class-wc-retailcrm-abstracts-settings.php')); diff --git a/src/uninstall.php b/src/uninstall.php index 27587f6..4bdb127 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -16,7 +16,7 @@ * * @link https://wordpress.org/plugins/woo-retailcrm/ * - * @version 4.4.1 + * @version 4.4.2 * * @package RetailCRM */