Skip to content

Commit

Permalink
add: affiliate creator api
Browse files Browse the repository at this point in the history
  • Loading branch information
nVuln committed Jul 16, 2024
1 parent 1f971fb commit 85c2c38
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace EcomPHP\TiktokShop;

use EcomPHP\TiktokShop\Resources\AffiliateCreator;
use EcomPHP\TiktokShop\Resources\AffiliateSeller;
use EcomPHP\TiktokShop\Resources\CustomerService;
use GuzzleHttp\HandlerStack;
Expand Down Expand Up @@ -46,6 +47,7 @@
* @property-read ReturnRefund $ReturnRefund
* @property-read CustomerService $CustomerService
* @property-read AffiliateSeller $AffiliateSeller
* @property-read AffiliateCreator $AffiliateCreator
*/
class Client
{
Expand Down Expand Up @@ -83,6 +85,7 @@ class Client
ReturnRefund::class,
CustomerService::class,
AffiliateSeller::class,
AffiliateCreator::class,
];

public function __construct($app_key, $app_secret, $options = [])
Expand Down
82 changes: 82 additions & 0 deletions src/Resources/AffiliateCreator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/*
* This file is part of tiktokshop-php.
*
* Copyright (c) 2024 Jin <[email protected]> All rights reserved.
*
* 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 AffiliateCreator extends Resource
{
protected $category = 'affiliate_creator';
protected $minimum_version = 202405;

public function addShowcaseProducts($add_type, $product_ids = [], $product_link = '')
{
return $this->call('POST', 'showcases/products/add', [
'add_type' => $add_type,
'product_ids' => $product_ids,
'product_link' => $product_link,
]);
}

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

return $this->call('GET', 'showcases/products', [
RequestOptions::QUERY => $query,
]);
}

public function getCreatorProfile()
{
return $this->call('GET', 'profiles');
}

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 searchTargetCollaborations($query, $body = [])
{
$query = array_merge([
'page_size' => 10,
], $query);

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

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

return $this->call('POST', 'orders/search', [
RequestOptions::QUERY => $query,
RequestOptions::JSON => [],
]);
}
}
65 changes: 65 additions & 0 deletions tests/Resources/AffiliateCreatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/*
* This file is part of tiktokshop-php.
*
* Copyright (c) 2024 Jin <[email protected]> All rights reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EcomPHP\TiktokShop\Tests\Resources;

use EcomPHP\TiktokShop\Tests\TestResource;

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

protected function tiktokShopClientForTest()
{
$client = parent::tiktokShopClientForTest();
$client->useVersion(self::TEST_API_VERSION);

return $client;
}

public function testAddShowcaseProducts()
{
$this->caller->addShowcaseProducts('add_type', [1, 2, 3], 'product_link');
$this->assertPreviousRequest('POST', 'affiliate_creator/'.self::TEST_API_VERSION.'/showcases/products/add');
}

public function testGetShowcaseProducts()
{
$this->caller->getShowcaseProducts();
$this->assertPreviousRequest('GET', 'affiliate_creator/'.self::TEST_API_VERSION.'/showcases/products');
}

public function testGetCreatorProfile()
{
$this->caller->getCreatorProfile();
$this->assertPreviousRequest('GET', 'affiliate_creator/'.self::TEST_API_VERSION.'/profiles');
}

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

public function testSearchTargetCollaborations()
{
$this->caller->searchTargetCollaborations([]);
$this->assertPreviousRequest('POST', 'affiliate_creator/'.self::TEST_API_VERSION.'/target_collaborations/search');
}

public function testSearchAffiliateOrders()
{
$this->caller->searchAffiliateOrders();
$this->assertPreviousRequest('POST', 'affiliate_creator/'.self::TEST_API_VERSION.'/orders/search');
}
}

0 comments on commit 85c2c38

Please sign in to comment.