Skip to content

Commit

Permalink
remove sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin committed Dec 21, 2023
1 parent 40bb76d commit 09f172e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class Auth

protected $authHost;

public function __construct(Client $client, $sandbox = false)
public function __construct(Client $client)
{
$this->client = $client;
$this->httpClient = new GuzzleHttpClient();

$this->authHost = $sandbox ? 'https://auth-sandbox.tiktok-shops.com' : 'https://auth.tiktok-shops.com';
$this->authHost = 'https://auth.tiktok-shops.com';
}

public function createAuthRequest($state = null, $returnAuthUrl = false)
Expand Down
14 changes: 5 additions & 9 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class Client
* required for calling cross-border shop
*/
protected $shop_cipher;
protected $sandbox;
protected $version;

/**
Expand All @@ -80,18 +79,17 @@ class Client
ReturnRefund::class,
];

public function __construct($app_key, $app_secret, $sandbox = false, $version = self::DEFAULT_VERSION, $options = [])
public function __construct($app_key, $app_secret, $options = [])
{
$this->app_key = $app_key;
$this->app_secret = $app_secret;
$this->sandbox = $sandbox;
$this->version = $version;
$this->version = static::DEFAULT_VERSION;
$this->options = $options;
}

public function useSandboxMode()
{
$this->sandbox = true;
trigger_deprecation('ecomphp/tiktokshop-php', '2.0.0', 'useSandboxMode() will be deprecated: Since API version 202309, Tiktokshop API sandbox is no longer worked, please use production environment.');
}

public function getAppKey()
Expand All @@ -116,7 +114,7 @@ public function setShopCipher($shop_cipher)

public function auth()
{
return new Auth($this, $this->sandbox);
return new Auth($this);
}

public function webhook()
Expand Down Expand Up @@ -175,12 +173,10 @@ protected function httpClient()
return $this->modifyRequestBeforeSend($request);
}));

$api_domain_endpoint = $this->sandbox ? 'open-api-sandbox.tiktokglobalshop.com' : 'open-api.tiktokglobalshop.com';

$options = array_merge([
RequestOptions::HTTP_ERRORS => false, // disable throw exception on http 4xx, manual handle it
'handler' => $stack,
'base_uri' => 'https://'.$api_domain_endpoint.'/',
'base_uri' => 'https://open-api.tiktokglobalshop.com/',
], $this->options ?? []);

return new GuzzleHttpClient($options);
Expand Down
26 changes: 0 additions & 26 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,6 @@ public function testAuth()
$this->assertInstanceOf(Auth::class, $this->client->auth());
}

public function testUseSandboxMode()
{
$clientReflection = new ReflectionClass($this->client);
$sandboxProperty = $clientReflection->getProperty('sandbox');
$sandboxProperty->setAccessible(true);

// sandbox is off
$this->assertFalse($sandboxProperty->getValue($this->client));

// change sandbox mode
$this->client->useSandboxMode();
$clientReflection = new ReflectionClass($this->client);
$sandboxProperty = $clientReflection->getProperty('sandbox');
$sandboxProperty->setAccessible(true);

// sandbox is on
$this->assertTrue($sandboxProperty->getValue($this->client));
}

public function test__get()
{
$resources = Client::resources;
Expand All @@ -86,15 +67,8 @@ public function test__get()

public function test__construct()
{
$clientReflection = new ReflectionClass($this->client);

$this->assertEquals('app_key', $this->client->getAppKey());
$this->assertEquals('app_secret', $this->client->getAppSecret());

$sandboxProperty = $clientReflection->getProperty('sandbox');
$sandboxProperty->setAccessible(true);

$this->assertEquals(false, $sandboxProperty->getValue($this->client));
}

public function testPrepareSignature()
Expand Down

0 comments on commit 09f172e

Please sign in to comment.