1
0
mirror of synced 2024-11-25 14:56:07 +03:00
api-client-php/lib/RetailCrm/ApiClient.php

1459 lines
38 KiB
PHP
Raw Normal View History

<?php
2016-03-09 02:31:29 +03:00
/**
* PHP version 5.3
*
* API client class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
*/
namespace RetailCrm;
use RetailCrm\Http\Client;
use RetailCrm\Response\ApiResponse;
/**
2016-03-09 02:31:29 +03:00
* PHP version 5.3
*
* API client class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
*/
class ApiClient
{
2016-01-09 15:23:50 +03:00
const VERSION = 'v3';
protected $client;
/**
* Site code
*/
protected $siteCode;
/**
* Client creating
*
2016-03-09 02:31:29 +03:00
* @param string $url api url
* @param string $apiKey api key
* @param string $site site code
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function __construct($url, $apiKey, $site = null)
{
2016-03-12 01:54:33 +03:00
if ('/' !== substr($url, strlen($url) - 1, 1)) {
$url .= '/';
}
$url = $url . 'api/' . self::VERSION;
2016-03-09 02:31:29 +03:00
$this->client = new Client($url, array('apiKey' => $apiKey));
$this->siteCode = $site;
}
/**
2016-01-09 15:23:50 +03:00
* Returns filtered orders list
*
2016-01-09 15:23:50 +03:00
* @param array $filter (default: array())
2016-03-09 02:31:29 +03:00
* @param int $page (default: null)
* @param int $limit (default: null)
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function ordersList(array $filter = array(), $page = null, $limit = null)
{
2016-01-09 15:23:50 +03:00
$parameters = array();
2016-03-12 01:54:33 +03:00
if (count($filter)) {
2016-01-09 15:23:50 +03:00
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/orders',
Client::METHOD_GET,
$parameters
);
}
2014-11-06 13:48:07 +03:00
/**
2016-01-09 15:23:50 +03:00
* Create a order
*
2016-03-09 02:31:29 +03:00
* @param array $order order data
* @param string $site (default: null)
2014-11-06 13:48:07 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 13:48:07 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function ordersCreate(array $order, $site = null)
2014-11-06 13:48:07 +03:00
{
2016-03-12 01:54:33 +03:00
if (!count($order)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Parameter `order` must contains a data'
);
2014-11-06 13:48:07 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
'/orders/create',
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
$this->fillSite($site, array('order' => json_encode($order)))
);
2014-11-06 13:48:07 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Save order IDs' (id and externalId) association in the CRM
*
2016-03-09 02:31:29 +03:00
* @param array $ids order identificators
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function ordersFixExternalIds(array $ids)
{
2016-03-12 01:54:33 +03:00
if (! count($ids)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Method parameter must contains at least one IDs pair'
);
2016-01-09 15:23:50 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
'/orders/fix-external-ids',
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('orders' => json_encode($ids)
)
);
}
2014-11-06 03:18:39 +03:00
/**
* Returns a orders history
*
2016-03-09 02:31:29 +03:00
* @param \DateTime $startDate (default: null)
* @param \DateTime $endDate (default: null)
* @param int $limit (default: 100)
* @param int $offset (default: 0)
* @param bool $skipMyChanges (default: true)
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 03:18:39 +03:00
* @return ApiResponse
*/
2016-03-09 02:31:29 +03:00
public function ordersHistory(
\DateTime $startDate = null,
\DateTime $endDate = null,
$limit = 100,
$offset = 0,
$skipMyChanges = true
) {
2014-11-06 03:18:39 +03:00
$parameters = array();
if ($startDate) {
$parameters['startDate'] = $startDate->format('Y-m-d H:i:s');
}
if ($endDate) {
$parameters['endDate'] = $endDate->format('Y-m-d H:i:s');
}
if ($limit) {
$parameters['limit'] = (int) $limit;
}
if ($offset) {
$parameters['offset'] = (int) $offset;
}
2014-11-06 17:19:20 +03:00
if ($skipMyChanges) {
$parameters['skipMyChanges'] = (bool) $skipMyChanges;
}
2014-11-06 03:18:39 +03:00
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/orders/history',
Client::METHOD_GET,
$parameters
);
2014-11-06 03:18:39 +03:00
}
2014-11-06 03:50:15 +03:00
/**
2016-01-09 15:23:50 +03:00
* Returns statuses of the orders
*
2016-03-09 02:31:29 +03:00
* @param array $ids (default: array())
2016-01-09 15:23:50 +03:00
* @param array $externalIds (default: array())
2014-11-06 03:50:15 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 13:48:07 +03:00
* @return ApiResponse
2014-11-06 03:50:15 +03:00
*/
2016-03-09 02:31:29 +03:00
public function ordersStatuses(
array $ids = array(),
array $externalIds = array()
) {
2014-11-06 03:50:15 +03:00
$parameters = array();
2016-03-12 01:54:33 +03:00
if (count($ids)) {
2016-01-09 15:23:50 +03:00
$parameters['ids'] = $ids;
2014-11-06 03:50:15 +03:00
}
2016-03-12 01:54:33 +03:00
if (count($externalIds)) {
2016-01-09 15:23:50 +03:00
$parameters['externalIds'] = $externalIds;
2014-11-06 03:50:15 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/orders/statuses',
Client::METHOD_GET,
$parameters
);
2014-11-06 03:50:15 +03:00
}
2014-11-13 09:37:53 +03:00
/**
2016-01-09 15:23:50 +03:00
* Upload array of the orders
*
2016-03-09 02:31:29 +03:00
* @param array $orders array of orders
* @param string $site (default: null)
2014-11-13 09:37:53 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-13 09:37:53 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function ordersUpload(array $orders, $site = null)
2014-11-13 09:37:53 +03:00
{
2016-03-12 01:54:33 +03:00
if (!count($orders)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Parameter `orders` must contains array of the orders'
);
2014-11-13 09:37:53 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
'/orders/upload',
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
$this->fillSite($site, array('orders' => json_encode($orders)))
);
2014-11-13 09:37:53 +03:00
}
2014-11-06 13:48:07 +03:00
/**
2016-01-09 15:23:50 +03:00
* Get order by id or externalId
*
2016-03-09 02:31:29 +03:00
* @param string $id order identificator
* @param string $by (default: 'externalId')
2016-01-09 15:23:50 +03:00
* @param string $site (default: null)
2014-11-06 13:48:07 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 13:48:07 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function ordersGet($id, $by = 'externalId', $site = null)
2014-11-06 13:48:07 +03:00
{
2016-01-09 15:23:50 +03:00
$this->checkIdParameter($by);
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
"/orders/$id",
Client::METHOD_GET,
$this->fillSite($site, array('by' => $by))
);
2016-01-09 15:23:50 +03:00
}
/**
* Edit a order
*
2016-03-09 02:31:29 +03:00
* @param array $order order data
* @param string $by (default: 'externalId')
* @param string $site (default: null)
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2016-01-09 15:23:50 +03:00
* @return ApiResponse
*/
public function ordersEdit(array $order, $by = 'externalId', $site = null)
{
2016-03-12 01:54:33 +03:00
if (!count($order)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Parameter `order` must contains a data'
);
2014-11-06 13:48:07 +03:00
}
2016-01-09 15:23:50 +03:00
$this->checkIdParameter($by);
2016-03-12 01:54:33 +03:00
if (!array_key_exists($by, $order)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
sprintf('Order array must contain the "%s" parameter.', $by)
);
2016-01-09 15:23:50 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/orders/%s/edit', $order[$by]),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
$this->fillSite(
$site,
array('order' => json_encode($order), 'by' => $by)
)
);
2014-11-06 13:48:07 +03:00
}
2015-05-08 18:03:05 +03:00
/**
2016-01-09 15:23:50 +03:00
* Returns filtered customers list
*
* @param array $filter (default: array())
2016-03-09 02:31:29 +03:00
* @param int $page (default: null)
* @param int $limit (default: null)
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
2016-03-09 02:31:29 +03:00
public function customersList(
array $filter = array(),
$page = null,
$limit = null
) {
$parameters = array();
2016-03-12 01:54:33 +03:00
if (count($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/customers',
Client::METHOD_GET,
$parameters
);
}
2014-11-06 13:48:07 +03:00
/**
* Create a customer
*
2016-03-09 02:31:29 +03:00
* @param array $customer customer data
* @param string $site (default: null)
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 13:48:07 +03:00
* @return ApiResponse
*/
public function customersCreate(array $customer, $site = null)
2014-11-06 13:48:07 +03:00
{
2016-03-12 01:54:33 +03:00
if (! count($customer)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Parameter `customer` must contains a data'
);
2014-11-06 13:48:07 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
'/customers/create',
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
$this->fillSite($site, array('customer' => json_encode($customer)))
);
2014-11-06 13:48:07 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Save customer IDs' (id and externalId) association in the CRM
*
2016-03-09 02:31:29 +03:00
* @param array $ids ids mapping
2014-11-06 13:48:07 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 13:48:07 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function customersFixExternalIds(array $ids)
2014-11-06 13:48:07 +03:00
{
2016-03-12 01:54:33 +03:00
if (! count($ids)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Method parameter must contains at least one IDs pair'
);
2014-11-06 13:48:07 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
'/customers/fix-external-ids',
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('customers' => json_encode($ids))
);
2014-11-06 13:48:07 +03:00
}
/**
* Upload array of the customers
*
2016-03-09 02:31:29 +03:00
* @param array $customers array of customers
* @param string $site (default: null)
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 13:48:07 +03:00
* @return ApiResponse
*/
public function customersUpload(array $customers, $site = null)
2014-11-06 13:48:07 +03:00
{
2016-03-12 01:54:33 +03:00
if (! count($customers)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Parameter `customers` must contains array of the customers'
);
2014-11-06 13:48:07 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
'/customers/upload',
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
$this->fillSite($site, array('customers' => json_encode($customers)))
);
2014-11-06 13:48:07 +03:00
}
/**
* Get customer by id or externalId
*
2016-03-09 02:31:29 +03:00
* @param string $id customer identificator
* @param string $by (default: 'externalId')
2016-01-09 15:23:50 +03:00
* @param string $site (default: null)
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 13:48:07 +03:00
* @return ApiResponse
*/
public function customersGet($id, $by = 'externalId', $site = null)
2014-11-06 13:48:07 +03:00
{
$this->checkIdParameter($by);
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
"/customers/$id",
Client::METHOD_GET,
$this->fillSite($site, array('by' => $by))
);
2014-11-06 13:48:07 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Edit a customer
*
2016-03-09 02:31:29 +03:00
* @param array $customer customer data
* @param string $by (default: 'externalId')
* @param string $site (default: null)
2014-11-06 13:48:07 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 13:48:07 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function customersEdit(array $customer, $by = 'externalId', $site = null)
{
2016-03-12 01:54:33 +03:00
if (!count($customer)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Parameter `customer` must contains a data'
);
2016-01-09 15:23:50 +03:00
}
$this->checkIdParameter($by);
2016-03-12 01:54:33 +03:00
if (!array_key_exists($by, $customer)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
sprintf('Customer array must contain the "%s" parameter.', $by)
);
2016-01-09 15:23:50 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/customers/%s/edit', $customer[$by]),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
$this->fillSite(
$site,
array('customer' => json_encode($customer), 'by' => $by)
)
);
2016-01-09 15:23:50 +03:00
}
/**
* Get orders assembly list
*
* @param array $filter (default: array())
2016-03-09 02:31:29 +03:00
* @param int $page (default: null)
* @param int $limit (default: null)
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2016-01-09 15:23:50 +03:00
* @return ApiResponse
*/
2016-03-09 02:31:29 +03:00
public function ordersPacksList(
array $filter = array(),
$page = null,
$limit = null
) {
2014-11-06 13:48:07 +03:00
$parameters = array();
2016-03-12 01:54:33 +03:00
if (count($filter)) {
2014-11-06 13:48:07 +03:00
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/orders/packs',
Client::METHOD_GET,
$parameters
);
2014-11-06 13:48:07 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Create orders assembly
*
2016-03-09 02:31:29 +03:00
* @param array $pack pack data
2016-01-09 15:23:50 +03:00
* @param string $site (default: null)
2014-11-06 13:48:07 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 13:48:07 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function ordersPacksCreate(array $pack, $site = null)
2014-11-06 13:48:07 +03:00
{
2016-03-12 01:54:33 +03:00
if (!count($pack)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Parameter `pack` must contains a data'
);
2014-11-06 13:48:07 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
'/orders/packs/create',
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
$this->fillSite($site, array('pack' => json_encode($pack)))
);
2014-11-06 13:48:07 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Get orders assembly history
*
* @param array $filter (default: array())
2016-03-09 02:31:29 +03:00
* @param int $page (default: null)
* @param int $limit (default: null)
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
2016-03-09 02:31:29 +03:00
public function ordersPacksHistory(
array $filter = array(),
$page = null,
$limit = null
) {
$parameters = array();
2016-03-12 01:54:33 +03:00
if (count($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/orders/packs/history',
Client::METHOD_GET,
$parameters
);
}
/**
2016-01-09 15:23:50 +03:00
* Get orders assembly by id
*
2016-03-09 02:31:29 +03:00
* @param string $id pack identificator
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function ordersPacksGet($id)
{
2016-01-09 15:23:50 +03:00
if (empty($id)) {
throw new \InvalidArgumentException('Parameter `id` must be set');
}
2016-03-12 01:54:33 +03:00
return $this->client->makeRequest(
"/orders/packs/$id",
Client::METHOD_GET
);
}
2014-11-06 16:39:55 +03:00
/**
2016-01-09 15:23:50 +03:00
* Delete orders assembly by id
2014-11-06 16:39:55 +03:00
*
2016-03-09 02:31:29 +03:00
* @param string $id pack identificator
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function ordersPacksDelete($id)
2014-11-06 16:39:55 +03:00
{
2016-01-09 15:23:50 +03:00
if (empty($id)) {
throw new \InvalidArgumentException('Parameter `id` must be set');
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/orders/packs/%s/delete', $id),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Edit orders assembly
*
2016-03-09 02:31:29 +03:00
* @param array $pack pack data
2016-01-09 15:23:50 +03:00
* @param string $site (default: null)
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function ordersPacksEdit(array $pack, $site = null)
2014-11-06 16:39:55 +03:00
{
2016-03-12 01:54:33 +03:00
if (!count($pack) || empty($pack['id'])) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Parameter `pack` must contains a data & pack `id` must be set'
);
2016-01-09 15:23:50 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/orders/packs/%s/edit', $pack['id']),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
$this->fillSite($site, array('pack' => json_encode($pack)))
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Get purchace prices & stock balance
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
2016-03-12 01:54:33 +03:00
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
2014-11-06 16:39:55 +03:00
*
* @return ApiResponse
*/
2016-03-09 02:31:29 +03:00
public function storeInventories(
array $filter = array(),
$page = null,
2016-03-12 01:54:33 +03:00
$limit = null
2016-03-09 02:31:29 +03:00
) {
2016-01-09 15:23:50 +03:00
$parameters = array();
2016-03-12 01:54:33 +03:00
if (count($filter)) {
2016-01-09 15:23:50 +03:00
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/store/inventories',
Client::METHOD_GET,
2016-03-12 01:54:33 +03:00
$parameters
2016-03-09 02:31:29 +03:00
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Upload store inventories
*
2016-03-09 02:31:29 +03:00
* @param array $offers offers data
* @param string $site (default: null)
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function storeInventoriesUpload(array $offers, $site = null)
2014-11-06 16:39:55 +03:00
{
2016-03-12 01:54:33 +03:00
if (!count($offers)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Parameter `offers` must contains array of the offers'
);
2016-01-09 15:23:50 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
'/store/inventories/upload',
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
$this->fillSite($site, array('offers' => json_encode($offers)))
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Returns available county list
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function countriesList()
2014-11-06 16:39:55 +03:00
{
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/reference/countries',
Client::METHOD_GET
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Returns deliveryServices list
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function deliveryServicesList()
2014-11-06 16:39:55 +03:00
{
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/reference/delivery-services',
Client::METHOD_GET
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Edit deliveryService
*
* @param array $data delivery service data
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function deliveryServicesEdit(array $data)
2014-11-06 16:39:55 +03:00
{
2016-03-12 01:54:33 +03:00
if (!array_key_exists('code', $data)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
2016-01-09 15:23:50 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/reference/delivery-services/%s/edit', $data['code']),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('deliveryService' => json_encode($data))
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Returns deliveryTypes list
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function deliveryTypesList()
2014-11-06 16:39:55 +03:00
{
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/reference/delivery-types',
Client::METHOD_GET
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Edit deliveryType
*
* @param array $data delivery type data
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function deliveryTypesEdit(array $data)
{
2016-03-12 01:54:33 +03:00
if (!array_key_exists('code', $data)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
2016-01-09 15:23:50 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/reference/delivery-types/%s/edit', $data['code']),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('deliveryType' => json_encode($data))
);
}
2015-06-15 16:40:39 +03:00
/**
2016-01-09 15:23:50 +03:00
* Returns orderMethods list
2015-06-15 16:40:39 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-15 16:40:39 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function orderMethodsList()
2015-06-15 16:40:39 +03:00
{
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
'/reference/order-methods',
Client::METHOD_GET
2016-03-09 02:31:29 +03:00
);
2015-06-15 16:40:39 +03:00
}
2014-11-06 16:39:55 +03:00
/**
2016-01-09 15:23:50 +03:00
* Edit orderMethod
*
* @param array $data order method data
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function orderMethodsEdit(array $data)
2014-11-06 16:39:55 +03:00
{
2016-03-12 01:54:33 +03:00
if (!array_key_exists('code', $data)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
2014-11-06 16:39:55 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/reference/order-methods/%s/edit', $data['code']),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('orderMethod' => json_encode($data))
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Returns orderTypes list
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function orderTypesList()
2014-11-06 16:39:55 +03:00
{
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/reference/order-types',
Client::METHOD_GET
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Edit orderType
*
* @param array $data order type data
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function orderTypesEdit(array $data)
2014-11-06 16:39:55 +03:00
{
2016-03-12 01:54:33 +03:00
if (!array_key_exists('code', $data)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
2014-11-06 16:39:55 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/reference/order-types/%s/edit', $data['code']),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('orderType' => json_encode($data))
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Returns paymentStatuses list
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function paymentStatusesList()
2014-11-06 16:39:55 +03:00
{
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/reference/payment-statuses',
Client::METHOD_GET
);
2014-11-06 16:39:55 +03:00
}
/**
* Edit paymentStatus
*
* @param array $data payment status data
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
public function paymentStatusesEdit(array $data)
{
2016-03-12 01:54:33 +03:00
if (!array_key_exists('code', $data)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
2014-11-06 16:39:55 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/reference/payment-statuses/%s/edit', $data['code']),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('paymentStatus' => json_encode($data))
);
2016-01-09 15:23:50 +03:00
}
/**
* Returns paymentTypes list
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2016-01-09 15:23:50 +03:00
* @return ApiResponse
*/
public function paymentTypesList()
{
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/reference/payment-types',
Client::METHOD_GET
);
2014-11-06 16:39:55 +03:00
}
/**
* Edit paymentType
*
* @param array $data payment type data
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
public function paymentTypesEdit(array $data)
{
2016-03-12 01:54:33 +03:00
if (!array_key_exists('code', $data)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
2014-11-06 16:39:55 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/reference/payment-types/%s/edit', $data['code']),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('paymentType' => json_encode($data))
);
2016-01-09 15:23:50 +03:00
}
/**
* Returns productStatuses list
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2016-01-09 15:23:50 +03:00
* @return ApiResponse
*/
public function productStatusesList()
{
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/reference/product-statuses',
Client::METHOD_GET
);
2014-11-06 16:39:55 +03:00
}
/**
* Edit productStatus
*
* @param array $data product status data
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
public function productStatusesEdit(array $data)
{
2016-03-12 01:54:33 +03:00
if (!array_key_exists('code', $data)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
2014-11-06 16:39:55 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/reference/product-statuses/%s/edit', $data['code']),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('productStatus' => json_encode($data))
);
2014-11-06 16:39:55 +03:00
}
/**
2016-01-09 15:23:50 +03:00
* Returns sites list
2014-11-06 16:39:55 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
2016-01-09 15:23:50 +03:00
public function sitesList()
2014-11-06 16:39:55 +03:00
{
2016-03-12 01:54:33 +03:00
return $this->client->makeRequest(
'/reference/sites',
Client::METHOD_GET
);
2014-11-06 16:39:55 +03:00
}
/**
* Edit site
*
* @param array $data site data
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function sitesEdit(array $data)
{
2016-03-12 01:54:33 +03:00
if (!array_key_exists('code', $data)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/reference/sites/%s/edit', $data['code']),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('site' => json_encode($data))
);
2016-01-09 15:23:50 +03:00
}
/**
* Returns statusGroups list
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2016-01-09 15:23:50 +03:00
* @return ApiResponse
*/
public function statusGroupsList()
{
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/reference/status-groups',
Client::METHOD_GET
);
2016-01-09 15:23:50 +03:00
}
/**
* Returns statuses list
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2016-01-09 15:23:50 +03:00
* @return ApiResponse
*/
public function statusesList()
{
2016-03-12 01:54:33 +03:00
return $this->client->makeRequest(
'/reference/statuses',
Client::METHOD_GET
);
2016-01-09 15:23:50 +03:00
}
/**
* Edit order status
*
* @param array $data status data
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2016-01-09 15:23:50 +03:00
* @return ApiResponse
*/
public function statusesEdit(array $data)
{
2016-03-12 01:54:33 +03:00
if (!array_key_exists('code', $data)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
2016-01-09 15:23:50 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/reference/statuses/%s/edit', $data['code']),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('status' => json_encode($data))
);
2016-01-09 15:23:50 +03:00
}
/**
* Returns stores list
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2016-01-09 15:23:50 +03:00
* @return ApiResponse
*/
public function storesList()
{
2016-03-12 01:54:33 +03:00
return $this->client->makeRequest(
'/reference/stores',
Client::METHOD_GET
);
}
2015-06-15 16:40:39 +03:00
/**
* Edit store
*
* @param array $data site data
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-15 16:40:39 +03:00
* @return ApiResponse
*/
public function storesEdit(array $data)
{
2016-03-12 01:54:33 +03:00
if (!array_key_exists('code', $data)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
2015-06-15 16:40:39 +03:00
}
2016-03-12 01:54:33 +03:00
if (!array_key_exists('name', $data)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Data must contain "name" parameter.'
);
2015-06-15 16:40:39 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
sprintf('/reference/stores/%s/edit', $data['code']),
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('store' => json_encode($data))
);
2015-06-15 16:40:39 +03:00
}
/**
* Telephony settings
*
* @param string $code symbolic code
* @param string $clientId client id
* @param boolean $active telephony activity
* @param mixed $makeCallUrl service init url
* @param mixed $name service name
* @param mixed $image service logo url(svg file)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function telephonySettings(
$code,
$clientId,
$active = false,
$makeCallUrl = false,
$name = false,
$image = false
) {
if (!isset($code)) {
throw new \InvalidArgumentException('Code must be set');
}
$parameters['code'] = $code;
if (!isset($clientId)) {
throw new \InvalidArgumentException('client id must be set');
}
$parameters['clientId'] = $clientId;
if (!isset($active)) {
$parameters['active'] = false;
} else {
$parameters['active'] = $active;
}
if (!isset($name)) {
throw new \InvalidArgumentException('name must be set');
}
if (isset($makeCallUrl)) {
$parameters['makeCallUrl'] = $makeCallUrl;
}
if (isset($name)) {
$parameters['name'] = $name;
}
if (isset($image)) {
$parameters['image'] = $image;
}
return $this->client->makeRequest(
"/telephony/setting/$code",
Client::METHOD_POST,
$parameters
);
}
2014-11-06 16:39:55 +03:00
/**
* Update CRM basic statistic
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2014-11-06 16:39:55 +03:00
* @return ApiResponse
*/
public function statisticUpdate()
{
2016-03-12 01:54:33 +03:00
return $this->client->makeRequest(
'/statistic/update',
Client::METHOD_GET
);
2014-11-06 16:39:55 +03:00
}
2016-01-09 15:23:50 +03:00
/**
* Call event
*
2016-03-09 02:31:29 +03:00
* @param string $phone phone number
* @param string $type call type
* @param string $code additional phone code
* @param string $status call status
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2016-01-09 15:23:50 +03:00
* @return ApiResponse
*/
public function telephonyCallEvent($phone, $type, $code, $status)
{
2016-03-12 01:54:33 +03:00
if (!isset($phone)) {
2016-01-09 15:23:50 +03:00
throw new \InvalidArgumentException('Phone number must be set');
}
$parameters['phone'] = $phone;
2016-03-12 01:54:33 +03:00
if (!isset($type)) {
2016-01-09 15:23:50 +03:00
throw new \InvalidArgumentException('Type must be set (in|out|hangup)');
}
$parameters['type'] = $type;
2016-03-12 01:54:33 +03:00
if (!isset($code)) {
2016-01-09 15:23:50 +03:00
throw new \InvalidArgumentException('Code must be set');
}
$parameters['code'] = $code;
$parameters['hangupStatus'] = $status;
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/telephony/call/event',
Client::METHOD_POST,
$parameters
);
2016-01-09 15:23:50 +03:00
}
/**
* Upload calls
*
2016-03-09 02:31:29 +03:00
* @param array $calls calls data
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2016-01-09 15:23:50 +03:00
* @return ApiResponse
*/
public function telephonyCallsUpload(array $calls)
{
2016-03-12 01:54:33 +03:00
if (!count($calls)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
'Parameter `calls` must contains array of the calls'
);
2016-01-09 15:23:50 +03:00
}
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
2016-03-12 01:54:33 +03:00
'/telephony/calls/upload',
2016-03-09 02:31:29 +03:00
Client::METHOD_POST,
array('calls' => json_encode($calls))
);
2016-01-09 15:23:50 +03:00
}
/**
* Get call manager
*
2016-03-09 02:31:29 +03:00
* @param string $phone phone number
* @param bool $details detailed information
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2016-01-09 15:23:50 +03:00
* @return ApiResponse
*/
public function telephonyCallManager($phone, $details)
{
if (!isset($phone)) {
throw new \InvalidArgumentException('Phone number must be set');
}
$parameters['phone'] = $phone;
$parameters['details'] = isset($details) ? $details : 0;
2016-03-09 02:31:29 +03:00
return $this->client->makeRequest(
'/telephony/manager',
2016-03-12 01:54:33 +03:00
Client::METHOD_GET,
$parameters
2016-03-09 02:31:29 +03:00
);
2016-01-09 15:23:50 +03:00
}
/**
* Return current site
*
* @return string
*/
public function getSite()
{
return $this->siteCode;
}
/**
* Set site
*
2016-03-09 02:31:29 +03:00
* @param string $site site code
2016-01-09 15:23:50 +03:00
*
* @return void
*/
public function setSite($site)
{
$this->siteCode = $site;
}
/**
* Check ID parameter
*
2016-03-09 02:31:29 +03:00
* @param string $by identify by
2016-01-09 15:23:50 +03:00
*
2016-03-12 01:54:33 +03:00
* @throws \InvalidArgumentException
*
* @return bool
*/
protected function checkIdParameter($by)
{
2016-01-09 15:23:50 +03:00
$allowedForBy = array(
'externalId',
'id'
);
2016-03-09 02:31:29 +03:00
2016-03-12 01:54:33 +03:00
if (!in_array($by, $allowedForBy, false)) {
2016-03-09 02:31:29 +03:00
throw new \InvalidArgumentException(
sprintf(
'Value "%s" for "by" param is not valid. Allowed values are %s.',
2016-03-09 02:31:29 +03:00
$by,
implode(', ', $allowedForBy)
)
);
}
return true;
}
/**
* Fill params by site value
*
2016-03-09 02:31:29 +03:00
* @param string $site site code
* @param array $params input parameters
2016-01-09 15:23:50 +03:00
*
* @return array
*/
protected function fillSite($site, array $params)
{
if ($site) {
$params['site'] = $site;
} elseif ($this->siteCode) {
$params['site'] = $this->siteCode;
}
return $params;
}
}