diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..9a874b5 Binary files /dev/null and b/.DS_Store differ diff --git a/composer.json b/composer.json index ee316aa..589214e 100644 --- a/composer.json +++ b/composer.json @@ -1,15 +1,16 @@ { - "name": "minchao/shopee-php", + "name": "upbase/shopee-php-sdk", "description": "Shopee Partner API PHP SDK", "type": "library", "keywords": [ "shopee", - "openapi" + "openapi", + "upbase" ], - "homepage": "https://github.com/minchao/shopee-php", + "homepage": "https://github.com/technology20nn/shopee-php", "license": "BSD-3-Clause", "support": { - "issues": "https://github.com/minchao/shopee-php/issues" + "issues": "https://github.com/technology20nn/shopee-php/issues" }, "require": { "php": ">=7.1", @@ -18,6 +19,7 @@ "psr/http-message": "^1.0" }, "require-dev": { + "mockery/mockery": "^1.4", "phpstan/phpstan": "^0.12.14", "phpunit/phpunit": "^7.5 || ^8.0 || ^9.0", "squizlabs/php_codesniffer": "^3.5" diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index ccb4086..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,19 +0,0 @@ - - - - - tests - - - - - src - - - diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..4fc470d Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/Client.php b/src/Client.php index 7f55e62..2df4104 100644 --- a/src/Client.php +++ b/src/Client.php @@ -116,6 +116,7 @@ public function __construct(array $config = []) $this->nodes['image'] = new Nodes\Image\Image($this); $this->nodes['push'] = new Nodes\Push\Push($this); $this->nodes['payment'] = new Nodes\Payment\Payment($this); + $this->nodes['ads'] = new Nodes\Ads\Ads($this); } public function __get(string $name) @@ -268,4 +269,5 @@ public function send(RequestInterface $request): ResponseInterface return $response; } + } diff --git a/src/ClientV2.php b/src/ClientV2.php new file mode 100644 index 0000000..27360d4 --- /dev/null +++ b/src/ClientV2.php @@ -0,0 +1,453 @@ + null, + 'baseUrl' => self::DEFAULT_BASE_URL, + 'userAgent' => self::DEFAULT_USER_AGENT, + 'secret' => getenv(self::ENV_SECRET_NAME), + 'partner_id' => (int)getenv(self::ENV_PARTNER_ID_NAME), + 'shop_id' => (int)getenv(self::ENV_SHOP_ID_NAME), + 'access_token' => '', + 'api_type' => self::API_TYPE_PUBLIC, + 'merchant_id' => '', + SignatureGeneratorInterface::class => null, + ], $config); + + $this->httpClient = $config['httpClient'] ?: new HttpClient(); + $this->setBaseUrl($config['baseUrl']); + $this->setUserAgent($config['userAgent']); + $this->secret = $config['secret']; + $this->partnerId = $config['partner_id']; + $this->shopId = $config['shop_id']; + $this->accessToken = $config['access_token']; + $this->merchantId = $config['merchant_id']; + $this->apiType = $config['api_type']; + + $signatureGenerator = $config[SignatureGeneratorInterface::class]; + if (is_null($signatureGenerator)) { + $this->signatureGenerator = new SignatureGenerator($this->secret); + } elseif ($signatureGenerator instanceof SignatureGeneratorInterface) { + $this->signatureGenerator = $signatureGenerator; + } else { + throw new InvalidArgumentException('Signature generator not implement SignatureGeneratorInterface'); + } + + $this->nodes['author'] = new Nodes\Shop\Authorization($this); + $this->nodes['shop'] = new Nodes\Shop\Shop($this); + $this->nodes['category'] = new Nodes\Item\Category($this); + $this->nodes['brand'] = new Nodes\Item\Brand($this); + $this->nodes['attribute'] = new Nodes\Item\Attribute($this); + $this->nodes['item'] = new Nodes\Item\Item($this); + $this->nodes['image'] = new Nodes\Image\Image($this); + $this->nodes['logistic'] = new Nodes\Logistics\Logistics($this); + $this->nodes['order'] = new Nodes\Order\Order($this); + $this->nodes['payment'] = new Nodes\Payment\Payment($this); + $this->nodes['video'] = new Nodes\Video\Video($this); + $this->nodes['returns'] = new Nodes\Returns\Returns($this); + $this->nodes['discount'] = new Nodes\Discount\Discount($this); + $this->nodes['chat'] = new Nodes\Chat\Chat($this); + $this->nodes['voucher'] = new Nodes\Voucher\Voucher($this); + $this->nodes['add_on_deal'] = new Nodes\AddOnDeal\AddOnDeal($this); + $this->nodes['ads'] = new Nodes\Ads\Ads($this); + $this->nodes['flash_sale'] = new Nodes\FlashSale\FlashSale($this); + } + + public function __get(string $name) + { + if (!array_key_exists($name, $this->nodes)) { + throw new InvalidArgumentException(sprintf('Property "%s" not exists', $name)); + } + + return $this->nodes[$name]; + } + + public function getHttpClient(): ClientInterface + { + return $this->httpClient; + } + + /** + * @param ClientInterface $client + * @return $this + */ + public function setHttpClient(ClientInterface $client) + { + $this->httpClient = $client; + + return $this; + } + + public function getUserAgent(): string + { + return $this->userAgent; + } + + /** + * @param string $userAgent + * @return $this + */ + public function setUserAgent(string $userAgent) + { + $this->userAgent = $userAgent; + + return $this; + } + + public function getBaseUrl(): UriInterface + { + return $this->baseUrl; + } + + /** + * @param string $url + * @return $this + */ + public function setBaseUrl(string $url) + { + $this->baseUrl = new Uri($url); + + return $this; + } + + public function getDefaultParameters($type_api = self::API_TYPE_SHOP): array + { + if($type_api == self::API_TYPE_PUBLIC){ + return [ + 'partner_id' => $this->partnerId, + 'timestamp' => time(), // Put the current UNIX timestamp when making a request + ]; + }else{ + return [ + 'partner_id' => $this->partnerId, + 'shopid' => $this->shopId, + 'timestamp' => time(), // Put the current UNIX timestamp when making a request + ]; + } + } + + /** + * Create HTTP JSON body + * + * The HTTP body should contain a serialized JSON string only + * + * @param array $data + * @return string + */ + protected function createJsonBody(array $data, $type_api = self::API_TYPE_SHOP): string + { + $data = array_merge($this->getDefaultParameters($type_api), $data); + + return json_encode($data); + } + + /** + * Generate an HMAC-SHA256 signature for a HTTP request + * + * @param UriInterface $uri + * @param integer $api_type + * @return string + */ + protected function signature($uri, $api_type): string + { + switch ($api_type) { + case self::API_TYPE_PUBLIC: + return $auth_query = $this->signatureGenerator->generateSignaturePublicLevel($uri, $this->partnerId); + case self::API_TYPE_SHOP: + return $auth_query = $this->signatureGenerator->generateSignatureShopLevel($uri, $this->partnerId, $this->accessToken, $this->shopId); + case self::API_TYPE_MERCHANT: + return $auth_query = $this->signatureGenerator->generateSignatureMerchantLevel($uri, $this->partnerId, $this->accessToken, $this->merchantId); + default: + return ""; + } + } + + /** + * @param string|UriInterface $uri + * @param $api_type integer + * @param array $headers + * @param array $data + * @return RequestInterface + */ + public function newRequest($uri, $api_type, array $headers = [], $data = []): RequestInterface + { + $uri = Utils::uriFor($uri); + $auth_query = $this->signature($uri, $api_type); + $path = $this->baseUrl->getPath() . $uri->getPath(); + $uri = $uri + ->withScheme($this->baseUrl->getScheme()) + ->withUserInfo($this->baseUrl->getUserInfo()) + ->withHost($this->baseUrl->getHost()) + ->withPort($this->baseUrl->getPort()) + ->withPath($path) + ->withQuery($auth_query); + + $jsonBody = $this->createJsonBody($data, $api_type); + + $headers['User-Agent'] = $this->userAgent; + $headers['Content-Type'] = 'application/json'; + + return new Request( + 'POST', // All APIs should use POST method + $uri, + $headers, + $jsonBody + ); + } + + public function upload(RequestInterface $request, $file_url, $field_name = 'image'): ResponseInterface + { + try { + list($tempImageDownload, $fileName) = $this->downloadFile($file_url); + $response = $this->httpClient->request( + "POST", + $request->getUri(), + [ + 'multipart' => [ + [ + 'name' => $field_name, + 'contents' => fopen($tempImageDownload, 'r'), + 'file_name' => $fileName + ], + ] + ]); + } catch (GuzzleClientException $exception) { + switch ($exception->getCode()) { + case 400: + $className = BadRequestException::class; + break; + case 403: + $className = AuthException::class; + break; + default: + $className = ClientException::class; + } + + throw Factory::create($className, $exception); + } catch (GuzzleServerException $exception) { + throw Factory::create(ServerException::class, $exception); + } catch (GuzzleException $exception) { + throw Factory::create(ServerException::class, $exception); + } + + return $response; + } + + public function uploadVideoPart(RequestInterface $request, $video_upload_id, $file_name, $chunk, $part_seq): ResponseInterface + { + try { + $part_md5 = md5($chunk); + $boundary = '----iCEBrkUploaderBoundary' . uniqid(); + $response = $this->httpClient->request( + "POST", + $request->getUri(), + [ + 'headers' => [ + 'Transfer-Encoding' => 'chunked', + 'Accept-Encoding' => 'gzip, deflate, br', + 'Accept' => 'application/json, text/javascript, */*; q=0.01', + 'Content-disposition' => 'attachment; filename="' . $file_name . '"', + 'Content-length' => strlen($chunk)-1, + ], + 'multipart' => [ + [ + 'name' => 'video_upload_id', + 'contents' => $video_upload_id, + ], + [ + 'name' => 'part_seq', + 'contents' => $part_seq, + ], + [ + 'name' => 'content_md5', + 'contents' => $part_md5, + ], + [ + 'name' => 'part_content', + 'contents' => $chunk, + 'filename' => $file_name, + 'headers' => [ + 'Content-Type' => 'multipart/form-data; boundary=' . $boundary + ] + ] + ] + ]); + + } catch (GuzzleClientException $exception) { + switch ($exception->getCode()) { + case 400: + $className = BadRequestException::class; + break; + case 403: + $className = AuthException::class; + break; + default: + $className = ClientException::class; + } + + throw Factory::create($className, $exception); + } catch (GuzzleServerException $exception) { + throw Factory::create(ServerException::class, $exception); + } catch (GuzzleException $exception) { + throw Factory::create(ServerException::class, $exception); + } + + return $response; + } + + public function send(RequestInterface $request): ResponseInterface + { + try { + $response = $this->httpClient->send($request); + } catch (GuzzleClientException $exception) { + switch ($exception->getCode()) { + case 400: + $className = BadRequestException::class; + break; + case 403: + $className = AuthException::class; + break; + default: + $className = ClientException::class; + } + + throw Factory::create($className, $exception); + } catch (GuzzleServerException $exception) { + throw Factory::create(ServerException::class, $exception); + } + + return $response; + } + + public function getAuthorizationUrl($redirect_url) + { + $uri = Utils::uriFor("/api/v2/shop/auth_partner"); + $auth_query = $this->signature($uri, self::API_TYPE_PUBLIC); + $uri = Utils::uriFor($uri); + $path = $this->baseUrl->getPath() . $uri->getPath(); + + $uri = $uri + ->withScheme($this->baseUrl->getScheme()) + ->withUserInfo($this->baseUrl->getUserInfo()) + ->withHost($this->baseUrl->getHost()) + ->withPort($this->baseUrl->getPort()) + ->withPath($path) + ->withQuery($auth_query); + $uri = Uri::withQueryValue($uri, 'redirect', $redirect_url); + return $uri->__toString(); + } + + public function downloadFile($urlDownload) + { + $path_info = pathinfo($urlDownload); + $filename = $path_info['basename']; + $tempImage = tempnam(sys_get_temp_dir(), 'shopee').$filename; + copy($urlDownload, $tempImage); + return [$tempImage, $filename]; + } + +} diff --git a/src/Nodes/.DS_Store b/src/Nodes/.DS_Store new file mode 100644 index 0000000..9ef028a Binary files /dev/null and b/src/Nodes/.DS_Store differ diff --git a/src/Nodes/AddOnDeal/AddOnDeal.php b/src/Nodes/AddOnDeal/AddOnDeal.php new file mode 100644 index 0000000..1586cff --- /dev/null +++ b/src/Nodes/AddOnDeal/AddOnDeal.php @@ -0,0 +1,126 @@ +post('/api/v2/add_on_deal/add_add_on_deal', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to add shop add on deal item. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function addAddOnDealMainItem($parameters = []): ResponseData + { + return $this->post('/api/v2/add_on_deal/add_add_on_deal_main_item', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to delete one add on deal activity BEFORE it starts. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function addAddOnDealSubItem($parameters = []): ResponseData + { + return $this->post('/api/v2/add_on_deal/add_add_on_deal_sub_item', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to delete items of the add on deal activity. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function deleteAddOnDeal($parameters = []): ResponseData + { + return $this->post('/api/v2/add_on_deal/delete_add_on_deal', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to get one shop add on deal activity detail. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function deleteAddOnDealMainItem($parameters = []): ResponseData + { + return $this->post('/api/v2/add_on_deal/delete_add_on_deal_main_item', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to get shop add on deal activity list. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function deleteAddOnDealSubItem($parameters = []): ResponseData + { + return $this->post('/api/v2/add_on_deal/delete_add_on_deal_sub_item', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to update one add on deal information + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function updateAddOnDeal($parameters = []): ResponseData + { + return $this->post('/api/v2/add_on_deal/update_add_on_deal', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to update items of the add on deal activity. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function updateAddOnDealMainItem($parameters = []): ResponseData + { + return $this->post('/api/v2/add_on_deal/update_add_on_deal_main_item', ClientV2::API_TYPE_SHOP, $parameters); + } + public function updateAddOnDealSubItem($parameters = []): ResponseData + { + return $this->post('/api/v2/add_on_deal/update_add_on_deal_sub_item', ClientV2::API_TYPE_SHOP, $parameters); + } + + public function endAddOnDeal($parameters = []): ResponseData + { + return $this->post('/api/v2/add_on_deal/end_add_on_deal', ClientV2::API_TYPE_SHOP, $parameters); + } + + public function getAddOnDealList($parameters = []): ResponseData + { + return $this->get('/api/v2/add_on_deal/get_add_on_deal_list', ClientV2::API_TYPE_SHOP, $parameters); + } + + public function getAddOnDeal($parameters = []): ResponseData + { + return $this->get('/api/v2/add_on_deal/get_add_on_deal', ClientV2::API_TYPE_SHOP, $parameters); + } + public function getAddOnDealMainItem($parameters = []): ResponseData + { + return $this->get('/api/v2/add_on_deal/get_add_on_deal_main_item', ClientV2::API_TYPE_SHOP, $parameters); + } + public function getAddOnDealSubItem($parameters = []): ResponseData + { + return $this->get('/api/v2/add_on_deal/get_add_on_deal_sub_item', ClientV2::API_TYPE_SHOP, $parameters); + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/AddAddOnDeal.php b/src/Nodes/AddOnDeal/Parameters/AddAddOnDeal.php new file mode 100755 index 0000000..d678f23 --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/AddAddOnDeal.php @@ -0,0 +1,120 @@ +parameters['add_on_deal_name']; + } + + /** + * @param string $add_on_deal_name + * @return $this + */ + public function setAddOnDealName(string $add_on_deal_name) + { + $this->parameters['add_on_deal_name'] = $add_on_deal_name; + return $this; + } + + public function getStartTime(): int + { + return $this->parameters['start_time']; + } + + /** + * @param int $start_time + * @return $this + */ + public function setStartTime(int $start_time) + { + $this->parameters['start_time'] = $start_time; + + return $this; + } + + public function getEndTime(): int + { + return $this->parameters['end_time']; + } + + /** + * @param int $end_time + * @return $this + */ + public function setEndTime(int $end_time) + { + $this->parameters['end_time'] = $end_time; + + return $this; + } + + public function getPromotionType(): int + { + return $this->parameters['promotion_type']; + } + + /** + * @param int $promotion_type + * @return $this + */ + public function setPromotionType(int $promotion_type) + { + $this->parameters['promotion_type'] = $promotion_type; + + return $this; + } + + public function getPuschaseMinSpend(): float + { + return $this->parameters['purchase_min_spend']; + } + + /** + * @param float|null $purchase_min_spend + * @return $this + */ + public function setPuschaseMinSpend($purchase_min_spend) + { + $this->parameters['purchase_min_spend'] = $purchase_min_spend; + + return $this; + } + + public function getPerGiftNum(): int + { + return $this->parameters['per_gift_num']; + } + + /** + * @param int|null $per_gift_num + * @return $this + */ + public function setPerGiftNum($per_gift_num) + { + $this->parameters['per_gift_num'] = $per_gift_num; + + return $this; + } + + public function getPromotionPurchaseLimit(): int + { + return $this->parameters['promotion_purchase_limit']; + } + + /** + * @param int|null $promotion_purchase_limit + * @return $this + */ + public function setPromotionPurchaseLimit($promotion_purchase_limit) + { + $this->parameters['promotion_purchase_limit'] = $promotion_purchase_limit; + + return $this; + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/AddAddOnDealMainItem.php b/src/Nodes/AddOnDeal/Parameters/AddAddOnDealMainItem.php new file mode 100755 index 0000000..1d15449 --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/AddAddOnDealMainItem.php @@ -0,0 +1,28 @@ +parameters['main_item_list']; + } + + /** + * + * @param MainItemList $main_item_list + * @return $this + */ + public function setMainItemList(MainItemList $main_item_list) + { + $this->parameters['main_item_list'] = $main_item_list; + return $this; + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/AddAddOnDealSubItem.php b/src/Nodes/AddOnDeal/Parameters/AddAddOnDealSubItem.php new file mode 100755 index 0000000..11ce954 --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/AddAddOnDealSubItem.php @@ -0,0 +1,27 @@ +parameters['sub_item_list']; + } + + /** + * + * @param SubItemList $sub_item_list + * @return $this + */ + public function setSubItemList(SubItemList $sub_item_list) + { + $this->parameters['sub_item_list'] = $sub_item_list; + return $this; + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/AddOnDealTrait.php b/src/Nodes/AddOnDeal/Parameters/AddOnDealTrait.php new file mode 100644 index 0000000..c34c266 --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/AddOnDealTrait.php @@ -0,0 +1,22 @@ +parameters['add_on_deal_id']; + } + + /** + * @param int $add_on_deal_id + * @return $this + */ + public function setAddOnDealId(int $add_on_deal_id) + { + $this->parameters['add_on_deal_id'] = $add_on_deal_id; + return $this; + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/DeleteAddOnDeal.php b/src/Nodes/AddOnDeal/Parameters/DeleteAddOnDeal.php new file mode 100755 index 0000000..f91a091 --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/DeleteAddOnDeal.php @@ -0,0 +1,10 @@ +parameters['main_item_list']; + } + + /** + * @param array $main_item_list + * @return $this + */ + public function setMainItemList(array $main_item_list) + { + $this->parameters['main_item_list'] = $main_item_list; + return $this; + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/DeleteAddOnDealSubItem.php b/src/Nodes/AddOnDeal/Parameters/DeleteAddOnDealSubItem.php new file mode 100755 index 0000000..0654579 --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/DeleteAddOnDealSubItem.php @@ -0,0 +1,26 @@ +parameters['sub_item_list']; + } + + /** + * @param $sub_item_list + * @return $this + */ + public function setMainItemList(SubItemList $sub_item_list) + { + $this->parameters['sub_item_list'] = $sub_item_list; + return $this; + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/EndAddOnDeal.php b/src/Nodes/AddOnDeal/Parameters/EndAddOnDeal.php new file mode 100755 index 0000000..202e122 --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/EndAddOnDeal.php @@ -0,0 +1,10 @@ +parameters['promotion_status']; + } + + /** + * @param string $promotion_status + * @return $this + */ + public function setPromotionStatus(string $promotion_status) + { + $this->parameters['promotion_status'] = $promotion_status; + + return $this; + } + + public function getPageNo(): int + { + return $this->parameters['page_no']; + } + + /** + * @param int $page_no + * @return $this + */ + public function setPageNo(int $page_no) + { + $this->parameters['page_no'] = $page_no; + + return $this; + } + + public function getPageSize(): int + { + return $this->parameters['page_size']; + } + + /** + * @param int $page_size + * @return $this + */ + public function setPageSize(int $page_size) + { + $this->parameters['page_size'] = $page_size; + + return $this; + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/GetAddOnDealMainItem.php b/src/Nodes/AddOnDeal/Parameters/GetAddOnDealMainItem.php new file mode 100755 index 0000000..4bd762d --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/GetAddOnDealMainItem.php @@ -0,0 +1,10 @@ +parameters['item_id']; + } + + /** + * @param int $item_id + * @return $this + */ + public function setItemId(int $item_id) + { + $this->parameters['item_id'] = $item_id; + + return $this; + } + + public function getStatus(): int + { + return $this->parameters['status']; + } + + /** + * @param int $status + * @return $this + */ + public function setStatus(int $status) + { + $this->parameters['status'] = $status; + + return $this; + } + +} diff --git a/src/Nodes/AddOnDeal/Parameters/MainItemList.php b/src/Nodes/AddOnDeal/Parameters/MainItemList.php new file mode 100755 index 0000000..51f4db3 --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/MainItemList.php @@ -0,0 +1,34 @@ +add(new MainItem($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/SubItem.php b/src/Nodes/AddOnDeal/Parameters/SubItem.php new file mode 100755 index 0000000..940b8bc --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/SubItem.php @@ -0,0 +1,89 @@ +parameters['item_id']; + } + + /** + * @param int $item_id + * @return $this + */ + public function setItemId(int $item_id) + { + $this->parameters['item_id'] = $item_id; + + return $this; + } + + public function getModelId(): int + { + return $this->parameters['model_id']; + } + + /** + * @param int $model_id + * @return $this + */ + public function setModelId(int $model_id) + { + $this->parameters['model_id'] = $model_id; + + return $this; + } + + public function getStatus(): int + { + return $this->parameters['status']; + } + + /** + * @param int $status + * @return $this + */ + public function setStatus(int $status) + { + $this->parameters['status'] = $status; + + return $this; + } + + public function getSubItemInputPrice(): float + { + return $this->parameters['sub_item_input_price']; + } + + /** + * @param float $sub_item_input_price + * @return $this + */ + public function setSubItemInputPrice(float $sub_item_input_price) + { + $this->parameters['sub_item_input_price'] = $sub_item_input_price; + + return $this; + } + + public function getSubItemLimit(): float + { + return $this->parameters['sub_item_limit']; + } + + /** + * @param float $sub_item_limit + * @return $this + */ + public function setSubItemLimit(float $sub_item_limit) + { + $this->parameters['sub_item_limit'] = $sub_item_limit; + + return $this; + } + +} diff --git a/src/Nodes/AddOnDeal/Parameters/SubItemList.php b/src/Nodes/AddOnDeal/Parameters/SubItemList.php new file mode 100755 index 0000000..c181095 --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/SubItemList.php @@ -0,0 +1,33 @@ +add(new SubItem($parameter)); + } + return $this; + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/UpdateAddOnDeal.php b/src/Nodes/AddOnDeal/Parameters/UpdateAddOnDeal.php new file mode 100755 index 0000000..0eb957a --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/UpdateAddOnDeal.php @@ -0,0 +1,121 @@ +parameters['add_on_deal_name']; + } + + /** + * @param string $add_on_deal_name + * @return $this + */ + public function setAddOnDealName(string $add_on_deal_name) + { + $this->parameters['add_on_deal_name'] = $add_on_deal_name; + return $this; + } + + public function getStartTime(): int + { + return $this->parameters['start_time']; + } + + /** + * @param int $start_time + * @return $this + */ + public function setStartTime(int $start_time) + { + $this->parameters['start_time'] = $start_time; + + return $this; + } + + public function getEndTime(): int + { + return $this->parameters['end_time']; + } + + /** + * @param int $end_time + * @return $this + */ + public function setEndTime(int $end_time) + { + $this->parameters['end_time'] = $end_time; + + return $this; + } + + public function getPuschaseMinSpend(): float + { + return $this->parameters['purchase_min_spend']; + } + + /** + * @param float $purchase_min_spend + * @return $this + */ + public function setPuschaseMinSpend(float $purchase_min_spend) + { + $this->parameters['purchase_min_spend'] = $purchase_min_spend; + + return $this; + } + + public function getPerGiftNum(): int + { + return $this->parameters['per_gift_num']; + } + + /** + * @param int $per_gift_num + * @return $this + */ + public function setPerGiftNum(int $per_gift_num) + { + $this->parameters['per_gift_num'] = $per_gift_num; + + return $this; + } + + public function getPromotionPurchaseLimit(): int + { + return $this->parameters['promotion_purchase_limit']; + } + + /** + * @param int $promotion_purchase_limit + * @return $this + */ + public function setPromotionPurchaseLimit($promotion_purchase_limit) + { + $this->parameters['promotion_purchase_limit'] = $promotion_purchase_limit; + + return $this; + } + + public function getSubItemPriority(): array + { + return $this->parameters['sub_item_priority']; + } + + /** + * @param array $sub_item_priority + * @return $this + */ + public function setSubItemPriority(array $sub_item_priority) + { + $this->parameters['sub_item_priority'] = $sub_item_priority; + + return $this; + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/UpdateAddOnDealMainItem.php b/src/Nodes/AddOnDeal/Parameters/UpdateAddOnDealMainItem.php new file mode 100755 index 0000000..8cf5506 --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/UpdateAddOnDealMainItem.php @@ -0,0 +1,28 @@ +parameters['main_item_list']; + } + + /** + * + * @param MainItemList $main_item_list + * @return $this + */ + public function setMainItemList(MainItemList $main_item_list) + { + $this->parameters['main_item_list'] = $main_item_list; + return $this; + } +} diff --git a/src/Nodes/AddOnDeal/Parameters/UpdateAddOnDealSubItem.php b/src/Nodes/AddOnDeal/Parameters/UpdateAddOnDealSubItem.php new file mode 100755 index 0000000..ad39a8f --- /dev/null +++ b/src/Nodes/AddOnDeal/Parameters/UpdateAddOnDealSubItem.php @@ -0,0 +1,28 @@ +parameters['main_item_list']; + } + + /** + * + * @param SubItemList $main_item_list + * @return $this + */ + public function setSubItemList(SubItemList $main_item_list) + { + $this->parameters['main_item_list'] = $main_item_list; + return $this; + } +} diff --git a/src/Nodes/Ads/.DS_Store b/src/Nodes/Ads/.DS_Store new file mode 100644 index 0000000..a02d7e7 Binary files /dev/null and b/src/Nodes/Ads/.DS_Store differ diff --git a/src/Nodes/Ads/Ads.php b/src/Nodes/Ads/Ads.php new file mode 100644 index 0000000..e74eb24 --- /dev/null +++ b/src/Nodes/Ads/Ads.php @@ -0,0 +1,34 @@ +get("/api/v2/ads/get_all_cpc_ads_daily_performance", ClientV2::API_TYPE_SHOP, $parameters); + } + + public function getCPCAdsHourlyPerformance($parameters = []): ResponseData + { + return $this->get("/api/v2/ads/get_all_cpc_ads_hourly_performance", ClientV2::API_TYPE_SHOP, $parameters); + } + + public function getProductCampainDailyPerformance($parameters = []): ResponseData + { + return $this->get("/api/v2/ads/get_product_campaign_daily_performance", ClientV2::API_TYPE_SHOP, $parameters); + } + +} diff --git a/src/Nodes/Ads/Parameters/GetCqcAdsDailyPerformance.php b/src/Nodes/Ads/Parameters/GetCqcAdsDailyPerformance.php new file mode 100644 index 0000000..9e1b928 --- /dev/null +++ b/src/Nodes/Ads/Parameters/GetCqcAdsDailyPerformance.php @@ -0,0 +1,27 @@ +parameters['start_date'] = $start_date; + } + public function setStartDate($start_date) + { + $this->parameters['start_date'] = $start_date; + return $this; + } + public function getEndDate($start_date) + { + return $this->parameters['end_date'] = $start_date; + } + public function setEndDate($start_date) + { + $this->parameters['end_date'] = $start_date; + return $this; + } +} \ No newline at end of file diff --git a/src/Nodes/Chat/Chat.php b/src/Nodes/Chat/Chat.php new file mode 100755 index 0000000..af3f8e9 --- /dev/null +++ b/src/Nodes/Chat/Chat.php @@ -0,0 +1,73 @@ +get("/api/v2/sellerchat/get_conversation_list", ClientV2::API_TYPE_SHOP, $parameters); + } + /** + * Use this call to get information of shop. + * https://open.shopee.com/documents/v2/v2.sellerchat.get_one_conversation?module=109&type=1 + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function getOneConversation($parameters = []): ResponseData { + return $this->get("/api/v2/sellerchat/get_one_conversation", ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this call to get information of shop. + * https://open.shopee.com/documents/v2/v2.sellerchat.read_conversation?module=109&type=1 + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function readConversation($parameters = []): ResponseData { + return $this->post("/api/v2/sellerchat/read_conversation", ClientV2::API_TYPE_SHOP, $parameters); + } + /** + * https://open.shopee.com/documents/v2/v2.sellerchat.get_message?module=109&type=1 + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function getMessages($parameters = []): ResponseData { + return $this->get("/api/v2/sellerchat/get_message", ClientV2::API_TYPE_SHOP, $parameters); + } + /** + * https://open.shopee.com/documents/v2/v2.sellerchat.send_message?module=109&type=1 + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function sendMessage($parameters = []): ResponseData { + return $this->post("/api/v2/sellerchat/send_message", ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * https://open.shopee.com/documents/v2/v2.sellerchat.send_autoreply_message?module=109&type=1 + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function sendAutoReply($parameters = []): ResponseData { + return $this->post("/api/v2/sellerchat/send_autoreply_message", ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * https://open.shopee.com/documents/v2/v2.sellerchat.upload_image?module=109&type=1 + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function uploadImage($image_url, $parameters = []): ResponseData { + return $this->chatUploadWithBody("/api/v2/sellerchat/upload_image", ClientV2::API_TYPE_SHOP, $image_url, $parameters); + } +} diff --git a/src/Nodes/Chat/Parameters/GetMessages.php b/src/Nodes/Chat/Parameters/GetMessages.php new file mode 100644 index 0000000..d75d4ff --- /dev/null +++ b/src/Nodes/Chat/Parameters/GetMessages.php @@ -0,0 +1,70 @@ +parameters['message_id_list']; + } + + /** + * @param int $message_id_list + * @return $this + */ + public function setMessageIdList($message_id_list) + { + $this->parameters['message_id_list'] = $message_id_list; + + return $this; + } + + public function getConversationId() + { + return $this->parameters['conversation_id']; + } + + /** + * @param int $conversation_id + * @return $this + */ + public function setConversationId(int $conversation_id) + { + $this->parameters['conversation_id'] = $conversation_id; + + return $this; + } + + public function getPageSize(){ + return $this->parameters['page_size']; + } + + /** + * @param MessageContent + * @return $this + */ + public function setPageSize($page_size) + { + $this->parameters['page_size'] = $page_size; + + return $this; + } + + public function getOffset(){ + return $this->parameters['offset']; + } + + /** + * @param MessageContent + * @return $this + */ + public function setOffset($offset) + { + $this->parameters['offset'] = $offset; + + return $this; + } +} diff --git a/src/Nodes/Chat/Parameters/Message.php b/src/Nodes/Chat/Parameters/Message.php new file mode 100644 index 0000000..6709d6c --- /dev/null +++ b/src/Nodes/Chat/Parameters/Message.php @@ -0,0 +1,55 @@ +parameters['to_id']; + } + + /** + * @param int $to_id + * @return $this + */ + public function setToId(int $to_id) + { + $this->parameters['to_id'] = $to_id; + + return $this; + } + + public function getMessageType(): string + { + return $this->parameters['message_type']; + } + + /** + * @param string $message_type + * @return $this + */ + public function setMessageType(string $message_type) + { + $this->parameters['message_type'] = $message_type; + + return $this; + } + + public function getMessageContent(){ + return $this->parameters['content']; + } + + /** + * @param MessageContent + * @return $this + */ + public function setMessageContent($message_content) + { + $this->parameters['content'] = $message_content; + + return $this; + } +} diff --git a/src/Nodes/Chat/Parameters/MessageContent.php b/src/Nodes/Chat/Parameters/MessageContent.php new file mode 100644 index 0000000..d545d07 --- /dev/null +++ b/src/Nodes/Chat/Parameters/MessageContent.php @@ -0,0 +1,70 @@ +parameters['text']; + } + + /** + * @param int $text + * @return $this + */ + public function setText(string $text) + { + $this->parameters['text'] = $text; + + return $this; + } + + public function getImageUrl(): string + { + return $this->parameters['image_url']; + } + + /** + * @param string $image_url + * @return $this + */ + public function setImageUrl(string $image_url) + { + $this->parameters['image_url'] = $image_url; + + return $this; + } + + public function getItemId() + { + return $this->parameters['item_id']; + } + + /** + * @param $item_id + * @return $this + */ + public function setItemId($item_id) + { + $this->parameters['item_id'] = $item_id; + return $this; + } + + public function getOrderSn(): string + { + return $this->parameters['order_sn']; + } + + /** + * @param string $order_sn + * @return $this + */ + public function setOrderSn(string $order_sn) + { + $this->parameters['order_sn'] = $order_sn; + return $this; + } +} diff --git a/src/Nodes/Chat/Parameters/ReadConversation.php b/src/Nodes/Chat/Parameters/ReadConversation.php new file mode 100644 index 0000000..2961ea4 --- /dev/null +++ b/src/Nodes/Chat/Parameters/ReadConversation.php @@ -0,0 +1,40 @@ +parameters['conversation_id']; + } + + /** + * @param int $conversation_id + * @return $this + */ + public function setConversationId($conversation_id) + { + $this->parameters['conversation_id'] = $conversation_id; + + return $this; + } + + public function getLastReadMessageId(): string + { + return $this->parameters['last_read_message_id']; + } + + /** + * @param string $last_read_message_id + * @return $this + */ + public function setLastReadMessageId(string $last_read_message_id) + { + $this->parameters['last_read_message_id'] = $last_read_message_id; + + return $this; + } +} diff --git a/src/Nodes/Discount/Discount.php b/src/Nodes/Discount/Discount.php index 643bd8f..7d6dd91 100644 --- a/src/Nodes/Discount/Discount.php +++ b/src/Nodes/Discount/Discount.php @@ -2,11 +2,12 @@ namespace Shopee\Nodes\Discount; -use Shopee\Nodes\NodeAbstract; +use Shopee\ClientV2; +use Shopee\Nodes\NodeAbstractV2; use Shopee\RequestParametersInterface; use Shopee\ResponseData; -class Discount extends NodeAbstract +class Discount extends NodeAbstractV2 { /** * Use this api to add shop discount activity. @@ -16,7 +17,7 @@ class Discount extends NodeAbstract */ public function addDiscount($parameters = []): ResponseData { - return $this->post('/api/v1/discount/add', $parameters); + return $this->post('/api/v2/discount/add_discount', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -27,7 +28,7 @@ public function addDiscount($parameters = []): ResponseData */ public function addDiscountItem($parameters = []): ResponseData { - return $this->post('/api/v1/discount/items/add', $parameters); + return $this->post('/api/v2/discount/add_discount_item', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -38,7 +39,7 @@ public function addDiscountItem($parameters = []): ResponseData */ public function deleteDiscount($parameters = []): ResponseData { - return $this->post('/api/v1/discount/delete', $parameters); + return $this->post('/api/v2/discount/delete_discount', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -49,7 +50,7 @@ public function deleteDiscount($parameters = []): ResponseData */ public function deleteDiscountItem($parameters = []): ResponseData { - return $this->post('/api/v1/discount/item/delete', $parameters); + return $this->post('/api/v2/discount/delete_discount_item', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -60,7 +61,7 @@ public function deleteDiscountItem($parameters = []): ResponseData */ public function getDiscountDetail($parameters = []): ResponseData { - return $this->post('/api/v1/discount/detail', $parameters); + return $this->get('/api/v2/discount/get_discount', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -71,7 +72,7 @@ public function getDiscountDetail($parameters = []): ResponseData */ public function getDiscountsList($parameters = []): ResponseData { - return $this->post('/api/v1/discounts/get', $parameters); + return $this->get('/api/v2/discount/get_discount_list', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -82,7 +83,7 @@ public function getDiscountsList($parameters = []): ResponseData */ public function updateDiscount($parameters = []): ResponseData { - return $this->post('/api/v1/discount/update', $parameters); + return $this->post('/api/v2/discount/update_discount', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -93,6 +94,10 @@ public function updateDiscount($parameters = []): ResponseData */ public function updateDiscountItems($parameters = []): ResponseData { - return $this->post('/api/v1/discount/items/update', $parameters); + return $this->post('/api/v2/discount/update_discount_item', ClientV2::API_TYPE_SHOP, $parameters); + } + public function endDiscount($parameters = []): ResponseData + { + return $this->post('/api/v2/discount/end_discount', ClientV2::API_TYPE_SHOP, $parameters); } } diff --git a/src/Nodes/Discount/Parameters/AddDiscount.php b/src/Nodes/Discount/Parameters/AddDiscount.php new file mode 100755 index 0000000..1f1aa81 --- /dev/null +++ b/src/Nodes/Discount/Parameters/AddDiscount.php @@ -0,0 +1,59 @@ +parameters['discount_name']; + } + + /** + * Name of the discount. + * + * @param string $name + * @return $this + */ + public function setName(string $name) + { + $this->parameters['discount_name'] = $name; + + return $this; + } + + public function getStartTime(): int + { + return $this->parameters['start_time']; + } + + /** + * @param int $start_time + * @return $this + */ + public function setStartTime(int $start_time) + { + $this->parameters['start_time'] = $start_time; + + return $this; + } + + public function getEndTime(): int + { + return $this->parameters['end_time']; + } + + /** + * @param int $end_time + * @return $this + */ + public function setEndTime(int $end_time) + { + $this->parameters['end_time'] = $end_time; + + return $this; + } +} diff --git a/src/Nodes/Discount/Parameters/AddDiscountItems.php b/src/Nodes/Discount/Parameters/AddDiscountItems.php new file mode 100755 index 0000000..9bb6b8c --- /dev/null +++ b/src/Nodes/Discount/Parameters/AddDiscountItems.php @@ -0,0 +1,28 @@ +parameters['item_list']; + } + + /** + * Name of the discount. + * + * @param DiscountItemList $discountItemList + * @return $this + */ + public function setItemList(DiscountItemList $discountItemList) + { + $this->parameters['item_list'] = $discountItemList; + + return $this; + } + +} diff --git a/src/Nodes/Discount/Parameters/DeleteDiscountItems.php b/src/Nodes/Discount/Parameters/DeleteDiscountItems.php new file mode 100755 index 0000000..14bf6f7 --- /dev/null +++ b/src/Nodes/Discount/Parameters/DeleteDiscountItems.php @@ -0,0 +1,15 @@ +parameters['item_promotion_price']; + } + + /** + * Name of the discount. + * + * @param float $item_promotion_price + * @return $this + */ + public function setPromotionPrice(float $item_promotion_price) + { + $this->parameters['item_promotion_price'] = $item_promotion_price; + + return $this; + } + + public function getPurchaseLimit(): int + { + return $this->parameters['purchase_limit']; + } + + /** + * @param int $purchase_limit + * @return $this + */ + public function setPurchaseLimit(int $purchase_limit) + { + $this->parameters['purchase_limit'] = $purchase_limit; + return $this; + } + + public function getPromotionStock(): int + { + return $this->parameters['item_promotion_stock']; + } + + /** + * @param int $item_promotion_stock + * @return $this + */ + public function setPromotionStock(int $item_promotion_stock) + { + $this->parameters['item_promotion_stock'] = $item_promotion_stock; + + return $this; + } + + public function getModelList(): ItemModelList + { + return $this->parameters['model_list']; + } + + /** + * @param ItemModelList $item_model_list + * @return $this + */ + public function setModelList(ItemModelList $item_model_list) + { + $this->parameters['model_list'] = $item_model_list; + + return $this; + } +} diff --git a/src/Nodes/Discount/Parameters/DiscountItemList.php b/src/Nodes/Discount/Parameters/DiscountItemList.php new file mode 100755 index 0000000..b92addb --- /dev/null +++ b/src/Nodes/Discount/Parameters/DiscountItemList.php @@ -0,0 +1,34 @@ +add(new DiscountItem($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/Discount/Parameters/DiscountTrait.php b/src/Nodes/Discount/Parameters/DiscountTrait.php new file mode 100644 index 0000000..e5b504f --- /dev/null +++ b/src/Nodes/Discount/Parameters/DiscountTrait.php @@ -0,0 +1,23 @@ +parameters['discount_id']; + } + + /** + * @param int $discount_id + * @return $this + */ + public function setDiscountId(int $discount_id) + { + $this->parameters['discount_id'] = $discount_id; + + return $this; + } +} diff --git a/src/Nodes/Discount/Parameters/ItemModel.php b/src/Nodes/Discount/Parameters/ItemModel.php new file mode 100755 index 0000000..3ba0756 --- /dev/null +++ b/src/Nodes/Discount/Parameters/ItemModel.php @@ -0,0 +1,45 @@ +parameters['model_promotion_price']; + } + + /** + * Name of the discount. + * + * @param float $model_promotion_price + * @return $this + */ + public function setModelPromotionPrice(float $model_promotion_price) + { + $this->parameters['model_promotion_price'] = $model_promotion_price; + + return $this; + } + + public function getModelPromotionStock(): int + { + return $this->parameters['model_promotion_stock']; + } + + /** + * @param int $model_promotion_stock + * @return $this + */ + public function setModelPromotionStock(int $model_promotion_stock) + { + $this->parameters['model_promotion_stock'] = $model_promotion_stock; + + return $this; + } + +} diff --git a/src/Nodes/Discount/Parameters/ItemModelList.php b/src/Nodes/Discount/Parameters/ItemModelList.php new file mode 100755 index 0000000..110e9b1 --- /dev/null +++ b/src/Nodes/Discount/Parameters/ItemModelList.php @@ -0,0 +1,34 @@ +add(new ItemModel($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/Discount/Parameters/UpdateDiscount.php b/src/Nodes/Discount/Parameters/UpdateDiscount.php new file mode 100755 index 0000000..c4568e5 --- /dev/null +++ b/src/Nodes/Discount/Parameters/UpdateDiscount.php @@ -0,0 +1,59 @@ +parameters['discount_name']; + } + + /** + * Name of the discount. + * + * @param string $name + * @return $this + */ + public function setName(string $name) + { + $this->parameters['discount_name'] = $name; + + return $this; + } + + public function getStartTime(): int + { + return $this->parameters['start_time']; + } + + /** + * @param int $start_time + * @return $this + */ + public function setStartTime(int $start_time) + { + $this->parameters['start_time'] = $start_time; + + return $this; + } + + public function getEndTime(): int + { + return $this->parameters['end_time']; + } + + /** + * @param int $end_time + * @return $this + */ + public function setEndTime(int $end_time) + { + $this->parameters['end_time'] = $end_time; + + return $this; + } +} diff --git a/src/Nodes/FlashSale/FlashSale.php b/src/Nodes/FlashSale/FlashSale.php new file mode 100644 index 0000000..32ef5a2 --- /dev/null +++ b/src/Nodes/FlashSale/FlashSale.php @@ -0,0 +1,110 @@ +post('/api/v2/shop_flash_sale/create_shop_flash_sale', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to add shop flash_sale item. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function addFlashSaleItem($parameters = []): ResponseData + { + return $this->post('/api/v2/shop_flash_sale/add_shop_flash_sale_items', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to delete one flash_sale activity BEFORE it starts. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function deleteFlashSale($parameters = []): ResponseData + { + return $this->post('/api/v2/shop_flash_sale/delete_shop_flash_sale', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to delete items of the flash_sale activity. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function deleteFlashSaleItem($parameters = []): ResponseData + { + return $this->post('/api/v2/shop_flash_sale/delete_shop_flash_sale_items', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to get one shop flash_sale activity detail. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function getFlashSale($parameters = []): ResponseData + { + return $this->get('/api/v2/shop_flash_sale/get_shop_flash_sale', ClientV2::API_TYPE_SHOP, $parameters); + } + + public function getFlashSaleItems($parameters = []): ResponseData + { + return $this->get('/api/v2/shop_flash_sale/get_shop_flash_sale_items', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to get shop flash_sale activity list. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function getFlashSalesList($parameters = []): ResponseData + { + return $this->get('/api/v2/shop_flash_sale/get_shop_flash_sale_list', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to update one flash_sale information + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function updateFlashSale($parameters = []): ResponseData + { + return $this->post('/api/v2/shop_flash_sale/update_shop_flash_sale', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to update items of the flash_sale activity. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function updateFlashSaleItems($parameters = []): ResponseData + { + return $this->post('/api/v2/shop_flash_sale/update_shop_flash_sale_items', ClientV2::API_TYPE_SHOP, $parameters); + } + + + public function getTimeSlotId($parameters = []): ResponseData + { + return $this->get('/api/v2/shop_flash_sale/get_time_slot_id', ClientV2::API_TYPE_SHOP, $parameters); + } +} diff --git a/src/Nodes/FlashSale/Parameters/AddFlashSaleItems.php b/src/Nodes/FlashSale/Parameters/AddFlashSaleItems.php new file mode 100755 index 0000000..377dbcb --- /dev/null +++ b/src/Nodes/FlashSale/Parameters/AddFlashSaleItems.php @@ -0,0 +1,28 @@ +parameters['items']; + } + + /** + * Name of the FlashSale. + * + * @param FlashSaleItemList $FlashSaleItemList + * @return $this + */ + public function setItemList(FlashSaleItemList $FlashSaleItemList) + { + $this->parameters['items'] = $FlashSaleItemList; + + return $this; + } + +} diff --git a/src/Nodes/FlashSale/Parameters/DeleteFlashSaleItems.php b/src/Nodes/FlashSale/Parameters/DeleteFlashSaleItems.php new file mode 100755 index 0000000..8dadeda --- /dev/null +++ b/src/Nodes/FlashSale/Parameters/DeleteFlashSaleItems.php @@ -0,0 +1,28 @@ +parameters['item_ids'] = $item_ids; + return $this; + } + + public function getItemIds(): int + { + return $this->parameters['item_ids']; + } +} diff --git a/src/Nodes/FlashSale/Parameters/FlashSaleItem.php b/src/Nodes/FlashSale/Parameters/FlashSaleItem.php new file mode 100755 index 0000000..269e890 --- /dev/null +++ b/src/Nodes/FlashSale/Parameters/FlashSaleItem.php @@ -0,0 +1,57 @@ +parameters['purchase_limit']; + } + + /** + * @param int $purchase_limit + * @return $this + */ + public function setPurchaseLimit(int $purchase_limit) + { + $this->parameters['purchase_limit'] = $purchase_limit; + return $this; + } + + public function getItemId(): int + { + return $this->parameters['item_id']; + } + + /** + * @param int $item_id + * @return $this + */ + public function setItemId(int $item_id) + { + $this->parameters['item_id'] = $item_id; + return $this; + } + + public function getModelList(): ItemModelList + { + return $this->parameters['models']; + } + + /** + * @param ItemModelList $item_model_list + * @return $this + */ + public function setModelList(ItemModelList $item_model_list) + { + $this->parameters['models'] = $item_model_list; + + return $this; + } +} diff --git a/src/Nodes/FlashSale/Parameters/FlashSaleItemList.php b/src/Nodes/FlashSale/Parameters/FlashSaleItemList.php new file mode 100755 index 0000000..4275a13 --- /dev/null +++ b/src/Nodes/FlashSale/Parameters/FlashSaleItemList.php @@ -0,0 +1,34 @@ +add(new FlashSaleItem($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/FlashSale/Parameters/FlashSaleTrait.php b/src/Nodes/FlashSale/Parameters/FlashSaleTrait.php new file mode 100644 index 0000000..8fcbe27 --- /dev/null +++ b/src/Nodes/FlashSale/Parameters/FlashSaleTrait.php @@ -0,0 +1,23 @@ +parameters['flash_sale_id']; + } + + /** + * @param int $flase_sale_id + * @return $this + */ + public function setFlashSaleId(int $flase_sale_id) + { + $this->parameters['flash_sale_id'] = $flase_sale_id; + + return $this; + } +} diff --git a/src/Nodes/FlashSale/Parameters/ItemModel.php b/src/Nodes/FlashSale/Parameters/ItemModel.php new file mode 100755 index 0000000..e579abe --- /dev/null +++ b/src/Nodes/FlashSale/Parameters/ItemModel.php @@ -0,0 +1,79 @@ +parameters['input_promo_price']; + } + + /** + * Name of the discount. + * + * @param float $input_promo_price + * @return $this + */ + public function setInputPromoPrice(float $input_promo_price) + { + $this->parameters['input_promo_price'] = $input_promo_price; + + return $this; + } + + public function getStatus(): int + { + return $this->parameters['status']; + } + + /** + * @param int $status + * @return $this + */ + public function setStatus(int $status) + { + $this->parameters['status'] = $status; + + return $this; + } + + public function getModelId() + { + return $this->parameters['model_id']; + } + + /** + * @param $model_id + * @return $this + */ + public function setModelId($model_id) + { + $this->parameters['model_id'] = $model_id; + + return $this; + } + + public function getStock(): int + { + return $this->parameters['stock']; + } + + /** + * @param int $stock + * @return $this + */ + public function setStock(int $stock) + { + $this->parameters['stock'] = $stock; + + return $this; + } + + + +} diff --git a/src/Nodes/FlashSale/Parameters/ItemModelList.php b/src/Nodes/FlashSale/Parameters/ItemModelList.php new file mode 100755 index 0000000..93e4760 --- /dev/null +++ b/src/Nodes/FlashSale/Parameters/ItemModelList.php @@ -0,0 +1,35 @@ +add(new ItemModel($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/FlashSale/Parameters/UpdateFlashSale.php b/src/Nodes/FlashSale/Parameters/UpdateFlashSale.php new file mode 100755 index 0000000..2484870 --- /dev/null +++ b/src/Nodes/FlashSale/Parameters/UpdateFlashSale.php @@ -0,0 +1,59 @@ +parameters['discount_name']; + } + + /** + * Name of the discount. + * + * @param string $name + * @return $this + */ + public function setName(string $name) + { + $this->parameters['discount_name'] = $name; + + return $this; + } + + public function getStartTime(): int + { + return $this->parameters['start_time']; + } + + /** + * @param int $start_time + * @return $this + */ + public function setStartTime(int $start_time) + { + $this->parameters['start_time'] = $start_time; + + return $this; + } + + public function getEndTime(): int + { + return $this->parameters['end_time']; + } + + /** + * @param int $end_time + * @return $this + */ + public function setEndTime(int $end_time) + { + $this->parameters['end_time'] = $end_time; + + return $this; + } +} diff --git a/src/Nodes/Image/Image.php b/src/Nodes/Image/Image.php index 810b628..4bee242 100644 --- a/src/Nodes/Image/Image.php +++ b/src/Nodes/Image/Image.php @@ -2,10 +2,12 @@ namespace Shopee\Nodes\Image; +use Shopee\ClientV2; use Shopee\Nodes\NodeAbstract; +use Shopee\Nodes\NodeAbstractV2; use Shopee\ResponseData; -class Image extends NodeAbstract +class Image extends NodeAbstractV2 { /** * Use this optional API to pre-validate your image urls and convert them to Shopee image url to use in item @@ -14,8 +16,8 @@ class Image extends NodeAbstract * @param array $parameters * @return ResponseData */ - public function uploadImage($parameters = []): ResponseData + public function uploadImage($image_url, $params = []): ResponseData { - return $this->post('/api/v1/image/upload', $parameters); + return $this->uploadWithBody('/api/v2/media_space/upload_image', ClientV2::API_TYPE_PUBLIC, $image_url,$params); } } diff --git a/src/Nodes/Item/Attribute.php b/src/Nodes/Item/Attribute.php new file mode 100755 index 0000000..bc7c835 --- /dev/null +++ b/src/Nodes/Item/Attribute.php @@ -0,0 +1,30 @@ +get("/api/v2/product/get_attributes", ClientV2::API_TYPE_SHOP, $parameters); + } + + public function getVariantAttributes($parameters = []): ResponseData { + return $this->get("/api/v2/product/get_variation_tree", ClientV2::API_TYPE_SHOP, $parameters); + } + + public function getTreeAttributes($parameters = []): ResponseData { + return $this->get("/api/v2/product/get_attribute_tree", ClientV2::API_TYPE_SHOP, $parameters); + } +} diff --git a/src/Nodes/Item/Brand.php b/src/Nodes/Item/Brand.php new file mode 100755 index 0000000..d7dd337 --- /dev/null +++ b/src/Nodes/Item/Brand.php @@ -0,0 +1,24 @@ +get("/api/v2/product/get_brand_list", ClientV2::API_TYPE_SHOP, $parameters); + } + +} diff --git a/src/Nodes/Item/Category.php b/src/Nodes/Item/Category.php new file mode 100755 index 0000000..60fe7ac --- /dev/null +++ b/src/Nodes/Item/Category.php @@ -0,0 +1,45 @@ +get("/api/v2/product/get_category", ClientV2::API_TYPE_SHOP, $parameters); + } + /** + * Use this call to get information of shop. + * https://open.shopee.com/documents?module=89&type=1&id=702&version=2 + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function getCategoryRecommend($parameters = []): ResponseData { + return $this->get("/api/v2/product/category_recommend", ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this call to get information of shop. + * https://open.shopee.com/documents/v2/v2.product.support_size_chart?module=89&type=1 + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function checkSupportChart($parameters = []): ResponseData { + return $this->get("/api/v2/product/support_size_chart", ClientV2::API_TYPE_SHOP, $parameters); + } + + public function getItemLimit($parameters = []): ResponseData { + return $this->get("/api/v2/product/get_item_limit", ClientV2::API_TYPE_SHOP, $parameters); + } +} diff --git a/src/Nodes/Item/Item.php b/src/Nodes/Item/Item.php index ed5107b..6a416c3 100644 --- a/src/Nodes/Item/Item.php +++ b/src/Nodes/Item/Item.php @@ -2,10 +2,12 @@ namespace Shopee\Nodes\Item; +use Shopee\ClientV2; use Shopee\Nodes\NodeAbstract; +use Shopee\Nodes\NodeAbstractV2; use Shopee\ResponseData; -class Item extends NodeAbstract +class Item extends NodeAbstractV2 { /** * Use this call to add a product item. @@ -15,325 +17,275 @@ class Item extends NodeAbstract */ public function add($parameters = []): ResponseData { - return $this->post('/api/v1/item/add', $parameters); + return $this->post('/api/v2/product/add_item', ClientV2::API_TYPE_SHOP, $parameters); } - /** - * Use this call to add product item images. - * - * @param array|Parameters\AddItemImg $parameters - * @return ResponseData - */ - public function addItemImg($parameters = []): ResponseData - { - return $this->post('/api/v1/item/img/add', $parameters); - } /** * Use this call to add item variations. - * + * https://open.shopee.com/documents?module=89&type=1&id=618&version=2 * @param array|Parameters\AddVariations $parameters * @return ResponseData */ - public function addVariations($parameters = []): ResponseData + public function getModelList($parameters = []): ResponseData { - return $this->post('/api/v1/item/add_variations', $parameters); + return $this->get('/api/v2/product/get_model_list', ClientV2::API_TYPE_SHOP, $parameters); } /** * Use this api to boost multiple items at once. - * + * https://open.shopee.com/documents?module=89&type=1&id=624&version=2 * @param array $parameters * @return ResponseData */ public function boostItem($parameters = []): ResponseData { - return $this->post('/api/v1/items/boost', $parameters); + return $this->post('/api/v2/product/boost_item', ClientV2::API_TYPE_SHOP, $parameters); } /** * Use this call to delete a product item. - * + * https://open.shopee.com/documents?module=89&type=1&id=615&version=2 * @param array|Parameters\Delete $parameters * @return ResponseData */ public function delete($parameters = []): ResponseData { - return $this->post('/api/v1/item/delete', $parameters); - } - - /** - * Use this call to delete a product item image. - * - * @param array|Parameters\DeleteItemImg $parameters - * @return ResponseData - */ - public function deleteItemImg($parameters = []): ResponseData - { - return $this->post('/api/v1/item/img/delete', $parameters); + return $this->post('/api/v2/product/delete_item', ClientV2::API_TYPE_SHOP, $parameters); } /** * Use this call to delete item variation. - * + * https://open.shopee.com/documents?module=89&type=1&id=650&version=2 * @param array|Parameters\DeleteVariation $parameters * @return ResponseData */ - public function deleteVariation($parameters = []): ResponseData + public function deleteModel($parameters = []): ResponseData { - return $this->post('/api/v1/item/delete_variation', $parameters); + return $this->post('/api/v2/product/delete_model', ClientV2::API_TYPE_SHOP, $parameters); } /** * Use this call to get attributes of product item. - * + * https://open.shopee.com/documents?module=89&type=1&id=655&version=2 * @param array|Parameters\GetAttributes $parameters * @return ResponseData */ public function getAttributes($parameters = []): ResponseData { - return $this->post('/api/v1/item/attributes/get', $parameters); + return $this->get('/api/v2/product/get_attributes', ClientV2::API_TYPE_SHOP, $parameters); } /** * Use this api to get all boosted items. - * + * https://open.shopee.com/documents?module=89&type=1&id=626&version=2 * @param array $parameters * @return ResponseData */ public function getBoostedItems($parameters = []): ResponseData { - return $this->post('/api/v1/items/get_boosted', $parameters); + return $this->get('/api/v2/product/get_boosted_list', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this call to get categories of product item. - * + * Use this api to get comment by + * https://open.shopee.com/documents?module=89&type=1&id=562&version=2 * @param array $parameters * @return ResponseData */ - public function getCategories($parameters = []): ResponseData + public function getComment($parameters = []): ResponseData { - return $this->post('/api/v1/item/categories/get', $parameters); + return $this->get('/api/v2/product/get_comment', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this api to get comment by shopid/itemid/comment_id - * - * @param array $parameters + * Use this call to get detail of item. + * https://open.shopee.com/documents?module=89&type=1&id=612&version=2 + * @param array|Parameters\GetItemDetail $parameters * @return ResponseData */ - public function getComment($parameters = []): ResponseData + public function getItemBaseInfo($parameters = []): ResponseData { - return $this->post('/api/v1/items/comments/get', $parameters); + return $this->get('/api/v2/product/get_item_base_info', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this call to get detail of item. - * + * https://open.shopee.com/documents?module=89&type=1&id=613&version=2 * @param array|Parameters\GetItemDetail $parameters * @return ResponseData */ - public function getItemDetail($parameters = []): ResponseData + public function getItemExtraInfo($parameters = []): ResponseData { - return $this->post('/api/v1/item/get', $parameters); + return $this->get('/api/v2/product/get_item_extra_info', ClientV2::API_TYPE_SHOP, $parameters); } /** * Use this call to get a list of items. - * + * https://open.shopee.com/documents?module=89&type=1&id=614&version=2 * @param array|Parameters\GetItemsList $parameters * @return ResponseData */ public function getItemsList($parameters = []): ResponseData { - return $this->post('/api/v1/items/get', $parameters); + return $this->get('/api/v2/product/get_item_list', ClientV2::API_TYPE_SHOP, $parameters); } /** * Use this api to get ongoing and upcoming promotions. - * + * https://open.shopee.com/documents?module=89&type=1&id=661&version=2 * @param array $parameters * @return ResponseData */ public function getPromotionInfo($parameters = []): ResponseData { - return $this->post('/api/v1/item/promotion/get', $parameters); + return $this->get('/api/v2/product/get_item_promotion', ClientV2::API_TYPE_SHOP, $parameters); } /** * Use this API to get recommended category ids according to item name. - * + * https://open.shopee.com/documents?module=89&type=1&id=702&version=2 * @param array $parameters * @return ResponseData */ public function getRecommendCats($parameters = []): ResponseData { - return $this->post('/api/v1/item/categories/get_recommend', $parameters); + return $this->get('/api/v2/product/category_recommend', ClientV2::API_TYPE_SHOP, $parameters); } - /** - * Use this call to add one item image in assigned position. - * - * @param array|Parameters\InsertItemImg $parameters - * @return ResponseData - */ - public function insertItemImg($parameters = []): ResponseData - { - return $this->post('/api/v1/item/img/insert', $parameters); - } /** * Use this api to reply comments from buyers in batch. - * + * https://open.shopee.com/documents?module=89&type=1&id=563&version=2 * @param array $parameters * @return ResponseData */ public function replyComments($parameters = []): ResponseData { - return $this->post('/api/v1/items/comments/reply', $parameters); + return $this->post('/api/v2/product/reply_comment', ClientV2::API_TYPE_SHOP, $parameters); } - /** - * Only for TW whitelisted shop. Use this API to set the installment tenures of items. - * - * @param array $parameters - * @return ResponseData - */ - public function setItemInstallmentTenures($parameters = []): ResponseData - { - return $this->post('/api/v1/item/installment/set', $parameters); - } /** * Use this call to update a product item. - * + * https://open.shopee.com/documents?module=89&type=1&id=617&version=2 * @param array|Parameters\UpdateItem $parameters * @return ResponseData */ public function updateItem($parameters = []): ResponseData { - return $this->post('/api/v1/item/update', $parameters); + return $this->post('/api/v2/product/update_item', ClientV2::API_TYPE_SHOP, $parameters); } - /** - * Override and update all the existing images of an item. - * - * @param array|Parameters\UpdateItemImg $parameters - * @return ResponseData - */ - public function updateItemImage($parameters = []): ResponseData - { - return $this->post('/api/v1/item/img/update', $parameters); - } /** * Use this call to update item price. - * - * @param array|Parameters\UpdatePrice $parameters + * https://open.shopee.com/documents?module=89&type=1&id=651&version=2 + * @param array|Parameters\UpdateVariationPriceList $parameters * @return ResponseData */ public function updatePrice($parameters = []): ResponseData { - return $this->post('/api/v1/items/update_price', $parameters); + return $this->post('/api/v2/product/update_price', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Update items price in batch. - * - * @param array $parameters + * Use this call to update item stock. + * https://open.shopee.com/documents?module=89&type=1&id=652&version=2 + * @param array|Parameters\UpdateVariationStockList $parameters * @return ResponseData */ - public function updatePriceBatch($parameters = []): ResponseData + public function updateStock($parameters = []): ResponseData { - return $this->post('/api/v1/items/update/items_price', $parameters); + return $this->post('/api/v2/product/update_stock', ClientV2::API_TYPE_SHOP, $parameters); } + /** - * Use this call to update item stock. - * - * @param array|Parameters\UpdateStock $parameters + * Use this call to update Sip Item price. + * https://open.shopee.com/documents?module=89&type=1&id=662&version=2 + * @param array|Parameters\UpdateVariationPrice $parameters * @return ResponseData */ - public function updateStock($parameters = []): ResponseData + public function updateSipItemPrice($parameters = []): ResponseData { - return $this->post('/api/v1/items/update_stock', $parameters); + return $this->post('/api/v2/product/update_sip_item_price', ClientV2::API_TYPE_SHOP, $parameters); } + /** - * Update items stock in batch. - * - * @param array $parameters + * Use this call to unlist or list items in batch. + * https://open.shopee.com/documents?module=89&type=1&id=622&version=2 + * @param array|Parameters\UpdateVariationStock $parameters * @return ResponseData */ - public function updateStockBatch($parameters = []): ResponseData + public function unlistItem($parameters = []): ResponseData { - return $this->post('/api/v1/items/update/items_stock', $parameters); + return $this->post('/api/v2/product/unlist_item', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this call to update item variation price. + * For adding 2-tier variations (Forked). * - * @param array|Parameters\UpdateVariationPrice $parameters + * @param array|Parameters\InitTierVariation $parameters * @return ResponseData */ - public function updateVariationPrice($parameters = []): ResponseData + public function initTierVariation($parameters = []): ResponseData { - return $this->post('/api/v1/items/update_variation_price', $parameters); + return $this->post('/api/v2/product/init_tier_variation', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Update variations price in batch. + * For adding 2-tier variations (Forked). * - * @param array $parameters + * @param array|Parameters\UpdateTierVariation $parameters * @return ResponseData */ - public function updateVariationPriceBatch($parameters = []): ResponseData + public function updateTierVariation($parameters = []): ResponseData { - return $this->post('/api/v1/items/update/vars_price', $parameters); + return $this->post('/api/v2/product/update_tier_variation', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this call to update item variation stock. + * For adding 2-tier variations (Forked). * - * @param array|Parameters\UpdateVariationStock $parameters + * @param array|Parameters\UpdateVariationModel $parameters * @return ResponseData */ - public function updateVariationStock($parameters = []): ResponseData + public function updateModel($parameters = []): ResponseData { - return $this->post('/api/v1/items/update_variation_stock', $parameters); + return $this->post('/api/v2/product/update_model', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Update variations stock in batch. + * For adding 2-tier variations (Forked). * - * @param array $parameters + * @param array|Parameters\AddVariations $parameters * @return ResponseData */ - public function updateVariationStockBatch($parameters = []): ResponseData + public function addModel($parameters = []): ResponseData { - return $this->post('/api/v1/items/update/vars_stock', $parameters); + return $this->post('/api/v2/product/add_model', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this call to unlist or list items in batch. + * For adding 2-tier variations (Forked). * - * @param array|Parameters\UpdateVariationStock $parameters + * @param array|Parameters\RemoveVariation $parameters * @return ResponseData */ - public function unlistItem($parameters = []): ResponseData + public function removeModel($parameters = []): ResponseData { - return $this->post('/api/v1/items/unlist', $parameters); + return $this->post('/api/v2/product/delete_model', ClientV2::API_TYPE_SHOP, $parameters); } /** - * For adding 2-tier variations (Forked). - * - * @param array|Parameters\InitTierVariation $parameters + * Update size chart image of item. + * https://open.shopee.com/documents/v2/v2.product.update_size_chart?module=89&type=1 + * @param array|Parameters\UpdateSizeChart $parameters * @return ResponseData */ - public function initTierVariation($parameters = []): ResponseData + public function updateSizeChart($parameters = []): ResponseData { - return $this->post('api/v1/item/tier_var/init', $parameters); + return $this->post('/api/v2/product/update_size_chart', ClientV2::API_TYPE_SHOP, $parameters); } } diff --git a/src/Nodes/Item/Parameters/Add.php b/src/Nodes/Item/Parameters/Add.php index b9d943e..eea8f42 100644 --- a/src/Nodes/Item/Parameters/Add.php +++ b/src/Nodes/Item/Parameters/Add.php @@ -10,7 +10,7 @@ class Add extends RequestParameters public function getName(): string { - return $this->parameters['name']; + return $this->parameters['item_name']; } /** @@ -21,7 +21,7 @@ public function getName(): string */ public function setName(string $name) { - $this->parameters['name'] = $name; + $this->parameters['item_name'] = $name; return $this; } @@ -46,7 +46,7 @@ public function setDescription(string $description) public function getPrice(): float { - return $this->parameters['price']; + return $this->parameters['original_price']; } /** @@ -57,69 +57,85 @@ public function getPrice(): float */ public function setPrice(float $price) { - $this->parameters['price'] = $price; + $this->parameters['original_price'] = $price; return $this; } - public function getStock(): int + public function getStock(): SellerStocks { - return $this->parameters['stock']; + return $this->parameters['seller_stock']; } /** * The current stock quantity of the item. * - * @param int $stock + * @param SellerStocks $stock * @return $this */ - public function setStock(int $stock) + public function setStock(SellerStocks $stock) { - $this->parameters['stock'] = $stock; + $this->parameters['seller_stock'] = $stock; return $this; } - public function getItemSku(): ?string + public function getStatus(): string { - return $this->parameters['item_sku']; + return $this->parameters['item_status']; } /** - * An item SKU (stock keeping unit) is an identifier defined by a seller, sometimes called parent SKU. - * Item SKU can be assigned to an item in Shopee Listings. - * @param string $itemSku + * The current stock quantity of the item. + * + * @param string $status * @return $this */ - public function setItemSku(string $itemSku) + public function setStatus(string $status) { - $this->parameters['item_sku'] = $itemSku; + $this->parameters['item_status'] = $status; return $this; } - public function getVariations(): ?Variations + public function getDimension(): Dimension { - return $this->parameters['variations']; + return $this->parameters['dimension']; } /** - * The variation of item is to list out all models of this product, for example, - * iPhone has model of White and Black, then its variations includes "White iPhone" and "Black iPhone". - * - * @param Variations $variations + * @param Dimension $dimension + * @return $this + */ + public function setDimension(Dimension $dimension) + { + $this->parameters['dimension'] = $dimension; + + return $this; + } + + + public function getItemSku(): ?string + { + return $this->parameters['item_sku']; + } + + /** + * An item SKU (stock keeping unit) is an identifier defined by a seller, sometimes called parent SKU. + * Item SKU can be assigned to an item in Shopee Listings. + * @param string $itemSku * @return $this */ - public function setVariations(Variations $variations) + public function setItemSku(string $itemSku) { - $this->parameters['variations'] = $variations; + $this->parameters['item_sku'] = $itemSku; return $this; } public function getImages(): Images { - return $this->parameters['images']; + return $this->parameters['image']; } /** @@ -131,14 +147,14 @@ public function getImages(): Images */ public function setImages(Images $images) { - $this->parameters['images'] = $images; + $this->parameters['image'] = $images; return $this; } public function getAttributes(): ?Attributes { - return $this->parameters['attributes']; + return $this->parameters['attribute_list']; } /** @@ -149,14 +165,14 @@ public function getAttributes(): ?Attributes */ public function setAttributes(Attributes $attributes) { - $this->parameters['attributes'] = $attributes; + $this->parameters['attribute_list'] = $attributes; return $this; } public function getLogistics(): ?Logistics { - return $this->parameters['logistics']; + return $this->parameters['logistic_info']; } /** @@ -167,7 +183,7 @@ public function getLogistics(): ?Logistics */ public function setLogistics(Logistics $logistics) { - $this->parameters['logistics'] = $logistics; + $this->parameters['logistic_info'] = $logistics; return $this; } @@ -190,92 +206,92 @@ public function setWeight(float $weight) return $this; } - public function getPackageLength(): ?int + public function getPreOrder(): ?PreOrder { - return $this->parameters['package_length']; + return $this->parameters['days_to_ship']; } /** - * The height of package for this single item, the unit is CM. + * The days to ship. Only work for pre-order, it means this value should be bigger than 7. * - * @param int $packageLength + * @param PreOrder $preOrder * @return $this */ - public function setPackageLength(int $packageLength) + public function setPreOrder(PreOrder $preOrder) { - $this->parameters['package_length'] = $packageLength; + $this->parameters['pre_order'] = $preOrder; return $this; } - public function getPackageWidth(): ?int + public function getWholesales(): ?Wholesales { - return $this->parameters['package_width']; + return $this->parameters['wholesales']; } /** - * The height of package for this single item, the unit is CM. + * The wholesales tier list. Please put the wholesale tier info in order by min count. * - * @param int $packageWidth + * @param Wholesales $wholesales * @return $this */ - public function setPackageWidth(int $packageWidth) + public function setWholesales(Wholesales $wholesales) { - $this->parameters['package_width'] = $packageWidth; + $this->parameters['wholesales'] = $wholesales; return $this; } - public function getPackageHeight(): ?int + public function getBrand(): ?Brand { - return $this->parameters['package_height']; + return $this->parameters['brand']; } /** - * The height of package for this single item, the unit is CM. - * @param int $packageHeight + * + * @param Brand $brand * @return $this */ - public function setPackageHeight(int $packageHeight) + public function setBrand(Brand $brand) { - $this->parameters['package_height'] = $packageHeight; + $this->parameters['brand'] = $brand; return $this; } - public function getDaysToShip(): ?int + public function geVideoUploadId(): string { - return $this->parameters['days_to_ship']; + return $this->parameters['video_upload_id']; } /** - * The days to ship. Only work for pre-order, it means this value should be bigger than 7. + * Name of the item in local language. * - * @param int $daysToShip + * @param string $name * @return $this */ - public function setDaysToShip(int $daysToShip) + public function setVideoUploadId(string $name) { - $this->parameters['days_to_ship'] = $daysToShip; + $this->parameters['video_upload_id'] = [$name]; return $this; } - - public function getWholesales(): ?Wholesales + public function getDescriptionType(): string { - return $this->parameters['wholesales']; + return $this->parameters['description_type']; } /** - * The wholesales tier list. Please put the wholesale tier info in order by min count. + * Name of the item in description_type * - * @param Wholesales $wholesales + * @param string $description_type * @return $this */ - public function setWholesales(Wholesales $wholesales) + public function setDescriptionType(string $description_type) { - $this->parameters['wholesales'] = $wholesales; + $this->parameters['description_type'] = $description_type; return $this; } + } diff --git a/src/Nodes/Item/Parameters/AddVariations.php b/src/Nodes/Item/Parameters/AddVariations.php index 8b9b42b..133a290 100644 --- a/src/Nodes/Item/Parameters/AddVariations.php +++ b/src/Nodes/Item/Parameters/AddVariations.php @@ -10,7 +10,7 @@ class AddVariations extends RequestParameters public function getVariations(): Variations { - return $this->parameters['variations']; + return $this->parameters['model_list']; } /** @@ -22,7 +22,7 @@ public function getVariations(): Variations */ public function setVariations(Variations $variations) { - $this->parameters['variations'] = $variations; + $this->parameters['model_list'] = $variations; return $this; } diff --git a/src/Nodes/Item/Parameters/Attribute.php b/src/Nodes/Item/Parameters/Attribute.php index d9b665d..719c6e6 100644 --- a/src/Nodes/Item/Parameters/Attribute.php +++ b/src/Nodes/Item/Parameters/Attribute.php @@ -8,7 +8,7 @@ class Attribute extends RequestParameters { public function getAttributeId(): int { - return $this->parameters['attributes_id']; + return $this->parameters['attribute_id']; } /** @@ -17,23 +17,23 @@ public function getAttributeId(): int */ public function setAttributeId(int $attributeId) { - $this->parameters['attributes_id'] = $attributeId; + $this->parameters['attribute_id'] = $attributeId; return $this; } - public function getValue(): string + public function getValueList(): AttributeValueList { - return $this->parameters['value']; + return $this->parameters['attribute_value_list']; } /** - * @param string $value + * @param AttributeValueList $valueList * @return $this */ - public function setValue(string $value) + public function setValueList(AttributeValueList $valueList) { - $this->parameters['value'] = $value; + $this->parameters['attribute_value_list'] = $valueList; return $this; } diff --git a/src/Nodes/Item/Parameters/AttributeValue.php b/src/Nodes/Item/Parameters/AttributeValue.php new file mode 100644 index 0000000..53d6b3f --- /dev/null +++ b/src/Nodes/Item/Parameters/AttributeValue.php @@ -0,0 +1,56 @@ +parameters['value_id']; + } + + /** + * @param int $value_id + * @return $this + */ + public function setValueId(int $value_id) + { + $this->parameters['value_id'] = $value_id; + + return $this; + } + + public function getOriginalValueName(): string + { + return $this->parameters['original_value_name']; + } + + /** + * @param string $original_value_name + * @return $this + */ + public function setOriginalValueName(string $original_value_name) + { + $this->parameters['original_value_name'] = $original_value_name; + + return $this; + } + + public function getValueUnit(): string + { + return $this->parameters['value_unit']; + } + + /** + * @param string $unit + * @return $this + */ + public function setValueUnit(string $unit) + { + $this->parameters['value_unit'] = $unit; + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/AttributeValueList.php b/src/Nodes/Item/Parameters/AttributeValueList.php new file mode 100644 index 0000000..49bb193 --- /dev/null +++ b/src/Nodes/Item/Parameters/AttributeValueList.php @@ -0,0 +1,33 @@ +add(new AttributeValue($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/Brand.php b/src/Nodes/Item/Parameters/Brand.php new file mode 100644 index 0000000..929e1d1 --- /dev/null +++ b/src/Nodes/Item/Parameters/Brand.php @@ -0,0 +1,40 @@ +parameters['brand_id']; + } + + /** + * @param int $brand_id + * @return $this + */ + public function setBrandId(int $brand_id) + { + $this->parameters['brand_id'] = $brand_id; + + return $this; + } + + public function getOriginalBrandName(): string + { + return $this->parameters['original_brand_name']; + } + + /** + * @param string $brand_name + * @return $this + */ + public function setOriginalBrandName(string $brand_name) + { + $this->parameters['original_brand_name'] = $brand_name; + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/Comment.php b/src/Nodes/Item/Parameters/Comment.php new file mode 100644 index 0000000..f089790 --- /dev/null +++ b/src/Nodes/Item/Parameters/Comment.php @@ -0,0 +1,42 @@ +parameters['comment_id']; + } + + /** + * @param int $commentId + * @return $this + */ + public function setCommentId(int $commentId) + { + $this->parameters['comment_id'] = $commentId; + + return $this; + } + + public function getComment(): string + { + return $this->parameters['comment']; + } + + /** + * @param string $comment + * @return $this + */ + public function setComment(string $comment) + { + $this->parameters['comment'] = $comment; + + return $this; + } + + +} diff --git a/src/Nodes/Item/Parameters/CommentList.php b/src/Nodes/Item/Parameters/CommentList.php new file mode 100644 index 0000000..e8d123b --- /dev/null +++ b/src/Nodes/Item/Parameters/CommentList.php @@ -0,0 +1,33 @@ +add(new Comment($parameter)); + } + + return $this; + } + +} diff --git a/src/Nodes/Item/Parameters/Dimension.php b/src/Nodes/Item/Parameters/Dimension.php new file mode 100644 index 0000000..cf13572 --- /dev/null +++ b/src/Nodes/Item/Parameters/Dimension.php @@ -0,0 +1,56 @@ +parameters['package_height']; + } + + /** + * @param int $height + * @return $this + */ + public function setPackageHeight(int $height) + { + $this->parameters['package_height'] = $height; + + return $this; + } + + public function getPackageLength(): int + { + return $this->parameters['package_length']; + } + + /** + * @param int $length + * @return $this + */ + public function setPackageLength(int $length) + { + $this->parameters['package_length'] = $length; + + return $this; + } + + public function getPackageWidth(): int + { + return $this->parameters['package_width']; + } + + /** + * @param int $width + * @return $this + */ + public function setPackageWidth(int $width) + { + $this->parameters['package_width'] = $width; + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/GetItemDetail.php b/src/Nodes/Item/Parameters/GetItemDetail.php index 2cc15ea..6079132 100644 --- a/src/Nodes/Item/Parameters/GetItemDetail.php +++ b/src/Nodes/Item/Parameters/GetItemDetail.php @@ -6,5 +6,21 @@ class GetItemDetail extends RequestParameters { - use ItemTrait; + public function getItemIdList(): int + { + return $this->parameters['item_id_list']; + } + + /** + * Set the Shopee's unique identifier for an item + * + * @param array $itemIdList + * @return $this + */ + public function setItemIdList($itemIdList) + { + $this->parameters['item_id_list'] = $itemIdList; + + return $this; + } } diff --git a/src/Nodes/Item/Parameters/GetItemsList.php b/src/Nodes/Item/Parameters/GetItemsList.php index 8a8ecc9..dfb16e7 100644 --- a/src/Nodes/Item/Parameters/GetItemsList.php +++ b/src/Nodes/Item/Parameters/GetItemsList.php @@ -6,14 +6,36 @@ class GetItemsList extends RequestParameters { + const NORMAL = "NORMAL"; + const BANNED = "BANNED"; + const DELETED = "DELETED"; + const UNLIST = "UNLIST"; + protected $parameters = [ - 'pagination_offset' => 0, - 'pagination_entries_per_page' => 100, + 'offset' => 0, + 'page_size' => 100, + 'item_status' => self::NORMAL ]; + public function getItemStatus(): string + { + return $this->parameters['item_status']; + } + + /** + * @param int $status + * @return $this + */ + public function setItemStatus(string $status) + { + $this->parameters['item_status'] = $status; + + return $this; + } + public function getPaginationOffset(): int { - return $this->parameters['pagination_offset']; + return $this->parameters['offset']; } /** @@ -25,14 +47,14 @@ public function getPaginationOffset(): int */ public function setPaginationOffset(int $offset) { - $this->parameters['pagination_offset'] = $offset; + $this->parameters['offset'] = $offset; return $this; } public function getPaginationEntriesPerPage(): int { - return $this->parameters['pagination_entries_per_page']; + return $this->parameters['page_size']; } /** @@ -46,7 +68,7 @@ public function getPaginationEntriesPerPage(): int */ public function setPaginationEntriesPerPage(int $perPage = 100) { - $this->parameters['pagination_entries_per_page'] = $perPage; + $this->parameters['page_size'] = $perPage; return $this; } diff --git a/src/Nodes/Item/Parameters/GetRecommendCats.php b/src/Nodes/Item/Parameters/GetRecommendCats.php index 7378d00..49b7545 100644 --- a/src/Nodes/Item/Parameters/GetRecommendCats.php +++ b/src/Nodes/Item/Parameters/GetRecommendCats.php @@ -6,11 +6,10 @@ class GetRecommendCats extends RequestParameters { - use CategoryIdTrait; public function getName(): string { - return $this->parameters['name']; + return $this->parameters['item_name']; } /** @@ -21,7 +20,7 @@ public function getName(): string */ public function setName(string $name) { - $this->parameters['name'] = $name; + $this->parameters['item_name'] = $name; return $this; } diff --git a/src/Nodes/Item/Parameters/Image.php b/src/Nodes/Item/Parameters/Image.php index 0c41aad..e9e44d5 100644 --- a/src/Nodes/Item/Parameters/Image.php +++ b/src/Nodes/Item/Parameters/Image.php @@ -6,18 +6,18 @@ class Image extends RequestParameters { - public function getUrl(): string + public function getImageId(): string { - return $this->parameters['url']; + return $this->parameters['image_id']; } /** - * @param string $url + * @param string $image_url * @return $this */ - public function setUrl(string $url) + public function setImageId(string $image_url) { - $this->parameters['url'] = $url; + $this->parameters['image_id'] = $image_url; return $this; } diff --git a/src/Nodes/Item/Parameters/Images.php b/src/Nodes/Item/Parameters/Images.php index e5bff20..d9e3217 100644 --- a/src/Nodes/Item/Parameters/Images.php +++ b/src/Nodes/Item/Parameters/Images.php @@ -3,30 +3,23 @@ namespace Shopee\Nodes\Item\Parameters; use Shopee\RequestParameterCollection; +use Shopee\RequestParameters; use Shopee\RequestParametersInterface; -class Images extends RequestParameterCollection +class Images extends RequestParameters { - /** - * @param Image|RequestParametersInterface $parameter - * @return $this - */ - public function add(RequestParametersInterface $parameter) + public function getImageIdList(): array { - parent::add($parameter); - - return $this; + return $this->parameters['image_id_list']; } /** - * @param array $parameters + * @param array $image_id_list * @return $this */ - public function fromArray(array $parameters) + public function setImageIdList(array $image_id_list) { - foreach ($parameters as $parameter) { - $this->add(new Image($parameter)); - } + $this->parameters['image_id_list'] = $image_id_list; return $this; } diff --git a/src/Nodes/Item/Parameters/InitTierVariation.php b/src/Nodes/Item/Parameters/InitTierVariation.php index a2567e3..a735567 100644 --- a/src/Nodes/Item/Parameters/InitTierVariation.php +++ b/src/Nodes/Item/Parameters/InitTierVariation.php @@ -6,15 +6,26 @@ class InitTierVariation extends RequestParameters { - use CategoryIdTrait; + use ItemTrait; - public function getTierVariation() + + public function getTierVariation(): TierVariants { return $this->parameters['tier_variation']; } - public function getVariation() + public function setTierVariation(TierVariants $tier_variants) + { + $this->parameters['tier_variation'] = $tier_variants; + } + + public function getModel(): Variations + { + return $this->parameters['model']; + } + + public function setModel(Variations $variations) { - return $this->parameters['variation']; + $this->parameters['model'] = $variations; } } diff --git a/src/Nodes/Item/Parameters/Logistics.php b/src/Nodes/Item/Parameters/Logistics.php index c97c5dc..d7917be 100644 --- a/src/Nodes/Item/Parameters/Logistics.php +++ b/src/Nodes/Item/Parameters/Logistics.php @@ -21,6 +21,7 @@ public function add(RequestParametersInterface $parameter) /** * @param array $parameters * @return $this + * @throws \ReflectionException */ public function fromArray(array $parameters) { diff --git a/src/Nodes/Item/Parameters/PreOrder.php b/src/Nodes/Item/Parameters/PreOrder.php new file mode 100644 index 0000000..97fd0aa --- /dev/null +++ b/src/Nodes/Item/Parameters/PreOrder.php @@ -0,0 +1,40 @@ +parameters['is_pre_order']; + } + + /** + * @param bool $is_pre_order + * @return $this + */ + public function setIsPreOrder(bool $is_pre_order) + { + $this->parameters['is_pre_order'] = $is_pre_order; + + return $this; + } + + public function getDaysToShip(): int + { + return $this->parameters['days_to_ship']; + } + + /** + * @param int $days_to_ship + * @return $this + */ + public function setDaysToShip(int $days_to_ship) + { + $this->parameters['days_to_ship'] = $days_to_ship; + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/RemoveVariation.php b/src/Nodes/Item/Parameters/RemoveVariation.php new file mode 100644 index 0000000..dae7c94 --- /dev/null +++ b/src/Nodes/Item/Parameters/RemoveVariation.php @@ -0,0 +1,11 @@ +parameters['comment_list']; + } + + /** + * @param array $comment_list + * @return $this + */ + public function setCommentList(CommentList $comment_list) + { + $this->parameters['comment_list'] = $comment_list; + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/SellerStock.php b/src/Nodes/Item/Parameters/SellerStock.php new file mode 100644 index 0000000..f25a7a5 --- /dev/null +++ b/src/Nodes/Item/Parameters/SellerStock.php @@ -0,0 +1,40 @@ +parameters['stock']; + } + + /** + * @param int $stock + * @return $this + */ + public function setStock(int $stock) + { + $this->parameters['stock'] = $stock; + + return $this; + } + + public function getLocationId(): string + { + return $this->parameters['location_id']; + } + + /** + * @param string $location_id + * @return $this + */ + public function setLocationId(string $location_id) + { + $this->parameters['location_id'] = $location_id; + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/SellerStocks.php b/src/Nodes/Item/Parameters/SellerStocks.php new file mode 100644 index 0000000..aa74cbd --- /dev/null +++ b/src/Nodes/Item/Parameters/SellerStocks.php @@ -0,0 +1,34 @@ +add(new SellerStock($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/TierVariant.php b/src/Nodes/Item/Parameters/TierVariant.php new file mode 100644 index 0000000..fd87cf0 --- /dev/null +++ b/src/Nodes/Item/Parameters/TierVariant.php @@ -0,0 +1,41 @@ +parameters['name']; + } + + /** + * @param string $name + * @return $this + */ + public function setName(string $name) + { + $this->parameters['name'] = $name; + + return $this; + } + + public function getOptionList(): TierVariantOptionList + { + return $this->parameters['option_list']; + } + + /** + * @param TierVariantOptionList $optionList + * @return $this + */ + public function setOptionList(TierVariantOptionList $optionList) + { + $this->parameters['option_list'] = $optionList; + + return $this; + } + +} diff --git a/src/Nodes/Item/Parameters/TierVariantOption.php b/src/Nodes/Item/Parameters/TierVariantOption.php new file mode 100644 index 0000000..ffd2313 --- /dev/null +++ b/src/Nodes/Item/Parameters/TierVariantOption.php @@ -0,0 +1,41 @@ +parameters['option']; + } + + /** + * @param string $name + * @return $this + */ + public function setOption(string $name) + { + $this->parameters['option'] = $name; + + return $this; + } + + public function getImage(): Image + { + return $this->parameters['image']; + } + + /** + * @param Image $image + * @return $this + */ + public function setImage(Image $image) + { + $this->parameters['image'] = $image; + + return $this; + } + +} diff --git a/src/Nodes/Item/Parameters/TierVariantOptionList.php b/src/Nodes/Item/Parameters/TierVariantOptionList.php new file mode 100644 index 0000000..8b6ecdc --- /dev/null +++ b/src/Nodes/Item/Parameters/TierVariantOptionList.php @@ -0,0 +1,34 @@ +add(new TierVariantOption($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/TierVariants.php b/src/Nodes/Item/Parameters/TierVariants.php new file mode 100644 index 0000000..a07f8ea --- /dev/null +++ b/src/Nodes/Item/Parameters/TierVariants.php @@ -0,0 +1,34 @@ +add(new TierVariant($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/UpdateItem.php b/src/Nodes/Item/Parameters/UpdateItem.php index cd746b7..64cb0d1 100644 --- a/src/Nodes/Item/Parameters/UpdateItem.php +++ b/src/Nodes/Item/Parameters/UpdateItem.php @@ -11,7 +11,7 @@ class UpdateItem extends RequestParameters public function getName(): string { - return $this->parameters['name']; + return $this->parameters['item_name']; } /** @@ -22,7 +22,7 @@ public function getName(): string */ public function setName(string $name) { - $this->parameters['name'] = $name; + $this->parameters['item_name'] = $name; return $this; } @@ -45,100 +45,100 @@ public function setDescription(string $description) return $this; } - public function getItemSku(): ?string + public function getStatus(): string { - return $this->parameters['item_sku']; + return $this->parameters['item_status']; } /** - * An item SKU (stock keeping unit) is an identifier defined by a seller, sometimes called parent SKU. - * Item SKU can be assigned to an item in Shopee Listings. - * @param string $itemSku + * The current stock quantity of the item. + * + * @param string $status * @return $this */ - public function setItemSku(string $itemSku) + public function setStatus(string $status) { - $this->parameters['item_sku'] = $itemSku; + $this->parameters['item_status'] = $status; return $this; } - public function getVariations(): ?VariationsForUpdateItem + public function getDimension(): Dimension { - return $this->parameters['variations']; + return $this->parameters['dimension']; } /** - * The variation of item is to list out all models of this product, for example, - * iPhone has model of White and Black, then its variations includes "White iPhone" and "Black iPhone". - * - * @param VariationsForUpdateItem $variations + * @param Dimension $dimension * @return $this */ - public function setVariations(VariationsForUpdateItem $variations) + public function setDimension(Dimension $dimension) { - $this->parameters['variations'] = $variations; + $this->parameters['dimension'] = $dimension; return $this; } - public function getAttributes(): ?Attributes + + public function getItemSku(): ?string { - return $this->parameters['attributes']; + return $this->parameters['item_sku']; } /** - * Should call shopee.item.GetAttributes to get attribute first. Should contain all all mandatory attribute. - * - * @param Attributes $attributes + * An item SKU (stock keeping unit) is an identifier defined by a seller, sometimes called parent SKU. + * Item SKU can be assigned to an item in Shopee Listings. + * @param string $itemSku * @return $this */ - public function setAttributes(Attributes $attributes) + public function setItemSku(string $itemSku) { - $this->parameters['attributes'] = $attributes; + $this->parameters['item_sku'] = $itemSku; return $this; } - public function getDaysToShip(): ?int + + public function getImages(): Images { - return $this->parameters['days_to_ship']; + return $this->parameters['image']; } /** - * The days to ship. Only work for pre-order, it means this value should be bigger than 7. + * Image URLs of the item. Up to 9 images, max 2.0 MB each.Image format accepted: JPG, JPEG, PNG. + * Suggested dimension: 1024 x 1024 px. * - * @param int $daysToShip + * @param Images $images * @return $this */ - public function setDaysToShip(int $daysToShip) + public function setImages(Images $images) { - $this->parameters['days_to_ship'] = $daysToShip; + $this->parameters['image'] = $images; return $this; } - public function getWholesales(): ?Wholesales + public function getAttributes(): ?Attributes { - return $this->parameters['wholesales']; + return $this->parameters['attribute_list']; } /** - * The wholesales tier list. Please put the wholesale tier info in order by min count. + * Should call shopee.item.GetAttributes to get attribute first. Should contain all all mandatory attribute. * - * @param Wholesales $wholesales + * @param Attributes $attributes * @return $this */ - public function setWholesales(Wholesales $wholesales) + public function setAttributes(Attributes $attributes) { - $this->parameters['wholesales'] = $wholesales; + $this->parameters['attribute_list'] = $attributes; return $this; } - public function getLogistics(): Logistics + public function getLogistics(): ?Logistics { - return $this->parameters['logistics']; + return $this->parameters['logistic_info']; } /** @@ -149,12 +149,12 @@ public function getLogistics(): Logistics */ public function setLogistics(Logistics $logistics) { - $this->parameters['logistics'] = $logistics; + $this->parameters['logistic_info'] = $logistics; return $this; } - public function getWeight(): float + public function getWeight(): ?float { return $this->parameters['weight']; } @@ -172,55 +172,73 @@ public function setWeight(float $weight) return $this; } - public function getPackageLength(): ?int + public function getPreOrder(): ?PreOrder { - return $this->parameters['package_length']; + return $this->parameters['days_to_ship']; } /** - * The height of package for this single item, the unit is CM. + * The days to ship. Only work for pre-order, it means this value should be bigger than 7. * - * @param int $packageLength + * @param PreOrder $preOrder * @return $this */ - public function setPackageLength(int $packageLength) + public function setPreOrder(PreOrder $preOrder) { - $this->parameters['package_length'] = $packageLength; + $this->parameters['pre_order'] = $preOrder; return $this; } - public function getPackageWidth(): ?int + public function getWholesales(): ?Wholesales { - return $this->parameters['package_width']; + return $this->parameters['wholesales']; } /** - * The height of package for this single item, the unit is CM. + * The wholesales tier list. Please put the wholesale tier info in order by min count. * - * @param int $packageWidth + * @param Wholesales $wholesales * @return $this */ - public function setPackageWidth(int $packageWidth) + public function setWholesales(Wholesales $wholesales) { - $this->parameters['package_width'] = $packageWidth; + $this->parameters['wholesales'] = $wholesales; return $this; } - public function getPackageHeight(): ?int + public function getBrand(): ?Brand { - return $this->parameters['package_height']; + return $this->parameters['brand']; } /** - * The height of package for this single item, the unit is CM. - * @param int $packageHeight + * + * @param Brand $brand + * @return $this + */ + public function setBrand(Brand $brand) + { + $this->parameters['brand'] = $brand; + + return $this; + } + + public function geVideoUploadId(): string + { + return $this->parameters['video_upload_id']; + } + + /** + * Name of the item in local language. + * + * @param string $name * @return $this */ - public function setPackageHeight(int $packageHeight) + public function setVideoUploadId(string $name) { - $this->parameters['package_height'] = $packageHeight; + $this->parameters['video_upload_id'] = [$name]; return $this; } diff --git a/src/Nodes/Item/Parameters/UpdateSizeChart.php b/src/Nodes/Item/Parameters/UpdateSizeChart.php new file mode 100644 index 0000000..57d54c3 --- /dev/null +++ b/src/Nodes/Item/Parameters/UpdateSizeChart.php @@ -0,0 +1,28 @@ +parameters['size_chart']; + } + + /** + * size chart image id + * + * @param string size_chart_id + * @return $this + */ + public function setSizeChart(string $size_chart_id) + { + $this->parameters['size_chart'] = $size_chart_id; + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/UpdateTierVariation.php b/src/Nodes/Item/Parameters/UpdateTierVariation.php new file mode 100644 index 0000000..fa15a5a --- /dev/null +++ b/src/Nodes/Item/Parameters/UpdateTierVariation.php @@ -0,0 +1,22 @@ +parameters['tier_variation']; + } + + public function setTierVariation(TierVariants $tier_variants) + { + $this->parameters['tier_variation'] = $tier_variants; + } + +} diff --git a/src/Nodes/Item/Parameters/UpdateVariation.php b/src/Nodes/Item/Parameters/UpdateVariation.php new file mode 100644 index 0000000..89e00f6 --- /dev/null +++ b/src/Nodes/Item/Parameters/UpdateVariation.php @@ -0,0 +1,26 @@ +parameters['model_sku']; + } + + /** + * @param string $variationSku + * @return $this + */ + public function setVariationSku(string $variationSku) + { + $this->parameters['model_sku'] = $variationSku; + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/UpdateVariationModel.php b/src/Nodes/Item/Parameters/UpdateVariationModel.php new file mode 100644 index 0000000..b329dc5 --- /dev/null +++ b/src/Nodes/Item/Parameters/UpdateVariationModel.php @@ -0,0 +1,22 @@ +parameters['model']; + } + + public function setModel(UpdateVariations $variations) + { + $this->parameters['model'] = $variations; + } + +} diff --git a/src/Nodes/Item/Parameters/UpdateVariationModelPrice.php b/src/Nodes/Item/Parameters/UpdateVariationModelPrice.php new file mode 100644 index 0000000..a533745 --- /dev/null +++ b/src/Nodes/Item/Parameters/UpdateVariationModelPrice.php @@ -0,0 +1,22 @@ +parameters['price_list']; + } + + public function setModel(UpdateVariationPriceList $variations) + { + $this->parameters['price_list'] = $variations; + } + +} diff --git a/src/Nodes/Item/Parameters/UpdateVariationModelStock.php b/src/Nodes/Item/Parameters/UpdateVariationModelStock.php new file mode 100644 index 0000000..7bd9d2d --- /dev/null +++ b/src/Nodes/Item/Parameters/UpdateVariationModelStock.php @@ -0,0 +1,22 @@ +parameters['stock_list']; + } + + public function setModel(UpdateVariationStockList $variations) + { + $this->parameters['stock_list'] = $variations; + } + +} diff --git a/src/Nodes/Item/Parameters/UpdateVariationPrice.php b/src/Nodes/Item/Parameters/UpdateVariationPrice.php index ba5de4e..42b0e46 100644 --- a/src/Nodes/Item/Parameters/UpdateVariationPrice.php +++ b/src/Nodes/Item/Parameters/UpdateVariationPrice.php @@ -4,6 +4,21 @@ class UpdateVariationPrice extends UpdatePrice { - use ItemTrait; use VariationIdTrait; + + public function getVariationPrice() + { + return $this->parameters['original_price']; + } + + /** + * @param float $price + * @return $this + */ + public function setVariationPrice(float $price) + { + $this->parameters['original_price'] = $price; + + return $this; + } } diff --git a/src/Nodes/Item/Parameters/UpdateVariationPriceList.php b/src/Nodes/Item/Parameters/UpdateVariationPriceList.php new file mode 100644 index 0000000..47b5cd9 --- /dev/null +++ b/src/Nodes/Item/Parameters/UpdateVariationPriceList.php @@ -0,0 +1,34 @@ +add(new UpdateVariationPrice($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/UpdateVariationStock.php b/src/Nodes/Item/Parameters/UpdateVariationStock.php index 6ed5aa4..4a2b788 100644 --- a/src/Nodes/Item/Parameters/UpdateVariationStock.php +++ b/src/Nodes/Item/Parameters/UpdateVariationStock.php @@ -4,6 +4,21 @@ class UpdateVariationStock extends UpdateStock { - use ItemTrait; use VariationIdTrait; + + public function getVariationStock() + { + return $this->parameters['seller_stock']; + } + + /** + * @param SellerStocks $stock + * @return $this + */ + public function setVariationStock(SellerStocks $stock) + { + $this->parameters['seller_stock'] = $stock; + + return $this; + } } diff --git a/src/Nodes/Item/Parameters/UpdateVariationStockList.php b/src/Nodes/Item/Parameters/UpdateVariationStockList.php new file mode 100644 index 0000000..96afaf6 --- /dev/null +++ b/src/Nodes/Item/Parameters/UpdateVariationStockList.php @@ -0,0 +1,34 @@ +add(new UpdateVariationStock($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/UpdateVariations.php b/src/Nodes/Item/Parameters/UpdateVariations.php new file mode 100644 index 0000000..03976ca --- /dev/null +++ b/src/Nodes/Item/Parameters/UpdateVariations.php @@ -0,0 +1,34 @@ +add(new UpdateVariation($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/Item/Parameters/Variation.php b/src/Nodes/Item/Parameters/Variation.php index cbfa379..4077bf4 100644 --- a/src/Nodes/Item/Parameters/Variation.php +++ b/src/Nodes/Item/Parameters/Variation.php @@ -6,48 +6,44 @@ class Variation extends RequestParameters { - public function getName(): string + public function getTierIndex(): array { - return $this->parameters['name']; + return $this->parameters['tier_index']; } /** - * Name of the variation that belongs to the same item.A seller can offer variations of the same item. - * For example, the seller could create a fixed-priced listing for a t-shirt design and offer the shirt in - * different colors and sizes. In this case, each color and size combination is a separate variation. - * Each variation can have a different quantity and price. * - * @param string $name + * @param array $index_list * @return $this */ - public function setName(string $name) + public function setTierIndex(array $index_list) { - $this->parameters['name'] = $name; + $this->parameters['tier_index'] = $index_list; return $this; } - public function getStock(): int + public function getStock(): SellerStocks { - return $this->parameters['stock']; + return $this->parameters['seller_stock']; } /** * The current stock quantity of the variation in the listing currency. * - * @param int $stock + * @param SellerStocks $stock * @return $this */ - public function setStock(int $stock) + public function setStock(SellerStocks $stock) { - $this->parameters['stock'] = $stock; + $this->parameters['seller_stock'] = $stock; return $this; } public function getPrice() { - return $this->parameters['price']; + return $this->parameters['original_price']; } /** @@ -58,28 +54,23 @@ public function getPrice() */ public function setPrice(float $price) { - $this->parameters['price'] = $price; + $this->parameters['original_price'] = $price; return $this; } public function getVariationSku() { - return $this->parameters['variation_sku']; + return $this->parameters['model_sku']; } /** - * A variation SKU (stock keeping unit) is an identifier defined by a seller. - * It is only intended for the seller's use. - * Many sellers assign a SKU to an item of a specific type, size, and color, which are variations of one item in - * Shopee Listings. - * * @param string $variationSku * @return $this */ public function setVariationSku(string $variationSku) { - $this->parameters['variation_sku'] = $variationSku; + $this->parameters['model_sku'] = $variationSku; return $this; } diff --git a/src/Nodes/Item/Parameters/VariationIdTrait.php b/src/Nodes/Item/Parameters/VariationIdTrait.php index 0e49078..521a5d3 100644 --- a/src/Nodes/Item/Parameters/VariationIdTrait.php +++ b/src/Nodes/Item/Parameters/VariationIdTrait.php @@ -4,22 +4,20 @@ trait VariationIdTrait { - public function getVariationId(): int + public function getModelId(): int { - return $this->parameters['variation_id']; + return $this->parameters['model_id']; } /** - * Shopee's unique identifier for a variation of an item. - * Please input the variation_id of a variation to be changed. - * The variation_id and item_id pair must be matched in order to perform the update. + * Set the Shopee's unique identifier for an item * - * @param int $variationId + * @param int $itemId * @return $this */ - public function setVariationId(int $variationId) + public function setModelId(int $itemId) { - $this->parameters['variation_id'] = $variationId; + $this->parameters['model_id'] = $itemId; return $this; } diff --git a/src/Nodes/Item/Parameters/Variations.php b/src/Nodes/Item/Parameters/Variations.php index cd3f735..faa3741 100644 --- a/src/Nodes/Item/Parameters/Variations.php +++ b/src/Nodes/Item/Parameters/Variations.php @@ -21,6 +21,7 @@ public function add(RequestParametersInterface $parameter) /** * @param array $parameters * @return $this + * @throws \ReflectionException */ public function fromArray(array $parameters) { diff --git a/src/Nodes/Item/Parameters/Wholesale.php b/src/Nodes/Item/Parameters/Wholesale.php index b95b231..8f9f38a 100644 --- a/src/Nodes/Item/Parameters/Wholesale.php +++ b/src/Nodes/Item/Parameters/Wholesale.php @@ -8,7 +8,7 @@ class Wholesale extends RequestParameters { public function getMin(): int { - return $this->parameters['min']; + return $this->parameters['min_count']; } /** @@ -20,14 +20,14 @@ public function getMin(): int */ public function setMin(int $min) { - $this->parameters['min'] = $min; + $this->parameters['min_count'] = $min; return $this; } public function getMax(): int { - return $this->parameters['max']; + return $this->parameters['max_count']; } /** @@ -38,7 +38,7 @@ public function getMax(): int */ public function setMax(int $max) { - $this->parameters['max'] = $max; + $this->parameters['max_count'] = $max; return $this; } diff --git a/src/Nodes/Item/Parameters/Wholesales.php b/src/Nodes/Item/Parameters/Wholesales.php index 476b754..5304ae3 100644 --- a/src/Nodes/Item/Parameters/Wholesales.php +++ b/src/Nodes/Item/Parameters/Wholesales.php @@ -21,6 +21,7 @@ public function add(RequestParametersInterface $parameter) /** * @param array $parameters * @return $this + * @throws \ReflectionException */ public function fromArray(array $parameters) { diff --git a/src/Nodes/Logistics/Logistics.php b/src/Nodes/Logistics/Logistics.php old mode 100644 new mode 100755 index 66b09b8..936620b --- a/src/Nodes/Logistics/Logistics.php +++ b/src/Nodes/Logistics/Logistics.php @@ -2,174 +2,131 @@ namespace Shopee\Nodes\Logistics; -use Shopee\Nodes\NodeAbstract; +use Illuminate\Support\Facades\Log; +use Shopee\ClientV2; +use Shopee\Nodes\NodeAbstractV2; use Shopee\RequestParametersInterface; use Shopee\ResponseData; -class Logistics extends NodeAbstract +class Logistics extends NodeAbstractV2 { - /** - * Use this call to get all required param for init logistic. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ - public function getAddress($parameters = []): ResponseData - { - return $this->post('/api/v1/logistics/address/get', $parameters); - } /** - * Use this API to get airway bill for orders. + * Use this call to get all supported Logistic Channel. * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function getAirwayBill($parameters = []): ResponseData + public function getLogistics($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/airway_bill/get_mass', $parameters); - } + return $this->get("/api/v2/logistics/get_channel_list", ClientV2::API_TYPE_SHOP, $parameters); - /** - * Use this call to get all required param for init logistic. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ - public function getBranch($parameters = []): ResponseData - { - return $this->post('/api/v1/logistics/branch/get', $parameters); } - /** - * Use this API to get airwaybill for fulfillment orders. + * Get return list. * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function getForderWaybill($parameters = []): ResponseData + public function getTrackingNumber($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/forder_waybill/get_mass', $parameters); + return $this->get('/api/v2/logistics/get_tracking_number', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this call to get all supported Logistic Channel. + * Get return list. * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function getLogistics($parameters = []): ResponseData + public function getShippingParameter($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/channel/get', $parameters); + return $this->get('/api/v2/logistics/get_shipping_parameter', ClientV2::API_TYPE_SHOP, $parameters); } - /** - * Get all the logistics info of an order to Init. + * Get return list. * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function getLogisticInfo($parameters = []): ResponseData + public function shipOrder($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/init_info/get', $parameters); + return $this->post('/api/v2/logistics/ship_order', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this call to get the logistics tracking information of an order. + * Get return list. * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function getLogisticsMessage($parameters = []): ResponseData + public function batchShipOrder($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/tracking', $parameters); + return $this->post('/api/v2/logistics/batch_ship_order', ClientV2::API_TYPE_SHOP, $parameters); } - /** - * Use this call to fetch the logistics information of an order, these info can be used for waybill printing. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ - public function getOrderLogistics($parameters = []): ResponseData - { - return $this->post('/api/v1/logistics/order/get', $parameters); - } /** - * Use this call to get all required param for init logistic. + * Get return list. * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function getParameterForInit($parameters = []): ResponseData + public function createShipingDocument($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/init_parameter/get', $parameters); + return $this->post('/api/v2/logistics/create_shipping_document', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this call to get all required param for init logistic. + * Get return list. * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function getTimeSlot($parameters = []): ResponseData + public function getShipingDocumentResult($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/timeslot/get', $parameters); + return $this->post('/api/v2/logistics/get_shipping_document_result', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this API to get tracking number of orders. + * Get return list. * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function getTrackingNo($parameters = []): ResponseData + public function downloadShipingDocument($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/tracking_number/get_mass', $parameters); + return $this->post('/api/v2/logistics/download_shipping_document', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this call to arrange Pickup, Dropoff or shipment for non-integrated logistic channels. + * Get return list address * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function init($parameters = []): ResponseData + public function getAddressList($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/init', $parameters); + return $this->get('/api/v2/logistics/get_address_list', ClientV2::API_TYPE_SHOP, $parameters); } - /** - * Set Logistic Status to PICKUP_DONE, this API only works for non-integrated logistic channels. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ - public function setLogisticStatus($parameters = []): ResponseData + public function getTrackingInfo($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/offline/set', $parameters); + return $this->get('/api/v2/logistics/get_tracking_info', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this call to set tracking number for each order in batch. + * Get return list. * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function setTrackingNo($parameters = []): ResponseData + public function updateShipOrder($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/tracking_number/set_mass', $parameters); + return $this->post('/api/v2/logistics/update_shipping_order', ClientV2::API_TYPE_SHOP, $parameters); } - - /** - * Configure shop level logistics. - * - * @param array|RequestParametersInterface $parameters $parameters - * @return ResponseData - */ - public function updateShopLogistics($parameters = []): ResponseData + public function getShippingDocumentDataInfo($parameters = []): ResponseData { - return $this->post('/api/v1/logistics/channels/update', $parameters); + return $this->post('/api/v2/logistics/get_shipping_document_data_info', ClientV2::API_TYPE_SHOP, $parameters); } } diff --git a/src/Nodes/Logistics/Parameters/BatchShipOrderInput.php b/src/Nodes/Logistics/Parameters/BatchShipOrderInput.php new file mode 100755 index 0000000..4542f99 --- /dev/null +++ b/src/Nodes/Logistics/Parameters/BatchShipOrderInput.php @@ -0,0 +1,27 @@ +parameters['order_list'] = $listOrderInput; + return $this; + } + + public function setPickup(ShipOrderPickupInput $pickupInput) + { + $this->parameters['pickup'] = $pickupInput; + return $this; + } +} diff --git a/src/Nodes/Logistics/Parameters/CreateShippingDocumentArrays.php b/src/Nodes/Logistics/Parameters/CreateShippingDocumentArrays.php new file mode 100755 index 0000000..32641cc --- /dev/null +++ b/src/Nodes/Logistics/Parameters/CreateShippingDocumentArrays.php @@ -0,0 +1,38 @@ +add(new CreateShippingDocumentParameter($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/Logistics/Parameters/CreateShippingDocumentInput.php b/src/Nodes/Logistics/Parameters/CreateShippingDocumentInput.php new file mode 100755 index 0000000..0128386 --- /dev/null +++ b/src/Nodes/Logistics/Parameters/CreateShippingDocumentInput.php @@ -0,0 +1,22 @@ +parameters['order_list'] = $params; + return $this; + } + +} diff --git a/src/Nodes/Logistics/Parameters/CreateShippingDocumentParameter.php b/src/Nodes/Logistics/Parameters/CreateShippingDocumentParameter.php new file mode 100755 index 0000000..0da7d1a --- /dev/null +++ b/src/Nodes/Logistics/Parameters/CreateShippingDocumentParameter.php @@ -0,0 +1,54 @@ + 'THERMAL_AIR_WAYBILL', + ]; + /** + * @param string $order_sn + * @return $this + */ + + public function setOrderSn(string $order_sn) + { + $this->parameters['order_sn'] = $order_sn; + return $this; + } + + /** + * @param string $shipping_document_type + * @return $this + */ + + public function setDocumentType(string $shipping_document_type) + { + $this->parameters['shipping_document_type'] = $shipping_document_type; + return $this; + } + /** + * @param string $package_number + * @return $this + */ + + public function setPackageNumber(string $package_number) + { + $this->parameters['package_number'] = $package_number; + return $this; + } + /** + * @param string $tracking_number + * @return $this + */ + + public function setTrackingNumber(string $tracking_number) + { + $this->parameters['tracking_number'] = $tracking_number; + return $this; + } +} diff --git a/src/Nodes/Logistics/Parameters/DownloadShippingDocumentInput.php b/src/Nodes/Logistics/Parameters/DownloadShippingDocumentInput.php new file mode 100755 index 0000000..ce5adce --- /dev/null +++ b/src/Nodes/Logistics/Parameters/DownloadShippingDocumentInput.php @@ -0,0 +1,35 @@ + 'THERMAL_AIR_WAYBILL', + ]; + + /** + * @param CreateShippingDocumentArrays $params + * @return $this + */ + + public function setOrderList(CreateShippingDocumentArrays $params) + { + $this->parameters['order_list'] = $params; + return $this; + } + + /** + * @param string $shipping_document_type + * @return $this + */ + + public function setDocumentType(string $shipping_document_type) + { + $this->parameters['shipping_document_type'] = $shipping_document_type; + return $this; + } + +} diff --git a/src/Nodes/Logistics/Parameters/GetShippingDocumentDataInfo.php b/src/Nodes/Logistics/Parameters/GetShippingDocumentDataInfo.php new file mode 100755 index 0000000..2f153b7 --- /dev/null +++ b/src/Nodes/Logistics/Parameters/GetShippingDocumentDataInfo.php @@ -0,0 +1,42 @@ +parameters['order_sn'] = $order_sn; + return $this; + } + /** + * @param string $package_number + * @return $this + */ + + public function setPackageNumber(string $package_number) + { + $this->parameters['package_number'] = $package_number; + return $this; + } + /** + * @param RecipientAddressInfo[] $recipient_address_infos + * @return $this + */ + public function setRecipientAddressInfo($recipient_address_infos) + { + foreach ($recipient_address_infos as $recipient_address_info) { + $this->parameters['recipient_address_info'][] = $recipient_address_info->toArray(); + } + return $this; + } + +} diff --git a/src/Nodes/Logistics/Parameters/GetTrackingInfo.php b/src/Nodes/Logistics/Parameters/GetTrackingInfo.php new file mode 100755 index 0000000..96f65bc --- /dev/null +++ b/src/Nodes/Logistics/Parameters/GetTrackingInfo.php @@ -0,0 +1,33 @@ +parameters['order_sn'] = $order_sn; + return $this; + } + /** + * @param string $package_number + * @return $this + */ + + public function setPackageNumber(string $package_number) + { + $this->parameters['package_number'] = $package_number; + return $this; + } + +} diff --git a/src/Nodes/Logistics/Parameters/GetTrackingNumber.php b/src/Nodes/Logistics/Parameters/GetTrackingNumber.php new file mode 100755 index 0000000..afa6b26 --- /dev/null +++ b/src/Nodes/Logistics/Parameters/GetTrackingNumber.php @@ -0,0 +1,25 @@ + 0, + ]; + + /** + * @param string $order_sn + * @return $this + */ + + public function setOrderSn(string $order_sn) + { + $this->parameters['order_sn'] = $order_sn; + return $this; + } + +} diff --git a/src/Nodes/Logistics/Parameters/ListOrderInput.php b/src/Nodes/Logistics/Parameters/ListOrderInput.php new file mode 100755 index 0000000..864f329 --- /dev/null +++ b/src/Nodes/Logistics/Parameters/ListOrderInput.php @@ -0,0 +1,38 @@ +add(new OrderPackageInput($parameter)); + } + + return $this; + } +} diff --git a/src/Nodes/Logistics/Parameters/OrderPackageInput.php b/src/Nodes/Logistics/Parameters/OrderPackageInput.php new file mode 100755 index 0000000..c67e9bd --- /dev/null +++ b/src/Nodes/Logistics/Parameters/OrderPackageInput.php @@ -0,0 +1,33 @@ +parameters['order_sn'] = $order_sn; + return $this; + } + /** + * @param string $package_number + * @return $this + */ + + public function setPackageNumber(string $package_number) + { + $this->parameters['package_number'] = $package_number; + return $this; + } + +} diff --git a/src/Nodes/Logistics/Parameters/RecipientAddressInfo.php b/src/Nodes/Logistics/Parameters/RecipientAddressInfo.php new file mode 100755 index 0000000..03e7115 --- /dev/null +++ b/src/Nodes/Logistics/Parameters/RecipientAddressInfo.php @@ -0,0 +1,34 @@ +parameters['key']; + } + + /** + * @param bool $key + * @return $this + */ + public function setKey(string $key) + { + $this->parameters['key'] = $key; + + return $this; + } + // /** + // * @param StyleShippingDocument[] $recipient_address_info + // * @return $this + // */ + public function setStyleShippingDocument(StyleShippingDocument $recipient_address_info) + { + $this->parameters['style'] = $recipient_address_info->toArray(); + return $this; + } +} diff --git a/src/Nodes/Logistics/Parameters/ShipOrderInput.php b/src/Nodes/Logistics/Parameters/ShipOrderInput.php new file mode 100755 index 0000000..45b1780 --- /dev/null +++ b/src/Nodes/Logistics/Parameters/ShipOrderInput.php @@ -0,0 +1,37 @@ +parameters['order_sn'] = $order_sn; + return $this; + } + /** + * @param string $package_number + * @return $this + */ + + public function setPackageNumber(string $package_number) + { + $this->parameters['package_number'] = $package_number; + return $this; + } + public function setPickup(ShipOrderPickupInput $pickupInput) + { + $this->parameters['pickup'] = $pickupInput; + return $this; + } +} diff --git a/src/Nodes/Logistics/Parameters/ShipOrderPickupInput.php b/src/Nodes/Logistics/Parameters/ShipOrderPickupInput.php new file mode 100755 index 0000000..16f99f0 --- /dev/null +++ b/src/Nodes/Logistics/Parameters/ShipOrderPickupInput.php @@ -0,0 +1,43 @@ +parameters['address_id'] = $address_id; + return $this; + } + /** + * @param int $pickup_time_id + * @return $this + */ + + public function setPickupTimeId($pickup_time_id) + { + $this->parameters['pickup_time_id'] = $pickup_time_id? ((string)$pickup_time_id ): null; + return $this; + } + /** + * @param string $tracking_number + * @return $this + */ + + public function setTrackingNumber(string $tracking_number) + { + $this->parameters['tracking_number'] = $tracking_number; + return $this; + } + +} diff --git a/src/Nodes/Logistics/Parameters/ShippingParameterInput.php b/src/Nodes/Logistics/Parameters/ShippingParameterInput.php new file mode 100755 index 0000000..9f2280a --- /dev/null +++ b/src/Nodes/Logistics/Parameters/ShippingParameterInput.php @@ -0,0 +1,33 @@ +parameters['order_sn'] = $order_sn; + return $this; + } + /** + * @param string $package_number + * @return $this + */ + + public function setPackageNumber(string $package_number) + { + $this->parameters['package_number'] = $package_number; + return $this; + } + +} diff --git a/src/Nodes/Logistics/Parameters/StyleShippingDocument.php b/src/Nodes/Logistics/Parameters/StyleShippingDocument.php new file mode 100755 index 0000000..3397c39 --- /dev/null +++ b/src/Nodes/Logistics/Parameters/StyleShippingDocument.php @@ -0,0 +1,88 @@ +parameters['text_style']; + } + + /** + * @param bool $text_style + * @return $this + */ + public function setTextStyle(Array $text_style) + { + $this->parameters['text_style'] = $text_style; + + return $this; + } + + public function getFontSize(): bool + { + return $this->parameters['font_size']; + } + + /** + * @param bool $font_size + * @return $this + */ + public function setFontSize(Int $font_size) + { + $this->parameters['font_size'] = $font_size; + + return $this; + } + + public function getTextColor(): bool + { + return $this->parameters['text_color']; + } + + /** + * @param bool $text_color + * @return $this + */ + public function setTextColor(String $text_color) + { + $this->parameters['text_color'] = $text_color; + + return $this; + } + + public function getImageWidth(): bool + { + return $this->parameters['image_width']; + } + + /** + * @param bool $image_width + * @return $this + */ + public function setImageWidth(Int $image_width) + { + $this->parameters['image_width'] = $image_width; + + return $this; + } + + public function getHAlign(): bool + { + return $this->parameters['h_align']; + } + + /** + * @param bool $h_align + * @return $this + */ + public function setHAlign(String $h_align) + { + $this->parameters['h_align'] = $h_align; + + return $this; + } +} diff --git a/src/Nodes/NodeAbstractV2.php b/src/Nodes/NodeAbstractV2.php new file mode 100644 index 0000000..69333ca --- /dev/null +++ b/src/Nodes/NodeAbstractV2.php @@ -0,0 +1,154 @@ +client = $client; + } + + /** + * @param string|UriInterface $uri + * @param $type_api + * @param array $parameters + * @return ResponseData + */ + public function post($uri, $type_api, $parameters) + { + if ($parameters instanceof RequestParametersInterface) { + $parameters = $parameters->toArray(); + } + + $request = $this->client->newRequest($uri, $type_api, [], $parameters); + $response = $this->client->send($request); + + return new ResponseData($response); + } + + /** + * @param string|UriInterface $uri + * @param $type_api + * @param array $parameters + * @return ResponseData + */ + public function get($uri, $type_api, $parameters) + { + if ($parameters instanceof RequestParametersInterface) { + $parameters = $parameters->toArray(); + } + $uri = Utils::uriFor($uri); + $path = Uri::withQueryValues($uri, $parameters); + + $request = $this->client->newRequest($path, $type_api, [], $parameters)->withMethod('GET'); + $response = $this->client->send($request); + + return new ResponseData($response); + } + + /** + * @param string|UriInterface $uri + * @param $type_api + * @param $file_url + * @return ResponseData + */ + public function upload($uri, $type_api, $file_url) + { + + $request = $this->client->newRequest($uri, $type_api, []); + $response = $this->client->upload($request, $file_url); + return new ResponseData($response); + } + /** + * @param string|UriInterface $uri + * @param $type_api + * @param $file_url + * @return ResponseData + */ + public function uploadWithBody($uri, $type_api, $file_url, $params = []) + { + + $request = $this->client->newRequest($uri, $type_api, $params); + $response = $this->client->upload($request, $file_url); + return new ResponseData($response); + } + + /** + * @param string|UriInterface $uri + * @param $type_api + * @param $file_url + * @return ResponseData + */ + public function chatUploadWithBody($uri, $type_api, $file_url, $params = []) + { + + $request = $this->client->newRequest($uri, $type_api, $params); + $response = $this->client->upload($request, $file_url, 'file'); + return new ResponseData($response); + } + + /** + * @param $video_upload_id + * @param $file_url + * @param $file_name + * @return ResponseData + * @throws Exception + */ + public function uploadVideoParts($video_upload_id, $file_url, $file_name){ + $fh = fopen($file_url, 'r'); + $chunkSize = 4194304; # 4MB + $response = []; + $parts = []; + $serial = 0; + while (! feof($fh)) { + $parts[] = $serial; + $chunk = fread($fh, $chunkSize); + $request = $this->client->newRequest("/api/v2/media_space/upload_video_part", ClientV2::API_TYPE_SHOP, []); + $response = $this->client->uploadVideoPart($request, $video_upload_id, $file_name, $chunk, $serial); + $this->parseResponseData(new ResponseData($response)); + $serial ++; + } + $response_data_video = new ResponseData($response); + $response_data_video->addData('part_seq_list', $parts); + return $response_data_video; + } + + public function downloadFile($urlDownload) + { + $path_info = pathinfo($urlDownload); + $filename = $path_info['basename']; + $tempImage = tempnam(sys_get_temp_dir(), $filename); + copy($urlDownload, $tempImage); + return [$tempImage, $filename]; + } + + /** + * @param $response ResponseData + * @return mixed + * @throws Exception + */ + private function parseResponseData($response){ + $response_data = $response->getData(); + if(!empty($response_data['error'])){ + $message = $response_data['error'] . ": " . $response_data['message']; + throw new Exception($message); + } + return $response_data; + } + +} diff --git a/src/Nodes/Order/Order.php b/src/Nodes/Order/Order.php index d5232cb..7c38d18 100644 --- a/src/Nodes/Order/Order.php +++ b/src/Nodes/Order/Order.php @@ -2,45 +2,15 @@ namespace Shopee\Nodes\Order; -use Shopee\Nodes\NodeAbstract; +use Shopee\ClientV2; +use Shopee\Nodes\NodeAbstractV2; use Shopee\RequestParametersInterface; use Shopee\ResponseData; -class Order extends NodeAbstract +class Order extends NodeAbstractV2 { - /** - * Use this call to retrieve detailed escrow information about one order based on OrderID. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ - public function getEscrowDetails($parameters = []): ResponseData - { - return $this->post('/api/v1/orders/my_income', $parameters); - } - /** - * Use this api to get orders' release time and escrow amount. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ - public function getEscrowReleasedOrders($parameters = []): ResponseData - { - return $this->post('/api/v1/orders/get_escrow_detail', $parameters); - } - - /** - * Use this call to retrieve detailed information of all the fulfill orders(forder) under a single regular order - * based on ordersn. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ - public function getForderInfo($parameters = []): ResponseData - { - return $this->post('/api/v1/orders/forder/get', $parameters); - } + const RESPONSE_FULL_FIELD = "buyer_user_id,buyer_username,estimated_shipping_fee,recipient_address,actual_shipping_fee ,goods_to_declare,note,note_update_time,item_list,pay_time,dropshipper,credit_card_number ,dropshipper_phone,split_up,buyer_cancel_reason,cancel_by,cancel_reason,actual_shipping_fee_confirmed,buyer_cpf_id,fulfillment_flag,pickup_done_time,package_list,shipping_carrier,payment_method,total_amount,buyer_username,invoice_data"; /** * Use this call to retrieve detailed information about one or more orders based on OrderIDs. @@ -50,19 +20,9 @@ public function getForderInfo($parameters = []): ResponseData */ public function getOrderDetails($parameters = []): ResponseData { - return $this->post('/api/v1/orders/detail', $parameters); + return $this->get('/api/v2/order/get_order_detail', ClientV2::API_TYPE_SHOP, $parameters); } - /** - * GetOrdersByStatus is the recommended call to use for order management. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ - public function getOrdersByStatus($parameters = []): ResponseData - { - return $this->post('/api/v1/orders/get', $parameters); - } /** * GetOrdersList is the recommended call to use for order management. @@ -72,7 +32,7 @@ public function getOrdersByStatus($parameters = []): ResponseData */ public function getOrdersList($parameters = []): ResponseData { - return $this->post('/api/v1/orders/basics', $parameters); + return $this->get('/api/v2/order/get_order_list', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -81,9 +41,9 @@ public function getOrdersList($parameters = []): ResponseData * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function acceptBuyerCancellation($parameters = []): ResponseData + public function handleBuyerCancellation($parameters = []): ResponseData { - return $this->post('/api/v1/orders/buyer_cancellation/accept', $parameters); + return $this->post('/api/v2/order/handle_buyer_cancellation', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -92,9 +52,9 @@ public function acceptBuyerCancellation($parameters = []): ResponseData * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function addOrderNote($parameters = []): ResponseData + public function setOrderNote($parameters = []): ResponseData { - return $this->post('/api/v1/orders/note/add', $parameters); + return $this->post('/api/v2/order/set_note', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -105,29 +65,30 @@ public function addOrderNote($parameters = []): ResponseData */ public function cancelOrder($parameters = []): ResponseData { - return $this->post('/api/v1/orders/cancel', $parameters); + return $this->post('/api/v2/order/cancel_order', ClientV2::API_TYPE_SHOP, $parameters); } + /** - * Use this call to reject buyer cancellation. + * Use this API to split order into fulfillment orders. * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function rejectBuyerCancellation($parameters = []): ResponseData + public function splitOrder($parameters = []): ResponseData { - return $this->post('/api/v1/orders/buyer_cancellation/reject', $parameters); + return $this->post('/api/v2/order/split_order', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this API to split order into fulfillment orders. + * Use this API to cancel split order from the seller side. * * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function splitOrder($parameters = []): ResponseData + public function undoSplitOrder($parameters = []): ResponseData { - return $this->post('/api/v1/orders/split', $parameters); + return $this->post('/api/v2/order/unsplit_order', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -136,8 +97,8 @@ public function splitOrder($parameters = []): ResponseData * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function undoSplitOrder($parameters = []): ResponseData + public function addInvoiceData($parameters = []): ResponseData { - return $this->post('/api/v1/orders/unsplit', $parameters); + return $this->post('/api/v2/order/add_invoice_data', ClientV2::API_TYPE_SHOP, $parameters); } } diff --git a/src/Nodes/Order/Parameters/AddInvoiceData.php b/src/Nodes/Order/Parameters/AddInvoiceData.php new file mode 100644 index 0000000..0ab0ce0 --- /dev/null +++ b/src/Nodes/Order/Parameters/AddInvoiceData.php @@ -0,0 +1,41 @@ +parameters['order_sn']; + } + + /** + * @param string $order_sn + * @return $this + */ + public function setOrderSn(string $order_sn) + { + $this->parameters['order_sn'] = $order_sn; + + return $this; + } + + public function getInvoiceData(): InvoiceData + { + return $this->parameters['invoice_data']; + } + + /** + * @param InvoiceData $invoice_data + * @return $this + */ + public function setInvoiceData($invoice_data) + { + $this->parameters['invoice_data'] = $invoice_data; + + return $this; + } + +} diff --git a/src/Nodes/Order/Parameters/GetOrdersList.php b/src/Nodes/Order/Parameters/GetOrdersList.php new file mode 100644 index 0000000..27be72e --- /dev/null +++ b/src/Nodes/Order/Parameters/GetOrdersList.php @@ -0,0 +1,132 @@ + self::TIME_RANGE_FIELD_CREATE, + 'time_from' => 0, + 'time_to' => 0, + 'page_size' => 100, + 'cursor' => "" + ]; + + public function getTimeRangeField(): string + { + return $this->parameters['time_range_field']; + } + + /** + * @param string $time_range_field + * @return $this + */ + public function setTimeRangeField(string $time_range_field) + { + $this->parameters['time_range_field'] = $time_range_field; + + return $this; + } + + public function getCursor(): int + { + return $this->parameters['cursor']; + } + + /** + * + * @param int $cursor + * @return $this + */ + public function setCursor(int $cursor) + { + $this->parameters['cursor'] = $cursor; + + return $this; + } + + public function getOrderStatus(): string + { + return $this->parameters['order_status']; + } + + /** + * + * @param string $status + * @return $this + */ + public function setOrderStatus(string $status) + { + $this->parameters['order_status'] = $status; + + return $this; + } + + public function getPaginationEntriesPerPage(): int + { + return $this->parameters['page_size']; + } + + /** + * If many items are available to retrieve, you may need to call GetItemsList multiple times to retrieve all the + * data. Each result set is returned as a page of entries. Use the Pagination filters to control the maximum number + * of entries (<= 100) to retrieve per page (i.e., per call), the offset number to start next call. + * This integer value is usUed to specify the maximum number of entries to return in a single ""page"" of data. + * + * @param int $perPage uint32 + * @return $this + */ + public function setPaginationEntriesPerPage(int $perPage = 100) + { + $this->parameters['page_size'] = $perPage; + + return $this; + } + + public function getTimeFrom(): ?int + { + return $this->parameters['time_from']; + } + + /** + * The update_time_from and update_time_to fields specify a date range for retrieving orders (based on the item + * update time). The update_time_from field is the starting date range. The maximum date range that may be specified + * with the update_time_from and update_time_to fields is 15 days. + * + * @param int $timestamp + * @return $this + */ + public function setTimeFrom(int $timestamp) + { + $this->parameters['time_from'] = $timestamp; + + return $this; + } + + public function getTimeTo(): ?int + { + return $this->parameters['time_to']; + } + + /** + * The update_time_from and update_time_to fields specify a date range for retrieving orders (based on the item + * update time). The update_time_to field is the ending date range. The maximum date range that may be specified + * with the update_time_from and update_time_to fields is 15 days. + * + * @param int $timestamp + * @return $this + */ + public function setTimeTo(int $timestamp) + { + $this->parameters['time_to'] = $timestamp; + + return $this; + } + +} diff --git a/src/Nodes/Order/Parameters/InvoiceData.php b/src/Nodes/Order/Parameters/InvoiceData.php new file mode 100644 index 0000000..35d40f2 --- /dev/null +++ b/src/Nodes/Order/Parameters/InvoiceData.php @@ -0,0 +1,119 @@ +parameters['number']; + } + + /** + * @param string $number + * @return $this + */ + public function setNumber(string $number) + { + $this->parameters['number'] = $number; + + return $this; + } + + public function getSeriesNumber(): string + { + return $this->parameters['series_number']; + } + + /** + * @param string $series_number + * @return $this + */ + public function setSeriesNumber($series_number) + { + $this->parameters['series_number'] = $series_number; + + return $this; + } + + public function getAccessKey(): string + { + return $this->parameters['access_key']; + } + + /** + * @param string $access_key + * @return $this + */ + public function setAccessKey($access_key) + { + $this->parameters['access_key'] = $access_key; + + return $this; + } + + public function getIssueDate(): int + { + return $this->parameters['issue_date']; + } + + /** + * @param int $issue_date + * @return $this + */ + public function setIssueDate($issue_date) + { + $this->parameters['issue_date'] = $issue_date; + + return $this; + } + + public function getTotalValue(): float + { + return $this->parameters['total_value']; + } + + /** + * @param float $total_value + * @return $this + */ + public function setTotalValue($total_value) + { + $this->parameters['total_value'] = $total_value; + + return $this; + } + + public function getProductsTotalValue(): float + { + return $this->parameters['products_total_value']; + } + + /** + * @param float $total_value + * @return $this + */ + public function setProductsTotalValue($total_value) + { + $this->parameters['products_total_value'] = $total_value; + + return $this; + } + public function getTaxCode(): string + { + return $this->parameters['tax_code']; + } + + /** + * @param string $tax_code + * @return $this + */ + public function setTaxCode($tax_code) + { + $this->parameters['tax_code'] = $tax_code; + + return $this; + } +} diff --git a/src/Nodes/Payment/Payment.php b/src/Nodes/Payment/Payment.php index 6d7c379..82ad86b 100644 --- a/src/Nodes/Payment/Payment.php +++ b/src/Nodes/Payment/Payment.php @@ -2,19 +2,20 @@ namespace Shopee\Nodes\Payment; -use Shopee\Nodes\NodeAbstract; +use Shopee\ClientV2; +use Shopee\Nodes\NodeAbstractV2; use Shopee\ResponseData; -class Payment extends NodeAbstract +class Payment extends NodeAbstractV2 { /** * Use this API to get the transaction records of wallet. * @param array $parameters * @return ResponseData */ - public function getTransactionList($parameters = []): ResponseData + public function getWalletTransactionList($parameters = []): ResponseData { - return $this->post('/api/v1/wallet/transaction/list', $parameters); + return $this->get('/api/v2/payment/get_wallet_transaction_list', ClientV2::API_TYPE_SHOP, $parameters); } /** @@ -24,6 +25,24 @@ public function getTransactionList($parameters = []): ResponseData */ public function getPayoutDetail($parameters = []): ResponseData { - return $this->post('/api/v1/payment/get_payout_details', $parameters); + return $this->post('/api/v2/payment/get_payout_detail', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * @param array $parameters + * @return ResponseData + */ + public function getEscrowDetail($parameters = []): ResponseData + { + return $this->get('/api/v2/payment/get_escrow_detail', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * @param array $parameters + * @return ResponseData + */ + public function getEscrowList($parameters = []): ResponseData + { + return $this->get('/api/v2/payment/get_escrow_list', ClientV2::API_TYPE_SHOP, $parameters); } } diff --git a/src/Nodes/Returns/Parameters/GetReturnOrdersList.php b/src/Nodes/Returns/Parameters/GetReturnOrdersList.php new file mode 100755 index 0000000..45f7f92 --- /dev/null +++ b/src/Nodes/Returns/Parameters/GetReturnOrdersList.php @@ -0,0 +1,38 @@ + 0, + 'page_size' => 40, + ]; + + /** + * @param int $page_no + * @return $this + */ + + public function setPageNo(int $page_no) + { + $this->parameters['page_no'] = $page_no; + return $this; + } + + /** + * @param int $page_no + * @return $this + */ + + public function setPaginationEntriesPerPage(int $perPage = 100) + { + $this->parameters['page_size'] = $perPage; + + return $this; + } + +} diff --git a/src/Nodes/Returns/Returns.php b/src/Nodes/Returns/Returns.php old mode 100644 new mode 100755 index 3c71287..c4e8e27 --- a/src/Nodes/Returns/Returns.php +++ b/src/Nodes/Returns/Returns.php @@ -2,33 +2,14 @@ namespace Shopee\Nodes\Returns; -use Shopee\Nodes\NodeAbstract; +use Illuminate\Support\Facades\Log; +use Shopee\ClientV2; +use Shopee\Nodes\NodeAbstractV2; use Shopee\RequestParametersInterface; use Shopee\ResponseData; -class Returns extends NodeAbstract +class Returns extends NodeAbstractV2 { - /** - * Confirm return. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ - public function confirmReturn($parameters = []): ResponseData - { - return $this->post('/api/v1/returns/confirm', $parameters); - } - - /** - * Dispute return. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ - public function disputeReturn($parameters = []): ResponseData - { - return $this->post('/api/v1/returns/dispute', $parameters); - } /** * Get return list. @@ -38,17 +19,11 @@ public function disputeReturn($parameters = []): ResponseData */ public function getReturnList($parameters = []): ResponseData { - return $this->post('/api/v1/returns/get', $parameters); + return $this->get('/api/v2/returns/get_return_list', ClientV2::API_TYPE_SHOP, $parameters); } - /** - * Use this api to get detail information of a returned order. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ public function getReturnDetail($parameters = []): ResponseData { - return $this->post('/api/v1/returns/detail', $parameters); + return $this->get('/api/v2/returns/get_return_detail', ClientV2::API_TYPE_SHOP, $parameters); } } diff --git a/src/Nodes/Shop/Authorization.php b/src/Nodes/Shop/Authorization.php new file mode 100644 index 0000000..d60d10c --- /dev/null +++ b/src/Nodes/Shop/Authorization.php @@ -0,0 +1,62 @@ +post('/api/v2/auth/token/get', ClientV2::API_TYPE_PUBLIC, [ + 'code' => $auth_code, + 'partner_id' => $partner_id, + 'shop_id' => $shop_id + ]); + } + /** + * Shop performance includes the indexes from "My Performance" of Seller Center. + * + * @param $auth_code + * @param $partner_id + * @param $shop_id + * @return ResponseData + */ + public function getAccessTokenByMainAccount($auth_code, $partner_id, $main_account_id): ResponseData + { + return $this->post('/api/v2/auth/token/get', ClientV2::API_TYPE_PUBLIC, [ + 'code' => $auth_code, + 'partner_id' => $partner_id, + 'main_account_id' => $main_account_id + ]); + } + + /** + * Only for TW whitelisted shop.Use this API to set the installment status of shop. + * + * @param $partner_id + * @param $shop_id + * @param $refresh_token + * @return ResponseData + */ + public function refreshAccessToken($partner_id, $shop_id, $refresh_token): ResponseData + { + return $this->post('/api/v2/auth/access_token/get', ClientV2::API_TYPE_PUBLIC, [ + 'partner_id' => $partner_id, + 'shop_id' => $shop_id, + 'refresh_token' => $refresh_token + ]); + } + +} diff --git a/src/Nodes/Shop/Shop.php b/src/Nodes/Shop/Shop.php index 6e7e430..8e86b75 100644 --- a/src/Nodes/Shop/Shop.php +++ b/src/Nodes/Shop/Shop.php @@ -2,64 +2,55 @@ namespace Shopee\Nodes\Shop; -use Shopee\Nodes\NodeAbstract; +use Shopee\ClientV2; +use Shopee\Nodes\NodeAbstractV2; use Shopee\RequestParametersInterface; use Shopee\ResponseData; -class Shop extends NodeAbstract +class Shop extends NodeAbstractV2 { /** * Use this call to get information of shop. - * + * https://open.shopee.com/documents?module=92&type=1&id=536&version=2 * @param array|RequestParametersInterface $parameters * @return ResponseData */ public function getShopInfo($parameters = []): ResponseData { - return $this->post('/api/v1/shop/get', $parameters); + return $this->get('/api/v2/shop/get_shop_info', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Shop performance includes the indexes from "My Performance" of Seller Center. * + * https://open.shopee.com/documents?module=92&type=1&id=584&version=2 * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function performance($parameters = []): ResponseData + public function getShopProfile($parameters = []): ResponseData { - return $this->post('/api/v1/shop/performance', $parameters); + return $this->get('/api/v2/shop/get_profile', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Only for TW whitelisted shop.Use this API to set the installment status of shop. * + * https://open.shopee.com/documents?module=92&type=1&id=585&version=2 * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function setShopInstallmentStatus($parameters = []): ResponseData + public function updateShopProfile($parameters = []): ResponseData { - return $this->post('/api/v1/shop/set_installment_status', $parameters); + return $this->post('/api/v2/shop/update_profile', ClientV2::API_TYPE_SHOP, $parameters); } /** - * Use this call to update information of shop. - * + * Use this call to get information of shop. + * https://open.shopee.com/documents/v2/v2.shop.get_warehouse_detail?module=92&type=1 * @param array|RequestParametersInterface $parameters * @return ResponseData */ - public function updateShopInfo($parameters = []): ResponseData + public function getWarehouseDetail($parameters = []): ResponseData { - return $this->post('/api/v1/shop/update', $parameters); + return $this->get('/api/v2/shop/get_warehouse_detail', ClientV2::API_TYPE_SHOP, $parameters); } - /** - * Use this call to get basic info of shops which have authorized to the partner. - * - * @param array|RequestParametersInterface $parameters - * @return ResponseData - */ - public function getShopsByPartner($parameters = []): ResponseData - { - return $this->post('/api/v1/shop/get_partner_shop', $parameters); - } } diff --git a/src/Nodes/Video/Video.php b/src/Nodes/Video/Video.php new file mode 100644 index 0000000..05cbeba --- /dev/null +++ b/src/Nodes/Video/Video.php @@ -0,0 +1,69 @@ +downloadFile($file_url); + $file_size = filesize($tempVideoDownload); + $file_md5 = md5_file($tempVideoDownload); + + #Init video upload + $response_init = $this->post('/api/v2/media_space/init_video_upload', + ClientV2::API_TYPE_SHOP, + [ + 'file_md5' => $file_md5, + 'file_size' => $file_size + ] + ); + $response_data = $response_init->getData(); + if (!empty($response_data['error'])) { + $message = $response_data['error'] . ": " . $response_data['message']; + throw new Exception($message); + } + + #Upload Video Part + $start = microtime(true); + $video_upload_id = $response_data['response']['video_upload_id']; + $response_video = $this->uploadVideoParts($video_upload_id, $tempVideoDownload, $fileName); + $time_elapsed_secs = intval(microtime(true) - $start); + + #Complete Video Upload + $response_complete_data = $this->post('/api/v2/media_space/complete_video_upload', ClientV2::API_TYPE_PUBLIC, [ + 'video_upload_id' => $video_upload_id, + 'part_seq_list' => $response_video->getData()['part_seq_list'], + 'report_data' => [ + 'upload_cost' => $time_elapsed_secs + ] + ]); + + $response_complete_data->addData('video_upload_id', $video_upload_id); + return $response_complete_data; + } + + /** + * Use this call to add a product item. + * + * @param array $parameters + * @return ResponseData + */ + public function getVideoUploadResult($parameters = []): ResponseData + { + return $this->get('/api/v2/media_space/get_video_upload_result', ClientV2::API_TYPE_SHOP, $parameters); + } + +} diff --git a/src/Nodes/Voucher/Parameters/AddVoucher.php b/src/Nodes/Voucher/Parameters/AddVoucher.php new file mode 100755 index 0000000..11ea982 --- /dev/null +++ b/src/Nodes/Voucher/Parameters/AddVoucher.php @@ -0,0 +1,79 @@ +parameters['voucher_name']; + } + + /** + * Name of the discount. + * + * @param string $name + * @return $this + */ + public function setName(string $name) + { + $this->parameters['voucher_name'] = $name; + + return $this; + } + public function getCode(): string + { + return $this->parameters['voucher_code']; + } + + /** + * Name of the discount. + * + * @param string $code + * @return $this + */ + public function setCode(string $code) + { + $this->parameters['voucher_code'] = $code; + + return $this; + } + + + + + public function getStartTime(): int + { + return $this->parameters['start_time']; + } + + /** + * @param int $start_time + * @return $this + */ + public function setStartTime(int $start_time) + { + $this->parameters['start_time'] = $start_time; + + return $this; + } + + public function getEndTime(): int + { + return $this->parameters['end_time']; + } + + /** + * @param int $end_time + * @return $this + */ + public function setEndTime(int $end_time) + { + $this->parameters['end_time'] = $end_time; + + return $this; + } +} diff --git a/src/Nodes/Voucher/Parameters/UpdateVoucher.php b/src/Nodes/Voucher/Parameters/UpdateVoucher.php new file mode 100755 index 0000000..1f388b7 --- /dev/null +++ b/src/Nodes/Voucher/Parameters/UpdateVoucher.php @@ -0,0 +1,81 @@ +parameters['voucher_name']; + } + + /** + * Name of the discount. + * + * @param string $name + * @return $this + */ + public function setName(string $name) + { + $this->parameters['voucher_name'] = $name; + + return $this; + } + public function getCode(): string + { + return $this->parameters['voucher_code']; + } + + /** + * Name of the discount. + * + * @param string $code + * @return $this + */ + public function setCode(string $code) + { + $this->parameters['voucher_code'] = $code; + + return $this; + } + + + + + public function getStartTime(): int + { + return $this->parameters['start_time']; + } + + /** + * @param int $start_time + * @return $this + */ + public function setStartTime(int $start_time) + { + $this->parameters['start_time'] = $start_time; + + return $this; + } + + public function getEndTime(): int + { + return $this->parameters['end_time']; + } + + /** + * @param int $end_time + * @return $this + */ + public function setEndTime(int $end_time) + { + $this->parameters['end_time'] = $end_time; + + return $this; + } +} diff --git a/src/Nodes/Voucher/Parameters/VoucherTrait.php b/src/Nodes/Voucher/Parameters/VoucherTrait.php new file mode 100644 index 0000000..2101065 --- /dev/null +++ b/src/Nodes/Voucher/Parameters/VoucherTrait.php @@ -0,0 +1,23 @@ +parameters['voucher_id']; + } + + /** + * @param int $voucher_id + * @return $this + */ + public function setVoucherId(int $voucher_id) + { + $this->parameters['voucher_id'] = $voucher_id; + + return $this; + } +} diff --git a/src/Nodes/Voucher/Voucher.php b/src/Nodes/Voucher/Voucher.php new file mode 100644 index 0000000..c818380 --- /dev/null +++ b/src/Nodes/Voucher/Voucher.php @@ -0,0 +1,75 @@ +post('/api/v2/voucher/add_voucher', ClientV2::API_TYPE_SHOP, $parameters); + } + + + + /** + * Use this api to delete one discount activity BEFORE it starts. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function deleteVoucher($parameters = []): ResponseData + { + return $this->post('/api/v2/voucher/delete_voucher', ClientV2::API_TYPE_SHOP, $parameters); + } + + + + /** + * Use this api to get one shop discount activity detail. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function getVoucherDetail($parameters = []): ResponseData + { + return $this->get('/api/v2/voucher/get_voucher', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to get shop discount activity list. + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function getVoucherList($parameters = []): ResponseData + { + return $this->get('/api/v2/voucher/get_voucher_list', ClientV2::API_TYPE_SHOP, $parameters); + } + + /** + * Use this api to update one discount information + * + * @param array|RequestParametersInterface $parameters + * @return ResponseData + */ + public function updateVoucher($parameters = []): ResponseData + { + return $this->post('/api/v2/voucher/update_voucher', ClientV2::API_TYPE_SHOP, $parameters); + } + + public function endVoucher($parameters = []): ResponseData + { + return $this->post('/api/v2/voucher/end_voucher', ClientV2::API_TYPE_SHOP, $parameters); + } +} diff --git a/src/RequestParameters.php b/src/RequestParameters.php index 2574946..355df0f 100644 --- a/src/RequestParameters.php +++ b/src/RequestParameters.php @@ -18,6 +18,11 @@ abstract class RequestParameters implements RequestParametersInterface */ protected $parameters = []; + /** + * RequestParameters constructor. + * @param array $parameters + * @throws \ReflectionException + */ public function __construct(array $parameters = []) { $this->fromArray($parameters); @@ -75,4 +80,12 @@ public function toArray(): array return $value; }, $this->parameters); } + + public function setParameter(string $param_name, $param_value) + { + $this->parameters[$param_name] = $param_value; + + return $this; + } + } diff --git a/src/ResponseData.php b/src/ResponseData.php index 7cdd480..2548d36 100644 --- a/src/ResponseData.php +++ b/src/ResponseData.php @@ -32,4 +32,8 @@ public function getData(): array { return $this->data; } + + public function addData($key, $value){ + $this->data[$key] = $value; + } } diff --git a/src/SignatureGenerator.php b/src/SignatureGenerator.php index ce662fd..7f1dee3 100644 --- a/src/SignatureGenerator.php +++ b/src/SignatureGenerator.php @@ -2,7 +2,10 @@ namespace Shopee; +use GuzzleHttp\Psr7\Uri; +use GuzzleHttp\Psr7\Utils; use function hash_hmac; +use Psr\Http\Message\UriInterface; class SignatureGenerator implements SignatureGeneratorInterface { @@ -19,4 +22,50 @@ public function generateSignature(string $url, string $body): string return hash_hmac('sha256', $data, $this->partnerKey); } + + public function generateSignatureShopLevel(UriInterface $uri, string $partner_id, string $access_token, string $shop_id): string + { + $time_st = time(); + $path = $uri->getPath(); + $data = $partner_id . $path . $time_st . $access_token . $shop_id; + $sign = hash_hmac('sha256', $data, $this->partnerKey); + $path = Uri::withQueryValues($uri, [ + 'partner_id' => $partner_id, + 'shop_id' => $shop_id, + 'timestamp' => $time_st, + 'access_token' => $access_token, + 'sign' => $sign + ]); + return $path->getQuery(); + } + + public function generateSignatureMerchantLevel(UriInterface $uri, string $partner_id, string $access_token, string $merchant_id): string + { + $time_st = time(); + $path = $uri->getPath(); + $data = $partner_id . $path . $time_st . $access_token . $merchant_id; + $sign = hash_hmac('sha256', $data, $this->partnerKey); + $path = Uri::withQueryValues($uri, [ + 'partner_id' => $partner_id, + 'merchant_id' => $partner_id, + 'timestamp' => $time_st, + 'access_token' => $partner_id, + 'sign' => $sign + ]); + return $path->getQuery(); + } + + public function generateSignaturePublicLevel(UriInterface $uri, string $partner_id): string + { + $time_st = time(); + $path = $uri->getPath(); + $data = $partner_id . $path . $time_st; + $sign = hash_hmac('sha256', $data, $this->partnerKey); + $path = Uri::withQueryValues($uri, [ + 'partner_id' => $partner_id, + 'timestamp' => $time_st, + 'sign' => $sign + ]); + return $path->getQuery(); + } } diff --git a/src/SignatureGeneratorInterface.php b/src/SignatureGeneratorInterface.php index e9b21ca..20b1126 100644 --- a/src/SignatureGeneratorInterface.php +++ b/src/SignatureGeneratorInterface.php @@ -2,7 +2,12 @@ namespace Shopee; +use Psr\Http\Message\UriInterface; + interface SignatureGeneratorInterface { - public function generateSignature(string $url, string $body): string; + public function generateSignature(string $url, string $body): string; // Using for V1 + public function generateSignatureShopLevel(UriInterface $path, string $partner_id, string $access_token, string $shop_id): string; + public function generateSignatureMerchantLevel(UriInterface $path, string $partner_id, string $access_token, string $merchant_id): string; + public function generateSignaturePublicLevel(UriInterface $path, string $partner_id): string; } diff --git a/tests/ClientTrait.php b/tests/ClientTrait.php index 1e43962..b2c40f1 100644 --- a/tests/ClientTrait.php +++ b/tests/ClientTrait.php @@ -11,13 +11,14 @@ use function is_array; use function array_merge; +use Shopee\ClientV2; trait ClientTrait { protected $defaultConfig = [ 'secret' => '42', 'partner_id' => 1, - 'shopid' => 10000, + 'shop_id' => 10000, ]; /** @@ -57,4 +58,27 @@ public function createClient(array $config = [], HttpClient $httpClient = null): return new Client(array_merge($this->defaultConfig, $config)); } + + public function createClientV2(array $config = [], HttpClient $httpClient = null): ClientV2 + { + if ($httpClient !== null) { + $config['httpClient'] = $httpClient; + } + + return new ClientV2(array_merge($this->defaultConfig, $config)); + } + + /** + * @param array $config + * @param HttpClient|null $httpClient + * @return \Mockery\LegacyMockInterface|\Mockery\MockInterface|ClientV2 + */ + public function createClientV2Mock(array $config = [], HttpClient $httpClient = null) + { + if ($httpClient !== null) { + $config['httpClient'] = $httpClient; + } + + return \Mockery::mock(ClientV2::class, array_merge($this->defaultConfig, $config)); + } } diff --git a/tests/ClientV2Test.php b/tests/ClientV2Test.php new file mode 100644 index 0000000..d6402f6 --- /dev/null +++ b/tests/ClientV2Test.php @@ -0,0 +1,234 @@ +createClientV2(); + + $this->assertInstanceOf(ClientV2::class, $client); + $this->assertInstanceOf(ClientInterface::class, $client->getHttpClient()); + $this->assertInstanceOf(UriInterface::class, $client->getBaseUrl()); + $this->assertEquals(ClientV2::DEFAULT_BASE_URL, $client->getBaseUrl()->__toString()); + $this->assertEquals(ClientV2::DEFAULT_USER_AGENT, $client->getUserAgent()); + } + + public function testCreateClientWithConfig() + { + $config = [ + 'httpClient' => new HttpClient(['ping' => 'pong']), + 'baseUrl' => 'https://galaxy.com/', + 'userAgent' => 'HeartOfGold/Prototype', + ]; + + $client = $this->createClientV2($config); + + $this->assertInstanceOf(ClientInterface::class, $client->getHttpClient()); + $this->assertEquals('pong', $client->getHttpClient()->getConfig('ping')); + $this->assertInstanceOf(UriInterface::class, $client->getBaseUrl()); + $this->assertEquals($config['baseUrl'], $client->getBaseUrl()->__toString()); + $this->assertEquals($config['userAgent'], $client->getUserAgent()); + } + + public function testCreateClientWithInvalidSignatureGenerator() + { + $this->expectException(InvalidArgumentException::class); + + $this->createClientV2([ + SignatureGeneratorInterface::class => new stdClass(), + ]); + } + + public function testShouldBeOkWhenRequestWithCustomSignatureGenerator() + { + $signatureGenerator = new class ('PARTNER_KEY') extends SignatureGenerator + { + public function generateSignaturePublicLevel(UriInterface $url, string $body): string + { + return 'CUSTOM_SIGNATURE'; + } + }; + + $actual = $this->createClientV2([ + SignatureGeneratorInterface::class => $signatureGenerator, + ])->newRequest('/api/v1/orders/detail', ClientV2::API_TYPE_PUBLIC); + + $this->assertEquals('https://partner.shopeemobile.com/api/v1/orders/detail?CUSTOM_SIGNATURE', $actual->getUri()->__toString()); + } + + public function testShouldBeOkWhenNewRequest() + { + $expected = new Request( + 'POST', + ClientV2::DEFAULT_BASE_URL . '/api/v2/orders/detail?CUSTOM_SIGNATURE', + [ + 'User-Agent' => ClientV2::DEFAULT_USER_AGENT, + 'Content-Type' => 'application/json', + ], + '{"partner_id":1,"shopid":61299,"timestamp":1470198856,"ordersn":"160726152598865"}' + ); + + $signatureGenerator = new class ('PARTNER_KEY') extends SignatureGenerator + { + public function generateSignaturePublicLevel(UriInterface $url, string $body): string + { + return 'CUSTOM_SIGNATURE'; + } + }; + + $object_mock = $this->createClientV2([ + SignatureGeneratorInterface::class => $signatureGenerator + ]); + + $actual = $object_mock->newRequest( + '/api/v2/orders/detail', + ClientV2::API_TYPE_PUBLIC, + [], + [ + 'partner_id' => 1, + 'shopid' => 61299, + 'timestamp' => 1470198856, + 'ordersn' => '160726152598865', + ] + ); + + $this->assertEquals($expected->getMethod(), $actual->getMethod()); + $this->assertEquals($expected->getUri(), $actual->getUri()); + $this->assertEquals($expected->getHeaders(), $actual->getHeaders()); + $this->assertEquals($expected->getBody()->getContents(), $actual->getBody()->getContents()); + $this->assertEquals($expected->getProtocolVersion(), $actual->getProtocolVersion()); + } + + public function getRequestUriCases() + { + return [ + [ + 'https://galaxy.com/', + '', + 'https://galaxy.com/?test=TEST_SIGNATURE', + ], + [ + 'https://galaxy.com/', + 'milky-way', + 'https://galaxy.com/milky-way?test=TEST_SIGNATURE', + ], + [ + 'https://galaxy.com/', + 'milky-way/solar-system', + 'https://galaxy.com/milky-way/solar-system?test=TEST_SIGNATURE', + ], + [ + 'https://galaxy.com/milky-way/', + 'solar-system', + 'https://galaxy.com/milky-way/solar-system?test=TEST_SIGNATURE', + ], + [ + 'https://galaxy.com/', + 'milky-way/solar-system?planet=earth', + 'https://galaxy.com/milky-way/solar-system?planet=earth&test=TEST_SIGNATURE', + ], + ]; + } + + /** + * @dataProvider getRequestUriCases + * @param string $baseUri + * @param string $actualUri + * @param string $exceptedUri + * @throws \Exception + */ + public function testShouldBeOkWhenNewRequestWithUri(string $baseUri, string $actualUri, string $exceptedUri) + { + $signatureGenerator = new class ('PARTNER_KEY') extends SignatureGenerator + { + public function generateSignaturePublicLevel(UriInterface $url, string $body): string + { + return Uri::withQueryValues($url, [ + 'test' => 'TEST_SIGNATURE', + ])->getQuery(); + } + }; + + $client = $this->createClientV2([ + 'baseUrl' => $baseUri, + SignatureGeneratorInterface::class => $signatureGenerator + ]); + + $expected = Utils::uriFor($exceptedUri); + $actual = $client->newRequest($actualUri, ClientV2::API_TYPE_PUBLIC)->getUri(); + + $this->assertEquals($expected, $actual); + } + + public function getAuthorizationRequestUriCases() + { + return [ + [ + 'https://galaxy.com', + 'test', + 'https://galaxy.com/api/v2/shop/auth_partner?test=TEST_SIGNATURE&redirect=test', + ], + [ + 'https://galaxy.com', + 'https://sme.upbase.vn/channel/shopee', + 'https://galaxy.com/api/v2/shop/auth_partner?test=TEST_SIGNATURE&redirect=https://sme.upbase.vn/channel/shopee', + ], + [ + 'https://galaxy.com', + 'https://sme.upbase.vn/channel/shopee?channel_code=123', + 'https://galaxy.com/api/v2/shop/auth_partner?test=TEST_SIGNATURE&redirect=https://sme.upbase.vn/channel/shopee?channel_code%3D123', + ], + ]; + } + + /** + * @dataProvider getAuthorizationRequestUriCases + * @param string $baseUri + * @param string $callback_url + * @param string $exceptedUri + */ + public function testAuthorizationUrl(string $baseUri, string $callback_url, string $exceptedUri){ + $signatureGenerator = new class ('PARTNER_KEY') extends SignatureGenerator + { + public function generateSignaturePublicLevel(UriInterface $url, string $body): string + { + return Uri::withQueryValues($url, [ + 'test' => 'TEST_SIGNATURE', + ])->getQuery(); + } + }; + + $client = $this->createClientV2([ + 'baseUrl' => $baseUri, + SignatureGeneratorInterface::class => $signatureGenerator + ]); + + $actual = $client->getAuthorizationUrl($callback_url); + + $this->assertEquals($exceptedUri, $actual); + } + +}