2017-06-22 00:55:08 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 5.4
|
|
|
|
*
|
2017-06-22 16:42:42 +03:00
|
|
|
* Customers
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace RetailCrm\Methods\V5;
|
|
|
|
|
|
|
|
use RetailCrm\Methods\V4\Customers as Previous;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 5.4
|
|
|
|
*
|
2017-06-22 16:42:42 +03:00
|
|
|
* Customers class
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
*/
|
|
|
|
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'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/customers/notes/create',
|
|
|
|
"POST",
|
2017-06-22 16:42:42 +03:00
|
|
|
$this->fillSite($site, ['note' => json_encode($note)])
|
2017-06-22 00:55:08 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-06-22 16:42:42 +03:00
|
|
|
* Delete customer note
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
|
|
|
* @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'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
"/customers/notes/$id/delete",
|
|
|
|
"POST"
|
|
|
|
);
|
|
|
|
}
|
2024-09-25 15:29:03 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update subscriptions a customer
|
|
|
|
*
|
|
|
|
* @param array $subscriptions subscriptions data
|
|
|
|
* @param integer $customerId identifier customer
|
|
|
|
* @param string $by (default: 'externalId')
|
|
|
|
* @param string|null $site (default: null)
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
|
|
|
public function customerSubscriptionsUpdate(array $subscriptions, $customerId, $by = 'externalId', $site = null)
|
|
|
|
{
|
|
|
|
if (!count($subscriptions)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Parameter `subscriptions` must contains a data'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_int($customerId)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Parameter `customerId` must be an integer'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->checkIdParameter($by);
|
|
|
|
|
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
|
|
|
return $this->client->makeRequest(
|
2024-09-25 16:33:21 +03:00
|
|
|
sprintf('/customers/%s/subscriptions', $customerId),
|
2024-09-25 15:29:03 +03:00
|
|
|
'POST',
|
|
|
|
$this->fillSite(
|
|
|
|
$site,
|
|
|
|
['subscriptions' => json_encode($subscriptions), 'by' => $by]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2017-06-22 00:55:08 +03:00
|
|
|
}
|