1
0
mirror of synced 2024-11-22 21:36:06 +03:00
api-client-php/lib/RetailCrm/Methods/V5/Orders.php

160 lines
4.1 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
2019-08-30 14:10:52 +03:00
* @link https://help.retailcrm.ru/Developers/ApiVersion5
*/
namespace RetailCrm\Methods\V5;
use RetailCrm\Methods\V4\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
2019-08-30 14:10:52 +03:00
* @link https://help.retailcrm.ru/Developers/ApiVersion5
*/
trait Orders
{
use Previous;
/**
* Combine orders
*
2018-01-10 11:35:57 +03:00
* @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')
{
2020-01-20 18:32:25 +03:00
$techniques = ['ours', 'summ', 'theirs', 'merge'];
if (!count($order) || !count($resultOrder)) {
throw new \InvalidArgumentException(
'Parameters `order` & `resultOrder` must contains a data'
);
}
if (!in_array($technique, $techniques)) {
throw new \InvalidArgumentException(
'Parameter `technique` must be on of ours|summ|theirs'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/combine',
"POST",
[
'technique' => $technique,
'order' => json_encode($order),
'resultOrder' => json_encode($resultOrder)
]
);
}
/**
* Create an order payment
*
* @param array $payment order data
2018-01-10 11:35:57 +03:00
* @param null $site site code
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPaymentCreate(array $payment, $site = null)
{
if (!count($payment)) {
throw new \InvalidArgumentException(
'Parameter `payment` must contains a data'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/orders/payments/create',
"POST",
$this->fillSite(
$site,
['payment' => json_encode($payment)]
)
);
}
/**
2018-01-10 11:35:57 +03:00
* Edit an order payment
*
* @param array $payment order data
* @param string $by by key
* @param null $site site code
*
* @return \RetailCrm\Response\ApiResponse
*/
public function ordersPaymentEdit(array $payment, $by = 'id', $site = null)
{
if (!count($payment)) {
throw new \InvalidArgumentException(
'Parameter `payment` must contains a data'
);
}
$this->checkIdParameter($by);
if (!array_key_exists($by, $payment)) {
throw new \InvalidArgumentException(
sprintf('Order array must contain the "%s" parameter.', $by)
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/orders/payments/%s/edit', $payment[$by]),
"POST",
$this->fillSite(
$site,
['payment' => json_encode($payment), 'by' => $by]
)
);
}
/**
* 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"
);
}
}