+apiv2; +upd RestApi
This commit is contained in:
parent
92d559d822
commit
38e7157d18
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
namespace IntaroCrm\Exception;
|
||||||
|
|
||||||
|
class ApiException extends \Exception
|
||||||
|
{
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
namespace IntaroCrm\Exception;
|
||||||
|
|
||||||
|
class CurlException extends \Exception
|
||||||
|
{
|
||||||
|
}
|
@ -108,26 +108,45 @@ class ICrmOrderActions
|
|||||||
$lastOrderId = $arOrder['ID'];
|
$lastOrderId = $arOrder['ID'];
|
||||||
|
|
||||||
if ($orderCount >= $pSize) {
|
if ($orderCount >= $pSize) {
|
||||||
|
|
||||||
|
try {
|
||||||
$customers = $api->customerUpload($resCustomers);
|
$customers = $api->customerUpload($resCustomers);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing customers
|
if($e->getCode() != 201)
|
||||||
if ($api->getStatusCode() != 201) {
|
if($e->getCode() != 460)
|
||||||
//handle err
|
return false;
|
||||||
//self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload', $api->getLastError());
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
if ($api->getStatusCode() != 460) // some orders were sent
|
return false;
|
||||||
return false; // in pack mode return errors
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$orders = $api->orderUpload($resOrders);
|
$orders = $api->orderUpload($resOrders);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing orders
|
if($e->getCode() != 201)
|
||||||
if ($api->getStatusCode() != 201) {
|
if($e->getCode() != 460)
|
||||||
//handle err
|
return false;
|
||||||
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
if ($api->getStatusCode() != 460) // some orders were sent
|
return false;
|
||||||
return false; // in pack mode return errors
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($lastOrderId)
|
if ($lastOrderId)
|
||||||
@ -137,26 +156,44 @@ class ICrmOrderActions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($resOrders)) {
|
if (!empty($resOrders)) {
|
||||||
|
try {
|
||||||
$customers = $api->customerUpload($resCustomers);
|
$customers = $api->customerUpload($resCustomers);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing customers
|
if($e->getCode() != 201)
|
||||||
if ($api->getStatusCode() != 201) {
|
if($e->getCode() != 460)
|
||||||
//handle err
|
return false;
|
||||||
//self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload', $api->getLastError());
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
if ($api->getStatusCode() != 460) // some orders were sent
|
return false;
|
||||||
return false; // in pack mode return errors
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$orders = $api->orderUpload($resOrders);
|
$orders = $api->orderUpload($resOrders);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing orders
|
if($e->getCode() != 201)
|
||||||
if ($api->getStatusCode() != 201) {
|
if($e->getCode() != 460)
|
||||||
//handle err
|
return false;
|
||||||
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
if ($api->getStatusCode() != 460) // some orders were sent
|
return false;
|
||||||
return false; // in pack mode return errors
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,26 +225,44 @@ class ICrmOrderActions
|
|||||||
$recOrders[] = $arOrder['ID'];
|
$recOrders[] = $arOrder['ID'];
|
||||||
|
|
||||||
if ($orderCount >= $pSize) {
|
if ($orderCount >= $pSize) {
|
||||||
|
try {
|
||||||
$customers = $api->customerUpload($resCustomers);
|
$customers = $api->customerUpload($resCustomers);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing customers
|
if($e->getCode() != 201)
|
||||||
if ($api->getStatusCode() != 201) {
|
if($e->getCode() != 460)
|
||||||
//handle err
|
return false;
|
||||||
//self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload', $api->getLastError());
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
if ($api->getStatusCode() != 460) // some orders were sent
|
return false;
|
||||||
return false; // in pack mode return errors
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$orders = $api->orderUpload($resOrders);
|
$orders = $api->orderUpload($resOrders);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing orders
|
if($e->getCode() != 201)
|
||||||
if ($api->getStatusCode() != 201) {
|
if($e->getCode() != 460)
|
||||||
//handle err
|
return false;
|
||||||
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
if ($api->getStatusCode() != 460) // some orders were sent
|
return false;
|
||||||
return false; // in pack mode return errors
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($recOrders)) {
|
if (!empty($recOrders)) {
|
||||||
@ -219,26 +274,44 @@ class ICrmOrderActions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($resOrders)) {
|
if (!empty($resOrders)) {
|
||||||
|
try {
|
||||||
$customers = $api->customerUpload($resCustomers);
|
$customers = $api->customerUpload($resCustomers);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing customers
|
if($e->getCode() != 201)
|
||||||
if ($api->getStatusCode() != 201) {
|
if($e->getCode() != 460)
|
||||||
//handle err
|
return false;
|
||||||
//self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload', $api->getLastError());
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::customerUpload::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
if ($api->getStatusCode() != 460) // some orders were sent
|
return false;
|
||||||
return false; // in pack mode return errors
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$orders = $api->orderUpload($resOrders);
|
$orders = $api->orderUpload($resOrders);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing orders
|
if($e->getCode() != 201)
|
||||||
if ($api->getStatusCode() != 201) {
|
if($e->getCode() != 460)
|
||||||
//handle err
|
return false;
|
||||||
self::eventLog('ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload', $api->getLastError());
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::uploadOrders', 'IntaroCrm\RestApi::orderUpload::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
if ($api->getStatusCode() != 460) // some orders were sent
|
return false;
|
||||||
return false; // in pack mode return errors
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,9 +441,25 @@ class ICrmOrderActions
|
|||||||
$dateStart = $dateStart->format('Y-m-d H:i:s');
|
$dateStart = $dateStart->format('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
$dateFinish = new \DateTime();
|
try {
|
||||||
|
|
||||||
$orderHistory = $api->orderHistory($dateStart);
|
$orderHistory = $api->orderHistory($dateStart);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::orderHistory',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::orderHistory::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dateFinish = $api->getGeneratedAt();
|
||||||
|
|
||||||
$GLOBALS['INTARO_CRM_FROM_HISTORY'] = true;
|
$GLOBALS['INTARO_CRM_FROM_HISTORY'] = true;
|
||||||
|
|
||||||
@ -447,11 +536,21 @@ class ICrmOrderActions
|
|||||||
$order['customer']['externalId'] = $registeredUserID;
|
$order['customer']['externalId'] = $registeredUserID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$api->customerFixExternalIds(array(array('id' => $order['customer']['id'], 'externalId' => $order['customer']['externalId'])));
|
$api->customerFixExternalIds(array(array('id' => $order['customer']['id'], 'externalId' => $order['customer']['externalId'])));
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::customerFixExternalIds',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::customerFixExternalIds::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
if ($api->getStatusCode() != 200) {
|
|
||||||
//handle err - write log & continue
|
|
||||||
self::eventLog('ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::customerFixExternalIds', $api->getLastError());
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,11 +579,21 @@ class ICrmOrderActions
|
|||||||
if(isset($GLOBALS['ICRM_ACCOUNT_NUMBER']))
|
if(isset($GLOBALS['ICRM_ACCOUNT_NUMBER']))
|
||||||
unset($GLOBALS['ICRM_ACCOUNT_NUMBER']);
|
unset($GLOBALS['ICRM_ACCOUNT_NUMBER']);
|
||||||
|
|
||||||
|
try {
|
||||||
$api->orderFixExternalIds(array(array('id' => $order['id'], 'externalId' => $order['externalId'])));
|
$api->orderFixExternalIds(array(array('id' => $order['id'], 'externalId' => $order['externalId'])));
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::orderFixExternalIds',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::orderFixExternalIds::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
if ($api->getStatusCode() != 200) {
|
|
||||||
//handle err - write log & continue
|
|
||||||
self::eventLog('ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::orderFixExternalIds', $api->getLastError());
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -985,14 +1094,24 @@ class ICrmOrderActions
|
|||||||
'createdAt' => $createdAt
|
'createdAt' => $createdAt
|
||||||
));
|
));
|
||||||
|
|
||||||
if($send)
|
if($send) {
|
||||||
|
try {
|
||||||
$customer = $api->customerEdit($customer);
|
$customer = $api->customerEdit($customer);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing customer
|
|
||||||
if (!$customer) {
|
|
||||||
//handle err
|
|
||||||
self::eventLog('ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit', $api->getLastError());
|
|
||||||
return false;
|
return false;
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// delivery types
|
// delivery types
|
||||||
@ -1166,8 +1285,25 @@ class ICrmOrderActions
|
|||||||
|
|
||||||
$resOrder = self::clearArr($resOrder);
|
$resOrder = self::clearArr($resOrder);
|
||||||
|
|
||||||
if($send)
|
if($send) {
|
||||||
|
try {
|
||||||
return $api->orderEdit($resOrder);
|
return $api->orderEdit($resOrder);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::orderEdit',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
self::eventLog(
|
||||||
|
'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::orderEdit::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'order' => $resOrder,
|
'order' => $resOrder,
|
||||||
|
@ -5,10 +5,9 @@ class RestApi
|
|||||||
{
|
{
|
||||||
protected $apiUrl;
|
protected $apiUrl;
|
||||||
protected $apiKey;
|
protected $apiKey;
|
||||||
protected $apiVersion = '1';
|
protected $apiVersion = '2';
|
||||||
|
protected $generatedAt;
|
||||||
|
|
||||||
protected $response;
|
|
||||||
protected $statusCode;
|
|
||||||
protected $parameters;
|
protected $parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,35 +21,6 @@ class RestApi
|
|||||||
$this->parameters = array('apiKey' => $this->apiKey);
|
$this->parameters = array('apiKey' => $this->apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getStatusCode()
|
|
||||||
{
|
|
||||||
return $this->statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Получение кода статуса и сообщения об ошибке */
|
|
||||||
public function getLastError()
|
|
||||||
{
|
|
||||||
if (isset($this->response['errorMsg']) && isset($this->response['errors']))
|
|
||||||
{
|
|
||||||
$result = $this->statusCode . ' ' . $this->response['errorMsg'];
|
|
||||||
foreach ($this->response['errors'] as $error)
|
|
||||||
$result .= ' ' . $error;
|
|
||||||
}
|
|
||||||
elseif (isset($this->response['errorMsg']))
|
|
||||||
$result = $this->statusCode . ' ' . $this->response['errorMsg'];
|
|
||||||
else
|
|
||||||
$result = null;
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Псообщения об ошибке */
|
|
||||||
public function getLastErrorMessage()
|
|
||||||
{
|
|
||||||
return $this->response['errorMsg'];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Методы для работы с заказами */
|
/* Методы для работы с заказами */
|
||||||
/**
|
/**
|
||||||
* Получение заказа по id
|
* Получение заказа по id
|
||||||
@ -122,12 +92,12 @@ class RestApi
|
|||||||
/**
|
/**
|
||||||
* Обновление externalId у заказов с переданными id
|
* Обновление externalId у заказов с переданными id
|
||||||
*
|
*
|
||||||
* @param array $orders - массив, содержащий id и externalId заказа
|
* @param array $orders- массив, содержащий id и externalId заказа
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function orderFixExternalIds($orders)
|
public function orderFixExternalIds($order)
|
||||||
{
|
{
|
||||||
$dataJson = json_encode($orders);
|
$dataJson = json_encode($order);
|
||||||
$this->parameters['orders'] = $dataJson;
|
$this->parameters['orders'] = $dataJson;
|
||||||
|
|
||||||
$url = $this->apiUrl.'orders/fix-external-ids';
|
$url = $this->apiUrl.'orders/fix-external-ids';
|
||||||
@ -241,22 +211,6 @@ class RestApi
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Обновление externalId у клиентов с переданными id
|
|
||||||
*
|
|
||||||
* @param array $customers- массив, содержащий id и externalId заказа
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function customerFixExternalIds($customers)
|
|
||||||
{
|
|
||||||
$dataJson = json_encode($customers);
|
|
||||||
$this->parameters['customers'] = $dataJson;
|
|
||||||
|
|
||||||
$url = $this->apiUrl.'customers/fix-external-ids';
|
|
||||||
$result = $this->curlRequest($url, 'POST');
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Удаление клиента
|
* Удаление клиента
|
||||||
*
|
*
|
||||||
@ -329,34 +283,6 @@ class RestApi
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Получение списка служб доставки
|
|
||||||
*
|
|
||||||
* @return array - массив типов доставки
|
|
||||||
*/
|
|
||||||
public function deliveryServicesList()
|
|
||||||
{
|
|
||||||
$url = $this->apiUrl.'reference/delivery-services';
|
|
||||||
$result = $this->curlRequest($url);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Редактирование службы доставки
|
|
||||||
*
|
|
||||||
* @param array $deliveryService - информация о типе доставки
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function deliveryServiceEdit($deliveryService)
|
|
||||||
{
|
|
||||||
$dataJson = json_encode($deliveryService);
|
|
||||||
$this->parameters['deliveryService'] = $dataJson;
|
|
||||||
|
|
||||||
$url = $this->apiUrl.'reference/delivery-services/'.$deliveryService['code'].'/edit';
|
|
||||||
$result = $this->curlRequest($url, 'POST');
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Получение списка типов оплаты
|
* Получение списка типов оплаты
|
||||||
@ -444,6 +370,35 @@ class RestApi
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получение списка способов оформления заказа
|
||||||
|
*
|
||||||
|
* @return array - массив способов оформления заказа
|
||||||
|
*/
|
||||||
|
public function orderMethodsList()
|
||||||
|
{
|
||||||
|
$url = $this->apiUrl.'reference/order-methods';
|
||||||
|
$result = $this->curlRequest($url);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Редактирование способа оформления заказа
|
||||||
|
*
|
||||||
|
* @param array $orderMethod - информация о способе оформления заказа
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function orderMethodsEdit($orderMethod)
|
||||||
|
{
|
||||||
|
$dataJson = json_encode($orderMethod);
|
||||||
|
$this->parameters['orderMethod'] = $dataJson;
|
||||||
|
|
||||||
|
$url = $this->apiUrl.'reference/order-methods/'.$orderMethod['code'].'/edit';
|
||||||
|
$result = $this->curlRequest($url, 'POST');
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Получение списка статусов заказа
|
* Получение списка статусов заказа
|
||||||
*
|
*
|
||||||
@ -497,6 +452,36 @@ class RestApi
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \DateTime
|
||||||
|
*/
|
||||||
|
public function getGeneratedAt() {
|
||||||
|
return $this->generatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getErrorMessage($response)
|
||||||
|
{
|
||||||
|
$str = '';
|
||||||
|
if (isset($response['message']))
|
||||||
|
$str = $response['message'];
|
||||||
|
elseif (isset($response[0]['message']))
|
||||||
|
$str = $response[0]['message'];
|
||||||
|
elseif (isset($response['error']) && isset($response['error']['message']))
|
||||||
|
$str = $response['error']['message'];
|
||||||
|
elseif (isset($response['errorMsg']))
|
||||||
|
$str = $response['errorMsg'];
|
||||||
|
|
||||||
|
if (isset($response['errors']) && sizeof($response['errors'])) {
|
||||||
|
foreach ($response['errors'] as $error)
|
||||||
|
$str .= '. ' . $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strlen($str))
|
||||||
|
return 'Application Error';
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
protected function curlRequest($url, $method = 'GET', $format = 'json')
|
protected function curlRequest($url, $method = 'GET', $format = 'json')
|
||||||
{
|
{
|
||||||
if ($method == 'GET' && !is_null($this->parameters))
|
if ($method == 'GET' && !is_null($this->parameters))
|
||||||
@ -516,28 +501,34 @@ class RestApi
|
|||||||
}
|
}
|
||||||
|
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$this->statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
unset($this->parameters);
|
unset($this->parameters);
|
||||||
/* Сброс массива с параметрами */
|
/* Сброс массива с параметрами */
|
||||||
$this->parameters = array('apiKey' => $this->apiKey);
|
$this->parameters = array('apiKey' => $this->apiKey);
|
||||||
|
|
||||||
if (curl_errno($ch))
|
$errno = curl_errno($ch);
|
||||||
{
|
$error = curl_error($ch);
|
||||||
$this->response = array('errorMsg' => 'Curl error: ' . curl_error($ch));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
$result = (array)json_decode($response, true);
|
if ($errno)
|
||||||
$this->response = $result;
|
throw new Exception\CurlException($error, $errno);
|
||||||
if ($result['success'] == false)
|
|
||||||
return null;
|
$result = json_decode($response, true);
|
||||||
|
|
||||||
|
if ($statusCode >= 400 || isset($result['success']) && $result['success'] === false) {
|
||||||
|
throw new Exception\ApiException($this->getErrorMessage($result), $statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($result['generatedAt'])) {
|
||||||
|
$this->generatedAt = new \DateTime($result['generatedAt']);
|
||||||
|
unset($result['generatedAt']);
|
||||||
|
}
|
||||||
|
|
||||||
unset($result['success']);
|
unset($result['success']);
|
||||||
|
|
||||||
if (count($result) == 0)
|
if (count($result) == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return reset($result);
|
return reset($result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
@ -213,11 +213,19 @@ class ICrmOrderEvent {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$api->orderEdit($order);
|
$api->orderEdit($order);
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
// error pushing order
|
ICrmOrderActions::eventLog(
|
||||||
if ($api->getStatusCode() != 201)
|
'ICrmOrderEvent::onSaleCancelOrder', 'IntaroCrm\RestApi::orderEdit',
|
||||||
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError());
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'ICrmOrderEvent::onSaleCancelOrder', 'IntaroCrm\RestApi::orderEdit::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -268,9 +276,19 @@ class ICrmOrderEvent {
|
|||||||
|
|
||||||
$api->orderEdit($order);
|
$api->orderEdit($order);
|
||||||
|
|
||||||
// error pushing order
|
try {
|
||||||
if ($api->getStatusCode() != 201)
|
$api->orderEdit($order);
|
||||||
ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'IntaroCrm\RestApi::orderEdit', $api->getLastError());
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'ICrmOrderEvent::onSalePayOrder', 'IntaroCrm\RestApi::orderEdit',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'ICrmOrderEvent::onSalePayOrder', 'IntaroCrm\RestApi::orderEdit::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ CModule::AddAutoloadClasses(
|
|||||||
'IntaroCrm\RestApi' => 'classes/general/RestApi.php',
|
'IntaroCrm\RestApi' => 'classes/general/RestApi.php',
|
||||||
'ICrmOrderActions' => 'classes/general/ICrmOrderActions.php',
|
'ICrmOrderActions' => 'classes/general/ICrmOrderActions.php',
|
||||||
'ICMLLoader' => 'classes/general/ICMLLoader.php',
|
'ICMLLoader' => 'classes/general/ICMLLoader.php',
|
||||||
'ICrmOrderEvent' => 'classes/general/events/ICrmOrderEvent.php'
|
'ICrmOrderEvent' => 'classes/general/events/ICrmOrderEvent.php',
|
||||||
|
'IntaroCrm\Exception\ApiException' => 'classes/general/Exception/ApiException.php',
|
||||||
|
'IntaroCrm\Exception\CurlException' => 'classes/general/Exception/CurlException.php'
|
||||||
)
|
)
|
||||||
);
|
);
|
@ -196,20 +196,48 @@ class intaro_intarocrm extends CModule {
|
|||||||
$this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
|
$this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
|
||||||
|
|
||||||
//prepare crm lists
|
//prepare crm lists
|
||||||
|
try {
|
||||||
$arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList();
|
$arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList();
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::orderTypesList',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
$APPLICATION->RestartBuffer();
|
||||||
|
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
|
||||||
|
die(json_encode(array("success" => false)));
|
||||||
|
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::orderTypesList::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
if ((int) $this->INTARO_CRM_API->getStatusCode() != 200) {
|
|
||||||
$APPLICATION->RestartBuffer();
|
$APPLICATION->RestartBuffer();
|
||||||
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
|
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
|
||||||
die(json_encode(array("success" => false)));
|
die(json_encode(array("success" => false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList();
|
$arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList();
|
||||||
$arResult['deliveryServicesList'] = $this->INTARO_CRM_API->deliveryServicesList();
|
$arResult['deliveryServicesList'] = $this->INTARO_CRM_API->deliveryServicesList();
|
||||||
$arResult['paymentTypesList'] = $this->INTARO_CRM_API->paymentTypesList();
|
$arResult['paymentTypesList'] = $this->INTARO_CRM_API->paymentTypesList();
|
||||||
$arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses
|
$arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses
|
||||||
$arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList();
|
$arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList();
|
||||||
$arResult['paymentGroupList'] = $this->INTARO_CRM_API->orderStatusGroupsList(); // -- statuses groups
|
$arResult['paymentGroupList'] = $this->INTARO_CRM_API->orderStatusGroupsList(); // -- statuses groups
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::*List',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::*List::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
//bitrix orderTypesList -- personTypes
|
//bitrix orderTypesList -- personTypes
|
||||||
$dbOrderTypesList = CSalePersonType::GetList(
|
$dbOrderTypesList = CSalePersonType::GetList(
|
||||||
array(
|
array(
|
||||||
@ -480,11 +508,29 @@ class intaro_intarocrm extends CModule {
|
|||||||
|
|
||||||
$this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
|
$this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
|
||||||
|
|
||||||
|
try {
|
||||||
$this->INTARO_CRM_API->paymentStatusesList();
|
$this->INTARO_CRM_API->paymentStatusesList();
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::paymentStatusesList',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
//check connection & apiKey valid
|
$arResult['errCode'] = 'ERR_' . $e->getCode();
|
||||||
if ((int) $this->INTARO_CRM_API->getStatusCode() != 200) {
|
|
||||||
$arResult['errCode'] = 'ERR_' . $this->INTARO_CRM_API->getStatusCode();
|
$APPLICATION->IncludeAdminFile(
|
||||||
|
GetMessage('MODULE_INSTALL_TITLE'),
|
||||||
|
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::paymentStatusesList::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
$arResult['errCode'] = 'ERR_' . $e->getCode();
|
||||||
|
|
||||||
$APPLICATION->IncludeAdminFile(
|
$APPLICATION->IncludeAdminFile(
|
||||||
GetMessage('MODULE_INSTALL_TITLE'),
|
GetMessage('MODULE_INSTALL_TITLE'),
|
||||||
@ -499,6 +545,7 @@ class intaro_intarocrm extends CModule {
|
|||||||
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_SITES, serialize($orderSites));
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_SITES, serialize($orderSites));
|
||||||
|
|
||||||
//prepare crm lists
|
//prepare crm lists
|
||||||
|
try {
|
||||||
$arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList();
|
$arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList();
|
||||||
$arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList();
|
$arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList();
|
||||||
$arResult['deliveryServicesList'] = $this->INTARO_CRM_API->deliveryServicesList();
|
$arResult['deliveryServicesList'] = $this->INTARO_CRM_API->deliveryServicesList();
|
||||||
@ -506,7 +553,18 @@ class intaro_intarocrm extends CModule {
|
|||||||
$arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses
|
$arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses
|
||||||
$arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList();
|
$arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList();
|
||||||
$arResult['paymentGroupList'] = $this->INTARO_CRM_API->orderStatusGroupsList(); // -- statuses groups
|
$arResult['paymentGroupList'] = $this->INTARO_CRM_API->orderStatusGroupsList(); // -- statuses groups
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::*List',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::*List::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
//bitrix orderTypesList -- personTypes
|
//bitrix orderTypesList -- personTypes
|
||||||
$dbOrderTypesList = CSalePersonType::GetList(
|
$dbOrderTypesList = CSalePersonType::GetList(
|
||||||
array(
|
array(
|
||||||
@ -691,6 +749,7 @@ class intaro_intarocrm extends CModule {
|
|||||||
$deliveryTypesArr[$arDeliveryTypesList['ID']] = $resultDeliveryTypeId;
|
$deliveryTypesArr[$arDeliveryTypesList['ID']] = $resultDeliveryTypeId;
|
||||||
|
|
||||||
// send to crm
|
// send to crm
|
||||||
|
try {
|
||||||
$this->INTARO_CRM_API->deliveryTypeEdit(ICrmOrderActions::clearArr(array(
|
$this->INTARO_CRM_API->deliveryTypeEdit(ICrmOrderActions::clearArr(array(
|
||||||
'code' => $resultDeliveryTypeId,
|
'code' => $resultDeliveryTypeId,
|
||||||
'name' => ICrmOrderActions::toJSON($arDeliveryTypesList['NAME']),
|
'name' => ICrmOrderActions::toJSON($arDeliveryTypesList['NAME']),
|
||||||
@ -698,14 +757,19 @@ class intaro_intarocrm extends CModule {
|
|||||||
'description' => ICrmOrderActions::toJSON($arDeliveryTypesList['DESCRIPTION']),
|
'description' => ICrmOrderActions::toJSON($arDeliveryTypesList['DESCRIPTION']),
|
||||||
'paymentTypes' => ''
|
'paymentTypes' => ''
|
||||||
)));
|
)));
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryTypeEdit',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing dt
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
if ($this->INTARO_CRM_API->getStatusCode() != 200) {
|
ICrmOrderActions::eventLog(
|
||||||
if ($this->INTARO_CRM_API->getStatusCode() != 201) {
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryTypeEdit::CurlException',
|
||||||
//handle err
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
ICrmOrderActions::eventLog('install/index.php', 'IntaroCrm\RestApi::deliveryTypeEdit', $this->INTARO_CRM_API->getLastError());
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch());
|
} while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -715,6 +779,7 @@ class intaro_intarocrm extends CModule {
|
|||||||
$deliveryTypesArr[$arDeliveryServicesList['SID']] = $arDeliveryServicesList['SID'];
|
$deliveryTypesArr[$arDeliveryServicesList['SID']] = $arDeliveryServicesList['SID'];
|
||||||
|
|
||||||
// send to crm
|
// send to crm
|
||||||
|
try {
|
||||||
$this->INTARO_CRM_API->deliveryTypeEdit(ICrmOrderActions::clearArr(array(
|
$this->INTARO_CRM_API->deliveryTypeEdit(ICrmOrderActions::clearArr(array(
|
||||||
'code' => $arDeliveryServicesList['SID'],
|
'code' => $arDeliveryServicesList['SID'],
|
||||||
'name' => ICrmOrderActions::toJSON($arDeliveryServicesList['NAME']),
|
'name' => ICrmOrderActions::toJSON($arDeliveryServicesList['NAME']),
|
||||||
@ -722,30 +787,39 @@ class intaro_intarocrm extends CModule {
|
|||||||
'description' => ICrmOrderActions::toJSON($arDeliveryTypesList['DESCRIPTION']),
|
'description' => ICrmOrderActions::toJSON($arDeliveryTypesList['DESCRIPTION']),
|
||||||
'paymentTypes' => ''
|
'paymentTypes' => ''
|
||||||
)));
|
)));
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryTypeEdit',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing dt
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
if ($this->INTARO_CRM_API->getStatusCode() != 200) {
|
ICrmOrderActions::eventLog(
|
||||||
if ($this->INTARO_CRM_API->getStatusCode() != 201) {
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryTypeEdit::CurlException',
|
||||||
//handle err
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
ICrmOrderActions::eventLog('install/index.php', 'IntaroCrm\RestApi::deliveryTypeEdit', $this->INTARO_CRM_API->getLastError());
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) {
|
foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) {
|
||||||
|
|
||||||
// send to crm
|
// send to crm
|
||||||
|
try {
|
||||||
$this->INTARO_CRM_API->deliveryServiceEdit(ICrmOrderActions::clearArr(array(
|
$this->INTARO_CRM_API->deliveryServiceEdit(ICrmOrderActions::clearArr(array(
|
||||||
'code' => $arDeliveryServicesList['SID'] . '-' . $id,
|
'code' => $arDeliveryServicesList['SID'] . '-' . $id,
|
||||||
'name' => ICrmOrderActions::toJSON($profile['TITLE']),
|
'name' => ICrmOrderActions::toJSON($profile['TITLE']),
|
||||||
'deliveryType' => $arDeliveryServicesList['SID']
|
'deliveryType' => $arDeliveryServicesList['SID']
|
||||||
)));
|
)));
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryServiceEdit',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing dt
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
if ($this->INTARO_CRM_API->getStatusCode() != 200) {
|
ICrmOrderActions::eventLog(
|
||||||
if ($this->INTARO_CRM_API->getStatusCode() != 201) {
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::deliveryServiceEdit::CurlException',
|
||||||
//handle err
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
ICrmOrderActions::eventLog('install/index.php', 'IntaroCrm\RestApi::deliveryServiceEdit', $this->INTARO_CRM_API->getLastError());
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1159,8 +1233,20 @@ class intaro_intarocrm extends CModule {
|
|||||||
$api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0);
|
$api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0);
|
||||||
$api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
|
$api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
|
||||||
$this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
|
$this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
|
||||||
|
try {
|
||||||
$this->INTARO_CRM_API->statisticUpdate();
|
$this->INTARO_CRM_API->statisticUpdate();
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::statisticUpdate',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/install/index.php', 'IntaroCrm\RestApi::statisticUpdate::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
// in fin order
|
// in fin order
|
||||||
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_HISTORY_DATE, date('Y-m-d H:i:s'));
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_HISTORY_DATE, date('Y-m-d H:i:s'));
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?
|
<?
|
||||||
$arModuleVersion = array(
|
$arModuleVersion = array(
|
||||||
"VERSION" => "1.0.2",
|
"VERSION" => "1.0.3",
|
||||||
"VERSION_DATE" => "2014-03-14 20:56:00",
|
"VERSION_DATE" => "2014-03-22 14:51:00",
|
||||||
);
|
);
|
@ -101,13 +101,27 @@ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_RE
|
|||||||
|
|
||||||
$api = new IntaroCrm\RestApi($api_host, $api_key);
|
$api = new IntaroCrm\RestApi($api_host, $api_key);
|
||||||
|
|
||||||
|
try {
|
||||||
$api->paymentStatusesList();
|
$api->paymentStatusesList();
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/options.php', 'IntaroCrm\RestApi::paymentStatusesList',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
//check connection & apiKey valid
|
|
||||||
if ((int) $api->getStatusCode() != 200) {
|
|
||||||
$APPLICATION->RestartBuffer();
|
$APPLICATION->RestartBuffer();
|
||||||
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
|
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
|
||||||
die(json_encode(array('success' => false, 'errMsg' => $api->getStatusCode())));
|
die(json_encode(array('success' => false, 'errMsg' => $e->getCode())));
|
||||||
|
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/options.php', 'IntaroCrm\RestApi::paymentStatusesList::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
$APPLICATION->RestartBuffer();
|
||||||
|
header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
|
||||||
|
die(json_encode(array('success' => false, 'errMsg' => $e->getCode())));
|
||||||
}
|
}
|
||||||
|
|
||||||
$optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0));
|
$optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0));
|
||||||
@ -134,18 +148,23 @@ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_RE
|
|||||||
foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) {
|
foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) {
|
||||||
|
|
||||||
// send to crm
|
// send to crm
|
||||||
|
try {
|
||||||
$api->deliveryServiceEdit(ICrmOrderActions::clearArr(array(
|
$api->deliveryServiceEdit(ICrmOrderActions::clearArr(array(
|
||||||
'code' => $arDeliveryServicesList['SID'] . '-' . $id,
|
'code' => $arDeliveryServicesList['SID'] . '-' . $id,
|
||||||
'name' => ICrmOrderActions::toJSON($profile['TITLE']),
|
'name' => ICrmOrderActions::toJSON($profile['TITLE']),
|
||||||
'deliveryType' => $arDeliveryServicesList['SID']
|
'deliveryType' => $arDeliveryServicesList['SID']
|
||||||
)));
|
)));
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/options.php', 'IntaroCrm\RestApi::deliveryServiceEdit',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
// error pushing dt
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
if ($api->getStatusCode() != 200) {
|
ICrmOrderActions::eventLog(
|
||||||
if ($api->getStatusCode() != 201) {
|
'intaro.crm/options.php', 'IntaroCrm\RestApi::deliveryServiceEdit::CurlException',
|
||||||
//handle err
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
ICrmOrderActions::eventLog('options.php', 'IntaroCrm\RestApi::deliveryServiceEdit', $api->getLastError());
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,18 +189,30 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
|||||||
|
|
||||||
if($api_host && $api_key) {
|
if($api_host && $api_key) {
|
||||||
$api = new IntaroCrm\RestApi($api_host, $api_key);
|
$api = new IntaroCrm\RestApi($api_host, $api_key);
|
||||||
|
try {
|
||||||
$api->paymentStatusesList();
|
$api->paymentStatusesList();
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/options.php', 'IntaroCrm\RestApi::paymentStatusesList',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
//check connection & apiKey valid
|
$uri .= '&errc=ERR_' . $e->getCode();
|
||||||
if((int) $api->getStatusCode() != 200) {
|
|
||||||
$uri .= '&errc=ERR_' . $api->getStatusCode();
|
|
||||||
LocalRedirect($uri);
|
LocalRedirect($uri);
|
||||||
} else {
|
|
||||||
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/options.php', 'IntaroCrm\RestApi::paymentStatusesList::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
$uri .= '&errc=ERR_' . $e->getCode();
|
||||||
|
LocalRedirect($uri);
|
||||||
|
}
|
||||||
|
|
||||||
COption::SetOptionString($mid, 'api_host', $api_host);
|
COption::SetOptionString($mid, 'api_host', $api_host);
|
||||||
COption::SetOptionString($mid, 'api_key', $api_key);
|
COption::SetOptionString($mid, 'api_key', $api_key);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//bitrix orderTypesList -- personTypes
|
//bitrix orderTypesList -- personTypes
|
||||||
$dbOrderTypesList = CSalePersonType::GetList(
|
$dbOrderTypesList = CSalePersonType::GetList(
|
||||||
@ -349,6 +380,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
|||||||
$arResult['arSites'][] = $ar;
|
$arResult['arSites'][] = $ar;
|
||||||
|
|
||||||
//prepare crm lists
|
//prepare crm lists
|
||||||
|
try {
|
||||||
$arResult['orderTypesList'] = $api->orderTypesList();
|
$arResult['orderTypesList'] = $api->orderTypesList();
|
||||||
$arResult['deliveryTypesList'] = $api->deliveryTypesList();
|
$arResult['deliveryTypesList'] = $api->deliveryTypesList();
|
||||||
$arResult['deliveryServicesList'] = $api->deliveryServicesList();
|
$arResult['deliveryServicesList'] = $api->deliveryServicesList();
|
||||||
@ -356,10 +388,22 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
|
|||||||
$arResult['paymentStatusesList'] = $api->paymentStatusesList(); // --statuses
|
$arResult['paymentStatusesList'] = $api->paymentStatusesList(); // --statuses
|
||||||
$arResult['paymentList'] = $api->orderStatusesList();
|
$arResult['paymentList'] = $api->orderStatusesList();
|
||||||
$arResult['paymentGroupList'] = $api->orderStatusGroupsList(); // -- statuses groups
|
$arResult['paymentGroupList'] = $api->orderStatusGroupsList(); // -- statuses groups
|
||||||
|
} catch (\IntaroCrm\Exception\ApiException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/options.php', 'IntaroCrm\RestApi::*List',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
//check connection & apiKey valid
|
echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode()));
|
||||||
if ((int) $api->getStatusCode() != 200)
|
|
||||||
echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $api->getStatusCode()));
|
} catch (\IntaroCrm\Exception\CurlException $e) {
|
||||||
|
ICrmOrderActions::eventLog(
|
||||||
|
'intaro.crm/options.php', 'IntaroCrm\RestApi::*List::CurlException',
|
||||||
|
$e->getCode() . ': ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode()));
|
||||||
|
}
|
||||||
|
|
||||||
//bitrix orderTypesList -- personTypes
|
//bitrix orderTypesList -- personTypes
|
||||||
$dbOrderTypesList = CSalePersonType::GetList(
|
$dbOrderTypesList = CSalePersonType::GetList(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user