diff --git a/src/Model/Request/Loyalty/LoyaltyBonusChargeRequest.php b/src/Model/Request/Loyalty/LoyaltyBonusChargeRequest.php new file mode 100644 index 0000000..0d6800c --- /dev/null +++ b/src/Model/Request/Loyalty/LoyaltyBonusChargeRequest.php @@ -0,0 +1,39 @@ +amount = 100; + * $request->comment = 'Payment for the goods.'; + * + * try { + * $response = $client->loyalty->accountBonusCharge(159, $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 'Status: ' . var_export($response->success, true); + * ``` + * + * @param int $id + * @param \RetailCrm\Api\Model\Request\Loyalty\LoyaltyBonusChargeRequest $request + * + * @return \RetailCrm\Api\Model\Response\Loyalty\LoyaltyBonusCreditResponse + * @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 accountBonusCharge(int $id, LoyaltyBonusChargeRequest $request): SuccessResponse + { + /** @var LoyaltyBonusCreditResponse $response */ + $response = $this->sendRequest( + RequestMethod::POST, + 'loyalty/account/' . $id . '/bonus/charge', + $request, + SuccessResponse::class + ); + return $response; + } + /** * Makes POST "/api/v5/loyalty/account/{id}/bonus/credit" request. * diff --git a/tests/src/ResourceGroup/LoyaltyTest.php b/tests/src/ResourceGroup/LoyaltyTest.php index 4f6b85f..a281a8d 100644 --- a/tests/src/ResourceGroup/LoyaltyTest.php +++ b/tests/src/ResourceGroup/LoyaltyTest.php @@ -38,6 +38,7 @@ use RetailCrm\Api\Model\Request\Loyalty\LoyaltiesRequest; use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountCreateRequest; use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountEditRequest; use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountsRequest; +use RetailCrm\Api\Model\Request\Loyalty\LoyaltyBonusChargeRequest; use RetailCrm\Api\Model\Request\Loyalty\LoyaltyBonusCreditRequest; use RetailCrm\Api\Model\Request\Loyalty\LoyaltyBonusOperationsRequest; use RetailCrm\Api\Model\Request\Loyalty\LoyaltyCalculateRequest; @@ -121,6 +122,29 @@ EOF; self::assertModelEqualsToResponse($json, $response); } + public function testAccountBonusCharge(): void + { + $json = <<amount = 100; + $request->comment = 'Monthly membership bonuses.'; + + $mock = static::createApiMockBuilder('loyalty/account/159/bonus/charge'); + $mock->matchMethod(RequestMethod::POST) + ->reply(200) + ->withBody($json); + + $client = TestClientFactory::createClient($mock->getClient()); + $response = $client->loyalty->accountBonusCharge(159, $request); + + self::assertModelEqualsToResponse($json, $response); + } + public function testAccountBonusCredit(): void { $activationDate = new DateTime();