diff --git a/src/include/api/class-wc-retailcrm-client-v5.php b/src/include/api/class-wc-retailcrm-client-v5.php index 222f784..d0768c5 100644 --- a/src/include/api/class-wc-retailcrm-client-v5.php +++ b/src/include/api/class-wc-retailcrm-client-v5.php @@ -23,6 +23,7 @@ if ( ! class_exists( 'WC_Retailcrm_Response' ) ) { class WC_Retailcrm_Client_V5 { protected $client; + protected $unversionedClient; /** * Site code @@ -36,7 +37,7 @@ class WC_Retailcrm_Client_V5 * @param string $apiKey api key * @param string $site site code * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * */ public function __construct($url, $apiKey, $version = null, $site = null) @@ -45,9 +46,11 @@ class WC_Retailcrm_Client_V5 $url .= '/'; } + $unversionedUrl = $url . 'api'; $url = $version == null ? $url . 'api' : $url . 'api/' . $version; $this->client = new WC_Retailcrm_Request($url, array('apiKey' => $apiKey)); + $this->unversionedClient = new WC_Retailcrm_Request($unversionedUrl, array('apiKey' => $apiKey)); $this->siteCode = $site; } @@ -58,7 +61,623 @@ class WC_Retailcrm_Client_V5 */ public function apiVersions() { - return $this->client->makeRequest('/api-versions', WC_Retailcrm_Request::METHOD_GET); + return $this->unversionedClient->makeRequest('/api-versions', WC_Retailcrm_Request::METHOD_GET); + } + + /** + * Returns credentials list + * + * @return WC_Retailcrm_Response + */ + public function credentials() + { + return $this->unversionedClient->makeRequest('/credentials', WC_Retailcrm_Request::METHOD_GET); + } + + /** + * Returns filtered corporate 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 customersCorporateList(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; + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + '/customers-corporate', + "GET", + $parameters + ); + } + + /** + * Create a corporate customer + * + * @param array $customerCorporate corporate 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 customersCorporateCreate(array $customerCorporate, $site = null) + { + if (! count($customerCorporate)) { + throw new InvalidArgumentException( + 'Parameter `customerCorporate` must contains a data' + ); + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + '/customers-corporate/create', + "POST", + $this->fillSite($site, ['customerCorporate' => json_encode($customerCorporate)]) + ); + } + + /** + * Save corporate 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 customersCorporateFixExternalIds(array $ids) + { + if (! count($ids)) { + throw new InvalidArgumentException( + 'Method parameter must contains at least one IDs pair' + ); + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + '/customers-corporate/fix-external-ids', + "POST", + ['customersCorporate' => json_encode($ids)] + ); + } + + /** + * Get corporate customers history + * @param array $filter + * @param null $page + * @param null $limit + * + * @return WC_Retailcrm_Response + */ + public function customersCorporateHistory(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; + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + '/customers-corporate/history', + "GET", + $parameters + ); + } + + /** + * Returns filtered corporate customers notes 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 customersCorporateNotesList(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; + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + '/customers-corporate/notes', + "GET", + $parameters + ); + } + + /** + * Create corporate customer note + * + * @param array $note (default: array()) + * @param string $site (default: null) + * + * @throws InvalidArgumentException + * @throws WC_Retailcrm_Exception_Curl + * @throws WC_Retailcrm_Exception_Json + * + * @return WC_Retailcrm_Response + */ + public function customersCorporateNotesCreate($note, $site = null) + { + if (empty($note['customer']['id']) && empty($note['customer']['externalId'])) { + throw new InvalidArgumentException( + 'Customer identifier must be set' + ); + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + '/customers-corporate/notes/create', + "POST", + $this->fillSite($site, ['note' => json_encode($note)]) + ); + } + + /** + * Delete corporate customer note + * + * @param integer $id + * + * @throws InvalidArgumentException + * @throws WC_Retailcrm_Exception_Curl + * @throws WC_Retailcrm_Exception_Json + * + * @return WC_Retailcrm_Response + */ + public function customersCorporateNotesDelete($id) + { + if (empty($id)) { + throw new InvalidArgumentException( + 'Note id must be set' + ); + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + "/customers-corporate/notes/$id/delete", + "POST" + ); + } + + /** + * Upload array of the corporate customers + * + * @param array $customersCorporate array of corporate customers + * @param string $site (default: null) + * + * @return WC_Retailcrm_Response + * @throws WC_Retailcrm_Exception_Curl + * @throws WC_Retailcrm_Exception_Json + * + * @throws InvalidArgumentException + */ + public function customersCorporateUpload(array $customersCorporate, $site = null) + { + if (!count($customersCorporate)) { + throw new InvalidArgumentException( + 'Parameter `customersCorporate` must contains array of the corporate customers' + ); + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + '/customers-corporate/upload', + "POST", + $this->fillSite($site, ['customersCorporate' => json_encode($customersCorporate)]) + ); + } + + /** + * Get corporate customer by id or externalId + * + * @param string $id corporate customer identifier + * @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 customersCorporateGet($id, $by = 'externalId', $site = null) + { + $this->checkIdParameter($by); + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + "/customers-corporate/$id", + "GET", + $this->fillSite($site, ['by' => $by]) + ); + } + + /** + * Get corporate customer addresses by id or externalId + * + * @param string $id corporate customer identifier + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * @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 customersCorporateAddresses( + $id, + array $filter = [], + $page = null, + $limit = null, + $by = 'externalId', + $site = null + ) { + $this->checkIdParameter($by); + $parameters = ['by' => $by]; + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + "/customers-corporate/$id/addresses", + "GET", + $this->fillSite($site, $parameters) + ); + } + + /** + * Create corporate customer address + * + * @param string $id corporate customer identifier + * @param array $address (default: array()) + * @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 customersCorporateAddressesCreate($id, array $address = [], $by = 'externalId', $site = null) + { + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + "/customers-corporate/$id/addresses/create", + "POST", + $this->fillSite($site, ['address' => json_encode($address), 'by' => $by]) + ); + } + + /** + * Edit corporate customer address + * + * @param string $customerId corporate customer identifier + * @param string $addressId corporate customer identifier + * @param array $address (default: array()) + * @param string $customerBy (default: 'externalId') + * @param string $addressBy (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 customersCorporateAddressesEdit( + $customerId, + $addressId, + array $address = [], + $customerBy = 'externalId', + $addressBy = 'externalId', + $site = null + ) { + $addressFiltered = array_filter($address); + if ((count(array_keys($addressFiltered)) <= 1) + && (!isset($addressFiltered['text']) + || (isset($addressFiltered['text']) && empty($addressFiltered['text'])) + ) + ) { + throw new InvalidArgumentException( + '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, [ + 'address' => json_encode($address), + 'by' => $customerBy, + 'entityBy' => $addressBy + ]) + ); + } + + /** + * Get corporate customer companies by id or externalId + * + * @param string $id corporate customer identifier + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * @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 customersCorporateCompanies( + $id, + array $filter = [], + $page = null, + $limit = null, + $by = 'externalId', + $site = null + ) { + $this->checkIdParameter($by); + $parameters = ['by' => $by]; + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + "/customers-corporate/$id/companies", + "GET", + $this->fillSite($site, $parameters) + ); + } + + /** + * Create corporate customer company + * + * @param string $id corporate customer identifier + * @param array $company (default: array()) + * @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 customersCorporateCompaniesCreate($id, array $company = [], $by = 'externalId', $site = null) + { + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + "/customers-corporate/$id/companies/create", + "POST", + $this->fillSite($site, ['company' => json_encode($company), 'by' => $by]) + ); + } + + /** + * Edit corporate customer company + * + * @param string $customerId corporate customer identifier + * @param string $companyId corporate customer identifier + * @param array $company (default: array()) + * @param string $customerBy (default: 'externalId') + * @param string $companyBy (default: 'externalId') + * @param string $site (default: null) + * + * @return WC_Retailcrm_Response + * @throws InvalidArgumentException + * @throws WC_Retailcrm_Exception_Curl + * @throws WC_Retailcrm_Exception_Json + * + */ + public function customersCorporateCompaniesEdit( + $customerId, + $companyId, + array $company = [], + $customerBy = 'externalId', + $companyBy = 'externalId', + $site = null + ) { + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + "/customers-corporate/$customerId/companies/$companyId/edit", + "POST", + $this->fillSite($site, [ + 'company' => json_encode($company), + 'by' => $customerBy, + 'entityBy' => $companyBy + ]) + ); + } + + /** + * Get corporate customer contacts by id or externalId + * + * @param string $id corporate customer identifier + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * @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 customersCorporateContacts( + $id, + array $filter = [], + $page = null, + $limit = null, + $by = 'externalId', + $site = null + ) { + $this->checkIdParameter($by); + $parameters = ['by' => $by]; + if (count($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + "/customers-corporate/$id/contacts", + "GET", + $this->fillSite($site, $parameters) + ); + } + + /** + * Create corporate customer contact + * + * @param string $id corporate customer identifier + * @param array $contact (default: array()) + * @param string $by (default: 'externalId') + * @param string $site (default: null) + * + * @return WC_Retailcrm_Response + * @throws WC_Retailcrm_Exception_Curl + * @throws WC_Retailcrm_Exception_Json + * + * @throws InvalidArgumentException + */ + 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, ['contact' => json_encode($contact), 'by' => $by]) + ); + } + + /** + * Edit corporate customer contact + * + * @param string $customerId corporate customer identifier + * @param string $contactId corporate customer identifier + * @param array $contact (default: array()) + * @param string $customerBy (default: 'externalId') + * @param string $contactBy (default: 'externalId') + * @param string $site (default: null) + * + * @return WC_Retailcrm_Response + * @throws InvalidArgumentException + * @throws WC_Retailcrm_Exception_Curl + * @throws WC_Retailcrm_Exception_Json + * + */ + public function customersCorporateContactsEdit( + $customerId, + $contactId, + array $contact = [], + $customerBy = 'externalId', + $contactBy = 'externalId', + $site = null + ) { + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + "/customers-corporate/$customerId/contacts/$contactId/edit", + "POST", + $this->fillSite($site, [ + 'contact' => json_encode($contact), + 'by' => $customerBy, + 'entityBy' => $contactBy + ]) + ); + } + + /** + * Edit a corporate customer + * + * @param array $customerCorporate corporate 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 customersCorporateEdit(array $customerCorporate, $by = 'externalId', $site = null) + { + if (!count($customerCorporate)) { + throw new InvalidArgumentException( + 'Parameter `customerCorporate` must contains a data' + ); + } + $this->checkIdParameter($by); + if (!array_key_exists($by, $customerCorporate)) { + throw new InvalidArgumentException( + sprintf('Corporate customer array must contain the "%s" parameter.', $by) + ); + } + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + sprintf('/customers-corporate/%s/edit', $customerCorporate[$by]), + "POST", + $this->fillSite( + $site, + ['customerCorporate' => json_encode($customerCorporate), 'by' => $by] + ) + ); } /** @@ -70,7 +689,7 @@ class WC_Retailcrm_Client_V5 * * @throws WC_Retailcrm_Exception_Json * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return WC_Retailcrm_Response */ @@ -102,7 +721,7 @@ class WC_Retailcrm_Client_V5 * * @throws WC_Retailcrm_Exception_Json * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return WC_Retailcrm_Response */ @@ -124,7 +743,7 @@ class WC_Retailcrm_Client_V5 $statuses = array("free", "busy", "dinner", "break"); if (empty($status) || !in_array($status, $statuses)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `status` must be not empty & must be equal one of these values: free|busy|dinner|break' ); } @@ -211,13 +830,13 @@ class WC_Retailcrm_Client_V5 empty($customField['name']) || empty($customField['type']) ) { - throw new \InvalidArgumentException( + 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( + throw new InvalidArgumentException( 'Parameter `entity` must contain a data & value must be `order` or `customer`' ); } @@ -240,13 +859,13 @@ class WC_Retailcrm_Client_V5 public function customFieldsEdit($entity, $customField) { if (!count($customField) || empty($customField['code'])) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `customField` must contain a data & fields `code` must be set' ); } if (empty($entity) || $entity != 'customer' || $entity != 'order') { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `entity` must contain a data & value must be `order` or `customer`' ); } @@ -269,13 +888,13 @@ class WC_Retailcrm_Client_V5 public function customFieldsGet($entity, $code) { if (empty($code)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `code` must be not empty' ); } if (empty($entity) || $entity != 'customer' || $entity != 'order') { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `entity` must contain a data & value must be `order` or `customer`' ); } @@ -329,7 +948,7 @@ class WC_Retailcrm_Client_V5 empty($customDictionary['code']) || empty($customDictionary['elements']) ) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `dictionary` must contain a data & fields `code` & `elemets` must be set' ); } @@ -354,7 +973,7 @@ class WC_Retailcrm_Client_V5 empty($customDictionary['code']) || empty($customDictionary['elements']) ) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `dictionary` must contain a data & fields `code` & `elemets` must be set' ); } @@ -376,7 +995,7 @@ class WC_Retailcrm_Client_V5 public function customDictionariesGet($code) { if (empty($code)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `code` must be not empty' ); } @@ -394,7 +1013,7 @@ class WC_Retailcrm_Client_V5 * @param int $page (default: null) * @param int $limit (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -427,7 +1046,7 @@ class WC_Retailcrm_Client_V5 * @param array $order order data * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -436,7 +1055,7 @@ class WC_Retailcrm_Client_V5 public function ordersCreate(array $order, $site = null) { if (!count($order)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `order` must contains a data' ); } @@ -453,7 +1072,7 @@ class WC_Retailcrm_Client_V5 * * @param array $ids order identificators * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -462,7 +1081,7 @@ class WC_Retailcrm_Client_V5 public function ordersFixExternalIds(array $ids) { if (! count($ids)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Method parameter must contains at least one IDs pair' ); } @@ -481,7 +1100,7 @@ class WC_Retailcrm_Client_V5 * @param array $ids (default: array()) * @param array $externalIds (default: array()) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -511,7 +1130,7 @@ class WC_Retailcrm_Client_V5 * @param array $orders array of orders * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -520,7 +1139,7 @@ class WC_Retailcrm_Client_V5 public function ordersUpload(array $orders, $site = null) { if (!count($orders)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `orders` must contains array of the orders' ); } @@ -539,7 +1158,7 @@ class WC_Retailcrm_Client_V5 * @param string $by (default: 'externalId') * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -563,7 +1182,7 @@ class WC_Retailcrm_Client_V5 * @param string $by (default: 'externalId') * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -572,7 +1191,7 @@ class WC_Retailcrm_Client_V5 public function ordersEdit(array $order, $by = 'externalId', $site = null) { if (!count($order)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `order` must contains a data' ); } @@ -580,7 +1199,7 @@ class WC_Retailcrm_Client_V5 $this->checkIdParameter($by); if (!array_key_exists($by, $order)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( sprintf('Order array must contain the "%s" parameter.', $by) ); } @@ -638,13 +1257,13 @@ class WC_Retailcrm_Client_V5 $techniques = array('ours', 'summ', 'theirs'); if (!count($order) || !count($resultOrder)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameters `order` & `resultOrder` must contains a data' ); } if (!in_array($technique, $techniques)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `technique` must be on of ours|summ|theirs' ); } @@ -665,7 +1284,7 @@ class WC_Retailcrm_Client_V5 * * @param array $payment order data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -674,7 +1293,7 @@ class WC_Retailcrm_Client_V5 public function ordersPaymentCreate(array $payment) { if (!count($payment)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `payment` must contains a data' ); } @@ -698,7 +1317,7 @@ class WC_Retailcrm_Client_V5 public function ordersPaymentEdit(array $payment, $by = 'externalId', $site = null) { if (!count($payment)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `payment` must contains a data' ); } @@ -706,7 +1325,7 @@ class WC_Retailcrm_Client_V5 $this->checkIdParameter($by); if (!array_key_exists($by, $payment)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( sprintf('Order array must contain the "%s" parameter.', $by) ); } @@ -731,7 +1350,7 @@ class WC_Retailcrm_Client_V5 public function ordersPaymentDelete($id) { if (!$id) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `id` must be set' ); } @@ -749,7 +1368,7 @@ class WC_Retailcrm_Client_V5 * @param int $page (default: null) * @param int $limit (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -782,7 +1401,7 @@ class WC_Retailcrm_Client_V5 * @param array $customer customer data * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -791,7 +1410,7 @@ class WC_Retailcrm_Client_V5 public function customersCreate(array $customer, $site = null) { if (! count($customer)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `customer` must contains a data' ); } @@ -808,7 +1427,7 @@ class WC_Retailcrm_Client_V5 * * @param array $ids ids mapping * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -817,7 +1436,7 @@ class WC_Retailcrm_Client_V5 public function customersFixExternalIds(array $ids) { if (! count($ids)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Method parameter must contains at least one IDs pair' ); } @@ -835,7 +1454,7 @@ class WC_Retailcrm_Client_V5 * @param array $customers array of customers * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -844,7 +1463,7 @@ class WC_Retailcrm_Client_V5 public function customersUpload(array $customers, $site = null) { if (! count($customers)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `customers` must contains array of the customers' ); } @@ -863,7 +1482,7 @@ class WC_Retailcrm_Client_V5 * @param string $by (default: 'externalId') * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -887,7 +1506,7 @@ class WC_Retailcrm_Client_V5 * @param string $by (default: 'externalId') * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -896,7 +1515,7 @@ class WC_Retailcrm_Client_V5 public function customersEdit(array $customer, $by = 'externalId', $site = null) { if (!count($customer)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `customer` must contains a data' ); } @@ -904,7 +1523,7 @@ class WC_Retailcrm_Client_V5 $this->checkIdParameter($by); if (!array_key_exists($by, $customer)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( sprintf('Customer array must contain the "%s" parameter.', $by) ); } @@ -960,7 +1579,7 @@ class WC_Retailcrm_Client_V5 { if (!count($customers) || !count($resultCustomer)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameters `customers` & `resultCustomer` must contains a data' ); } @@ -982,7 +1601,7 @@ class WC_Retailcrm_Client_V5 * @param int $page (default: null) * @param int $limit (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1013,7 +1632,7 @@ class WC_Retailcrm_Client_V5 * @param array $note (default: array()) * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1022,7 +1641,7 @@ class WC_Retailcrm_Client_V5 public function customersNotesCreate($note, $site = null) { if (empty($note['customer']['id']) && empty($note['customer']['externalId'])) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Customer identifier must be set' ); } @@ -1038,7 +1657,7 @@ class WC_Retailcrm_Client_V5 * * @param integer $id * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1047,7 +1666,7 @@ class WC_Retailcrm_Client_V5 public function customersNotesDelete($id) { if (empty($id)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Note id must be set' ); } @@ -1064,7 +1683,7 @@ class WC_Retailcrm_Client_V5 * @param int $page (default: null) * @param int $limit (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1097,7 +1716,7 @@ class WC_Retailcrm_Client_V5 * @param array $pack pack data * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1106,7 +1725,7 @@ class WC_Retailcrm_Client_V5 public function ordersPacksCreate(array $pack, $site = null) { if (!count($pack)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `pack` must contains a data' ); } @@ -1125,7 +1744,7 @@ class WC_Retailcrm_Client_V5 * @param int $page (default: null) * @param int $limit (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1157,7 +1776,7 @@ class WC_Retailcrm_Client_V5 * * @param string $id pack identificator * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1166,7 +1785,7 @@ class WC_Retailcrm_Client_V5 public function ordersPacksGet($id) { if (empty($id)) { - throw new \InvalidArgumentException('Parameter `id` must be set'); + throw new InvalidArgumentException('Parameter `id` must be set'); } return $this->client->makeRequest( @@ -1180,7 +1799,7 @@ class WC_Retailcrm_Client_V5 * * @param string $id pack identificator * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1189,7 +1808,7 @@ class WC_Retailcrm_Client_V5 public function ordersPacksDelete($id) { if (empty($id)) { - throw new \InvalidArgumentException('Parameter `id` must be set'); + throw new InvalidArgumentException('Parameter `id` must be set'); } return $this->client->makeRequest( @@ -1204,7 +1823,7 @@ class WC_Retailcrm_Client_V5 * @param array $pack pack data * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1213,7 +1832,7 @@ class WC_Retailcrm_Client_V5 public function ordersPacksEdit(array $pack, $site = null) { if (!count($pack) || empty($pack['id'])) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `pack` must contains a data & pack `id` must be set' ); } @@ -1267,7 +1886,7 @@ class WC_Retailcrm_Client_V5 public function tasksCreate($task, $site = null) { if (!count($task)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `task` must contain a data' ); } @@ -1294,7 +1913,7 @@ class WC_Retailcrm_Client_V5 public function tasksEdit($task, $site = null) { if (!count($task)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `task` must contain a data' ); } @@ -1319,7 +1938,7 @@ class WC_Retailcrm_Client_V5 public function tasksGet($id) { if (empty($id)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `id` must be not empty' ); } @@ -1337,7 +1956,7 @@ class WC_Retailcrm_Client_V5 * @param int $page (default: null) * @param int $limit (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1371,7 +1990,7 @@ class WC_Retailcrm_Client_V5 * @param int $page (default: null) * @param int $limit (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1406,14 +2025,14 @@ class WC_Retailcrm_Client_V5 * @return WC_Retailcrm_Response * @throws WC_Retailcrm_Exception_Json * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return WC_Retailcrm_Response */ public function storeSettingsGet($code) { if (empty($code)) { - throw new \InvalidArgumentException('Parameter `code` must be set'); + throw new InvalidArgumentException('Parameter `code` must be set'); } return $this->client->makeRequest( @@ -1429,14 +2048,14 @@ class WC_Retailcrm_Client_V5 * * @throws WC_Retailcrm_Exception_Json * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return WC_Retailcrm_Response */ public function storeSettingsEdit(array $configuration) { if (!count($configuration) || empty($configuration['code'])) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `configuration` must contains a data & configuration `code` must be set' ); } @@ -1454,7 +2073,7 @@ class WC_Retailcrm_Client_V5 * @param array $offers offers data * @param string $site (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1463,7 +2082,7 @@ class WC_Retailcrm_Client_V5 public function storeInventoriesUpload(array $offers, $site = null) { if (!count($offers)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `offers` must contains array of the offers' ); } @@ -1482,7 +2101,7 @@ class WC_Retailcrm_Client_V5 * @param int $page (default: null) * @param int $limit (default: null) * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1514,7 +2133,7 @@ class WC_Retailcrm_Client_V5 * * @param string $code * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1523,7 +2142,7 @@ class WC_Retailcrm_Client_V5 public function deliverySettingsGet($code) { if (empty($code)) { - throw new \InvalidArgumentException('Parameter `code` must be set'); + throw new InvalidArgumentException('Parameter `code` must be set'); } return $this->client->makeRequest( @@ -1539,14 +2158,14 @@ class WC_Retailcrm_Client_V5 * * @throws WC_Retailcrm_Exception_Json * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return WC_Retailcrm_Response */ public function deliverySettingsEdit(array $configuration) { if (!count($configuration) || empty($configuration['code'])) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `configuration` must contains a data & configuration `code` must be set' ); } @@ -1566,18 +2185,18 @@ class WC_Retailcrm_Client_V5 * * @throws WC_Retailcrm_Exception_Json * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return WC_Retailcrm_Response */ public function deliveryTracking($code, array $statusUpdate) { if (empty($code)) { - throw new \InvalidArgumentException('Parameter `code` must be set'); + throw new InvalidArgumentException('Parameter `code` must be set'); } if (!count($statusUpdate)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `statusUpdate` must contains a data' ); } @@ -1592,7 +2211,7 @@ class WC_Retailcrm_Client_V5 /** * Returns available county list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1609,7 +2228,7 @@ class WC_Retailcrm_Client_V5 /** * Returns deliveryServices list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1628,7 +2247,7 @@ class WC_Retailcrm_Client_V5 * * @param array $data delivery service data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1637,7 +2256,7 @@ class WC_Retailcrm_Client_V5 public function deliveryServicesEdit(array $data) { if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Data must contain "code" parameter.' ); } @@ -1652,7 +2271,7 @@ class WC_Retailcrm_Client_V5 /** * Returns deliveryTypes list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1671,7 +2290,7 @@ class WC_Retailcrm_Client_V5 * * @param array $data delivery type data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1680,7 +2299,7 @@ class WC_Retailcrm_Client_V5 public function deliveryTypesEdit(array $data) { if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Data must contain "code" parameter.' ); } @@ -1695,7 +2314,7 @@ class WC_Retailcrm_Client_V5 /** * Returns orderMethods list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1714,7 +2333,7 @@ class WC_Retailcrm_Client_V5 * * @param array $data order method data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1723,7 +2342,7 @@ class WC_Retailcrm_Client_V5 public function orderMethodsEdit(array $data) { if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Data must contain "code" parameter.' ); } @@ -1738,7 +2357,7 @@ class WC_Retailcrm_Client_V5 /** * Returns orderTypes list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1757,7 +2376,7 @@ class WC_Retailcrm_Client_V5 * * @param array $data order type data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1766,7 +2385,7 @@ class WC_Retailcrm_Client_V5 public function orderTypesEdit(array $data) { if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Data must contain "code" parameter.' ); } @@ -1781,7 +2400,7 @@ class WC_Retailcrm_Client_V5 /** * Returns paymentStatuses list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1800,7 +2419,7 @@ class WC_Retailcrm_Client_V5 * * @param array $data payment status data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1809,7 +2428,7 @@ class WC_Retailcrm_Client_V5 public function paymentStatusesEdit(array $data) { if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Data must contain "code" parameter.' ); } @@ -1824,7 +2443,7 @@ class WC_Retailcrm_Client_V5 /** * Returns paymentTypes list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1843,7 +2462,7 @@ class WC_Retailcrm_Client_V5 * * @param array $data payment type data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1852,7 +2471,7 @@ class WC_Retailcrm_Client_V5 public function paymentTypesEdit(array $data) { if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Data must contain "code" parameter.' ); } @@ -1867,7 +2486,7 @@ class WC_Retailcrm_Client_V5 /** * Returns productStatuses list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1886,7 +2505,7 @@ class WC_Retailcrm_Client_V5 * * @param array $data product status data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1895,7 +2514,7 @@ class WC_Retailcrm_Client_V5 public function productStatusesEdit(array $data) { if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Data must contain "code" parameter.' ); } @@ -1910,7 +2529,7 @@ class WC_Retailcrm_Client_V5 /** * Returns sites list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1929,7 +2548,7 @@ class WC_Retailcrm_Client_V5 * * @param array $data site data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1938,7 +2557,7 @@ class WC_Retailcrm_Client_V5 public function sitesEdit(array $data) { if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Data must contain "code" parameter.' ); } @@ -1953,7 +2572,7 @@ class WC_Retailcrm_Client_V5 /** * Returns statusGroups list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1970,7 +2589,7 @@ class WC_Retailcrm_Client_V5 /** * Returns statuses list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1989,7 +2608,7 @@ class WC_Retailcrm_Client_V5 * * @param array $data status data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -1998,7 +2617,7 @@ class WC_Retailcrm_Client_V5 public function statusesEdit(array $data) { if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Data must contain "code" parameter.' ); } @@ -2013,7 +2632,7 @@ class WC_Retailcrm_Client_V5 /** * Returns stores list * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -2032,7 +2651,7 @@ class WC_Retailcrm_Client_V5 * * @param array $data site data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -2041,13 +2660,13 @@ class WC_Retailcrm_Client_V5 public function storesEdit(array $data) { if (!array_key_exists('code', $data)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Data must contain "code" parameter.' ); } if (!array_key_exists('name', $data)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Data must contain "name" parameter.' ); } @@ -2066,14 +2685,14 @@ class WC_Retailcrm_Client_V5 * * @throws WC_Retailcrm_Exception_Json * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return WC_Retailcrm_Response */ public function telephonySettingsGet($code) { if (empty($code)) { - throw new \InvalidArgumentException('Parameter `code` must be set'); + throw new InvalidArgumentException('Parameter `code` must be set'); } return $this->client->makeRequest( @@ -2119,13 +2738,13 @@ class WC_Retailcrm_Client_V5 ) { if (!isset($code)) { - throw new \InvalidArgumentException('Code must be set'); + throw new InvalidArgumentException('Code must be set'); } $parameters['code'] = $code; if (!isset($clientId)) { - throw new \InvalidArgumentException('client id must be set'); + throw new InvalidArgumentException('client id must be set'); } $parameters['clientId'] = $clientId; @@ -2137,7 +2756,7 @@ class WC_Retailcrm_Client_V5 } if (!isset($name)) { - throw new \InvalidArgumentException('name must be set'); + throw new InvalidArgumentException('name must be set'); } if (isset($name)) { @@ -2212,15 +2831,15 @@ class WC_Retailcrm_Client_V5 ) { if (!isset($phone)) { - throw new \InvalidArgumentException('Phone number must be set'); + throw new InvalidArgumentException('Phone number must be set'); } if (!isset($type)) { - throw new \InvalidArgumentException('Type must be set (in|out|hangup)'); + throw new InvalidArgumentException('Type must be set (in|out|hangup)'); } if (empty($codes)) { - throw new \InvalidArgumentException('Codes array must be set'); + throw new InvalidArgumentException('Codes array must be set'); } $parameters['phone'] = $phone; @@ -2243,7 +2862,7 @@ class WC_Retailcrm_Client_V5 * * @param array $calls calls data * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -2252,7 +2871,7 @@ class WC_Retailcrm_Client_V5 public function telephonyCallsUpload(array $calls) { if (!count($calls)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `calls` must contains array of the calls' ); } @@ -2270,7 +2889,7 @@ class WC_Retailcrm_Client_V5 * @param string $phone phone number * @param bool $details detailed information * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -2279,7 +2898,7 @@ class WC_Retailcrm_Client_V5 public function telephonyCallManager($phone, $details) { if (!isset($phone)) { - throw new \InvalidArgumentException('Phone number must be set'); + throw new InvalidArgumentException('Phone number must be set'); } $parameters['phone'] = $phone; @@ -2299,14 +2918,14 @@ class WC_Retailcrm_Client_V5 * * @throws WC_Retailcrm_Exception_Json * @throws WC_Retailcrm_Exception_Curl - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return WC_Retailcrm_Response */ public function integrationModulesEdit(array $configuration) { if (!count($configuration) || empty($configuration['code'])) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Parameter `configuration` must contains a data & configuration `code` must be set' ); } @@ -2323,7 +2942,7 @@ class WC_Retailcrm_Client_V5 /** * Update CRM basic statistic * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws WC_Retailcrm_Exception_Curl * @throws WC_Retailcrm_Exception_Json * @@ -2347,6 +2966,30 @@ class WC_Retailcrm_Client_V5 return $this->siteCode; } + /** + * getSingleSiteForKey + * + * @return string|bool + */ + public function getSingleSiteForKey() + { + if (!empty($this->getSite())) { + return $this->getSite(); + } + + $response = $this->credentials(); + + if ($response instanceof WC_Retailcrm_Response + && $response->offsetExists('sitesAvailable') + && is_array($response['sitesAvailable']) + && !empty($response['sitesAvailable']) + ) { + $this->siteCode = $response['sitesAvailable'][0]; + } + + return $this->getSite(); + } + /** * Set site * @@ -2364,7 +3007,7 @@ class WC_Retailcrm_Client_V5 * * @param string $by identify by * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return bool */ @@ -2376,7 +3019,7 @@ class WC_Retailcrm_Client_V5 ); if (!in_array($by, $allowedForBy, false)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( sprintf( 'Value "%s" for "by" param is not valid. Allowed values are %s.', $by, diff --git a/src/include/api/class-wc-retailcrm-proxy.php b/src/include/api/class-wc-retailcrm-proxy.php index 6be9439..3b15166 100644 --- a/src/include/api/class-wc-retailcrm-proxy.php +++ b/src/include/api/class-wc-retailcrm-proxy.php @@ -47,6 +47,10 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) : try { $response = call_user_func_array(array($this->retailcrm, $method), $arguments); + if (is_string($response)) { + return $response; + } + if ($response->isSuccessful()) { $result = ' Ok'; } else { @@ -57,8 +61,8 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) : ); if (isset($response['errors'])) { - foreach ($response['errors'] as $error) { - $result .= " $error"; + foreach ($response['errors'] as $key => $error) { + $result .= " [$key] => $error"; } } } diff --git a/src/include/class-wc-retailcrm-customers.php b/src/include/class-wc-retailcrm-customers.php index a7a180b..6d0e730 100644 --- a/src/include/class-wc-retailcrm-customers.php +++ b/src/include/class-wc-retailcrm-customers.php @@ -16,7 +16,7 @@ if (!class_exists('WC_Retailcrm_Customers')) : const CUSTOMER_ROLE = 'customer'; - /** @var bool | WC_Retailcrm_Proxy */ + /** @var bool | WC_Retailcrm_Proxy | \WC_Retailcrm_Client_V5 */ protected $retailcrm; /** @var array */ @@ -28,6 +28,18 @@ if (!class_exists('WC_Retailcrm_Customers')) : /** @var array */ private $customer = array(); + /** @var array */ + private $customerCorporate = array(); + + /** @var array */ + private $customerCorporateContact = array(); + + /** @var array */ + private $customerCorporateCompany = array(); + + /** @var array */ + private $customerCorporateAddress = array(); + /** * WC_Retailcrm_Customers constructor. * @@ -42,6 +54,79 @@ if (!class_exists('WC_Retailcrm_Customers')) : $this->customer_address = $customer_address; } + /** + * Returns true if corporate customers are enabled and accessible + * + * @param WC_Retailcrm_Client_V5|\WC_Retailcrm_Proxy $apiClient + * + * @return bool + */ + public static function isCorporateEnabledInApi($apiClient) + { + if (is_object($apiClient)) { + $requiredMethods = array( + "/api/customers-corporate", + "/api/customers-corporate/create", + "/api/customers-corporate/fix-external-ids", + "/api/customers-corporate/notes", + "/api/customers-corporate/notes/create", + "/api/customers-corporate/notes/{id}/delete", + "/api/customers-corporate/history", + "/api/customers-corporate/upload", + "/api/customers-corporate/{externalId}", + "/api/customers-corporate/{externalId}/edit" + ); + + $credentials = $apiClient->credentials(); + + if ($credentials && isset($credentials['credentials'])) { + $existingMethods = array_filter( + $credentials['credentials'], + function ($val) use ($requiredMethods) { + return in_array($val, $requiredMethods); + } + ); + + return count($requiredMethods) == count($existingMethods); + } + } + + return false; + } + + /** + * Is corporate customers enabled in provided API + * + * @return bool + */ + public function isCorporateEnabled() + { + if (!$this->retailcrm) { + return false; + } + + return static::isCorporateEnabledInApi($this->retailcrm); + } + + /** + * Returns true if provided customer has company name in billing address. + * Note: customer can have company name in address which was added after synchronization. + * In that case customer will not be corporate, but this method will return true. + * + * @param \WC_Customer $customer + * + * @return bool + */ + public static function customerPossiblyCorporate($customer) + { + if (!($customer instanceof WC_Customer)) { + return false; + } + + return !empty($customer->get_billing_company()); + } + + /** * Upload customers to CRM * @@ -55,7 +140,9 @@ if (!class_exists('WC_Retailcrm_Customers')) : } $users = get_users(array('include' => $ids)); + $corporateEnabled = $this->isCorporateEnabled(); $data_customers = array(); + $data_corporate = array(); foreach ($users as $user) { if (!\in_array(self::CUSTOMER_ROLE, $user->roles)) { @@ -63,7 +150,19 @@ if (!class_exists('WC_Retailcrm_Customers')) : } $customer = $this->wcCustomerGet($user->ID); - $this->processCustomer($customer); + if ($corporateEnabled && static::customerPossiblyCorporate($customer)) { + $this->processCorporateCustomer($customer); + $data_corporate[] = array( + 'customer' => $this->customerCorporate, + 'address' => $this->customerCorporateAddress, + 'company' => $this->customerCorporateCompany, + 'contact' => $this->customerCorporateContact + ); + } else { + $this->processCustomer($customer); + $data_customers[] = $this->customer; + } + $data_customers[] = $this->customer; } @@ -85,6 +184,38 @@ if (!class_exists('WC_Retailcrm_Customers')) : * @return mixed */ public function createCustomer($customer) + { + if ($this->isCorporateEnabled() && static::customerPossiblyCorporate($customer)) { + return $this->createCorporateCustomer($customer); + } else { + return $this->createRegularCustomer($customer); + } + } + + /** + * Update customer in CRM + * + * @param $customer + * + * @return void|\WC_Customer + */ + public function updateCustomer($customer) + { + if ($this->isCorporateEnabled() && static::customerPossiblyCorporate($customer)) { + return $this->updateCorporateCustomer($customer); + } else { + return $this->updateRegularCustomer($customer); + } + } + + /** + * Create regular customer in CRM + * + * @param int | WC_Customer $customer + * + * @return mixed + */ + public function createRegularCustomer($customer) { if (!$this->retailcrm) { return null; @@ -111,13 +242,13 @@ if (!class_exists('WC_Retailcrm_Customers')) : } /** - * Edit customer in CRM + * Edit regular customer in CRM * * @param int $customer_id * * @return WC_Customer $customer */ - public function updateCustomer($customer_id) + public function updateRegularCustomer($customer_id) { if (!$this->retailcrm) { return; @@ -133,6 +264,231 @@ if (!class_exists('WC_Retailcrm_Customers')) : return $customer; } + /** + * Create corporate customer in CRM + * + * @param int | WC_Customer $customer + * + * @return mixed + */ + public function createCorporateCustomer($customer) + { + if (!$this->retailcrm) { + return null; + } + + if (is_int($customer)) { + $customer = $this->wcCustomerGet($customer); + } + + if (!$customer instanceof WC_Customer) { + return null; + } + + if ($customer->get_role() == self::CUSTOMER_ROLE) { + $this->processCorporateCustomer($customer); + $response = $this->retailcrm->customersCorporateCreate($this->customerCorporate); + + return $this->fillCorporateCustomer($response); + } + + return null; + } + + /** + * Edit customer in CRM + * + * @param int $customer_id + * + * @return WC_Customer|void $customer + */ + public function updateCorporateCustomer($customer_id) + { + if (!$this->retailcrm) { + return; + } + + $customer = $this->wcCustomerGet($customer_id); + + if ($customer->get_role() == self::CUSTOMER_ROLE){ + $this->processCorporateCustomer($customer); + $response = $this->retailcrm->customersCorporateGet($this->customerCorporate['externalId']); + + $this->fillCorporateCustomer($response); + } + + return $customer; + } + + /** + * Fills corporate customer with required data after customer was created or updated. + * Create or update response after sending customer must be passed. + * + * @param \WC_Retailcrm_Response $response + * + * @return \WC_Retailcrm_Customer_Corporate_Response|null + */ + protected function fillCorporateCustomer($response) + { + $customerData = array(); + $addressId = 0; + $companyId = 0; + $contactId = 0; + $contactExternalId = ''; + + if (!$response->isSuccessful()) { + return null; + } + + if ($response->offsetExists('customerCorporate') && isset($response['customerCorporate']['id'])) { + $customerData = $response['customerCorporate']; + } else { + $customerData = $response; + } + + if (!empty($customerData['id'])) { + $customerData = $this->retailcrm->customersCorporateGet($customerData['id'], 'id'); + + if ($customerData->isSuccessful() && isset($customerData['customerCorporate'])) { + $this->customerCorporate = $customerData['customerCorporate']; + $customerData = $customerData['customerCorporate']; + + // Create main address or obtain existing address + if (empty($customerData['mainAddress'])) { + $addressCreateResponse = $this->retailcrm->customersCorporateAddressesCreate( + $customerData['id'], + $this->customerCorporateAddress, + 'id' + ); + + if ($addressCreateResponse->isSuccessful() && isset($addressCreateResponse['id'])) { + $this->customerCorporateAddress['id'] = $addressCreateResponse['id']; + $addressId = (int) $addressCreateResponse['id']; + } + } else { + $addressEditResponse = $this->retailcrm->customersCorporateAddressesEdit( + $customerData['id'], + $customerData['mainAddress']['id'], + $this->customerCorporateAddress, + 'id', + 'id' + ); + + if ($addressEditResponse->isSuccessful() && isset($addressEditResponse['id'])) { + $this->customerCorporateAddress['id'] = $addressEditResponse['id']; + $addressId = (int) $addressEditResponse['id']; + } + } + + // Update address in company if address was obtained / created + if (!empty($this->customerCorporateCompany) + && isset($this->customerCorporateAddress['id']) + ) { + $this->customerCorporateCompany['address'] = array( + 'id' => $this->customerCorporateAddress['id'] + ); + } + + // Create main company or obtain existing + if (empty($customerData['mainCompany'])) { + $companyCreateResponse = $this->retailcrm->customersCorporateCompaniesCreate( + $customerData['id'], + $this->customerCorporateCompany, + 'id' + ); + + if ($companyCreateResponse->isSuccessful() && isset($companyCreateResponse['id'])) { + $this->customerCorporateCompany['id'] = $companyCreateResponse['id']; + $companyId = (int) $companyCreateResponse['id']; + } + } else { + $companyEditResponse = $this->retailcrm->customersCorporateCompaniesEdit( + $customerData['id'], + $customerData['mainCompany']['id'], + $this->customerCorporateCompany, + 'id', + 'id' + ); + + if ($companyEditResponse->isSuccessful() && isset($companyEditResponse['id'])) { + $this->customerCorporateCompany['id'] = $companyEditResponse['id']; + $companyId = (int) $companyEditResponse['id']; + } + } + + // Create main customer or obtain existing + if (empty($customerData['mainCustomerContact'])) { + $contactCustomerCreated = false; + $contactCustomerGetResponse = + $this->retailcrm->customersGet($this->customerCorporateContact['externalId']); + + if ($contactCustomerGetResponse->isSuccessful() && isset($contactCustomerGetResponse['customer'])) { + $this->customerCorporateContact['id'] = $contactCustomerGetResponse['customer']['id']; + $this->retailcrm->customersEdit($this->customerCorporateContact, 'id'); + $contactId = (int) $contactCustomerGetResponse['customer']['id']; + $contactExternalId = $this->customerCorporateContact['externalId']; + + $contactCustomerCreated = true; + } else { + $contactCustomerCreateResponse = $this->retailcrm->customersCreate($this->customerCorporateContact); + + if ($contactCustomerCreateResponse->isSuccessful() && isset($contactCustomerCreateResponse['id'])) { + $contactId = (int) $contactCustomerCreateResponse['id']; + $contactExternalId = $this->customerCorporateContact['externalId']; + $contactCustomerCreated = true; + } + } + + if ($contactCustomerCreated) { + $contactPair = array( + 'isMain' => true, + 'customer' => array( + 'id' => $contactId, + 'externalId' => $contactExternalId, + 'site' => $this->retailcrm->getSingleSiteForKey() + ) + ); + + // Update company in contact in company was obtained / created + if (!empty($this->customerCorporateContact) + && isset($this->customerCorporateCompany['id']) + ) { + $contactPair['companies'] = array( + array( + 'company' => array( + 'id' => $this->customerCorporateCompany['id'] + ) + ) + ); + } + + $this->retailcrm->customersCorporateContactsCreate( + $customerData['id'], + $contactPair, + 'id' + ); + } + } else { + $this->customerCorporateContact['id'] = $customerData['mainCustomerContact']['customer']['id']; + $this->retailcrm->customersEdit($this->customerCorporateContact, 'id'); + $contactId = (int) $this->customerCorporateContact['id']; + $contactExternalId = $this->customerCorporateContact['externalId']; + } + } + + return new WC_Retailcrm_Customer_Corporate_Response( + isset($this->customerCorporate['id']) ? $this->customerCorporate['id'] : 0, + $this->customerCorporate['externalId'], + $addressId, + $companyId, + $contactId, + $contactExternalId + ); + } + + return null; + } + /** * Process customer * @@ -165,6 +521,68 @@ if (!class_exists('WC_Retailcrm_Customers')) : $this->customer = apply_filters('retailcrm_process_customer', $data_customer, $customer); } + /** + * Process corporate customer + * + * @param WC_Customer $customer + * + * @return void + */ + protected function processCorporateCustomer($customer) + { + $createdAt = $customer->get_date_created(); + $firstName = $customer->get_first_name(); + $data_contact = array( + 'createdAt' => $createdAt->date('Y-m-d H:i:s'), + 'firstName' => $firstName ? $firstName : $customer->get_username(), + 'lastName' => $customer->get_last_name(), + 'email' => $customer->get_email(), + 'address' => $this->customer_address->build($customer)->get_data() + ); + $data_company = array( + 'isMain' => true, + 'name' => $customer->get_billing_company() + ); + $data_customer = array( + 'externalId' => $customer->get_id(), + 'nickName' => $data_contact['firstName'] + ); + + if ($customer->get_id() > 0) { + $data_contact['externalId'] = static::getContactPersonExternalId($customer->get_id()); + } + + if ($customer->get_billing_phone()) { + $data_contact['phones'][] = array( + 'number' => $customer->get_billing_phone() + ); + } + + $this->customerCorporate = apply_filters( + 'retailcrm_process_customer_corporate', + $data_customer, + $customer + ); + $this->customerCorporateContact = apply_filters( + 'retailcrm_process_customer_corporate_contact', + $data_contact, + $customer + ); + $this->customerCorporateAddress = apply_filters( + 'retailcrm_process_customer_corporate_address', + array_merge( + $data_contact['address'], + array('isMain' => true) + ), + $customer + ); + $this->customerCorporateCompany = apply_filters( + 'retailcrm_process_customer_corporate_company', + $data_company, + $customer + ); + } + /** * @param array $filter * @@ -195,6 +613,36 @@ if (!class_exists('WC_Retailcrm_Customers')) : return false; } + /** + * @param array $filter + * + * @return bool|array + */ + public function searchCorporateCustomer($filter) + { + if (isset($filter['externalId'])) { + $search = $this->retailcrm->customersCorporateGet($filter['externalId']); + } elseif (isset($filter['email'])) { + $search = $this->retailcrm->customersCorporateList(array('email' => $filter['email'])); + } + + if ($search->isSuccessful()) { + if (isset($search['customersCorporate'])) { + if (empty($search['customersCorporate'])) { + return false; + } + + $customer = reset($search['customersCorporate']); + } else { + $customer = $search['customerCorporate']; + } + + return $customer; + } + + return false; + } + /** * @param WC_Order $order * @@ -234,5 +682,15 @@ if (!class_exists('WC_Retailcrm_Customers')) : { return $this->customer; } + + public static function getContactPersonExternalId($wpCustomerId) + { + return 'wpcontact_' . $wpCustomerId; + } + + public static function getCustomerIdFromContact($contactExternalId) + { + return str_ireplace('wpcontact_', '', $contactExternalId); + } } endif; diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php index 992a44d..5cab0fe 100644 --- a/src/include/class-wc-retailcrm-orders.php +++ b/src/include/class-wc-retailcrm-orders.php @@ -115,49 +115,134 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : /** * Create order * - * @param $order_id + * @param $order_id + * + * @param bool $forceRegularCustomer * * @return mixed + * @throws \Exception */ - public function orderCreate($order_id) + public function orderCreate($order_id, $forceRegularCustomer = false) { if (!$this->retailcrm) { return null; } + $isCorporateEnabled = $forceRegularCustomer ? false : WC_Retailcrm_Customers::isCorporateEnabledInApi($this->retailcrm); $wcOrder = wc_get_order($order_id); $this->processOrder($wcOrder); $wpUser = $wcOrder->get_user(); if ($wpUser instanceof WP_User) { $wpUserId = (int)$wpUser->get('ID'); - $foundCustomer = $this->customers->searchCustomer(array( - 'externalId' => $wpUserId - )); + $wooCustomer = new WC_Customer($wpUserId); - if (empty($foundCustomer)) { - $customerId = $this->customers->createCustomer($wpUserId); + if ($isCorporateEnabled && WC_Retailcrm_Customers::customerPossiblyCorporate($wooCustomer)) { + $foundRegularCustomer = $this->customers->searchCustomer(array( + 'externalId' => $wpUserId + )); - if (!empty($customerId)) { - $this->order['customer']['id'] = $customerId; + // If regular customer was found - create order with it. + if (!empty($foundRegularCustomer)) { + return $this->orderCreate($order_id, true); + } + + $foundCustomer = $this->customers->searchCorporateCustomer(array( + 'externalId' => $wpUserId + )); + + if (empty($foundCustomer)) { + $customerData = $this->customers->createCorporateCustomer($wpUserId); + + if ($customerData instanceof WC_Retailcrm_Customer_Corporate_Response) { + if (!empty($customerData->getId())) { + $this->order['customer']['id'] = $customerData->getId(); + } + + if (!empty($customerData->getContactId())) { + $this->order['contact']['id'] = $customerData->getContactId(); + } + + if (!empty($customerData->getContactExternalId())) { + $this->order['contact']['externalId'] = $customerData->getContactExternalId(); + } + } + } else { + $this->order['customer']['externalId'] = $foundCustomer['externalId']; + + if (isset($foundCustomer['mainCustomerContact']['customer']['id'])) { + $this->order['contact']['id'] = $foundCustomer['mainCustomerContact']['customer']['id']; + } } } else { - $this->order['customer']['externalId'] = $foundCustomer['externalId']; + $foundCustomer = $this->customers->searchCustomer(array( + 'externalId' => $wpUserId + )); + + if (empty($foundCustomer)) { + $customerId = $this->customers->createRegularCustomer($wpUserId); + + if (!empty($customerId)) { + $this->order['customer']['id'] = $customerId; + } + } else { + $this->order['customer']['externalId'] = $foundCustomer['externalId']; + } } } else { - $foundCustomer = $this->customers->searchCustomer(array( - 'email' => $wcOrder->get_billing_email() - )); + $wcCustomer = $this->customers->buildCustomerFromOrderData($wcOrder); - if (empty($foundCustomer)) { - $wcCustomer = $this->customers->buildCustomerFromOrderData($wcOrder); - $customerId = $this->customers->createCustomer($wcCustomer); + if ($isCorporateEnabled && WC_Retailcrm_Customers::customerPossiblyCorporate($wcCustomer)) { + $foundRegularCustomer = $this->customers->searchCustomer(array( + 'email' => $wcOrder->get_billing_email() + )); - if (!empty($customerId)) { - $this->order['customer']['id'] = $customerId; + // If regular customer was found - create order with it. + if (!empty($foundRegularCustomer)) { + return $this->orderCreate($order_id, true); + } + + $foundCustomer = $this->customers->searchCorporateCustomer(array( + 'email' => $wcOrder->get_billing_email() + )); + + if (empty($foundCustomer)) { + $customerData = $this->customers->createCorporateCustomer($wcCustomer); + + if ($customerData instanceof WC_Retailcrm_Customer_Corporate_Response) { + if (!empty($customerData->getId())) { + $this->order['customer']['id'] = $customerData->getId(); + } + + if (!empty($customerData->getContactId())) { + $this->order['contact']['id'] = $customerData->getContactId(); + } + + if (!empty($customerData->getContactExternalId())) { + $this->order['contact']['externalId'] = $customerData->getContactExternalId(); + } + } + } else { + $this->order['customer']['externalId'] = $foundCustomer['externalId']; + + if (isset($foundCustomer['mainCustomerContact']['customer']['id'])) { + $this->order['contact']['id'] = $foundCustomer['mainCustomerContact']['customer']['id']; + } } } else { - $this->order['customer']['externalId'] = $foundCustomer['externalId']; + $foundCustomer = $this->customers->searchCustomer(array( + 'email' => $wcOrder->get_billing_email() + )); + + if (empty($foundCustomer)) { + $customerId = $this->customers->createRegularCustomer($wcCustomer); + + if (!empty($customerId)) { + $this->order['customer']['id'] = $customerId; + } + } else { + $this->order['customer']['externalId'] = $foundCustomer['externalId']; + } } } diff --git a/src/include/customer/class-wc-retailcrm-customer-corporate-response.php b/src/include/customer/class-wc-retailcrm-customer-corporate-response.php new file mode 100644 index 0000000..33b0585 --- /dev/null +++ b/src/include/customer/class-wc-retailcrm-customer-corporate-response.php @@ -0,0 +1,123 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +if (!class_exists('WC_Retailcrm_Customer_Corporate_Response')) : +/** + * Class WC_Retailcrm_Customer_Corporate_Response + */ +class WC_Retailcrm_Customer_Corporate_Response +{ + /** + * @var int $corporateId + */ + private $corporateId; + + /** + * @var string $corporateExternalId + */ + private $corporateExternalId; + + /** + * @var int $addressId + */ + private $addressId; + + /** + * @var int $companyId + */ + private $companyId; + + /** + * @var int $contactId + */ + private $contactId; + + /** + * @var int $contactExternalId + */ + private $contactExternalId; + + /** + * WC_Retailcrm_Customer_Corporate_Response constructor. + * + * @param int $corporateId + * @param string $corporateExternalId + * @param int $addressId + * @param int $companyId + * @param int $contactId + * @param string $contactExternalId + */ + public function __construct( + $corporateId, + $corporateExternalId, + $addressId, + $companyId, + $contactId, + $contactExternalId + ) { + $this->corporateId = $corporateId; + $this->corporateExternalId = $corporateExternalId; + $this->addressId = $addressId; + $this->companyId = $companyId; + $this->contactId = $contactId; + $this->contactExternalId = $contactExternalId; + } + + /** + * @return int + */ + public function getId() + { + return $this->corporateId; + } + + /** + * @return string + */ + public function getExternalId() + { + return $this->corporateExternalId; + } + + /** + * @return int + */ + public function getAddressId() + { + return $this->addressId; + } + + /** + * @return int + */ + public function getCompanyId() + { + return $this->companyId; + } + + /** + * @return int + */ + public function getContactId() + { + return $this->contactId; + } + + /** + * @return int + */ + public function getContactExternalId() + { + return $this->contactExternalId; + } +} + +endif; diff --git a/src/retailcrm.php b/src/retailcrm.php index 49cb19a..3cfda64 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -47,6 +47,7 @@ if (!class_exists( 'WC_Integration_Retailcrm')) : require_once(dirname(__FILE__ ) . '/include/order/class-wc-retailcrm-order-item.php'); require_once(dirname(__FILE__ ) . '/include/order/class-wc-retailcrm-order-address.php'); require_once(dirname(__FILE__ ) . '/include/customer/class-wc-retailcrm-customer-address.php'); + require_once(dirname(__FILE__ ) . '/include/customer/class-wc-retailcrm-customer-corporate-response.php'); require_once(dirname(__FILE__ ) . '/include/class-wc-retailcrm-base.php'); require_once(dirname(__FILE__ ) . '/include/functions.php'); add_filter('woocommerce_integrations', array( $this, 'add_integration')); diff --git a/tests/test-wc-retailcrm-customers.php b/tests/test-wc-retailcrm-customers.php index 35c82c3..182cd86 100644 --- a/tests/test-wc-retailcrm-customers.php +++ b/tests/test-wc-retailcrm-customers.php @@ -80,7 +80,7 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper public function test_create_customer($retailcrm) { $retailcrm_customer = $this->getRetailcrmCustomer($retailcrm); - $id = $retailcrm_customer->createCustomer($this->customer->get_id()); + $id = $retailcrm_customer->createRegularCustomer($this->customer->get_id()); $customer_send = $retailcrm_customer->getCustomer(); if ($retailcrm) { @@ -103,7 +103,7 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper public function test_update_customer($retailcrm) { $retailcrm_customer = $this->getRetailcrmCustomer($retailcrm); - $customer = $retailcrm_customer->updateCustomer($this->customer->get_id()); + $customer = $retailcrm_customer->updateRegularCustomer($this->customer->get_id()); $customer_send = $retailcrm_customer->getCustomer(); if ($retailcrm) {