-
-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathEndpoint.php
73 lines (60 loc) · 2.23 KB
/
Endpoint.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
namespace SellingPartnerApi\Enums;
use SellingPartnerApi\Traits\EnumTrait;
enum Endpoint: string
{
use EnumTrait;
case NA = 'https://sellingpartnerapi-na.amazon.com';
case NA_SANDBOX = 'https://sandbox.sellingpartnerapi-na.amazon.com';
case EU = 'https://sellingpartnerapi-eu.amazon.com';
case EU_SANDBOX = 'https://sandbox.sellingpartnerapi-eu.amazon.com';
case FE = 'https://sellingpartnerapi-fe.amazon.com';
case FE_SANDBOX = 'https://sandbox.sellingpartnerapi-fe.amazon.com';
public static function isSandbox(Endpoint $endpoint): bool
{
return in_array(
$endpoint,
[
self::NA_SANDBOX,
self::EU_SANDBOX,
self::FE_SANDBOX,
],
true
);
}
public static function host(Endpoint $endpoint): string
{
return str_replace('https://', '', $endpoint->value);
}
public static function byMarketplaceId(string|Marketplace $marketplaceId, bool $sandbox = false): self
{
if (is_string($marketplaceId)) {
$marketplaceId = Marketplace::from($marketplaceId);
}
return match (Marketplace::toRegion($marketplaceId)) {
Region::NA => $sandbox ? self::NA_SANDBOX : self::NA,
Region::EU => $sandbox ? self::EU_SANDBOX : self::EU,
Region::FE => $sandbox ? self::FE_SANDBOX : self::FE,
};
}
public static function byCountryCode(string $countryCode, bool $sandbox = false): self
{
// UK and GB are both common country codes for the United Kingdom
$marketplace = $countryCode === 'UK'
? Marketplace::GB
: Marketplace::fromCountryCode($countryCode);
return self::byMarketplaceId($marketplace, $sandbox);
}
public static function byRegion(string|Region $region, bool $sandbox = false): self
{
if (is_string($region)) {
$region = Region::from($region);
}
return match ($region) {
Region::NA => $sandbox ? self::NA_SANDBOX : self::NA,
Region::EU => $sandbox ? self::EU_SANDBOX : self::EU,
Region::FE => $sandbox ? self::FE_SANDBOX : self::FE,
};
}
}