mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-18 10:15:41 +00:00
feat: EPP order domain
This commit is contained in:
parent
7048d8d22b
commit
bebd3f81e5
@ -94,8 +94,6 @@ final readonly class OrderDomainHandler
|
||||
* If no errors occur, the purchase is attempted.
|
||||
*/
|
||||
|
||||
$connectorProvider->authenticate($connector->getAuthData());
|
||||
|
||||
$connectorProvider->orderDomain($domain, $this->kernel->isDebug());
|
||||
|
||||
/*
|
||||
|
||||
@ -8,12 +8,23 @@ use App\Message\OrderDomain;
|
||||
use App\Message\SendDomainEventNotif;
|
||||
use App\Message\UpdateDomainsFromWatchlist;
|
||||
use App\Notifier\DomainDeletedNotification;
|
||||
use App\Notifier\DomainOrderErrorNotification;
|
||||
use App\Notifier\DomainOrderNotification;
|
||||
use App\Notifier\DomainUpdateErrorNotification;
|
||||
use App\Repository\WatchListRepository;
|
||||
use App\Service\ChatNotificationService;
|
||||
use App\Service\Connector\AbstractProvider;
|
||||
use App\Service\Connector\CheckDomainProviderInterface;
|
||||
use App\Service\Connector\EppClientProvider;
|
||||
use App\Service\InfluxdbService;
|
||||
use App\Service\RDAPService;
|
||||
use App\Service\StatService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
@ -40,6 +51,14 @@ final readonly class UpdateDomainsFromWatchlistHandler
|
||||
private MessageBusInterface $bus,
|
||||
private WatchListRepository $watchListRepository,
|
||||
private LoggerInterface $logger,
|
||||
#[Autowire(service: 'service_container')]
|
||||
private ContainerInterface $locator,
|
||||
private EntityManagerInterface $em,
|
||||
private KernelInterface $kernel,
|
||||
private StatService $statService,
|
||||
private InfluxdbService $influxdbService,
|
||||
#[Autowire(param: 'influxdb_enabled')]
|
||||
private bool $influxdbEnabled,
|
||||
) {
|
||||
$this->sender = new Address($mailerSenderEmail, $mailerSenderName);
|
||||
}
|
||||
@ -63,6 +82,73 @@ final readonly class UpdateDomainsFromWatchlistHandler
|
||||
'token' => $message->watchListToken,
|
||||
]);
|
||||
|
||||
$connector = $watchList->getConnector();
|
||||
|
||||
if (null !== $connector && null !== $connector->getProvider()) {
|
||||
$provider = $connector->getProvider();
|
||||
$connectorProviderClass = $provider->getConnectorProvider();
|
||||
/** @var AbstractProvider $connectorProvider */
|
||||
/** @var EppClientProvider $connectorProvider */
|
||||
$connectorProvider = $this->locator->get($connectorProviderClass);
|
||||
}
|
||||
|
||||
if (isset($connectorProvider) && $connectorProvider instanceof CheckDomainProviderInterface) {
|
||||
$this->logger->notice('Watchlist {watchlist} is linked to connector {connector}.', [
|
||||
'watchlist' => $message->watchListToken,
|
||||
'connector' => $connector->getId(),
|
||||
]);
|
||||
|
||||
try {
|
||||
$checkedDomains = $connectorProvider->checkDomains(
|
||||
...array_unique(array_map(fn (Domain $d) => $d->getLdhName(), $watchList->getDomains()->toArray()))
|
||||
);
|
||||
} catch (\Throwable $exception) {
|
||||
$this->logger->warning('Unable to check domain names availability with connector {connector}.', [
|
||||
'connector' => $connector->getId(),
|
||||
]);
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
foreach ($checkedDomains as $domain) {
|
||||
try {
|
||||
$connectorProvider->orderDomain($this->em->getReference(Domain::class, $domain), $this->kernel->isDebug());
|
||||
|
||||
$this->logger->notice('Watchlist {watchlist} is linked to connector {connector}. A purchase was successfully made for domain {ldhName}.', [
|
||||
'watchlist' => $message->watchListToken,
|
||||
'connector' => $connector->getId(),
|
||||
'ldhName' => $domain,
|
||||
]);
|
||||
|
||||
// TODO : remove dupcode
|
||||
$this->statService->incrementStat('stats.domain.purchased');
|
||||
if ($this->influxdbEnabled) {
|
||||
$this->influxdbService->addDomainOrderPoint($connector, $domain, true);
|
||||
}
|
||||
$notification = (new DomainOrderNotification($this->sender, $domain, $connector));
|
||||
$this->mailer->send($notification->asEmailMessage(new Recipient($watchList->getUser()->getEmail()))->getMessage());
|
||||
$this->chatNotificationService->sendChatNotification($watchList, $notification);
|
||||
} catch (\Throwable $exception) {
|
||||
// TODO : remove dupcode
|
||||
$this->logger->warning('Unable to complete purchase. An error message is sent to user {username}.', [
|
||||
'username' => $watchList->getUser()->getUserIdentifier(),
|
||||
]);
|
||||
|
||||
$this->statService->incrementStat('stats.domain.purchase.failed');
|
||||
if ($this->influxdbEnabled) {
|
||||
$this->influxdbService->addDomainOrderPoint($connector, $domain, false);
|
||||
}
|
||||
$notification = (new DomainOrderErrorNotification($this->sender, $domain));
|
||||
$this->mailer->send($notification->asEmailMessage(new Recipient($watchList->getUser()->getEmail()))->getMessage());
|
||||
$this->chatNotificationService->sendChatNotification($watchList, $notification);
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* A domain name is updated if one or more of these conditions are met:
|
||||
* - was updated more than 7 days ago
|
||||
@ -89,7 +175,7 @@ final readonly class UpdateDomainsFromWatchlistHandler
|
||||
$this->chatNotificationService->sendChatNotification($watchList, $notification);
|
||||
}
|
||||
|
||||
if (null !== $watchList->getConnector()) {
|
||||
if (null !== $connector) {
|
||||
/*
|
||||
* If the domain name no longer appears in the WHOIS AND a connector is associated with this Watchlist,
|
||||
* this connector is used to purchase the domain name.
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Service\Connector;
|
||||
|
||||
interface EppClientProviderInterface
|
||||
interface CheckDomainProviderInterface
|
||||
{
|
||||
public function checkDomains(string ...$domains): array;
|
||||
}
|
||||
@ -15,7 +15,7 @@ use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
|
||||
class EppClientProvider extends AbstractProvider implements EppClientProviderInterface
|
||||
class EppClientProvider extends AbstractProvider implements CheckDomainProviderInterface
|
||||
{
|
||||
private eppConnection $eppClient;
|
||||
|
||||
@ -62,7 +62,9 @@ class EppClientProvider extends AbstractProvider implements EppClientProviderInt
|
||||
$d->addContact(new eppContactHandle($contact, $type));
|
||||
}
|
||||
|
||||
$this->eppClient->request(new eppCreateDomainRequest($d));
|
||||
if (!$dryRun) {
|
||||
$this->eppClient->request(new eppCreateDomainRequest($d));
|
||||
}
|
||||
|
||||
$this->eppClient->logout();
|
||||
$this->eppClient->disconnect();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user