1
0
mirror of synced 2024-11-21 21:06:07 +03:00

Added ordersHistory. Fix test

This commit is contained in:
Ilyas Salikhov 2014-11-06 03:18:39 +03:00
parent 5a9c0bdb7b
commit 8b59f079ef
4 changed files with 76 additions and 3 deletions

View File

@ -22,7 +22,7 @@ composer require retailcrm/api-client-php 3.0
Usage Usage
----- -----
Example of the usage: Example of the receipt of order:
```php ```php
$client = new \RetailCrm\ApiClient( $client = new \RetailCrm\ApiClient(
@ -43,4 +43,35 @@ if ($response->isSuccessful()) {
// $order = $response->getOrder(); // $order = $response->getOrder();
// $order['totalSumm']; // $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();
}
``` ```

View File

@ -79,6 +79,35 @@ class ApiClient
return $this->client->makeRequest("/orders/$id", Client::METHOD_GET, array('by' => $by)); 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 * Check ID parameter
* *

View File

@ -113,7 +113,6 @@ class ApiClientTest extends TestCase
$this->assertTrue($response->success); $this->assertTrue($response->success);
} }
/** /**
* @group unit * @group unit
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
@ -124,4 +123,18 @@ class ApiClientTest extends TestCase
$response = $client->ordersEdit(array('id' => 678678678), 'asdf'); $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']));
}
} }

View File

@ -53,7 +53,7 @@ class ClientTest extends TestCase
public function testMakeRequestSuccess() public function testMakeRequestSuccess()
{ {
$client = new Client('https://demo.intarocrm.ru/api/' . ApiClient::VERSION, array()); $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->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
$this->assertEquals(403, $response->getStatusCode()); $this->assertEquals(403, $response->getStatusCode());