1
0
mirror of synced 2024-11-25 14:56:07 +03:00

sync with master

This commit is contained in:
Alex Lushpai 2017-06-22 00:57:44 +03:00
commit f181c9d063
67 changed files with 7117 additions and 2449 deletions

View File

@ -5,15 +5,14 @@ cache:
- $HOME/.composer/cache - $HOME/.composer/cache
php: php:
- '5.3'
- '5.4' - '5.4'
- '5.5' - '5.5'
- '5.6' - '5.6'
- '7.0' - '7.0'
before_script: before_script:
- flags="--prefer-dist --no-dev -o" - flags="-o"
- composer install $flags - composer install $flags
- wget -c -O phpunit.xml https://goo.gl/yZHStN - cp phpunit.xml.dist phpunit.xml
script: phpunit script: phpunit

View File

@ -6,7 +6,7 @@ Use [API documentation](http://retailcrm.github.io/api-client-php)
## Requirements ## Requirements
* PHP 5.3 and above * PHP 5.4 and above
* PHP's cURL support * PHP's cURL support
## Install ## Install
@ -29,12 +29,12 @@ require 'path/to/vendor/autoload.php';
```php ```php
$client = new \RetailCrm\ApiClient( $client = new \RetailCrm\ApiClient(
'https://demo.retailcrm.ru', 'https://demo.retailcrm.ru',
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH' 'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
'v5'
); );
try { try {
$response = $client->ordersGet('M-2342'); $response = $client->request->ordersGet('M-2342');
} catch (\RetailCrm\Exception\CurlException $e) { } catch (\RetailCrm\Exception\CurlException $e) {
echo "Connection error: " . $e->getMessage(); echo "Connection error: " . $e->getMessage();
} }
@ -63,12 +63,13 @@ if ($response->isSuccessful()) {
```php ```php
$client = new \RetailCrm\ApiClient( $client = new \RetailCrm\ApiClient(
'https://demo.retailcrm.pro', 'https://demo.retailcrm.ru',
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH' 'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
'v4'
); );
try { try {
$response = $client->ordersCreate(array( $response = $client->request->ordersCreate(array(
'externalId' => 'some-shop-order-id', 'externalId' => 'some-shop-order-id',
'firstName' => 'Vasily', 'firstName' => 'Vasily',
'lastName' => 'Pupkin', 'lastName' => 'Pupkin',

View File

@ -6,7 +6,7 @@ PHP-клиент для работы с [retailCRM API](http://www.retailcrm.ru/
## Обязательные требования ## Обязательные требования
* PHP версии 5.3 и выше * PHP версии 5.4 и выше
* PHP-расширение cURL * PHP-расширение cURL
## Установка ## Установка
@ -31,12 +31,12 @@ require 'path/to/vendor/autoload.php';
```php ```php
$client = new \RetailCrm\ApiClient( $client = new \RetailCrm\ApiClient(
'https://demo.retailcrm.ru', 'https://demo.retailcrm.ru',
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH' 'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
'v5'
); );
try { try {
$response = $client->ordersGet('M-2342'); $response = $client-request->ordersGet('M-2342');
} catch (\RetailCrm\Exception\CurlException $e) { } catch (\RetailCrm\Exception\CurlException $e) {
echo "Сетевые проблемы. Ошибка подключения к retailCRM: " . $e->getMessage(); echo "Сетевые проблемы. Ошибка подключения к retailCRM: " . $e->getMessage();
} }
@ -66,11 +66,12 @@ if ($response->isSuccessful()) {
$client = new \RetailCrm\ApiClient( $client = new \RetailCrm\ApiClient(
'https://demo.retailcrm.ru', 'https://demo.retailcrm.ru',
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH' 'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
'v4'
); );
try { try {
$response = $client->ordersCreate(array( $response = $client-request->ordersCreate(array(
'externalId' => 'some-shop-order-id', 'externalId' => 'some-shop-order-id',
'firstName' => 'Vasily', 'firstName' => 'Vasily',
'lastName' => 'Pupkin', 'lastName' => 'Pupkin',

View File

@ -8,15 +8,15 @@
"authors": [ "authors": [
{ {
"name": "retailCRM", "name": "retailCRM",
"email": "support@retailcrm.pro" "email": "support@retailcrm.ru"
} }
], ],
"require": { "require": {
"php": ">=5.3.0", "php": ">=5.4.0",
"ext-curl": "*" "ext-curl": "*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "5.*", "phpunit/phpunit": "3.7.*",
"squizlabs/php_codesniffer": "3.*" "squizlabs/php_codesniffer": "3.*"
}, },
"support": { "support": {

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,132 @@
<?php
/**
* PHP version 5.4
*
* API client 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\Client;
use RetailCrm\Http\Client;
/**
* PHP version 5.4
*
* API client 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
*/
abstract class AbstractLoader
{
protected $siteCode;
protected $client;
/**
* Init version based client
*
* @param string $url api url
* @param string $apiKey api key
* @param string $version api version
* @param string $site site code
*/
public function __construct($url, $apiKey, $version, $site = null)
{
if ('/' !== $url[strlen($url) - 1]) {
$url .= '/';
}
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'
);
}
$url = $url . 'api/' . $version;
$this->client = new Client($url, ['apiKey' => $apiKey]);
$this->siteCode = $site;
}
/**
* Set site
*
* @param string $site site code
*
* @return void
*/
public function setSite($site)
{
$this->siteCode = $site;
}
/**
* Check ID parameter
*
* @param string $by identify by
*
* @throws \InvalidArgumentException
*
* @return bool
*/
protected function checkIdParameter($by)
{
$allowedForBy = [
'externalId',
'id'
];
if (!in_array($by, $allowedForBy, false)) {
throw new \InvalidArgumentException(
sprintf(
'Value "%s" for "by" param is not valid. Allowed values are %s.',
$by,
implode(', ', $allowedForBy)
)
);
}
return true;
}
/**
* Fill params by site value
*
* @param string $site site code
* @param array $params input parameters
*
* @return array
*/
protected function fillSite($site, array $params)
{
if ($site) {
$params['site'] = $site;
} elseif ($this->siteCode) {
$params['site'] = $this->siteCode;
}
return $params;
}
/**
* Return current site
*
* @return string
*/
public function getSite()
{
return $this->siteCode;
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* PHP version 5.4
*
* API client 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\Client;
use RetailCrm\Methods\V3;
/**
* PHP version 5.4
*
* API client 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
*/
class ApiVersion3 extends AbstractLoader
{
/**
* Init version based client
*
* @param string $url api url
* @param string $apiKey api key
* @param string $version api version
* @param string $site site code
*
*/
public function __construct($url, $apiKey, $version, $site)
{
parent::__construct($url, $apiKey, $version, $site);
}
use V3\Customers;
use V3\Orders;
use V3\Packs;
use V3\References;
use V3\Statistic;
use V3\Stores;
use V3\Telephony;
}

View File

@ -0,0 +1,56 @@
<?php
/**
* PHP version 5.4
*
* API client 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\Client;
use RetailCrm\Methods\V4;
/**
* PHP version 5.4
*
* API client 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
*/
class ApiVersion4 extends AbstractLoader
{
/**
* Init version based client
*
* @param string $url api url
* @param string $apiKey api key
* @param string $version api version
* @param string $site site code
*
*/
public function __construct($url, $apiKey, $version, $site)
{
parent::__construct($url, $apiKey, $version, $site);
}
use V4\Customers;
use V4\Delivery;
use V4\Marketplace;
use V4\Orders;
use V4\Packs;
use V4\References;
use V4\Statistic;
use V4\Stores;
use V4\Telephony;
use V4\Users;
}

View File

@ -0,0 +1,59 @@
<?php
/**
* PHP version 5.4
*
* API client 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\Client;
use RetailCrm\Methods\V5;
/**
* PHP version 5.4
*
* API client 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
*/
class ApiVersion5 extends AbstractLoader
{
/**
* Init version based client
*
* @param string $url api url
* @param string $apiKey api key
* @param string $version api version
* @param string $site site code
*
*/
public function __construct($url, $apiKey, $version, $site)
{
parent::__construct($url, $apiKey, $version, $site);
}
use V5\Customers;
use V5\CustomFields;
use V5\Delivery;
use V5\Marketplace;
use V5\Orders;
use V5\Packs;
use V5\References;
use V5\Segments;
use V5\Statistic;
use V5\Stores;
use V5\Tasks;
use V5\Telephony;
use V5\Users;
}

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* Class CurlException * Class CurlException
* *
@ -15,7 +15,7 @@
namespace RetailCrm\Exception; namespace RetailCrm\Exception;
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* Class CurlException * Class CurlException
* *

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* Class InvalidJsonException * Class InvalidJsonException
* *
@ -15,7 +15,7 @@
namespace RetailCrm\Exception; namespace RetailCrm\Exception;
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* Class InvalidJsonException * Class InvalidJsonException
* *

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* HTTP client * HTTP client
* *
@ -19,7 +19,7 @@ use RetailCrm\Exception\InvalidJsonException;
use RetailCrm\Response\ApiResponse; use RetailCrm\Response\ApiResponse;
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* HTTP client * HTTP client
* *
@ -45,7 +45,7 @@ class Client
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function __construct($url, array $defaultParameters = array()) public function __construct($url, array $defaultParameters = [])
{ {
if (false === stripos($url, 'https://')) { if (false === stripos($url, 'https://')) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
@ -75,9 +75,9 @@ class Client
public function makeRequest( public function makeRequest(
$path, $path,
$method, $method,
array $parameters = array() array $parameters = []
) { ) {
$allowedMethods = array(self::METHOD_GET, self::METHOD_POST); $allowedMethods = [self::METHOD_GET, self::METHOD_POST];
if (!in_array($method, $allowedMethods, false)) { if (!in_array($method, $allowedMethods, false)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(

View File

@ -0,0 +1,206 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V3;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Customers
{
/**
* Returns filtered customers list
*
* @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
*/
public function customersList(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(
'/customers',
"GET",
$parameters
);
}
/**
* Create a customer
*
* @param array $customer customer data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCreate(array $customer, $site = null)
{
if (! count($customer)) {
throw new \InvalidArgumentException(
'Parameter `customer` must contains a data'
);
}
return $this->client->makeRequest(
'/customers/create',
"POST",
$this->fillSite($site, ['customer' => json_encode($customer)])
);
}
/**
* Save customer IDs' (id and externalId) association in the CRM
*
* @param array $ids ids mapping
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersFixExternalIds(array $ids)
{
if (! count($ids)) {
throw new \InvalidArgumentException(
'Method parameter must contains at least one IDs pair'
);
}
return $this->client->makeRequest(
'/customers/fix-external-ids',
"POST",
['customers' => json_encode($ids)]
);
}
/**
* Upload array of the customers
*
* @param array $customers array of customers
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersUpload(array $customers, $site = null)
{
if (! count($customers)) {
throw new \InvalidArgumentException(
'Parameter `customers` must contains array of the customers'
);
}
return $this->client->makeRequest(
'/customers/upload',
"POST",
$this->fillSite($site, ['customers' => json_encode($customers)])
);
}
/**
* Get customer by id or externalId
*
* @param string $id customer identificator
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersGet($id, $by = 'externalId', $site = null)
{
$this->checkIdParameter($by);
return $this->client->makeRequest(
"/customers/$id",
"GET",
$this->fillSite($site, ['by' => $by])
);
}
/**
* Edit a customer
*
* @param array $customer customer data
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersEdit(array $customer, $by = 'externalId', $site = null)
{
if (!count($customer)) {
throw new \InvalidArgumentException(
'Parameter `customer` must contains a data'
);
}
$this->checkIdParameter($by);
if (!array_key_exists($by, $customer)) {
throw new \InvalidArgumentException(
sprintf('Customer array must contain the "%s" parameter.', $by)
);
}
return $this->client->makeRequest(
sprintf('/customers/%s/edit', $customer[$by]),
"POST",
$this->fillSite(
$site,
['customer' => json_encode($customer), 'by' => $by]
)
);
}
}

View File

@ -0,0 +1,267 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V3;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Orders
{
/**
* Returns filtered orders list
*
* @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
*/
public function ordersList(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(
'/orders',
"GET",
$parameters
);
}
/**
* Create an order
*
* @param array $order order data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersCreate(array $order, $site = null)
{
if (!count($order)) {
throw new \InvalidArgumentException(
'Parameter `order` must contains a data'
);
}
return $this->client->makeRequest(
'/orders/create',
"POST",
$this->fillSite($site, ['order' => json_encode($order)])
);
}
/**
* Save order IDs' (id and externalId) association into CRM
*
* @param array $ids order identificators
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersFixExternalIds(array $ids)
{
if (! count($ids)) {
throw new \InvalidArgumentException(
'Method parameter must contains at least one IDs pair'
);
}
return $this->client->makeRequest(
'/orders/fix-external-ids',
"POST",
['orders' => json_encode($ids)
]
);
}
/**
* Returns statuses of the orders
*
* @param array $ids (default: array())
* @param array $externalIds (default: array())
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersStatuses(array $ids = [], array $externalIds = [])
{
$parameters = [];
if (count($ids)) {
$parameters['ids'] = $ids;
}
if (count($externalIds)) {
$parameters['externalIds'] = $externalIds;
}
return $this->client->makeRequest(
'/orders/statuses',
"GET",
$parameters
);
}
/**
* Upload array of the orders
*
* @param array $orders array of orders
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersUpload(array $orders, $site = null)
{
if (!count($orders)) {
throw new \InvalidArgumentException(
'Parameter `orders` must contains array of the orders'
);
}
return $this->client->makeRequest(
'/orders/upload',
"POST",
$this->fillSite($site, ['orders' => json_encode($orders)])
);
}
/**
* Get order by id or externalId
*
* @param string $id order identificator
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersGet($id, $by = 'externalId', $site = null)
{
$this->checkIdParameter($by);
return $this->client->makeRequest(
"/orders/$id",
"GET",
$this->fillSite($site, ['by' => $by])
);
}
/**
* Edit an order
*
* @param array $order order data
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersEdit(array $order, $by = 'externalId', $site = null)
{
if (!count($order)) {
throw new \InvalidArgumentException(
'Parameter `order` must contains a data'
);
}
$this->checkIdParameter($by);
if (!array_key_exists($by, $order)) {
throw new \InvalidArgumentException(
sprintf('Order array must contain the "%s" parameter.', $by)
);
}
return $this->client->makeRequest(
sprintf('/orders/%s/edit', $order[$by]),
"POST",
$this->fillSite(
$site,
['order' => json_encode($order), 'by' => $by]
)
);
}
/**
* Get orders history
* @param array $filter
* @param null $page
* @param null $limit
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersHistory(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(
'/orders/history',
"GET",
$parameters
);
}
}

View File

@ -0,0 +1,197 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V3;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Packs
{
/**
* Get orders assembly list
*
* @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
*/
public function ordersPacksList(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(
'/orders/packs',
"GET",
$parameters
);
}
/**
* Create orders assembly
*
* @param array $pack pack data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPacksCreate(array $pack, $site = null)
{
if (!count($pack)) {
throw new \InvalidArgumentException(
'Parameter `pack` must contains a data'
);
}
return $this->client->makeRequest(
'/orders/packs/create',
"POST",
$this->fillSite($site, ['pack' => json_encode($pack)])
);
}
/**
* Get orders assembly history
*
* @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
*/
public function ordersPacksHistory(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(
'/orders/packs/history',
"GET",
$parameters
);
}
/**
* Get orders assembly by id
*
* @param string $id pack identificator
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPacksGet($id)
{
if (empty($id)) {
throw new \InvalidArgumentException('Parameter `id` must be set');
}
return $this->client->makeRequest(
"/orders/packs/$id",
"GET"
);
}
/**
* Delete orders assembly by id
*
* @param string $id pack identificator
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPacksDelete($id)
{
if (empty($id)) {
throw new \InvalidArgumentException('Parameter `id` must be set');
}
return $this->client->makeRequest(
sprintf('/orders/packs/%s/delete', $id),
"POST"
);
}
/**
* Edit orders assembly
*
* @param array $pack pack data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPacksEdit(array $pack, $site = null)
{
if (!count($pack) || empty($pack['id'])) {
throw new \InvalidArgumentException(
'Parameter `pack` must contains a data & pack `id` must be set'
);
}
return $this->client->makeRequest(
sprintf('/orders/packs/%s/edit', $pack['id']),
"POST",
$this->fillSite($site, ['pack' => json_encode($pack)])
);
}
}

View File

@ -0,0 +1,499 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V3;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait References
{
/**
* Returns available county list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function countriesList()
{
return $this->client->makeRequest(
'/reference/countries',
"GET"
);
}
/**
* Returns deliveryServices list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryServicesList()
{
return $this->client->makeRequest(
'/reference/delivery-services',
"GET"
);
}
/**
* Edit deliveryService
*
* @param array $data delivery service data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryServicesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/delivery-services/%s/edit', $data['code']),
"POST",
['deliveryService' => json_encode($data)]
);
}
/**
* Returns deliveryTypes list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryTypesList()
{
return $this->client->makeRequest(
'/reference/delivery-types',
"GET"
);
}
/**
* Edit deliveryType
*
* @param array $data delivery type data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryTypesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/delivery-types/%s/edit', $data['code']),
"POST",
['deliveryType' => json_encode($data)]
);
}
/**
* Returns orderMethods list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function orderMethodsList()
{
return $this->client->makeRequest(
'/reference/order-methods',
"GET"
);
}
/**
* Edit orderMethod
*
* @param array $data order method data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function orderMethodsEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/order-methods/%s/edit', $data['code']),
"POST",
['orderMethod' => json_encode($data)]
);
}
/**
* Returns orderTypes list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function orderTypesList()
{
return $this->client->makeRequest(
'/reference/order-types',
"GET"
);
}
/**
* Edit orderType
*
* @param array $data order type data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function orderTypesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/order-types/%s/edit', $data['code']),
"POST",
['orderType' => json_encode($data)]
);
}
/**
* Returns paymentStatuses list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function paymentStatusesList()
{
return $this->client->makeRequest(
'/reference/payment-statuses',
"GET"
);
}
/**
* Edit paymentStatus
*
* @param array $data payment status data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function paymentStatusesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/payment-statuses/%s/edit', $data['code']),
"POST",
['paymentStatus' => json_encode($data)]
);
}
/**
* Returns paymentTypes list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function paymentTypesList()
{
return $this->client->makeRequest(
'/reference/payment-types',
"GET"
);
}
/**
* Edit paymentType
*
* @param array $data payment type data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function paymentTypesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/payment-types/%s/edit', $data['code']),
"POST",
['paymentType' => json_encode($data)]
);
}
/**
* Returns productStatuses list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function productStatusesList()
{
return $this->client->makeRequest(
'/reference/product-statuses',
"GET"
);
}
/**
* Edit productStatus
*
* @param array $data product status data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function productStatusesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/product-statuses/%s/edit', $data['code']),
"POST",
['productStatus' => json_encode($data)]
);
}
/**
* Returns sites list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function sitesList()
{
return $this->client->makeRequest(
'/reference/sites',
"GET"
);
}
/**
* Edit site
*
* @param array $data site data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function sitesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/sites/%s/edit', $data['code']),
"POST",
['site' => json_encode($data)]
);
}
/**
* Returns statusGroups list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function statusGroupsList()
{
return $this->client->makeRequest(
'/reference/status-groups',
"GET"
);
}
/**
* Returns statuses list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function statusesList()
{
return $this->client->makeRequest(
'/reference/statuses',
"GET"
);
}
/**
* Edit order status
*
* @param array $data status data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function statusesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/statuses/%s/edit', $data['code']),
"POST",
['status' => json_encode($data)]
);
}
/**
* Returns stores list
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function storesList()
{
return $this->client->makeRequest(
'/reference/stores',
"GET"
);
}
/**
* Edit store
*
* @param array $data site data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function storesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
if (!array_key_exists('name', $data)) {
throw new \InvalidArgumentException(
'Data must contain "name" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/stores/%s/edit', $data['code']),
"POST",
['store' => json_encode($data)]
);
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* PHP version 5.4
*
* Statistic 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\Methods\V3;
/**
* PHP version 5.4
*
* Statistic 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
*/
trait Statistic
{
/**
* Update CRM basic statistic
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function statisticUpdate()
{
return $this->client->makeRequest(
'/statistic/update',
"GET"
);
}
}

View File

@ -0,0 +1,90 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V3;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Stores
{
/**
* Get purchace prices & stock balance
*
* @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
*/
public function storeInventories(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(
'/store/inventories',
"GET",
$parameters
);
}
/**
* Upload store inventories
*
* @param array $offers offers data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function storeInventoriesUpload(array $offers, $site = null)
{
if (!count($offers)) {
throw new \InvalidArgumentException(
'Parameter `offers` must contains array of the offers'
);
}
return $this->client->makeRequest(
'/store/inventories/upload',
"POST",
$this->fillSite($site, ['offers' => json_encode($offers)])
);
}
}

View File

@ -0,0 +1,156 @@
<?php
/**
* PHP version 5.4
*
* Telephony
*
* @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\Methods\V3;
/**
* PHP version 5.4
*
* Telephony 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
*/
trait Telephony
{
/**
* Get telephony settings
*
* @param string $code
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function telephonySettingsGet($code)
{
if (empty($code)) {
throw new \InvalidArgumentException('Parameter `code` must be set');
}
return $this->client->makeRequest(
"/telephony/setting/$code",
"GET"
);
}
/**
* Call event
*
* @param string $phone phone number
* @param string $type call type
* @param array $codes
* @param string $hangupStatus
* @param string $externalPhone
* @param array $webAnalyticsData
*
* @return \RetailCrm\Response\ApiResponse
* @internal param string $code additional phone code
* @internal param string $status call status
*
*/
public function telephonyCallEvent(
$phone,
$type,
$codes,
$hangupStatus,
$externalPhone = null,
$webAnalyticsData = []
) {
if (!isset($phone)) {
throw new \InvalidArgumentException('Phone number must be set');
}
if (!isset($type)) {
throw new \InvalidArgumentException('Type must be set (in|out|hangup)');
}
if (empty($codes)) {
throw new \InvalidArgumentException('Codes array must be set');
}
$parameters['phone'] = $phone;
$parameters['type'] = $type;
$parameters['codes'] = $codes;
$parameters['hangupStatus'] = $hangupStatus;
$parameters['callExternalId'] = $externalPhone;
$parameters['webAnalyticsData'] = $webAnalyticsData;
return $this->client->makeRequest(
'/telephony/call/event',
"POST",
['event' => json_encode($parameters)]
);
}
/**
* Upload calls
*
* @param array $calls calls data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function telephonyCallsUpload(array $calls)
{
if (!count($calls)) {
throw new \InvalidArgumentException(
'Parameter `calls` must contains array of the calls'
);
}
return $this->client->makeRequest(
'/telephony/calls/upload',
"POST",
['calls' => json_encode($calls)]
);
}
/**
* Get call manager
*
* @param string $phone phone number
* @param bool $details detailed information
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function telephonyCallManager($phone, $details)
{
if (!isset($phone)) {
throw new \InvalidArgumentException('Phone number must be set');
}
$parameters['phone'] = $phone;
$parameters['details'] = isset($details) ? $details : 0;
return $this->client->makeRequest(
'/telephony/manager',
"GET",
$parameters
);
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V4;
use RetailCrm\Methods\V3\Customers as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Customers
{
use Previous;
/**
* Get customers history
* @param array $filter
* @param null $page
* @param null $limit
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersHistory(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(
'/customers/history',
"GET",
$parameters
);
}
}

View File

@ -0,0 +1,109 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V4;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Delivery
{
/**
* Get delivery settings
*
* @param string $code
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliverySettingsGet($code)
{
if (empty($code)) {
throw new \InvalidArgumentException('Parameter `code` must be set');
}
return $this->client->makeRequest(
"/delivery/generic/setting/$code",
"GET"
);
}
/**
* Edit delivery configuration
*
* @param array $configuration
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliverySettingsEdit(array $configuration)
{
if (!count($configuration) || empty($configuration['code'])) {
throw new \InvalidArgumentException(
'Parameter `configuration` must contains a data & configuration `code` must be set'
);
}
return $this->client->makeRequest(
sprintf('/delivery/generic/setting/%s/edit', $configuration['code']),
"POST",
['configuration' => json_encode($configuration)]
);
}
/**
* Delivery tracking update
*
* @param string $code
* @param array $statusUpdate
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryTracking($code, array $statusUpdate)
{
if (empty($code)) {
throw new \InvalidArgumentException('Parameter `code` must be set');
}
if (!count($statusUpdate)) {
throw new \InvalidArgumentException(
'Parameter `statusUpdate` must contains a data'
);
}
return $this->client->makeRequest(
sprintf('/delivery/generic/%s/tracking', $code),
"POST",
['statusUpdate' => json_encode($statusUpdate)]
);
}
}

View File

@ -0,0 +1,56 @@
<?php
/**
* PHP version 5.4
*
* Marketplace
*
* @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\Methods\V4;
/**
* PHP version 5.4
*
* Marketplace 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
*/
trait Marketplace
{
/**
* Edit marketplace configuration
*
* @param array $configuration
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function marketplaceSettingsEdit(array $configuration)
{
if (!count($configuration) || empty($configuration['code'])) {
throw new \InvalidArgumentException(
'Parameter `configuration` must contains a data & configuration `code` must be set'
);
}
return $this->client->makeRequest(
sprintf('/marketplace/external/setting/%s/edit', $configuration['code']),
"POST",
['configuration' => json_encode($configuration)]
);
}
}

View File

@ -0,0 +1,271 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V4;
use RetailCrm\Methods\V3\Orders as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Orders
{
use Previous;
/**
* Returns filtered orders list
*
* @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
*/
public function ordersList(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(
'/orders',
"GET",
$parameters
);
}
/**
* Create an order
*
* @param array $order order data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersCreate(array $order, $site = null)
{
if (!count($order)) {
throw new \InvalidArgumentException(
'Parameter `order` must contains a data'
);
}
return $this->client->makeRequest(
'/orders/create',
"POST",
$this->fillSite($site, ['order' => json_encode($order)])
);
}
/**
* Save order IDs' (id and externalId) association into CRM
*
* @param array $ids order identificators
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersFixExternalIds(array $ids)
{
if (! count($ids)) {
throw new \InvalidArgumentException(
'Method parameter must contains at least one IDs pair'
);
}
return $this->client->makeRequest(
'/orders/fix-external-ids',
"POST",
['orders' => json_encode($ids)
]
);
}
/**
* Returns statuses of the orders
*
* @param array $ids (default: array())
* @param array $externalIds (default: array())
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersStatuses(array $ids = [], array $externalIds = [])
{
$parameters = [];
if (count($ids)) {
$parameters['ids'] = $ids;
}
if (count($externalIds)) {
$parameters['externalIds'] = $externalIds;
}
return $this->client->makeRequest(
'/orders/statuses',
"GET",
$parameters
);
}
/**
* Upload array of the orders
*
* @param array $orders array of orders
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersUpload(array $orders, $site = null)
{
if (!count($orders)) {
throw new \InvalidArgumentException(
'Parameter `orders` must contains array of the orders'
);
}
return $this->client->makeRequest(
'/orders/upload',
"POST",
$this->fillSite($site, ['orders' => json_encode($orders)])
);
}
/**
* Get order by id or externalId
*
* @param string $id order identificator
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersGet($id, $by = 'externalId', $site = null)
{
$this->checkIdParameter($by);
return $this->client->makeRequest(
"/orders/$id",
"GET",
$this->fillSite($site, ['by' => $by])
);
}
/**
* Edit an order
*
* @param array $order order data
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersEdit(array $order, $by = 'externalId', $site = null)
{
if (!count($order)) {
throw new \InvalidArgumentException(
'Parameter `order` must contains a data'
);
}
$this->checkIdParameter($by);
if (!array_key_exists($by, $order)) {
throw new \InvalidArgumentException(
sprintf('Order array must contain the "%s" parameter.', $by)
);
}
return $this->client->makeRequest(
sprintf('/orders/%s/edit', $order[$by]),
"POST",
$this->fillSite(
$site,
['order' => json_encode($order), 'by' => $by]
)
);
}
/**
* Get orders history
* @param array $filter
* @param null $page
* @param null $limit
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersHistory(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(
'/orders/history',
"GET",
$parameters
);
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V4;
use RetailCrm\Methods\V3\Packs as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Packs
{
use Previous;
}

View File

@ -0,0 +1,81 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V4;
use RetailCrm\Methods\V3\References as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait References
{
use Previous;
/**
* Get prices types
*
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function pricesTypes()
{
return $this->client->makeRequest(
'/reference/price-types',
"GET"
);
}
/**
* Edit price type
*
* @param array $data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function pricesTypesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
if (!array_key_exists('name', $data)) {
throw new \InvalidArgumentException(
'Data must contain "name" parameter.'
);
}
return $this->client->makeRequest(
sprintf('/reference/price-types/%s/edit', $data['code']),
"POST",
['priceType' => json_encode($data)]
);
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V4;
use RetailCrm\Methods\V3\Statistic as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Statistic
{
use Previous;
}

View File

@ -0,0 +1,144 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V4;
use RetailCrm\Methods\V3\Stores as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Stores
{
use Previous;
/**
* Get store settings
*
* @param string $code get settings code
*
* @return \RetailCrm\Response\ApiResponse
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function storeSettingsGet($code)
{
if (empty($code)) {
throw new \InvalidArgumentException('Parameter `code` must be set');
}
return $this->client->makeRequest(
"/store/setting/$code",
"GET"
);
}
/**
* Edit store configuration
*
* @param array $configuration
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function storeSettingsEdit(array $configuration)
{
if (!count($configuration) || empty($configuration['code'])) {
throw new \InvalidArgumentException(
'Parameter `configuration` must contains a data & configuration `code` must be set'
);
}
return $this->client->makeRequest(
sprintf('/store/setting/%s/edit', $configuration['code']),
"POST",
['configuration' => json_encode($configuration)]
);
}
/**
* Upload store prices
*
* @param array $prices prices data
* @param string $site default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function storePricesUpload(array $prices, $site = null)
{
if (!count($prices)) {
throw new \InvalidArgumentException(
'Parameter `prices` must contains array of the prices'
);
}
return $this->client->makeRequest(
'/store/prices/upload',
"POST",
$this->fillSite($site, ['prices' => json_encode($prices)])
);
}
/**
* Get products
*
* @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
*/
public function storeProducts(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(
'/store/products',
"GET",
$parameters
);
}
}

View File

@ -0,0 +1,137 @@
<?php
/**
* PHP version 5.4
*
* Telephony
*
* @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\Methods\V4;
use RetailCrm\Methods\V3\Telephony as Previous;
/**
* PHP version 5.4
*
* Telephony 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
*/
trait Telephony
{
use Previous;
/**
* Edit telephony settings
*
* @param string $code symbolic code
* @param string $clientId client id
* @param boolean $active telephony activity
* @param mixed $name service name
* @param mixed $makeCallUrl service init url
* @param mixed $image service logo url(svg file)
*
* @param array $additionalCodes
* @param array $externalPhones
* @param bool $allowEdit
* @param bool $inputEventSupported
* @param bool $outputEventSupported
* @param bool $hangupEventSupported
* @param bool $changeUserStatusUrl
*
* @return \RetailCrm\Response\ApiResponse
*/
public function telephonySettingsEdit(
$code,
$clientId,
$active = false,
$name = false,
$makeCallUrl = false,
$image = false,
$additionalCodes = [],
$externalPhones = [],
$allowEdit = false,
$inputEventSupported = false,
$outputEventSupported = false,
$hangupEventSupported = false,
$changeUserStatusUrl = false
) {
if (!isset($code)) {
throw new \InvalidArgumentException('Code must be set');
}
$parameters['code'] = $code;
if (!isset($clientId)) {
throw new \InvalidArgumentException('client id must be set');
}
$parameters['clientId'] = $clientId;
if (!isset($active)) {
$parameters['active'] = false;
} else {
$parameters['active'] = $active;
}
if (!isset($name)) {
throw new \InvalidArgumentException('name must be set');
}
if (isset($name)) {
$parameters['name'] = $name;
}
if (isset($makeCallUrl)) {
$parameters['makeCallUrl'] = $makeCallUrl;
}
if (isset($image)) {
$parameters['image'] = $image;
}
if (isset($additionalCodes)) {
$parameters['additionalCodes'] = $additionalCodes;
}
if (isset($externalPhones)) {
$parameters['externalPhones'] = $externalPhones;
}
if (isset($allowEdit)) {
$parameters['allowEdit'] = $allowEdit;
}
if (isset($inputEventSupported)) {
$parameters['inputEventSupported'] = $inputEventSupported;
}
if (isset($outputEventSupported)) {
$parameters['outputEventSupported'] = $outputEventSupported;
}
if (isset($hangupEventSupported)) {
$parameters['hangupEventSupported'] = $hangupEventSupported;
}
if (isset($changeUserStatusUrl)) {
$parameters['changeUserStatusUrl'] = $changeUserStatusUrl;
}
return $this->client->makeRequest(
"/telephony/setting/$code/edit",
"POST",
['configuration' => json_encode($parameters)]
);
}
}

View File

@ -0,0 +1,111 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V4;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Users
{
/**
* Returns users list
*
* @param array $filter
* @param null $page
* @param null $limit
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function usersList(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;
}
/** @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/users',
"GET",
$parameters
);
}
/**
* Get user groups
*
* @param null $page
* @param null $limit
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function usersGroups($page = null, $limit = null)
{
$parameters = [];
if (null !== $page) {
$parameters['page'] = (int)$page;
}
if (null !== $limit) {
$parameters['limit'] = (int)$limit;
}
/** @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/user-groups',
"GET",
$parameters
);
}
/**
* Returns user data
*
* @param integer $id user ID
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function usersGet($id)
{
/** @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest("/users/$id", "GET");
}
}

View File

@ -0,0 +1,250 @@
<?php
/**
* PHP version 5.4
*
* CustomFields
*
* @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\Methods\V5;
/**
* PHP version 5.4
*
* CustomFields 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
*/
trait CustomFields
{
/**
* Get custom fields list
*
* @param array $filter
* @param null $limit
* @param null $page
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customFieldsList(array $filter = [], $limit = null, $page = 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(
'/custom-fields',
"GET",
$parameters
);
}
/**
* Create custom field
*
* @param $entity
* @param $customField
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customFieldsCreate($entity, $customField)
{
if (!count($customField) ||
empty($customField['code']) ||
empty($customField['name']) ||
empty($customField['type'])
) {
throw new \InvalidArgumentException(
'Parameter `customField` must contain a data & fields `code`, `name` & `type` must be set'
);
}
if (empty($entity) || $entity != 'customer' || $entity != 'order') {
throw new \InvalidArgumentException(
'Parameter `entity` must contain a data & value must be `order` or `customer`'
);
}
return $this->client->makeRequest(
"/custom-fields/$entity/create",
"POST",
['customField' => json_encode($customField)]
);
}
/**
* Edit custom field
*
* @param $entity
* @param $customField
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customFieldsEdit($entity, $customField)
{
if (!count($customField) || empty($customField['code'])) {
throw new \InvalidArgumentException(
'Parameter `customField` must contain a data & fields `code` must be set'
);
}
if (empty($entity) || $entity != 'customer' || $entity != 'order') {
throw new \InvalidArgumentException(
'Parameter `entity` must contain a data & value must be `order` or `customer`'
);
}
return $this->client->makeRequest(
"/custom-fields/$entity/edit/{$customField['code']}",
"POST",
['customField' => json_encode($customField)]
);
}
/**
* Get custom field
*
* @param $entity
* @param $code
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customFieldsGet($entity, $code)
{
if (empty($code)) {
throw new \InvalidArgumentException(
'Parameter `code` must be not empty'
);
}
if (empty($entity) || $entity != 'customer' || $entity != 'order') {
throw new \InvalidArgumentException(
'Parameter `entity` must contain a data & value must be `order` or `customer`'
);
}
return $this->client->makeRequest(
"/custom-fields/$entity/$code",
"GET"
);
}
/**
* Get custom dictionaries list
*
* @param array $filter
* @param null $limit
* @param null $page
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customDictionariesList(array $filter = [], $limit = null, $page = 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(
'/custom-fields/dictionaries',
"GET",
$parameters
);
}
/**
* Create custom dictionary
*
* @param $customDictionary
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customDictionariesCreate($customDictionary)
{
if (!count($customDictionary) ||
empty($customDictionary['code']) ||
empty($customDictionary['elements'])
) {
throw new \InvalidArgumentException(
'Parameter `dictionary` must contain a data & fields `code` & `elemets` must be set'
);
}
return $this->client->makeRequest(
"/custom-fields/dictionaries/{$customDictionary['code']}/create",
"POST",
['customDictionary' => json_encode($customDictionary)]
);
}
/**
* Edit custom dictionary
*
* @param $customDictionary
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customDictionariesEdit($customDictionary)
{
if (!count($customDictionary) ||
empty($customDictionary['code']) ||
empty($customDictionary['elements'])
) {
throw new \InvalidArgumentException(
'Parameter `dictionary` must contain a data & fields `code` & `elemets` must be set'
);
}
return $this->client->makeRequest(
"/custom-fields/dictionaries/{$customDictionary['code']}/edit",
"POST",
['customDictionary' => json_encode($customDictionary)]
);
}
/**
* Get custom dictionary
*
* @param $code
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customDictionariesGet($code)
{
if (empty($code)) {
throw new \InvalidArgumentException(
'Parameter `code` must be not empty'
);
}
return $this->client->makeRequest(
"/custom-fields/dictionaries/$code",
"GET"
);
}
}

View File

@ -0,0 +1,146 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V5;
use RetailCrm\Methods\V4\Customers as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Customers
{
use Previous;
/**
* Combine customers
*
* @param array $customers
* @param array $resultCustomer
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCombine(array $customers, $resultCustomer)
{
if (!count($customers) || !count($resultCustomer)) {
throw new \InvalidArgumentException(
'Parameters `customers` & `resultCustomer` must contains a data'
);
}
return $this->client->makeRequest(
'/customers/combine',
"POST",
[
'customers' => json_encode($customers),
'resultCustomer' => json_encode($resultCustomer)
]
);
}
/**
* Returns filtered customers notes list
*
* @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
*/
public function customersNotesList(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(
'/customers/notes',
"GET",
$parameters
);
}
/**
* Create customer note
*
* @param array $note (default: array())
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersNotesCreate($note, $site = null)
{
if (empty($note['customer']['id']) && empty($note['customer']['externalId'])) {
throw new \InvalidArgumentException(
'Customer identifier must be set'
);
}
return $this->client->makeRequest(
'/customers/notes/create',
"POST",
['note' => json_encode($note)]
);
}
/**
* Create customer note
*
* @param integer $id
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersNotesDelete($id)
{
if (empty($id)) {
throw new \InvalidArgumentException(
'Note id must be set'
);
}
return $this->client->makeRequest(
"/customers/notes/$id/delete",
"POST"
);
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V5;
use RetailCrm\Methods\V4\Delivery as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Delivery
{
use Previous;
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHP version 5.4
*
* Marketplace
*
* @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\Methods\V5;
use RetailCrm\Methods\V4\Marketplace as Previous;
/**
* PHP version 5.4
*
* Marketplace 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
*/
trait Marketplace
{
use Previous;
}

View File

@ -0,0 +1,131 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V5;
use RetailCrm\Response\ApiResponse;
use RetailCrm\Methods\V4\Orders as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Orders
{
use Previous;
/**
* Combine orders
*
* @param string $technique
* @param array $order
* @param array $resultOrder
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersCombine($order, $resultOrder, $technique = 'ours')
{
$techniques = ['ours', 'summ', 'theirs'];
if (!count($order) || !count($resultOrder)) {
throw new \InvalidArgumentException(
'Parameters `order` & `resultOrder` must contains a data'
);
}
if (!in_array($technique, $techniques)) {
throw new \InvalidArgumentException(
'Parameter `technique` must be on of ours|summ|theirs'
);
}
return $this->client->makeRequest(
'/orders/combine',
"POST",
[
'technique' => $technique,
'order' => json_encode($order),
'resultOrder' => json_encode($resultOrder)
]
);
}
/**
* Create an order payment
*
* @param array $payment order data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPaymentCreate(array $payment)
{
if (!count($payment)) {
throw new \InvalidArgumentException(
'Parameter `payment` must contains a data'
);
}
return $this->client->makeRequest(
'/orders/payments/create',
"POST",
['payment' => json_encode($payment)]
);
}
/**
* Edit an order payment
*
* @param array $payment order data
* @param string $by by key
* @param null $site site code
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPaymentEdit(array $payment, $by = 'id', $site = null)
{
if (!count($payment)) {
throw new \InvalidArgumentException(
'Parameter `payment` must contains a data'
);
}
$this->checkIdParameter($by);
if (!array_key_exists($by, $payment)) {
throw new \InvalidArgumentException(
sprintf('Order array must contain the "%s" parameter.', $by)
);
}
return $this->client->makeRequest(
sprintf('/orders/payments/%s/edit', $payment[$by]),
"POST",
$this->fillSite(
$site,
['payment' => json_encode($payment), 'by' => $by]
)
);
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V5;
use RetailCrm\Methods\V4\Packs as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Packs
{
use Previous;
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V5;
use RetailCrm\Methods\V4\References as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait References
{
use Previous;
}

View File

@ -0,0 +1,59 @@
<?php
/**
* PHP version 5.4
*
* Segments
*
* @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\Methods\V5;
/**
* PHP version 5.4
*
* Segments 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
*/
trait Segments
{
/**
* Get segments list
*
* @param array $filter
* @param null $limit
* @param null $page
*
* @return \RetailCrm\Response\ApiResponse
*/
public function segmentsList(array $filter = [], $limit = null, $page = 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(
'/segments',
"GET",
$parameters
);
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V5;
use RetailCrm\Methods\V3\Statistic as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Statistic
{
use Previous;
}

View File

@ -0,0 +1,67 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V5;
use RetailCrm\Methods\V4\Stores as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Stores
{
use Previous;
/**
* Get products groups
*
* @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
*/
public function storeProductsGroups(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(
'/store/product-groups',
"GET",
$parameters
);
}
}

View File

@ -0,0 +1,134 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V5;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Tasks
{
/**
* Get tasks list
*
* @param array $filter
* @param null $limit
* @param null $page
*
* @return \RetailCrm\Response\ApiResponse
*/
public function tasksList(array $filter = [], $limit = null, $page = 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(
'/tasks',
"GET",
$parameters
);
}
/**
* Create task
*
* @param array $task
* @param null $site
*
* @return \RetailCrm\Response\ApiResponse
*
*/
public function tasksCreate($task, $site = null)
{
if (!count($task)) {
throw new \InvalidArgumentException(
'Parameter `task` must contain a data'
);
}
return $this->client->makeRequest(
"/tasks/create",
"POST",
$this->fillSite(
$site,
['task' => json_encode($task)]
)
);
}
/**
* Edit task
*
* @param array $task
* @param null $site
*
* @return \RetailCrm\Response\ApiResponse
*
*/
public function tasksEdit($task, $site = null)
{
if (!count($task)) {
throw new \InvalidArgumentException(
'Parameter `task` must contain a data'
);
}
return $this->client->makeRequest(
"/tasks/{$task['id']}/edit",
"POST",
$this->fillSite(
$site,
['task' => json_encode($task)]
)
);
}
/**
* Get custom dictionary
*
* @param $id
*
* @return \RetailCrm\Response\ApiResponse
*/
public function tasksGet($id)
{
if (empty($id)) {
throw new \InvalidArgumentException(
'Parameter `id` must be not empty'
);
}
return $this->client->makeRequest(
"/tasks/$id",
"GET"
);
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHP version 5.4
*
* Telephony
*
* @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\Methods\V5;
use RetailCrm\Methods\V4\Telephony as Previous;
/**
* PHP version 5.4
*
* Telephony 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
*/
trait Telephony
{
use Previous;
}

View File

@ -0,0 +1,60 @@
<?php
/**
* PHP version 5.4
*
* TaskTrait
*
* @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\Methods\V5;
use RetailCrm\Response\ApiResponse;
use RetailCrm\Methods\V4\Users as Previous;
/**
* PHP version 5.4
*
* TaskTrait 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
*/
trait Users
{
use Previous;
/**
* Change user status
*
* @param integer $id user ID
* @param string $status user status
*
* @return \RetailCrm\Response\ApiResponse
*/
public function usersStatus($id, $status)
{
$statuses = ["free", "busy", "dinner", "break"];
if (empty($status) || !in_array($status, $statuses)) {
throw new \InvalidArgumentException(
'Parameter `status` must be not empty & must be equal one of these values: free|busy|dinner|break'
);
}
/** @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/users/$id/status",
"POST",
['status' => $status]
);
}
}

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* Response from retailCRM API * Response from retailCRM API
* *
@ -17,10 +17,11 @@ namespace RetailCrm\Response;
use RetailCrm\Exception\InvalidJsonException; use RetailCrm\Exception\InvalidJsonException;
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* Response from retailCRM API * Response from retailCRM API
* *
* @property mixed success
* @category RetailCrm * @category RetailCrm
* @package RetailCrm * @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru> * @author RetailCrm <integration@retailcrm.ru>

View File

@ -10,8 +10,9 @@
<!-- Dummy values used to provide credentials. No need to change these. --> <!-- Dummy values used to provide credentials. No need to change these. -->
<php> <php>
<server name="CRM_URL" value="https://demo.retailcrm.ru" /> <server name="CRM_API_URL" value="https://demo.retailcrm.ru" />
<server name="CRM_API_KEY" value="nSBFWecViONG5c96wUQQgZzHkilTnaa6" /> <server name="CRM_API_KEY" value="nSBFWecViONG5c96wUQQgZzHkilTnaa6" />
<server name="CRM_API_VERSION" value="v5" />
<server name="CRM_USER_ID" value="1" /> <server name="CRM_USER_ID" value="1" />
</php> </php>

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* Test case class * Test case class
* *
@ -29,16 +29,22 @@ class TestCase extends \PHPUnit_Framework_TestCase
* *
* @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 $site (default: null) * @param string $site (default: null)
* *
* @return ApiClient * @return ApiClient
*/ */
public static function getApiClient($url = null, $apiKey = 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'];
return new ApiClient( return new ApiClient(
$url ?: $_SERVER['CRM_URL'], $url ?: $configUrl,
$apiKey ?: $_SERVER['CRM_API_KEY'], $apiKey ?: $configKey,
$site ?: (isset($_SERVER['CRM_SITE']) ? $_SERVER['CRM_SITE'] : null) $version ?: $configVersion,
$site ?: null
); );
} }
@ -50,15 +56,21 @@ class TestCase extends \PHPUnit_Framework_TestCase
* *
* @return Client * @return Client
*/ */
public static function getClient($url = null, $defaultParameters = array()) public static function getClient($url = null, $defaultParameters = [])
{ {
$version = getenv('CRM_API_VERSION');
if (false == $version) {
$version = $_SERVER['CRM_API_VERSION'];
}
return new Client( return new Client(
$url ?: $_SERVER['CRM_URL'] . '/api/' . ApiClient::VERSION, $url ?: $_SERVER['CRM_API_URL'] . '/api/' . $version,
array( [
'apiKey' => array_key_exists('apiKey', $defaultParameters) 'apiKey' => array_key_exists('apiKey', $defaultParameters)
? $defaultParameters['apiKey'] ? $defaultParameters['apiKey']
: $_SERVER['CRM_API_KEY'] : $_SERVER['CRM_API_KEY']
) ]
); );
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* API client test class * API client test class
* *
@ -28,7 +28,7 @@ use RetailCrm\Test\TestCase;
class ApiClientTest extends TestCase class ApiClientTest extends TestCase
{ {
/** /**
* @group unit * @group client
*/ */
public function testConstruct() public function testConstruct()
{ {

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* API client test class * API client test class
* *
@ -30,27 +30,27 @@ use RetailCrm\Http\Client;
class ClientTest extends TestCase class ClientTest extends TestCase
{ {
/** /**
* @group unit * @group client
*/ */
public function testConstruct() public function testConstruct()
{ {
$client = new Client('https://asdf.df', array()); $client = new Client('https://asdf.df', []);
static::assertInstanceOf('RetailCrm\Http\Client', $client); static::assertInstanceOf('RetailCrm\Http\Client', $client);
} }
/** /**
* @group unit * @group client
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testHttpRequiring() public function testHttpRequiring()
{ {
$client = new Client('http://demo.retailcrm.ru/api/' . ApiClient::VERSION, array('apiKey' => '123')); $client = new Client('http://demo.retailcrm.ru/api/' . $_SERVER['CRM_API_VERSION'], ['apiKey' => '123']);
return $client; return $client;
} }
/** /**
* @group unit * @group client
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testRequestWrongMethod() public function testRequestWrongMethod()
@ -60,17 +60,17 @@ class ClientTest extends TestCase
} }
/** /**
* @group integration * @group client
* @expectedException \RetailCrm\Exception\CurlException * @expectedException \RetailCrm\Exception\CurlException
*/ */
public function testRequestWrongUrl() public function testRequestWrongUrl()
{ {
$client = new Client('https://asdf.df', array()); $client = new Client('https://asdf.df', []);
$client->makeRequest('/a', Client::METHOD_GET, array()); $client->makeRequest('/a', Client::METHOD_GET, []);
} }
/** /**
* @group integration * @group client
*/ */
public function testRequestSuccess() public function testRequestSuccess()
{ {

View File

@ -0,0 +1,286 @@
<?php
/**
* PHP version 5.4
*
* API client customers 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\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientCustomersTest
*
* @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 ApiClientCustomersTest extends TestCase
{
const FIRST_NAME = 'Иннокентий';
/**
* @group customers_v4
*/
public function testCustomersCreate()
{
$client = static::getApiClient(null, null, 'v4');
$externalId = 'c-create-' . time();
$response = $client->request->customersCreate([
'firstName' => self::FIRST_NAME,
'externalId' => $externalId,
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(201, $response->getStatusCode());
static::assertTrue(is_int($response['id']));
return [
'id' => $response['id'],
'externalId' => $externalId,
];
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCreateExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersCreate([]);
}
/**
* @group customers
* @depends testCustomersCreate
*
* @param array $ids
*
* @return array
*/
public function testCustomersGet(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->customersGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->request->customersGet($ids['id'], 'id');
$customerById = $response['customer'];
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertEquals(self::FIRST_NAME, $response['customer']['firstName']);
$response = $client->request->customersGet($ids['externalId'], 'externalId');
static::assertEquals($customerById['id'], $response['customer']['id']);
return $ids;
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCustomersGetException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersGet(678678678, 'asdf');
}
/**
* @group customers
* @depends testCustomersGet
*
* @param array $ids
*/
public function testCustomersEdit(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->customersEdit(
[
'id' => 22342134,
'lastName' => '12345',
],
'id'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
$response = $client->request->customersEdit([
'externalId' => $ids['externalId'],
'lastName' => '12345',
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCustomersEditExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersEdit([], 'asdf');
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCustomersEditException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersEdit(['id' => 678678678], 'asdf');
}
/**
* @group customers_v4
*/
public function testCustomersList()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->customersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response['customers']));
$response = $client->request->customersList([], 1, 300);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertFalse(
$response->isSuccessful(),
'Pagination error'
);
$response = $client->request->customersList(['maxOrdersCount' => 10], 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(
$response->isSuccessful(),
'API returns customers list'
);
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCustomersFixExternalIdsException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersFixExternalIds([]);
}
/**
* @group customers_v4
*/
public function testCustomersFixExternalIds()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersCreate([
'firstName' => 'Aaa111',
]);
static::assertTrue(
$response->isSuccessful(),
'Order created'
);
$response = $client->request->ordersGet($response['id'], 'id');
static::assertTrue(
$response->isSuccessful(),
'Order fetched'
);
$id = $response['order']['customer']['id'];
$externalId = 'asdf' . time();
$response = $client->request->customersFixExternalIds([
['id' => $id, 'externalId' => $externalId]
]);
static::assertTrue(
$response->isSuccessful(),
'Fixed customer ids'
);
$response = $client->request->customersGet($externalId);
static::assertTrue(
$response->isSuccessful(),
'Got customer'
);
static::assertEquals(
$id,
$response['customer']['id'],
'Fixing of customer ids were right'
);
static::assertEquals(
$externalId,
$response['customer']['externalId'],
'Fixing of customer ids were right'
);
}
/**
* @group customers_v4
* @expectedException \InvalidArgumentException
*/
public function testCustomersUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->customersUpload([]);
}
/**
* @group customers_v4
*/
public function testCustomersUpload()
{
$client = static::getApiClient(null, null, 'v4');
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->request->customersUpload([
[
'externalId' => $externalIdA,
'firstName' => 'Aaa',
],
[
'externalId' => $externalIdB,
'lastName' => 'Bbb',
],
]);
static::assertTrue(
$response->isSuccessful(),
'Got customer'
);
static::assertEquals(
$externalIdA,
$response['uploadedCustomers'][0]['externalId']
);
static::assertEquals(
$externalIdB,
$response['uploadedCustomers'][1]['externalId']
);
}
}

View File

@ -0,0 +1,49 @@
<?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\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientMarketplaceTest
*
* @package RetailCrm\Tests
*/
class ApiClientMarketplaceTest extends TestCase
{
const SNAME = 'Marketplace integration v4';
const SCODE = 'integration_v4';
/**
* @group marketplace_v4
*/
public function testConfigurationEdit()
{
$client = static::getApiClient(null, null, "v4");
$response = $client->request->marketplaceSettingsEdit(
[
'name' => self::SNAME,
'code' => self::SCODE,
'logo' => 'http://download.retailcrm.pro/logos/setup.svg',
'active' => 'true'
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
}

View File

@ -0,0 +1,332 @@
<?php
/**
* PHP version 5.4
*
* API client orders 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\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientOrdersTest
*
* @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 ApiClientOrdersTest extends TestCase
{
const FIRST_NAME = 'Иннокентий';
/**
* @group orders_v4
*/
public function testOrdersCreate()
{
$client = static::getApiClient(null, null, 'v4');
$externalId = 'o-create-' . time();
$response = $client->request->ordersCreate([
'firstName' => self::FIRST_NAME,
'externalId' => $externalId,
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(201, $response->getStatusCode());
static::assertTrue(is_int($response['id']));
return [
'id' => $response['id'],
'externalId' => $externalId,
];
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersCreateExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersCreate([]);
}
/**
* @group orders
* @depends testOrdersCreate
*
* @param array $ids
*/
public function testOrdersStatuses(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersStatuses();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(400, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->request->ordersStatuses([], ['asdf']);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(0, sizeof($orders));
$response = $client->request->ordersStatuses([], [$ids['externalId']]);
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']);
$response = $client->request->ordersStatuses([$ids['id']], [$ids['externalId']]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(1, sizeof($orders));
$response = $client->request->ordersStatuses([$ids['id']]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(1, sizeof($orders));
}
/**
* @group orders
* @depends testOrdersCreate
*
* @param array $ids
*
* @return array
*/
public function testOrdersGet(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->request->ordersGet($ids['id'], 'id');
$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']);
$response = $client->request->ordersGet($ids['externalId'], 'externalId');
static::assertEquals($orderById['id'], $response['order']['id']);
return $ids;
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersGetException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersGet(678678678, 'asdf');
}
/**
* @group orders
* @depends testOrdersGet
*
* @param array $ids
*/
public function testOrdersEdit(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersEdit(
[
'id' => 22342134,
'lastName' => '12345',
],
'id'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
$response = $client->request->ordersEdit([
'externalId' => $ids['externalId'],
'lastName' => '12345',
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersEditExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersEdit([], 'asdf');
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersEditException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersEdit(['id' => 678678678], 'asdf');
}
/**
* @group orders_v4
*/
public function testOrdersHistory()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersHistory();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group orders_v4
*/
public function testOrdersList()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response['orders']));
$response = $client->request->ordersList([], 1, 300);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertFalse(
$response->isSuccessful(),
'Pagination error'
);
$response = $client->request->ordersList(['paymentStatus' => 'paid'], 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersFixExternalIdsException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersFixExternalIds([]);
}
/**
* @group orders_v4
*/
public function testOrdersFixExternalIds()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->ordersCreate([
'firstName' => 'Aaa',
]);
static::assertTrue(
$response->isSuccessful(),
'Order created'
);
$id = $response['id'];
$externalId = 'asdf' . time();
$response = $client->request->ordersFixExternalIds([
['id' => $id, 'externalId' => $externalId]
]);
static::assertTrue(
$response->isSuccessful(),
'Fixed order ids'
);
$response = $client->request->ordersGet($externalId);
static::assertTrue(
$response->isSuccessful(),
'Got order'
);
static::assertEquals(
$id,
$response['order']['id'],
'Fixing of order ids were right'
);
static::assertEquals(
$externalId,
$response['order']['externalId'],
'Fixing of order ids were right'
);
}
/**
* @group orders_v4
* @expectedException \InvalidArgumentException
*/
public function testOrdersUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->ordersUpload([]);
}
/**
* @group orders_v4
*/
public function testOrdersUpload()
{
$client = static::getApiClient(null, null, 'v4');
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->request->ordersUpload([
[
'externalId' => $externalIdA,
'firstName' => 'Aaa',
],
[
'externalId' => $externalIdB,
'lastName' => 'Bbb',
],
]);
static::assertTrue(
$response->isSuccessful(),
'Got order'
);
static::assertEquals(
$externalIdA,
$response['uploadedOrders'][0]['externalId']
);
static::assertEquals(
$externalIdB,
$response['uploadedOrders'][1]['externalId']
);
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* PHP version 5.4
*
* API client packs 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\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientPacksTest
*
* @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 ApiClientPacksTest extends TestCase
{
/**
* @group packs_v4
*/
public function testPacksHistory()
{
$client = static::getApiClient(null, null, "v4");
$response = $client->request->ordersPacksHistory();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->success);
static::assertTrue(
isset($response['history']),
'API returns orders assembly history'
);
static::assertTrue(
isset($response['generatedAt']),
'API returns generatedAt in orders assembly history'
);
}
/**
* @group packs_v4
*/
public function testPacksCreateFailed()
{
$client = static::getApiClient(null, null, "v4");
$pack = [
'itemId' => 12,
'store' => 'test',
'quantity' => 2
];
$response = $client->request->ordersPacksCreate($pack);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(400, $response->getStatusCode());
static::assertFalse($response->success);
}
}

View File

@ -0,0 +1,114 @@
<?php
/**
* PHP version 5.4
*
* API client prices 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\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientPricesTest
*
* @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 ApiClientPricesTest extends TestCase
{
/**
* @group prices_v4
*/
public function testPricesEdit()
{
$client = static::getApiClient(null, null, "v4");
$response = $client->request->pricesTypesEdit(
[
'code' => 'sample_v4_price_code',
'name' => 'Sample v4 price type',
'ordering' => 500,
'active' => true
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @depends testPricesEdit
* @group prices_v4
*/
public function testPricesGet()
{
$client = static::getApiClient(null, null, "v4");
$response = $client->request->pricesTypes();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group prices_v4
* @expectedException \InvalidArgumentException
*/
public function testPricesUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, "v4");
$client->request->storePricesUpload([]);
}
/**
* @depends testPricesEdit
* @group prices_v4
*/
public function testPricesUpload()
{
$client = static::getApiClient(null, null, "v4");
$xmlIdA = 'upload-a-' . time();
$xmlIdB = 'upload-b-' . time();
$response = $client->request->storePricesUpload([
[
'xmlId' => $xmlIdA,
'prices' => [
[
'code' => 'sample_v4_price_code',
'price' => 1700
]
]
],
[
'xmlId' => $xmlIdB,
'prices' => [
[
'code' => 'sample_v4_price_code',
'price' => 1500
]
]
],
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
}
}

View File

@ -0,0 +1,171 @@
<?php
/**
* PHP version 5.4
*
* API client references 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\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientReferenceTest
*
* @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 ApiClientReferenceTest extends TestCase
{
/**
* @group reference_v4
* @dataProvider getListDictionaries
* @param $name
*/
public function testList($name)
{
$client = static::getApiClient(null, null, 'v4');
$method = $name . 'List';
$response = $client->request->$method();
/* @var \RetailCrm\Response\ApiResponse $response */
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response[$name]));
static::assertTrue(is_array($response[$name]));
}
/**
* @group reference_v4
* @dataProvider getEditDictionaries
* @expectedException \InvalidArgumentException
*
* @param $name
*/
public function testEditingException($name)
{
$client = static::getApiClient(null, null, 'v4');
$method = $name . 'Edit';
$client->request->$method([]);
}
/**
* @group reference_v4
* @dataProvider getEditDictionaries
*
* @param $name
*/
public function testEditing($name)
{
$client = static::getApiClient(null, null, 'v4');
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';
$params = [
'code' => $code,
'name' => 'Aaa' . $code,
'active' => false
];
if ($name == 'statuses') {
$params['group'] = 'new';
}
$response = $client->request->$method($params);
/* @var \RetailCrm\Response\ApiResponse $response */
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
$response = $client->request->$method([
'code' => $code,
'name' => 'Bbb' . $code,
'active' => false
]);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
}
/**
* @group reference_v4
* @group site
*/
public function testSiteEditing()
{
$name = 'sites';
$client = static::getApiClient(null, null, 'v4');
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';
$params = [
'code' => $code,
'name' => 'Aaa',
'active' => false
];
$response = $client->request->$method($params);
/* @var \RetailCrm\Response\ApiResponse $response */
static::assertEquals(400, $response->getStatusCode());
if ($code == $client->request->getSite()) {
$method = $name . 'Edit';
$params = [
'code' => $code,
'name' => 'Aaa' . time(),
'active' => false
];
$response = $client->request->$method($params);
static::assertEquals(200, $response->getStatusCode());
}
}
/**
* @return array
*/
public function getListDictionaries()
{
return [
['deliveryServices'],
['deliveryTypes'],
['orderMethods'],
['orderTypes'],
['paymentStatuses'],
['paymentTypes'],
['productStatuses'],
['statusGroups'],
['statuses'],
['sites'],
['stores'],
];
}
/**
* @return array
*/
public function getEditDictionaries()
{
return [
['deliveryServices'],
['deliveryTypes'],
['orderMethods'],
['orderTypes'],
['paymentStatuses'],
['paymentTypes'],
['productStatuses'],
['statuses'],
];
}
}

View File

@ -0,0 +1,146 @@
<?php
/**
* PHP version 5.4
*
* API client store 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\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientStoreTest
*
* @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 ApiClientStoreTest extends TestCase
{
const SNAME = 'Test Store V4';
const SCODE = 'test-store-v4';
/**
* @group store_v4
*/
public function testStoreCreate()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->storesEdit(['name' => self::SNAME, 'code' => self::SCODE]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group store_v4
*/
public function testStoreInventories()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->storeInventories();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertTrue(
isset($response['offers']),
'API returns orders assembly history'
);
}
/**
* @group store_v4
* @expectedException \InvalidArgumentException
*/
public function testInventoriesException()
{
$client = static::getApiClient(null, null, 'v4');
$client->request->storeInventoriesUpload([]);
}
/**
* @group store_v4
*/
public function testInventoriesUpload()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->storeInventoriesUpload([
[
'externalId' => 'pTKIKAeghYzX21HTdzFCe1',
'stores' => [
[
'code' => self::SCODE,
'available' => 10,
'purchasePrice' => 1700
]
]
],
[
'externalId' => 'JQIvcrCtiSpOV3AAfMiQB3',
'stores' => [
[
'code' => self::SCODE,
'available' => 20,
'purchasePrice' => 1500
]
]
],
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
}
/**
* @group integration
*/
public function testInventoriesFailed()
{
$client = static::getApiClient(null, null, 'v4');
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->request->storeInventoriesUpload([
[
'externalId' => $externalIdA,
'available' => 10,
'purchasePrice' => 1700
],
[
'externalId' => $externalIdB,
'available' => 20,
'purchasePrice' => 1500
],
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(400, $response->getStatusCode());
static::assertTrue(isset($response['errorMsg']), $response['errorMsg']);
}
/**
* @group store_v4
*/
public function testStoreProducts()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->storeProducts();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
}

View File

@ -0,0 +1,159 @@
<?php
/**
* PHP version 5.4
*
* API client telephony 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\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientTelephonyTest
* @category RetailCrm
* @package RetailCrm\Tests
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientTelephonyTest extends TestCase
{
const TEL_CODE = 'telephony-code-v4';
const TEL_CLIENT = '123';
const TEL_IMAGE = 'http://www.mec.ph/horizon/wp-content/uploads/2011/11/telephony.svg';
/**
* Settings Edit test
*
* @group telephony
*
* @return void
*/
public function testTelephonySettingsEdit()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->telephonySettingsEdit(
self::TEL_CODE,
self::TEL_CLIENT,
true,
'TestTelephonyV4',
false,
self::TEL_IMAGE,
[['userId' => $_SERVER['CRM_USER_ID'], 'code' => '101']],
[['siteCode' => 'api-client-php', 'externalPhone' => '+74950000000']]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* Settings Get test
*
* @group telephony
*
* @return void
*/
public function testTelephonySettingsGet()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->telephonySettingsGet(self::TEL_CODE);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* Event test
*
* @group telephony
*
* @return void
*/
public function testTelephonyEvent()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->telephonyCallEvent(
'+79999999999',
'in',
['101'],
'failed',
'+74950000000'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* Upload test
*
* @group telephony
*
* @return void
*/
public function testTelephonyUpload()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->telephonyCallsUpload(
[
[
'date' => '2016-07-22 00:18:00',
'type' => 'in',
'phone' => '+79999999999',
'code' => '101',
'result' => 'answered',
'externalId' => rand(10, 100),
'recordUrl' => 'http://download.retailcrm.pro/api-client-files/beep1.mp3'
],
[
'date' => '2016-07-22 00:24:00',
'type' => 'in',
'phone' => '+79999999999',
'code' => '101',
'result' => 'answered',
'externalId' => rand(10, 100),
'recordUrl' => 'http://download.retailcrm.pro/api-client-files/beep2.mp3'
]
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* Manager test
*
* @group telephony
*
* @return void
*/
public function testTelephonyManager()
{
$client = static::getApiClient(null, null, 'v4');
$response = $client->request->telephonyCallManager('+79999999999', 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* PHP version 5.4
*
* API client users 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\Version4;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientUsersTest
*
* @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 ApiClientUsersTest extends TestCase
{
/**
* @group users_v4
*/
public function testUsersGroups()
{
$client = static::getApiClient(null, null, "v4");
$response = $client->request->usersGroups();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group users_v4
*/
public function testUsersList()
{
$client = static::getApiClient(null, null, "v4");
$response = $client->request->usersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group users_v4
*/
public function testUsersGet()
{
$client = static::getApiClient(null, null, "v4");
$response = $client->request->usersGet($_SERVER["CRM_USER_ID"]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
}

View File

@ -0,0 +1,447 @@
<?php
/**
* PHP version 5.4
*
* API client customers 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 ApiClientCustomersTest
*
* @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 ApiClientCustomersTest extends TestCase
{
const FIRST_NAME = 'Иннокентий';
/**
* @group customers_v5
*/
public function testCustomersCreate()
{
$client = static::getApiClient();
$externalId = 'c-create-' . time();
$response = $client->request->customersCreate([
'firstName' => self::FIRST_NAME,
'externalId' => $externalId,
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(201, $response->getStatusCode());
static::assertTrue(is_int($response['id']));
return [
'id' => $response['id'],
'externalId' => $externalId,
];
}
/**
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCreateExceptionEmpty()
{
$client = static::getApiClient();
$client->request->customersCreate([]);
}
/**
* @group customers_v5
* @depends testCustomersCreate
*
* @param array $ids
*
* @return array
*/
public function testCustomersGet(array $ids)
{
$client = static::getApiClient();
$response = $client->request->customersGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->request->customersGet($ids['id'], 'id');
$customerById = $response['customer'];
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertEquals(self::FIRST_NAME, $response['customer']['firstName']);
$response = $client->request->customersGet($ids['externalId'], 'externalId');
static::assertEquals($customerById['id'], $response['customer']['id']);
return $ids;
}
/**
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersGetException()
{
$client = static::getApiClient();
$client->request->customersGet(678678678, 'asdf');
}
/**
* @group customers_v5
* @depends testCustomersGet
*
* @param array $ids
*/
public function testCustomersEdit(array $ids)
{
$client = static::getApiClient();
$response = $client->request->customersEdit(
[
'id' => 22342134,
'lastName' => '12345',
],
'id'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
$response = $client->request->customersEdit([
'externalId' => $ids['externalId'],
'lastName' => '12345',
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersEditExceptionEmpty()
{
$client = static::getApiClient();
$client->request->customersEdit([], 'asdf');
}
/**
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersEditException()
{
$client = static::getApiClient();
$client->request->customersEdit(['id' => 678678678], 'asdf');
}
/**
* @group customers_v5
*/
public function testCustomersList()
{
$client = static::getApiClient();
$response = $client->request->customersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response['customers']));
$response = $client->request->customersList([], 1, 300);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertFalse(
$response->isSuccessful(),
'Pagination error'
);
$response = $client->request->customersList(['maxOrdersCount' => 10], 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(
$response->isSuccessful(),
'API returns customers list'
);
}
/**
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersFixExternalIdsException()
{
$client = static::getApiClient();
$client->request->customersFixExternalIds([]);
}
/**
* @group customers_v5
*/
public function testCustomersFixExternalIds()
{
$client = static::getApiClient();
$response = $client->request->ordersCreate([
'firstName' => 'Aaa111',
]);
static::assertTrue(
$response->isSuccessful(),
'Order created'
);
$response = $client->request->ordersGet($response['id'], 'id');
static::assertTrue(
$response->isSuccessful(),
'Order fetched'
);
$id = $response['order']['customer']['id'];
$externalId = 'asdf' . time();
$response = $client->request->customersFixExternalIds([
['id' => $id, 'externalId' => $externalId]
]);
static::assertTrue(
$response->isSuccessful(),
'Fixed customer ids'
);
$response = $client->request->customersGet($externalId);
static::assertTrue(
$response->isSuccessful(),
'Got customer'
);
static::assertEquals(
$id,
$response['customer']['id'],
'Fixing of customer ids were right'
);
static::assertEquals(
$externalId,
$response['customer']['externalId'],
'Fixing of customer ids were right'
);
}
/**
* @group customers_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersUploadExceptionEmpty()
{
$client = static::getApiClient();
$client->request->customersUpload([]);
}
/**
* @group customers_v5
*/
public function testCustomersUpload()
{
$client = static::getApiClient();
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->request->customersUpload([
[
'externalId' => $externalIdA,
'firstName' => 'Aaa',
],
[
'externalId' => $externalIdB,
'lastName' => 'Bbb',
],
]);
static::assertTrue(
$response->isSuccessful(),
'Got customer'
);
static::assertEquals(
$externalIdA,
$response['uploadedCustomers'][0]['externalId']
);
static::assertEquals(
$externalIdB,
$response['uploadedCustomers'][1]['externalId']
);
}
/**
* @group customers_v5
*/
public function testCustomersCombine()
{
$client = static::getApiClient();
$responseCreateFirst = $client->request->customersCreate([
'firstName' => 'Aaa111',
'externalId' => 'AA-' . time(),
'phones' => [
[
'number' => '+79999999990'
]
]
]);
static::assertTrue(
$responseCreateFirst->isSuccessful(),
'Got customer'
);
$responseCreateSecond = $client->request->customersCreate([
'firstName' => 'Aaa222',
'externalId' => 'BB-' . time(),
'phones' => [
[
'number' => '+79999999991'
]
]
]);
static::assertTrue(
$responseCreateSecond->isSuccessful(),
'Got customer'
);
$customers = [
['id' => $responseCreateFirst['id']]
];
$resultCustomer = ['id' => $responseCreateSecond['id']];
$response = $client->request->customersCombine($customers, $resultCustomer);
static::assertTrue(
$response->isSuccessful(),
'Customers combined'
);
}
/**
* @group customers_v5
*/
public function testCustomersNotesCreate()
{
$client = static::getApiClient();
$responseCreateFirst = $client->request->customersCreate([
'firstName' => 'Some',
'lastName' => 'Test',
'externalId' => 'AA-' . time(),
'phones' => [
[
'number' => '+79999999990'
]
]
]);
static::assertTrue(
$responseCreateFirst->isSuccessful(),
'Got customer'
);
$note = [
'managerId' => 6,
'text' => 'test note',
'createdAt' => date('Y-m-d H:i:s'),
'customer' => [
'id' => $responseCreateFirst['id']
]
];
$response = $client->request->customersNotesCreate($note);
static::assertTrue($response->isSuccessful(), 'Note created');
static::assertEquals(201, $response->getStatusCode());
}
/**
* @group customers_v5
*/
public function testCustomersNotesList()
{
$client = static::getApiClient();
$responseCreateFirst = $client->request->customersCreate([
'firstName' => 'Some',
'lastName' => 'Test',
'externalId' => 'AA-' . time(),
'phones' => [
[
'number' => '+79999999990'
]
]
]);
static::assertTrue(
$responseCreateFirst->isSuccessful(),
'Got customer'
);
$response = $client->request->customersNotesList(['customerIds' => [$responseCreateFirst['id']]]);
static::assertTrue($response->isSuccessful(), 'Got notes list');
static::assertEquals(200, $response->getStatusCode());
}
/**
* @group customers_v5
*/
public function testCustomersNotesDelete()
{
$client = static::getApiClient();
$responseCreateFirst = $client->request->customersCreate([
'firstName' => 'Some',
'lastName' => 'Test',
'externalId' => 'AA-' . time(),
'phones' => [
[
'number' => '+79999999990'
]
]
]);
static::assertTrue(
$responseCreateFirst->isSuccessful(),
'Got customer'
);
$note = [
'managerId' => 6,
'text' => 'test note',
'createdAt' => date('Y-m-d H:i:s'),
'customer' => [
'id' => $responseCreateFirst['id']
]
];
$response = $client->request->customersNotesCreate($note);
static::assertTrue($response->isSuccessful(), 'Note created');
static::assertEquals(201, $response->getStatusCode());
$responseDelete = $client->request->customersNotesDelete($response['id']);
static::assertTrue($responseDelete->isSuccessful(), 'Note deleted');
static::assertEquals(200, $responseDelete->getStatusCode());
}
}

View File

@ -0,0 +1,49 @@
<?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
*
* @package RetailCrm\Tests
*/
class ApiClientMarketplaceTest extends TestCase
{
const SNAME = 'Marketplace integration v5';
const SCODE = 'integration_v5';
/**
* @group marketplace_v5
*/
public function testConfigurationEdit()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->marketplaceSettingsEdit(
[
'name' => self::SNAME,
'code' => self::SCODE,
'logo' => 'http://download.retailcrm.pro/logos/setup.svg',
'active' => 'true'
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
}

View File

@ -0,0 +1,420 @@
<?php
/**
* PHP version 5.4
*
* API client orders 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 ApiClientOrdersTest
*
* @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 ApiClientOrdersTest extends TestCase
{
const FIRST_NAME = 'Иннокентий';
/**
* @group orders_v5
*/
public function testOrdersCreate()
{
$client = static::getApiClient(null, null, "v5");
$externalId = 'o-create-' . time();
$response = $client->request->ordersCreate([
'firstName' => self::FIRST_NAME,
'externalId' => $externalId,
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(201, $response->getStatusCode());
static::assertTrue(is_int($response['id']));
return [
'id' => $response['id'],
'externalId' => $externalId,
];
}
/**
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersCreateExceptionEmpty()
{
$client = static::getApiClient(null, null, "v5");
$client->request->ordersCreate([]);
}
/**
* @group orders
* @depends testOrdersCreate
*
* @param array $ids
*/
public function testOrdersStatuses(array $ids)
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->ordersStatuses();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(400, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->request->ordersStatuses([], ['asdf']);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(0, sizeof($orders));
$response = $client->request->ordersStatuses([], [$ids['externalId']]);
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']);
$response = $client->request->ordersStatuses([$ids['id']], [$ids['externalId']]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(1, sizeof($orders));
$response = $client->request->ordersStatuses([$ids['id']]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
$orders = $response['orders'];
static::assertEquals(1, sizeof($orders));
}
/**
* @group orders
* @depends testOrdersCreate
*
* @param array $ids
*
* @return array
*/
public function testOrdersGet(array $ids)
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->ordersGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->request->ordersGet($ids['id'], 'id');
$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']);
$response = $client->request->ordersGet($ids['externalId'], 'externalId');
static::assertEquals($orderById['id'], $response['order']['id']);
return $ids;
}
/**
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersGetException()
{
$client = static::getApiClient(null, null, "v5");
$client->request->ordersGet(678678678, 'asdf');
}
/**
* @group orders
* @depends testOrdersGet
*
* @param array $ids
*/
public function testOrdersEdit(array $ids)
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->ordersEdit(
[
'id' => 22342134,
'lastName' => '12345',
],
'id'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
$response = $client->request->ordersEdit([
'externalId' => $ids['externalId'],
'lastName' => '12345',
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersEditExceptionEmpty()
{
$client = static::getApiClient(null, null, "v5");
$client->request->ordersEdit([], 'asdf');
}
/**
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersEditException()
{
$client = static::getApiClient(null, null, "v5");
$client->request->ordersEdit(['id' => 678678678], 'asdf');
}
/**
* @group orders_v5
*/
public function testOrdersHistory()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->ordersHistory();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group orders_v5
*/
public function testOrdersList()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->ordersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response['orders']));
$response = $client->request->ordersList([], 1, 300);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertFalse(
$response->isSuccessful(),
'Pagination error'
);
$response = $client->request->ordersList(['paymentStatus' => 'paid'], 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
}
/**
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersFixExternalIdsException()
{
$client = static::getApiClient(null, null, "v5");
$client->request->ordersFixExternalIds([]);
}
/**
* @group orders_v5
*/
public function testOrdersFixExternalIds()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->ordersCreate([
'firstName' => 'Aaa',
]);
static::assertTrue(
$response->isSuccessful(),
'Order created'
);
$id = $response['id'];
$externalId = 'asdf' . time();
$response = $client->request->ordersFixExternalIds([
['id' => $id, 'externalId' => $externalId]
]);
static::assertTrue(
$response->isSuccessful(),
'Fixed order ids'
);
$response = $client->request->ordersGet($externalId);
static::assertTrue(
$response->isSuccessful(),
'Got order'
);
static::assertEquals(
$id,
$response['order']['id'],
'Fixing of order ids were right'
);
static::assertEquals(
$externalId,
$response['order']['externalId'],
'Fixing of order ids were right'
);
}
/**
* @group orders_v5
* @expectedException \InvalidArgumentException
*/
public function testOrdersUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, "v5");
$client->request->ordersUpload([]);
}
/**
* @group orders_v5
*/
public function testOrdersUpload()
{
$client = static::getApiClient(null, null, "v5");
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->request->ordersUpload([
[
'externalId' => $externalIdA,
'firstName' => 'Aaa',
],
[
'externalId' => $externalIdB,
'lastName' => 'Bbb',
],
]);
static::assertTrue(
$response->isSuccessful(),
'Got order'
);
static::assertEquals(
$externalIdA,
$response['uploadedOrders'][0]['externalId']
);
static::assertEquals(
$externalIdB,
$response['uploadedOrders'][1]['externalId']
);
}
/**
* @group orders_v5
*/
public function testOrdersCombine()
{
$client = static::getApiClient(null, null, "v5");
$responseCreateFirst = $client->request->ordersCreate([
'firstName' => 'Aaa111',
'externalId' => 'AA-' . time(),
'phone' => '+79999999990'
]);
static::assertTrue(
$responseCreateFirst->isSuccessful(),
'Got order'
);
$responseCreateSecond = $client->request->ordersCreate([
'firstName' => 'Aaa222',
'externalId' => 'BB-' . time(),
'phone' => '+79999999991'
]);
static::assertTrue(
$responseCreateSecond->isSuccessful(),
'Got order'
);
$order = ['id' => $responseCreateFirst['id']];
$resultOrder = ['id' => $responseCreateSecond['id']];
$response = $client->request->ordersCombine($order, $resultOrder, 'ours');
static::assertTrue(
$response->isSuccessful(),
'Orders combined'
);
}
public function testOrdersPayment()
{
$client = static::getApiClient(null, null, "v5");
$externalId = 'AA-' . time();
$responseCreateFirst = $client->request->ordersCreate([
'firstName' => 'Aaa111aaA',
'phone' => '+79999999990'
]);
static::assertTrue(
$responseCreateFirst->isSuccessful(),
'Got order'
);
$payment = [
'externalId' => $externalId,
'order' => ['id' => $responseCreateFirst['id']],
'amount' => 1200,
'comment' => 'test payment',
'type' => 'cash',
'status' => 'paid'
];
$response = $client->request->ordersPaymentCreate($payment);
static::assertTrue(
$response->isSuccessful(),
'Got payment'
);
$paymentEdit = [
'id' => $response['id'],
'externalId' => $externalId,
'amount' => 1500,
'comment' => 'test payment!',
'type' => 'cash',
'status' => 'paid'
];
$responseAgain = $client->request->ordersPaymentEdit($paymentEdit);
static::assertTrue(
$responseAgain->isSuccessful(),
'Got payment'
);
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* PHP version 5.4
*
* API client packs 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 ApiClientPacksTest
*
* @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 ApiClientPacksTest extends TestCase
{
/**
* @group packs_v5
*/
public function testPacksHistory()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->ordersPacksHistory();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->success);
static::assertTrue(
isset($response['history']),
'API returns orders assembly history'
);
static::assertTrue(
isset($response['generatedAt']),
'API returns generatedAt in orders assembly history'
);
}
/**
* @group packs_v5
*/
public function testPacksCreateFailed()
{
$client = static::getApiClient(null, null, "v5");
$pack = [
'itemId' => 12,
'store' => 'test',
'quantity' => 2
];
$response = $client->request->ordersPacksCreate($pack);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(400, $response->getStatusCode());
static::assertFalse($response->success);
}
}

View File

@ -0,0 +1,114 @@
<?php
/**
* PHP version 5.4
*
* API client prices 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 ApiClientPricesTest
*
* @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 ApiClientPricesTest extends TestCase
{
/**
* @group prices_v5
*/
public function testPricesEdit()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->pricesTypesEdit(
[
'code' => 'sample_v4_price_code',
'name' => 'Sample v4 price type',
'ordering' => 500,
'active' => true
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @depends testPricesEdit
* @group prices_v5
*/
public function testPricesGet()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->pricesTypes();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group prices_v5
* @expectedException \InvalidArgumentException
*/
public function testPricesUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, "v5");
$client->request->storePricesUpload([]);
}
/**
* @depends testPricesEdit
* @group prices_v5
*/
public function testPricesUpload()
{
$client = static::getApiClient(null, null, "v5");
$xmlIdA = 'upload-a-' . time();
$xmlIdB = 'upload-b-' . time();
$response = $client->request->storePricesUpload([
[
'xmlId' => $xmlIdA,
'prices' => [
[
'code' => 'sample_v4_price_code',
'price' => 1700
]
]
],
[
'xmlId' => $xmlIdB,
'prices' => [
[
'code' => 'sample_v4_price_code',
'price' => 1500
]
]
],
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
}
}

View File

@ -0,0 +1,171 @@
<?php
/**
* PHP version 5.4
*
* API client references 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 ApiClientReferenceTest
*
* @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 ApiClientReferenceTest extends TestCase
{
/**
* @group reference_v5
* @dataProvider getListDictionaries
* @param $name
*/
public function testList($name)
{
$client = static::getApiClient(null, null, "v5");
$method = $name . 'List';
$response = $client->request->$method();
/* @var \RetailCrm\Response\ApiResponse $response */
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response[$name]));
static::assertTrue(is_array($response[$name]));
}
/**
* @group reference_v5
* @dataProvider getEditDictionaries
* @expectedException \InvalidArgumentException
*
* @param $name
*/
public function testEditingException($name)
{
$client = static::getApiClient(null, null, "v5");
$method = $name . 'Edit';
$client->request->$method([]);
}
/**
* @group reference_v5
* @dataProvider getEditDictionaries
*
* @param $name
*/
public function testEditing($name)
{
$client = static::getApiClient(null, null, "v5");
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';
$params = [
'code' => $code,
'name' => 'Aaa' . $code,
'active' => false
];
if ($name == 'statuses') {
$params['group'] = 'new';
}
$response = $client->request->$method($params);
/* @var \RetailCrm\Response\ApiResponse $response */
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
$response = $client->request->$method([
'code' => $code,
'name' => 'Bbb' . $code,
'active' => false
]);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
}
/**
* @group reference_v5
* @group site
*/
public function testSiteEditing()
{
$name = 'sites';
$client = static::getApiClient(null, null, "v5");
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';
$params = [
'code' => $code,
'name' => 'Aaa',
'active' => false
];
$response = $client->request->$method($params);
/* @var \RetailCrm\Response\ApiResponse $response */
static::assertEquals(400, $response->getStatusCode());
if ($code == $client->request->getSite()) {
$method = $name . 'Edit';
$params = [
'code' => $code,
'name' => 'Aaa' . time(),
'active' => false
];
$response = $client->request->$method($params);
static::assertEquals(200, $response->getStatusCode());
}
}
/**
* @return array
*/
public function getListDictionaries()
{
return [
['deliveryServices'],
['deliveryTypes'],
['orderMethods'],
['orderTypes'],
['paymentStatuses'],
['paymentTypes'],
['productStatuses'],
['statusGroups'],
['statuses'],
['sites'],
['stores'],
];
}
/**
* @return array
*/
public function getEditDictionaries()
{
return [
['deliveryServices'],
['deliveryTypes'],
['orderMethods'],
['orderTypes'],
['paymentStatuses'],
['paymentTypes'],
['productStatuses'],
['statuses'],
];
}
}

View File

@ -0,0 +1,159 @@
<?php
/**
* PHP version 5.4
*
* API client store 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 ApiClientStoreTest
*
* @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 ApiClientStoreTest extends TestCase
{
const SNAME = 'Test Store V5';
const SCODE = 'test-store-v5';
/**
* @group store_v4
*/
public function testStoreCreate()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->storesEdit(['name' => self::SNAME, 'code' => self::SCODE]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group store_v4
*/
public function testStoreInventories()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->storeInventories();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertTrue(
isset($response['offers']),
'API returns orders assembly history'
);
}
/**
* @group store_v4
* @expectedException \InvalidArgumentException
*/
public function testInventoriesException()
{
$client = static::getApiClient(null, null, "v5");
$client->request->storeInventoriesUpload([]);
}
/**
* @group store_v4
*/
public function testInventoriesUpload()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->storeInventoriesUpload([
[
'externalId' => 'pTKIKAeghYzX21HTdzFCe1',
'stores' => [
[
'code' => self::SCODE,
'available' => 10,
'purchasePrice' => 1700
]
]
],
[
'externalId' => 'JQIvcrCtiSpOV3AAfMiQB3',
'stores' => [
[
'code' => self::SCODE,
'available' => 20,
'purchasePrice' => 1500
]
]
],
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
}
/**
* @group integration
*/
public function testInventoriesFailed()
{
$client = static::getApiClient(null, null, "v5");
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->request->storeInventoriesUpload([
[
'externalId' => $externalIdA,
'available' => 10,
'purchasePrice' => 1700
],
[
'externalId' => $externalIdB,
'available' => 20,
'purchasePrice' => 1500
],
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(400, $response->getStatusCode());
static::assertTrue(isset($response['errorMsg']), $response['errorMsg']);
}
/**
* @group store_v4
*/
public function testStoreProducts()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->storeProducts();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group store_v4
*/
public function testStoreProductsGroups()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->storeProductsGroups();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* PHP version 5.4
*
* API client orders 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 ApiClientTasksTest
*
* @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 ApiClientTasksTest extends TestCase
{
/**
* @group tasks_v5
*/
public function testTasksList()
{
$client = static::getApiClient(null, null, 'v5');
$response = $client->request->tasksList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
}
/**
* @group tasks_v5
* @expectedException \InvalidArgumentException
*/
public function testTasksCreateExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v5');
$client->request->tasksCreate([]);
}
public function testTasksCRU()
{
$client = static::getApiClient(null, null, 'v5');
$task = [
'text' => 'test task',
'commentary' => 'test task commentary',
'performerId' => $_SERVER['CRM_USER_ID'],
'complete' => false
];
$responseCreate = $client->request->tasksCreate($task);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseCreate);
static::assertEquals(201, $responseCreate->getStatusCode());
$uid = $responseCreate['id'];
$responseRead = $client->request->tasksGet($uid);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseRead);
static::assertEquals(200, $responseRead->getStatusCode());
$task['id'] = $uid;
$task['complete'] = true;
$responseUpdate = $client->request->tasksEdit($task);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $responseUpdate);
static::assertEquals(200, $responseUpdate->getStatusCode());
}
}

View File

@ -0,0 +1,159 @@
<?php
/**
* PHP version 5.4
*
* API client telephony 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 ApiClientTelephonyTest
* @category RetailCrm
* @package RetailCrm\Tests
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class ApiClientTelephonyTest extends TestCase
{
const TEL_CODE = 'telephony-code-v5';
const TEL_CLIENT = '456';
const TEL_IMAGE = 'http://www.mec.ph/horizon/wp-content/uploads/2011/11/telephony.svg';
/**
* Settings Edit test
*
* @group telephony
*
* @return void
*/
public function testTelephonySettingsEdit()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->telephonySettingsEdit(
self::TEL_CODE,
self::TEL_CLIENT,
true,
'TestTelephonyV5',
false,
self::TEL_IMAGE,
[['userId' => $_SERVER['CRM_USER_ID'], 'code' => '101']],
[['siteCode' => 'api-client-php', 'externalPhone' => '+74950000000']]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* Settings Get test
*
* @group telephony
*
* @return void
*/
public function testTelephonySettingsGet()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->telephonySettingsGet(self::TEL_CODE);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* Event test
*
* @group telephony
*
* @return void
*/
public function testTelephonyEvent()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->telephonyCallEvent(
'+79999999999',
'in',
['101'],
'failed',
'+74950000000'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* Upload test
*
* @group telephony
*
* @return void
*/
public function testTelephonyUpload()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->telephonyCallsUpload(
[
[
'date' => '2016-07-22 00:18:00',
'type' => 'in',
'phone' => '+79999999999',
'code' => '101',
'result' => 'answered',
'externalId' => rand(10, 100),
'recordUrl' => 'http://download.retailcrm.pro/api-client-files/beep1.mp3'
],
[
'date' => '2016-07-22 00:24:00',
'type' => 'in',
'phone' => '+79999999999',
'code' => '101',
'result' => 'answered',
'externalId' => rand(10, 100),
'recordUrl' => 'http://download.retailcrm.pro/api-client-files/beep2.mp3'
]
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* Manager test
*
* @group telephony
*
* @return void
*/
public function testTelephonyManager()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->telephonyCallManager('+79999999999', 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* PHP version 5.4
*
* API client users 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 ApiClientUsersTest
*
* @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 ApiClientUsersTest extends TestCase
{
/**
* @group users_v5
*/
public function testUsersGroups()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->usersGroups();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group users_v5
*/
public function testUsersList()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->usersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group users_v5
*/
public function testUsersGet()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->usersGet($_SERVER["CRM_USER_ID"]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
/**
* @group users_v5
*/
public function testUsersStatus()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->usersStatus($_SERVER["CRM_USER_ID"], 'dinner');
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
}
}

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHP version 5.3 * PHP version 5.4
* *
* API client response test class * API client response test class
* *
@ -29,19 +29,19 @@ use RetailCrm\Response\ApiResponse;
class ApiResponseTest extends TestCase class ApiResponseTest extends TestCase
{ {
/** /**
* @group unit * @group response
*/ */
public function testSuccessConstruct() public function testSuccessConstruct()
{ {
$response = new ApiResponse(200); $response = new ApiResponse(200);
$this->assertInstanceOf( static::assertInstanceOf(
'RetailCrm\Response\ApiResponse', 'RetailCrm\Response\ApiResponse',
$response, $response,
'Response object created' 'Response object created'
); );
$response = new ApiResponse(201, '{ "success": true }'); $response = new ApiResponse(201, '{ "success": true }');
$this->assertInstanceOf( static::assertInstanceOf(
'RetailCrm\Response\ApiResponse', 'RetailCrm\Response\ApiResponse',
$response, $response,
'Response object created' 'Response object created'
@ -49,28 +49,28 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
* @expectedException \RetailCrm\Exception\InvalidJsonException * @expectedException \RetailCrm\Exception\InvalidJsonException
*/ */
public function testJsonInvalid() public function testJsonInvalid()
{ {
$response = new ApiResponse(400, '{ "asdf": }'); new ApiResponse(400, '{ "asdf": }');
} }
/** /**
* @group unit * @group response
*/ */
public function testStatusCodeGetting() public function testStatusCodeGetting()
{ {
$response = new ApiResponse(200); $response = new ApiResponse(200);
$this->assertEquals( static::assertEquals(
200, 200,
$response->getStatusCode(), $response->getStatusCode(),
'Response object returns the right status code' 'Response object returns the right status code'
); );
$response = new ApiResponse(460, '{ "success": false }'); $response = new ApiResponse(460, '{ "success": false }');
$this->assertEquals( static::assertEquals(
460, 460,
$response->getStatusCode(), $response->getStatusCode(),
'Response object returns the right status code' 'Response object returns the right status code'
@ -78,38 +78,38 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
*/ */
public function testIsSuccessful() public function testIsSuccessful()
{ {
$response = new ApiResponse(200); $response = new ApiResponse(200);
$this->assertTrue( static::assertTrue(
$response->isSuccessful(), $response->isSuccessful(),
'Request was successful' 'Request was successful'
); );
$response = new ApiResponse(460, '{ "success": false }'); $response = new ApiResponse(460, '{ "success": false }');
$this->assertFalse( static::assertFalse(
$response->isSuccessful(), $response->isSuccessful(),
'Request was failed' 'Request was failed'
); );
} }
/** /**
* @group unit * @group response
*/ */
public function testMagicCall() public function testMagicCall()
{ {
$response = new ApiResponse(201, '{ "success": true }'); $response = new ApiResponse(201, '{ "success": true }');
$this->assertEquals( static::assertEquals(
true, true,
$response->getSuccess(), $response->isSuccessful(),
'Response object returns property value throw magic method' 'Response object returns property value throw magic method'
); );
} }
/** /**
* @group unit * @group response
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testMagicCallException1() public function testMagicCallException1()
@ -119,7 +119,7 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testMagicCallException2() public function testMagicCallException2()
@ -129,12 +129,12 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
*/ */
public function testMagicGet() public function testMagicGet()
{ {
$response = new ApiResponse(201, '{ "success": true }'); $response = new ApiResponse(201, '{ "success": true }');
$this->assertEquals( static::assertEquals(
true, true,
$response->success, $response->success,
'Response object returns property value throw magic get' 'Response object returns property value throw magic get'
@ -142,7 +142,7 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testMagicGetException1() public function testMagicGetException1()
@ -152,7 +152,7 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testMagicGetException2() public function testMagicGetException2()
@ -162,12 +162,12 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
*/ */
public function testArrayGet() public function testArrayGet()
{ {
$response = new ApiResponse(201, '{ "success": true }'); $response = new ApiResponse(201, '{ "success": true }');
$this->assertEquals( static::assertEquals(
true, true,
$response['success'], $response['success'],
'Response object returns property value throw magic array get' 'Response object returns property value throw magic array get'
@ -175,7 +175,7 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testArrayGetException1() public function testArrayGetException1()
@ -185,7 +185,7 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testArrayGetException2() public function testArrayGetException2()
@ -195,25 +195,25 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
*/ */
public function testArrayIsset() public function testArrayIsset()
{ {
$response = new ApiResponse(201, '{ "success": true }'); $response = new ApiResponse(201, '{ "success": true }');
$this->assertTrue( static::assertTrue(
isset($response['success']), isset($response['success']),
'Response object returns property existing' 'Response object returns property existing'
); );
$this->assertFalse( static::assertFalse(
isset($response['suess']), isset($response['suess']),
'Response object returns property existing' 'Response object returns property existing'
); );
} }
/** /**
* @group unit * @group response
* @expectedException \BadMethodCallException * @expectedException \BadMethodCallException
*/ */
public function testArraySetException1() public function testArraySetException1()
@ -223,7 +223,7 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
* @expectedException \BadMethodCallException * @expectedException \BadMethodCallException
*/ */
public function testArraySetException2() public function testArraySetException2()
@ -233,7 +233,7 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
* @expectedException \BadMethodCallException * @expectedException \BadMethodCallException
*/ */
public function testArrayUnsetException1() public function testArrayUnsetException1()
@ -243,7 +243,7 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
* @expectedException \BadMethodCallException * @expectedException \BadMethodCallException
*/ */
public function testArrayUnsetException2() public function testArrayUnsetException2()
@ -253,18 +253,18 @@ class ApiResponseTest extends TestCase
} }
/** /**
* @group unit * @group response
*/ */
public function testMagicIsset() public function testMagicIsset()
{ {
$response = new ApiResponse(201, '{ "success": true }'); $response = new ApiResponse(201, '{ "success": true }');
$this->assertTrue( static::assertTrue(
isset($response->success), isset($response->success),
'Response object returns property existing' 'Response object returns property existing'
); );
$this->assertFalse( static::assertFalse(
isset($response->suess), isset($response->suess),
'Response object returns property existing' 'Response object returns property existing'
); );