1
0
Fork 0
mirror of synced 2025-04-11 13:10:57 +00:00

add customers notes methods

This commit is contained in:
Alex Lushpai 2017-06-22 00:36:47 +03:00
parent 699c9d569a
commit 9c8725b666
2 changed files with 195 additions and 0 deletions

View file

@ -57,4 +57,89 @@ trait Customers
]
);
}
/**
* 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())
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersNotesCreate($note)
{
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",
['note' => json_encode($note)]
);
}
/**
* Create 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"
);
}
}

View file

@ -334,4 +334,114 @@ class ApiClientCustomersTest extends TestCase
'Customers combined'
);
}
/**
* @group customers_v5
*/
public function testCustomersNotesCreate()
{
$client = static::getApiClient();
$responseCreateFirst = $client->request->customersCreate([
'firstName' => 'Some',
'lastName' => 'Test',
'externalId' => 'AA-' . time(),
'phones' => [
[
'number' => '+79999999990'
]
]
]);
static::assertTrue(
$responseCreateFirst->isSuccessful(),
'Got customer'
);
$note = [
'managerId' => 6,
'text' => 'test note',
'createdAt' => date('Y-m-d H:i:s'),
'customer' => [
'id' => $responseCreateFirst['id']
]
];
$response = $client->request->customersNotesCreate($note);
static::assertTrue($response->isSuccessful(), 'Note created');
static::assertEquals(201, $response->getStatusCode());
}
/**
* @group customers_v5
*/
public function testCustomersNotesList()
{
$client = static::getApiClient();
$responseCreateFirst = $client->request->customersCreate([
'firstName' => 'Some',
'lastName' => 'Test',
'externalId' => 'AA-' . time(),
'phones' => [
[
'number' => '+79999999990'
]
]
]);
static::assertTrue(
$responseCreateFirst->isSuccessful(),
'Got customer'
);
$response = $client->request->customersNotesList(['customerIds' => [$responseCreateFirst['id']]]);
static::assertTrue($response->isSuccessful(), 'Got notes list');
static::assertEquals(200, $response->getStatusCode());
}
/**
* @group customers_v5
*/
public function testCustomersNotesDelete()
{
$client = static::getApiClient();
$responseCreateFirst = $client->request->customersCreate([
'firstName' => 'Some',
'lastName' => 'Test',
'externalId' => 'AA-' . time(),
'phones' => [
[
'number' => '+79999999990'
]
]
]);
static::assertTrue(
$responseCreateFirst->isSuccessful(),
'Got customer'
);
$note = [
'managerId' => 6,
'text' => 'test note',
'createdAt' => date('Y-m-d H:i:s'),
'customer' => [
'id' => $responseCreateFirst['id']
]
];
$response = $client->request->customersNotesCreate($note);
static::assertTrue($response->isSuccessful(), 'Note created');
static::assertEquals(201, $response->getStatusCode());
$responseDelete = $client->request->customersNotesDelete($response['id']);
static::assertTrue($responseDelete->isSuccessful(), 'Note deleted');
static::assertEquals(200, $responseDelete->getStatusCode());
}
}