diff --git a/src/Builder/ContainerBuilder.php b/src/Builder/ContainerBuilder.php index 3b5d45c..406191e 100644 --- a/src/Builder/ContainerBuilder.php +++ b/src/Builder/ContainerBuilder.php @@ -185,6 +185,7 @@ class ContainerBuilder implements BuilderInterface public function build(): ContainerInterface { $container = new Container(); + $container->set(Environment::class, new Environment($this->env)); switch ($this->env) { case Environment::PROD: diff --git a/src/Builder/TopClientBuilder.php b/src/Builder/TopClientBuilder.php index 7b3c06c..323e465 100644 --- a/src/Builder/TopClientBuilder.php +++ b/src/Builder/TopClientBuilder.php @@ -13,6 +13,7 @@ namespace RetailCrm\Builder; use RetailCrm\Component\Constants; +use RetailCrm\Component\Environment; use RetailCrm\Component\ServiceLocator; use RetailCrm\Component\Storage\ProductSchemaStorage; use RetailCrm\Factory\ProductSchemaStorageFactory; @@ -85,6 +86,8 @@ class TopClientBuilder implements ContainerAwareInterface, BuilderInterface $client->setHttpClient($this->container->get(Constants::HTTP_CLIENT)); $client->setSerializer($this->container->get(Constants::SERIALIZER)); $client->setValidator($this->container->get(Constants::VALIDATOR)); + $client->setEnv($this->container->get(Environment::class)); + $client->setLogger($this->container->get(Constants::LOGGER)); $client->setRequestFactory($this->container->get(TopRequestFactoryInterface::class)); $client->setServiceLocator($this->container->get(ServiceLocator::class)); $client->setProcessor($this->container->get(TopRequestProcessorInterface::class)); diff --git a/src/Component/Environment.php b/src/Component/Environment.php index ec058b2..0a21109 100644 --- a/src/Component/Environment.php +++ b/src/Component/Environment.php @@ -12,6 +12,8 @@ */ namespace RetailCrm\Component; +use InvalidArgumentException; + /** * Class Environment * @@ -27,4 +29,41 @@ class Environment public const PROD = 'PROD'; public const DEV = 'DEV'; public const TEST = 'TEST'; + public const DEBUG_VALUES = [self::DEV, self::TEST]; + public const AVAILABLE_VALUES = [self::PROD, self::DEV, self::TEST]; + + /** + * @var string $value + */ + private $value; + + /** + * Environment constructor. + * + * @param string $value + */ + public function __construct(string $value) + { + if (!in_array($value, self::AVAILABLE_VALUES)) { + throw new InvalidArgumentException(sprintf('Incorrect environment provided: %s', $value)); + } + + $this->value = $value; + } + + /** + * @return bool + */ + public function isDebug(): bool + { + return in_array($this->value, self::DEBUG_VALUES); + } + + /** + * @return string + */ + public function getValue(): string + { + return $this->value; + } } diff --git a/src/Model/Request/AliExpress/Data/SingleOrderQuery.php b/src/Model/Request/AliExpress/Data/SingleOrderQuery.php new file mode 100644 index 0000000..df53c07 --- /dev/null +++ b/src/Model/Request/AliExpress/Data/SingleOrderQuery.php @@ -0,0 +1,36 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Request\AliExpress\Data; + +use JMS\Serializer\Annotation as JMS; + +/** + * Class SingleOrderQuery + * + * @category SingleOrderQuery + * @package RetailCrm\Model\Request\AliExpress\Data + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SingleOrderQuery +{ + /** + * @var int $orderId + * + * @JMS\Type("int") + * @JMS\SerializedName("order_id") + */ + public $orderId; +} diff --git a/src/Model/Request/AliExpress/LogisticsRedefiningListLogisticsService.php b/src/Model/Request/AliExpress/LogisticsRedefiningListLogisticsService.php new file mode 100644 index 0000000..e967338 --- /dev/null +++ b/src/Model/Request/AliExpress/LogisticsRedefiningListLogisticsService.php @@ -0,0 +1,45 @@ + + * @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 RetailCrm\Model\Response\AliExpress\LogisticsRedefiningListLogisticsServiceResponse; + +/** + * Class LogisticsRedefiningListLogisticsService + * + * @category LogisticsRedefiningListLogisticsService + * @package RetailCrm\Model\Request\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class LogisticsRedefiningListLogisticsService extends BaseRequest +{ + /** + * @inheritDoc + */ + public function getMethod(): string + { + return 'aliexpress.logistics.redefining.listlogisticsservice'; + } + + /** + * @inheritDoc + */ + public function getExpectedResponse(): string + { + return LogisticsRedefiningListLogisticsServiceResponse::class; + } +} diff --git a/src/Model/Request/AliExpress/SolutionOrderFulfill.php b/src/Model/Request/AliExpress/SolutionOrderFulfill.php new file mode 100644 index 0000000..777577b --- /dev/null +++ b/src/Model/Request/AliExpress/SolutionOrderFulfill.php @@ -0,0 +1,99 @@ + + * @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 Symfony\Component\Validator\Constraints as Assert; +use RetailCrm\Model\Response\AliExpress\SolutionOrderFulfillResponse; + +/** + * Class SolutionOrderFulfill + * + * @category SolutionOrderFulfill + * @package RetailCrm\Model\Request\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionOrderFulfill extends BaseRequest +{ + /** + * @var string $serviceName + * + * @JMS\Type("string") + * @JMS\SerializedName("service_name") + * @Assert\NotBlank() + */ + public $serviceName; + + /** + * @var string $trackingWebsite + * + * @JMS\Type("string") + * @JMS\SerializedName("tracking_website") + */ + public $trackingWebsite; + + /** + * @var string $outRef + * + * @JMS\Type("string") + * @JMS\SerializedName("out_ref") + * @Assert\NotBlank() + */ + public $outRef; + + /** + * @var string $sendType + * + * @JMS\Type("string") + * @JMS\SerializedName("send_type") + * @Assert\NotBlank() + */ + public $sendType; + + /** + * @var string $description + * + * @JMS\Type("string") + * @JMS\SerializedName("description") + */ + public $description; + + /** + * @var string $logisticsNo + * + * @JMS\Type("string") + * @JMS\SerializedName("logistics_no") + * @Assert\NotBlank() + */ + public $logisticsNo; + + /** + * @inheritDoc + */ + public function getMethod(): string + { + return 'aliexpress.solution.order.fulfill'; + } + + /** + * @inheritDoc + */ + public function getExpectedResponse(): string + { + return SolutionOrderFulfillResponse::class; + } +} diff --git a/src/Model/Request/AliExpress/SolutionOrderReceiptInfoGet.php b/src/Model/Request/AliExpress/SolutionOrderReceiptInfoGet.php new file mode 100644 index 0000000..ff906e9 --- /dev/null +++ b/src/Model/Request/AliExpress/SolutionOrderReceiptInfoGet.php @@ -0,0 +1,54 @@ + + * @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\SolutionOrderReceiptInfoGetResponse; + +/** + * Class SolutionOrderReceiptInfoGet + * + * @category SolutionOrderReceiptInfoGet + * @package RetailCrm\Model\Request\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionOrderReceiptInfoGet extends BaseRequest +{ + /** + * @var \RetailCrm\Model\Request\AliExpress\Data\SingleOrderQuery $param1 + * + * @JMS\Type("RetailCrm\Model\Request\AliExpress\Data\SingleOrderQuery") + * @JMS\SerializedName("param1") + */ + public $param1; + + /** + * @inheritDoc + */ + public function getMethod(): string + { + return 'aliexpress.solution.order.receiptinfo.get'; + } + + /** + * @inheritDoc + */ + public function getExpectedResponse(): string + { + return SolutionOrderReceiptInfoGetResponse::class; + } +} diff --git a/src/Model/Response/AliExpress/Data/LogisticsRedefiningListLogisticsServiceResponseData.php b/src/Model/Response/AliExpress/Data/LogisticsRedefiningListLogisticsServiceResponseData.php new file mode 100644 index 0000000..507449b --- /dev/null +++ b/src/Model/Response/AliExpress/Data/LogisticsRedefiningListLogisticsServiceResponseData.php @@ -0,0 +1,52 @@ + + * @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; + +/** + * Class LogisticsRedefiningListLogisticsServiceResponseData + * + * @category LogisticsRedefiningListLogisticsServiceResponseData + * @package RetailCrm\Model\Response\AliExpress\Data + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class LogisticsRedefiningListLogisticsServiceResponseData +{ + /** + * @var \RetailCrm\Model\Response\AliExpress\Result\Entity\AeopLogisticsServiceResultItemList $resultList + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Result\Entity\AeopLogisticsServiceResultItemList") + * @JMS\SerializedName("result_list") + */ + public $resultList; + + /** + * @var string $errorDesc + * + * @JMS\Type("string") + * @JMS\SerializedName("error_desc") + */ + public $errorDesc; + + /** + * @var bool $resultSuccess + * + * @JMS\Type("bool") + * @JMS\SerializedName("result_success") + */ + public $resultSuccess; +} diff --git a/src/Model/Response/AliExpress/Data/SolutionOrderFulfillResponseData.php b/src/Model/Response/AliExpress/Data/SolutionOrderFulfillResponseData.php new file mode 100644 index 0000000..3e44431 --- /dev/null +++ b/src/Model/Response/AliExpress/Data/SolutionOrderFulfillResponseData.php @@ -0,0 +1,36 @@ + + * @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; + +/** + * Class SolutionOrderFulfillResponseData + * + * @category SolutionOrderFulfillResponseData + * @package RetailCrm\Model\Response\AliExpress\Data + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionOrderFulfillResponseData +{ + /** + * @var \RetailCrm\Model\Response\AliExpress\Result\SuccessResult $result + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Result\SuccessResult") + * @JMS\SerializedName("result") + */ + public $result; +} diff --git a/src/Model/Response/AliExpress/Data/SolutionOrderReceiptInfoGetResponseData.php b/src/Model/Response/AliExpress/Data/SolutionOrderReceiptInfoGetResponseData.php new file mode 100644 index 0000000..24e1599 --- /dev/null +++ b/src/Model/Response/AliExpress/Data/SolutionOrderReceiptInfoGetResponseData.php @@ -0,0 +1,37 @@ + + * @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\AliExpress\Result\SolutionOrderReceiptInfoGetResponseResult; + +/** + * Class SolutionOrderReceiptInfoGetResponseData + * + * @category SolutionOrderReceiptInfoGetResponseData + * @package RetailCrm\Model\Response\AliExpress\Data + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionOrderReceiptInfoGetResponseData +{ + /** + * @var SolutionOrderReceiptInfoGetResponseResult $result + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Result\SolutionOrderReceiptInfoGetResponseResult") + * @JMS\SerializedName("result") + */ + public $result; +} diff --git a/src/Model/Response/AliExpress/LogisticsRedefiningListLogisticsServiceResponse.php b/src/Model/Response/AliExpress/LogisticsRedefiningListLogisticsServiceResponse.php new file mode 100644 index 0000000..180dd23 --- /dev/null +++ b/src/Model/Response/AliExpress/LogisticsRedefiningListLogisticsServiceResponse.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 LogisticsRedefiningListLogisticsServiceResponse + * + * @category LogisticsRedefiningListLogisticsServiceResponse + * @package RetailCrm\Model\Response\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class LogisticsRedefiningListLogisticsServiceResponse extends BaseResponse +{ + /** + * @var \RetailCrm\Model\Response\AliExpress\Data\LogisticsRedefiningListLogisticsServiceResponseData $responseData + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Data\LogisticsRedefiningListLogisticsServiceResponseData") + * @JMS\SerializedName("aliexpress_logistics_redefining_listlogisticsservice_response") + */ + public $responseData; +} diff --git a/src/Model/Response/AliExpress/Result/Entity/AeopLogisticsServiceResultItem.php b/src/Model/Response/AliExpress/Result/Entity/AeopLogisticsServiceResultItem.php new file mode 100644 index 0000000..d517cb9 --- /dev/null +++ b/src/Model/Response/AliExpress/Result/Entity/AeopLogisticsServiceResultItem.php @@ -0,0 +1,84 @@ + + * @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 AeopLogisticsServiceResultItem + * + * @category AeopLogisticsServiceResultItem + * @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 AeopLogisticsServiceResultItem +{ + /** + * @var int $recommendOrder + * + * @JMS\Type("int") + * @JMS\SerializedName("recommend_order") + */ + public $recommendOrder; + + /** + * @var string $trackingNoRegex + * + * @JMS\Type("string") + * @JMS\SerializedName("tracking_no_regex") + */ + public $trackingNoRegex; + + /** + * @var int $minProcessDay + * + * @JMS\Type("int") + * @JMS\SerializedName("min_process_day") + */ + public $minProcessDay; + + /** + * @var string $logisticsCompany + * + * @JMS\Type("string") + * @JMS\SerializedName("logistics_company") + */ + public $logisticsCompany; + + /** + * @var int $maxProcessDay + * + * @JMS\Type("int") + * @JMS\SerializedName("max_process_day") + */ + public $maxProcessDay; + + /** + * @var string $displayName + * + * @JMS\Type("string") + * @JMS\SerializedName("display_name") + */ + public $displayName; + + /** + * @var string $service_name + * + * @JMS\Type("string") + * @JMS\SerializedName("service_name") + */ + public $serviceName; +} diff --git a/src/Model/Response/AliExpress/Result/Entity/AeopLogisticsServiceResultItemList.php b/src/Model/Response/AliExpress/Result/Entity/AeopLogisticsServiceResultItemList.php new file mode 100644 index 0000000..b4115ff --- /dev/null +++ b/src/Model/Response/AliExpress/Result/Entity/AeopLogisticsServiceResultItemList.php @@ -0,0 +1,37 @@ + + * @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 AeopLogisticsServiceResultItemList + * + * @category AeopLogisticsServiceResultItemList + * @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 AeopLogisticsServiceResultItemList +{ + /** + * phpcs:ignore + * @var \RetailCrm\Model\Response\AliExpress\Result\Entity\AeopLogisticsServiceResultItem[] $aeopLogisticsServiceResult phpcs:ignore + * + * @JMS\Type("array") + * @JMS\SerializedName("aeop_logistics_service_result") + */ + public $aeopLogisticsServiceResult; +} diff --git a/src/Model/Response/AliExpress/Result/SolutionOrderReceiptInfoGetResponseResult.php b/src/Model/Response/AliExpress/Result/SolutionOrderReceiptInfoGetResponseResult.php new file mode 100644 index 0000000..8b17e54 --- /dev/null +++ b/src/Model/Response/AliExpress/Result/SolutionOrderReceiptInfoGetResponseResult.php @@ -0,0 +1,157 @@ + + * @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 SolutionOrderReceiptInfoGetResponseResult + * + * @category SolutionOrderReceiptInfoGetResponseResult + * @package RetailCrm\Model\Response\AliExpress\Result + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + * @SuppressWarnings(PHPMD.TooManyFields) + */ +class SolutionOrderReceiptInfoGetResponseResult +{ + /** + * @var string $countryName + * + * @JMS\Type("string") + * @JMS\SerializedName("country_name") + */ + public $countryName; + + /** + * @var string $mobileNo + * + * @JMS\Type("string") + * @JMS\SerializedName("mobile_no") + */ + public $mobileNo; + + /** + * @var string $contactPerson + * + * @JMS\Type("string") + * @JMS\SerializedName("contact_person") + */ + public $contactPerson; + + /** + * @var string $phoneCountry + * + * @JMS\Type("string") + * @JMS\SerializedName("phone_country") + */ + public $phoneCountry; + + /** + * @var string $phoneArea + * + * @JMS\Type("string") + * @JMS\SerializedName("phone_area") + */ + public $phoneArea; + + /** + * @var string $province + * + * @JMS\Type("string") + * @JMS\SerializedName("province") + */ + public $province; + + /** + * @var string $address + * + * @JMS\Type("string") + * @JMS\SerializedName("address") + */ + public $address; + + /** + * @var string $phoneNumber + * + * @JMS\Type("string") + * @JMS\SerializedName("phone_number") + */ + public $phoneNumber; + + /** + * @var string $faxNumber + * + * @JMS\Type("string") + * @JMS\SerializedName("fax_number") + */ + public $faxNumber; + + /** + * @var string $detailAddress + * + * @JMS\Type("string") + * @JMS\SerializedName("detail_address") + */ + public $detailAddress; + + /** + * @var string $city + * + * @JMS\Type("string") + * @JMS\SerializedName("city") + */ + public $city; + + /** + * @var string $country + * + * @JMS\Type("string") + * @JMS\SerializedName("country") + */ + public $country; + + /** + * @var string $address2 + * + * @JMS\Type("string") + * @JMS\SerializedName("address2") + */ + public $address2; + + /** + * @var string $faxCountry + * + * @JMS\Type("string") + * @JMS\SerializedName("fax_country") + */ + public $faxCountry; + + /** + * @var string $zip + * + * @JMS\Type("string") + * @JMS\SerializedName("zip") + */ + public $zip; + + /** + * @var string $faxArea + * + * @JMS\Type("string") + * @JMS\SerializedName("fax_area") + */ + public $faxArea; +} diff --git a/src/Model/Response/AliExpress/Result/SuccessResult.php b/src/Model/Response/AliExpress/Result/SuccessResult.php new file mode 100644 index 0000000..11612a5 --- /dev/null +++ b/src/Model/Response/AliExpress/Result/SuccessResult.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; + +use JMS\Serializer\Annotation as JMS; + +/** + * Class SuccessResult + * + * @category SuccessResult + * @package RetailCrm\Model\Response\AliExpress\Result + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SuccessResult +{ + /** + * @var bool $resultSuccess + * + * @JMS\Type("bool") + * @JMS\SerializedName("result_success") + */ + public $resultSuccess; +} diff --git a/src/Model/Response/AliExpress/SolutionOrderFulfillResponse.php b/src/Model/Response/AliExpress/SolutionOrderFulfillResponse.php new file mode 100644 index 0000000..4b631ea --- /dev/null +++ b/src/Model/Response/AliExpress/SolutionOrderFulfillResponse.php @@ -0,0 +1,38 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress; + +use RetailCrm\Model\Response\AliExpress\Data\SolutionOrderFulfillResponseData; +use RetailCrm\Model\Response\BaseResponse; +use JMS\Serializer\Annotation as JMS; + +/** + * Class SolutionOrderFulfillResponse + * + * @category SolutionOrderFulfillResponse + * @package RetailCrm\Model\Response\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionOrderFulfillResponse extends BaseResponse +{ + /** + * @var SolutionOrderFulfillResponseData $responseData + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Data\SolutionOrderFulfillResponseData") + * @JMS\SerializedName("aliexpress_solution_order_fulfill_response") + */ + public $responseData; +} diff --git a/src/Model/Response/AliExpress/SolutionOrderReceiptInfoGetResponse.php b/src/Model/Response/AliExpress/SolutionOrderReceiptInfoGetResponse.php new file mode 100644 index 0000000..9cb9795 --- /dev/null +++ b/src/Model/Response/AliExpress/SolutionOrderReceiptInfoGetResponse.php @@ -0,0 +1,38 @@ + + * @license http://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see http://help.retailcrm.ru + */ + +namespace RetailCrm\Model\Response\AliExpress; + +use RetailCrm\Model\Response\AliExpress\Data\SolutionOrderReceiptInfoGetResponseData; +use RetailCrm\Model\Response\BaseResponse; +use JMS\Serializer\Annotation as JMS; + +/** + * Class SolutionOrderReceiptInfoGetResponse + * + * @category SolutionOrderReceiptInfoGetResponse + * @package RetailCrm\Model\Response\AliExpress + * @author RetailDriver LLC + * @license https://retailcrm.ru Proprietary + * @link http://retailcrm.ru + * @see https://help.retailcrm.ru + */ +class SolutionOrderReceiptInfoGetResponse extends BaseResponse +{ + /** + * @var SolutionOrderReceiptInfoGetResponseData $responseData + * + * @JMS\Type("RetailCrm\Model\Response\AliExpress\Data\SolutionOrderReceiptInfoGetResponseData") + * @JMS\SerializedName("aliexpress_solution_order_receiptinfo_get_response") + */ + public $responseData; +} diff --git a/src/TopClient/TopClient.php b/src/TopClient/TopClient.php index 0104ebe..239f30f 100644 --- a/src/TopClient/TopClient.php +++ b/src/TopClient/TopClient.php @@ -16,7 +16,10 @@ use JMS\Serializer\SerializerInterface; use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\StreamInterface; +use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use RetailCrm\Builder\AuthorizationUriBuilder; +use RetailCrm\Component\Environment; use RetailCrm\Component\Exception\TopApiException; use RetailCrm\Component\Exception\TopClientException; use RetailCrm\Component\ServiceLocator; @@ -77,11 +80,6 @@ class TopClient implements TopClientInterface */ protected $serviceLocator; - /** - * @var \RetailCrm\Interfaces\RequestTimestampProviderInterface - */ - protected $timestampProvider; - /** * @var TopRequestProcessorInterface $processor */ @@ -97,6 +95,16 @@ class TopClient implements TopClientInterface */ protected $productSchemaStorageFactory; + /** + * @var \Psr\Log\LoggerInterface $logger + */ + protected $logger; + + /** + * @var Environment $environment + */ + protected $env; + /** * TopClient constructor. * @@ -180,6 +188,28 @@ class TopClient implements TopClientInterface return $this; } + /** + * @param \Psr\Log\LoggerInterface $logger + * + * @return TopClient + */ + public function setLogger(LoggerInterface $logger): TopClient + { + $this->logger = $logger; + return $this; + } + + /** + * @param \RetailCrm\Component\Environment $env + * + * @return TopClient + */ + public function setEnv(Environment $env): TopClient + { + $this->env = $env; + return $this; + } + /** * @return \RetailCrm\Component\ServiceLocator */ @@ -249,9 +279,10 @@ class TopClient implements TopClientInterface throw new TopClientException(sprintf('Error sending request: %s', $exception->getMessage()), $exception); } + $bodyData = self::getBodyContents($httpResponse->getBody()); /** @var BaseResponse $response */ $response = $this->serializer->deserialize( - self::getBodyContents($httpResponse->getBody()), + $bodyData, $request->getExpectedResponse(), $request->format ); @@ -264,6 +295,15 @@ class TopClient implements TopClientInterface throw new TopApiException($response->errorResponse, $response->requestId); } + if (null !== $this->logger && !($this->logger instanceof NullLogger) && $this->env->isDebug()) { + $this->logger->debug(sprintf( + ' Request %s (%s): got response %s', + $request->getMethod(), + $httpRequest->getUri()->__toString(), + $bodyData + )); + } + return $response; } diff --git a/tests/RetailCrm/Test/TestCase.php b/tests/RetailCrm/Test/TestCase.php index 9c45a11..b4bc0c1 100644 --- a/tests/RetailCrm/Test/TestCase.php +++ b/tests/RetailCrm/Test/TestCase.php @@ -50,7 +50,6 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase $this->container = ContainerBuilder::create() ->setEnv(Environment::TEST) ->setClient(is_null($client) ? self::getMockClient() : $client) - ->setLogger(new StdoutLogger()) ->setStreamFactory($factory) ->setRequestFactory($factory) ->setUriFactory($factory) diff --git a/tests/RetailCrm/Tests/TopClient/ClientTest.php b/tests/RetailCrm/Tests/TopClient/ClientTest.php index 7ef613d..efd3b6c 100644 --- a/tests/RetailCrm/Tests/TopClient/ClientTest.php +++ b/tests/RetailCrm/Tests/TopClient/ClientTest.php @@ -24,11 +24,15 @@ use RetailCrm\Model\Enum\OfflinePickupTypes; use RetailCrm\Model\Enum\OrderStatuses; use RetailCrm\Model\Request\AliExpress\Data\OrderQuery; use RetailCrm\Model\Request\AliExpress\Data\SingleItemRequestDto; +use RetailCrm\Model\Request\AliExpress\Data\SingleOrderQuery; +use RetailCrm\Model\Request\AliExpress\LogisticsRedefiningListLogisticsService; 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\SolutionOrderFulfill; use RetailCrm\Model\Request\AliExpress\SolutionOrderGet; +use RetailCrm\Model\Request\AliExpress\SolutionOrderReceiptInfoGet; use RetailCrm\Model\Request\AliExpress\SolutionProductSchemaGet; use RetailCrm\Model\Request\AliExpress\SolutionSellerCategoryTreeQuery; use RetailCrm\Model\Request\Taobao\HttpDnsGetRequest; @@ -616,4 +620,151 @@ EOF; $result->targetList->orderDto[0]->offlinePickupType ); } + + public function testAliexpressSolutionOrderReceiptInfoGet() + { + $json = <<<'EOF' +{ + "aliexpress_solution_order_receiptinfo_get_response":{ + "result":{ + "country_name":"Russian Federation", + "mobile_no":"4679974", + "contact_person":"Mark", + "phone_country":"04", + "phone_area":"12345", + "province":"Moscow", + "address":"address 001", + "phone_number":"88688435", + "fax_number":"88688436", + "detail_address":"center street No.99", + "city":"Babenki", + "country":"RU", + "address2":"address 001", + "fax_country":"400120", + "zip":"400120", + "fax_area":"203" + } + } +} +EOF; + $mock = self::getMockClient(); + $mock->on( + RequestMatcher::createMatcher('api.taobao.com') + ->setPath('/router/rest') + ->setOptionalQueryParams([ + 'app_key' => self::getEnvAppKey(), + 'method' => 'aliexpress.solution.order.receiptinfo.get', + 'session' => self::getEnvToken() + ]), + $this->responseJson(200, $json) + ); + $client = TopClientBuilder::create() + ->setContainer($this->getContainer($mock)) + ->setAppData($this->getEnvAppData()) + ->setAuthenticator($this->getEnvTokenAuthenticator()) + ->build(); + $query = new SingleOrderQuery(); + $query->orderId = 1; + $request = new SolutionOrderReceiptInfoGet(); + $request->param1 = $query; + + /** @var \RetailCrm\Model\Response\AliExpress\SolutionOrderReceiptInfoGetResponse $response */ + $response = $client->sendAuthenticatedRequest($request); + + self::assertNotNull($response->responseData); + self::assertNotNull($response->responseData->result); + + foreach (array_keys(get_class_vars(get_class($response->responseData->result))) as $key) { + self::assertNotEmpty($response->responseData->result->$key); + } + } + + public function testAliexpressLogisticsRedefiningListLogisticsService() + { + $json = <<<'EOF' +{ + "aliexpress_logistics_redefining_listlogisticsservice_response":{ + "result_list":{ + "aeop_logistics_service_result":[ + { + "recommend_order":11, + "tracking_no_regex":"^[a-zA-z]{2}[A-Za-z0-9]{9}[a-zA-z]{2}$", + "min_process_day":1, + "logistics_company":"CPAM", + "max_process_day":5, + "display_name":"China Post Registered Air Mail", + "service_name":"CPAM" + } + ] + }, + "error_desc":"System error", + "result_success":true + } +} +EOF; + $mock = self::getMockClient(); + $mock->on( + RequestMatcher::createMatcher('api.taobao.com') + ->setPath('/router/rest') + ->setOptionalQueryParams([ + 'app_key' => self::getEnvAppKey(), + 'method' => 'aliexpress.logistics.redefining.listlogisticsservice', + 'session' => self::getEnvToken() + ]), + $this->responseJson(200, $json) + ); + $client = TopClientBuilder::create() + ->setContainer($this->getContainer($mock)) + ->setAppData($this->getEnvAppData()) + ->setAuthenticator($this->getEnvTokenAuthenticator()) + ->build(); + /** @var \RetailCrm\Model\Response\AliExpress\LogisticsRedefiningListLogisticsServiceResponse $response */ + $response = $client->sendAuthenticatedRequest(new LogisticsRedefiningListLogisticsService()); + + self::assertEquals( + 'China Post Registered Air Mail', + $response->responseData->resultList->aeopLogisticsServiceResult[0]->displayName + ); + } + + public function testAliexpressSolutionOrderFulfill() + { + $json = <<<'EOF' +{ + "aliexpress_solution_order_fulfill_response":{ + "result":{ + "result_success":true + } + } +} +EOF; + $mock = self::getMockClient(); + $mock->on( + RequestMatcher::createMatcher('api.taobao.com') + ->setPath('/router/rest') + ->setOptionalQueryParams([ + 'app_key' => self::getEnvAppKey(), + 'method' => 'aliexpress.solution.order.fulfill', + 'session' => self::getEnvToken() + ]), + $this->responseJson(200, $json) + ); + $client = TopClientBuilder::create() + ->setContainer($this->getContainer($mock)) + ->setAppData($this->getEnvAppData()) + ->setAuthenticator($this->getEnvTokenAuthenticator()) + ->build(); + $request = new SolutionOrderFulfill(); + $request->serviceName = 'EMS'; + $request->trackingWebsite = 'www.17track.com'; + $request->outRef = '888877779999'; + $request->sendType = 'part'; + $request->description = 'memo'; + $request->logisticsNo = 'LA88887777CN'; + + /** @var \RetailCrm\Model\Response\AliExpress\SolutionOrderFulfillResponse $response */ + $response = $client->sendAuthenticatedRequest($request); + + self::assertTrue($response->responseData->result->resultSuccess); + } }