/api/v5/orders/loyalty/cancel-bonus-operations
support
This commit is contained in:
commit
cfa975db17
@ -38,7 +38,6 @@
|
||||
"symfony/cache": ">=v3.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-http/mock-client": "^1.0",
|
||||
"squizlabs/php_codesniffer": "^3.5",
|
||||
"phpmd/phpmd": "^2.10",
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
|
||||
|
@ -176,6 +176,14 @@ class Order
|
||||
*/
|
||||
public $personalDiscountPercent;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Api\Model\Entity\Orders\OrderLoyaltyAccount
|
||||
*
|
||||
* @JMS\Type("RetailCrm\Api\Model\Entity\Orders\OrderLoyaltyAccount")
|
||||
* @JMS\SerializedName("loyaltyAccount")
|
||||
*/
|
||||
public $loyaltyAccount;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Api\Model\Entity\Loyalty\LoyaltyLevel
|
||||
*
|
||||
|
37
src/Model/Entity/Orders/OrderLoyaltyAccount.php
Normal file
37
src/Model/Entity/Orders/OrderLoyaltyAccount.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.3
|
||||
*
|
||||
* @category OrderLoyaltyAccount
|
||||
* @package RetailCrm\Api\Model\Entity\Orders
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Api\Model\Entity\Orders;
|
||||
|
||||
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||
|
||||
/**
|
||||
* Class OrderLoyaltyAccount
|
||||
*
|
||||
* @category OrderLoyaltyAccount
|
||||
* @package RetailCrm\Api\Model\Entity\Orders
|
||||
*/
|
||||
class OrderLoyaltyAccount
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @JMS\Type("int")
|
||||
* @JMS\SerializedName("id")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @JMS\Type("float")
|
||||
* @JMS\SerializedName("amount")
|
||||
*/
|
||||
public $amount;
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP 7.3
|
||||
*
|
||||
* @category OrderLoyaltyCancelBonusOperationsRequest
|
||||
* @package RetailCrm\Api\Model\Request\Orders
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Api\Model\Request\Orders;
|
||||
|
||||
use RetailCrm\Api\Component\FormData\Mapping as Form;
|
||||
use RetailCrm\Api\Interfaces\RequestInterface;
|
||||
use RetailCrm\Api\Model\Entity\Delivery\SerializedEntityOrder;
|
||||
|
||||
/**
|
||||
* Class OrderLoyaltyCancelBonusOperationsRequest
|
||||
*
|
||||
* @category OrderLoyaltyCancelBonusOperationsRequest
|
||||
* @package RetailCrm\Api\Model\Request\Orders
|
||||
*/
|
||||
class OrderLoyaltyCancelBonusOperationsRequest implements RequestInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @Form\Type("string")
|
||||
* @Form\SerializedName("site")
|
||||
*/
|
||||
public $site;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Api\Model\Entity\Delivery\SerializedEntityOrder
|
||||
*
|
||||
* @Form\Type("RetailCrm\Api\Model\Entity\Orders\SerializedEntityOrder")
|
||||
* @Form\SerializedName("order")
|
||||
* @Form\JsonField()
|
||||
*/
|
||||
public $order;
|
||||
|
||||
/**
|
||||
* OrderLoyaltyCancelBonusOperationsRequest constructor.
|
||||
*
|
||||
* @param \RetailCrm\Api\Model\Entity\Delivery\SerializedEntityOrder|null $order
|
||||
* @param string $site
|
||||
*/
|
||||
public function __construct(SerializedEntityOrder $order = null, string $site = '')
|
||||
{
|
||||
$this->order = $order ?? new SerializedEntityOrder();
|
||||
$this->site = $site;
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ namespace RetailCrm\Api\ResourceGroup;
|
||||
|
||||
use RetailCrm\Api\Enum\RequestMethod;
|
||||
use RetailCrm\Api\Model\Request\BySiteRequest;
|
||||
use RetailCrm\Api\Model\Request\Orders\OrderLoyaltyCancelBonusOperationsRequest;
|
||||
use RetailCrm\Api\Model\Request\Orders\OrdersCombineRequest;
|
||||
use RetailCrm\Api\Model\Request\Orders\OrdersCreateRequest;
|
||||
use RetailCrm\Api\Model\Request\Orders\OrdersEditRequest;
|
||||
@ -549,6 +550,66 @@ class Orders extends AbstractApiResourceGroup
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes POST "/api/v5/orders/loyalty/cancel-bonus-operations" request.
|
||||
*
|
||||
* Example:
|
||||
* ```php
|
||||
* use RetailCrm\Api\Factory\SimpleClientFactory;
|
||||
* use RetailCrm\Api\Interfaces\ApiExceptionInterface;
|
||||
* use RetailCrm\Api\Model\Entity\Delivery\SerializedEntityOrder;
|
||||
* use RetailCrm\Api\Model\Request\Orders\OrderLoyaltyCancelBonusOperationsRequest;
|
||||
*
|
||||
* $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
|
||||
* $request = new OrderLoyaltyCancelBonusOperationsRequest(
|
||||
* SerializedEntityOrder::withId(7751),
|
||||
* 'bitrix-test'
|
||||
* );
|
||||
*
|
||||
* try {
|
||||
* $response = $client->orders->cancelBonusOperations($request);
|
||||
* } catch (ApiExceptionInterface $exception) {
|
||||
* echo sprintf(
|
||||
* 'Error from RetailCRM API (status code: %d): %s',
|
||||
* $exception->getStatusCode(),
|
||||
* $exception->getMessage()
|
||||
* );
|
||||
*
|
||||
* if (count($exception->getErrorResponse()->errors) > 0) {
|
||||
* echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
|
||||
* }
|
||||
*
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
* echo 'Current loyalty account balance: ' . $response->order->loyaltyAccount->amount . ' bonuses.';
|
||||
* ```
|
||||
*
|
||||
* @param \RetailCrm\Api\Model\Request\Orders\OrderLoyaltyCancelBonusOperationsRequest $request
|
||||
*
|
||||
* @return \RetailCrm\Api\Model\Response\Orders\OrdersGetResponse
|
||||
* @throws \RetailCrm\Api\Exception\Api\AccountDoesNotExistException
|
||||
* @throws \RetailCrm\Api\Exception\Api\ApiErrorException
|
||||
* @throws \RetailCrm\Api\Exception\Api\MissingCredentialsException
|
||||
* @throws \RetailCrm\Api\Exception\Api\MissingParameterException
|
||||
* @throws \RetailCrm\Api\Exception\Api\ValidationException
|
||||
* @throws \RetailCrm\Api\Exception\Client\HandlerException
|
||||
* @throws \RetailCrm\Api\Exception\Client\HttpClientException
|
||||
* @throws \RetailCrm\Api\Interfaces\ApiExceptionInterface
|
||||
* @throws \RetailCrm\Api\Interfaces\ClientExceptionInterface
|
||||
*/
|
||||
public function cancelBonusOperations(OrderLoyaltyCancelBonusOperationsRequest $request): OrdersGetResponse
|
||||
{
|
||||
/** @var OrdersGetResponse $response */
|
||||
$response = $this->sendRequest(
|
||||
RequestMethod::POST,
|
||||
'orders/loyalty/cancel-bonus-operations',
|
||||
$request,
|
||||
OrdersGetResponse::class
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes POST "/api/v5/orders/payments/create" request.
|
||||
*
|
||||
|
@ -35,6 +35,7 @@ use RetailCrm\Api\Model\Entity\Orders\SerializedRelationCustomer;
|
||||
use RetailCrm\Api\Model\Filter\Orders\OrderFilter;
|
||||
use RetailCrm\Api\Model\Filter\Orders\OrderHistoryFilterV4Type;
|
||||
use RetailCrm\Api\Model\Request\BySiteRequest;
|
||||
use RetailCrm\Api\Model\Request\Orders\OrderLoyaltyCancelBonusOperationsRequest;
|
||||
use RetailCrm\Api\Model\Request\Orders\OrdersCombineRequest;
|
||||
use RetailCrm\Api\Model\Request\Orders\OrdersCreateRequest;
|
||||
use RetailCrm\Api\Model\Request\Orders\OrdersEditRequest;
|
||||
@ -7493,6 +7494,72 @@ EOF;
|
||||
self::assertModelEqualsToResponse($json, $response);
|
||||
}
|
||||
|
||||
public function testCancelBonusOperations(): void
|
||||
{
|
||||
$json = <<<'EOF'
|
||||
{
|
||||
"success": true,
|
||||
"order": {
|
||||
"bonusesCreditTotal": 0,
|
||||
"bonusesChargeTotal": 0,
|
||||
"privilegeType": "none",
|
||||
"totalSumm": 1279,
|
||||
"loyaltyAccount": {
|
||||
"id": 164,
|
||||
"amount": 1000
|
||||
},
|
||||
"delivery": {
|
||||
"cost": 500
|
||||
},
|
||||
"site": "bitrix-test",
|
||||
"items": [
|
||||
{
|
||||
"bonusesChargeTotal": 0,
|
||||
"bonusesCreditTotal": 0,
|
||||
"discounts": [],
|
||||
"id": 12153,
|
||||
"externalIds": [
|
||||
{
|
||||
"code": "bitrix",
|
||||
"value": "0_169"
|
||||
}
|
||||
],
|
||||
"initialPrice": 779,
|
||||
"discountTotal": 0,
|
||||
"prices": [
|
||||
{
|
||||
"price": 779,
|
||||
"quantity": 1
|
||||
}
|
||||
],
|
||||
"quantity": 1,
|
||||
"offer": {
|
||||
"id": 66445,
|
||||
"externalId": "169"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
EOF;
|
||||
|
||||
$request = new OrderLoyaltyCancelBonusOperationsRequest(
|
||||
SerializedEntityOrder::withId(7751),
|
||||
'bitrix-test'
|
||||
);
|
||||
$mock = static::createApiMockBuilder('orders/loyalty/cancel-bonus-operations');
|
||||
|
||||
$mock->matchMethod(RequestMethod::POST)
|
||||
->matchBody(static::encodeForm($request))
|
||||
->reply(200)
|
||||
->withBody($json);
|
||||
|
||||
$client = TestClientFactory::createClient($mock->getClient());
|
||||
$response = $client->orders->cancelBonusOperations($request);
|
||||
|
||||
self::assertModelEqualsToResponse($json, $response);
|
||||
}
|
||||
|
||||
public function testPaymentsCreate(): void
|
||||
{
|
||||
$json = <<<'EOF'
|
||||
|
Loading…
Reference in New Issue
Block a user