diff --git a/lib/RetailCrm/Methods/V5/Orders.php b/lib/RetailCrm/Methods/V5/Orders.php index f2a72409b..490d23c15 100644 --- a/lib/RetailCrm/Methods/V5/Orders.php +++ b/lib/RetailCrm/Methods/V5/Orders.php @@ -225,4 +225,35 @@ public function ordersLinksCreate(array $links, $site = null) ) ); } + + /** + * Cancellation of bonus operations on the Loyalty Program + * + * @param array $order order data + * @param string|null $site (default: null) + * + * @throws \RetailCrm\Exception\InvalidJsonException + * @throws \RetailCrm\Exception\CurlException + * @throws \InvalidArgumentException + * + * @return \RetailCrm\Response\ApiResponse + */ + public function cancelBonusOperations(array $order, $site = null) + { + if (!isset($order['id']) && !isset($order['externalId']) && !isset($order['number'])) { + throw new \InvalidArgumentException( + 'Parameters `order` must contains a identifying data' + ); + } + + /* @noinspection PhpUndefinedMethodInspection */ + return $this->client->makeRequest( + '/orders/loyalty/cancel-bonus-operations', + 'POST', + $this->fillSite( + $site, + ['order' => json_encode($order)] + ) + ); + } } diff --git a/tests/RetailCrm/Tests/Methods/Version5/ApiClientOrdersTest.php b/tests/RetailCrm/Tests/Methods/Version5/ApiClientOrdersTest.php index 79b15a8fd..d75b012ee 100644 --- a/tests/RetailCrm/Tests/Methods/Version5/ApiClientOrdersTest.php +++ b/tests/RetailCrm/Tests/Methods/Version5/ApiClientOrdersTest.php @@ -443,6 +443,33 @@ public function testOrdersLoyaltyApply(array $order, float $bonuses, string $sit } } + /** + * @dataProvider ordersLoyaltyCancelBonus + * + * @group orders_v5 + * + * @param array $order + * @param string $site + * @param string|null $exceptionClass + * + * @return void + */ + public function testCancelBonusOperations(array $order, string $site, $exceptionClass) + { + $client = static::getApiClient(); + + if (isset($exceptionClass)) { + $this->expectException($exceptionClass); + } + + $response = $client->request->cancelBonusOperations($order, $site); + + if (!isset($exceptionClass)) { + static::assertContains($response->getStatusCode(), [200, 201]); + static::assertTrue($response->isSuccessful()); + } + } + /** * @return array[] */ @@ -497,4 +524,39 @@ public function ordersLoyaltyApplyProvider(): array ], ]; } + + /** + * @return array + */ + public function ordersLoyaltyCancelBonus(): array + { + return [ + 'success_id' => [ + [ + 'id' => 111111111, + ], + 'site', + null, + ], + 'success_externalId' => [ + [ + 'externalId' => 111111111, + ], + 'site', + null, + ], + 'success_number' => [ + [ + 'number' => '111C' + ], + 'site', + null, + ], + 'error' => [ + [], + 'site', + 'InvalidArgumentException', + ] + ]; + } }