Added ordersHistory. Fix test
This commit is contained in:
parent
5a9c0bdb7b
commit
8b59f079ef
33
README.md
33
README.md
@ -22,7 +22,7 @@ composer require retailcrm/api-client-php 3.0
|
||||
Usage
|
||||
-----
|
||||
|
||||
Example of the usage:
|
||||
Example of the receipt of order:
|
||||
```php
|
||||
|
||||
$client = new \RetailCrm\ApiClient(
|
||||
@ -43,4 +43,35 @@ if ($response->isSuccessful()) {
|
||||
// $order = $response->getOrder();
|
||||
// $order['totalSumm'];
|
||||
}
|
||||
```
|
||||
|
||||
Example of the order creating:
|
||||
```php
|
||||
|
||||
$client = new \RetailCrm\ApiClient(
|
||||
'https://demo.intarocrm.ru',
|
||||
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH'
|
||||
);
|
||||
|
||||
try {
|
||||
$response = $client->ordersCreate(array(
|
||||
'externalId' => 'some-shop-order-id',
|
||||
'firstName' => 'Vasily',
|
||||
'lastName' => 'Pupkin',
|
||||
'items' => array(
|
||||
//...
|
||||
),
|
||||
delivery => array(
|
||||
'code' => 'russian-post',
|
||||
)
|
||||
));
|
||||
} catch (\RetailCrm\Exception\CurlException $e) {
|
||||
echo "CRM connection error: " . $e->getMessage();
|
||||
}
|
||||
|
||||
if ($response->isSuccessful() && 201 === $response->getStatusCode()) {
|
||||
echo 'Order created successfully! Order ID in CRM - ' . $response->id;
|
||||
// or $response['id'];
|
||||
// or $response->getId();
|
||||
}
|
||||
```
|
@ -79,6 +79,35 @@ class ApiClient
|
||||
return $this->client->makeRequest("/orders/$id", Client::METHOD_GET, array('by' => $by));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a orders history
|
||||
*
|
||||
* @param \DateTime $startDate (default: null)
|
||||
* @param \DateTime $endDate (default: null)
|
||||
* @param int $limit (default: 100)
|
||||
* @param int $offset (default: 0)
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function ordersHistory(\DateTime $startDate = null, \DateTime $endDate = null, $limit = 100, $offset = 0)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
return $this->client->makeRequest('/orders/history', Client::METHOD_GET, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check ID parameter
|
||||
*
|
||||
|
@ -113,7 +113,6 @@ class ApiClientTest extends TestCase
|
||||
$this->assertTrue($response->success);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @expectedException \InvalidArgumentException
|
||||
@ -124,4 +123,18 @@ class ApiClientTest extends TestCase
|
||||
|
||||
$response = $client->ordersEdit(array('id' => 678678678), 'asdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
public function testOrdersHistory()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersHistory();
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->success);
|
||||
$this->assertTrue(isset($response['orders']));
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class ClientTest extends TestCase
|
||||
public function testMakeRequestSuccess()
|
||||
{
|
||||
$client = new Client('https://demo.intarocrm.ru/api/' . ApiClient::VERSION, array());
|
||||
$response = $client->makeRequest('/a', Client::METHOD_GET);
|
||||
$response = $client->makeRequest('/orders', Client::METHOD_GET);
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(403, $response->getStatusCode());
|
||||
|
Loading…
Reference in New Issue
Block a user