2014-11-06 13:48:07 +03:00
|
|
|
<?php
|
|
|
|
|
2016-07-22 01:01:47 +03:00
|
|
|
/**
|
|
|
|
* PHP version 5.3
|
|
|
|
*
|
|
|
|
* API client orders test class
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
* @author RetailCrm <integration@retailcrm.ru>
|
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
2017-06-12 23:58:56 +03:00
|
|
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
2016-07-22 01:01:47 +03:00
|
|
|
*/
|
|
|
|
|
2014-11-06 13:48:07 +03:00
|
|
|
namespace RetailCrm\Tests;
|
|
|
|
|
|
|
|
use RetailCrm\Test\TestCase;
|
|
|
|
|
2016-07-22 01:01:47 +03:00
|
|
|
/**
|
|
|
|
* Class ApiClientOrdersTest
|
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
* @author RetailCrm <integration@retailcrm.ru>
|
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
2017-06-12 23:58:56 +03:00
|
|
|
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
2016-07-22 01:01:47 +03:00
|
|
|
*/
|
2014-11-06 13:48:07 +03:00
|
|
|
class ApiClientOrdersTest extends TestCase
|
|
|
|
{
|
|
|
|
const FIRST_NAME = 'Иннокентий';
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testOrdersCreate()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$externalId = 'o-create-' . time();
|
|
|
|
|
|
|
|
$response = $client->ordersCreate(array(
|
|
|
|
'firstName' => self::FIRST_NAME,
|
|
|
|
'externalId' => $externalId,
|
|
|
|
));
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(201, $response->getStatusCode());
|
|
|
|
static::assertTrue(is_int($response['id']));
|
2014-11-06 13:48:07 +03:00
|
|
|
|
|
|
|
return array(
|
2017-06-12 23:58:56 +03:00
|
|
|
'id' => $response['id'],
|
2014-11-06 13:48:07 +03:00
|
|
|
'externalId' => $externalId,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testOrdersCreateExceptionEmpty()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2017-06-12 23:58:56 +03:00
|
|
|
$client->ordersCreate(array());
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
2014-11-13 09:37:53 +03:00
|
|
|
/**
|
2017-06-12 23:58:56 +03:00
|
|
|
* @group orders
|
2014-11-13 09:37:53 +03:00
|
|
|
* @depends testOrdersCreate
|
2017-06-12 23:58:56 +03:00
|
|
|
*
|
|
|
|
* @param array $ids
|
2014-11-13 09:37:53 +03:00
|
|
|
*/
|
|
|
|
public function testOrdersStatuses(array $ids)
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$response = $client->ordersStatuses();
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(400, $response->getStatusCode());
|
|
|
|
static::assertFalse($response->isSuccessful());
|
2014-11-13 09:37:53 +03:00
|
|
|
|
|
|
|
$response = $client->ordersStatuses(array(), array('asdf'));
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
|
|
|
static::assertTrue($response->isSuccessful());
|
|
|
|
$orders = $response['orders'];
|
|
|
|
static::assertEquals(0, sizeof($orders));
|
2014-11-13 09:37:53 +03:00
|
|
|
|
|
|
|
$response = $client->ordersStatuses(array(), array($ids['externalId']));
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
|
|
|
static::assertTrue($response->isSuccessful());
|
|
|
|
$orders = $response['orders'];
|
|
|
|
static::assertEquals(1, sizeof($orders));
|
|
|
|
static::assertEquals('new', $orders[0]['status']);
|
2014-11-13 09:37:53 +03:00
|
|
|
|
|
|
|
$response = $client->ordersStatuses(array($ids['id']), array($ids['externalId']));
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
|
|
|
static::assertTrue($response->isSuccessful());
|
|
|
|
$orders = $response['orders'];
|
|
|
|
static::assertEquals(1, sizeof($orders));
|
2014-11-13 09:37:53 +03:00
|
|
|
|
|
|
|
$response = $client->ordersStatuses(array($ids['id']));
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
|
|
|
static::assertTrue($response->isSuccessful());
|
|
|
|
$orders = $response['orders'];
|
|
|
|
static::assertEquals(1, sizeof($orders));
|
2014-11-13 09:37:53 +03:00
|
|
|
}
|
|
|
|
|
2014-11-06 13:48:07 +03:00
|
|
|
/**
|
2017-06-12 23:58:56 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
* @depends testOrdersCreate
|
2017-06-12 23:58:56 +03:00
|
|
|
*
|
|
|
|
* @param array $ids
|
|
|
|
*
|
|
|
|
* @return array
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testOrdersGet(array $ids)
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$response = $client->ordersGet(678678678);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(404, $response->getStatusCode());
|
|
|
|
static::assertFalse($response->isSuccessful());
|
2014-11-06 13:48:07 +03:00
|
|
|
|
|
|
|
$response = $client->ordersGet($ids['id'], 'id');
|
2017-06-12 23:58:56 +03:00
|
|
|
$orderById = $response['order'];
|
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
|
|
|
static::assertTrue($response->isSuccessful());
|
|
|
|
static::assertEquals(self::FIRST_NAME, $response['order']['firstName']);
|
2014-11-06 13:48:07 +03:00
|
|
|
|
|
|
|
$response = $client->ordersGet($ids['externalId'], 'externalId');
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertEquals($orderById['id'], $response['order']['id']);
|
2014-11-06 13:48:07 +03:00
|
|
|
|
|
|
|
return $ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testOrdersGetException()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2017-06-12 23:58:56 +03:00
|
|
|
$client->ordersGet(678678678, 'asdf');
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-06-12 23:58:56 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
* @depends testOrdersGet
|
2017-06-12 23:58:56 +03:00
|
|
|
*
|
|
|
|
* @param array $ids
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testOrdersEdit(array $ids)
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$response = $client->ordersEdit(
|
|
|
|
array(
|
|
|
|
'id' => 22342134,
|
|
|
|
'lastName' => '12345',
|
|
|
|
),
|
|
|
|
'id'
|
|
|
|
);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(404, $response->getStatusCode());
|
2014-11-06 13:48:07 +03:00
|
|
|
|
|
|
|
$response = $client->ordersEdit(array(
|
|
|
|
'externalId' => $ids['externalId'],
|
|
|
|
'lastName' => '12345',
|
|
|
|
));
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
|
|
|
static::assertTrue($response->isSuccessful());
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testOrdersEditExceptionEmpty()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2017-06-12 23:58:56 +03:00
|
|
|
$client->ordersEdit(array(), 'asdf');
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testOrdersEditException()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2017-06-12 23:58:56 +03:00
|
|
|
$client->ordersEdit(array('id' => 678678678), 'asdf');
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testOrdersHistory()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$response = $client->ordersHistory();
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertEquals(200, $response->getStatusCode());
|
|
|
|
static::assertTrue($response->isSuccessful());
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testOrdersList()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$response = $client->ordersList();
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertTrue($response->isSuccessful());
|
|
|
|
static::assertTrue(isset($response['orders']));
|
2014-11-06 13:48:07 +03:00
|
|
|
|
|
|
|
$response = $client->ordersList(array(), 1, 300);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
static::assertFalse(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'Pagination error'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $client->ordersList(array('paymentStatus' => 'paid'), 1);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testOrdersFixExternalIdsException()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2017-06-12 23:58:56 +03:00
|
|
|
$client->ordersFixExternalIds(array());
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group orders
|
2017-06-12 01:23:48 +03:00
|
|
|
*/
|
2014-11-06 13:48:07 +03:00
|
|
|
public function testOrdersFixExternalIds()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$response = $client->ordersCreate(array(
|
|
|
|
'firstName' => 'Aaa',
|
|
|
|
));
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertTrue(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'Order created'
|
|
|
|
);
|
|
|
|
|
2017-06-12 23:58:56 +03:00
|
|
|
$id = $response['id'];
|
2014-11-06 13:48:07 +03:00
|
|
|
$externalId = 'asdf' . time();
|
|
|
|
|
|
|
|
$response = $client->ordersFixExternalIds(array(
|
|
|
|
array('id' => $id, 'externalId' => $externalId)
|
|
|
|
));
|
|
|
|
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertTrue(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'Fixed order ids'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $client->ordersGet($externalId);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertTrue(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'Got order'
|
|
|
|
);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertEquals(
|
2014-11-06 13:48:07 +03:00
|
|
|
$id,
|
2017-06-12 23:58:56 +03:00
|
|
|
$response['order']['id'],
|
2014-11-06 13:48:07 +03:00
|
|
|
'Fixing of order ids were right'
|
|
|
|
);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertEquals(
|
2014-11-06 13:48:07 +03:00
|
|
|
$externalId,
|
2017-06-12 23:58:56 +03:00
|
|
|
$response['order']['externalId'],
|
2014-11-06 13:48:07 +03:00
|
|
|
'Fixing of order ids were right'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testOrdersUploadExceptionEmpty()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2017-06-12 23:58:56 +03:00
|
|
|
$client->ordersUpload(array());
|
2014-11-06 13:48:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 01:01:47 +03:00
|
|
|
* @group orders
|
2014-11-06 13:48:07 +03:00
|
|
|
*/
|
|
|
|
public function testOrdersUpload()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$externalIdA = 'upload-a-' . time();
|
|
|
|
$externalIdB = 'upload-b-' . time();
|
|
|
|
|
|
|
|
$response = $client->ordersUpload(array(
|
|
|
|
array(
|
|
|
|
'externalId' => $externalIdA,
|
|
|
|
'firstName' => 'Aaa',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'externalId' => $externalIdB,
|
|
|
|
'lastName' => 'Bbb',
|
|
|
|
),
|
|
|
|
));
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertTrue(
|
2014-11-06 13:48:07 +03:00
|
|
|
$response->isSuccessful(),
|
|
|
|
'Got order'
|
|
|
|
);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertEquals(
|
2014-11-06 13:48:07 +03:00
|
|
|
$externalIdA,
|
2017-06-12 23:58:56 +03:00
|
|
|
$response['uploadedOrders'][0]['externalId']
|
2014-11-06 13:48:07 +03:00
|
|
|
);
|
2017-06-12 23:58:56 +03:00
|
|
|
static::assertEquals(
|
2014-11-06 13:48:07 +03:00
|
|
|
$externalIdB,
|
2017-06-12 23:58:56 +03:00
|
|
|
$response['uploadedOrders'][1]['externalId']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group orders
|
|
|
|
*/
|
|
|
|
public function testOrdersCombine()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$responseCreateFirst = $client->ordersCreate([
|
|
|
|
'firstName' => 'Aaa111',
|
|
|
|
'externalId' => 'AA-' . time(),
|
|
|
|
'phone' => '+79999999990'
|
|
|
|
]);
|
|
|
|
|
|
|
|
static::assertTrue(
|
|
|
|
$responseCreateFirst->isSuccessful(),
|
|
|
|
'Got order'
|
|
|
|
);
|
|
|
|
|
|
|
|
$responseCreateSecond = $client->ordersCreate([
|
|
|
|
'firstName' => 'Aaa222',
|
|
|
|
'externalId' => 'BB-' . time(),
|
|
|
|
'phone' => '+79999999991'
|
|
|
|
]);
|
|
|
|
|
|
|
|
static::assertTrue(
|
|
|
|
$responseCreateSecond->isSuccessful(),
|
|
|
|
'Got order'
|
|
|
|
);
|
|
|
|
|
|
|
|
$order = ['id' => $responseCreateFirst['id']];
|
|
|
|
$resultOrder = ['id' => $responseCreateSecond['id']];
|
|
|
|
|
|
|
|
$response = $client->ordersCombine($order, $resultOrder, 'ours');
|
|
|
|
|
|
|
|
static::assertTrue(
|
|
|
|
$response->isSuccessful(),
|
|
|
|
'Orders combined'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOrdersPayment()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
$externalId = 'AA-' . time();
|
|
|
|
|
|
|
|
$responseCreateFirst = $client->ordersCreate([
|
|
|
|
'firstName' => 'Aaa111aaA',
|
|
|
|
'phone' => '+79999999990'
|
|
|
|
]);
|
|
|
|
|
|
|
|
static::assertTrue(
|
|
|
|
$responseCreateFirst->isSuccessful(),
|
|
|
|
'Got order'
|
|
|
|
);
|
|
|
|
|
|
|
|
$payment = array(
|
|
|
|
'externalId' => $externalId,
|
|
|
|
'order' => array('id' => $responseCreateFirst['id']),
|
|
|
|
'amount' => 1200,
|
|
|
|
'comment' => 'test payment',
|
|
|
|
'type' => 'cash',
|
|
|
|
'status' => 'paid'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $client->ordersPaymentCreate($payment);
|
|
|
|
|
|
|
|
static::assertTrue(
|
|
|
|
$response->isSuccessful(),
|
|
|
|
'Got payment'
|
|
|
|
);
|
|
|
|
|
|
|
|
$paymentEdit = array(
|
2017-06-13 10:54:20 +03:00
|
|
|
'id' => $response['id'],
|
2017-06-12 23:58:56 +03:00
|
|
|
'externalId' => $externalId,
|
|
|
|
'amount' => 1500,
|
|
|
|
'comment' => 'test payment!',
|
|
|
|
'type' => 'cash',
|
|
|
|
'status' => 'paid'
|
|
|
|
);
|
|
|
|
|
|
|
|
$responseAgain = $client->ordersPaymentEdit($paymentEdit);
|
|
|
|
|
|
|
|
static::assertTrue(
|
|
|
|
$responseAgain->isSuccessful(),
|
|
|
|
'Got payment'
|
2014-11-06 13:48:07 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|