Update to API version 5 (#40)
* combine methods for orders & customer * update status method for users * custom fields|dictionaries * task methods * segments * product groups list methods, * orders payments * multi-version * customers notes methods
This commit is contained in:
parent
b701fa232c
commit
a18767bddc
@ -11,8 +11,8 @@ php:
|
||||
- '7.0'
|
||||
|
||||
before_script:
|
||||
- flags="--prefer-dist --no-dev"
|
||||
- flags="-o"
|
||||
- composer install $flags
|
||||
- wget -c -O phpunit.xml https://db.tt/uMin8U9t
|
||||
- cp phpunit.xml.dist phpunit.xml
|
||||
|
||||
script: phpunit
|
||||
|
21
README.md
21
README.md
@ -1,12 +1,12 @@
|
||||
# retailCRM API PHP client
|
||||
|
||||
PHP-client for [retailCRM API](http://www.retailcrm.pro/docs/Developers/ApiVersion4).
|
||||
PHP-client for [retailCRM API](http://www.retailcrm.pro/docs/Developers/ApiVersion5).
|
||||
|
||||
Use [API documentation](http://retailcrm.github.io/api-client-php)
|
||||
|
||||
## Requirements
|
||||
|
||||
* PHP 5.3 and above
|
||||
* PHP 5.4 and above
|
||||
* PHP's cURL support
|
||||
|
||||
## Install
|
||||
@ -15,7 +15,7 @@ Use [API documentation](http://retailcrm.github.io/api-client-php)
|
||||
|
||||
2) Run into your project directory:
|
||||
```bash
|
||||
composer require retailcrm/api-client-php 4.* --no-dev
|
||||
composer require retailcrm/api-client-php 5.* --no-dev
|
||||
```
|
||||
|
||||
If you have not used `composer` before, include autoloader into your project.
|
||||
@ -28,13 +28,13 @@ require 'path/to/vendor/autoload.php';
|
||||
### Get order
|
||||
```php
|
||||
$client = new \RetailCrm\ApiClient(
|
||||
'https://demo.retailcrm.pro',
|
||||
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH'
|
||||
'https://demo.retailcrm.ru',
|
||||
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
|
||||
'v5'
|
||||
);
|
||||
|
||||
|
||||
try {
|
||||
$response = $client->ordersGet('M-2342');
|
||||
$response = $client->request->ordersGet('M-2342');
|
||||
} catch (\RetailCrm\Exception\CurlException $e) {
|
||||
echo "Connection error: " . $e->getMessage();
|
||||
}
|
||||
@ -63,12 +63,13 @@ if ($response->isSuccessful()) {
|
||||
```php
|
||||
|
||||
$client = new \RetailCrm\ApiClient(
|
||||
'https://demo.retailcrm.pro',
|
||||
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH'
|
||||
'https://demo.retailcrm.ru',
|
||||
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
|
||||
'v4'
|
||||
);
|
||||
|
||||
try {
|
||||
$response = $client->ordersCreate(array(
|
||||
$response = $client->request->ordersCreate(array(
|
||||
'externalId' => 'some-shop-order-id',
|
||||
'firstName' => 'Vasily',
|
||||
'lastName' => 'Pupkin',
|
||||
|
17
README.ru.md
17
README.ru.md
@ -1,12 +1,12 @@
|
||||
# PHP-клиент для retailCRM API
|
||||
|
||||
PHP-клиент для работы с [retailCRM API](http://www.retailcrm.ru/docs/Developers/ApiVersion4).
|
||||
PHP-клиент для работы с [retailCRM API](http://www.retailcrm.ru/docs/Developers/ApiVersion5).
|
||||
|
||||
Рекомендуем обращаться к [документации](http://retailcrm.github.io/api-client-php) по библиотеке, в частности по классу [RetailCrm\ApiClient](http://retailcrm.github.io/api-client-php/class-RetailCrm.ApiClient.html).
|
||||
|
||||
## Обязательные требования
|
||||
|
||||
* PHP версии 5.3 и выше
|
||||
* PHP версии 5.4 и выше
|
||||
* PHP-расширение cURL
|
||||
|
||||
## Установка
|
||||
@ -15,7 +15,7 @@ PHP-клиент для работы с [retailCRM API](http://www.retailcrm.ru/
|
||||
|
||||
2) Выполните в папке проекта:
|
||||
```bash
|
||||
composer require retailcrm/api-client-php 4.* --no-dev
|
||||
composer require retailcrm/api-client-php 5.* --no-dev
|
||||
```
|
||||
|
||||
В конфиг `composer.json` вашего проекта будет добавлена библиотека `retailcrm/api-client-php`, которая установится в папку `vendor/`. При отсутствии файла конфига или папки с вендорами они будут созданы.
|
||||
@ -31,12 +31,12 @@ require 'path/to/vendor/autoload.php';
|
||||
```php
|
||||
$client = new \RetailCrm\ApiClient(
|
||||
'https://demo.retailcrm.ru',
|
||||
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH'
|
||||
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
|
||||
'v5'
|
||||
);
|
||||
|
||||
|
||||
try {
|
||||
$response = $client->ordersGet('M-2342');
|
||||
$response = $client-request->ordersGet('M-2342');
|
||||
} catch (\RetailCrm\Exception\CurlException $e) {
|
||||
echo "Сетевые проблемы. Ошибка подключения к retailCRM: " . $e->getMessage();
|
||||
}
|
||||
@ -66,11 +66,12 @@ if ($response->isSuccessful()) {
|
||||
|
||||
$client = new \RetailCrm\ApiClient(
|
||||
'https://demo.retailcrm.ru',
|
||||
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH'
|
||||
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
|
||||
'v4'
|
||||
);
|
||||
|
||||
try {
|
||||
$response = $client->ordersCreate(array(
|
||||
$response = $client-request->ordersCreate(array(
|
||||
'externalId' => 'some-shop-order-id',
|
||||
'firstName' => 'Vasily',
|
||||
'lastName' => 'Pupkin',
|
||||
|
@ -3,30 +3,31 @@
|
||||
"description": "PHP client for retailCRM API",
|
||||
"type": "library",
|
||||
"keywords": ["API", "retailCRM", "REST"],
|
||||
"homepage": "http://www.retailcrm.pro/",
|
||||
"homepage": "http://www.retailcrm.ru/",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "retailCRM",
|
||||
"email": "support@retailcrm.pro"
|
||||
"email": "support@retailcrm.ru"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"php": ">=5.4.0",
|
||||
"ext-curl": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.8.29"
|
||||
"phpunit/phpunit": "3.7.*",
|
||||
"squizlabs/php_codesniffer": "3.*"
|
||||
},
|
||||
"support": {
|
||||
"email": "support@retailcrm.pro"
|
||||
"email": "support@retailcrm.ru"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "RetailCrm\\": "lib/" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.0.x-dev"
|
||||
"dev-master": "5.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
|
File diff suppressed because it is too large
Load Diff
132
lib/RetailCrm/Client/AbstractLoader.php
Normal file
132
lib/RetailCrm/Client/AbstractLoader.php
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
53
lib/RetailCrm/Client/ApiVersion3.php
Normal file
53
lib/RetailCrm/Client/ApiVersion3.php
Normal 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;
|
||||
}
|
56
lib/RetailCrm/Client/ApiVersion4.php
Normal file
56
lib/RetailCrm/Client/ApiVersion4.php
Normal 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;
|
||||
}
|
59
lib/RetailCrm/Client/ApiVersion5.php
Normal file
59
lib/RetailCrm/Client/ApiVersion5.php
Normal 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;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
* PHP version 5.4
|
||||
*
|
||||
* Class CurlException
|
||||
*
|
||||
@ -9,13 +9,13 @@
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Exception;
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
* PHP version 5.4
|
||||
*
|
||||
* Class CurlException
|
||||
*
|
||||
@ -23,7 +23,7 @@ namespace RetailCrm\Exception;
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
class CurlException extends \RuntimeException
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
* PHP version 5.4
|
||||
*
|
||||
* Class InvalidJsonException
|
||||
*
|
||||
@ -9,13 +9,13 @@
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Exception;
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
* PHP version 5.4
|
||||
*
|
||||
* Class InvalidJsonException
|
||||
*
|
||||
@ -23,7 +23,7 @@ namespace RetailCrm\Exception;
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
class InvalidJsonException extends \DomainException
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
* PHP version 5.4
|
||||
*
|
||||
* HTTP client
|
||||
*
|
||||
@ -9,7 +9,7 @@
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Http;
|
||||
@ -19,7 +19,7 @@ use RetailCrm\Exception\InvalidJsonException;
|
||||
use RetailCrm\Response\ApiResponse;
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
* PHP version 5.4
|
||||
*
|
||||
* HTTP client
|
||||
*
|
||||
@ -27,7 +27,7 @@ use RetailCrm\Response\ApiResponse;
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
class Client
|
||||
{
|
||||
@ -45,7 +45,7 @@ class Client
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct($url, array $defaultParameters = array())
|
||||
public function __construct($url, array $defaultParameters = [])
|
||||
{
|
||||
if (false === stripos($url, 'https://')) {
|
||||
throw new \InvalidArgumentException(
|
||||
@ -75,9 +75,9 @@ class Client
|
||||
public function makeRequest(
|
||||
$path,
|
||||
$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)) {
|
||||
throw new \InvalidArgumentException(
|
||||
|
206
lib/RetailCrm/Methods/V3/Customers.php
Normal file
206
lib/RetailCrm/Methods/V3/Customers.php
Normal 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]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
267
lib/RetailCrm/Methods/V3/Orders.php
Normal file
267
lib/RetailCrm/Methods/V3/Orders.php
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
197
lib/RetailCrm/Methods/V3/Packs.php
Normal file
197
lib/RetailCrm/Methods/V3/Packs.php
Normal 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)])
|
||||
);
|
||||
}
|
||||
}
|
499
lib/RetailCrm/Methods/V3/References.php
Normal file
499
lib/RetailCrm/Methods/V3/References.php
Normal 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)]
|
||||
);
|
||||
}
|
||||
}
|
46
lib/RetailCrm/Methods/V3/Statistic.php
Normal file
46
lib/RetailCrm/Methods/V3/Statistic.php
Normal 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"
|
||||
);
|
||||
}
|
||||
}
|
90
lib/RetailCrm/Methods/V3/Stores.php
Normal file
90
lib/RetailCrm/Methods/V3/Stores.php
Normal 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)])
|
||||
);
|
||||
}
|
||||
}
|
156
lib/RetailCrm/Methods/V3/Telephony.php
Normal file
156
lib/RetailCrm/Methods/V3/Telephony.php
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
62
lib/RetailCrm/Methods/V4/Customers.php
Normal file
62
lib/RetailCrm/Methods/V4/Customers.php
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
109
lib/RetailCrm/Methods/V4/Delivery.php
Normal file
109
lib/RetailCrm/Methods/V4/Delivery.php
Normal 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)]
|
||||
);
|
||||
}
|
||||
}
|
56
lib/RetailCrm/Methods/V4/Marketplace.php
Normal file
56
lib/RetailCrm/Methods/V4/Marketplace.php
Normal 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)]
|
||||
);
|
||||
}
|
||||
}
|
271
lib/RetailCrm/Methods/V4/Orders.php
Normal file
271
lib/RetailCrm/Methods/V4/Orders.php
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
33
lib/RetailCrm/Methods/V4/Packs.php
Normal file
33
lib/RetailCrm/Methods/V4/Packs.php
Normal 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;
|
||||
}
|
81
lib/RetailCrm/Methods/V4/References.php
Normal file
81
lib/RetailCrm/Methods/V4/References.php
Normal 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)]
|
||||
);
|
||||
}
|
||||
}
|
33
lib/RetailCrm/Methods/V4/Statistic.php
Normal file
33
lib/RetailCrm/Methods/V4/Statistic.php
Normal 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;
|
||||
}
|
144
lib/RetailCrm/Methods/V4/Stores.php
Normal file
144
lib/RetailCrm/Methods/V4/Stores.php
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
137
lib/RetailCrm/Methods/V4/Telephony.php
Normal file
137
lib/RetailCrm/Methods/V4/Telephony.php
Normal 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)]
|
||||
);
|
||||
}
|
||||
}
|
111
lib/RetailCrm/Methods/V4/Users.php
Normal file
111
lib/RetailCrm/Methods/V4/Users.php
Normal 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");
|
||||
}
|
||||
}
|
250
lib/RetailCrm/Methods/V5/CustomFields.php
Normal file
250
lib/RetailCrm/Methods/V5/CustomFields.php
Normal 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"
|
||||
);
|
||||
}
|
||||
}
|
146
lib/RetailCrm/Methods/V5/Customers.php
Normal file
146
lib/RetailCrm/Methods/V5/Customers.php
Normal 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"
|
||||
);
|
||||
}
|
||||
}
|
33
lib/RetailCrm/Methods/V5/Delivery.php
Normal file
33
lib/RetailCrm/Methods/V5/Delivery.php
Normal 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;
|
||||
}
|
33
lib/RetailCrm/Methods/V5/Marketplace.php
Normal file
33
lib/RetailCrm/Methods/V5/Marketplace.php
Normal 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;
|
||||
}
|
131
lib/RetailCrm/Methods/V5/Orders.php
Normal file
131
lib/RetailCrm/Methods/V5/Orders.php
Normal 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]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
33
lib/RetailCrm/Methods/V5/Packs.php
Normal file
33
lib/RetailCrm/Methods/V5/Packs.php
Normal 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;
|
||||
}
|
33
lib/RetailCrm/Methods/V5/References.php
Normal file
33
lib/RetailCrm/Methods/V5/References.php
Normal 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;
|
||||
}
|
59
lib/RetailCrm/Methods/V5/Segments.php
Normal file
59
lib/RetailCrm/Methods/V5/Segments.php
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
33
lib/RetailCrm/Methods/V5/Statistic.php
Normal file
33
lib/RetailCrm/Methods/V5/Statistic.php
Normal 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;
|
||||
}
|
67
lib/RetailCrm/Methods/V5/Stores.php
Normal file
67
lib/RetailCrm/Methods/V5/Stores.php
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
134
lib/RetailCrm/Methods/V5/Tasks.php
Normal file
134
lib/RetailCrm/Methods/V5/Tasks.php
Normal 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"
|
||||
);
|
||||
}
|
||||
}
|
33
lib/RetailCrm/Methods/V5/Telephony.php
Normal file
33
lib/RetailCrm/Methods/V5/Telephony.php
Normal 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;
|
||||
}
|
60
lib/RetailCrm/Methods/V5/Users.php
Normal file
60
lib/RetailCrm/Methods/V5/Users.php
Normal 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]
|
||||
);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
* PHP version 5.4
|
||||
*
|
||||
* Response from retailCRM API
|
||||
*
|
||||
@ -9,7 +9,7 @@
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Response;
|
||||
@ -17,15 +17,16 @@ namespace RetailCrm\Response;
|
||||
use RetailCrm\Exception\InvalidJsonException;
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
* PHP version 5.4
|
||||
*
|
||||
* Response from retailCRM API
|
||||
*
|
||||
* @property mixed success
|
||||
* @category RetailCrm
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
class ApiResponse implements \ArrayAccess
|
||||
{
|
||||
|
@ -10,8 +10,9 @@
|
||||
|
||||
<!-- Dummy values used to provide credentials. No need to change these. -->
|
||||
<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_VERSION" value="v5" />
|
||||
<server name="CRM_USER_ID" value="1" />
|
||||
</php>
|
||||
|
||||
|
@ -1,10 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.4
|
||||
*
|
||||
* Test case 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\Test;
|
||||
|
||||
use RetailCrm\ApiClient;
|
||||
use RetailCrm\Http\Client;
|
||||
|
||||
/**
|
||||
* Class TestCase
|
||||
*
|
||||
* @package RetailCrm\Test
|
||||
*/
|
||||
class TestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
@ -12,15 +29,22 @@ class TestCase extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @param string $url (default: null)
|
||||
* @param string $apiKey (default: null)
|
||||
* @param string $version (default: null)
|
||||
* @param string $site (default: null)
|
||||
*
|
||||
* @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(
|
||||
$url ?: $_SERVER['CRM_URL'],
|
||||
$apiKey ?: $_SERVER['CRM_API_KEY'],
|
||||
$site ?: (isset($_SERVER['CRM_SITE']) ? $_SERVER['CRM_SITE'] : null)
|
||||
$url ?: $configUrl,
|
||||
$apiKey ?: $configKey,
|
||||
$version ?: $configVersion,
|
||||
$site ?: null
|
||||
);
|
||||
}
|
||||
|
||||
@ -32,16 +56,21 @@ class TestCase extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @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(
|
||||
$url ?: $_SERVER['CRM_URL'] . '/api/' . ApiClient::VERSION,
|
||||
array(
|
||||
$url ?: $_SERVER['CRM_API_URL'] . '/api/' . $version,
|
||||
[
|
||||
'apiKey' => array_key_exists('apiKey', $defaultParameters)
|
||||
? $defaultParameters['apiKey']
|
||||
: $_SERVER['CRM_API_KEY']
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,284 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* 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/ApiVersion4
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests;
|
||||
|
||||
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/ApiVersion4
|
||||
*/
|
||||
class ApiClientCustomersTest extends TestCase
|
||||
{
|
||||
const FIRST_NAME = 'Иннокентий';
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
*/
|
||||
public function testCustomersCreate()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$externalId = 'c-create-' . time();
|
||||
|
||||
$response = $client->customersCreate(array(
|
||||
'firstName' => self::FIRST_NAME,
|
||||
'externalId' => $externalId,
|
||||
));
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
$this->assertTrue(is_int($response->getId()));
|
||||
|
||||
return array(
|
||||
'id' => $response->getId(),
|
||||
'externalId' => $externalId,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testCustomersCreateExceptionEmpty()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->customersCreate(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
* @depends testCustomersCreate
|
||||
*/
|
||||
public function testCustomersGet(array $ids)
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->customersGet(678678678);
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
$this->assertFalse($response->isSuccessful());
|
||||
|
||||
$response = $client->customersGet($ids['id'], 'id');
|
||||
$customerById = $response->customer;
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$this->assertEquals(self::FIRST_NAME, $response->customer['firstName']);
|
||||
|
||||
$response = $client->customersGet($ids['externalId'], 'externalId');
|
||||
$this->assertEquals($customerById['id'], $response->customer['id']);
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testCustomersGetException()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->customersGet(678678678, 'asdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
* @depends testCustomersGet
|
||||
*/
|
||||
public function testCustomersEdit(array $ids)
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->customersEdit(
|
||||
array(
|
||||
'id' => 22342134,
|
||||
'lastName' => '12345',
|
||||
),
|
||||
'id'
|
||||
);
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
|
||||
$response = $client->customersEdit(array(
|
||||
'externalId' => $ids['externalId'],
|
||||
'lastName' => '12345',
|
||||
));
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testCustomersEditExceptionEmpty()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->customersEdit(array(), 'asdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testCustomersEditException()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->customersEdit(array('id' => 678678678), 'asdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
*/
|
||||
public function testCustomersList()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->customersList();
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$this->assertTrue(isset($response['customers']));
|
||||
|
||||
$response = $client->customersList(array(), 1, 300);
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertFalse(
|
||||
$response->isSuccessful(),
|
||||
'Pagination error'
|
||||
);
|
||||
|
||||
$response = $client->customersList(array('maxOrdersCount' => 10), 1);
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertTrue(
|
||||
$response->isSuccessful(),
|
||||
'API returns customers list'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testCustomersFixExternalIdsException()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->customersFixExternalIds(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
*/
|
||||
public function testCustomersFixExternalIds()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersCreate(array(
|
||||
'firstName' => 'Aaa111',
|
||||
));
|
||||
$this->assertTrue(
|
||||
$response->isSuccessful(),
|
||||
'Order created'
|
||||
);
|
||||
|
||||
$response = $client->ordersGet($response->id, 'id');
|
||||
$this->assertTrue(
|
||||
$response->isSuccessful(),
|
||||
'Order fetched'
|
||||
);
|
||||
|
||||
$id = $response->order['customer']['id'];
|
||||
$externalId = 'asdf' . time();
|
||||
|
||||
$response = $client->customersFixExternalIds(array(
|
||||
array('id' => $id, 'externalId' => $externalId)
|
||||
));
|
||||
|
||||
$this->assertTrue(
|
||||
$response->isSuccessful(),
|
||||
'Fixed customer ids'
|
||||
);
|
||||
|
||||
$response = $client->customersGet($externalId);
|
||||
$this->assertTrue(
|
||||
$response->isSuccessful(),
|
||||
'Got customer'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$id,
|
||||
$response->customer['id'],
|
||||
'Fixing of customer ids were right'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$externalId,
|
||||
$response->customer['externalId'],
|
||||
'Fixing of customer ids were right'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testCustomersUploadExceptionEmpty()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->customersUpload(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group customers
|
||||
*/
|
||||
public function testCustomersUpload()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$externalIdA = 'upload-a-' . time();
|
||||
$externalIdB = 'upload-b-' . time();
|
||||
|
||||
$response = $client->customersUpload(array(
|
||||
array(
|
||||
'externalId' => $externalIdA,
|
||||
'firstName' => 'Aaa',
|
||||
),
|
||||
array(
|
||||
'externalId' => $externalIdB,
|
||||
'lastName' => 'Bbb',
|
||||
),
|
||||
));
|
||||
$this->assertTrue(
|
||||
$response->isSuccessful(),
|
||||
'Got customer'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$externalIdA,
|
||||
$response->uploadedCustomers[0]['externalId']
|
||||
);
|
||||
$this->assertEquals(
|
||||
$externalIdB,
|
||||
$response->uploadedCustomers[1]['externalId']
|
||||
);
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* 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/ApiVersion4
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests;
|
||||
|
||||
use RetailCrm\Test\TestCase;
|
||||
|
||||
|
||||
class ApiClientMarketplaceTest extends TestCase
|
||||
{
|
||||
const SNAME = 'Marketplace integration';
|
||||
const SCODE = 'integration';
|
||||
|
||||
/**
|
||||
* @group marketplace
|
||||
*/
|
||||
public function testConfigurationEdit()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->marketplaceSettingsEdit(
|
||||
array(
|
||||
'name' => self::SNAME,
|
||||
'code' => self::SCODE,
|
||||
'logo' => 'http://download.retailcrm.pro/logos/setup.svg',
|
||||
'active' => 'true'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
}
|
@ -1,330 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* API client orders test class
|
||||
*
|
||||
* @category RetailCrm
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests;
|
||||
|
||||
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/ApiVersion4
|
||||
*/
|
||||
class ApiClientOrdersTest extends TestCase
|
||||
{
|
||||
const FIRST_NAME = 'Иннокентий';
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
*/
|
||||
public function testOrdersCreate()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$externalId = 'o-create-' . time();
|
||||
|
||||
$response = $client->ordersCreate(array(
|
||||
'firstName' => self::FIRST_NAME,
|
||||
'externalId' => $externalId,
|
||||
));
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
$this->assertTrue(is_int($response->getId()));
|
||||
|
||||
return array(
|
||||
'id' => $response->getId(),
|
||||
'externalId' => $externalId,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testOrdersCreateExceptionEmpty()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersCreate(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
* @depends testOrdersCreate
|
||||
*/
|
||||
public function testOrdersStatuses(array $ids)
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersStatuses();
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(400, $response->getStatusCode());
|
||||
$this->assertFalse($response->isSuccessful());
|
||||
|
||||
$response = $client->ordersStatuses(array(), array('asdf'));
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$orders = $response->orders;
|
||||
$this->assertEquals(0, sizeof($orders));
|
||||
|
||||
$response = $client->ordersStatuses(array(), array($ids['externalId']));
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$orders = $response->orders;
|
||||
$this->assertEquals(1, sizeof($orders));
|
||||
$this->assertEquals('new', $orders[0]['status']);
|
||||
|
||||
$response = $client->ordersStatuses(array($ids['id']), array($ids['externalId']));
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$orders = $response->orders;
|
||||
$this->assertEquals(1, sizeof($orders));
|
||||
|
||||
$response = $client->ordersStatuses(array($ids['id']));
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$orders = $response->orders;
|
||||
$this->assertEquals(1, sizeof($orders));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
* @depends testOrdersCreate
|
||||
*/
|
||||
public function testOrdersGet(array $ids)
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersGet(678678678);
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
$this->assertFalse($response->isSuccessful());
|
||||
|
||||
$response = $client->ordersGet($ids['id'], 'id');
|
||||
$orderById = $response->order;
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$this->assertEquals(self::FIRST_NAME, $response->order['firstName']);
|
||||
|
||||
$response = $client->ordersGet($ids['externalId'], 'externalId');
|
||||
$this->assertEquals($orderById['id'], $response->order['id']);
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testOrdersGetException()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersGet(678678678, 'asdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
* @depends testOrdersGet
|
||||
*/
|
||||
public function testOrdersEdit(array $ids)
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersEdit(
|
||||
array(
|
||||
'id' => 22342134,
|
||||
'lastName' => '12345',
|
||||
),
|
||||
'id'
|
||||
);
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
|
||||
$response = $client->ordersEdit(array(
|
||||
'externalId' => $ids['externalId'],
|
||||
'lastName' => '12345',
|
||||
));
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testOrdersEditExceptionEmpty()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersEdit(array(), 'asdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testOrdersEditException()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersEdit(array('id' => 678678678), 'asdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
*/
|
||||
public function testOrdersHistory()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersHistory();
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
*/
|
||||
public function testOrdersList()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersList();
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$this->assertTrue(isset($response['orders']));
|
||||
|
||||
$response = $client->ordersList(array(), 1, 300);
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertFalse(
|
||||
$response->isSuccessful(),
|
||||
'Pagination error'
|
||||
);
|
||||
|
||||
$response = $client->ordersList(array('paymentStatus' => 'paid'), 1);
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testOrdersFixExternalIdsException()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersFixExternalIds(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
*/
|
||||
public function testOrdersFixExternalIds()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersCreate(array(
|
||||
'firstName' => 'Aaa',
|
||||
));
|
||||
$this->assertTrue(
|
||||
$response->isSuccessful(),
|
||||
'Order created'
|
||||
);
|
||||
|
||||
$id = $response->id;
|
||||
$externalId = 'asdf' . time();
|
||||
|
||||
$response = $client->ordersFixExternalIds(array(
|
||||
array('id' => $id, 'externalId' => $externalId)
|
||||
));
|
||||
|
||||
$this->assertTrue(
|
||||
$response->isSuccessful(),
|
||||
'Fixed order ids'
|
||||
);
|
||||
|
||||
$response = $client->ordersGet($externalId);
|
||||
$this->assertTrue(
|
||||
$response->isSuccessful(),
|
||||
'Got order'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$id,
|
||||
$response->order['id'],
|
||||
'Fixing of order ids were right'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$externalId,
|
||||
$response->order['externalId'],
|
||||
'Fixing of order ids were right'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testOrdersUploadExceptionEmpty()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersUpload(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group orders
|
||||
*/
|
||||
public function testOrdersUpload()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$externalIdA = 'upload-a-' . time();
|
||||
$externalIdB = 'upload-b-' . time();
|
||||
|
||||
$response = $client->ordersUpload(array(
|
||||
array(
|
||||
'externalId' => $externalIdA,
|
||||
'firstName' => 'Aaa',
|
||||
),
|
||||
array(
|
||||
'externalId' => $externalIdB,
|
||||
'lastName' => 'Bbb',
|
||||
),
|
||||
));
|
||||
$this->assertTrue(
|
||||
$response->isSuccessful(),
|
||||
'Got order'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$externalIdA,
|
||||
$response->uploadedOrders[0]['externalId']
|
||||
);
|
||||
$this->assertEquals(
|
||||
$externalIdB,
|
||||
$response->uploadedOrders[1]['externalId']
|
||||
);
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* 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/ApiVersion4
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests;
|
||||
|
||||
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/ApiVersion4
|
||||
*/
|
||||
class ApiClientPacksTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test packs history
|
||||
*
|
||||
* @group packs
|
||||
* @return void
|
||||
*/
|
||||
public function testOrdersPacksHistory()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->ordersPacksHistory();
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->success);
|
||||
$this->assertTrue(
|
||||
isset($response['history']),
|
||||
'API returns orders assembly history'
|
||||
);
|
||||
$this->assertTrue(
|
||||
isset($response['generatedAt']),
|
||||
'API returns generatedAt in orders assembly history'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test packs failed create
|
||||
*
|
||||
* @group packs
|
||||
* @return void
|
||||
*/
|
||||
public function testOrdersPacksCreateFailed()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
$pack = array(
|
||||
'itemId' => 12,
|
||||
'store' => 'test',
|
||||
'quantity' => 2
|
||||
);
|
||||
|
||||
$response = $client->ordersPacksCreate($pack);
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(400, $response->getStatusCode());
|
||||
$this->assertFalse($response->success);
|
||||
}
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* 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/ApiVersion4
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests;
|
||||
|
||||
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/ApiVersion4
|
||||
*/
|
||||
class ApiClientPricesTest extends TestCase
|
||||
{
|
||||
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* ApiClientPricesTest constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->code = 'price-code-a-' . time();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group prices
|
||||
*/
|
||||
public function testUsersGroups()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->usersGroups();
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group prices
|
||||
*/
|
||||
public function testPricesGet()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->pricesTypes();
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group prices
|
||||
*/
|
||||
public function testPricesEdit()
|
||||
{
|
||||
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->pricesEdit(
|
||||
array(
|
||||
'code' => $this->code,
|
||||
'name' => $this->code,
|
||||
'ordering' => 500,
|
||||
'active' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group prices
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testPricesUploadExceptionEmpty()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
$client->storePricesUpload(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group prices
|
||||
*/
|
||||
public function testPricesUpload()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$xmlIdA = 'upload-a-' . time();
|
||||
$xmlIdB = 'upload-b-' . time();
|
||||
|
||||
$response = $client->storePricesUpload(array(
|
||||
array(
|
||||
'xmlId' => $xmlIdA,
|
||||
'prices' => array(
|
||||
array(
|
||||
'code' => $this->code,
|
||||
'price' => 1700
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'xmlId' => $xmlIdB,
|
||||
'prices' => array(
|
||||
array(
|
||||
'code' => $this->code,
|
||||
'price' => 1500
|
||||
)
|
||||
)
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* 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/ApiVersion4
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests;
|
||||
|
||||
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/ApiVersion4
|
||||
*/
|
||||
class ApiClientReferenceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group reference
|
||||
* @dataProvider getListDictionaries
|
||||
* @param $name
|
||||
*/
|
||||
public function testList($name)
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$method = $name . 'List';
|
||||
$response = $client->$method();
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$this->assertTrue(isset($response[$name]));
|
||||
$this->assertTrue(is_array($response[$name]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group reference
|
||||
* @dataProvider getEditDictionaries
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testEditingException($name)
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$method = $name . 'Edit';
|
||||
$response = $client->$method(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group reference
|
||||
* @dataProvider getEditDictionaries
|
||||
*/
|
||||
public function testEditing($name)
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$code = 'dict-' . strtolower($name) . '-' . time();
|
||||
$method = $name . 'Edit';
|
||||
$params = array(
|
||||
'code' => $code,
|
||||
'name' => 'Aaa',
|
||||
);
|
||||
if ($name == 'statuses') {
|
||||
$params['group'] = 'new';
|
||||
}
|
||||
|
||||
$response = $client->$method($params);
|
||||
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||
|
||||
$response = $client->$method(array(
|
||||
'code' => $code,
|
||||
'name' => 'Bbb',
|
||||
));
|
||||
|
||||
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group reference
|
||||
* @group site
|
||||
*/
|
||||
public function testSiteEditing()
|
||||
{
|
||||
$name = 'sites';
|
||||
$client = static::getApiClient();
|
||||
|
||||
$code = 'dict-' . strtolower($name) . '-' . time();
|
||||
$method = $name . 'Edit';
|
||||
$params = array(
|
||||
'code' => $code,
|
||||
'name' => 'Aaa',
|
||||
);
|
||||
|
||||
$response = $client->$method($params);
|
||||
$this->assertEquals(400, $response->getStatusCode());
|
||||
|
||||
if ($code = $client->getSite()) {
|
||||
$method = $name . 'Edit';
|
||||
$params = array(
|
||||
'code' => $code,
|
||||
'name' => 'Aaa' . time(),
|
||||
);
|
||||
|
||||
$response = $client->$method($params);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function getListDictionaries()
|
||||
{
|
||||
return array(
|
||||
array('deliveryServices'),
|
||||
array('deliveryTypes'),
|
||||
array('orderMethods'),
|
||||
array('orderTypes'),
|
||||
array('paymentStatuses'),
|
||||
array('paymentTypes'),
|
||||
array('productStatuses'),
|
||||
array('statusGroups'),
|
||||
array('statuses'),
|
||||
array('sites'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getEditDictionaries()
|
||||
{
|
||||
return array(
|
||||
array('deliveryServices'),
|
||||
array('deliveryTypes'),
|
||||
array('orderMethods'),
|
||||
array('orderTypes'),
|
||||
array('paymentStatuses'),
|
||||
array('paymentTypes'),
|
||||
array('productStatuses'),
|
||||
array('statuses'),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* 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/ApiVersion4
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests;
|
||||
|
||||
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/ApiVersion4
|
||||
*/
|
||||
class ApiClientStoreTest extends TestCase
|
||||
{
|
||||
const SNAME = 'Test Store';
|
||||
const SCODE = 'test-store';
|
||||
|
||||
/**
|
||||
* @group store
|
||||
*/
|
||||
public function testStoreCreate()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->storesEdit(array('name' => self::SNAME, 'code' => self::SCODE));
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group store
|
||||
*/
|
||||
public function testStoreInventories()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->storeInventories();
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
$this->assertTrue(
|
||||
isset($response['offers']),
|
||||
'API returns orders assembly history'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group store
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testStoreInventoriesUploadExceptionEmpty()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
$client->storeInventoriesUpload(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group store
|
||||
*/
|
||||
public function testStoreInventoriesUpload()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$externalIdA = 'upload-a-' . time();
|
||||
$externalIdB = 'upload-b-' . time();
|
||||
|
||||
$response = $client->storeInventoriesUpload(array(
|
||||
array(
|
||||
'externalId' => $externalIdA,
|
||||
'stores' => array(
|
||||
array(
|
||||
'code' => self::SCODE,
|
||||
'available' => 10,
|
||||
'purchasePrice' => 1700
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'externalId' => $externalIdB,
|
||||
'stores' => array(
|
||||
array(
|
||||
'code' => self::SCODE,
|
||||
'available' => 20,
|
||||
'purchasePrice' => 1500
|
||||
)
|
||||
)
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertFalse($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
public function testStoreInventoriesUploadFailed()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$externalIdA = 'upload-a-' . time();
|
||||
$externalIdB = 'upload-b-' . time();
|
||||
|
||||
$response = $client->storeInventoriesUpload(array(
|
||||
array(
|
||||
'externalId' => $externalIdA,
|
||||
'available' => 10,
|
||||
'purchasePrice' => 1700
|
||||
),
|
||||
array(
|
||||
'externalId' => $externalIdB,
|
||||
'available' => 20,
|
||||
'purchasePrice' => 1500
|
||||
),
|
||||
));
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(400, $response->getStatusCode());
|
||||
$this->assertTrue(isset($response['errorMsg']), $response['errorMsg']);
|
||||
}
|
||||
}
|
@ -1,159 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* 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/ApiVersion4
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests;
|
||||
|
||||
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/ApiVersion4
|
||||
*/
|
||||
class ApiClientTelephonyTest extends TestCase
|
||||
{
|
||||
|
||||
const TEL_CODE = 'telephony-code';
|
||||
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();
|
||||
|
||||
$response = $client->telephonySettingsEdit(
|
||||
self::TEL_CODE,
|
||||
self::TEL_CLIENT,
|
||||
true,
|
||||
'TestTelephony',
|
||||
false,
|
||||
self::TEL_IMAGE,
|
||||
array(array('userId' => $_SERVER['CRM_USER_ID'], 'code' => '101')),
|
||||
array(array('siteCode' => 'api-client-php', 'externalPhone' => '+74950000000'))
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings Get test
|
||||
*
|
||||
* @group telephony
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTelephonySettingsGet()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->telephonySettingsGet(self::TEL_CODE);
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* Event test
|
||||
*
|
||||
* @group telephony
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTelephonyEvent()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->telephonyCallEvent(
|
||||
'+79999999999',
|
||||
'in',
|
||||
array('101'),
|
||||
'failed',
|
||||
'+74950000000'
|
||||
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload test
|
||||
*
|
||||
* @group telephony
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTelephonyUpload()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->telephonyCallsUpload(
|
||||
array(
|
||||
array(
|
||||
'date' => '2016-07-22 00:18:00',
|
||||
'type' => 'in',
|
||||
'phone' => '+79999999999',
|
||||
'code' => '101',
|
||||
'result' => 'answered',
|
||||
'externalId' => rand(10,100),
|
||||
'recordUrl' => 'https://dl.dropboxusercontent.com/u/15492750/dontry2bfunny.mp3'
|
||||
),
|
||||
array(
|
||||
'date' => '2016-07-22 00:24:00',
|
||||
'type' => 'in',
|
||||
'phone' => '+79999999999',
|
||||
'code' => '101',
|
||||
'result' => 'answered',
|
||||
'externalId' => rand(10,100),
|
||||
'recordUrl' => 'https://dl.dropboxusercontent.com/u/15492750/donttytobefunny.mp3'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* Manager test
|
||||
*
|
||||
* @group telephony
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTelephonyManager()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->telephonyCallManager('+79999999999', 1);
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
* PHP version 5.4
|
||||
*
|
||||
* API client test class
|
||||
*
|
||||
@ -9,7 +9,7 @@
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests;
|
||||
@ -23,17 +23,17 @@ use RetailCrm\Test\TestCase;
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
class ApiClientTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group unit
|
||||
* @group client
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\ApiClient', $client);
|
||||
static::assertInstanceOf('RetailCrm\ApiClient', $client);
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* 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/ApiVersion4
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests;
|
||||
|
||||
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/ApiVersion4
|
||||
*/
|
||||
class ApiClientUsersTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group users
|
||||
*/
|
||||
public function testUsersList()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->usersList();
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group users
|
||||
*/
|
||||
public function testUsersGet()
|
||||
{
|
||||
$client = static::getApiClient();
|
||||
|
||||
$response = $client->usersGet($_SERVER["CRM_USER_ID"]);
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertTrue(in_array($response->getStatusCode(), array(200, 201)));
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
* PHP version 5.4
|
||||
*
|
||||
* API client test class
|
||||
*
|
||||
@ -9,7 +9,7 @@
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests\Http;
|
||||
@ -25,59 +25,59 @@ use RetailCrm\Http\Client;
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
class ClientTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group unit
|
||||
* @group client
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$client = new Client('https://asdf.df', array());
|
||||
$client = new Client('https://asdf.df', []);
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Http\Client', $client);
|
||||
static::assertInstanceOf('RetailCrm\Http\Client', $client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group client
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group client
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testMakeRequestWrongMethod()
|
||||
public function testRequestWrongMethod()
|
||||
{
|
||||
$client = static::getClient();
|
||||
$client->makeRequest('/a', 'adsf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
* @group client
|
||||
* @expectedException \RetailCrm\Exception\CurlException
|
||||
*/
|
||||
public function testMakeRequestWrongUrl()
|
||||
public function testRequestWrongUrl()
|
||||
{
|
||||
$client = new Client('https://asdf.df', array());
|
||||
$client->makeRequest('/a', Client::METHOD_GET, array());
|
||||
$client = new Client('https://asdf.df', []);
|
||||
$client->makeRequest('/a', Client::METHOD_GET, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
* @group client
|
||||
*/
|
||||
public function testMakeRequestSuccess()
|
||||
public function testRequestSuccess()
|
||||
{
|
||||
$client = static::getClient();
|
||||
$response = $client->makeRequest('/orders', Client::METHOD_GET);
|
||||
|
||||
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
||||
static::assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
@ -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']
|
||||
);
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
332
tests/RetailCrm/Tests/Methods/Version4/ApiClientOrdersTest.php
Normal file
332
tests/RetailCrm/Tests/Methods/Version4/ApiClientOrdersTest.php
Normal 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']
|
||||
);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
114
tests/RetailCrm/Tests/Methods/Version4/ApiClientPricesTest.php
Normal file
114
tests/RetailCrm/Tests/Methods/Version4/ApiClientPricesTest.php
Normal 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());
|
||||
}
|
||||
}
|
@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
146
tests/RetailCrm/Tests/Methods/Version4/ApiClientStoreTest.php
Normal file
146
tests/RetailCrm/Tests/Methods/Version4/ApiClientStoreTest.php
Normal 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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
420
tests/RetailCrm/Tests/Methods/Version5/ApiClientOrdersTest.php
Normal file
420
tests/RetailCrm/Tests/Methods/Version5/ApiClientOrdersTest.php
Normal 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'
|
||||
);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
114
tests/RetailCrm/Tests/Methods/Version5/ApiClientPricesTest.php
Normal file
114
tests/RetailCrm/Tests/Methods/Version5/ApiClientPricesTest.php
Normal 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());
|
||||
}
|
||||
}
|
@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
159
tests/RetailCrm/Tests/Methods/Version5/ApiClientStoreTest.php
Normal file
159
tests/RetailCrm/Tests/Methods/Version5/ApiClientStoreTest.php
Normal 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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
* PHP version 5.4
|
||||
*
|
||||
* API client response test class
|
||||
*
|
||||
@ -9,7 +9,7 @@
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Tests\Response;
|
||||
@ -24,24 +24,24 @@ use RetailCrm\Response\ApiResponse;
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
class ApiResponseTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
*/
|
||||
public function testSuccessConstruct()
|
||||
{
|
||||
$response = new ApiResponse(200);
|
||||
$this->assertInstanceOf(
|
||||
static::assertInstanceOf(
|
||||
'RetailCrm\Response\ApiResponse',
|
||||
$response,
|
||||
'Response object created'
|
||||
);
|
||||
|
||||
$response = new ApiResponse(201, '{ "success": true }');
|
||||
$this->assertInstanceOf(
|
||||
static::assertInstanceOf(
|
||||
'RetailCrm\Response\ApiResponse',
|
||||
$response,
|
||||
'Response object created'
|
||||
@ -49,28 +49,28 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
* @expectedException \RetailCrm\Exception\InvalidJsonException
|
||||
*/
|
||||
public function testJsonInvalid()
|
||||
{
|
||||
$response = new ApiResponse(400, '{ "asdf": }');
|
||||
new ApiResponse(400, '{ "asdf": }');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
*/
|
||||
public function testStatusCodeGetting()
|
||||
{
|
||||
$response = new ApiResponse(200);
|
||||
$this->assertEquals(
|
||||
static::assertEquals(
|
||||
200,
|
||||
$response->getStatusCode(),
|
||||
'Response object returns the right status code'
|
||||
);
|
||||
|
||||
$response = new ApiResponse(460, '{ "success": false }');
|
||||
$this->assertEquals(
|
||||
static::assertEquals(
|
||||
460,
|
||||
$response->getStatusCode(),
|
||||
'Response object returns the right status code'
|
||||
@ -78,38 +78,38 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
*/
|
||||
public function testIsSuccessful()
|
||||
{
|
||||
$response = new ApiResponse(200);
|
||||
$this->assertTrue(
|
||||
static::assertTrue(
|
||||
$response->isSuccessful(),
|
||||
'Request was successful'
|
||||
);
|
||||
|
||||
$response = new ApiResponse(460, '{ "success": false }');
|
||||
$this->assertFalse(
|
||||
static::assertFalse(
|
||||
$response->isSuccessful(),
|
||||
'Request was failed'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
*/
|
||||
public function testMagicCall()
|
||||
{
|
||||
$response = new ApiResponse(201, '{ "success": true }');
|
||||
$this->assertEquals(
|
||||
static::assertEquals(
|
||||
true,
|
||||
$response->getSuccess(),
|
||||
$response->isSuccessful(),
|
||||
'Response object returns property value throw magic method'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testMagicCallException1()
|
||||
@ -119,7 +119,7 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testMagicCallException2()
|
||||
@ -129,12 +129,12 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
*/
|
||||
public function testMagicGet()
|
||||
{
|
||||
$response = new ApiResponse(201, '{ "success": true }');
|
||||
$this->assertEquals(
|
||||
static::assertEquals(
|
||||
true,
|
||||
$response->success,
|
||||
'Response object returns property value throw magic get'
|
||||
@ -142,7 +142,7 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testMagicGetException1()
|
||||
@ -152,7 +152,7 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testMagicGetException2()
|
||||
@ -162,12 +162,12 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
*/
|
||||
public function testArrayGet()
|
||||
{
|
||||
$response = new ApiResponse(201, '{ "success": true }');
|
||||
$this->assertEquals(
|
||||
static::assertEquals(
|
||||
true,
|
||||
$response['success'],
|
||||
'Response object returns property value throw magic array get'
|
||||
@ -175,7 +175,7 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testArrayGetException1()
|
||||
@ -185,7 +185,7 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testArrayGetException2()
|
||||
@ -195,25 +195,25 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
*/
|
||||
public function testArrayIsset()
|
||||
{
|
||||
$response = new ApiResponse(201, '{ "success": true }');
|
||||
|
||||
$this->assertTrue(
|
||||
static::assertTrue(
|
||||
isset($response['success']),
|
||||
'Response object returns property existing'
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
static::assertFalse(
|
||||
isset($response['suess']),
|
||||
'Response object returns property existing'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testArraySetException1()
|
||||
@ -223,7 +223,7 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testArraySetException2()
|
||||
@ -233,7 +233,7 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testArrayUnsetException1()
|
||||
@ -243,7 +243,7 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testArrayUnsetException2()
|
||||
@ -253,18 +253,18 @@ class ApiResponseTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group response
|
||||
*/
|
||||
public function testMagicIsset()
|
||||
{
|
||||
$response = new ApiResponse(201, '{ "success": true }');
|
||||
|
||||
$this->assertTrue(
|
||||
static::assertTrue(
|
||||
isset($response->success),
|
||||
'Response object returns property existing'
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
static::assertFalse(
|
||||
isset($response->suess),
|
||||
'Response object returns property existing'
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user