diff --git a/src/Component/Constants.php b/src/Component/Constants.php index d7fc3d6..3215a9e 100644 --- a/src/Component/Constants.php +++ b/src/Component/Constants.php @@ -29,7 +29,5 @@ class Constants public const LOGGER = 'logger'; public const VALIDATOR = 'validator'; public const TOP_VERSION = 'top-sdk-php-20180326'; - public const SIGN_TYPE_MD5 = 'md5'; - public const SIGN_TYPE_HMAC = 'hmac'; public const UNSIGNED_MARK = '00000000000000000000000000000000'; } diff --git a/src/Model/Enum/AvailableResponseFormats.php b/src/Model/Enum/AvailableResponseFormats.php new file mode 100644 index 0000000..91a8b83 --- /dev/null +++ b/src/Model/Enum/AvailableResponseFormats.php @@ -0,0 +1,30 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Enum; + +/** + * Class AvailableResponseFormats + * + * @category AvailableResponseFormats + * @package RetailCrm\Model\Enum + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class AvailableResponseFormats +{ + public const XML = 'xml'; + public const JSON = 'json'; + public const AVAILABLE_FORMATS = [self::JSON, self::XML]; +} diff --git a/src/Model/Enum/AvailableSignMethods.php b/src/Model/Enum/AvailableSignMethods.php new file mode 100644 index 0000000..ebd6112 --- /dev/null +++ b/src/Model/Enum/AvailableSignMethods.php @@ -0,0 +1,30 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Enum; + +/** + * Class AvailableSignMethods + * + * @category AvailableSignMethods + * @package RetailCrm\Model\Enum + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class AvailableSignMethods +{ + public const MD5 = 'md5'; + public const HMAC_MD5 = 'hmac'; + public const AVAILABLE_METHODS = [self::MD5, self::HMAC_MD5]; +} diff --git a/src/Model/Enum/CategoryForecastSupportedLanguages.php b/src/Model/Enum/CategoryForecastSupportedLanguages.php new file mode 100644 index 0000000..435fcdf --- /dev/null +++ b/src/Model/Enum/CategoryForecastSupportedLanguages.php @@ -0,0 +1,63 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Enum; + +/** + * Class CategoryForecastSupportedLanguages + * + * @category CategoryForecastSupportedLanguages + * @package RetailCrm\Model\Enum + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class CategoryForecastSupportedLanguages +{ + public const EN = 'en'; + public const RU = 'ru'; + public const PT = 'pt'; + public const ID = 'id'; + public const ES = 'es'; + public const FR = 'fr'; + public const IT = 'it'; + public const DE = 'de'; + public const NL = 'nl'; + public const TR = 'tr'; + public const HE = 'he'; + public const JA = 'ja'; + public const AR = 'ar'; + public const TH = 'th'; + public const VI = 'vi'; + public const KO = 'ko'; + public const PL = 'pl'; + public const SUPPORTED_LANGUAGES = [ + self::EN, + self::RU, + self::PT, + self::ID, + self::ES, + self::FR, + self::IT, + self::DE, + self::NL, + self::TR, + self::HE, + self::JA, + self::AR, + self::TH, + self::VI, + self::KO, + self::PL + ]; +} diff --git a/src/Model/Enum/FeedOperationTypes.php b/src/Model/Enum/FeedOperationTypes.php new file mode 100644 index 0000000..0f5b9fd --- /dev/null +++ b/src/Model/Enum/FeedOperationTypes.php @@ -0,0 +1,37 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Enum; + +/** + * Class FeedOperationTypes + * + * @category FeedOperationTypes + * @package RetailCrm\Model\Enum + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class FeedOperationTypes +{ + public const PRODUCT_CREATE = 'PRODUCT_CREATE'; + public const PRODUCT_FULL_UPDATE = 'PRODUCT_FULL_UPDATE'; + public const PRODUCT_STOCKS_UPDATE = 'PRODUCT_STOCKS_UPDATE'; + public const PRODUCT_PRICES_UPDATE = 'PRODUCT_PRICES_UPDATE'; + public const ALLOWED_OPERATION_TYPES = [ + self::PRODUCT_CREATE, + self::PRODUCT_FULL_UPDATE, + self::PRODUCT_STOCKS_UPDATE, + self::PRODUCT_PRICES_UPDATE + ]; +} diff --git a/src/Model/Enum/FeedStatuses.php b/src/Model/Enum/FeedStatuses.php new file mode 100644 index 0000000..2663069 --- /dev/null +++ b/src/Model/Enum/FeedStatuses.php @@ -0,0 +1,31 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Enum; + +/** + * Class FeedStatuses + * + * @category FeedStatuses + * @package RetailCrm\Model\Enum + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class FeedStatuses +{ + public const FINISH = 'FINISH'; + public const PROCESSING = 'PROCESSING'; + public const QUEUEING = 'QUEUEING'; + public const AVAILABLE_STATUSES = [self::FINISH, self::PROCESSING, self::QUEUEING]; +} diff --git a/src/Model/Request/AliExpress/PostproductRedefiningCategoryForecast.php b/src/Model/Request/AliExpress/PostproductRedefiningCategoryForecast.php index c69f81b..63563bb 100644 --- a/src/Model/Request/AliExpress/PostproductRedefiningCategoryForecast.php +++ b/src/Model/Request/AliExpress/PostproductRedefiningCategoryForecast.php @@ -43,9 +43,7 @@ class PostproductRedefiningCategoryForecast extends BaseRequest * * @JMS\Type("string") * @JMS\SerializedName("locale") - * - * phpcs:disable Generic.Files.LineLength - * @Assert\Choice({"en", "ru", "pt", "id", "es", "fr", "it", "de", "nl", "tr", "he", "ja", "ar", "th", "vi", "ko", "pl"}) + * @Assert\Choice(choices=RetailCrm\Model\Enum\CategoryForecastSupportedLanguages::SUPPORTED_LANGUAGES) */ public $locale; diff --git a/src/Model/Request/AliExpress/SolutionFeedListGet.php b/src/Model/Request/AliExpress/SolutionFeedListGet.php new file mode 100644 index 0000000..c2462af --- /dev/null +++ b/src/Model/Request/AliExpress/SolutionFeedListGet.php @@ -0,0 +1,78 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Request\AliExpress; + +use JMS\Serializer\Annotation as JMS; +use RetailCrm\Model\Request\BaseRequest; +use RetailCrm\Model\Response\AliExpress\SolutionFeedListGetResponse; + +/** + * Class SolutionFeedListGet + * + * @category SolutionFeedListGet + * @package RetailCrm\Model\Request\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionFeedListGet extends BaseRequest +{ + /** + * @var int $currentPage + * + * @JMS\Type("int") + * @JMS\SerializedName("current_page") + */ + public $currentPage; + + /** + * @var string $feedType + * + * @JMS\Type("string") + * @JMS\SerializedName("feed_type") + */ + public $feedType; + + /** + * @var int $pageSize + * + * @JMS\Type("int") + * @JMS\SerializedName("page_size") + */ + public $pageSize; + + /** + * @var string $status + * + * @JMS\Type("string") + * @JMS\SerializedName("status") + */ + public $status; + + /** + * @inheritDoc + */ + public function getMethod(): string + { + return 'aliexpress.solution.feed.list.get'; + } + + /** + * @inheritDoc + */ + public function getExpectedResponse(): string + { + return SolutionFeedListGetResponse::class; + } +} diff --git a/src/Model/Request/AliExpress/SolutionFeedQuery.php b/src/Model/Request/AliExpress/SolutionFeedQuery.php new file mode 100644 index 0000000..00a7bd5 --- /dev/null +++ b/src/Model/Request/AliExpress/SolutionFeedQuery.php @@ -0,0 +1,57 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Request\AliExpress; + +use RetailCrm\Model\Request\BaseRequest; +use JMS\Serializer\Annotation as JMS; +use RetailCrm\Model\Response\AliExpress\SolutionFeedQueryResponse; + +/** + * Class SolutionFeedQuery + * + * @category SolutionFeedQuery + * @package RetailCrm\Model\Request\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionFeedQuery extends BaseRequest +{ + /** + * Job ID. + * This field is marked as optional for some reason... so, no assertions here. + * + * @var int $jobId + * + * @JMS\Type("int") + * @JMS\SerializedName("job_id") + */ + public $jobId; + + /** + * @inheritDoc + */ + public function getMethod(): string + { + return 'aliexpress.solution.feed.query'; + } + + /** + * @inheritDoc + */ + public function getExpectedResponse(): string + { + return SolutionFeedQueryResponse::class; + } +} diff --git a/src/Model/Request/AliExpress/SolutionFeedSubmit.php b/src/Model/Request/AliExpress/SolutionFeedSubmit.php index b7205fd..2efeabe 100644 --- a/src/Model/Request/AliExpress/SolutionFeedSubmit.php +++ b/src/Model/Request/AliExpress/SolutionFeedSubmit.php @@ -30,22 +30,12 @@ use Symfony\Component\Validator\Constraints as Assert; */ class SolutionFeedSubmit extends BaseRequest { - public const PRODUCT_CREATE = 'PRODUCT_CREATE'; - public const PRODUCT_FULL_UPDATE = 'PRODUCT_FULL_UPDATE'; - public const PRODUCT_STOCKS_UPDATE = 'PRODUCT_STOCKS_UPDATE'; - public const PRODUCT_PRICES_UPDATE = 'PRODUCT_PRICES_UPDATE'; - /** * @var string $operationType * * @JMS\Type("string") * @JMS\SerializedName("operation_type") - * @Assert\Choice({ - * "PRODUCT_CREATE", - * "PRODUCT_FULL_UPDATE", - * "PRODUCT_STOCKS_UPDATE", - * "PRODUCT_PRICES_UPDATE" - * }) + * @Assert\Choice(choices=RetailCrm\Model\Enum\FeedOperationTypes::ALLOWED_OPERATION_TYPES) */ public $operationType; @@ -54,7 +44,7 @@ class SolutionFeedSubmit extends BaseRequest * * @JMS\Type("array") * @JMS\SerializedName("item_list") - * @Assert\NotBlank() + * @Assert\Count(min=1, max=2000) */ public $itemList; diff --git a/src/Model/Request/BaseRequest.php b/src/Model/Request/BaseRequest.php index af42707..55beb0c 100644 --- a/src/Model/Request/BaseRequest.php +++ b/src/Model/Request/BaseRequest.php @@ -14,6 +14,8 @@ namespace RetailCrm\Model\Request; use JMS\Serializer\Annotation as JMS; use RetailCrm\Component\Constants; +use RetailCrm\Model\Enum\AvailableResponseFormats; +use RetailCrm\Model\Enum\AvailableSignMethods; use Symfony\Component\Validator\Constraints as Assert; /** @@ -72,9 +74,9 @@ abstract class BaseRequest * @JMS\Type("string") * @JMS\SerializedName("format") * @Assert\NotBlank() - * @Assert\Choice({"xml", "json"}) + * @Assert\Choice(choices=RetailCrm\Model\Enum\AvailableResponseFormats::AVAILABLE_FORMATS) */ - public $format = 'json'; + public $format = AvailableResponseFormats::JSON; /** * @var string $version @@ -101,9 +103,9 @@ abstract class BaseRequest * @JMS\Type("string") * @JMS\SerializedName("sign_method") * @Assert\NotBlank() - * @Assert\Choice({"hmac", "md5"}) + * @Assert\Choice(choices=RetailCrm\Model\Enum\AvailableSignMethods::AVAILABLE_METHODS) */ - public $signMethod = Constants::SIGN_TYPE_HMAC; + public $signMethod = AvailableSignMethods::HMAC_MD5; /** * @var string $sign diff --git a/src/Model/Response/AliExpress/Data/SolutionFeedListGetResponseData.php b/src/Model/Response/AliExpress/Data/SolutionFeedListGetResponseData.php new file mode 100644 index 0000000..ceaffd1 --- /dev/null +++ b/src/Model/Response/AliExpress/Data/SolutionFeedListGetResponseData.php @@ -0,0 +1,69 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress\Data; + +use RetailCrm\Model\Response\AbstractResponseData; +use JMS\Serializer\Annotation as JMS; + +/** + * Class SolutionFeedListGetResponseData + * + * @category SolutionFeedListGetResponseData + * @package RetailCrm\Model\Response\AliExpress\Data + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionFeedListGetResponseData extends AbstractResponseData +{ + /** + * @var int $currentPage + * + * @JMS\Type("int") + * @JMS\SerializedName("current_page") + */ + public $currentPage; + + /** + * @var \RetailCrm\Model\Response\AliExpress\Result\Entity\BatchOperationJobDtoList $jobList + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Result\Entity\BatchOperationJobDtoList") + * @JMS\SerializedName("job_list") + */ + public $jobList; + + /** + * @var int $pageSize + * + * @JMS\Type("int") + * @JMS\SerializedName("page_size") + */ + public $pageSize; + + /** + * @var int $totalCount + * + * @JMS\Type("int") + * @JMS\SerializedName("total_count") + */ + public $totalCount; + + /** + * @var int $totalPage + * + * @JMS\Type("int") + * @JMS\SerializedName("total_page") + */ + public $totalPage; +} diff --git a/src/Model/Response/AliExpress/Data/SolutionFeedQueryResponseData.php b/src/Model/Response/AliExpress/Data/SolutionFeedQueryResponseData.php new file mode 100644 index 0000000..6521ad9 --- /dev/null +++ b/src/Model/Response/AliExpress/Data/SolutionFeedQueryResponseData.php @@ -0,0 +1,61 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress\Data; + +use JMS\Serializer\Annotation as JMS; +use RetailCrm\Model\Response\AbstractResponseData; + +/** + * Class SolutionFeedQueryResponseData + * + * @category SolutionFeedQueryResponseData + * @package RetailCrm\Model\Response\AliExpress\Data + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionFeedQueryResponseData extends AbstractResponseData +{ + /** + * @var int $jobId + * + * @JMS\Type("int") + * @JMS\SerializedName("job_id") + */ + public $jobId; + + /** + * @var int $successItemCount + * + * @JMS\Type("int") + * @JMS\SerializedName("success_item_count") + */ + public $successItemCount; + + /** + * @var \RetailCrm\Model\Response\AliExpress\Result\Entity\SingleItemResponseDtoList $resultList + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Result\Entity\SingleItemResponseDtoList") + * @JMS\SerializedName("result_list") + */ + public $resultList; + + /** + * @var int $totalItemCount + * + * @JMS\Type("int") + * @JMS\SerializedName("total_item_count") + */ + public $totalItemCount; +} diff --git a/src/Model/Response/AliExpress/Result/BatchOperationJobDto.php b/src/Model/Response/AliExpress/Result/BatchOperationJobDto.php new file mode 100644 index 0000000..7e2b148 --- /dev/null +++ b/src/Model/Response/AliExpress/Result/BatchOperationJobDto.php @@ -0,0 +1,52 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress\Result; + +use JMS\Serializer\Annotation as JMS; + +/** + * Class BatchOperationJobDto + * + * @category BatchOperationJobDto + * @package RetailCrm\Model\Response\AliExpress\Result + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class BatchOperationJobDto +{ + /** + * @var string $status + * + * @JMS\Type("string") + * @JMS\SerializedName("status") + */ + public $status; + + /** + * @var string $operationType + * + * @JMS\Type("string") + * @JMS\SerializedName("operation_type") + */ + public $operationType; + + /** + * @var int $jobId + * + * @JMS\Type("int") + * @JMS\SerializedName("job_id") + */ + public $jobId; +} diff --git a/src/Model/Response/AliExpress/Result/Entity/BatchOperationJobDtoList.php b/src/Model/Response/AliExpress/Result/Entity/BatchOperationJobDtoList.php new file mode 100644 index 0000000..38b81e9 --- /dev/null +++ b/src/Model/Response/AliExpress/Result/Entity/BatchOperationJobDtoList.php @@ -0,0 +1,36 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress\Result\Entity; + +use JMS\Serializer\Annotation as JMS; + +/** + * Class BatchOperationJobDtoList + * + * @category BatchOperationJobDtoList + * @package RetailCrm\Model\Response\AliExpress\Result\Entity + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class BatchOperationJobDtoList +{ + /** + * @var \RetailCrm\Model\Response\AliExpress\Result\BatchOperationJobDto[] $batchOperationJobDto + * + * @JMS\Type("array") + * @JMS\SerializedName("batch_operation_job_dto") + */ + public $batchOperationJobDto; +} diff --git a/src/Model/Response/AliExpress/Result/Entity/SingleItemResponseDtoList.php b/src/Model/Response/AliExpress/Result/Entity/SingleItemResponseDtoList.php new file mode 100644 index 0000000..63f78b4 --- /dev/null +++ b/src/Model/Response/AliExpress/Result/Entity/SingleItemResponseDtoList.php @@ -0,0 +1,36 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress\Result\Entity; + +use JMS\Serializer\Annotation as JMS; + +/** + * Class SingleItemResponseDtoList + * + * @category SingleItemResponseDtoList + * @package RetailCrm\Model\Response\AliExpress\Result\Entity + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SingleItemResponseDtoList +{ + /** + * @var \RetailCrm\Model\Response\AliExpress\Result\SingleItemResponseDto[] $singleItemResponseDto + * + * @JMS\Type("array") + * @JMS\SerializedName("single_item_response_dto") + */ + public $singleItemResponseDto; +} diff --git a/src/Model/Response/AliExpress/Result/ItemExecutionResult.php b/src/Model/Response/AliExpress/Result/ItemExecutionResult.php new file mode 100644 index 0000000..2cc88ae --- /dev/null +++ b/src/Model/Response/AliExpress/Result/ItemExecutionResult.php @@ -0,0 +1,44 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress\Result; + +use JMS\Serializer\Annotation as JMS; + +/** + * Class ItemExecutionResult + * + * @category ItemExecutionResult + * @package RetailCrm\Model\Response\AliExpress\Result + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class ItemExecutionResult +{ + /** + * @var int $productId + * + * @JMS\Type("int") + * @JMS\SerializedName("productId") + */ + public $productId; + + /** + * @var bool $success + * + * @JMS\Type("bool") + * @JMS\SerializedName("success") + */ + public $success; +} diff --git a/src/Model/Response/AliExpress/Result/SingleItemResponseDto.php b/src/Model/Response/AliExpress/Result/SingleItemResponseDto.php new file mode 100644 index 0000000..0ac7688 --- /dev/null +++ b/src/Model/Response/AliExpress/Result/SingleItemResponseDto.php @@ -0,0 +1,45 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress\Result; + +use JMS\Serializer\Annotation as JMS; + +/** + * Class SingleItemResponseDto + * + * @category SingleItemResponseDto + * @package RetailCrm\Model\Response\AliExpress\Result + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SingleItemResponseDto +{ + /** + * @var \RetailCrm\Model\Response\AliExpress\Result\ItemExecutionResult $itemExecutionResult + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Result\ItemExecutionResult") + * @JMS\SerializedName("item_execution_result") + * @JMS\Groups(groups={"InlineJsonBody"}) + */ + public $itemExecutionResult; + + /** + * @var string $itemContentId + * + * @JMS\Type("string") + * @JMS\SerializedName("item_content_id") + */ + public $itemContentId; +} diff --git a/src/Model/Response/AliExpress/SolutionFeedListGetResponse.php b/src/Model/Response/AliExpress/SolutionFeedListGetResponse.php new file mode 100644 index 0000000..2161d04 --- /dev/null +++ b/src/Model/Response/AliExpress/SolutionFeedListGetResponse.php @@ -0,0 +1,37 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress; + +use RetailCrm\Model\Response\BaseResponse; +use JMS\Serializer\Annotation as JMS; + +/** + * Class SolutionFeedListGetResponse + * + * @category SolutionFeedListGetResponse + * @package RetailCrm\Model\Response\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionFeedListGetResponse extends BaseResponse +{ + /** + * @var \RetailCrm\Model\Response\AliExpress\Data\SolutionFeedListGetResponseData $responseData + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Data\SolutionFeedListGetResponseData") + * @JMS\SerializedName("aliexpress_solution_feed_list_get_response") + */ + public $responseData; +} diff --git a/src/Model/Response/AliExpress/SolutionFeedQueryResponse.php b/src/Model/Response/AliExpress/SolutionFeedQueryResponse.php new file mode 100644 index 0000000..5d35866 --- /dev/null +++ b/src/Model/Response/AliExpress/SolutionFeedQueryResponse.php @@ -0,0 +1,37 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress; + +use RetailCrm\Model\Response\BaseResponse; +use JMS\Serializer\Annotation as JMS; + +/** + * Class SolutionFeedQueryResponse + * + * @category SolutionFeedQueryResponse + * @package RetailCrm\Model\Response\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionFeedQueryResponse extends BaseResponse +{ + /** + * @var \RetailCrm\Model\Response\AliExpress\Data\SolutionFeedQueryResponseData $responseData + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Data\SolutionFeedQueryResponseData") + * @JMS\SerializedName("aliexpress_solution_feed_query_response") + */ + public $responseData; +} diff --git a/src/Service/RequestSigner.php b/src/Service/RequestSigner.php index 086af4a..92b3c80 100644 --- a/src/Service/RequestSigner.php +++ b/src/Service/RequestSigner.php @@ -17,6 +17,7 @@ use RetailCrm\Component\Constants; use RetailCrm\Component\Exception\NotImplementedException; use RetailCrm\Interfaces\AppDataInterface; use RetailCrm\Interfaces\RequestSignerInterface; +use RetailCrm\Model\Enum\AvailableSignMethods; use RetailCrm\Model\Request\BaseRequest; /** @@ -69,11 +70,11 @@ class RequestSigner implements RequestSignerInterface } switch ($request->signMethod) { - case Constants::SIGN_TYPE_MD5: + case AvailableSignMethods::MD5: $stringToBeSigned = $appData->getAppSecret() . $stringToBeSigned . $appData->getAppSecret(); $request->sign = strtoupper(md5($stringToBeSigned)); break; - case Constants::SIGN_TYPE_HMAC: + case AvailableSignMethods::HMAC_MD5: $request->sign = strtoupper(hash_hmac('md5', $stringToBeSigned, $appData->getAppSecret())); break; default: diff --git a/tests/RetailCrm/Test/TestCase.php b/tests/RetailCrm/Test/TestCase.php index 8a85a9c..9c45a11 100644 --- a/tests/RetailCrm/Test/TestCase.php +++ b/tests/RetailCrm/Test/TestCase.php @@ -93,7 +93,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase protected function getEnvTokenAuthenticator(): AuthenticatorInterface { - return $this->getTokenAuthenticator(self::getenv('SESSION', 'test')); + return $this->getTokenAuthenticator(self::getEnvToken()); } /** @@ -185,6 +185,14 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase return self::getenv('APP_KEY', 'appKey'); } + /** + * @return string + */ + protected static function getEnvToken(): string + { + return self::getenv('SESSION', 'test'); + } + /** * @param string $variable * @param mixed $default diff --git a/tests/RetailCrm/Tests/Factory/TopRequestFactoryTest.php b/tests/RetailCrm/Tests/Factory/TopRequestFactoryTest.php index c892b2f..350e531 100644 --- a/tests/RetailCrm/Tests/Factory/TopRequestFactoryTest.php +++ b/tests/RetailCrm/Tests/Factory/TopRequestFactoryTest.php @@ -15,6 +15,7 @@ namespace RetailCrm\Tests\Factory; use RetailCrm\Component\Constants; use RetailCrm\Factory\TopRequestFactory; use RetailCrm\Interfaces\TopRequestFactoryInterface; +use RetailCrm\Model\Enum\AvailableSignMethods; use RetailCrm\Test\TestCase; /** @@ -34,7 +35,7 @@ class TopRequestFactoryTest extends TestCase /** @var TopRequestFactory $factory */ $factory = $this->getContainer()->get(TopRequestFactoryInterface::class); $request = $factory->fromModel( - $this->getTestRequest(Constants::SIGN_TYPE_HMAC), + $this->getTestRequest(AvailableSignMethods::HMAC_MD5), $this->getAppData() ); $uri = $request->getUri(); @@ -51,7 +52,7 @@ class TopRequestFactoryTest extends TestCase /** @var TopRequestFactory $factory */ $factory = $this->getContainer()->get(TopRequestFactoryInterface::class); $request = $factory->fromModel( - $this->getTestRequest(Constants::SIGN_TYPE_HMAC, true, true), + $this->getTestRequest(AvailableSignMethods::HMAC_MD5, true, true), $this->getAppData() ); $uri = $request->getUri(); diff --git a/tests/RetailCrm/Tests/Service/RequestSignerTest.php b/tests/RetailCrm/Tests/Service/RequestSignerTest.php index f4262cb..a10f2e0 100644 --- a/tests/RetailCrm/Tests/Service/RequestSignerTest.php +++ b/tests/RetailCrm/Tests/Service/RequestSignerTest.php @@ -16,6 +16,7 @@ use RetailCrm\Component\AppData; use RetailCrm\Component\Constants; use RetailCrm\Interfaces\AppDataInterface; use RetailCrm\Interfaces\RequestSignerInterface; +use RetailCrm\Model\Enum\AvailableSignMethods; use RetailCrm\Test\TestCase; use RetailCrm\Test\TestSignerRequest; @@ -53,22 +54,22 @@ class RequestSignerTest extends TestCase return [ [ - $this->getTestRequest(Constants::SIGN_TYPE_MD5), + $this->getTestRequest(AvailableSignMethods::MD5), $appData, '468BF7C95925C187D0DFD7D042072EB4' ], [ - $this->getTestRequest(Constants::SIGN_TYPE_HMAC), + $this->getTestRequest(AvailableSignMethods::HMAC_MD5), $appData, '5EF5C76D5C158BFFA9F35BAAA712A879' ], [ - $this->getTestRequest(Constants::SIGN_TYPE_MD5, true), + $this->getTestRequest(AvailableSignMethods::MD5, true), $appData, '468BF7C95925C187D0DFD7D042072EB4' ], [ - $this->getTestRequest(Constants::SIGN_TYPE_HMAC, true), + $this->getTestRequest(AvailableSignMethods::HMAC_MD5, true), $appData, '5EF5C76D5C158BFFA9F35BAAA712A879' ] diff --git a/tests/RetailCrm/Tests/TopClient/ClientTest.php b/tests/RetailCrm/Tests/TopClient/ClientTest.php index b4082bf..919798f 100644 --- a/tests/RetailCrm/Tests/TopClient/ClientTest.php +++ b/tests/RetailCrm/Tests/TopClient/ClientTest.php @@ -17,9 +17,14 @@ use Psr\Http\Message\RequestInterface; use RetailCrm\Builder\ClientBuilder; use RetailCrm\Component\AppData; use RetailCrm\Component\Constants; +use RetailCrm\Component\Exception\ValidationException; use RetailCrm\Model\Entity\CategoryInfo; +use RetailCrm\Model\Enum\FeedOperationTypes; +use RetailCrm\Model\Enum\FeedStatuses; use RetailCrm\Model\Request\AliExpress\Data\SingleItemRequestDto; use RetailCrm\Model\Request\AliExpress\PostproductRedefiningCategoryForecast; +use RetailCrm\Model\Request\AliExpress\SolutionFeedListGet; +use RetailCrm\Model\Request\AliExpress\SolutionFeedQuery; use RetailCrm\Model\Request\AliExpress\SolutionFeedSubmit; use RetailCrm\Model\Request\AliExpress\SolutionSellerCategoryTreeQuery; use RetailCrm\Model\Request\Taobao\HttpDnsGetRequest; @@ -27,6 +32,7 @@ use RetailCrm\Model\Response\AliExpress\Data\SolutionFeedSubmitResponseData; use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseData; use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList; use RetailCrm\Model\Response\AliExpress\PostproductRedefiningCategoryForecastResponse; +use RetailCrm\Model\Response\AliExpress\SolutionFeedListGetResponse; use RetailCrm\Model\Response\AliExpress\SolutionFeedSubmitResponse; use RetailCrm\Model\Response\AliExpress\SolutionSellerCategoryTreeQueryResponse; use RetailCrm\Model\Response\ErrorResponseBody; @@ -126,7 +132,8 @@ EOF; 'app_key' => self::getEnvAppKey(), 'method' => 'aliexpress.solution.seller.category.tree.query', 'category_id' => '5090300', - 'filter_no_permission' => 1 + 'filter_no_permission' => 1, + 'session' => self::getEnvToken() ]), $this->responseJson(200, $json) ); @@ -184,14 +191,14 @@ EOF; } } EOF; - $mock = self::getMockClient(); $mock->on( RequestMatcher::createMatcher('api.taobao.com') ->setPath('/router/rest') ->setOptionalQueryParams([ 'app_key' => self::getEnvAppKey(), - 'method' => 'aliexpress.postproduct.redefining.categoryforecast' + 'method' => 'aliexpress.postproduct.redefining.categoryforecast', + 'session' => self::getEnvToken() ]), $this->responseJson(200, $json) ); @@ -231,14 +238,14 @@ EOF; } } EOF; - $mock = self::getMockClient(); $mock->on( RequestMatcher::createMatcher('api.taobao.com') ->setPath('/router/rest') ->setOptionalQueryParams([ 'app_key' => self::getEnvAppKey(), - 'method' => 'aliexpress.solution.feed.submit' + 'method' => 'aliexpress.solution.feed.submit', + 'session' => self::getEnvToken() ]), $this->responseJson(200, $json) ); @@ -254,13 +261,121 @@ EOF; $dto->code = 'code'; $item->itemContent = $dto; $item->itemContentId = 'A00000000Y1'; - $request->operationType = SolutionFeedSubmit::PRODUCT_PRICES_UPDATE; + $request->operationType = FeedOperationTypes::PRODUCT_PRICES_UPDATE; $request->itemList = [$item]; - /** @var SolutionFeedSubmitResponse $response */ $response = $client->sendAuthenticatedRequest($request); self::assertInstanceOf(SolutionFeedSubmitResponseData::class, $response->responseData); self::assertEquals(200000000060024475, $response->responseData->jobId); } + + public function testClientAliexpressSolutionFeedQuery() + { + $json = <<<'EOF' +{ + "aliexpress_solution_feed_query_response":{ + "job_id":200000000060054475, + "success_item_count":1, + "result_list":{ + "single_item_response_dto":[ + { + "item_execution_result":"{\"productId\":33030372006,\"success\":true}", + "item_content_id":"A00000000Y1" + } + ] + }, + "total_item_count":1 + } +} +EOF; + $mock = self::getMockClient(); + $mock->on( + RequestMatcher::createMatcher('api.taobao.com') + ->setPath('/router/rest') + ->setOptionalQueryParams([ + 'app_key' => self::getEnvAppKey(), + 'method' => 'aliexpress.solution.feed.query', + 'session' => self::getEnvToken() + ]), + $this->responseJson(200, $json) + ); + $client = ClientBuilder::create() + ->setContainer($this->getContainer($mock)) + ->setAppData($this->getEnvAppData()) + ->setAuthenticator($this->getEnvTokenAuthenticator()) + ->build(); + $request = new SolutionFeedQuery(); + $request->jobId = 200000000060054475; + + /** @var \RetailCrm\Model\Response\AliExpress\SolutionFeedQueryResponse $response */ + $response = $client->sendAuthenticatedRequest($request); + + self::assertEquals(200000000060054475, $response->responseData->jobId); + self::assertEquals(1, $response->responseData->successItemCount); + self::assertNotNull($response->responseData->resultList); + self::assertNotNull($response->responseData->resultList->singleItemResponseDto); + self::assertCount(1, $response->responseData->resultList->singleItemResponseDto); + + $item = $response->responseData->resultList->singleItemResponseDto[0]; + + self::assertEquals("A00000000Y1", $item->itemContentId); + self::assertNotNull($item->itemExecutionResult); + self::assertTrue($item->itemExecutionResult->success); + self::assertEquals(33030372006, $item->itemExecutionResult->productId); + } + + public function testAliexpressSolutionFeedListGet() + { + $json = <<<'EOF' +{ + "aliexpress_solution_feed_list_get_response":{ + "current_page":3, + "job_list":{ + "batch_operation_job_dto":[ + { + "status":"PROCESSING", + "operation_type":"PRODUCT_CREATE", + "job_id":2000000000123456 + } + ] + }, + "page_size":20, + "total_count":300, + "total_page":15 + } +} +EOF; + $mock = self::getMockClient(); + $mock->on( + RequestMatcher::createMatcher('api.taobao.com') + ->setPath('/router/rest') + ->setOptionalQueryParams([ + 'app_key' => self::getEnvAppKey(), + 'method' => 'aliexpress.solution.feed.list.get', + 'session' => self::getEnvToken() + ]), + $this->responseJson(200, $json) + ); + $client = ClientBuilder::create() + ->setContainer($this->getContainer($mock)) + ->setAppData($this->getEnvAppData()) + ->setAuthenticator($this->getEnvTokenAuthenticator()) + ->build(); + /** @var SolutionFeedListGetResponse $response */ + $response = $client->sendAuthenticatedRequest(new SolutionFeedListGet()); + + self::assertEquals(3, $response->responseData->currentPage); + self::assertEquals(20, $response->responseData->pageSize); + self::assertEquals(300, $response->responseData->totalCount); + self::assertEquals(15, $response->responseData->totalPage); + self::assertNotNull($response->responseData->jobList); + self::assertCount(1, $response->responseData->jobList->batchOperationJobDto); + + $item = $response->responseData->jobList->batchOperationJobDto[0]; + + self::assertEquals(FeedStatuses::PROCESSING, $item->status); + self::assertEquals(FeedOperationTypes::PRODUCT_CREATE, $item->operationType); + self::assertEquals(2000000000123456, $item->jobId); + } }