1
0
mirror of synced 2025-01-31 23:31:42 +03:00
woocommerce-module/retailcrm/include/api/class-wc-retailcrm-proxy.php
Alex Lushpai 295c58e4a8 init
2017-06-07 16:29:57 +03:00

63 lines
2.0 KiB
PHP

<?php
/**
* Retailcrm Integration.
*
* @package WC_Retailcrm_Proxy
* @category Integration
* @author Retailcrm
*/
if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) :
/**
* Class WC_Retailcrm_Proxy
*/
class WC_Retailcrm_Proxy
{
public function __construct($api_url, $api_key)
{
$this->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;