diff --git a/src/Dto/Connector/OpenProviderProviderDto.php b/src/Dto/Connector/OpenProviderProviderDto.php new file mode 100644 index 0000000..cdb6743 --- /dev/null +++ b/src/Dto/Connector/OpenProviderProviderDto.php @@ -0,0 +1,34 @@ +getLdhName(); + if (!$ldhName) { + throw new \InvalidArgumentException('Domain name cannot be null'); + } + + $payload = [ + 'admin_handle' => $this->authData->adminHandle, + 'billing_handle' => $this->authData->billingHandle, + 'owner_handle' => $this->authData->ownerHandle, + 'tech_handle' => $this->authData->techHandle, + 'domain' => [ + 'name' => explode('.', $domain->getLdhName(), 2)[0], + 'extension' => explode('.', $domain->getLdhName(), 2)[1], + ], + 'period' => '1', + 'ns_group' => $this->authData->nsGroup, + 'autorenew' => 'default', + ]; + + if (null !== $this->authData->resellerHandle) { + $payload['resellerHandle'] = $this->authData->resellerHandle; + } + + $res = $this->client->request('POST', '/domain', (new HttpOptions()) + ->setAuthBearer($this->authData->token) + ->setHeader('Accept', 'application/json') + ->setBaseUri(self::BASE_URL) + ->setJson($payload)->toArray()); + + if ((!$dryRun && Response::HTTP_ACCEPTED !== $res->getStatusCode()) + || ($dryRun && Response::HTTP_OK !== $res->getStatusCode())) { + throw new HttpException($res->toArray()['message']); + } + } + + /** + * @throws TransportExceptionInterface + */ + protected function assertAuthentication(): void + { + $response = $this->client->request('GET', '/customers', (new HttpOptions()) + ->setAuthBearer($this->authData->token) + ->setHeader('Accept', 'application/json') + ->setBaseUri(self::BASE_URL) + ->toArray() + ); + + if (Response::HTTP_OK !== $response->getStatusCode()) { + throw new BadRequestHttpException('The status of these credentials is not valid'); + } + } + + protected function getSupportedTldList(): array + { + return []; + } + + /** + * @throws \Psr\Cache\InvalidArgumentException + */ + protected function getCachedTldList(): CacheItemInterface + { + return $this->cacheItemPool->getItem('app.provider.openprovider.supported-tld'); + } +} diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index 64446d5..9f16528 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -34,6 +34,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpClient\Exception\ClientException; use Symfony\Component\HttpFoundation\Exception\BadRequestException; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Yaml\Yaml; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; @@ -264,7 +265,7 @@ class RDAPService private function handleRdapException(\Exception $e, string $idnDomain, ?Domain $domain, ?ResponseInterface $response): \Exception { if ( - ($e instanceof ClientException && 404 === $e->getResponse()->getStatusCode()) + ($e instanceof ClientException && Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) || ($e instanceof TransportExceptionInterface && null !== $response && !in_array('content-length', $response->getHeaders(false)) && 404 === $response->getStatusCode()) ) { if (null !== $domain) {