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

delivery shipments

This commit is contained in:
Alex Lushpai 2018-01-10 11:35:57 +03:00
parent 6947dfe08c
commit d61ab837e8
10 changed files with 315 additions and 35 deletions

View File

@ -50,7 +50,7 @@ abstract class AbstractLoader
if (empty($version) || !in_array($version, ['v3', 'v4', 'v5'])) {
throw new \InvalidArgumentException(
'Version parameter must be not empty and must be equal one of v3|v4|v5'
'Version must be not empty and must be equal one of v3|v4|v5'
);
}

View File

@ -242,9 +242,14 @@ trait Orders
/**
* Get orders history
* @param array $filter
* @param null $page
* @param null $limit
*
* @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
*/

View File

@ -34,7 +34,25 @@ trait Delivery
/**
* Get delivery settings
*
* @param string $code
* @param string $code delivery code
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return void
*/
public function deliverySettingsGet($code)
{
throw new \InvalidArgumentException('This method is not available');
}
/**
* Get delivery list
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
@ -42,8 +60,121 @@ trait Delivery
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliverySettingsGet($code)
public function deliveryShipmentsList(
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(
'/delivery/shipments',
"GET",
$parameters
);
}
/**
* Create delivery shipment
*
* @param array $shipment (default: array())
* @param string $deliveryType (default: string)
* @param null $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryShipmentsCreate(
array $shipment,
$deliveryType,
$site = null
) {
if (!count($shipment)) {
throw new \InvalidArgumentException(
'Parameter `shipment` must contains a data'
);
}
return $this->client->makeRequest(
'/delivery/shipments/create',
"POST",
$this->fillSite(
$site,
[
'deliveryShipment' => json_encode($shipment),
'deliveryType' => $deliveryType
]
)
);
}
/**
* Get shipment
*
* @param string $id shipment id
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryShipmentGet($id)
{
throw new \InvalidArgumentException('This method is not available');
return $this->client->makeRequest(
sprintf("/delivery/shipments/%s", $id),
"GET"
);
}
/**
* Edit delivery shipment
*
* @param array $shipment (default: array())
* @param null $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryShipmentsEdit(array $shipment, $site = null)
{
if (!count($shipment)) {
throw new \InvalidArgumentException(
'Parameter `shipment` must contains a data'
);
}
if (empty($shipment['id'])) {
throw new \InvalidArgumentException(
'Parameter `shipment` must contains an `id` field'
);
}
return $this->client->makeRequest(
sprintf("/delivery/shipments/%s/edit", $shipment['id']),
"POST",
$this->fillSite(
$site,
[
'deliveryShipment' => json_encode($shipment)
]
)
);
}
}

View File

@ -34,9 +34,9 @@ trait Orders
/**
* Combine orders
*
* @param string $technique
* @param array $order
* @param array $resultOrder
* @param array $order orgin order
* @param array $resultOrder result order
* @param string $technique combining technique
*
* @return \RetailCrm\Response\ApiResponse
*/

View File

@ -20,7 +20,11 @@ use RetailCrm\Http\Client;
/**
* Class TestCase
*
* @package RetailCrm\Test
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class TestCase extends \PHPUnit_Framework_TestCase
{
@ -34,8 +38,12 @@ class TestCase extends \PHPUnit_Framework_TestCase
*
* @return ApiClient
*/
public static function getApiClient($url = null, $apiKey = null, $version = null, $site = null)
{
public static function getApiClient(
$url = null,
$apiKey = null,
$version = null,
$site = null
) {
$configUrl = getenv('CRM_API_URL') ?: $_SERVER['CRM_API_URL'];
$configKey = getenv('CRM_API_KEY') ?: $_SERVER['CRM_API_KEY'];
$configVersion = getenv('CRM_API_VERSION') ?: $_SERVER['CRM_API_VERSION'];

View File

@ -28,7 +28,11 @@ use RetailCrm\Test\TestCase;
class CommonMethodsTest extends TestCase
{
/**
* Available versions
*
* @group api_methods
*
* @return void
*/
public function testAvailableVersions()
{
@ -37,12 +41,16 @@ class CommonMethodsTest extends TestCase
$response = $client->request->availableVersions();
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->getSuccess());
static::assertGreaterThan(0, count($response->getVersions()));
static::assertTrue($response->isSuccessful());
static::assertGreaterThan(0, count($response['versions']));
}
/**
* Available methods
*
* @group api_methods
*
* @return void
*/
public function testCredentials()
{
@ -51,7 +59,7 @@ class CommonMethodsTest extends TestCase
$response = $client->request->credentials();
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->getSuccess());
static::assertGreaterThan(0, count($response->getCredentials()));
static::assertTrue($response->isSuccessful());
static::assertGreaterThan(0, count($response['credentials']));
}
}

View File

@ -0,0 +1,109 @@
<?php
/**
* PHP version 5.4
*
* API client marketplace test class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientMarketplaceTest
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientDeliveryTest extends TestCase
{
/**
* Test delivery list
*
* @group marketplace_v5
*
* @return void
*/
public function testDeliveryShipmentsList()
{
$client = static::getApiClient();
$response = $client->request->deliveryShipmentsList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals($response->getStatusCode(), 200);
static::assertTrue($response->isSuccessful());
}
/**
* Test delivery methods
*
* @group marketplace_v5
*
* @return void
*/
public function testDeliveryShipments()
{
$client = static::getApiClient();
$deliveryType = 'courier';
$order = [
'number' => uniqid(),
'firstName' => 'Test',
'lastName' => 'Customer',
'email' => 'test@example.com',
'delivery' => ['code' => $deliveryType]
];
$responseOrder = $client->request->ordersCreate($order);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseOrder);
static::assertEquals($responseOrder->getStatusCode(), 201);
static::assertTrue($responseOrder->isSuccessful());
$orderid = $responseOrder['id'];
$shipment = [
'date' => date('Y-m-d'),
'orders' => [
[
'id' => $orderid
]
],
'comment' => 'test shipment'
];
$responseCreate = $client
->request
->deliveryShipmentsCreate($shipment, $deliveryType);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseCreate);
static::assertTrue($responseCreate->isSuccessful());
$responseGet = $client->request->deliveryShipmentGet($responseCreate['id']);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseGet);
static::assertTrue($responseGet->isSuccessful());
$updateShipment = array_merge($shipment, ['status' => 'cancelled']);
$responseUpdate = $client
->request
->deliveryShipmentsUpdate($updateShipment);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseUpdate);
static::assertTrue($responseUpdate->isSuccessful());
}
}

View File

@ -19,7 +19,11 @@ use RetailCrm\Test\TestCase;
/**
* Class ApiClientMarketplaceTest
*
* @package RetailCrm\Tests
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientMarketplaceTest extends TestCase
{
@ -27,12 +31,21 @@ class ApiClientMarketplaceTest extends TestCase
const SERVICE_CODE = 'integration_v5';
/**
* Test configuration
*
* @group marketplace_v5
*
* @return void
*/
public function testConfigurationEdit()
{
$client = static::getApiClient();
/**
* Response
*
* @var \RetailCrm\Response\ApiResponse $response
*/
$response = $client->request->integrationModulesEdit(
[
'name' => self::SERVICE_NAME,

View File

@ -1,4 +1,10 @@
<?php
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
if (function_exists('date_default_timezone_set')
&& function_exists('date_default_timezone_get')
) {
date_default_timezone_set(@date_default_timezone_get());
}
$loader = include dirname(__DIR__) . '/vendor/autoload.php';
$loader->add('RetailCrm\\Test', __DIR__);