feat: get supported tlds by namecheap

This commit is contained in:
Vincent
2024-09-25 14:03:16 +02:00
parent f0e708272e
commit f70ddb6b05

View File

@@ -4,6 +4,7 @@ namespace App\Service\Connector;
use App\Entity\Domain; use App\Entity\Domain;
use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure; use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -14,8 +15,9 @@ class NamecheapConnector extends AbstractProvider
public const SANDBOX_BASE_URL = 'http://api.sandbox.namecheap.com/xml.response'; public const SANDBOX_BASE_URL = 'http://api.sandbox.namecheap.com/xml.response';
public function __construct(private HttpClientInterface $client, private readonly string $outgoingIp) public function __construct(CacheItemPoolInterface $cacheItemPool, private HttpClientInterface $client, private readonly string $outgoingIp)
{ {
parent::__construct($cacheItemPool);
} }
public function orderDomain(Domain $domain, $dryRun): void public function orderDomain(Domain $domain, $dryRun): void
@@ -27,8 +29,8 @@ class NamecheapConnector extends AbstractProvider
throw new \Exception('Namecheap account requires at least one address to purchase a domain'); throw new \Exception('Namecheap account requires at least one address to purchase a domain');
} }
$addressId = (string) $addresses->attributes()['AddressId']; $addressId = (string)$addresses->attributes()['AddressId'];
$address = (array) $this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId], $dryRun)->GetAddressInfoResult; $address = (array)$this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId], $dryRun)->GetAddressInfoResult;
if (empty($address['PostalCode'])) { if (empty($address['PostalCode'])) {
$address['PostalCode'] = $address['Zip']; $address['PostalCode'] = $address['Zip'];
@@ -52,7 +54,7 @@ class NamecheapConnector extends AbstractProvider
private static function mergePrefixKeys(string $prefix, array|object $src, array &$dest) private static function mergePrefixKeys(string $prefix, array|object $src, array &$dest)
{ {
foreach ($src as $key => $value) { foreach ($src as $key => $value) {
$dest[$prefix.$key] = $value; $dest[$prefix . $key] = $value;
} }
} }
@@ -86,11 +88,19 @@ class NamecheapConnector extends AbstractProvider
protected function getCachedTldList(): CacheItemInterface protected function getCachedTldList(): CacheItemInterface
{ {
// TODO: Implement getCachedTldList() method. return $this->cacheItemPool->getItem('app.provider.namecheap.supported-tld');
} }
protected function getSupportedTldList(): array protected function getSupportedTldList(): array
{ {
// TODO: Implement getSupportedTldList() method. $supported = [];
$tlds = $this->call('namecheap.domains.gettldlist', [], false)->Tlds->Tld;
for ($i = 0; $i < $tlds->count(); ++$i) {
$supported[] = (string) $tlds[$i]['Name'];
}
return $supported;
} }
} }