logger = new WC_Logger(); if ( ! class_exists( 'WC_Retailcrm_Client' ) ) { include_once( __DIR__ . '/class-wc-retailcrm-client.php' ); } if ($api_url && $api_key) { $this->retailcrm = new WC_Retailcrm_Client($api_url, $api_key); } } public function __call($method, $arguments) { try { $response = call_user_func_array(array($this->retailcrm, $method), $arguments); if ($response->isSuccessful()) { $result = ' Ok'; } else { $result = sprintf( $method ." : Error: [HTTP-code %s] %s", $response->getStatusCode(), $response->getErrorMsg() ); if (isset($response['errors'])) { foreach ($response['errors'] as $error) { $result .= " $error"; } } } $this->logger->add('retailcrm', sprintf("[%s] %s", $method, $result)); } catch (WC_Retailcrm_Exception_Curl $exception) { $this->logger->add('retailcrm', sprintf("[%s] %s - %s", $method, $exception->getMessage(), $result)); } catch (WC_Retailcrm_Exception_Json $exception) { $this->logger->add('retailcrm', sprintf("[%s] %s - %s", $method, $exception->getMessage(), $result)); } catch (InvalidArgumentException $exception) { $this->logger->add('retailcrm', sprintf("[%s] %s - %s", $method, $exception->getMessage(), $result)); } return $response; } } endif;