1
0
mirror of synced 2024-11-29 00:25:30 +03:00
magento-module/Model/ApiClient/ApiClient.php

1844 lines
48 KiB
PHP
Raw Normal View History

<?php
/**
2017-02-03 11:05:00 +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/ApiVersion4
*/
2017-05-31 15:24:46 +03:00
namespace Retailcrm\Retailcrm\Model\ApiClient;
use Retailcrm\Retailcrm\Model\ApiClient\Http\Client;
use Retailcrm\Retailcrm\Model\ApiClient\Response\ApiResponse;
/**
* 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/ApiVersion4
*/
class ApiClient
{
2017-02-03 11:05:00 +03:00
const VERSION = 'v4';
protected $client;
/**
* Site code
*/
protected $siteCode;
/**
2017-02-03 11:05:00 +03:00
* Client creating
*
* @param string $url api url
* @param string $apiKey api key
* @param string $site site code
*
2017-02-03 11:05:00 +03:00
* @throws \InvalidArgumentException
*/
2017-02-03 11:05:00 +03:00
public function __construct($url, $apiKey, $site = null)
{
2017-02-03 11:05:00 +03:00
if ('/' !== $url[strlen($url) - 1]) {
$url .= '/';
}
$url = $url . 'api/' . self::VERSION;
2017-05-31 15:24:46 +03:00
$this->client = new Client($url, array('apiKey' => $apiKey));
2017-02-03 11:05:00 +03:00
$this->siteCode = $site;
}
/**
2017-02-03 11:05:00 +03:00
* Returns users list
*
* @param array $filter
* @param null $page
* @param null $limit
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function usersList(array $filter = array(), $page = null, $limit = null)
{
2017-02-03 11:05:00 +03:00
$parameters = array();
2017-05-31 15:24:46 +03:00
2017-02-03 11:05:00 +03:00
if (count($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2017-05-31 15:24:46 +03:00
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/users',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
);
}
/**
* Get user groups
*
* @param null $page
* @param null $limit
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
*
* @return ApiResponse
*/
public function usersGroups($page = null, $limit = null)
{
$parameters = array();
2017-02-03 11:05:00 +03:00
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
return $this->client->makeRequest(
'/user-groups',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
);
}
/**
2017-02-03 11:05:00 +03:00
* Returns user data
*
* @param integer $id user ID
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function usersGet($id)
{
2017-05-31 15:24:46 +03:00
return $this->client->makeRequest("/users/$id", Client::METHOD_GET);
2017-02-03 11:05:00 +03:00
}
/**
* Returns filtered orders list
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function ordersList(array $filter = array(), $page = null, $limit = null)
{
$parameters = array();
if (count($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2017-05-31 15:24:46 +03:00
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/orders',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
);
}
/**
* Create a order
*
* @param array $order order data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function ordersCreate(array $order, $site = null)
{
2017-02-03 11:05:00 +03:00
if (!count($order)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `order` must contains a data'
);
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/orders/create',
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
$this->fillSite($site, array('order' => json_encode($order)))
);
}
2017-02-03 11:05:00 +03:00
/**
* Save order IDs' (id and externalId) association in the CRM
*
* @param array $ids order identificators
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function ordersFixExternalIds(array $ids)
{
if (! count($ids)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Method parameter must contains at least one IDs pair'
);
}
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
'/orders/fix-external-ids',
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('orders' => json_encode($ids)
)
);
}
/**
* Returns statuses of the orders
*
* @param array $ids (default: array())
* @param array $externalIds (default: array())
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function ordersStatuses(array $ids = array(), array $externalIds = array())
{
$parameters = array();
if (count($ids)) {
$parameters['ids'] = $ids;
}
if (count($externalIds)) {
$parameters['externalIds'] = $externalIds;
}
2017-05-31 15:24:46 +03:00
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/orders/statuses',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
);
}
/**
* Upload array of the orders
*
2017-02-03 11:05:00 +03:00
* @param array $orders array of orders
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
public function ordersUpload(array $orders, $site = null)
{
2017-02-03 11:05:00 +03:00
if (!count($orders)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `orders` must contains array of the orders'
);
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/orders/upload',
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
$this->fillSite($site, array('orders' => json_encode($orders)))
);
}
/**
* Get order by id or externalId
*
2017-02-03 11:05:00 +03:00
* @param string $id order identificator
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
public function ordersGet($id, $by = 'externalId', $site = null)
{
$this->checkIdParameter($by);
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
"/orders/$id",
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$this->fillSite($site, array('by' => $by))
);
}
/**
2017-02-03 11:05:00 +03:00
* Edit a order
*
* @param array $order order data
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function ordersEdit(array $order, $by = 'externalId', $site = null)
{
if (!count($order)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `order` must contains a data'
);
}
$this->checkIdParameter($by);
if (!array_key_exists($by, $order)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
sprintf('Order array must contain the "%s" parameter.', $by)
);
}
return $this->client->makeRequest(
sprintf('/orders/%s/edit', $order[$by]),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
$this->fillSite(
$site,
array('order' => json_encode($order), 'by' => $by)
)
);
}
/**
* Get orders history
* @param array $filter
* @param null $page
* @param null $limit
*
* @return ApiResponse
*/
public function ordersHistory(array $filter = array(), $page = null, $limit = null)
{
$parameters = array();
2017-02-03 11:05:00 +03:00
if (count($filter)) {
$parameters['filter'] = $filter;
}
2017-02-03 11:05:00 +03:00
if (null !== $page) {
$parameters['page'] = (int) $page;
}
2017-02-03 11:05:00 +03:00
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/orders/history',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
);
}
/**
* Returns filtered customers list
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function customersList(array $filter = array(), $page = null, $limit = null)
{
$parameters = array();
if (count($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
2017-02-03 11:05:00 +03:00
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/customers',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
);
}
/**
2017-02-03 11:05:00 +03:00
* Create a customer
*
* @param array $customer customer data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function customersCreate(array $customer, $site = null)
{
if (! count($customer)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `customer` must contains a data'
);
}
return $this->client->makeRequest(
'/customers/create',
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
$this->fillSite($site, array('customer' => json_encode($customer)))
);
}
/**
* Save customer IDs' (id and externalId) association in the CRM
*
* @param array $ids ids mapping
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function customersFixExternalIds(array $ids)
{
if (! count($ids)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Method parameter must contains at least one IDs pair'
);
}
return $this->client->makeRequest(
'/customers/fix-external-ids',
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('customers' => json_encode($ids))
);
}
/**
* Upload array of the customers
*
* @param array $customers array of customers
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function customersUpload(array $customers, $site = null)
{
if (! count($customers)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `customers` must contains array of the customers'
);
}
return $this->client->makeRequest(
'/customers/upload',
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
$this->fillSite($site, array('customers' => json_encode($customers)))
);
}
/**
* Get customer by id or externalId
*
* @param string $id customer identificator
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function customersGet($id, $by = 'externalId', $site = null)
{
$this->checkIdParameter($by);
return $this->client->makeRequest(
"/customers/$id",
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$this->fillSite($site, array('by' => $by))
);
}
/**
* Edit a customer
*
* @param array $customer customer data
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function customersEdit(array $customer, $by = 'externalId', $site = null)
{
if (!count($customer)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `customer` must contains a data'
);
}
$this->checkIdParameter($by);
if (!array_key_exists($by, $customer)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
sprintf('Customer array must contain the "%s" parameter.', $by)
);
}
return $this->client->makeRequest(
sprintf('/customers/%s/edit', $customer[$by]),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
$this->fillSite(
$site,
array('customer' => json_encode($customer), 'by' => $by)
)
);
}
/**
* Get customers history
* @param array $filter
* @param null $page
* @param null $limit
*
* @return ApiResponse
*/
public function customersHistory(array $filter = array(), $page = null, $limit = null)
{
$parameters = array();
2017-02-03 11:05:00 +03:00
if (count($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/customers/history',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
);
}
/**
2017-02-03 11:05:00 +03:00
* Get orders assembly list
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function ordersPacksList(array $filter = array(), $page = null, $limit = null)
{
$parameters = array();
2017-02-03 11:05:00 +03:00
if (count($filter)) {
$parameters['filter'] = $filter;
}
2017-02-03 11:05:00 +03:00
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/orders/packs',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
);
}
/**
2017-02-03 11:05:00 +03:00
* Create orders assembly
*
* @param array $pack pack data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function ordersPacksCreate(array $pack, $site = null)
{
2017-02-03 11:05:00 +03:00
if (!count($pack)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `pack` must contains a data'
);
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/orders/packs/create',
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
$this->fillSite($site, array('pack' => json_encode($pack)))
);
}
2015-06-25 18:01:54 +03:00
/**
* Get orders assembly history
*
2017-02-03 11:05:00 +03:00
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
public function ordersPacksHistory(array $filter = array(), $page = null, $limit = null)
{
$parameters = array();
2017-02-03 11:05:00 +03:00
if (count($filter)) {
2015-06-25 18:01:54 +03:00
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/orders/packs/history',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
);
2015-06-25 18:01:54 +03:00
}
/**
2017-02-03 11:05:00 +03:00
* Get orders assembly by id
*
* @param string $id pack identificator
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function ordersPacksGet($id)
{
2017-02-03 11:05:00 +03:00
if (empty($id)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('Parameter `id` must be set');
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
"/orders/packs/$id",
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
/**
2017-02-03 11:05:00 +03:00
* Delete orders assembly by id
*
* @param string $id pack identificator
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function ordersPacksDelete($id)
{
2017-02-03 11:05:00 +03:00
if (empty($id)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('Parameter `id` must be set');
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
sprintf('/orders/packs/%s/delete', $id),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST
2017-02-03 11:05:00 +03:00
);
}
2017-02-03 11:05:00 +03:00
/**
* Edit orders assembly
*
* @param array $pack pack data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function ordersPacksEdit(array $pack, $site = null)
{
if (!count($pack) || empty($pack['id'])) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `pack` must contains a data & pack `id` must be set'
);
}
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
sprintf('/orders/packs/%s/edit', $pack['id']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
$this->fillSite($site, array('pack' => json_encode($pack)))
2015-06-25 18:01:54 +03:00
);
}
/**
2017-02-03 11:05:00 +03:00
* Get purchace prices & stock balance
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function storeInventories(array $filter = array(), $page = null, $limit = null)
{
2017-02-03 11:05:00 +03:00
$parameters = array();
if (count($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/store/inventories',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
);
}
/**
2017-02-03 11:05:00 +03:00
* Get store settings
*
* @param string $code get settings code
*
* @return ApiResponse
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function storeSettingsGet($code)
{
2017-02-03 11:05:00 +03:00
if (empty($code)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('Parameter `code` must be set');
2017-02-03 11:05:00 +03:00
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
"/store/setting/$code",
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
/**
2017-02-03 11:05:00 +03:00
* Edit store configuration
*
* @param array $configuration
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function storeSettingsEdit(array $configuration)
{
if (!count($configuration) || empty($configuration['code'])) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `configuration` must contains a data & configuration `code` must be set'
);
}
return $this->client->makeRequest(
sprintf('/store/setting/%s/edit', $configuration['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('configuration' => json_encode($configuration))
);
}
/**
* Upload store inventories
*
* @param array $offers offers data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function storeInventoriesUpload(array $offers, $site = null)
{
if (!count($offers)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `offers` must contains array of the offers'
);
}
return $this->client->makeRequest(
'/store/inventories/upload',
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
$this->fillSite($site, array('offers' => json_encode($offers)))
);
}
/**
* Upload store prices
*
* @param array $prices prices data
* @param string $site default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function storePricesUpload(array $prices, $site = null)
{
if (!count($prices)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `prices` must contains array of the prices'
);
}
return $this->client->makeRequest(
'/store/prices/upload',
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
$this->fillSite($site, array('prices' => json_encode($prices)))
);
}
/**
* Get products
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function storeProducts(array $filter = array(), $page = null, $limit = null)
{
$parameters = array();
2017-02-03 11:05:00 +03:00
if (count($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
2017-05-31 15:24:46 +03:00
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/store/products',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
);
}
/**
* Get delivery settings
*
* @param string $code
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function deliverySettingsGet($code)
{
if (empty($code)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('Parameter `code` must be set');
2017-02-03 11:05:00 +03:00
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
"/delivery/generic/setting/$code",
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
/**
2017-02-03 11:05:00 +03:00
* Edit delivery configuration
*
* @param array $configuration
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
*/
public function deliverySettingsEdit(array $configuration)
{
if (!count($configuration) || empty($configuration['code'])) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `configuration` must contains a data & configuration `code` must be set'
);
}
return $this->client->makeRequest(
sprintf('/delivery/generic/setting/%s/edit', $configuration['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('configuration' => json_encode($configuration))
);
}
/**
* Delivery tracking update
*
* @param string $code
* @param array $statusUpdate
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
*/
public function deliveryTracking($code, array $statusUpdate)
{
if (empty($code)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('Parameter `code` must be set');
2017-02-03 11:05:00 +03:00
}
if (!count($statusUpdate)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `statusUpdate` must contains a data'
);
}
return $this->client->makeRequest(
sprintf('/delivery/generic/%s/tracking', $code),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
$statusUpdate
);
}
/**
* Returns available county list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function countriesList()
{
return $this->client->makeRequest(
'/reference/countries',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
/**
* Returns deliveryServices list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function deliveryServicesList()
{
return $this->client->makeRequest(
'/reference/delivery-services',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
/**
* Edit deliveryService
*
* @param array $data delivery service data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function deliveryServicesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/delivery-services/%s/edit', $data['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('deliveryService' => json_encode($data))
);
}
/**
* Returns deliveryTypes list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function deliveryTypesList()
{
return $this->client->makeRequest(
'/reference/delivery-types',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
/**
* Edit deliveryType
*
* @param array $data delivery type data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return ApiResponse
*/
public function deliveryTypesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/delivery-types/%s/edit', $data['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('deliveryType' => json_encode($data))
);
}
/**
* Returns orderMethods list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function orderMethodsList()
{
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/reference/order-methods',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
2015-06-25 18:01:54 +03:00
/**
2017-02-03 11:05:00 +03:00
* Edit orderMethod
*
* @param array $data order method data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
2015-06-25 18:01:54 +03:00
*
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function orderMethodsEdit(array $data)
2015-06-25 18:01:54 +03:00
{
2017-02-03 11:05:00 +03:00
if (!array_key_exists('code', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "code" parameter.'
);
2015-06-25 18:01:54 +03:00
}
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
sprintf('/reference/order-methods/%s/edit', $data['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('orderMethod' => json_encode($data))
);
2015-06-25 18:01:54 +03:00
}
/**
2017-02-03 11:05:00 +03:00
* Returns orderTypes list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
2015-06-25 18:01:54 +03:00
*
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function orderTypesList()
2015-06-25 18:01:54 +03:00
{
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
'/reference/order-types',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2015-06-25 18:01:54 +03:00
);
}
/**
2017-02-03 11:05:00 +03:00
* Edit orderType
*
* @param array $data order type data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function orderTypesEdit(array $data)
{
2017-02-03 11:05:00 +03:00
if (!array_key_exists('code', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/order-types/%s/edit', $data['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('orderType' => json_encode($data))
);
}
/**
2017-02-03 11:05:00 +03:00
* Returns paymentStatuses list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function paymentStatusesList()
{
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/reference/payment-statuses',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
/**
2017-02-03 11:05:00 +03:00
* Edit paymentStatus
*
* @param array $data payment status data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function paymentStatusesEdit(array $data)
{
2017-02-03 11:05:00 +03:00
if (!array_key_exists('code', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/payment-statuses/%s/edit', $data['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('paymentStatus' => json_encode($data))
);
}
/**
2017-02-03 11:05:00 +03:00
* Returns paymentTypes list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function paymentTypesList()
{
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/reference/payment-types',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
/**
2017-02-03 11:05:00 +03:00
* Edit paymentType
*
* @param array $data payment type data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function paymentTypesEdit(array $data)
{
2017-02-03 11:05:00 +03:00
if (!array_key_exists('code', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/payment-types/%s/edit', $data['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('paymentType' => json_encode($data))
);
}
/**
2017-02-03 11:05:00 +03:00
* Returns productStatuses list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function productStatusesList()
{
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/reference/product-statuses',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
/**
2017-02-03 11:05:00 +03:00
* Edit productStatus
*
* @param array $data product status data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function productStatusesEdit(array $data)
{
2017-02-03 11:05:00 +03:00
if (!array_key_exists('code', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/product-statuses/%s/edit', $data['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('productStatus' => json_encode($data))
);
}
/**
2017-02-03 11:05:00 +03:00
* Returns sites list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function sitesList()
{
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/reference/sites',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
/**
2017-02-03 11:05:00 +03:00
* Edit site
*
* @param array $data site data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function sitesEdit(array $data)
{
2017-02-03 11:05:00 +03:00
if (!array_key_exists('code', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/sites/%s/edit', $data['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('site' => json_encode($data))
);
}
/**
2017-02-03 11:05:00 +03:00
* Returns statusGroups list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function statusGroupsList()
{
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/reference/status-groups',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
2015-06-25 18:01:54 +03:00
/**
2017-02-03 11:05:00 +03:00
* Returns statuses list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
2015-06-25 18:01:54 +03:00
*
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function statusesList()
2015-06-25 18:01:54 +03:00
{
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/reference/statuses',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
2015-06-25 18:01:54 +03:00
}
/**
2017-02-03 11:05:00 +03:00
* Edit order status
*
* @param array $data status data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function statusesEdit(array $data)
{
2017-02-03 11:05:00 +03:00
if (!array_key_exists('code', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
sprintf('/reference/statuses/%s/edit', $data['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('status' => json_encode($data))
);
}
/**
2017-02-03 11:05:00 +03:00
* Returns stores list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function storesList()
{
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
'/reference/stores',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
);
}
/**
2017-02-03 11:05:00 +03:00
* Edit store
*
* @param array $data site data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function storesEdit(array $data)
{
2017-02-03 11:05:00 +03:00
if (!array_key_exists('code', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "code" parameter.'
);
}
if (!array_key_exists('name', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "name" parameter.'
);
}
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
sprintf('/reference/stores/%s/edit', $data['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('store' => json_encode($data))
);
}
/**
2017-02-03 11:05:00 +03:00
* Get prices types
*
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function pricesTypes()
{
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
'/reference/price-types',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
);
}
/**
2017-02-03 11:05:00 +03:00
* Edit price type
*
* @param array $data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function pricesEdit(array $data)
{
2017-02-03 11:05:00 +03:00
if (!array_key_exists('code', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "code" parameter.'
);
}
if (!array_key_exists('name', $data)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Data must contain "name" parameter.'
);
}
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
sprintf('/reference/price-types/%s/edit', $data['code']),
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('priceType' => json_encode($data))
);
}
/**
2017-02-03 11:05:00 +03:00
* Get telephony settings
*
* @param string $code
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function telephonySettingsGet($code)
{
2017-02-03 11:05:00 +03:00
if (empty($code)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('Parameter `code` must be set');
}
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
"/telephony/setting/$code",
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
);
}
/**
2017-02-03 11:05:00 +03:00
* Edit telephony settings
*
* @param string $code symbolic code
* @param string $clientId client id
* @param boolean $active telephony activity
* @param mixed $name service name
* @param mixed $makeCallUrl service init url
* @param mixed $image service logo url(svg file)
*
* @param array $additionalCodes
* @param array $externalPhones
* @param bool $allowEdit
* @param bool $inputEventSupported
* @param bool $outputEventSupported
* @param bool $hangupEventSupported
* @param bool $changeUserStatusUrl
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-05-31 15:24:46 +03:00
public function telephonySettingsEdit(
$code,
$clientId,
$active = false,
$name = false,
$makeCallUrl = false,
$image = false,
$additionalCodes = array(),
$externalPhones = array(),
$allowEdit = false,
$inputEventSupported = false,
$outputEventSupported = false,
$hangupEventSupported = false,
$changeUserStatusUrl = false
)
{
2017-02-03 11:05:00 +03:00
if (!isset($code)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('Code must be set');
2017-02-03 11:05:00 +03:00
}
$parameters['code'] = $code;
if (!isset($clientId)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('client id must be set');
2017-02-03 11:05:00 +03:00
}
$parameters['clientId'] = $clientId;
if (!isset($active)) {
$parameters['active'] = false;
} else {
$parameters['active'] = $active;
}
if (!isset($name)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('name must be set');
2017-02-03 11:05:00 +03:00
}
if (isset($name)) {
$parameters['name'] = $name;
}
if (isset($makeCallUrl)) {
$parameters['makeCallUrl'] = $makeCallUrl;
}
if (isset($image)) {
$parameters['image'] = $image;
}
if (isset($additionalCodes)) {
$parameters['additionalCodes'] = $additionalCodes;
}
if (isset($externalPhones)) {
$parameters['externalPhones'] = $externalPhones;
}
if (isset($allowEdit)) {
$parameters['allowEdit'] = $allowEdit;
}
if (isset($inputEventSupported)) {
$parameters['inputEventSupported'] = $inputEventSupported;
}
if (isset($outputEventSupported)) {
$parameters['outputEventSupported'] = $outputEventSupported;
}
if (isset($hangupEventSupported)) {
$parameters['hangupEventSupported'] = $hangupEventSupported;
}
if (isset($changeUserStatusUrl)) {
$parameters['changeUserStatusUrl'] = $changeUserStatusUrl;
}
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
"/telephony/setting/$code/edit",
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('configuration' => json_encode($parameters))
);
}
/**
2017-02-03 11:05:00 +03:00
* Call event
*
* @param string $phone phone number
* @param string $type call type
* @param array $codes
* @param string $hangupStatus
* @param string $externalPhone
* @param array $webAnalyticsData
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
2017-02-03 11:05:00 +03:00
* @internal param string $code additional phone code
* @internal param string $status call status
*
*/
2017-05-31 15:24:46 +03:00
public function telephonyCallEvent(
$phone,
$type,
$codes,
$hangupStatus,
$externalPhone = null,
$webAnalyticsData = array()
)
{
2017-02-03 11:05:00 +03:00
if (!isset($phone)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('Phone number must be set');
2017-02-03 11:05:00 +03:00
}
if (!isset($type)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('Type must be set (in|out|hangup)');
}
2017-02-03 11:05:00 +03:00
if (empty($codes)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('Codes array must be set');
2017-02-03 11:05:00 +03:00
}
$parameters['phone'] = $phone;
$parameters['type'] = $type;
$parameters['codes'] = $codes;
$parameters['hangupStatus'] = $hangupStatus;
$parameters['callExternalId'] = $externalPhone;
$parameters['webAnalyticsData'] = $webAnalyticsData;
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
'/telephony/call/event',
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('event' => json_encode($parameters))
);
}
/**
2017-02-03 11:05:00 +03:00
* Upload calls
*
* @param array $calls calls data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function telephonyCallsUpload(array $calls)
{
2017-02-03 11:05:00 +03:00
if (!count($calls)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
'Parameter `calls` must contains array of the calls'
);
}
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
'/telephony/calls/upload',
2017-05-31 15:24:46 +03:00
Client::METHOD_POST,
2017-02-03 11:05:00 +03:00
array('calls' => json_encode($calls))
);
}
2015-06-25 18:01:54 +03:00
/**
2017-02-03 11:05:00 +03:00
* Get call manager
*
* @param string $phone phone number
* @param bool $details detailed information
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
2015-06-25 18:01:54 +03:00
*
* @return ApiResponse
*/
2017-02-03 11:05:00 +03:00
public function telephonyCallManager($phone, $details)
2015-06-25 18:01:54 +03:00
{
2017-02-03 11:05:00 +03:00
if (!isset($phone)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException('Phone number must be set');
2015-06-25 18:01:54 +03:00
}
2017-02-03 11:05:00 +03:00
$parameters['phone'] = $phone;
$parameters['details'] = isset($details) ? $details : 0;
2015-06-25 18:01:54 +03:00
return $this->client->makeRequest(
2017-02-03 11:05:00 +03:00
'/telephony/manager',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET,
2017-02-03 11:05:00 +03:00
$parameters
2015-06-25 18:01:54 +03:00
);
}
/**
* Update CRM basic statistic
*
2017-02-03 11:05:00 +03:00
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
2015-06-25 18:01:54 +03:00
* @return ApiResponse
*/
public function statisticUpdate()
{
2017-02-03 11:05:00 +03:00
return $this->client->makeRequest(
'/statistic/update',
2017-05-31 15:24:46 +03:00
Client::METHOD_GET
2017-02-03 11:05:00 +03:00
);
}
/**
* Return current site
*
* @return string
*/
public function getSite()
{
return $this->siteCode;
}
/**
* Set site
*
2017-02-03 11:05:00 +03:00
* @param string $site site code
*
* @return void
*/
public function setSite($site)
{
$this->siteCode = $site;
}
/**
* Check ID parameter
*
2017-02-03 11:05:00 +03:00
* @param string $by identify by
*
* @throws \InvalidArgumentException
*
* @return bool
*/
protected function checkIdParameter($by)
{
2017-02-03 11:05:00 +03:00
$allowedForBy = array(
'externalId',
'id'
);
if (!in_array($by, $allowedForBy, false)) {
2017-05-31 15:24:46 +03:00
throw new \InvalidArgumentException(
2017-02-03 11:05:00 +03:00
sprintf(
'Value "%s" for "by" param is not valid. Allowed values are %s.',
$by,
implode(', ', $allowedForBy)
)
);
}
return true;
}
/**
* Fill params by site value
*
2017-02-03 11:05:00 +03:00
* @param string $site site code
* @param array $params input parameters
*
* @return array
*/
protected function fillSite($site, array $params)
{
if ($site) {
$params['site'] = $site;
} elseif ($this->siteCode) {
$params['site'] = $this->siteCode;
}
return $params;
}
}