From 9c6029fa0df20489585bb0f2c2555e7fe8ea2caa Mon Sep 17 00:00:00 2001 From: tishmaria90 Date: Tue, 28 Sep 2021 11:20:48 +0300 Subject: [PATCH] add applyRound and loyaltyLevelId params (#119) --- .../Entity/Delivery/SerializedEntityOrder.php | 24 ++++++++++++++++++- src/Model/Entity/Loyalty/LoyaltyAccount.php | 8 +++++++ src/Model/Entity/Loyalty/SerializedOrder.php | 8 +++++++ src/Model/Entity/Orders/Order.php | 8 +++++++ tests/src/ResourceGroup/LoyaltyTest.php | 15 ++++++++++++ tests/src/ResourceGroup/OrdersTest.php | 19 +++++++++++++-- 6 files changed, 79 insertions(+), 3 deletions(-) diff --git a/src/Model/Entity/Delivery/SerializedEntityOrder.php b/src/Model/Entity/Delivery/SerializedEntityOrder.php index 7ffbf97..0e9c7be 100644 --- a/src/Model/Entity/Delivery/SerializedEntityOrder.php +++ b/src/Model/Entity/Delivery/SerializedEntityOrder.php @@ -43,10 +43,18 @@ class SerializedEntityOrder */ public $number; + /** + * @var bool + * + * @JMS\Type("bool") + * @JMS\SerializedName("applyRound") + */ + public $applyRound; + /** * SerializedEntityOrder constructor. * - * @param int $id + * @param int $id * @param string $externalId * @param string $number */ @@ -101,4 +109,18 @@ class SerializedEntityOrder { return new self(0, '', $number); } + + /** + * Set applyRound and return this entity + * + * @param bool $applyRound + * + * @return $this + */ + public function setApplyRound(bool $applyRound): self + { + $this->applyRound = $applyRound; + + return $this; + } } diff --git a/src/Model/Entity/Loyalty/LoyaltyAccount.php b/src/Model/Entity/Loyalty/LoyaltyAccount.php index b083e50..5c10278 100644 --- a/src/Model/Entity/Loyalty/LoyaltyAccount.php +++ b/src/Model/Entity/Loyalty/LoyaltyAccount.php @@ -147,4 +147,12 @@ class LoyaltyAccount * @JMS\SerializedName("loyalty") */ public $loyalty; + + /** + * @var int + * + * @JMS\Type("int") + * @JMS\SerializedName("loyaltyLevelId") + */ + public $loyaltyLevelId; } diff --git a/src/Model/Entity/Loyalty/SerializedOrder.php b/src/Model/Entity/Loyalty/SerializedOrder.php index d7ba517..9a7dc05 100644 --- a/src/Model/Entity/Loyalty/SerializedOrder.php +++ b/src/Model/Entity/Loyalty/SerializedOrder.php @@ -68,4 +68,12 @@ class SerializedOrder * @JMS\SerializedName("delivery") */ public $delivery; + + /** + * @var bool + * + * @JMS\Type("bool") + * @JMS\SerializedName("applyRound") + */ + public $applyRound; } diff --git a/src/Model/Entity/Orders/Order.php b/src/Model/Entity/Orders/Order.php index 0ced6ca..6015887 100644 --- a/src/Model/Entity/Orders/Order.php +++ b/src/Model/Entity/Orders/Order.php @@ -503,4 +503,12 @@ class Order * @JMS\SerializedName("loyaltyEventId") */ public $loyaltyEventId; + + /** + * @var bool + * + * @JMS\Type("bool") + * @JMS\SerializedName("applyRound") + */ + public $applyRound; } diff --git a/tests/src/ResourceGroup/LoyaltyTest.php b/tests/src/ResourceGroup/LoyaltyTest.php index 1d37c23..9a6a2bc 100644 --- a/tests/src/ResourceGroup/LoyaltyTest.php +++ b/tests/src/ResourceGroup/LoyaltyTest.php @@ -12,6 +12,7 @@ namespace RetailCrm\Tests\ResourceGroup; use DateInterval; use DateTime; use DateTimeInterface; +use Psr\Http\Message\RequestInterface; use RetailCrm\Api\Component\Transformer\DateTimeTransformer; use RetailCrm\Api\Enum\Loyalty\AccountStatus; use RetailCrm\Api\Enum\Loyalty\PrivilegeType; @@ -234,12 +235,19 @@ EOF; $account = new LoyaltyAccount(); $account->cardNumber = '4444 5555 6666 7777'; $account->phoneNumber = '88005553000'; + $account->loyaltyLevelId = 1; $request = new LoyaltyAccountEditRequest($account); $mock = static::createApiMockBuilder('loyalty/account/159/edit'); $mock->matchMethod(RequestMethod::POST) ->matchBody(static::encodeForm($request)) + ->matchCallback(static function (RequestInterface $request) { + $data = []; + parse_str((string) $request->getBody(), $data); + + return false !== strpos($data['loyaltyAccount'] ?? '', '"loyaltyLevelId"'); + }) ->reply(200) ->withBody($json); @@ -700,6 +708,7 @@ EOF; $order->items = [$item]; $order->delivery = new SerializedOrderDelivery(100); $order->privilegeType = PrivilegeType::NONE; + $order->applyRound = true; $request = new LoyaltyCalculateRequest(); $request->site = 'bitrix-test'; @@ -709,6 +718,12 @@ EOF; $mock = static::createApiMockBuilder('loyalty/calculate'); $mock->matchMethod(RequestMethod::POST) ->matchBody(static::encodeForm($request)) + ->matchCallback(static function (RequestInterface $request) { + $data = []; + parse_str((string) $request->getBody(), $data); + + return false !== strpos($data['order'] ?? '', '"applyRound"'); + }) ->reply(200) ->withBody($json); diff --git a/tests/src/ResourceGroup/OrdersTest.php b/tests/src/ResourceGroup/OrdersTest.php index ee6015f..53710a1 100644 --- a/tests/src/ResourceGroup/OrdersTest.php +++ b/tests/src/ResourceGroup/OrdersTest.php @@ -529,6 +529,7 @@ EOF; "call": false, "expired": false, "managerId": 28, + "applyRound": true, "customer": { "type": "customer", "id": 4924, @@ -7486,12 +7487,18 @@ EOF; $request = new OrdersLoyaltyApplyRequest(); $request->site = 'bitrix-test'; - $request->order = SerializedEntityOrder::withNumber('7'); + $request->order = SerializedEntityOrder::withNumber('7')->setApplyRound(true); $request->bonuses = 10; $mock = static::createApiMockBuilder('orders/loyalty/apply'); $mock->matchMethod(RequestMethod::POST) ->matchBody(static::encodeForm($request)) + ->matchCallback(static function (RequestInterface $request) { + $data = []; + parse_str((string) $request->getBody(), $data); + + return false !== strpos($data['order'] ?? '', '"applyRound"'); + }) ->reply(200) ->withBody($json); @@ -7551,13 +7558,19 @@ EOF; EOF; $request = new OrderLoyaltyCancelBonusOperationsRequest( - SerializedEntityOrder::withId(7751), + SerializedEntityOrder::withId(7751)->setApplyRound(true), 'bitrix-test' ); $mock = static::createApiMockBuilder('orders/loyalty/cancel-bonus-operations'); $mock->matchMethod(RequestMethod::POST) ->matchBody(static::encodeForm($request)) + ->matchCallback(static function (RequestInterface $request) { + $data = []; + parse_str((string) $request->getBody(), $data); + + return false !== strpos($data['order'] ?? '', '"applyRound"'); + }) ->reply(200) ->withBody($json); @@ -7708,6 +7721,7 @@ EOF; "call": false, "expired": false, "managerId": 28, + "applyRound": true, "customer": { "type": "customer", "id": 4924, @@ -8511,6 +8525,7 @@ EOF; "call": false, "expired": false, "managerComment": "Manager comment", + "applyRound": true, "customer": { "type": "customer", "id": 4976,