2017-06-22 00:55:08 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 5.4
|
|
|
|
*
|
2017-06-22 16:42:42 +03:00
|
|
|
* Orders
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace RetailCrm\Methods\V5;
|
|
|
|
|
|
|
|
use RetailCrm\Methods\V4\Orders as Previous;
|
2024-08-02 15:25:37 +03:00
|
|
|
use RetailCrm\Response\ApiResponse;
|
2017-06-22 00:55:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 5.4
|
|
|
|
*
|
2017-06-22 16:42:42 +03:00
|
|
|
* Orders class
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
*/
|
|
|
|
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
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
2024-08-02 15:25:37 +03:00
|
|
|
* @return ApiResponse
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
|
|
|
public function ordersCombine($order, $resultOrder, $technique = 'ours')
|
|
|
|
{
|
2020-01-20 18:32:25 +03:00
|
|
|
$techniques = ['ours', 'summ', 'theirs', 'merge'];
|
2017-06-22 00:55:08 +03:00
|
|
|
|
|
|
|
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'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
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
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
*
|
2024-08-02 15:25:37 +03:00
|
|
|
* @return ApiResponse
|
2017-06-22 00:55:08 +03:00
|
|
|
*/
|
2017-08-18 09:16:21 +03:00
|
|
|
public function ordersPaymentCreate(array $payment, $site = null)
|
2017-06-22 00:55:08 +03:00
|
|
|
{
|
|
|
|
if (!count($payment)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Parameter `payment` must contains a data'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/orders/payments/create',
|
|
|
|
"POST",
|
2017-08-18 09:16:21 +03:00
|
|
|
$this->fillSite(
|
|
|
|
$site,
|
|
|
|
['payment' => json_encode($payment)]
|
|
|
|
)
|
2017-06-22 00:55:08 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
*
|
2024-08-02 15:25:37 +03:00
|
|
|
* @return ApiResponse
|
2018-01-10 11:35:57 +03:00
|
|
|
*/
|
2017-06-22 00:55:08 +03:00
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
sprintf('/orders/payments/%s/edit', $payment[$by]),
|
|
|
|
"POST",
|
|
|
|
$this->fillSite(
|
|
|
|
$site,
|
|
|
|
['payment' => json_encode($payment), 'by' => $by]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2017-07-24 15:12:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit an order payment
|
|
|
|
*
|
|
|
|
* @param string $id payment id
|
|
|
|
*
|
2024-08-02 15:25:37 +03:00
|
|
|
* @return ApiResponse
|
2017-07-24 15:12:13 +03:00
|
|
|
*/
|
|
|
|
public function ordersPaymentDelete($id)
|
|
|
|
{
|
|
|
|
if (!$id) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Parameter `id` must be set'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-07-24 15:12:13 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
sprintf('/orders/payments/%s/delete', $id),
|
|
|
|
"POST"
|
|
|
|
);
|
|
|
|
}
|
2023-06-21 12:57:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Application of loyalty program bonuses
|
|
|
|
*
|
|
|
|
* @param array $payment order data
|
|
|
|
* @param float $bonuses bonuses count
|
|
|
|
* @param null $site site code
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
*
|
2024-08-02 15:25:37 +03:00
|
|
|
* @return ApiResponse
|
2023-06-21 12:57:37 +03:00
|
|
|
*/
|
|
|
|
public function ordersLoyaltyApply(array $order, float $bonuses, $site = null)
|
|
|
|
{
|
|
|
|
if (!count($order)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Parameter `order` must contains a data'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($order['id']) && empty($order['externalId'])) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Parameter `order` must contain an identifier: `id` or `externalId`'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($bonuses)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Specify a different amount of bonuses'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/orders/loyalty/apply',
|
|
|
|
"POST",
|
|
|
|
$this->fillSite(
|
|
|
|
$site,
|
|
|
|
[
|
|
|
|
'order' => json_encode($order),
|
|
|
|
'bonuses' => $bonuses,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2024-08-02 15:25:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create links between orders
|
|
|
|
*
|
|
|
|
* @param array $links links data
|
|
|
|
* @param null $site site code
|
|
|
|
*
|
|
|
|
* @return ApiResponse
|
|
|
|
*/
|
|
|
|
public function ordersLinksCreate(array $links, $site = null)
|
|
|
|
{
|
|
|
|
if (!count($links)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Parameters `links` must contains a data'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/orders/links/create',
|
|
|
|
'POST',
|
|
|
|
$this->fillSite(
|
|
|
|
$site,
|
2024-08-05 09:23:18 +03:00
|
|
|
['link' => json_encode($links)]
|
2024-08-02 15:25:37 +03:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2017-06-22 00:55:08 +03:00
|
|
|
}
|