Skip to content

Commit

Permalink
add: fbt api (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquariuscool authored Dec 16, 2024
1 parent b9eddb2 commit 252bacf
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,6 +94,7 @@ class Client
AffiliateCreator::class,
AffiliatePartner::class,
Analytics::class,
FulfilledByTiktok::class,
];

public function __construct($app_key, $app_secret, $options = [])
Expand Down
75 changes: 75 additions & 0 deletions src/Resources/FulfilledByTiktok.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/*
* This file is part of tiktok-shop.
*
* (c) Jin <j@sax.vn>
*
* 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);
}
}
46 changes: 46 additions & 0 deletions tests/Resources/FulfilledByTiktokTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace EcomPHP\TiktokShop\Tests\Resources;

use EcomPHP\TiktokShop\Tests\TestResource;

class FulfilledByTiktokTest extends TestResource
{
public const TEST_API_VERSION = 202408;

public function testGetFbtMerchantOnboardedRegions()
{
$this->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');
}
}

0 comments on commit 252bacf

Please sign in to comment.