Skip to content

Commit

Permalink
update: affiliate seller api
Browse files Browse the repository at this point in the history
  • Loading branch information
nVuln committed Jul 15, 2024
1 parent 78839e2 commit 1f971fb
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 2 deletions.
71 changes: 70 additions & 1 deletion src/Resources/AffiliateSeller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,81 @@
class AffiliateSeller extends Resource
{
protected $category = 'affiliate_seller';
protected $minimum_version = 202405;
protected $minimum_version = 202406;

public function editOpenCollaborationSettings($body)
{
return $this->call('POST', 'open_collaboration_settings', [
RequestOptions::JSON => $body,
]);
}

public function searchOpenCollaborationProduct($query = [], $body = [])
{
$query = array_merge([
'page_size' => 10,
], $query);

return $this->call('POST', 'open_collaborations/products/search', [
RequestOptions::QUERY => $query,
RequestOptions::JSON => $body,
]);
}

public function searchSellerAffiliateOrders($query = [])
{
$query = array_merge([
'page_size' => 10,
], $query);

return $this->call('POST', 'orders/search', [
RequestOptions::QUERY => $query,
RequestOptions::JSON => [],
]);
}

public function createOpenCollaboration($product_id, $commission_rate, $require_seller_approve_creator = false)
{
return $this->call('POST', 'open_collaborations', [
RequestOptions::JSON => [
'product_id' => $product_id,
'commission_rate' => $commission_rate,
'require_seller_approve_creator' => $require_seller_approve_creator,
],
]);
}

public function createTargetCollaboration($body)
{
return $this->call('POST', 'target_collaborations', [
RequestOptions::JSON => $body,
]);
}

public function removeCreatorAffiliateFromCollaboration($open_collaboration_id, $creator_user_id, $product_id)
{
return $this->call('POST', 'open_collaborations/'.$open_collaboration_id.'/remove_creator', [
RequestOptions::JSON => [
'creator_user_id' => $creator_user_id,
'product_id' => $product_id,
],
]);
}

public function getMarketplaceCreatorPerformance($creator_user_id)
{
return $this->call('GET', 'marketplace_creators/'.$creator_user_id);
}

public function searchCreatorOnMarketplace($query = [], $body = [])
{
$query = array_merge([
'page_size' => 12,
], $query);

return $this->call('POST', 'marketplace_creators/search', [
RequestOptions::QUERY => $query,
RequestOptions::JSON => $body,
]);
}
}
47 changes: 46 additions & 1 deletion tests/Resources/AffiliateSellerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@

use EcomPHP\TiktokShop\Tests\TestResource;

/**
* @property-read \EcomPHP\TiktokShop\Resources\AffiliateSeller $caller
*/
class AffiliateSellerTest extends TestResource
{
public const TEST_API_VERSION = 202405;
public const TEST_API_VERSION = 202406;

protected function tiktokShopClientForTest()
{
Expand All @@ -29,4 +32,46 @@ public function testEditOpenCollaborationSettings()
$this->caller->editOpenCollaborationSettings([]);
$this->assertPreviousRequest('POST', 'affiliate_seller/'.self::TEST_API_VERSION.'/open_collaboration_settings');
}

public function testSearchOpenCollaborationProduct()
{
$this->caller->searchOpenCollaborationProduct();
$this->assertPreviousRequest('POST', 'affiliate_seller/'.self::TEST_API_VERSION.'/open_collaborations/products/search');
}

public function testSearchSellerAffiliateOrders()
{
$this->caller->searchSellerAffiliateOrders();
$this->assertPreviousRequest('POST', 'affiliate_seller/'.self::TEST_API_VERSION.'/orders/search');
}

public function testCreateOpenCollaboration()
{
$this->caller->createOpenCollaboration(1, 1);
$this->assertPreviousRequest('POST', 'affiliate_seller/'.self::TEST_API_VERSION.'/open_collaborations');
}

public function testCreateTargetCollaboration()
{
$this->caller->createTargetCollaboration([]);
$this->assertPreviousRequest('POST', 'affiliate_seller/'.self::TEST_API_VERSION.'/target_collaborations');
}

public function testRemoveCreatorAffiliateFromCollaboration()
{
$this->caller->removeCreatorAffiliateFromCollaboration(1, 2, 3);
$this->assertPreviousRequest('POST', 'affiliate_seller/'.self::TEST_API_VERSION.'/open_collaborations/1/remove_creator');
}

public function testGetMarketplaceCreatorPerformance()
{
$this->caller->getMarketplaceCreatorPerformance(1);
$this->assertPreviousRequest('GET', 'affiliate_seller/'.self::TEST_API_VERSION.'/marketplace_creators/1');
}

public function testSearchCreatorOnMarketplace()
{
$this->caller->searchCreatorOnMarketplace();
$this->assertPreviousRequest('POST', 'affiliate_seller/'.self::TEST_API_VERSION.'/marketplace_creators/search');
}
}

0 comments on commit 1f971fb

Please sign in to comment.