Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: fbt api #57

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}
Loading