1
0
mirror of synced 2024-11-25 06:46:07 +03:00
api-client-php/lib/RetailCrm/Methods/V4/Orders.php

286 lines
7.7 KiB
PHP
Raw Normal View History

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