147 lines
3.7 KiB
PHP
147 lines
3.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* PHP version 5.4
|
|
*
|
|
* Customers
|
|
*
|
|
* @category RetailCrm
|
|
* @package RetailCrm
|
|
* @author RetailCrm <integration@retailcrm.ru>
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
|
*/
|
|
|
|
namespace RetailCrm\Methods\V5;
|
|
|
|
use RetailCrm\Methods\V4\Customers as Previous;
|
|
|
|
/**
|
|
* PHP version 5.4
|
|
*
|
|
* Customers 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/ApiVersion5
|
|
*/
|
|
trait Customers
|
|
{
|
|
use Previous;
|
|
|
|
/**
|
|
* Combine customers
|
|
*
|
|
* @param array $customers
|
|
* @param array $resultCustomer
|
|
*
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
*/
|
|
public function customersCombine(array $customers, $resultCustomer)
|
|
{
|
|
|
|
if (!count($customers) || !count($resultCustomer)) {
|
|
throw new \InvalidArgumentException(
|
|
'Parameters `customers` & `resultCustomer` must contains a data'
|
|
);
|
|
}
|
|
|
|
return $this->client->makeRequest(
|
|
'/customers/combine',
|
|
"POST",
|
|
[
|
|
'customers' => json_encode($customers),
|
|
'resultCustomer' => json_encode($resultCustomer)
|
|
]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns filtered customers notes 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 \RetailCrm\Response\ApiResponse
|
|
*/
|
|
public function customersNotesList(array $filter = [], $page = null, $limit = null)
|
|
{
|
|
$parameters = [];
|
|
|
|
if (count($filter)) {
|
|
$parameters['filter'] = $filter;
|
|
}
|
|
if (null !== $page) {
|
|
$parameters['page'] = (int) $page;
|
|
}
|
|
if (null !== $limit) {
|
|
$parameters['limit'] = (int) $limit;
|
|
}
|
|
|
|
return $this->client->makeRequest(
|
|
'/customers/notes',
|
|
"GET",
|
|
$parameters
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create customer note
|
|
*
|
|
* @param array $note (default: array())
|
|
* @param string $site (default: null)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
*
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
*/
|
|
public function customersNotesCreate($note, $site = null)
|
|
{
|
|
if (empty($note['customer']['id']) && empty($note['customer']['externalId'])) {
|
|
throw new \InvalidArgumentException(
|
|
'Customer identifier must be set'
|
|
);
|
|
}
|
|
|
|
return $this->client->makeRequest(
|
|
'/customers/notes/create',
|
|
"POST",
|
|
$this->fillSite($site, ['note' => json_encode($note)])
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Delete customer note
|
|
*
|
|
* @param integer $id
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
*
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
*/
|
|
public function customersNotesDelete($id)
|
|
{
|
|
if (empty($id)) {
|
|
throw new \InvalidArgumentException(
|
|
'Note id must be set'
|
|
);
|
|
}
|
|
|
|
return $this->client->makeRequest(
|
|
"/customers/notes/$id/delete",
|
|
"POST"
|
|
);
|
|
}
|
|
}
|