diff --git a/composer.json b/composer.json index 8f5e302..b4277b4 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -113,4 +112,4 @@ "bin-dir": "vendor/bin", "process-timeout": 600 } -} \ No newline at end of file +} diff --git a/src/Model/Entity/Orders/Order.php b/src/Model/Entity/Orders/Order.php index b601e53..0ced6ca 100644 --- a/src/Model/Entity/Orders/Order.php +++ b/src/Model/Entity/Orders/Order.php @@ -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 * diff --git a/src/Model/Entity/Orders/OrderLoyaltyAccount.php b/src/Model/Entity/Orders/OrderLoyaltyAccount.php new file mode 100644 index 0000000..dde4af4 --- /dev/null +++ b/src/Model/Entity/Orders/OrderLoyaltyAccount.php @@ -0,0 +1,37 @@ +order = $order ?? new SerializedEntityOrder(); + $this->site = $site; + } +} diff --git a/src/ResourceGroup/Orders.php b/src/ResourceGroup/Orders.php index 5f760ed..63a468f 100644 --- a/src/ResourceGroup/Orders.php +++ b/src/ResourceGroup/Orders.php @@ -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. * diff --git a/tests/src/ResourceGroup/OrdersTest.php b/tests/src/ResourceGroup/OrdersTest.php index 9a88667..d0018e5 100644 --- a/tests/src/ResourceGroup/OrdersTest.php +++ b/tests/src/ResourceGroup/OrdersTest.php @@ -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'