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

Merge pull request #56 from gwinn/master

delivery shipments
This commit is contained in:
Alex Lushpai 2018-01-10 11:39:54 +03:00 committed by GitHub
commit 5e890c9324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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'])) { if (empty($version) || !in_array($version, ['v3', 'v4', 'v5'])) {
throw new \InvalidArgumentException( 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

@ -63,7 +63,7 @@ class Client
* @param string $path request url * @param string $path request url
* @param string $method (default: 'GET') * @param string $method (default: 'GET')
* @param array $parameters (default: array()) * @param array $parameters (default: array())
* @param bool $fullPath (default: false) * @param bool $fullPath (default: false)
* *
* @SuppressWarnings(PHPMD.ExcessiveParameterList) * @SuppressWarnings(PHPMD.ExcessiveParameterList)
* *

View File

@ -242,9 +242,14 @@ trait Orders
/** /**
* Get orders history * Get orders history
* @param array $filter *
* @param null $page * @param array $filter (default: array())
* @param null $limit * @param int $page (default: null)
* @param int $limit (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
* *
* @return \RetailCrm\Response\ApiResponse * @return \RetailCrm\Response\ApiResponse
*/ */

View File

@ -34,7 +34,25 @@ trait Delivery
/** /**
* Get delivery settings * 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 \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException * @throws \RetailCrm\Exception\CurlException
@ -42,8 +60,121 @@ trait Delivery
* *
* @return \RetailCrm\Response\ApiResponse * @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 * Combine orders
* *
* @param string $technique * @param array $order orgin order
* @param array $order * @param array $resultOrder result order
* @param array $resultOrder * @param string $technique combining technique
* *
* @return \RetailCrm\Response\ApiResponse * @return \RetailCrm\Response\ApiResponse
*/ */
@ -71,7 +71,7 @@ trait Orders
* Create an order payment * Create an order payment
* *
* @param array $payment order data * @param array $payment order data
* @param null $site site code * @param null $site site code
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException * @throws \RetailCrm\Exception\CurlException
@ -98,14 +98,14 @@ trait Orders
} }
/** /**
* Edit an order payment * Edit an order payment
* *
* @param array $payment order data * @param array $payment order data
* @param string $by by key * @param string $by by key
* @param null $site site code * @param null $site site code
* *
* @return \RetailCrm\Response\ApiResponse * @return \RetailCrm\Response\ApiResponse
*/ */
public function ordersPaymentEdit(array $payment, $by = 'id', $site = null) public function ordersPaymentEdit(array $payment, $by = 'id', $site = null)
{ {
if (!count($payment)) { if (!count($payment)) {

View File

@ -20,22 +20,30 @@ use RetailCrm\Http\Client;
/** /**
* Class TestCase * 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 class TestCase extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Return ApiClient object * Return ApiClient object
* *
* @param string $url (default: null) * @param string $url (default: null)
* @param string $apiKey (default: null) * @param string $apiKey (default: null)
* @param string $version (default: null) * @param string $version (default: null)
* @param string $site (default: null) * @param string $site (default: null)
* *
* @return ApiClient * @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']; $configUrl = getenv('CRM_API_URL') ?: $_SERVER['CRM_API_URL'];
$configKey = getenv('CRM_API_KEY') ?: $_SERVER['CRM_API_KEY']; $configKey = getenv('CRM_API_KEY') ?: $_SERVER['CRM_API_KEY'];
$configVersion = getenv('CRM_API_VERSION') ?: $_SERVER['CRM_API_VERSION']; $configVersion = getenv('CRM_API_VERSION') ?: $_SERVER['CRM_API_VERSION'];
@ -51,8 +59,8 @@ class TestCase extends \PHPUnit_Framework_TestCase
/** /**
* Return Client object * Return Client object
* *
* @param string $url (default: null) * @param string $url (default: null)
* @param array $defaultParameters (default: array()) * @param array $defaultParameters (default: array())
* *
* @return Client * @return Client
*/ */

View File

@ -28,7 +28,11 @@ use RetailCrm\Test\TestCase;
class CommonMethodsTest extends TestCase class CommonMethodsTest extends TestCase
{ {
/** /**
* Available versions
*
* @group api_methods * @group api_methods
*
* @return void
*/ */
public function testAvailableVersions() public function testAvailableVersions()
{ {
@ -37,12 +41,16 @@ class CommonMethodsTest extends TestCase
$response = $client->request->availableVersions(); $response = $client->request->availableVersions();
static::assertEquals(200, $response->getStatusCode()); static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->getSuccess()); static::assertTrue($response->isSuccessful());
static::assertGreaterThan(0, count($response->getVersions())); static::assertGreaterThan(0, count($response['versions']));
} }
/** /**
* Available methods
*
* @group api_methods * @group api_methods
*
* @return void
*/ */
public function testCredentials() public function testCredentials()
{ {
@ -51,7 +59,7 @@ class CommonMethodsTest extends TestCase
$response = $client->request->credentials(); $response = $client->request->credentials();
static::assertEquals(200, $response->getStatusCode()); static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->getSuccess()); static::assertTrue($response->isSuccessful());
static::assertGreaterThan(0, count($response->getCredentials())); 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 * 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 class ApiClientMarketplaceTest extends TestCase
{ {
@ -27,12 +31,21 @@ class ApiClientMarketplaceTest extends TestCase
const SERVICE_CODE = 'integration_v5'; const SERVICE_CODE = 'integration_v5';
/** /**
* Test configuration
*
* @group marketplace_v5 * @group marketplace_v5
*
* @return void
*/ */
public function testConfigurationEdit() public function testConfigurationEdit()
{ {
$client = static::getApiClient(); $client = static::getApiClient();
/**
* Response
*
* @var \RetailCrm\Response\ApiResponse $response
*/
$response = $client->request->integrationModulesEdit( $response = $client->request->integrationModulesEdit(
[ [
'name' => self::SERVICE_NAME, 'name' => self::SERVICE_NAME,

View File

@ -1,4 +1,10 @@
<?php <?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__); $loader->add('RetailCrm\\Test', __DIR__);