diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index 67048a8..591c493 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -167,6 +167,27 @@ class ApiClient return $this->client->makeRequest('/orders', Client::METHOD_GET, $parameters); } + /** + * Returns statuses of the orders + * + * @param array $ids (default: array()) + * @param array $externalIds (default: array()) + * @return ApiResponse + */ + public function ordersStatuses(array $ids = array(), array $externalIds = array()) + { + $parameters = array(); + + if (sizeof($ids)) { + $parameters['ids'] = $ids; + } + if (sizeof($externalIds)) { + $parameters['externalIds'] = $externalIds; + } + + return $this->client->makeRequest('/orders/statuses', Client::METHOD_GET, $parameters); + } + /** * Save order IDs' (id and externalId) association in the CRM * diff --git a/tests/RetailCrm/Tests/ApiClientOrdersTest.php b/tests/RetailCrm/Tests/ApiClientOrdersTest.php index 315663a..8d1254d 100644 --- a/tests/RetailCrm/Tests/ApiClientOrdersTest.php +++ b/tests/RetailCrm/Tests/ApiClientOrdersTest.php @@ -42,6 +42,49 @@ class ApiClientOrdersTest extends TestCase $response = $client->ordersCreate(array()); } + /** + * @group integration + * @depends testOrdersCreate + */ + public function testOrdersStatuses(array $ids) + { + $client = static::getApiClient(); + + $response = $client->ordersStatuses(); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(400, $response->getStatusCode()); + $this->assertFalse($response->success); + + $response = $client->ordersStatuses(array(), array('asdf')); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + $orders = $response->orders; + $this->assertEquals(0, sizeof($orders)); + + $response = $client->ordersStatuses(array(), array($ids['externalId'])); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + $orders = $response->orders; + $this->assertEquals(1, sizeof($orders)); + $this->assertEquals('new', $orders[0]['status']); + + $response = $client->ordersStatuses(array($ids['id']), array($ids['externalId'])); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + $orders = $response->orders; + $this->assertEquals(1, sizeof($orders)); + + $response = $client->ordersStatuses(array($ids['id'])); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertTrue($response->success); + $orders = $response->orders; + $this->assertEquals(1, sizeof($orders)); + } + /** * @group integration * @depends testOrdersCreate