1
0
mirror of synced 2024-11-22 05:16:07 +03:00

merge master

This commit is contained in:
Alex Lushpai 2021-06-02 16:58:22 +03:00
commit 9fc83d3b8f
89 changed files with 3959 additions and 1317 deletions

41
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,41 @@
name: ci
on:
push:
branches:
- '**'
tags-ignore:
- '*.*'
pull_request:
env:
RETAILCRM_URL: ${{ secrets.RETAILCRM_URL }}
RETAILCRM_KEY: ${{ secrets.RETAILCRM_KEY }}
RETAILCRM_VERSION: ${{ secrets.RETAILCRM_VERSION }}
RETAILCRM_SITE: ${{ secrets.RETAILCRM_SITE }}
RETAILCRM_USER: ${{ secrets.RETAILCRM_USER }}
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.0', '7.1', '7.2', '7.3', '7.4']
steps:
- uses: actions/checkout@v2
- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug
- name: Composer cache
uses: actions/cache@v2
with:
path: ${{ env.HOME }}/.composer/cache
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
- name: Install dependencies
run: composer install -o
- name: Run tests
run: php ./vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist
- name: Coverage
run: bash <(curl -s https://codecov.io/bash)

2
.gitignore vendored
View File

@ -2,6 +2,8 @@
/bin
composer.lock
composer.phar
coverage.xml
test-report.xml
phpunit.xml
.idea
.DS_Store

View File

@ -1,18 +0,0 @@
language: php
cache:
directories:
- $HOME/.composer/cache
php:
- '5.4'
- '5.5'
- '5.6'
- '7.0'
before_script:
- flags="-o"
- composer install $flags
- cp phpunit.xml.dist phpunit.xml
script: phpunit

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2015 RetailDriver LLC
Copyright (c) 2015-2020 RetailDriver LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,13 +1,19 @@
# retailCRM API PHP client
[![Build Status](https://github.com/retailcrm/api-client-php/workflows/ci/badge.svg)](https://github.com/retailcrm/api-client-php/actions)
[![Covarage](https://img.shields.io/codecov/c/gh/retailcrm/api-client-php/master.svg?logo=codecov&logoColor=white)](https://codecov.io/gh/retailcrm/api-client-php)
[![Latest stable](https://img.shields.io/packagist/v/retailcrm/api-client-php.svg)](https://packagist.org/packages/retailcrm/api-client-php)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/retailcrm/api-client-php.svg?logo=php&logoColor=white)](https://packagist.org/packages/retailcrm/api-client-php)
PHP-client for [retailCRM API](http://www.retailcrm.pro/docs/Developers/ApiVersion5).
Use [API documentation](http://retailcrm.github.io/api-client-php)
# RetailCRM API PHP client
This is php RetailCRM API client. This library allows to use all available API versions. [API documentation](http://retailcrm.github.io/api-client-php)
## Requirements
* PHP 5.4 and above
* PHP's cURL support
* PHP's JSON support
* PHP's Fileinfo support
## Install
@ -15,7 +21,7 @@ Use [API documentation](http://retailcrm.github.io/api-client-php)
2) Run into your project directory:
```bash
composer require retailcrm/api-client-php 5.* --no-dev
composer require retailcrm/api-client-php ~5.0
```
If you have not used `composer` before, include autoloader into your project.
@ -28,9 +34,9 @@ require 'path/to/vendor/autoload.php';
### Get order
```php
$client = new \RetailCrm\ApiClient(
'https://demo.retailcrm.ru',
'https://demo.retailcrm.pro',
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
'v5'
\RetailCrm\ApiClient::V5
);
try {
@ -63,21 +69,21 @@ if ($response->isSuccessful()) {
```php
$client = new \RetailCrm\ApiClient(
'https://demo.retailcrm.ru',
'https://demo.retailcrm.pro',
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
'v4'
\RetailCrm\ApiClient::V5
);
try {
$response = $client->request->ordersCreate(array(
'externalId' => 'some-shop-order-id',
'firstName' => 'Vasily',
'lastName' => 'Pupkin',
'firstName' => 'John',
'lastName' => 'Doe',
'items' => array(
//...
),
'delivery' => array(
'code' => 'russian-post',
'code' => 'fedex',
)
));
} catch (\RetailCrm\Exception\CurlException $e) {
@ -85,7 +91,7 @@ try {
}
if ($response->isSuccessful() && 201 === $response->getStatusCode()) {
echo 'Order successfully created. Order ID into retailCRM = ' . $response->id;
echo 'Order successfully created. Order ID into RetailCRM = ' . $response->id;
// or $response['id'];
// or $response->getId();
} else {
@ -101,3 +107,19 @@ if ($response->isSuccessful() && 201 === $response->getStatusCode()) {
//}
}
```
### Set custom headers and client timeout
```php
$client = new \RetailCrm\ApiClient(
'https://demo.retailcrm.pro',
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
\RetailCrm\ApiClient::V5
);
$options = new \RetailCrm\Http\RequestOptions(
['X-Rlimit-Token' => 'example_token'], // array of custom headers
10 // client timeout (in seconds)
);
$client->request->setOptions($options);
```

View File

@ -1,105 +0,0 @@
# PHP-клиент для retailCRM API
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.4 и выше
* PHP-расширение cURL
## Установка
1) Установите [composer](https://getcomposer.org/download/)
2) Выполните в папке проекта:
```bash
composer require retailcrm/api-client-php 5.* --no-dev
```
В конфиг `composer.json` вашего проекта будет добавлена библиотека `retailcrm/api-client-php`, которая установится в папку `vendor/`. При отсутствии файла конфига или папки с вендорами они будут созданы.
В случае, если до этого в вашем проекте не использовался `composer`, подключите файл автозагрузки вендоров. Для этого укажите в коде проекта:
```php
require 'path/to/vendor/autoload.php';
```
## Примеры использования
### Получение информации о заказе
```php
$client = new \RetailCrm\ApiClient(
'https://demo.retailcrm.ru',
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
'v5'
);
try {
$response = $client-request->ordersGet('M-2342');
} catch (\RetailCrm\Exception\CurlException $e) {
echo "Сетевые проблемы. Ошибка подключения к retailCRM: " . $e->getMessage();
}
if ($response->isSuccessful()) {
echo $response->order['totalSumm'];
// или $response['order']['totalSumm'];
// или
// $order = $response->getOrder();
// $order['totalSumm'];
} else {
echo sprintf(
"Ошибка получения информации о заказа: [Статус HTTP-ответа %s] %s",
$response->getStatusCode(),
$response->getErrorMsg()
);
// получить детализацию ошибок
//if (isset($response['errors'])) {
// print_r($response['errors']);
//}
}
```
### Создание заказа
```php
$client = new \RetailCrm\ApiClient(
'https://demo.retailcrm.ru',
'T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH',
'v4'
);
try {
$response = $client-request->ordersCreate(array(
'externalId' => 'some-shop-order-id',
'firstName' => 'Vasily',
'lastName' => 'Pupkin',
'items' => array(
//...
),
'delivery' => array(
'code' => 'russian-post',
)
));
} catch (\RetailCrm\Exception\CurlException $e) {
echo "Сетевые проблемы. Ошибка подключения к retailCRM: " . $e->getMessage();
}
if ($response->isSuccessful() && 201 === $response->getStatusCode()) {
echo 'Заказ успешно создан. ID заказа в retailCRM = ' . $response->id;
// или $response['id'];
// или $response->getId();
} else {
echo sprintf(
"Ошибка создания заказа: [Статус HTTP-ответа %s] %s",
$response->getStatusCode(),
$response->getErrorMsg()
);
// получить детализацию ошибок
//if (isset($response['errors'])) {
// print_r($response['errors']);
//}
}
```

View File

@ -1,31 +0,0 @@
extensions:
- php
source:
- lib
exclude:
- tests/
- vendor/
- bin/
- docs/
charset:
- auto
- UTF-8
- Windows-1251
title: retailCRM PHP API client
templateTheme: bootstrap
groups: auto
accessLevels:
- public
internal: true
php: false
tree: true
deprecated: true
todo: true
destination: ../api-client-php.pages/
download: false

View File

@ -1,26 +1,28 @@
{
"name": "retailcrm/api-client-php",
"description": "PHP client for retailCRM API",
"description": "PHP client for RetailCRM API",
"type": "library",
"keywords": ["API", "retailCRM", "REST"],
"homepage": "http://www.retailcrm.ru/",
"keywords": ["API", "RetailCRM", "REST"],
"homepage": "http://www.retailcrm.pro/",
"license": "MIT",
"authors": [
{
"name": "retailCRM",
"email": "support@retailcrm.ru"
"name": "RetailCRM",
"email": "support@retailcrm.pro"
}
],
"require": {
"php": ">=5.4.0",
"ext-curl": "*"
"ext-curl": "*",
"ext-json": "*",
"ext-fileinfo": "*"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
"phpunit/phpunit": "6.*",
"squizlabs/php_codesniffer": "3.*"
},
"support": {
"email": "support@retailcrm.ru"
"email": "support@retailcrm.pro"
},
"autoload": {
"psr-0": { "RetailCrm\\": "lib/" }
@ -31,7 +33,7 @@
}
},
"config": {
"bin-dir": "bin",
"bin-dir": "vendor/bin",
"process-timeout": 600
}
}

View File

@ -7,9 +7,6 @@
*
* @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;
@ -25,15 +22,16 @@ use RetailCrm\Client\ApiVersion5;
*
* @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 ApiClient
{
public $request;
public $version;
const V3 = 'v3';
const V4 = 'v4';
const V5 = 'v5';
/**
* Init version based client
*
@ -41,21 +39,21 @@ class ApiClient
* @param string $apiKey api key
* @param string $version api version
* @param string $site site code
*
* @param bool $debug debug mode
*/
public function __construct($url, $apiKey, $version = 'v5', $site = null)
public function __construct($url, $apiKey, $version = self::V5, $site = null, $debug = false)
{
$this->version = $version;
switch ($version) {
case 'v5':
$this->request = new ApiVersion5($url, $apiKey, $version, $site);
case self::V4:
$this->request = new ApiVersion4($url, $apiKey, $version, $site, $debug);
break;
case 'v4':
$this->request = new ApiVersion4($url, $apiKey, $version, $site);
case self::V3:
$this->request = new ApiVersion3($url, $apiKey, $version, $site, $debug);
break;
case 'v3':
$this->request = new ApiVersion3($url, $apiKey, $version, $site);
default:
$this->request = new ApiVersion5($url, $apiKey, $version, $site, $debug);
break;
}
}

64
lib/RetailCrm/Client/AbstractLoader.php Normal file → Executable file
View File

@ -3,35 +3,36 @@
/**
* PHP version 5.4
*
* API client class
* Abstract API client
*
* @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;
use RetailCrm\Http\RequestOptions;
/**
* PHP version 5.4
*
* API client class
* Abstract 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
{
/** @var string|null */
protected $siteCode;
/** @var \RetailCrm\Http\Client */
protected $client;
/** @var string */
protected $crmUrl;
/**
* Init version based client
*
@ -39,25 +40,38 @@ abstract class AbstractLoader
* @param string $apiKey api key
* @param string $version api version
* @param string $site site code
* @param bool $debug debug mode
*/
public function __construct($url, $apiKey, $version, $site = null)
public function __construct($url, $apiKey, $version, $site = null, $debug = false)
{
if ('/' !== $url[strlen($url) - 1]) {
$url .= '/';
}
$this->crmUrl = $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'
'Version 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->client = new Client($url, ['apiKey' => $apiKey], $debug);
$this->siteCode = $site;
}
/**
* Set request options
*
* @param RequestOptions $options
*/
public function setOptions(RequestOptions $options)
{
$this->client->setOptions($options);
}
/**
* Set site
*
@ -128,5 +142,33 @@ abstract class AbstractLoader
return $this->siteCode;
}
/**
* Getting the list of available api versions
*
* @return \RetailCrm\Response\ApiResponse
*/
public function availableVersions()
{
return $this->client->makeRequest(
$this->crmUrl . 'api/api-versions',
"GET",
[],
true
);
}
/**
* Getting the list of available api methods and stores for current key
*
* @return \RetailCrm\Response\ApiResponse
*/
public function credentials()
{
return $this->client->makeRequest(
$this->crmUrl . 'api/credentials',
"GET",
[],
true
);
}
}

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* API client class
* API client v3
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V3;
/**
* PHP version 5.4
*
* API client class
* API client v3 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
{
@ -36,11 +30,11 @@ class ApiVersion3 extends AbstractLoader
* @param string $apiKey api key
* @param string $version api version
* @param string $site site code
*
* @param bool $debug debug mode
*/
public function __construct($url, $apiKey, $version, $site)
public function __construct($url, $apiKey, $version, $site, $debug = false)
{
parent::__construct($url, $apiKey, $version, $site);
parent::__construct($url, $apiKey, $version, $site, $debug);
}
use V3\Customers;

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* API client class
* API client v4
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V4;
/**
* PHP version 5.4
*
* API client class
* API client v4 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
{
@ -36,11 +30,11 @@ class ApiVersion4 extends AbstractLoader
* @param string $apiKey api key
* @param string $version api version
* @param string $site site code
*
* @param bool $debug debug mode
*/
public function __construct($url, $apiKey, $version, $site)
public function __construct($url, $apiKey, $version, $site, $debug = false)
{
parent::__construct($url, $apiKey, $version, $site);
parent::__construct($url, $apiKey, $version, $site, $debug);
}
use V4\Customers;
@ -49,6 +43,7 @@ class ApiVersion4 extends AbstractLoader
use V4\Orders;
use V4\Packs;
use V4\References;
use V4\Settings;
use V4\Statistic;
use V4\Stores;
use V4\Telephony;

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* API client class
* API client v5
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V5;
/**
* PHP version 5.4
*
* API client class
* API client v5 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
{
@ -36,24 +30,29 @@ class ApiVersion5 extends AbstractLoader
* @param string $apiKey api key
* @param string $version api version
* @param string $site site code
*
* @param bool $debug debug mode
*/
public function __construct($url, $apiKey, $version, $site)
public function __construct($url, $apiKey, $version, $site, $debug = false)
{
parent::__construct($url, $apiKey, $version, $site);
parent::__construct($url, $apiKey, $version, $site, $debug);
}
use V5\Customers;
use V5\CustomersCorporate;
use V5\Costs;
use V5\CustomFields;
use V5\Delivery;
use V5\Marketplace;
use V5\Files;
use V5\Module;
use V5\Orders;
use V5\Packs;
use V5\References;
use V5\Segments;
use V5\Settings;
use V5\Statistic;
use V5\Stores;
use V5\Tasks;
use V5\Telephony;
use V5\Users;
use V5\IntegrationPayments;
}

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* Class CurlException
* CurlException
*
* @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\Exception;
@ -21,9 +18,6 @@ namespace RetailCrm\Exception;
*
* @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 CurlException extends \RuntimeException
{

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* Class InvalidJsonException
* InvalidJsonException
*
* @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\Exception;
@ -21,9 +18,6 @@ namespace RetailCrm\Exception;
*
* @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 InvalidJsonException extends \DomainException
{

View File

@ -0,0 +1,24 @@
<?php
/**
* PHP version 5.4
*
* Class LimitException
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Exception;
/**
* PHP version 5.4
*
* Class LimitException
*
* @category RetailCrm
* @package RetailCrm
*/
class LimitException extends \DomainException
{
}

View File

@ -0,0 +1,24 @@
<?php
/**
* PHP version 5.4
*
* Class LimitException
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Exception;
/**
* PHP version 5.4
*
* Class NotFoundException
*
* @category RetailCrm
* @package RetailCrm
*/
class NotFoundException extends \DomainException
{
}

105
lib/RetailCrm/Http/Client.php Normal file → Executable file
View File

@ -7,15 +7,14 @@
*
* @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\Http;
use RetailCrm\Exception\CurlException;
use RetailCrm\Exception\InvalidJsonException;
use RetailCrm\Exception\LimitException;
use RetailCrm\Exception\NotFoundException;
use RetailCrm\Response\ApiResponse;
/**
@ -25,9 +24,6 @@ use RetailCrm\Response\ApiResponse;
*
* @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 Client
{
@ -36,18 +32,20 @@ class Client
protected $url;
protected $defaultParameters;
protected $options;
/**
* Client constructor.
*
* @param string $url api url
* @param array $defaultParameters array of parameters
* @param bool $debug debug mode
*
* @throws \InvalidArgumentException
*/
public function __construct($url, array $defaultParameters = [])
public function __construct($url, array $defaultParameters = [], $debug = false)
{
if (false === stripos($url, 'https://')) {
if (false === stripos($url, 'https://') && false === $debug) {
throw new \InvalidArgumentException(
'API schema requires HTTPS protocol'
);
@ -55,6 +53,7 @@ class Client
$this->url = $url;
$this->defaultParameters = $defaultParameters;
$this->options = new RequestOptions();
}
/**
@ -63,6 +62,7 @@ class Client
* @param string $path request url
* @param string $method (default: 'GET')
* @param array $parameters (default: array())
* @param bool $fullPath (default: false)
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*
@ -72,10 +72,11 @@ class Client
*
* @return ApiResponse
*/
public function makeRequest(
public function makeRawRequest(
$path,
$method,
array $parameters = []
array $parameters = [],
$fullPath = false
) {
$allowedMethods = [self::METHOD_GET, self::METHOD_POST];
@ -91,12 +92,16 @@ class Client
$parameters = array_merge($this->defaultParameters, $parameters);
$url = $this->url . $path;
$url = $fullPath ? $path : $this->url . $path;
if (self::METHOD_GET === $method && count($parameters)) {
$url .= '?' . http_build_query($parameters, '', '&');
}
if (self::METHOD_POST === $method && '/files/upload' == $path) {
$url .= '?apiKey=' . $parameters['apiKey'];
}
$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_URL, $url);
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
@ -104,16 +109,86 @@ class Client
curl_setopt($curlHandler, CURLOPT_FAILONERROR, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curlHandler, CURLOPT_TIMEOUT, 30);
curl_setopt($curlHandler, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curlHandler, CURLOPT_TIMEOUT, $this->options->getClientTimeout());
curl_setopt($curlHandler, CURLOPT_CONNECTTIMEOUT, $this->options->getClientTimeout());
if ($this->options->getHeaders()) {
curl_setopt($curlHandler, CURLOPT_HTTPHEADER, $this->options->getHttpHeaders());
}
if (self::METHOD_POST === $method) {
curl_setopt($curlHandler, CURLOPT_POST, true);
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $parameters);
if ('/files/upload' == $path) {
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, file_get_contents($parameters['file']));
} else {
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $parameters);
}
}
list($statusCode, $responseBody) = $this->checkResponse($curlHandler, $method);
return new ApiResponse($statusCode, $responseBody);
}
/**
* Make HTTP request and deserialize JSON body (throws exception otherwise)
*
* @param string $path request url
* @param string $method (default: 'GET')
* @param array $parameters (default: array())
* @param bool $fullPath (default: false)
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*
* @throws \InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
*
* @return ApiResponse
*/
public function makeRequest(
$path,
$method,
array $parameters = [],
$fullPath = false
) {
return $this->makeRawRequest($path, $method, $parameters, $fullPath)->asJsonResponse();
}
/**
* Set request options
*
* @param RequestOptions $options
*/
public function setOptions(RequestOptions $options)
{
$this->options = $options;
}
/**
* @param $curlHandler
* @param $method
*
* @return array
*/
private function checkResponse($curlHandler, $method)
{
$responseBody = curl_exec($curlHandler);
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
$contentType = curl_getinfo($curlHandler, CURLINFO_CONTENT_TYPE);
if (503 === $statusCode) {
throw new LimitException("Service temporary unavailable");
}
if (
(404 === $statusCode && false !== stripos($responseBody, 'Account does not exist'))
|| ('GET' !== $method && 405 === $statusCode && false !== stripos($contentType, 'text/html'))
) {
throw new NotFoundException("Account does not exist");
}
$errno = curl_errno($curlHandler);
$error = curl_error($curlHandler);
@ -123,6 +198,6 @@ class Client
throw new CurlException($error, $errno);
}
return new ApiResponse($statusCode, $responseBody);
return [$statusCode, $responseBody];
}
}

View File

@ -0,0 +1,95 @@
<?php
/**
* PHP version 5.4
*
* Request options
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Http;
/**
* PHP version 5.4
*
* Request options class
*
* @category RetailCrm
* @package RetailCrm
*/
class RequestOptions
{
/** @var array */
private $headers;
/** @var int */
private $clientTimeout;
/**
* Init request options.
*
* @param array $headers
* @param int $clientTimeout
*/
public function __construct($headers = array(), $clientTimeout = 30)
{
$this->headers = $headers;
$this->clientTimeout = $clientTimeout;
}
/**
* @return array
*/
public function getHeaders()
{
return $this->headers;
}
/**
* @return array
*/
public function getHttpHeaders()
{
$headers = [];
foreach ($this->headers as $header => $value) {
$headers[] = sprintf("%s: %s", $header, $value);
}
return $headers;
}
/**
* @param array $headers
*
* @return self
*/
public function setHeaders($headers)
{
$this->headers = $headers;
return $this;
}
/**
* @return int
*/
public function getClientTimeout()
{
return $this->clientTimeout;
}
/**
* @param int $clientTimeout
*
* @return self
*/
public function setClientTimeout($clientTimeout)
{
$this->clientTimeout = $clientTimeout;
return $this;
}
}

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Customers
*
* @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;
@ -17,13 +14,10 @@ namespace RetailCrm\Methods\V3;
/**
* PHP version 5.4
*
* TaskTrait class
* Customers 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
{
@ -54,6 +48,7 @@ trait Customers
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers',
"GET",
@ -81,6 +76,7 @@ trait Customers
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers/create',
"POST",
@ -107,6 +103,7 @@ trait Customers
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers/fix-external-ids',
"POST",
@ -134,6 +131,7 @@ trait Customers
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers/upload',
"POST",
@ -158,6 +156,7 @@ trait Customers
{
$this->checkIdParameter($by);
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/customers/$id",
"GET",
@ -194,6 +193,7 @@ trait Customers
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/customers/%s/edit', $customer[$by]),
"POST",

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Orders
*
* @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;
@ -17,13 +14,10 @@ namespace RetailCrm\Methods\V3;
/**
* PHP version 5.4
*
* TaskTrait class
* Orders 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
{
@ -55,6 +49,7 @@ trait Orders
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders',
"GET",
@ -82,6 +77,7 @@ trait Orders
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/create',
"POST",
@ -108,6 +104,7 @@ trait Orders
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/fix-external-ids',
"POST",
@ -139,6 +136,7 @@ trait Orders
$parameters['externalIds'] = $externalIds;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/statuses',
"GET",
@ -166,6 +164,7 @@ trait Orders
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/upload',
"POST",
@ -190,6 +189,7 @@ trait Orders
{
$this->checkIdParameter($by);
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/orders/$id",
"GET",
@ -226,6 +226,7 @@ trait Orders
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/orders/%s/edit', $order[$by]),
"POST",
@ -258,6 +259,7 @@ trait Orders
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/history',
"GET",

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Packs
*
* @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;
@ -17,13 +14,10 @@ namespace RetailCrm\Methods\V3;
/**
* PHP version 5.4
*
* TaskTrait class
* Packs 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
{
@ -54,6 +48,7 @@ trait Packs
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/packs',
"GET",
@ -81,6 +76,7 @@ trait Packs
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/packs/create',
"POST",
@ -115,6 +111,7 @@ trait Packs
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/packs/history',
"GET",
@ -139,6 +136,7 @@ trait Packs
throw new \InvalidArgumentException('Parameter `id` must be set');
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/orders/packs/$id",
"GET"
@ -162,6 +160,7 @@ trait Packs
throw new \InvalidArgumentException('Parameter `id` must be set');
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/orders/packs/%s/delete', $id),
"POST"
@ -188,6 +187,7 @@ trait Packs
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/orders/packs/%s/edit', $pack['id']),
"POST",

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* References
*
* @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;
@ -17,13 +14,10 @@ namespace RetailCrm\Methods\V3;
/**
* PHP version 5.4
*
* TaskTrait class
* References 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
{
@ -38,6 +32,7 @@ trait References
*/
public function countriesList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/countries',
"GET"
@ -55,6 +50,7 @@ trait References
*/
public function deliveryServicesList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/delivery-services',
"GET"
@ -80,6 +76,7 @@ trait References
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/delivery-services/%s/edit', $data['code']),
"POST",
@ -98,6 +95,7 @@ trait References
*/
public function deliveryTypesList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/delivery-types',
"GET"
@ -123,6 +121,7 @@ trait References
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/delivery-types/%s/edit', $data['code']),
"POST",
@ -141,6 +140,7 @@ trait References
*/
public function orderMethodsList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/order-methods',
"GET"
@ -166,6 +166,7 @@ trait References
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/order-methods/%s/edit', $data['code']),
"POST",
@ -184,6 +185,7 @@ trait References
*/
public function orderTypesList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/order-types',
"GET"
@ -209,6 +211,7 @@ trait References
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/order-types/%s/edit', $data['code']),
"POST",
@ -227,6 +230,7 @@ trait References
*/
public function paymentStatusesList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/payment-statuses',
"GET"
@ -252,6 +256,7 @@ trait References
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/payment-statuses/%s/edit', $data['code']),
"POST",
@ -270,6 +275,7 @@ trait References
*/
public function paymentTypesList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/payment-types',
"GET"
@ -295,6 +301,7 @@ trait References
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/payment-types/%s/edit', $data['code']),
"POST",
@ -313,6 +320,7 @@ trait References
*/
public function productStatusesList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/product-statuses',
"GET"
@ -338,6 +346,7 @@ trait References
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/product-statuses/%s/edit', $data['code']),
"POST",
@ -356,6 +365,7 @@ trait References
*/
public function sitesList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/sites',
"GET"
@ -381,6 +391,7 @@ trait References
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/sites/%s/edit', $data['code']),
"POST",
@ -399,6 +410,7 @@ trait References
*/
public function statusGroupsList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/status-groups',
"GET"
@ -416,6 +428,7 @@ trait References
*/
public function statusesList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/statuses',
"GET"
@ -441,6 +454,7 @@ trait References
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/statuses/%s/edit', $data['code']),
"POST",
@ -459,6 +473,7 @@ trait References
*/
public function storesList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/stores',
"GET"
@ -490,6 +505,7 @@ trait References
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/stores/%s/edit', $data['code']),
"POST",

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* Statistic class
* Statistic
*
* @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;
@ -21,9 +18,6 @@ namespace RetailCrm\Methods\V3;
*
* @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
{
@ -38,6 +32,7 @@ trait Statistic
*/
public function statisticUpdate()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/statistic/update',
"GET"

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Stores
*
* @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;
@ -17,13 +14,10 @@ namespace RetailCrm\Methods\V3;
/**
* PHP version 5.4
*
* TaskTrait class
* Stores 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
{
@ -54,6 +48,7 @@ trait Stores
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/store/inventories',
"GET",
@ -81,6 +76,7 @@ trait Stores
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/store/inventories/upload',
"POST",

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ namespace RetailCrm\Methods\V3;
*
* @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
{
@ -44,6 +38,7 @@ trait Telephony
throw new \InvalidArgumentException('Parameter `code` must be set');
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/telephony/setting/$code",
"GET"
@ -54,24 +49,29 @@ trait Telephony
* Call event
*
* @param string $phone phone number
* @param string $type call type
* @param string $type call type
* @param array $codes
* @param array $userIds
* @param string $callExternalId
* @param string $hangupStatus
* @param string $externalPhone
* @param array $webAnalyticsData
* @param string $site (default: null)
*
* @return \RetailCrm\Response\ApiResponse
* @internal param string $code additional phone code
* @internal param string $status call status
*
*/
public function telephonyCallEvent(
$phone,
$type,
$codes,
$hangupStatus,
$userIds = [],
$hangupStatus = null,
$externalPhone = null,
$webAnalyticsData = []
$callExternalId = null,
$webAnalyticsData = [],
$site = null
) {
if (!isset($phone)) {
throw new \InvalidArgumentException('Phone number must be set');
@ -88,30 +88,34 @@ trait Telephony
$parameters['phone'] = $phone;
$parameters['type'] = $type;
$parameters['codes'] = $codes;
if (!empty($userIds)) {
$parameters['userIds'] = $userIds;
}
$parameters['hangupStatus'] = $hangupStatus;
$parameters['callExternalId'] = $externalPhone;
$parameters['callExternalId'] = $callExternalId;
$parameters['externalPhone'] = $externalPhone;
$parameters['webAnalyticsData'] = $webAnalyticsData;
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/telephony/call/event',
"POST",
['event' => json_encode($parameters)]
['event' => json_encode($this->fillSite($site, $parameters))]
);
}
/**
* Upload calls
*
* @param array $calls calls data
* @param array $calls calls data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
* @param bool $autoFillSite fill site code from API client in provided calls
*
* @return \RetailCrm\Response\ApiResponse
*/
public function telephonyCallsUpload(array $calls)
public function telephonyCallsUpload(array $calls, $autoFillSite = false)
{
if (!count($calls)) {
throw new \InvalidArgumentException(
@ -119,6 +123,13 @@ trait Telephony
);
}
if ($autoFillSite) {
foreach ($calls as $key => $call) {
$calls[$key] = $this->fillSite(null, $call);
}
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/telephony/calls/upload',
"POST",
@ -147,6 +158,7 @@ trait Telephony
$parameters['phone'] = $phone;
$parameters['details'] = isset($details) ? $details : 0;
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/telephony/manager',
"GET",

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Customers
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V3\Customers as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* Customers 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
{
@ -53,6 +47,7 @@ trait Customers
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers/history',
"GET",

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Delivery
*
* @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;
@ -17,13 +14,10 @@ namespace RetailCrm\Methods\V4;
/**
* PHP version 5.4
*
* TaskTrait class
* Delivery 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
{
@ -44,38 +38,13 @@ trait Delivery
throw new \InvalidArgumentException('Parameter `code` must be set');
}
/* @noinspection PhpUndefinedMethodInspection */
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
*
@ -100,6 +69,7 @@ trait Delivery
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/delivery/generic/%s/tracking', $code),
"POST",

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ namespace RetailCrm\Methods\V4;
*
* @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
{
@ -47,6 +41,7 @@ trait Marketplace
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/marketplace/external/setting/%s/edit', $configuration['code']),
"POST",

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Orders
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V3\Orders as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* Orders 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
{
@ -59,6 +53,7 @@ trait Orders
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders',
"GET",
@ -86,6 +81,7 @@ trait Orders
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/create',
"POST",
@ -112,6 +108,8 @@ trait Orders
);
}
/** @noinspection PhpUndefinedMethodInspection */
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/fix-external-ids',
"POST",
@ -143,6 +141,7 @@ trait Orders
$parameters['externalIds'] = $externalIds;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/statuses',
"GET",
@ -170,6 +169,7 @@ trait Orders
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/upload',
"POST",
@ -194,6 +194,7 @@ trait Orders
{
$this->checkIdParameter($by);
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/orders/$id",
"GET",
@ -230,6 +231,7 @@ trait Orders
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/orders/%s/edit', $order[$by]),
"POST",
@ -242,9 +244,14 @@ trait Orders
/**
* Get orders history
* @param array $filter
* @param null $page
* @param null $limit
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
@ -262,6 +269,7 @@ trait Orders
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/history',
"GET",

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Packs
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V3\Packs as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* Packs 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
{

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* References
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V3\References as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* References 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
{
@ -41,6 +35,7 @@ trait References
*/
public function pricesTypes()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/price-types',
"GET"
@ -72,6 +67,7 @@ trait References
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/price-types/%s/edit', $data['code']),
"POST",

View File

@ -0,0 +1,183 @@
<?php
/**
* PHP version 5.4
*
* Settings
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Methods\V4;
/**
* PHP version 5.4
*
* Settings class
*
* @category RetailCrm
* @package RetailCrm
*/
trait Settings
{
/**
* 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'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/store/setting/%s/edit', $configuration['code']),
"POST",
['configuration' => json_encode($configuration)]
);
}
/**
* 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;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/telephony/setting/$code/edit",
"POST",
['configuration' => json_encode($parameters)]
);
}
/**
* 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'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/delivery/generic/setting/%s/edit', $configuration['code']),
"POST",
['configuration' => json_encode($configuration)]
);
}
}

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Statistic
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V3\Statistic as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* 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
{

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Stores
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V3\Stores as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* Stores 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
{
@ -49,37 +43,13 @@ trait Stores
throw new \InvalidArgumentException('Parameter `code` must be set');
}
/* @noinspection PhpUndefinedMethodInspection */
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
@ -101,6 +71,7 @@ trait Stores
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/store/prices/upload',
"POST",
@ -135,6 +106,7 @@ trait Stores
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/store/products',
"GET",

View File

@ -7,9 +7,6 @@
*
* @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;
@ -23,115 +20,8 @@ use RetailCrm\Methods\V3\Telephony as Previous;
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
trait Telephony
{
use Previous;
/**
* Edit telephony settings
*
* @param string $code symbolic code
* @param string $clientId client id
* @param boolean $active telephony activity
* @param mixed $name service name
* @param mixed $makeCallUrl service init url
* @param mixed $image service logo url(svg file)
*
* @param array $additionalCodes
* @param array $externalPhones
* @param bool $allowEdit
* @param bool $inputEventSupported
* @param bool $outputEventSupported
* @param bool $hangupEventSupported
* @param bool $changeUserStatusUrl
*
* @return \RetailCrm\Response\ApiResponse
*/
public function telephonySettingsEdit(
$code,
$clientId,
$active = false,
$name = false,
$makeCallUrl = false,
$image = false,
$additionalCodes = [],
$externalPhones = [],
$allowEdit = false,
$inputEventSupported = false,
$outputEventSupported = false,
$hangupEventSupported = false,
$changeUserStatusUrl = false
) {
if (!isset($code)) {
throw new \InvalidArgumentException('Code must be set');
}
$parameters['code'] = $code;
if (!isset($clientId)) {
throw new \InvalidArgumentException('client id must be set');
}
$parameters['clientId'] = $clientId;
if (!isset($active)) {
$parameters['active'] = false;
} else {
$parameters['active'] = $active;
}
if (!isset($name)) {
throw new \InvalidArgumentException('name must be set');
}
if (isset($name)) {
$parameters['name'] = $name;
}
if (isset($makeCallUrl)) {
$parameters['makeCallUrl'] = $makeCallUrl;
}
if (isset($image)) {
$parameters['image'] = $image;
}
if (isset($additionalCodes)) {
$parameters['additionalCodes'] = $additionalCodes;
}
if (isset($externalPhones)) {
$parameters['externalPhones'] = $externalPhones;
}
if (isset($allowEdit)) {
$parameters['allowEdit'] = $allowEdit;
}
if (isset($inputEventSupported)) {
$parameters['inputEventSupported'] = $inputEventSupported;
}
if (isset($outputEventSupported)) {
$parameters['outputEventSupported'] = $outputEventSupported;
}
if (isset($hangupEventSupported)) {
$parameters['hangupEventSupported'] = $hangupEventSupported;
}
if (isset($changeUserStatusUrl)) {
$parameters['changeUserStatusUrl'] = $changeUserStatusUrl;
}
return $this->client->makeRequest(
"/telephony/setting/$code/edit",
"POST",
['configuration' => json_encode($parameters)]
);
}
}

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Users
*
* @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;
@ -17,13 +14,10 @@ namespace RetailCrm\Methods\V4;
/**
* PHP version 5.4
*
* TaskTrait class
* Users 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
{

View File

@ -0,0 +1,216 @@
<?php
/**
* PHP version 5.4
*
* CostsTrait
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Methods\V5;
/**
* PHP version 5.4
*
* CostsTrait class
*
* @category RetailCrm
* @package RetailCrm
*/
trait Costs
{
/**
* Returns filtered costs 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 costsList(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;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/costs',
"GET",
$parameters
);
}
/**
* Create a cost
*
* @param array $cost cost data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function costsCreate(array $cost, $site = null)
{
if (!count($cost)) {
throw new \InvalidArgumentException(
'Parameter `cost` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/costs/create',
"POST",
$this->fillSite($site, ['cost' => json_encode($cost)])
);
}
/**
* Delete costs set
*
* @param array $ids costs identifiers
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function costsDelete(array $ids)
{
if (!count($ids)) {
throw new \InvalidArgumentException(
'Parameter `ids` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/costs/delete',
"POST",
['ids' => json_encode($ids)]
);
}
/**
* Upload costs
*
* @param array $costs costs array
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function costsUpload($costs)
{
if (!count($costs)) {
throw new \InvalidArgumentException(
'Parameter `costs` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/costs/upload',
"POST",
['costs' => json_encode($costs)]
);
}
/**
* Get cost by id
*
* @param string $id customer identificator
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function costsGet($id)
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/costs/$id",
"GET"
);
}
/**
* Edit a cost
*
* @param array $cost cost data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function costsEdit(array $cost, $site = null)
{
if (!count($cost)) {
throw new \InvalidArgumentException(
'Parameter `cost` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/costs/%s/edit', $cost['id']),
"POST",
$this->fillSite(
$site,
['cost' => json_encode($cost)]
)
);
}
/**
* Delete cost by id
*
* @param string $id cost identifier
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function costsDeleteById($id)
{
if (!empty($id)) {
throw new \InvalidArgumentException(
'Parameter `id` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/costs/%s/delete', $id),
"POST"
);
}
}

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ namespace RetailCrm\Methods\V5;
*
* @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
{
@ -50,6 +44,7 @@ trait CustomFields
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/custom-fields',
"GET",
@ -77,12 +72,16 @@ trait CustomFields
);
}
if (empty($entity) || $entity != 'customer' || $entity != 'order') {
if (empty($entity) || !in_array($entity, ['customer', 'order', 'customer_corporate', 'company'])) {
throw new \InvalidArgumentException(
'Parameter `entity` must contain a data & value must be `order` or `customer`'
sprintf(
'Parameter `entity` must contain a data & value must be %s',
'`order`, `customer`, `customer_corporate` or `company`'
)
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/custom-fields/$entity/create",
"POST",
@ -106,14 +105,18 @@ trait CustomFields
);
}
if (empty($entity) || $entity != 'customer' || $entity != 'order') {
if (empty($entity) || !in_array($entity, ['customer', 'order', 'customer_corporate', 'company'])) {
throw new \InvalidArgumentException(
'Parameter `entity` must contain a data & value must be `order` or `customer`'
sprintf(
'Parameter `entity` must contain a data & value must be %s',
'`order`, `customer`, `customer_corporate` or `company`'
)
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/custom-fields/$entity/edit/{$customField['code']}",
"/custom-fields/$entity/{$customField['code']}/edit",
"POST",
['customField' => json_encode($customField)]
);
@ -135,12 +138,16 @@ trait CustomFields
);
}
if (empty($entity) || $entity != 'customer' || $entity != 'order') {
if (empty($entity) || !in_array($entity, ['customer', 'order', 'customer_corporate', 'company'])) {
throw new \InvalidArgumentException(
'Parameter `entity` must contain a data & value must be `order` or `customer`'
sprintf(
'Parameter `entity` must contain a data & value must be %s',
'`order`, `customer`, `customer_corporate` or `company`'
)
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/custom-fields/$entity/$code",
"GET"
@ -170,6 +177,7 @@ trait CustomFields
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/custom-fields/dictionaries',
"GET",
@ -195,8 +203,9 @@ trait CustomFields
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/custom-fields/dictionaries/{$customDictionary['code']}/create",
"/custom-fields/dictionaries/create",
"POST",
['customDictionary' => json_encode($customDictionary)]
);
@ -220,6 +229,7 @@ trait CustomFields
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/custom-fields/dictionaries/{$customDictionary['code']}/edit",
"POST",
@ -242,6 +252,7 @@ trait CustomFields
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/custom-fields/dictionaries/$code",
"GET"

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Customers
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V4\Customers as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* Customers 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
{
@ -48,6 +42,7 @@ trait Customers
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers/combine',
"POST",
@ -85,6 +80,7 @@ trait Customers
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers/notes',
"GET",
@ -112,15 +108,16 @@ trait Customers
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers/notes/create',
"POST",
['note' => json_encode($note)]
$this->fillSite($site, ['note' => json_encode($note)])
);
}
/**
* Create customer note
* Delete customer note
*
* @param integer $id
*
@ -138,6 +135,7 @@ trait Customers
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/customers/notes/$id/delete",
"POST"

View File

@ -0,0 +1,656 @@
<?php
/**
* PHP version 5.4
*
* CustomersCorporate
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Methods\V5;
/**
* PHP version 5.4
*
* CustomersCorporate class
*
* @category RetailCrm
* @package RetailCrm
*/
trait CustomersCorporate
{
/**
* Returns filtered corporate 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 customersCorporateList(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(
'/customers-corporate',
"GET",
$parameters
);
}
/**
* Create a corporate customer
*
* @param array $customerCorporate corporate customer data
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCorporateCreate(array $customerCorporate, $site = null)
{
if (! count($customerCorporate)) {
throw new \InvalidArgumentException(
'Parameter `customerCorporate` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers-corporate/create',
"POST",
$this->fillSite($site, ['customerCorporate' => json_encode($customerCorporate)])
);
}
/**
* Save corporate 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 customersCorporateFixExternalIds(array $ids)
{
if (! count($ids)) {
throw new \InvalidArgumentException(
'Method parameter must contains at least one IDs pair'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers-corporate/fix-external-ids',
"POST",
['customersCorporate' => json_encode($ids)]
);
}
/**
* Get corporate customers history
* @param array $filter
* @param null $page
* @param null $limit
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCorporateHistory(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(
'/customers-corporate/history',
"GET",
$parameters
);
}
/**
* Returns filtered corporate 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 customersCorporateNotesList(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(
'/customers-corporate/notes',
"GET",
$parameters
);
}
/**
* Create corporate 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 customersCorporateNotesCreate($note, $site = null)
{
if (empty($note['customer']['id']) && empty($note['customer']['externalId'])) {
throw new \InvalidArgumentException(
'Customer identifier must be set'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers-corporate/notes/create',
"POST",
$this->fillSite($site, ['note' => json_encode($note)])
);
}
/**
* Delete corporate customer note
*
* @param integer $id
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCorporateNotesDelete($id)
{
if (empty($id)) {
throw new \InvalidArgumentException(
'Note id must be set'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/customers-corporate/notes/$id/delete",
"POST"
);
}
/**
* Upload array of the corporate customers
*
* @param array $customersCorporate array of corporate customers
* @param string $site (default: null)
*
* @return \RetailCrm\Response\ApiResponse
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @throws \InvalidArgumentException
*/
public function customersCorporateUpload(array $customersCorporate, $site = null)
{
if (!count($customersCorporate)) {
throw new \InvalidArgumentException(
'Parameter `customersCorporate` must contains array of the corporate customers'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/customers-corporate/upload',
"POST",
$this->fillSite($site, ['customersCorporate' => json_encode($customersCorporate)])
);
}
/**
* Get corporate customer by id or externalId
*
* @param string $id corporate customer identifier
* @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 customersCorporateGet($id, $by = 'externalId', $site = null)
{
$this->checkIdParameter($by);
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/customers-corporate/$id",
"GET",
$this->fillSite($site, ['by' => $by])
);
}
/**
* Get corporate customer addresses by id or externalId
*
* @param string $id corporate customer identifier
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
* @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 customersCorporateAddresses(
$id,
array $filter = [],
$page = null,
$limit = null,
$by = 'externalId',
$site = null
) {
$this->checkIdParameter($by);
$parameters = ['by' => $by];
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(
"/customers-corporate/$id/addresses",
"GET",
$this->fillSite($site, $parameters)
);
}
/**
* Create corporate customer address
*
* @param string $id corporate customer identifier
* @param array $address (default: array())
* @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 customersCorporateAddressesCreate($id, array $address = [], $by = 'externalId', $site = null)
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/customers-corporate/$id/addresses/create",
"POST",
$this->fillSite($site, ['address' => json_encode($address), 'by' => $by])
);
}
/**
* Edit corporate customer address
*
* @param string $customerId corporate customer identifier
* @param string $addressId corporate customer identifier
* @param array $address (default: array())
* @param string $customerBy (default: 'externalId')
* @param string $addressBy (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCorporateAddressesEdit(
$customerId,
$addressId,
array $address = [],
$customerBy = 'externalId',
$addressBy = 'externalId',
$site = null
) {
$addressFiltered = array_filter($address);
if ((count(array_keys($addressFiltered)) <= 1)
&& (!isset($addressFiltered['text'])
|| (isset($addressFiltered['text']) && empty($addressFiltered['text']))
)
) {
throw new \InvalidArgumentException(
'Parameter `address` must contain address text or all other address field'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/customers-corporate/$customerId/addresses/$addressId/edit",
"POST",
$this->fillSite($site, [
'address' => json_encode($address),
'by' => $customerBy,
'entityBy' => $addressBy
])
);
}
/**
* Get corporate customer companies by id or externalId
*
* @param string $id corporate customer identifier
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
* @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 customersCorporateCompanies(
$id,
array $filter = [],
$page = null,
$limit = null,
$by = 'externalId',
$site = null
) {
$this->checkIdParameter($by);
$parameters = ['by' => $by];
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(
"/customers-corporate/$id/companies",
"GET",
$this->fillSite($site, $parameters)
);
}
/**
* Create corporate customer company
*
* @param string $id corporate customer identifier
* @param array $company (default: array())
* @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 customersCorporateCompaniesCreate($id, array $company = [], $by = 'externalId', $site = null)
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/customers-corporate/$id/companies/create",
"POST",
$this->fillSite($site, ['company' => json_encode($company), 'by' => $by])
);
}
/**
* Edit corporate customer company
*
* @param string $customerId corporate customer identifier
* @param string $companyId corporate customer identifier
* @param array $company (default: array())
* @param string $customerBy (default: 'externalId')
* @param string $companyBy (default: 'externalId')
* @param string $site (default: null)
*
* @return \RetailCrm\Response\ApiResponse
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
*/
public function customersCorporateCompaniesEdit(
$customerId,
$companyId,
array $company = [],
$customerBy = 'externalId',
$companyBy = 'externalId',
$site = null
) {
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/customers-corporate/$customerId/companies/$companyId/edit",
"POST",
$this->fillSite($site, [
'company' => json_encode($company),
'by' => $customerBy,
'entityBy' => $companyBy
])
);
}
/**
* Get corporate customer contacts by id or externalId
*
* @param string $id corporate customer identifier
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
* @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 customersCorporateContacts(
$id,
array $filter = [],
$page = null,
$limit = null,
$by = 'externalId',
$site = null
) {
$this->checkIdParameter($by);
$parameters = ['by' => $by];
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(
"/customers-corporate/$id/contacts",
"GET",
$this->fillSite($site, $parameters)
);
}
/**
* Create corporate customer contact
*
* @param string $id corporate customer identifier
* @param array $contact (default: array())
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @return \RetailCrm\Response\ApiResponse
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @throws \InvalidArgumentException
*/
public function customersCorporateContactsCreate($id, array $contact = [], $by = 'externalId', $site = null)
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/customers-corporate/$id/contacts/create",
"POST",
$this->fillSite($site, ['contact' => json_encode($contact), 'by' => $by])
);
}
/**
* Edit corporate customer contact
*
* @param string $customerId corporate customer identifier
* @param string $contactId corporate customer identifier
* @param array $contact (default: array())
* @param string $customerBy (default: 'externalId')
* @param string $contactBy (default: 'externalId')
* @param string $site (default: null)
*
* @return \RetailCrm\Response\ApiResponse
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
*/
public function customersCorporateContactsEdit(
$customerId,
$contactId,
array $contact = [],
$customerBy = 'externalId',
$contactBy = 'externalId',
$site = null
) {
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/customers-corporate/$customerId/contacts/$contactId/edit",
"POST",
$this->fillSite($site, [
'contact' => json_encode($contact),
'by' => $customerBy,
'entityBy' => $contactBy
])
);
}
/**
* Edit a corporate customer
*
* @param array $customerCorporate corporate 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 customersCorporateEdit(array $customerCorporate, $by = 'externalId', $site = null)
{
if (!count($customerCorporate)) {
throw new \InvalidArgumentException(
'Parameter `customerCorporate` must contains a data'
);
}
$this->checkIdParameter($by);
if (!array_key_exists($by, $customerCorporate)) {
throw new \InvalidArgumentException(
sprintf('Corporate customer array must contain the "%s" parameter.', $by)
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/customers-corporate/%s/edit', $customerCorporate[$by]),
"POST",
$this->fillSite(
$site,
['customerCorporate' => json_encode($customerCorporate), 'by' => $by]
)
);
}
}

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Delivery
*
* @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;
@ -19,15 +16,163 @@ use RetailCrm\Methods\V4\Delivery as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* Delivery 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;
/**
* Get delivery settings
*
* @param string $code delivery code
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return void
*/
public function deliverySettingsGet($code)
{
throw new \InvalidArgumentException("This method is not available, setting code: $code is unnecessary");
}
/**
* Get delivery 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 deliveryShipmentsList(
array $filter = [],
$page = null,
$limit = null
) {
$parameters = [];
if (count($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/delivery/shipments',
"GET",
$parameters
);
}
/**
* Create delivery shipment
*
* @param array $shipment (default: array())
* @param string $deliveryType (default: string)
* @param null $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryShipmentsCreate(
array $shipment,
$deliveryType,
$site = null
) {
if (!count($shipment)) {
throw new \InvalidArgumentException(
'Parameter `shipment` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/delivery/shipments/create',
"POST",
$this->fillSite(
$site,
[
'deliveryShipment' => json_encode($shipment),
'deliveryType' => $deliveryType
]
)
);
}
/**
* Get shipment
*
* @param string $id shipment id
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryShipmentGet($id)
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf("/delivery/shipments/%s", $id),
"GET"
);
}
/**
* Edit delivery shipment
*
* @param array $shipment (default: array())
* @param null $site (default: null)
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function deliveryShipmentsEdit(array $shipment, $site = null)
{
if (!count($shipment)) {
throw new \InvalidArgumentException(
'Parameter `shipment` must contains a data'
);
}
if (empty($shipment['id'])) {
throw new \InvalidArgumentException(
'Parameter `shipment` must contains an `id` field'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf("/delivery/shipments/%s/edit", $shipment['id']),
"POST",
$this->fillSite(
$site,
[
'deliveryShipment' => json_encode($shipment)
]
)
);
}
}

View File

@ -0,0 +1,209 @@
<?php
/**
* PHP version 5.4
*
* CostsTrait
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Methods\V5;
/**
* PHP version 5.4
*
* Files trait
*
* @category RetailCrm
* @package RetailCrm
*/
trait Files
{
/**
* Returns filtered files 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 filesList(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;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/files',
"GET",
$parameters
);
}
/**
* Upload file
*
* @param string $file filepath
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function fileUpload($file)
{
if (!file_exists($file)) {
throw new \InvalidArgumentException("File doesn't exist");
}
if (filesize($file) == 0) {
throw new \InvalidArgumentException("Empty file provided");
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/files/upload',
"POST",
["file" => $file]
);
}
/**
* Get file by id
*
* @param string $id file ID
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function fileGet($id)
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/files/$id",
"GET"
);
}
/**
* Delete file by id
*
* @param string $id file ID
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function fileDelete($id)
{
if (empty($id)) {
throw new \InvalidArgumentException(
'Parameter `id` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/files/%s/delete', $id),
"POST"
);
}
/**
* Download file by id
*
* @param string $id file ID
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function fileDownload($id)
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRawRequest(
sprintf('/files/%s/download', $id),
"GET"
);
}
/**
* Edit file data
*
* @param int $id file ID
* @param array $file file data
*
* $file = [
* 'filename' => 'Test file',
* 'attachment' => [
* [
* 'customer' => [
* 'id' => 1
* ],
* 'order' => [
* 'id' => 1
* ]
* ]
* ]
* ];
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function fileEdit($id, array $file)
{
if (empty($id)) {
throw new \InvalidArgumentException(
'Parameter `id` can`t be blank'
);
}
if (empty($file)) {
throw new \InvalidArgumentException(
'Parameter `file` must contains a data'
);
}
$allowedFields = ['filename', 'attachment'];
foreach (array_keys($file) as $field) {
if (!in_array($field, $allowedFields)) {
throw new \InvalidArgumentException(
'Invalid structure of `file` parameter'
);
}
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/files/%s/edit', $id),
"POST",
['file' => json_encode($file), 'id' => $id]
);
}
}

View File

@ -0,0 +1,95 @@
<?php
/**
* PHP version 5.4
*
* Orders
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Methods\V5;
/**
* PHP version 5.4
*
* Orders class
*
* @category RetailCrm
* @package RetailCrm
*/
trait IntegrationPayments
{
/**
* Create Invoice
*
* @param array $createInvoice
* @return \RetailCrm\Response\ApiResponse
*/
public function paymentCreateInvoice($createInvoice)
{
if (!count($createInvoice)) {
throw new \InvalidArgumentException(
'Parameters `createInvoice` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/payment/create-invoice',
'POST',
[
'createInvoice' => json_encode($createInvoice)
]
);
}
/**
* Update Invoice
*
* @param array $updateInvoice
* @return \RetailCrm\Response\ApiResponse
*/
public function paymentUpdateInvoice($updateInvoice)
{
if (!count($updateInvoice)) {
throw new \InvalidArgumentException(
'Parameters `updateInvoice` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/payment/update-invoice',
'POST',
[
'updateInvoice' => json_encode($updateInvoice)
]
);
}
/**
* Check Invoice
*
* @param array $check
* @return \RetailCrm\Response\ApiResponse
*/
public function paymentCheckInvoice($check)
{
if (!count($check)) {
throw new \InvalidArgumentException(
'Parameters `check` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/payment/check',
'POST',
[
'check' => json_encode($check)
]
);
}
}

View File

@ -1,33 +0,0 @@
<?php
/**
* PHP version 5.4
*
* Marketplace
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Methods\V5;
use RetailCrm\Methods\V4\Marketplace as Previous;
/**
* PHP version 5.4
*
* Marketplace class
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
trait Marketplace
{
use Previous;
}

View File

@ -0,0 +1,76 @@
<?php
/**
* PHP version 5.4
*
* Marketplace
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Methods\V5;
/**
* PHP version 5.4
*
* Module class
*
* @category RetailCrm
* @package RetailCrm
*/
trait Module
{
/**
* Get module configuration
*
* @param string $code
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function integrationModulesGet($code)
{
if (empty($code)) {
throw new \InvalidArgumentException(
'Parameter `code` must be set'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/integration-modules/%s', $code),
"GET"
);
}
/**
* Edit module configuration
*
* @param array $configuration
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function integrationModulesEdit(array $configuration)
{
if (!count($configuration) || empty($configuration['code'])) {
throw new \InvalidArgumentException(
'Parameter `configuration` must contains a data & configuration `code` must be set'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/integration-modules/%s/edit', $configuration['code']),
"POST",
['integrationModule' => json_encode($configuration)]
);
}
}

View File

@ -3,30 +3,23 @@
/**
* PHP version 5.4
*
* TaskTrait
* Orders
*
* @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
* Orders 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
{
@ -35,15 +28,15 @@ trait Orders
/**
* Combine orders
*
* @param string $technique
* @param array $order
* @param array $resultOrder
* @param array $order orgin order
* @param array $resultOrder result order
* @param string $technique combining technique
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersCombine($order, $resultOrder, $technique = 'ours')
{
$techniques = ['ours', 'summ', 'theirs'];
$techniques = ['ours', 'summ', 'theirs', 'merge'];
if (!count($order) || !count($resultOrder)) {
throw new \InvalidArgumentException(
@ -57,6 +50,7 @@ trait Orders
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/combine',
"POST",
@ -72,6 +66,7 @@ trait Orders
* Create an order payment
*
* @param array $payment order data
* @param null $site site code
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
@ -79,7 +74,7 @@ trait Orders
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPaymentCreate(array $payment)
public function ordersPaymentCreate(array $payment, $site = null)
{
if (!count($payment)) {
throw new \InvalidArgumentException(
@ -87,10 +82,14 @@ trait Orders
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/payments/create',
"POST",
['payment' => json_encode($payment)]
$this->fillSite(
$site,
['payment' => json_encode($payment)]
)
);
}
@ -119,6 +118,7 @@ trait Orders
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/orders/payments/%s/edit', $payment[$by]),
"POST",
@ -128,4 +128,26 @@ trait Orders
)
);
}
/**
* Edit an order payment
*
* @param string $id payment id
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPaymentDelete($id)
{
if (!$id) {
throw new \InvalidArgumentException(
'Parameter `id` must be set'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/orders/payments/%s/delete', $id),
"POST"
);
}
}

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Packs
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V4\Packs as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* Packs 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
{

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* References
*
* @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;
@ -19,15 +16,272 @@ use RetailCrm\Methods\V4\References as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* References 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 costs groups
*
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function costGroups()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/cost-groups',
"GET"
);
}
/**
* Edit costs groups
*
* @param array $data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function costGroupsEdit(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.'
);
}
if (!array_key_exists('color', $data)) {
throw new \InvalidArgumentException(
'Data must contain "color" parameter.'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/cost-groups/%s/edit', $data['code']),
"POST",
['costGroup' => json_encode($data)]
);
}
/**
* Get costs items
*
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function costItems()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/cost-items',
"GET"
);
}
/**
* Edit costs items
*
* @param array $data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function costItemsEdit(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.'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/cost-items/%s/edit', $data['code']),
"POST",
['costItem' => json_encode($data)]
);
}
/**
* Get legal entities
*
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function legalEntities()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/legal-entities',
"GET"
);
}
/**
* Edit legal entity
*
* @param array $data
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function legalEntitiesEdit(array $data)
{
if (!array_key_exists('code', $data)) {
throw new \InvalidArgumentException(
'Data must contain "code" parameter.'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/legal-entities/%s/edit', $data['code']),
"POST",
['legalEntity' => json_encode($data)]
);
}
/**
* Get couriers
*
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function couriersList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/couriers',
"GET"
);
}
/**
* Create courier
*
* @param array $courier
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function couriersCreate(array $courier)
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/couriers/create',
"POST",
['courier' => json_encode($courier)]
);
}
/**
* Edit courier
*
* @param array $courier
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function couriersEdit(array $courier)
{
if (!array_key_exists('id', $courier)) {
throw new \InvalidArgumentException(
'Data must contain "id" parameter.'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/couriers/%s/edit', $courier['id']),
"POST",
['courier' => json_encode($courier)]
);
}
/**
* Get units
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function unitsList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/units',
"GET"
);
}
/**
* Edit unit
*
* @param array $unit
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function unitsEdit(array $unit)
{
if (empty($unit['code']) || empty($unit['name']) || empty($unit['sym'])) {
throw new \InvalidArgumentException(
'`code`, `name` and `sym` parameters must not be empty.'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/units/%s/edit', $unit['code']),
"POST",
['unit' => json_encode($unit)]
);
}
}

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ namespace RetailCrm\Methods\V5;
*
* @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
{
@ -50,6 +44,7 @@ trait Segments
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/segments',
"GET",

View File

@ -0,0 +1,38 @@
<?php
/**
* PHP version 5.4
*
* Settings
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Methods\V5;
/**
* PHP version 5.4
*
* Settings class
*
* @category RetailCrm
* @package RetailCrm
*/
trait Settings
{
/**
* Get settings
*
* @return \RetailCrm\Response\ApiResponse
*/
public function settings()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/settings',
"GET",
[]
);
}
}

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Statistic
*
* @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;
@ -19,13 +16,10 @@ use RetailCrm\Methods\V3\Statistic as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* 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
{

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Stores
*
* @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;
@ -19,18 +16,28 @@ use RetailCrm\Methods\V4\Stores as Previous;
/**
* PHP version 5.4
*
* TaskTrait class
* Stores 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 void
*
*/
public function storeSettingsGet($code)
{
throw new \InvalidArgumentException("This method is not available, setting code: $code is unnecessary");
}
/**
* Get products groups
*
@ -58,10 +65,46 @@ trait Stores
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/store/product-groups',
"GET",
$parameters
);
}
/**
* Get products properties
*
* @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 storeProductsProperties(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(
'/store/products/properties',
"GET",
$parameters
);
}
}

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* TaskTrait
* Tasks
*
* @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;
@ -17,13 +14,10 @@ namespace RetailCrm\Methods\V5;
/**
* PHP version 5.4
*
* TaskTrait class
* Tasks 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
{
@ -50,6 +44,7 @@ trait Tasks
$parameters['limit'] = (int) $limit;
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/tasks',
"GET",
@ -74,6 +69,7 @@ trait Tasks
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/tasks/create",
"POST",
@ -101,6 +97,7 @@ trait Tasks
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/tasks/{$task['id']}/edit",
"POST",
@ -126,6 +123,7 @@ trait Tasks
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
"/tasks/$id",
"GET"

View File

@ -7,9 +7,6 @@
*
* @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;
@ -23,11 +20,17 @@ use RetailCrm\Methods\V4\Telephony as Previous;
*
* @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;
/**
* @param string $code integration code
*/
public function telephonySettingsGet($code)
{
throw new \InvalidArgumentException("This method is not available, setting code: $code is unnecessary");
}
}

View File

@ -3,30 +3,23 @@
/**
* PHP version 5.4
*
* TaskTrait
* Users
*
* @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
* Users 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
{

View File

@ -3,13 +3,10 @@
/**
* PHP version 5.4
*
* Response from retailCRM API
* Response from RetailCRM API
*
* @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\Response;
@ -19,20 +16,20 @@ use RetailCrm\Exception\InvalidJsonException;
/**
* PHP version 5.4
*
* Response from retailCRM API
* 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/ApiVersion5
*/
class ApiResponse implements \ArrayAccess
{
// HTTP response status code
protected $statusCode;
// raw json response
protected $rawResponse;
// response assoc array
protected $response;
@ -47,9 +44,18 @@ class ApiResponse implements \ArrayAccess
public function __construct($statusCode, $responseBody = null)
{
$this->statusCode = (int) $statusCode;
$this->rawResponse = $responseBody;
}
if (!empty($responseBody)) {
$response = json_decode($responseBody, true);
/**
* Deserialize JSON from raw response body
*
* @return $this
*/
public function asJsonResponse()
{
if (!empty($this->rawResponse)) {
$response = json_decode($this->rawResponse, true);
if (!$response && JSON_ERROR_NONE !== ($error = json_last_error())) {
throw new InvalidJsonException(
@ -60,6 +66,8 @@ class ApiResponse implements \ArrayAccess
$this->response = $response;
}
return $this;
}
/**
@ -72,6 +80,26 @@ class ApiResponse implements \ArrayAccess
return $this->statusCode;
}
/**
* Return HTTP response
*
* @return array
*/
public function getResponse()
{
return $this->response;
}
/**
* Return HTTP raw response body
*
* @return string
*/
public function getResponseBody()
{
return $this->rawResponse;
}
/**
* HTTP request was successful
*
@ -191,3 +219,4 @@ class ApiResponse implements \ArrayAccess
return $this->response[$offset];
}
}

View File

@ -1,30 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="phpunit.xsd"
bootstrap="./tests/bootstrap.php"
colors="true"
verbose="true"
processIsolation="false"
stopOnFailure="false">
<!-- Dummy values used to provide credentials. No need to change these. -->
<php>
<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>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
backupGlobals="false"
colors="false"
bootstrap="tests/bootstrap.php"
backupStaticAttributes="false"
convertErrorsToExceptions="false"
convertNoticesToExceptions="false"
convertWarningsToExceptions="false"
processIsolation="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
>
<testsuites>
<testsuite name="RetailCrm">
<directory>tests/RetailCrm/Tests</directory>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/RetailCrm</directory>
<directory>lib</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="coverage.xml"/>
<log type="junit" target="test-report.xml"/>
</logging>
</phpunit>

View File

@ -1,251 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:documentation source="http://www.phpunit.de/manual/3.7/en/appendixes.configuration.html">
This Schema file defines the rules by which the XML configuration file of PHPUnit 3.7 may be structured.
</xs:documentation>
<xs:appinfo source="http://www.phpunit.de/manual/current/en/appendixes.configuration.html"/>
</xs:annotation>
<xs:element name="phpunit" type="phpUnitType">
<xs:annotation>
<xs:documentation>Root Element</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="filtersType">
<xs:choice>
<xs:sequence>
<xs:element name="blacklist" type="filterType"/>
<xs:element name="whitelist" type="whiteListType" minOccurs="0"/>
</xs:sequence>
<xs:sequence>
<xs:element name="whitelist" type="whiteListType"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
<xs:complexType name="filterType">
<xs:sequence>
<xs:group ref="pathGroup"/>
<xs:element name="exclude" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:group ref="pathGroup"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="whiteListType">
<xs:complexContent>
<xs:extension base="filterType">
<xs:attribute name="processUncoveredFilesFromWhitelist" default="true" type="xs:boolean"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="groupsType">
<xs:choice>
<xs:sequence>
<xs:element name="include" type="groupType"/>
<xs:element name="exclude" type="groupType" minOccurs="0"/>
</xs:sequence>
<xs:sequence>
<xs:element name="exclude" type="groupType"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
<xs:complexType name="groupType">
<xs:sequence>
<xs:element name="group" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="listenersType">
<xs:sequence>
<xs:element name="listener" type="objectType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="objectType">
<xs:sequence>
<xs:element name="arguments" minOccurs="0">
<xs:complexType>
<xs:group ref="argumentsGroup"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="class" type="xs:string" use="required"/>
<xs:attribute name="file" type="xs:anyURI"/>
</xs:complexType>
<xs:complexType name="arrayType">
<xs:sequence>
<xs:element name="element" type="argumentType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="argumentType">
<xs:group ref="argumentChoice"/>
<xs:attribute name="key" use="required"/>
</xs:complexType>
<xs:group name="argumentsGroup">
<xs:sequence>
<xs:element name="array" type="arrayType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="integer" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="string" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="double" type="xs:double" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="null" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="object" type="objectType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="file" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="directory" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:group>
<xs:group name="argumentChoice">
<xs:choice>
<xs:element name="array" type="arrayType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="integer" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="string" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="double" type="xs:double" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="null" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="object" type="objectType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="file" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="directory" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
</xs:group>
<xs:complexType name="loggersType">
<xs:sequence>
<xs:element name="log" type="loggerType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="loggerType">
<xs:attribute name="type">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="coverage-html"/>
<xs:enumeration value="coverage-clover"/>
<xs:enumeration value="json"/>
<xs:enumeration value="plain"/>
<xs:enumeration value="tap"/>
<xs:enumeration value="junit"/>
<xs:enumeration value="testdox-html"/>
<xs:enumeration value="testdox-text"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="target" type="xs:anyURI"/>
<xs:attribute name="title" type="xs:string"/>
<xs:attribute name="charset" type="xs:string" default="UTF-8"/>
<xs:attribute name="yui" type="xs:boolean" default="true"/>
<xs:attribute name="highlight" type="xs:boolean" default="false"/>
<xs:attribute name="lowUpperBound" type="xs:nonNegativeInteger" default="35"/>
<xs:attribute name="highLowerBound" type="xs:nonNegativeInteger" default="70"/>
<xs:attribute name="logIncompleteSkipped" type="xs:boolean" default="false"/>
</xs:complexType>
<xs:group name="pathGroup">
<xs:sequence>
<xs:element name="directory" type="directoryFilterType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="file" type="fileFilterType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:group>
<xs:complexType name="directoryFilterType">
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:attribute type="xs:string" name="suffix" default="Test.php"/>
<xs:attributeGroup ref="phpVersionGroup"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="fileFilterType">
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:attributeGroup ref="phpVersionGroup"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:attributeGroup name="phpVersionGroup">
<xs:attribute name="phpVersion" type="xs:string" default="5.3.0"/>
<xs:attribute name="phpVersionOperator" type="xs:string" default="&gt;="/>
</xs:attributeGroup>
<xs:complexType name="phpType">
<xs:sequence>
<xs:element name="includePath" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="ini" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="const" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="var" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="env" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="post" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="get" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="cookie" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="server" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="files" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="request" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="namedValueType">
<xs:attribute name="name" use="required" type="xs:string"/>
<xs:attribute name="value" use="required" type="xs:anySimpleType"/>
</xs:complexType>
<xs:complexType name="phpUnitType">
<xs:annotation>
<xs:documentation>The main type specifying the document structure</xs:documentation>
</xs:annotation>
<xs:group ref="configGroup"/>
<xs:attributeGroup ref="configAttributeGroup"/>
</xs:complexType>
<xs:attributeGroup name="configAttributeGroup">
<xs:attribute name="backupGlobals" type="xs:boolean" default="true"/>
<xs:attribute name="backupStaticAttributes" type="xs:boolean" default="false"/>
<xs:attribute name="bootstrap" type="xs:anyURI"/>
<xs:attribute name="cacheTokens" type="xs:boolean"/>
<xs:attribute name="colors" type="xs:boolean" default="false"/>
<xs:attribute name="convertErrorsToExceptions" type="xs:boolean" default="true"/>
<xs:attribute name="convertNoticesToExceptions" type="xs:boolean" default="true"/>
<xs:attribute name="convertWarningsToExceptions" type="xs:boolean" default="true"/>
<xs:attribute name="forceCoversAnnotation" type="xs:boolean" default="false"/>
<xs:attribute name="mapTestClassNameToCoveredClassName" type="xs:boolean" default="false"/>
<xs:attribute name="printerClass" type="xs:string" default="PHPUnit_TextUI_ResultPrinter"/>
<xs:attribute name="printerFile" type="xs:anyURI"/>
<xs:attribute name="processIsolation" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnError" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnFailure" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnIncomplete" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnSkipped" type="xs:boolean" default="false"/>
<xs:attribute name="strict" type="xs:boolean" default="false"/>
<xs:attribute name="testSuiteLoaderClass" type="xs:string" default="PHPUnit_Runner_StandardTestSuiteLoader"/>
<xs:attribute name="testSuiteLoaderFile" type="xs:anyURI"/>
<xs:attribute name="timeoutForSmallTests" type="xs:integer" default="1"/>
<xs:attribute name="timeoutForMediumTests" type="xs:integer" default="10"/>
<xs:attribute name="timeoutForLargeTests" type="xs:integer" default="60"/>
<xs:attribute name="verbose" type="xs:boolean" default="false"/>
</xs:attributeGroup>
<xs:group name="configGroup">
<xs:all>
<xs:element ref="testSuiteFacet" minOccurs="0"/>
<xs:element name="groups" type="groupsType" minOccurs="0"/>
<xs:element name="filter" type="filtersType" minOccurs="0"/>
<xs:element name="logging" type="loggersType" minOccurs="0"/>
<xs:element name="listeners" type="listenersType" minOccurs="0"/>
<xs:element name="php" type="phpType" minOccurs="0"/>
<xs:element name="selenium" type="seleniumType" minOccurs="0"/>
</xs:all>
</xs:group>
<xs:complexType name="seleniumType">
<xs:sequence>
<xs:element name="browser" type="browserType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="browserType">
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="browser" type="xs:string"/>
<xs:attribute name="host" type="xs:anyURI"/>
<xs:attribute name="port" type="xs:nonNegativeInteger"/>
<xs:attribute name="timeout" type="xs:nonNegativeInteger"/>
</xs:complexType>
<xs:element name="testSuiteFacet" abstract="true"/>
<xs:element name="testsuite" type="testSuiteType" substitutionGroup="testSuiteFacet"/>
<xs:element name="testsuites" type="testSuitesType" substitutionGroup="testSuiteFacet"/>
<xs:complexType name="testSuitesType">
<xs:sequence>
<xs:element name="testsuite" type="testSuiteType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="testSuiteType">
<xs:sequence>
<xs:group ref="pathGroup"/>
<xs:element name="exclude" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>

View File

@ -7,69 +7,88 @@
*
* @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 PHPUnit\Framework\MockObject\MockObject;
use RetailCrm\ApiClient;
use RetailCrm\Http\Client;
use PHPUnit\Framework\TestCase as BaseCase;
/**
* Class TestCase
*
* @package RetailCrm\Test
* @category RetailCrm
* @package RetailCrm
*/
class TestCase extends \PHPUnit_Framework_TestCase
class TestCase extends BaseCase
{
/**
* Return ApiClient object
*
* @param string $url (default: null)
* @param string $apiKey (default: null)
* @param string $version (default: null)
* @param string $site (default: null)
* @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, $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'];
public static function getApiClient(
$url = null,
$apiKey = null,
$version = null,
$site = null
) {
$configUrl = getenv('RETAILCRM_URL') ?: $_SERVER['RETAILCRM_URL'];
$configKey = getenv('RETAILCRM_KEY') ?: $_SERVER['RETAILCRM_KEY'];
$configVersion = getenv('RETAILCRM_VERSION') ?: $_SERVER['RETAILCRM_VERSION'];
$configSite = getenv('RETAILCRM_SITE') ?: $_SERVER['RETAILCRM_SITE'];
return new ApiClient(
$url ?: $configUrl,
$apiKey ?: $configKey,
$version ?: $configVersion,
$site ?: null
$site ?: $configSite
);
}
/**
* @param \RetailCrm\Http\Client|MockObject $httpClient
* @return ApiClient
* @throws \ReflectionException
*/
public static function getMockedApiClient($httpClient)
{
$client = self::getApiClient();
$property = new \ReflectionProperty(get_class($client->request), 'client');
$property->setAccessible(true);
$property->setValue($client->request, $httpClient);
return $client;
}
/**
* Return Client object
*
* @param string $url (default: null)
* @param array $defaultParameters (default: array())
* @param string $url (default: null)
* @param array $defaultParameters (default: array())
*
* @return Client
*/
public static function getClient($url = null, $defaultParameters = [])
{
$version = getenv('CRM_API_VERSION');
if (false == $version) {
$version = $_SERVER['CRM_API_VERSION'];
}
$configUrl = getenv('RETAILCRM_URL') ?: $_SERVER['RETAILCRM_URL'];
$configKey = getenv('RETAILCRM_KEY') ?: $_SERVER['RETAILCRM_KEY'];
$configVersion = getenv('RETAILCRM_VERSION') ?: $_SERVER['RETAILCRM_VERSION'];
return new Client(
$url ?: $_SERVER['CRM_API_URL'] . '/api/' . $version,
$url ?: $configUrl . '/api/' . $configVersion,
[
'apiKey' => array_key_exists('apiKey', $defaultParameters)
? $defaultParameters['apiKey']
: $_SERVER['CRM_API_KEY']
: $configKey
]
);
}

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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 ApiClientTest extends TestCase
{

View File

@ -7,15 +7,11 @@
*
* @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\Http;
use RetailCrm\Test\TestCase;
use RetailCrm\ApiClient;
use RetailCrm\Http\Client;
/**
@ -23,9 +19,6 @@ use RetailCrm\Http\Client;
*
* @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 ClientTest extends TestCase
{
@ -45,10 +38,26 @@ class ClientTest extends TestCase
*/
public function testHttpRequiring()
{
$client = new Client('http://demo.retailcrm.ru/api/' . $_SERVER['CRM_API_VERSION'], ['apiKey' => '123']);
$configVersion = getenv('RETAILCRM_VERSION') ?: $_SERVER['RETAILCRM_VERSION'];
$client = new Client('http://demo.retailcrm.ru/api/' . $configVersion, ['apiKey' => '123']);
return $client;
}
/**
* @group client
*/
public function testHttpDebug()
{
$client_v3 = new Client('http://demo.retailcrm.ru/api/v3', ['apiKey' => '123'], true);
$client_v4 = new Client('http://demo.retailcrm.ru/api/v4', ['apiKey' => '123'], true);
$client_v5 = new Client('http://demo.retailcrm.ru/api/v5', ['apiKey' => '123'], true);
static::assertInstanceOf('RetailCrm\Http\Client', $client_v3);
static::assertInstanceOf('RetailCrm\Http\Client', $client_v4);
static::assertInstanceOf('RetailCrm\Http\Client', $client_v5);
}
/**
* @group client
* @expectedException \InvalidArgumentException
@ -78,6 +87,22 @@ class ClientTest extends TestCase
$response = $client->makeRequest('/orders', Client::METHOD_GET);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertNotEmpty($response->getResponseBody());
static::assertNotEmpty($response->getResponse());
static::assertEquals(200, $response->getStatusCode());
}
/**
* @group client
*/
public function testRequestSuccessNoDeserialization()
{
$client = static::getClient();
$response = $client->makeRawRequest('/orders', Client::METHOD_GET);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertNotEmpty($response->getResponseBody());
static::assertEmpty($response->getResponse());
static::assertEquals(200, $response->getStatusCode());
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace RetailCrm\Tests\Http;
use RetailCrm\Http\RequestOptions;
use RetailCrm\Test\TestCase;
class RequestOptionsTest extends TestCase
{
public function testGetHeaders()
{
$headers = ['X-Test-Header' => 'Test'];
$options = new RequestOptions($headers);
self::assertEquals('X-Test-Header: Test', $options->getHttpHeaders()[0]);
self::assertEquals('Test', $options->getHeaders()['X-Test-Header']);
}
public function testGetClientTimeout()
{
$options = new RequestOptions([], 10);
self::assertEquals(10, $options->getClientTimeout());
}
}

View File

@ -0,0 +1,77 @@
<?php
/**
* PHP version 5.4
*
* API client customers test class
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Tests\Methods;
use RetailCrm\Test\TestCase;
/**
* Class CommonMethodsTest
*
* @category RetailCrm
* @package RetailCrm
*/
class CommonMethodsTest extends TestCase
{
/**
* Available versions
*
* @group api_methods
*
* @return void
*/
public function testAvailableVersions()
{
$client = static::getApiClient();
$response = $client->request->availableVersions();
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertGreaterThan(0, count($response['versions']));
}
/**
* Available methods
*
* @group api_methods
*
* @return void
*/
public function testCredentials()
{
$client = static::getApiClient();
$response = $client->request->credentials();
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertGreaterThan(0, count($response['credentials']));
}
/**
* System settings
*
* @group api_methods
*
* @return void
*/
public function testSettings()
{
$client = static::getApiClient();
$response = $client->request->settings();
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertGreaterThan(0, count($response['settings']));
}
}

View File

@ -7,13 +7,11 @@
*
* @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\ApiClient;
use RetailCrm\Test\TestCase;
/**
@ -21,9 +19,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -34,7 +29,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersCreate()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$externalId = 'c-create-' . time();
@ -59,7 +54,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCreateExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->customersCreate([]);
}
@ -73,7 +68,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersGet(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->customersGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -99,7 +94,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersGetException()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->customersGet(678678678, 'asdf');
}
@ -111,7 +106,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersEdit(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->customersEdit(
[
@ -138,7 +133,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersEditExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->customersEdit([], 'asdf');
}
@ -148,7 +143,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersEditException()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->customersEdit(['id' => 678678678], 'asdf');
}
@ -157,7 +152,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersList()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->customersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -185,7 +180,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersFixExternalIdsException()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->customersFixExternalIds([]);
}
@ -194,7 +189,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersFixExternalIds()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->ordersCreate([
'firstName' => 'Aaa111',
@ -246,7 +241,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->customersUpload([]);
}
@ -255,7 +250,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersUpload()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();

View File

@ -7,9 +7,6 @@
*
* @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;
@ -33,6 +30,7 @@ class ApiClientMarketplaceTest extends TestCase
{
$client = static::getApiClient(null, null, "v4");
/* @var \RetailCrm\Response\ApiResponse $response */
$response = $client->request->marketplaceSettingsEdit(
[
'name' => self::SNAME,

View File

@ -7,13 +7,11 @@
*
* @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\ApiClient;
use RetailCrm\Test\TestCase;
/**
@ -21,9 +19,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -34,7 +29,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersCreate()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$externalId = 'o-create-' . time();
@ -58,7 +53,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersCreateExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->ordersCreate([]);
}
@ -70,7 +65,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersStatuses(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->ordersStatuses();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -117,7 +112,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersGet(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->ordersGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -143,7 +138,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersGetException()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->ordersGet(678678678, 'asdf');
}
@ -155,7 +150,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersEdit(array $ids)
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->ordersEdit(
[
@ -182,7 +177,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersEditExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->ordersEdit([], 'asdf');
}
@ -192,7 +187,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersEditException()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->ordersEdit(['id' => 678678678], 'asdf');
}
@ -201,7 +196,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersHistory()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->ordersHistory();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -214,7 +209,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersList()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->ordersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -238,7 +233,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersFixExternalIdsException()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->ordersFixExternalIds([]);
}
@ -247,7 +242,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersFixExternalIds()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->ordersCreate([
'firstName' => 'Aaa',
@ -292,7 +287,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->ordersUpload([]);
}
@ -301,7 +296,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersUpload()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{

View File

@ -7,13 +7,11 @@
*
* @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\ApiClient;
use RetailCrm\Test\TestCase;
/**
@ -21,9 +19,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -34,7 +29,7 @@ class ApiClientReferenceTest extends TestCase
*/
public function testList($name)
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$method = $name . 'List';
$response = $client->request->$method();
@ -56,7 +51,7 @@ class ApiClientReferenceTest extends TestCase
*/
public function testEditingException($name)
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$method = $name . 'Edit';
$client->request->$method([]);
@ -70,7 +65,7 @@ class ApiClientReferenceTest extends TestCase
*/
public function testEditing($name)
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';
@ -94,6 +89,8 @@ class ApiClientReferenceTest extends TestCase
'active' => false
]);
sleep(1);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
}
@ -104,7 +101,7 @@ class ApiClientReferenceTest extends TestCase
public function testSiteEditing()
{
$name = 'sites';
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';

View File

@ -7,13 +7,11 @@
*
* @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\ApiClient;
use RetailCrm\Test\TestCase;
/**
@ -21,9 +19,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -35,7 +30,7 @@ class ApiClientStoreTest extends TestCase
*/
public function testStoreCreate()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->storesEdit(['name' => self::SNAME, 'code' => self::SCODE]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -48,7 +43,7 @@ class ApiClientStoreTest extends TestCase
*/
public function testStoreInventories()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->storeInventories();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -66,7 +61,7 @@ class ApiClientStoreTest extends TestCase
*/
public function testInventoriesException()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$client->request->storeInventoriesUpload([]);
}
@ -75,7 +70,7 @@ class ApiClientStoreTest extends TestCase
*/
public function testInventoriesUpload()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->storeInventoriesUpload([
[
@ -109,7 +104,7 @@ class ApiClientStoreTest extends TestCase
*/
public function testInventoriesFailed()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
@ -136,7 +131,7 @@ class ApiClientStoreTest extends TestCase
*/
public function testStoreProducts()
{
$client = static::getApiClient(null, null, 'v4');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->storeProducts();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);

View File

@ -7,22 +7,18 @@
*
* @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\ApiClient;
use RetailCrm\Response\ApiResponse;
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
{
@ -40,8 +36,11 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonySettingsEdit()
{
$client = static::getApiClient(null, null, 'v4');
self::markTestSkipped('Should be fixed.');
$client = static::getApiClient(null, null, ApiClient::V4);
$user = getenv('RETAILCRM_USER') ?: $_SERVER['RETAILCRM_USER'];
/* @var \RetailCrm\Response\ApiResponse $response */
$response = $client->request->telephonySettingsEdit(
self::TEL_CODE,
self::TEL_CLIENT,
@ -49,7 +48,7 @@ class ApiClientTelephonyTest extends TestCase
'TestTelephonyV4',
false,
self::TEL_IMAGE,
[['userId' => $_SERVER['CRM_USER_ID'], 'code' => '101']],
[['userId' => $user, 'code' => '101']],
[['siteCode' => 'api-client-php', 'externalPhone' => '+74950000000']]
);
@ -67,8 +66,10 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonySettingsGet()
{
$client = static::getApiClient(null, null, 'v4');
self::markTestSkipped('Should be fixed.');
$client = static::getApiClient(null, null, ApiClient::V4);
/* @var \RetailCrm\Response\ApiResponse $response */
$response = $client->request->telephonySettingsGet(self::TEL_CODE);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
@ -84,19 +85,42 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonyEvent()
{
$client = static::getApiClient(null, null, 'v4');
$stub = $this->getMockBuilder(\RetailCrm\Http\Client::class)
->disableOriginalConstructor()
->setMethods(['makeRequest'])
->getMock();
$parameters = [
'phone' => '+79999999999',
'type' => 'in',
'codes' => ['101'],
'userIds' => [2],
'hangupStatus' => 'failed',
'callExternalId' => '+74950000000',
'externalPhone' => '123456789',
'webAnalyticsData' => [],
'site' => 'retailcrm-ru'
];
$stub->expects(self::once())->method('makeRequest')->with(
'/telephony/call/event',
"POST",
['event' => json_encode($parameters)]
)->willReturn((new ApiResponse(200, json_encode(['success' => true])))->asJsonResponse());
$client = static::getMockedApiClient($stub);
$response = $client->request->telephonyCallEvent(
'+79999999999',
'in',
['101'],
[2],
'failed',
'+74950000000'
'123456789',
'+74950000000',
[]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
@ -109,7 +133,8 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonyUpload()
{
$client = static::getApiClient(null, null, 'v4');
self::markTestSkipped('Should be fixed.');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->telephonyCallsUpload(
[
@ -148,7 +173,8 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonyManager()
{
$client = static::getApiClient(null, null, 'v4');
self::markTestSkipped('Should be fixed.');
$client = static::getApiClient(null, null, ApiClient::V4);
$response = $client->request->telephonyCallManager('+79999999999', 1);

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -59,8 +53,9 @@ class ApiClientUsersTest extends TestCase
public function testUsersGet()
{
$client = static::getApiClient(null, null, "v4");
$user = getenv('RETAILCRM_USER') ?: $_SERVER['RETAILCRM_USER'];
$response = $client->request->usersGet($_SERVER["CRM_USER_ID"]);
$response = $client->request->usersGet($user);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());

View File

@ -0,0 +1,666 @@
<?php
/**
* PHP version 5.4
*
* API client corporate customers test class
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientCustomersCorporateTest
*
* @category RetailCrm
* @package RetailCrm
*/
class ApiClientCustomersCorporateTest extends TestCase
{
const NICK_NAME = 'ООО "Чем-то Пахнет"';
/**
* @group customers_corporate_v5
*/
public function testCustomersCorporateCreate()
{
$client = static::getApiClient();
$externalId = 'c-create-' . time();
$response = $client->request->customersCorporateCreate([
'nickName' => self::NICK_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_corporate_v5
* @expectedException \InvalidArgumentException
*/
public function testCreateExceptionEmpty()
{
$client = static::getApiClient();
$client->request->customersCorporateCreate([]);
}
/**
* @group customers_corporate_v5
* @depends testCustomersCorporateCreate
*
* @param array $ids
*
* @return array
*/
public function testCustomersCorporateGet(array $ids)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
static::assertFalse($response->isSuccessful());
$response = $client->request->customersCorporateGet($ids['id'], 'id');
$customerById = $response['customerCorporate'];
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
static::assertEquals(self::NICK_NAME, $response['customerCorporate']['nickName']);
$response = $client->request->customersCorporateGet($ids['externalId'], 'externalId');
static::assertEquals($customerById['id'], $response['customerCorporate']['id']);
return $ids;
}
/**
* @group customers_corporate_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersCorporateGetException()
{
$client = static::getApiClient();
$client->request->customersCorporateGet(678678678, 'asdf');
}
/**
* @group customers_corporate_v5
* @depends testCustomersCorporateGet
*
* @param array $ids
*
* @return array
*/
public function testCustomersCorporateEdit(array $ids)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateEdit(
[
'id' => 22342134,
'nickName' => '12345',
],
'id'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(404, $response->getStatusCode());
$response = $client->request->customersCorporateEdit([
'externalId' => $ids['externalId'],
'mainAddress' => ['name' => '12345'],
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
return $ids;
}
/**
* testCustomersCorporateEditException
* @expectedException \InvalidArgumentException
*/
public function testCustomersCorporateEditExceptionNoExternalId()
{
$client = static::getApiClient();
$client->request->customersCorporateEdit(['id' => 0]);
}
/**
* @group customers_corporate_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersCorporateEditExceptionEmpty()
{
$client = static::getApiClient();
$client->request->customersCorporateEdit([], 'asdf');
}
/**
* @group customers_corporate_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersCorporateEditException()
{
$client = static::getApiClient();
$client->request->customersCorporateEdit(['id' => 678678678], 'asdf');
}
/**
* @group customers_corporate_v5
*/
public function testCustomersCorporateList()
{
$client = static::getApiClient();
$response = $client->request->customersCorporateList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful());
static::assertTrue(isset($response['customersCorporate']));
$response = $client->request->customersCorporateList([], 1, 300);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertFalse(
$response->isSuccessful(),
'Pagination error'
);
$response = $client->request->customersCorporateList(['maxOrdersCount' => 10], 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(
$response->isSuccessful(),
'API returns customers list'
);
}
/**
* @group customers_corporate_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersCorporateFixExternalIdsException()
{
$client = static::getApiClient();
$client->request->customersCorporateFixExternalIds([]);
}
/**
* @group customers_corporate_v5
*/
public function testCustomersCorporateFixExternalIds()
{
$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->customersCorporateFixExternalIds([
['id' => $id, 'externalId' => $externalId]
]);
static::assertTrue(
$response->isSuccessful(),
'Fixed customer ids'
);
$response = $client->request->customersCorporateGet($externalId);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
}
/**
* @group customers_corporate_v5
* @expectedException \InvalidArgumentException
*/
public function testCustomersCorporateUploadExceptionEmpty()
{
$client = static::getApiClient();
$client->request->customersCorporateUpload([]);
}
/**
* @group customers_corporate_v5
*/
public function testCustomersCorporateUpload()
{
$client = static::getApiClient();
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
$response = $client->request->customersCorporateUpload([
[
'externalId' => $externalIdA,
'nickName' => 'Aaa',
],
[
'externalId' => $externalIdB,
'nickName' => 'Bbb',
],
]);
static::assertTrue(
$response->isSuccessful(),
'Got customer'
);
static::assertEquals(
$externalIdA,
$response['uploadedCustomers'][0]['externalId']
);
static::assertEquals(
$externalIdB,
$response['uploadedCustomers'][1]['externalId']
);
}
/**
* testCustomersCorporateAddressesException
* @expectedException \InvalidArgumentException
*/
public function testCustomersCorporateAddressesException()
{
$client = static::getApiClient();
$client->request->customersCorporateAddresses('', [], [], [], 'uid');
}
/**
* testCustomersCorporateAddresses
*
* @param array $ids
*
* @group customers_corporate_v5
* @depends testCustomersCorporateEdit
* @return array
*/
public function testCustomersCorporateAddresses(array $ids)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateAddresses($ids['externalId'], ['name' => 'name'], 1, 20);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(
$response->isSuccessful(),
'API returns addresses list'
);
return $ids;
}
/**
* @group customers_corporate_v5
*/
public function testCustomersCorporateHistory()
{
$client = static::getApiClient();
$response = $client->request->customersCorporateHistory(['sinceId' => 1], 1, 20);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(
$response->isSuccessful(),
'API returns history list'
);
}
/**
* @group customers_corporate_v5
*/
public function testCustomersCorporateNotesList()
{
$client = static::getApiClient();
$response = $client->request->customersCorporateNotesList(['text' => 'text'], 1, 20);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(
$response->isSuccessful(),
'API returns notes list'
);
}
/**
* @group customers_corporate_v5
* @depends testCustomersCorporateAddresses
*
* @param array $ids
*
* @return array
*/
public function testCustomersCorporateCompaniesList(array $ids)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateCompanies($ids['externalId'], ['ids' => [1]], 1, 20);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(
$response->isSuccessful(),
'API returns companies list'
);
return $ids;
}
/**
* @group customers_corporate_v5
*
* @param array $ids
* @depends testCustomersCorporateCompaniesList
*
* @return array
*/
public function testCustomersCorporateContactsList(array $ids)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateContacts($ids['externalId'], ['ids' => [1]], 1, 20);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(
$response->isSuccessful(),
'API returns contacts list'
);
return $ids;
}
/**
* testCustomersCorporateNotesCreate
*
* @param array $ids
*
* @depends testCustomersCorporateContactsList
* @return array
*/
public function testCustomersCorporateNotesCreate(array $ids)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateNotesCreate([
'text' => 'test note',
'customer' => [
'externalId' => $ids['externalId']
]
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(201, $response->getStatusCode());
static::assertArrayHasKey('id', $response->getResponse());
return array_merge($response->getResponse(), ['customer' => $ids]);
}
/**
* testCustomersCorporateNotesCreateException
* @expectedException \InvalidArgumentException
*/
public function testCustomersCorporateNotesCreateException()
{
$client = static::getApiClient();
$client->request->customersCorporateNotesCreate([
'text' => 'test note',
'customer' => []
]);
}
/**
* testCustomersCorporateNotesDelete
*
* @param array $noteResponse
*
* @depends testCustomersCorporateNotesCreate
* @return mixed
*/
public function testCustomersCorporateNotesDelete(array $noteResponse)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateNotesDelete($noteResponse['id']);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
return $noteResponse['customer'];
}
/**
* testCustomersCorporateNotesDeleteException
* @expectedException \InvalidArgumentException
*/
public function testCustomersCorporateNotesDeleteException()
{
$client = static::getApiClient();
$client->request->customersCorporateNotesDelete(null);
}
/**
* testCustomersCorporateAddressCreate
*
* @param array $ids
* @depends testCustomersCorporateNotesDelete
*
* @return array
*/
public function testCustomersCorporateAddressCreate(array $ids)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateAddressesCreate(
$ids['externalId'],
['text' => 'Boldovo, Ruzayevsky District, Respublika Mordoviya']
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful(), 'Address is created');
static::assertArrayHasKey('id', $response->getResponse());
return array_merge($response->getResponse(), ['customer' => $ids]);
}
/**
* testCustomersCorporateAddressEdit
*
* @param array $createResponse
* @depends testCustomersCorporateAddressCreate
*
* @return array
*/
public function testCustomersCorporateAddressEdit(array $createResponse)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateAddressesEdit(
$createResponse['customer']['externalId'],
$createResponse['id'],
['text' => '648593, Evenkiysky District, Krasnoyarsk Krai'],
'externalId',
'id'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful(), 'Address is edited');
return $createResponse['customer'];
}
/**
* testCustomersCorporateAddressesEditException
* @expectedException \InvalidArgumentException
*/
public function testCustomersCorporateAddressesEditException()
{
$client = static::getApiClient();
$client->request->customersCorporateAddressesEdit(0, 0, []);
}
/**
* testCustomersCorporateCompaniesCreate
*
* @param array $ids
* @depends testCustomersCorporateAddressEdit
*
* @return array
*/
public function testCustomersCorporateCompaniesCreate(array $ids)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateCompaniesCreate(
$ids['externalId'],
[
'active' => true,
'name' => 'Company name',
'brand' => 'company brand',
'contragent' => [
'contragentType' => 'legal-entity',
'legalName' => 'Company Name',
'legalAddress' => '648593, Evenkiysky District, Krasnoyarsk Krai',
'INN' => '000000000',
'OKPO' => '000000000',
'KPP' => '000000000',
'OGRN' => '000000000',
'BIK' => '000000000',
'bank' => 'bank',
'bankAddress' => 'bank address',
'corrAccount' => 'correspondent account',
'bankAccount' => 'bank account'
]
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful(), 'Company is created');
static::assertArrayHasKey('id', $response->getResponse());
return array_merge($response->getResponse(), ['customer' => $ids]);
}
/**
* testCustomersCorporateCompaniesEdit
*
* @depends testCustomersCorporateCompaniesCreate
*
* @param array $createResp
*
* @return mixed
*/
public function testCustomersCorporateCompaniesEdit(array $createResp)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateCompaniesEdit(
$createResp['customer']['externalId'],
$createResp['id'],
['name' => 'Company Name 2'],
'externalId',
'id'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful(), 'Company is edited');
static::assertArrayHasKey('id', $response->getResponse());
return $createResp['customer'];
}
/**
* testCustomersCorporateContactsCreate
*
* @param array $ids
* @depends testCustomersCorporateCompaniesEdit
*
* @return array
*/
public function testCustomersCorporateContactsCreate(array $ids)
{
$client = static::getApiClient();
$testCustomerExternalId = sprintf('test-customer-external-id-%d', time());
$customerResponse = $client->request->customersCreate([
'firstName' => 'Test Customer',
'externalId' => $testCustomerExternalId,
]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $customerResponse);
static::assertTrue($customerResponse->isSuccessful(), 'Test customer is created');
$response = $client->request->customersCorporateContactsCreate(
$ids['externalId'],
[
'customer' => [
'externalId' => $testCustomerExternalId,
'browserId' => 'ca205b35862546758218cac776355f32',
'site' => static::getSite()
]
]
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful(), 'Contact person is created');
static::assertArrayHasKey('id', $response->getResponse());
return [
'contact' => $customerResponse->getResponse(),
'customer' => $ids
];
}
/**
* testCustomersCorporateContactsEdit
*
* @depends testCustomersCorporateContactsCreate
*
* @param array $createResp
*
* @return mixed
*/
public function testCustomersCorporateContactsEdit(array $createResp)
{
$client = static::getApiClient();
$response = $client->request->customersCorporateContactsEdit(
$createResp['customer']['externalId'],
$createResp['contact']['id'],
[
'id' => $createResp['contact']['id'],
'customer' => [
'browserId' => '73997eedbdaf4c0991b1a5511aeae407',
'site' => static::getSite()
]
],
'externalId',
'id',
static::getSite()
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue($response->isSuccessful(), 'Contact person is edited');
static::assertArrayHasKey('id', $response->getResponse());
return $createResp['customer'];
}
/**
* getSite
*
* @return string
*/
private static function getSite()
{
return getenv('RETAILCRM_SITE') ?: $_SERVER['RETAILCRM_SITE'];
}
}

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -340,6 +334,7 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersNotesCreate()
{
self::markTestSkipped('Should be fixed.');
$client = static::getApiClient();
$responseCreateFirst = $client->request->customersCreate([
@ -407,6 +402,8 @@ class ApiClientCustomersTest extends TestCase
*/
public function testCustomersNotesDelete()
{
self::markTestSkipped('Should be fixed.');
$client = static::getApiClient();
$responseCreateFirst = $client->request->customersCreate([

View File

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

View File

@ -0,0 +1,87 @@
<?php
/**
* PHP version 5.4
*
* API client prices test class
*
* @category RetailCrm
* @package RetailCrm
*/
namespace RetailCrm\Tests\Methods\Version5;
use RetailCrm\Test\TestCase;
/**
* Class ApiClientPricesTest
*
* @category RetailCrm
* @package RetailCrm
*/
class ApiClientFilesTest extends TestCase
{
/**
* @group files_v5
*/
public function testFilesList()
{
$client = static::getApiClient();
$response = $client->request->filesList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group files_v5
*/
public function testFileUpload()
{
$client = static::getApiClient();
$response = $client->request->fileUpload(__DIR__ . '/../../../Tests/Resources/Report.pdf');
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
sleep(1);
$fileId = $response['file']['id'];
$response = $client->request->fileGet($fileId);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
sleep(1);
$response = $client->request->fileEdit($fileId, ['filename' => 'Test file']);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
sleep(1);
$response = $client->request->fileDelete($fileId);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
sleep(1);
}
public function testFileEditFailure()
{
static::expectExceptionObject(new \InvalidArgumentException('Invalid structure of `file` parameter'));
$client = static::getApiClient();
$client->request->fileEdit(1, ['file' => []]);
}
}

View File

@ -7,9 +7,6 @@
*
* @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;
@ -19,31 +16,42 @@ use RetailCrm\Test\TestCase;
/**
* Class ApiClientMarketplaceTest
*
* @package RetailCrm\Tests
* @category RetailCrm
* @package RetailCrm
*/
class ApiClientMarketplaceTest extends TestCase
{
const SNAME = 'Marketplace integration v5';
const SCODE = 'integration_v5';
const SERVICE_NAME = 'Marketplace integration v5';
const SERVICE_CODE = 'integration_v5';
/**
* Test configuration
*
* @group marketplace_v5
*
* @return void
*/
public function testConfigurationEdit()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->marketplaceSettingsEdit(
/**
* Response
*
* @var \RetailCrm\Response\ApiResponse $response
*/
$response = $client->request->integrationModulesEdit(
[
'name' => self::SNAME,
'code' => self::SCODE,
'name' => self::SERVICE_NAME,
'code' => self::SERVICE_CODE,
'clientId' => uniqid(),
'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::assertEquals($response->getStatusCode(), 200);
static::assertTrue($response->isSuccessful());
}
}

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -34,7 +28,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersCreate()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$externalId = 'o-create-' . time();
@ -58,7 +52,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersCreateExceptionEmpty()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$client->request->ordersCreate([]);
}
@ -70,7 +64,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersStatuses(array $ids)
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->ordersStatuses();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -117,7 +111,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersGet(array $ids)
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->ordersGet(678678678);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -143,7 +137,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersGetException()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$client->request->ordersGet(678678678, 'asdf');
}
@ -155,7 +149,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersEdit(array $ids)
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->ordersEdit(
[
@ -182,7 +176,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersEditExceptionEmpty()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$client->request->ordersEdit([], 'asdf');
}
@ -192,7 +186,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersEditException()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$client->request->ordersEdit(['id' => 678678678], 'asdf');
}
@ -201,7 +195,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersHistory()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->ordersHistory();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -214,7 +208,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersList()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->ordersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -238,7 +232,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersFixExternalIdsException()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$client->request->ordersFixExternalIds([]);
}
@ -247,7 +241,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersFixExternalIds()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->ordersCreate([
'firstName' => 'Aaa',
@ -292,7 +286,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$client->request->ordersUpload([]);
}
@ -301,7 +295,7 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersUpload()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
@ -335,7 +329,8 @@ class ApiClientOrdersTest extends TestCase
*/
public function testOrdersCombine()
{
$client = static::getApiClient(null, null, "v5");
self::markTestSkipped('Should be fixed.');
$client = static::getApiClient();
$responseCreateFirst = $client->request->ordersCreate([
'firstName' => 'Aaa111',
@ -372,7 +367,7 @@ class ApiClientOrdersTest extends TestCase
public function testOrdersPayment()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$externalId = 'AA-' . time();
$responseCreateFirst = $client->request->ordersCreate([
@ -403,10 +398,8 @@ class ApiClientOrdersTest extends TestCase
$paymentEdit = [
'id' => $response['id'],
'externalId' => $externalId,
'amount' => 1500,
'comment' => 'test payment!',
'type' => 'cash',
'status' => 'paid'
];
@ -414,7 +407,14 @@ class ApiClientOrdersTest extends TestCase
static::assertTrue(
$responseAgain->isSuccessful(),
'Got payment'
'Edit payment'
);
$responseLast = $client->request->ordersPaymentDelete($response['id']);
static::assertTrue(
$responseLast->isSuccessful(),
'Delete payment'
);
}
}

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -32,7 +26,7 @@ class ApiClientPacksTest extends TestCase
*/
public function testPacksHistory()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->ordersPacksHistory();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -53,7 +47,8 @@ class ApiClientPacksTest extends TestCase
*/
public function testPacksCreateFailed()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$pack = [
'itemId' => 12,
'store' => 'test',

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -33,8 +27,7 @@ class ApiClientPricesTest extends TestCase
*/
public function testPricesEdit()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->pricesTypesEdit(
[
@ -56,8 +49,7 @@ class ApiClientPricesTest extends TestCase
*/
public function testPricesGet()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->pricesTypes();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
@ -72,7 +64,7 @@ class ApiClientPricesTest extends TestCase
*/
public function testPricesUploadExceptionEmpty()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$client->request->storePricesUpload([]);
}
@ -82,7 +74,8 @@ class ApiClientPricesTest extends TestCase
*/
public function testPricesUpload()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$xmlIdA = 'upload-a-' . time();
$xmlIdB = 'upload-b-' . time();

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -34,9 +28,11 @@ class ApiClientReferenceTest extends TestCase
*/
public function testList($name)
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$method = $name . 'List';
echo $method;
$response = $client->request->$method();
/* @var \RetailCrm\Response\ApiResponse $response */
@ -56,7 +52,8 @@ class ApiClientReferenceTest extends TestCase
*/
public function testEditingException($name)
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$method = $name . 'Edit';
$client->request->$method([]);
@ -70,7 +67,8 @@ class ApiClientReferenceTest extends TestCase
*/
public function testEditing($name)
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';
@ -104,7 +102,8 @@ class ApiClientReferenceTest extends TestCase
public function testSiteEditing()
{
$name = 'sites';
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$code = 'dict-' . strtolower($name) . '-' . time();
$method = $name . 'Edit';
@ -132,6 +131,40 @@ class ApiClientReferenceTest extends TestCase
}
}
/**
* @group reference_v5
*/
public function testUnitsEditing()
{
$client = static::getApiClient();
$unit = [
'code' => 'test',
'name' => 'Test',
'sym' => 'tst'
];
$response = $client->request->unitsEdit($unit);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
}
/**
* @group reference_v5
* @expectedException \InvalidArgumentException
*/
public function testUnitsEditingFail()
{
$client = static::getApiClient();
$unit = [
'name' => 'Test',
'sym' => 'tst'
];
$client->request->unitsEdit($unit);
}
/**
* @return array
*/
@ -149,6 +182,9 @@ class ApiClientReferenceTest extends TestCase
['statuses'],
['sites'],
['stores'],
['couriers'],
['costs'],
['units']
];
}

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -31,11 +25,12 @@ class ApiClientStoreTest extends TestCase
const SCODE = 'test-store-v5';
/**
* @group store_v4
* @group store_v5
*/
public function testStoreCreate()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->storesEdit(['name' => self::SNAME, 'code' => self::SCODE]);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -44,11 +39,12 @@ class ApiClientStoreTest extends TestCase
}
/**
* @group store_v4
* @group store_v5
*/
public function testStoreInventories()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->storeInventories();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -61,21 +57,23 @@ class ApiClientStoreTest extends TestCase
}
/**
* @group store_v4
* @group store_v5
* @expectedException \InvalidArgumentException
*/
public function testInventoriesException()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$client->request->storeInventoriesUpload([]);
}
/**
* @group store_v4
* @group store_v5
*/
public function testInventoriesUpload()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->storeInventoriesUpload([
[
@ -105,11 +103,12 @@ class ApiClientStoreTest extends TestCase
}
/**
* @group integration
* @group store_v5
*/
public function testInventoriesFailed()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$externalIdA = 'upload-a-' . time();
$externalIdB = 'upload-b-' . time();
@ -132,11 +131,12 @@ class ApiClientStoreTest extends TestCase
}
/**
* @group store_v4
* @group store_v5
*/
public function testStoreProducts()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->storeProducts();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -145,15 +145,26 @@ class ApiClientStoreTest extends TestCase
}
/**
* @group store_v4
* @group store_v5
*/
public function testStoreProductsGroups()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->storeProductsGroups();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group store_v5
* @expectedException \InvalidArgumentException
*/
public function testStoreSettingsGet()
{
$client = static::getApiClient();
$client->request->storeSettingsGet(self::SCODE);
}
}

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -32,8 +26,8 @@ class ApiClientTasksTest extends TestCase
*/
public function testTasksList()
{
$client = static::getApiClient(null, null, 'v5');
$client = static::getApiClient();
$response = $client->request->tasksList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -46,18 +40,18 @@ class ApiClientTasksTest extends TestCase
*/
public function testTasksCreateExceptionEmpty()
{
$client = static::getApiClient(null, null, 'v5');
$client = static::getApiClient();
$client->request->tasksCreate([]);
}
public function testTasksCRU()
{
$client = static::getApiClient(null, null, 'v5');
$client = static::getApiClient();
$user = getenv('RETAILCRM_USER') ?: $_SERVER['RETAILCRM_USER'];
$task = [
'text' => 'test task',
'commentary' => 'test task commentary',
'performerId' => $_SERVER['CRM_USER_ID'],
'performerId' => $user,
'complete' => false
];

View File

@ -7,9 +7,6 @@
*
* @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;
@ -20,9 +17,6 @@ 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
{
@ -31,50 +25,6 @@ class ApiClientTelephonyTest extends TestCase
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
*
@ -84,15 +34,14 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonyEvent()
{
$client = static::getApiClient(null, null, "v5");
self::markTestSkipped('Should be fixed.');
$client = static::getApiClient();
$response = $client->request->telephonyCallEvent(
'+79999999999',
'in',
['101'],
'failed',
'+74950000000'
);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -109,8 +58,8 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonyUpload()
{
$client = static::getApiClient(null, null, "v5");
self::markTestSkipped('Should be fixed.');
$client = static::getApiClient();
$response = $client->request->telephonyCallsUpload(
[
[
@ -148,12 +97,22 @@ class ApiClientTelephonyTest extends TestCase
*/
public function testTelephonyManager()
{
$client = static::getApiClient(null, null, "v5");
self::markTestSkipped('Should be fixed.');
$client = static::getApiClient();
$response = $client->request->telephonyCallManager('+79999999999', 1);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertEquals(200, $response->getStatusCode());
static::assertTrue($response->isSuccessful());
}
/**
* @group telephony_v5
* @expectedException \InvalidArgumentException
*/
public function testTelephonySettingsGet()
{
$client = static::getApiClient();
$client->request->telephonySettingsGet(self::TEL_CODE);
}
}

View File

@ -7,9 +7,6 @@
*
* @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;
@ -21,9 +18,6 @@ use RetailCrm\Test\TestCase;
*
* @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
{
@ -32,7 +26,7 @@ class ApiClientUsersTest extends TestCase
*/
public function testUsersGroups()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->usersGroups();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -45,7 +39,7 @@ class ApiClientUsersTest extends TestCase
*/
public function testUsersList()
{
$client = static::getApiClient(null, null, "v5");
$client = static::getApiClient();
$response = $client->request->usersList();
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
@ -58,9 +52,9 @@ class ApiClientUsersTest extends TestCase
*/
public function testUsersGet()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->usersGet($_SERVER["CRM_USER_ID"]);
$client = static::getApiClient();
$user = getenv('RETAILCRM_USER') ?: $_SERVER['RETAILCRM_USER'];
$response = $client->request->usersGet($user);
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());
@ -71,9 +65,9 @@ class ApiClientUsersTest extends TestCase
*/
public function testUsersStatus()
{
$client = static::getApiClient(null, null, "v5");
$response = $client->request->usersStatus($_SERVER["CRM_USER_ID"], 'dinner');
$client = static::getApiClient();
$user = getenv('RETAILCRM_USER') ?: $_SERVER['RETAILCRM_USER'];
$response = $client->request->usersStatus($user, 'dinner');
static::assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
static::assertTrue($response->isSuccessful());

Binary file not shown.

View File

@ -7,9 +7,6 @@
*
* @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\Response;
@ -22,9 +19,6 @@ use RetailCrm\Response\ApiResponse;
*
* @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 ApiResponseTest extends TestCase
{
@ -40,7 +34,7 @@ class ApiResponseTest extends TestCase
'Response object created'
);
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
static::assertInstanceOf(
'RetailCrm\Response\ApiResponse',
$response,
@ -54,7 +48,20 @@ class ApiResponseTest extends TestCase
*/
public function testJsonInvalid()
{
new ApiResponse(400, '{ "asdf": }');
(new ApiResponse(400, '{ "asdf": }'))->asJsonResponse();
}
/**
* @group response
*/
public function testJsonInvalidNoDeserialize()
{
$response = new ApiResponse(400, '{ "asdf": }');
static::assertInstanceOf(
'RetailCrm\Response\ApiResponse',
$response,
'Response object created'
);
}
/**
@ -69,7 +76,7 @@ class ApiResponseTest extends TestCase
'Response object returns the right status code'
);
$response = new ApiResponse(460, '{ "success": false }');
$response = (new ApiResponse(460, '{ "success": false }'))->asJsonResponse();
static::assertEquals(
460,
$response->getStatusCode(),
@ -88,7 +95,7 @@ class ApiResponseTest extends TestCase
'Request was successful'
);
$response = new ApiResponse(460, '{ "success": false }');
$response = (new ApiResponse(460, '{ "success": false }'))->asJsonResponse();
static::assertFalse(
$response->isSuccessful(),
'Request was failed'
@ -100,7 +107,7 @@ class ApiResponseTest extends TestCase
*/
public function testMagicCall()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
static::assertEquals(
true,
$response->isSuccessful(),
@ -115,6 +122,7 @@ class ApiResponseTest extends TestCase
public function testMagicCallException1()
{
$response = new ApiResponse(200);
/* @noinspection PhpUndefinedMethodInspection */
$response->getSome();
}
@ -124,7 +132,8 @@ class ApiResponseTest extends TestCase
*/
public function testMagicCallException2()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
/* @noinspection PhpUndefinedMethodInspection */
$response->getSomeSuccess();
}
@ -133,7 +142,7 @@ class ApiResponseTest extends TestCase
*/
public function testMagicGet()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
static::assertEquals(
true,
$response->success,
@ -148,6 +157,7 @@ class ApiResponseTest extends TestCase
public function testMagicGetException1()
{
$response = new ApiResponse(200);
/* @noinspection PhpUndefinedFieldInspection */
$response->some;
}
@ -157,7 +167,8 @@ class ApiResponseTest extends TestCase
*/
public function testMagicGetException2()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
/* @noinspection PhpUndefinedFieldInspection */
$response->someSuccess;
}
@ -166,7 +177,7 @@ class ApiResponseTest extends TestCase
*/
public function testArrayGet()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
static::assertEquals(
true,
$response['success'],
@ -190,7 +201,7 @@ class ApiResponseTest extends TestCase
*/
public function testArrayGetException2()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
$response['someSuccess'];
}
@ -199,7 +210,7 @@ class ApiResponseTest extends TestCase
*/
public function testArrayIsset()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
static::assertTrue(
isset($response['success']),
@ -218,7 +229,7 @@ class ApiResponseTest extends TestCase
*/
public function testArraySetException1()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
$response['success'] = 'a';
}
@ -228,7 +239,7 @@ class ApiResponseTest extends TestCase
*/
public function testArraySetException2()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
$response['sssssssuccess'] = 'a';
}
@ -238,7 +249,7 @@ class ApiResponseTest extends TestCase
*/
public function testArrayUnsetException1()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
unset($response['success']);
}
@ -248,7 +259,7 @@ class ApiResponseTest extends TestCase
*/
public function testArrayUnsetException2()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
unset($response['sssssssuccess']);
}
@ -257,7 +268,7 @@ class ApiResponseTest extends TestCase
*/
public function testMagicIsset()
{
$response = new ApiResponse(201, '{ "success": true }');
$response = (new ApiResponse(201, '{ "success": true }'))->asJsonResponse();
static::assertTrue(
isset($response->success),

View File

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