Add new loyalty methods (#121)
* add supporting /api/v5/loyalty/account/{}/bonus/{0}/details method * repair example for getBonusAccountDetails * add catcher ApiExceptionInterfaces for example for getBonusAccountDetails method
This commit is contained in:
parent
bce2bfaf4c
commit
0ada1cd922
@ -50,4 +50,12 @@ class BotConfiguration
|
||||
* @JMS\SerializedName("name")
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @JMS\Type("string")
|
||||
* @JMS\SerializedName("endpointUrl")
|
||||
*/
|
||||
public $endpointUrl;
|
||||
}
|
||||
|
37
src/Model/Entity/Loyalty/BonusDetail.php
Normal file
37
src/Model/Entity/Loyalty/BonusDetail.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.3
|
||||
*
|
||||
* @category BonusDetail
|
||||
* @package RetailCrm\Api\Model\Entity\Loyalty
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Api\Model\Entity\Loyalty;
|
||||
|
||||
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||
|
||||
/**
|
||||
* Class BonusDetail
|
||||
*
|
||||
* @category BonusDetail
|
||||
* @package RetailCrm\Api\Model\Entity\Loyalty
|
||||
*/
|
||||
class BonusDetail
|
||||
{
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @JMS\Type("DateTime<'Y-m-d H:i:s'>")
|
||||
* @JMS\SerializedName("date")
|
||||
*/
|
||||
public $date;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @JMS\Type("float")
|
||||
* @JMS\SerializedName("amount")
|
||||
*/
|
||||
public $amount;
|
||||
}
|
@ -22,6 +22,14 @@ use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||
*/
|
||||
class Loyalty
|
||||
{
|
||||
/**
|
||||
* @var \RetailCrm\Api\Model\Entity\Loyalty\LoyaltyLevel[]
|
||||
*
|
||||
* @JMS\Type("array<RetailCrm\Api\Model\Entity\Loyalty\LoyaltyLevel>")
|
||||
* @JMS\SerializedName("levels")
|
||||
*/
|
||||
public $levels;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*
|
||||
|
@ -43,6 +43,14 @@ class LoyaltyLevel
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @JMS\Type("int")
|
||||
* @JMS\SerializedName("sum")
|
||||
*/
|
||||
public $sum;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.3
|
||||
*
|
||||
* @category LoyaltyAccountBonusApiFilterType
|
||||
* @package RetailCrm\Api\Model\Filter\Loyalty
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Api\Model\Filter\Loyalty;
|
||||
|
||||
use RetailCrm\Api\Component\FormData\Mapping as Form;
|
||||
|
||||
/**
|
||||
* Class LoyaltyAccountBonusApiFilterType
|
||||
*
|
||||
* @category LoyaltyAccountBonusApiFilterType
|
||||
* @package RetailCrm\Api\Model\Filter\Loyalty
|
||||
*/
|
||||
class LoyaltyAccountBonusApiFilterType
|
||||
{
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @Form\Type("DateTime<'Y-m-d H:i:s'>")
|
||||
* @Form\SerializedName("date")
|
||||
*/
|
||||
public $date;
|
||||
}
|
49
src/Model/Request/Loyalty/BonusAccountDetailsRequest.php
Normal file
49
src/Model/Request/Loyalty/BonusAccountDetailsRequest.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.3
|
||||
*
|
||||
* @category BonusAccountDetailsRequest
|
||||
* @package RetailCrm\Api\Model\Request\Loyalty
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Api\Model\Request\Loyalty;
|
||||
|
||||
use RetailCrm\Api\Interfaces\RequestInterface;
|
||||
use RetailCrm\Api\Model\Request\Traits\PageLimitTrait;
|
||||
use RetailCrm\Api\Component\FormData\Mapping as Form;
|
||||
|
||||
/**
|
||||
* Class BonusAccountDetailsRequest
|
||||
*
|
||||
* @category BonusAccountDetailsRequest
|
||||
* @package RetailCrm\Api\Model\Request\Loyalty
|
||||
*/
|
||||
class BonusAccountDetailsRequest implements RequestInterface
|
||||
{
|
||||
use PageLimitTrait;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Api\Model\Filter\Loyalty\LoyaltyAccountBonusApiFilterType
|
||||
*
|
||||
* @Form\Type("RetailCrm\Api\Model\Filter\Loyalty\LoyaltyAccountBonusApiFilterType")
|
||||
* @Form\SerializedName("filter")
|
||||
*/
|
||||
public $filter;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @Form\Type("int")
|
||||
* @Form\SerializedName("id")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @Form\Type("string")
|
||||
* @Form\SerializedName("status")
|
||||
*/
|
||||
public $status;
|
||||
}
|
38
src/Model/Response/Loyalty/BonusAccountDetailsResponse.php
Normal file
38
src/Model/Response/Loyalty/BonusAccountDetailsResponse.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.3
|
||||
*
|
||||
* @category BonusAccountDetailsResponse
|
||||
* @package RetailCrm\Api\Model\Response\Loyalty
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Api\Model\Response\Loyalty;
|
||||
|
||||
use RetailCrm\Api\Model\Response\AbstractPaginatedResponse;
|
||||
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||
|
||||
/**
|
||||
* Class BonusAccountDetailsResponse
|
||||
*
|
||||
* @category BonusAccountDetailsResponse
|
||||
* @package RetailCrm\Api\Model\Response\Loyalty
|
||||
*/
|
||||
class BonusAccountDetailsResponse extends AbstractPaginatedResponse
|
||||
{
|
||||
/**
|
||||
* @var \RetailCrm\Api\Model\Response\Loyalty\LoyaltyBonusStatisticResponse
|
||||
*
|
||||
* @JMS\Type("RetailCrm\Api\Model\Response\Loyalty\LoyaltyBonusStatisticResponse")
|
||||
* @JMS\SerializedName("statistic")
|
||||
*/
|
||||
public $statistic;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Api\Model\Entity\Loyalty\BonusDetail[]
|
||||
*
|
||||
* @JMS\Type("array<RetailCrm\Api\Model\Entity\Loyalty\BonusDetail>")
|
||||
* @JMS\SerializedName("bonuses")
|
||||
*/
|
||||
public $bonuses;
|
||||
}
|
29
src/Model/Response/Loyalty/LoyaltyBonusStatisticResponse.php
Normal file
29
src/Model/Response/Loyalty/LoyaltyBonusStatisticResponse.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.3
|
||||
*
|
||||
* @category LoyaltyBonusStatisticResponse
|
||||
* @package RetailCrm\Api\Model\Response\Loyalty
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Api\Model\Response\Loyalty;
|
||||
|
||||
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||
|
||||
/**
|
||||
* Class LoyaltyBonusStatisticResponse
|
||||
*
|
||||
* @category LoyaltyBonusStatisticResponse
|
||||
* @package RetailCrm\Api\Model\Response\Loyalty
|
||||
*/
|
||||
class LoyaltyBonusStatisticResponse
|
||||
{
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @JMS\Type("float")
|
||||
* @JMS\SerializedName("totalAmount")
|
||||
*/
|
||||
public $totalAmount;
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
namespace RetailCrm\Api\ResourceGroup;
|
||||
|
||||
use RetailCrm\Api\Enum\RequestMethod;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\BonusAccountDetailsRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltiesRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountCreateRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountEditRequest;
|
||||
@ -17,6 +18,7 @@ use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountsRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyBonusCreditRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyBonusOperationsRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyCalculateRequest;
|
||||
use RetailCrm\Api\Model\Response\Loyalty\BonusAccountDetailsResponse;
|
||||
use RetailCrm\Api\Model\Response\Loyalty\LoyaltiesResponse;
|
||||
use RetailCrm\Api\Model\Response\Loyalty\LoyaltyAccountActivateResponse;
|
||||
use RetailCrm\Api\Model\Response\Loyalty\LoyaltyAccountCreateResponse;
|
||||
@ -656,4 +658,78 @@ class Loyalty extends AbstractApiResourceGroup
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes GET "/api/v5/loyalty/account/{$id}/bonus/{$status}/details" request.
|
||||
*
|
||||
* Example:
|
||||
* ```php
|
||||
* use RetailCrm\Api\Factory\SimpleClientFactory;
|
||||
* use RetailCrm\Api\Interfaces\ApiExceptionInterface;
|
||||
* use RetailCrm\Api\Model\Filter\Loyalty\LoyaltyAccountBonusApiFilterType;
|
||||
* use RetailCrm\Api\Model\Request\Loyalty\BonusAccountDetailsRequest;
|
||||
*
|
||||
* $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
|
||||
*
|
||||
* try {
|
||||
* $request = new BonusAccountDetailsRequest();
|
||||
* $request->status = 'bonus_status';
|
||||
* $request->id = 1;
|
||||
* $request->limit = 2;
|
||||
* $request->page = 1;
|
||||
* $request->filter = new LoyaltyAccountBonusApiFilterType();
|
||||
* $request->filter->date = new DateTime();
|
||||
*
|
||||
* $response = $client->loyalty->getBonusAccountDetails(
|
||||
* $request->status,
|
||||
* $request->id,
|
||||
* $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 'Total bonus amount: ' . $response->statistic->totalAmount;
|
||||
* ```
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $status
|
||||
* @param \RetailCrm\Api\Model\Request\Loyalty\BonusAccountDetailsRequest $request
|
||||
*
|
||||
* @return \RetailCrm\Api\Model\Response\Loyalty\BonusAccountDetailsResponse
|
||||
* @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 getBonusAccountDetails(
|
||||
int $id,
|
||||
string $status,
|
||||
BonusAccountDetailsRequest $request
|
||||
): BonusAccountDetailsResponse {
|
||||
/** @var BonusAccountDetailsResponse $response */
|
||||
$response = $this->sendRequest(
|
||||
RequestMethod::GET,
|
||||
'loyalty/account/' . $id . '/bonus/' . $status . '/details',
|
||||
$request,
|
||||
BonusAccountDetailsResponse::class
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -20,15 +20,19 @@ use RetailCrm\Api\Enum\NumericBoolean;
|
||||
use RetailCrm\Api\Enum\RequestMethod;
|
||||
use RetailCrm\Api\Model\Entity\CustomersCorporate\SerializedEntityCustomer;
|
||||
use RetailCrm\Api\Model\Entity\CustomersCorporate\SerializedRelationAbstractCustomer;
|
||||
use RetailCrm\Api\Model\Entity\Loyalty\BonusDetail;
|
||||
use RetailCrm\Api\Model\Entity\Loyalty\LoyaltyAccount;
|
||||
use RetailCrm\Api\Model\Entity\Loyalty\SerializedCreateLoyaltyAccount;
|
||||
use RetailCrm\Api\Model\Entity\Loyalty\SerializedOrder;
|
||||
use RetailCrm\Api\Model\Entity\Loyalty\SerializedOrderDelivery;
|
||||
use RetailCrm\Api\Model\Entity\Loyalty\SerializedOrderProduct;
|
||||
use RetailCrm\Api\Model\Entity\Loyalty\SerializedOrderProductOffer;
|
||||
use RetailCrm\Api\Model\Entity\Pagination;
|
||||
use RetailCrm\Api\Model\Filter\Loyalty\LoyaltyAccountApiFilterType;
|
||||
use RetailCrm\Api\Model\Filter\Loyalty\LoyaltyAccountBonusApiFilterType;
|
||||
use RetailCrm\Api\Model\Filter\Loyalty\LoyaltyAccountBonusOperationsApiFilterType;
|
||||
use RetailCrm\Api\Model\Filter\Loyalty\LoyaltyApiFilterType;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\BonusAccountDetailsRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltiesRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountCreateRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountEditRequest;
|
||||
@ -36,6 +40,8 @@ use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountsRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyBonusCreditRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyBonusOperationsRequest;
|
||||
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyCalculateRequest;
|
||||
use RetailCrm\Api\Model\Response\Loyalty\BonusAccountDetailsResponse;
|
||||
use RetailCrm\Api\Model\Response\Loyalty\LoyaltyBonusStatisticResponse;
|
||||
use RetailCrm\TestUtils\Factory\TestClientFactory;
|
||||
use RetailCrm\TestUtils\TestCase\AbstractApiResourceGroupTestCase;
|
||||
|
||||
@ -825,4 +831,47 @@ EOF;
|
||||
|
||||
self::assertModelEqualsToResponse($json, $response);
|
||||
}
|
||||
|
||||
public function testGetBonusAccountDetails(): void
|
||||
{
|
||||
$json = <<<'EOF'
|
||||
{
|
||||
"statistic": {
|
||||
"totalAmount": 2.1
|
||||
},
|
||||
"bonuses": [
|
||||
{
|
||||
"date": "2021-03-17 18:08:02",
|
||||
"amount": 1.2
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
"limit": 10,
|
||||
"totalCount": 20,
|
||||
"currentPage": 2,
|
||||
"totalPageCount": 30
|
||||
},
|
||||
"success": true
|
||||
}
|
||||
EOF;
|
||||
|
||||
$mock = static::createApiMockBuilder('loyalty/account/4/bonus/bonus_status/details');
|
||||
$mock->matchMethod(RequestMethod::GET)
|
||||
->reply(200)
|
||||
->withBody($json);
|
||||
|
||||
$request = new BonusAccountDetailsRequest();
|
||||
$request->status = 'bonus_status';
|
||||
$request->id = 1;
|
||||
$request->limit = 2;
|
||||
$request->page = 1;
|
||||
$request->filter = new LoyaltyAccountBonusApiFilterType();
|
||||
$request->filter->date = new DateTime();
|
||||
|
||||
|
||||
$client = TestClientFactory::createClient($mock->getClient());
|
||||
$response = $client->loyalty->getBonusAccountDetails(4, 'bonus_status', $request);
|
||||
|
||||
self::assertModelEqualsToResponse($json, $response);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user