Skip to content

Commit

Permalink
Added possibility to set sandbox mode (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech authored Jul 14, 2022
1 parent ac6311d commit 769b346
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 28 additions & 7 deletions src/AmazonPHP/SellingPartner/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ final class Configuration

private Extensions $extensions;

private bool $sandbox = false;

public function __construct(
string $lwaClientID,
string $lwaClientSecret,
Expand Down Expand Up @@ -91,11 +93,11 @@ public function apiURL(string $awsRegion) : string

switch ($awsRegion) {
case Regions::EUROPE:
return Regions::EUROPE_URL;
return $this->sandbox ? Regions::EUROPE_SANDBOX_URL : Regions::EUROPE_URL;
case Regions::FAR_EAST:
return Regions::FAR_EAST_URL;
return $this->sandbox ? Regions::FAR_EAST_SANDBOX_URL : Regions::FAR_EAST_URL;
case Regions::NORTH_AMERICA:
return Regions::NORTH_AMERICA_URL;
return $this->sandbox ? Regions::NORTH_AMERICA_SANDBOX_URL : Regions::NORTH_AMERICA_URL;

default:
throw new \RuntimeException('unknown region');
Expand All @@ -110,14 +112,14 @@ public function apiHost(string $awsRegion) : string

switch ($awsRegion) {
case Regions::EUROPE:
return Regions::EUROPE_HOST;
return $this->sandbox ? Regions::EUROPE_SANDBOX_HOST : Regions::EUROPE_HOST;
case Regions::FAR_EAST:
return Regions::FAR_EAST_HOST;
return $this->sandbox ? Regions::FAR_EAST_SANDBOX_HOST : Regions::FAR_EAST_HOST;
case Regions::NORTH_AMERICA:
return Regions::NORTH_AMERICA_HOST;
return $this->sandbox ? Regions::NORTH_AMERICA_SANDBOX_HOST : Regions::NORTH_AMERICA_HOST;

default:
throw new \RuntimeException('unknown region');
throw new \RuntimeException('Unknown region: ' . $awsRegion);
}
}

Expand Down Expand Up @@ -239,4 +241,23 @@ public function extensions() : Extensions
{
return $this->extensions;
}

public function isSandbox() : bool
{
return $this->sandbox;
}

public function setSandbox() : self
{
$this->sandbox = true;

return $this;
}

public function setProduction() : self
{
$this->sandbox = false;

return $this;
}
}
12 changes: 12 additions & 0 deletions src/AmazonPHP/SellingPartner/Regions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,32 @@ final class Regions

public const EUROPE_HOST = 'sellingpartnerapi-eu.amazon.com';

public const EUROPE_SANDBOX_HOST = 'sandbox.sellingpartnerapi-eu.amazon.com';

public const EUROPE_URL = 'https://' . self::EUROPE_HOST;

public const EUROPE_SANDBOX_URL = 'https://' . self::EUROPE_SANDBOX_HOST;

public const FAR_EAST = 'us-west-2';

public const FAR_EAST_HOST = 'sellingpartnerapi-fe.amazon.com';

public const FAR_EAST_SANDBOX_HOST = 'sandbox.sellingpartnerapi-fe.amazon.com';

public const FAR_EAST_URL = 'https://' . self::FAR_EAST_HOST;

public const FAR_EAST_SANDBOX_URL = 'https://' . self::FAR_EAST_SANDBOX_HOST;

public const NORTH_AMERICA = 'us-east-1';

public const NORTH_AMERICA_HOST = 'sellingpartnerapi-na.amazon.com';

public const NORTH_AMERICA_SANDBOX_HOST = 'sandbox.sellingpartnerapi-na.amazon.com';

public const NORTH_AMERICA_URL = 'https://' . self::NORTH_AMERICA_HOST;

public const NORTH_AMERICA_SANDBOX_URL = 'https://' . self::NORTH_AMERICA_SANDBOX_HOST;

public static function isValid(string $region) : bool
{
return \in_array($region, [self::EUROPE, self::FAR_EAST, self::NORTH_AMERICA], true);
Expand Down

0 comments on commit 769b346

Please sign in to comment.