2025-09-15 20:37:53 +02:00
|
|
|
<?php
|
|
|
|
|
|
2025-10-27 21:57:08 +01:00
|
|
|
namespace App\Service\Provider;
|
2025-09-15 20:37:53 +02:00
|
|
|
|
|
|
|
|
use App\Dto\Connector\DefaultProviderDto;
|
|
|
|
|
use App\Dto\Connector\OpenProviderProviderDto;
|
|
|
|
|
use App\Entity\Domain;
|
2025-10-27 23:36:48 +01:00
|
|
|
use App\Exception\Provider\DomainOrderFailedExeption;
|
|
|
|
|
use App\Exception\Provider\InvalidLoginException;
|
2025-09-15 20:37:53 +02:00
|
|
|
use Psr\Cache\CacheItemInterface;
|
|
|
|
|
use Psr\Cache\CacheItemPoolInterface;
|
|
|
|
|
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
|
|
|
|
|
use Symfony\Component\HttpClient\HttpOptions;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
|
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
|
|
|
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
|
|
|
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
|
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
|
|
|
|
|
|
#[Autoconfigure(public: true)]
|
|
|
|
|
class OpenProviderProvider extends AbstractProvider
|
|
|
|
|
{
|
|
|
|
|
protected string $dtoClass = OpenProviderProviderDto::class;
|
|
|
|
|
|
|
|
|
|
/** @var OpenProviderProviderDto */
|
|
|
|
|
protected DefaultProviderDto $authData;
|
|
|
|
|
|
2025-10-27 23:36:48 +01:00
|
|
|
private const string BASE_URL = 'https://api.openprovider.eu';
|
2025-09-15 20:37:53 +02:00
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
CacheItemPoolInterface $cacheItemPool,
|
|
|
|
|
private readonly HttpClientInterface $client,
|
|
|
|
|
DenormalizerInterface&NormalizerInterface $serializer,
|
|
|
|
|
ValidatorInterface $validator,
|
|
|
|
|
) {
|
|
|
|
|
parent::__construct($cacheItemPool, $serializer, $validator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Order a domain name with the Open Provider API.
|
|
|
|
|
*
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
* @throws TransportExceptionInterface
|
|
|
|
|
* @throws DecodingExceptionInterface
|
|
|
|
|
*/
|
|
|
|
|
public function orderDomain(Domain $domain, bool $dryRun = false): void
|
|
|
|
|
{
|
|
|
|
|
$ldhName = $domain->getLdhName();
|
|
|
|
|
if (!$ldhName) {
|
|
|
|
|
throw new \InvalidArgumentException('Domain name cannot be null');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$payload = [
|
2025-10-27 23:36:48 +01:00
|
|
|
'accept_eap_fee' => 0,
|
|
|
|
|
'accept_premium_fee' => 0,
|
|
|
|
|
// additional_data
|
2025-09-15 20:37:53 +02:00
|
|
|
'admin_handle' => $this->authData->adminHandle,
|
2025-10-27 23:36:48 +01:00
|
|
|
// application_mode
|
|
|
|
|
// application_notice_id
|
|
|
|
|
// application_smd
|
|
|
|
|
// auth_code
|
|
|
|
|
'autorenew' => 'default',
|
2025-09-15 20:37:53 +02:00
|
|
|
'billing_handle' => $this->authData->billingHandle,
|
2025-10-27 23:36:48 +01:00
|
|
|
'comments' => 'Ordered with Domain Watchdog',
|
|
|
|
|
// dnssec_keys
|
2025-09-15 20:37:53 +02:00
|
|
|
'domain' => [
|
|
|
|
|
'name' => explode('.', $domain->getLdhName(), 2)[0],
|
|
|
|
|
'extension' => explode('.', $domain->getLdhName(), 2)[1],
|
|
|
|
|
],
|
2025-10-27 23:36:48 +01:00
|
|
|
// is_dnssec_enabled
|
|
|
|
|
// is_easy_dmarc_enabled
|
|
|
|
|
// is_private_whois_enabled
|
|
|
|
|
// is_sectigo_dns_enabled
|
|
|
|
|
// is_spamexperts_enabled
|
|
|
|
|
// name_servers
|
2025-09-15 20:37:53 +02:00
|
|
|
'ns_group' => $this->authData->nsGroup,
|
2025-10-27 23:36:48 +01:00
|
|
|
// ns_template_id
|
|
|
|
|
// ns_template_name
|
|
|
|
|
'owner_handle' => $this->authData->ownerHandle,
|
|
|
|
|
'period' => $this->authData->period,
|
|
|
|
|
// promo_code
|
|
|
|
|
// provider
|
|
|
|
|
'tech_handle' => $this->authData->techHandle,
|
|
|
|
|
// unit
|
|
|
|
|
// use_domicile
|
2025-09-15 20:37:53 +02:00
|
|
|
];
|
|
|
|
|
|
2025-10-27 23:56:06 +01:00
|
|
|
if (!empty($this->authData->resellerHandle)) {
|
2025-09-15 20:37:53 +02:00
|
|
|
$payload['resellerHandle'] = $this->authData->resellerHandle;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-27 23:36:48 +01:00
|
|
|
if ($dryRun) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$res = $this->client->request('POST', '/v1beta/domain', (new HttpOptions())
|
2025-09-15 20:37:53 +02:00
|
|
|
->setAuthBearer($this->authData->token)
|
|
|
|
|
->setHeader('Accept', 'application/json')
|
|
|
|
|
->setBaseUri(self::BASE_URL)
|
|
|
|
|
->setJson($payload)->toArray());
|
|
|
|
|
|
2025-10-27 23:36:48 +01:00
|
|
|
if (Response::HTTP_OK !== $res->getStatusCode()) {
|
|
|
|
|
throw new DomainOrderFailedExeption($res->toArray()['message']);
|
2025-09-15 20:37:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws TransportExceptionInterface
|
2025-10-27 23:36:48 +01:00
|
|
|
* @throws InvalidLoginException
|
2025-09-15 20:37:53 +02:00
|
|
|
*/
|
|
|
|
|
protected function assertAuthentication(): void
|
|
|
|
|
{
|
2025-10-27 23:36:48 +01:00
|
|
|
$response = $this->client->request('GET', '/v1beta/customers', (new HttpOptions())
|
2025-09-15 20:37:53 +02:00
|
|
|
->setAuthBearer($this->authData->token)
|
|
|
|
|
->setBaseUri(self::BASE_URL)
|
|
|
|
|
->toArray()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (Response::HTTP_OK !== $response->getStatusCode()) {
|
2025-10-27 23:36:48 +01:00
|
|
|
throw new InvalidLoginException();
|
2025-09-15 20:37:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getSupportedTldList(): array
|
|
|
|
|
{
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-27 23:56:06 +01:00
|
|
|
public function isSupported(Domain ...$domainList): bool
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-15 20:37:53 +02:00
|
|
|
/**
|
|
|
|
|
* @throws \Psr\Cache\InvalidArgumentException
|
|
|
|
|
*/
|
|
|
|
|
protected function getCachedTldList(): CacheItemInterface
|
|
|
|
|
{
|
|
|
|
|
return $this->cacheItemPool->getItem('app.provider.openprovider.supported-tld');
|
|
|
|
|
}
|
|
|
|
|
}
|