From d715c7a5a229ce1e12add026a5e3284c47296374 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Wed, 11 Dec 2024 12:11:40 +0800 Subject: [PATCH] add: fbt api --- src/Client.php | 2 + src/Resources/FulfilledByTiktok.php | 75 +++++++++++++++++++++++ tests/Resources/FulfilledByTiktokTest.php | 46 ++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 src/Resources/FulfilledByTiktok.php create mode 100644 tests/Resources/FulfilledByTiktokTest.php diff --git a/src/Client.php b/src/Client.php index 24bc09f..575449e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -16,6 +16,7 @@ use EcomPHP\TiktokShop\Resources\AffiliateSeller; use EcomPHP\TiktokShop\Resources\Analytics; use EcomPHP\TiktokShop\Resources\CustomerService; +use EcomPHP\TiktokShop\Resources\FulfilledByTiktok; use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\HandlerStack; use GuzzleHttp\Client as GuzzleHttpClient; @@ -93,6 +94,7 @@ class Client AffiliateCreator::class, AffiliatePartner::class, Analytics::class, + FulfilledByTiktok::class, ]; public function __construct($app_key, $app_secret, $options = []) diff --git a/src/Resources/FulfilledByTiktok.php b/src/Resources/FulfilledByTiktok.php new file mode 100644 index 0000000..e104700 --- /dev/null +++ b/src/Resources/FulfilledByTiktok.php @@ -0,0 +1,75 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace EcomPHP\TiktokShop\Resources; + +use EcomPHP\TiktokShop\Resource; +use GuzzleHttp\RequestOptions; + +class FulfilledByTiktok extends Resource +{ + protected $category = 'fbt'; + protected $minimum_version = 202408; + + public function getFbtMerchantOnboardedRegions() + { + return $this->call('GET', 'merchants/onboarded_regions', [], 202409); + } + + public function getFbtWarehouseList() + { + return $this->call('GET', 'warehouses'); + } + + public function getInboundOrder($ids) + { + return $this->call('GET', 'inbound_orders', [ + RequestOptions::QUERY => [ + 'ids' => static::dataTypeCast('array', $ids) + ] + ], 202409); + } + + public function searchFbtInventory($query = [], $body = []) + { + $query = array_merge([ + 'page_size' => 10, + ], $query); + + return $this->call('POST', 'inventory/search', [ + RequestOptions::QUERY => $query, + RequestOptions::JSON => $body, + ]); + } + + public function searchFbtInventoryRecord($query = [], $body = []) + { + $query = array_merge([ + 'page_size' => 10, + ], $query); + + return $this->call('POST', 'inventory_records/search', [ + RequestOptions::QUERY => $query, + RequestOptions::JSON => $body, + ], 202410); + } + + public function searchGoodsInfo($query = [], $body = []) + { + $query = array_merge([ + 'page_size' => 10, + ], $query); + + return $this->call('POST', 'goods/search', [ + RequestOptions::QUERY => $query, + RequestOptions::JSON => $body, + ], 202409); + } +} \ No newline at end of file diff --git a/tests/Resources/FulfilledByTiktokTest.php b/tests/Resources/FulfilledByTiktokTest.php new file mode 100644 index 0000000..7c2029b --- /dev/null +++ b/tests/Resources/FulfilledByTiktokTest.php @@ -0,0 +1,46 @@ +caller->getFbtMerchantOnboardedRegions(); + $this->assertPreviousRequest('GET', 'fbt/202409/merchants/onboarded_regions'); + } + + public function getFbtWarehouseList() + { + $this->caller->getFbtWarehouseList(); + $this->assertPreviousRequest('GET', 'fbt/' . self::TEST_API_VERSION . '/warehouses'); + } + + public function getInboundOrder() + { + $this->caller->getInboundOrder([]); + $this->assertPreviousRequest('GET', 'fbt/202409/inbound_orders'); + } + + public function testSearchFbtInventory() + { + $this->caller->searchFbtInventory(); + $this->assertPreviousRequest('POST', 'fbt/' . self::TEST_API_VERSION . '/inventory/search'); + } + + public function testSearchFbtInventoryRecord() + { + $this->caller->searchFbtInventoryRecord(); + $this->assertPreviousRequest('POST', 'fbt/202410/inventory_records/search'); + } + + public function testSearchGoodsInfo() + { + $this->caller->searchGoodsInfo(); + $this->assertPreviousRequest('POST', 'fbt/202409/goods/search'); + } +} \ No newline at end of file