diff --git a/src/Config/ConnectorInterface.php b/src/Config/ConnectorInterface.php index 47acd03..51f96aa 100644 --- a/src/Config/ConnectorInterface.php +++ b/src/Config/ConnectorInterface.php @@ -6,5 +6,10 @@ use App\Entity\Domain; interface ConnectorInterface { - public function orderDomain(Domain $domain, bool $acceptConditions, bool $ownerLegalAge, bool $waiveRetractationPeriod): void; + public function orderDomain(Domain $domain, + bool $acceptConditions, + bool $ownerLegalAge, + bool $waiveRetractationPeriod, + bool $dryRyn + ): void; } \ No newline at end of file diff --git a/src/Config/TriggerAction.php b/src/Config/TriggerAction.php index c2b29fe..229fcc6 100644 --- a/src/Config/TriggerAction.php +++ b/src/Config/TriggerAction.php @@ -6,4 +6,5 @@ namespace App\Config; enum TriggerAction: string { case SendEmail = 'email'; + case BuyDomain = 'buy'; } diff --git a/src/Entity/OVHConnector.php b/src/Entity/OVHConnector.php index b369962..2245a4d 100644 --- a/src/Entity/OVHConnector.php +++ b/src/Entity/OVHConnector.php @@ -13,10 +13,18 @@ class OVHConnector extends Connector implements ConnectorInterface { /** + * Order a domain name with the OVH API * @throws Exception */ - public function orderDomain(Domain $domain, bool $acceptConditions, bool $ownerLegalAge, bool $waiveRetractationPeriod): void + public function orderDomain(Domain $domain, + bool $acceptConditions, + bool $ownerLegalAge, + bool $waiveRetractationPeriod, + bool $dryRyn = false + ): void { + if (!$domain->getDeleted()) throw new Exception('The domain name still appears in the WHOIS database.'); + $ldhName = $domain->getLdhName(); if (!$ldhName) throw new Exception("Domain name cannot be null."); @@ -83,11 +91,11 @@ class OVHConnector extends Connector implements ConnectorInterface ]); } $conn->get("/order/cart/{$cartId}/checkout"); - /* + + if ($dryRyn) return; $conn->post("/order/cart/{$cartId}/checkout", [ "autoPayWithPreferredPaymentMethod" => true, "waiveRetractationPeriod" => $waiveRetractationPeriod ]); - */ } } \ No newline at end of file diff --git a/src/MessageHandler/ProcessDomainTriggerHandler.php b/src/MessageHandler/ProcessDomainTriggerHandler.php index 660403d..93b8477 100644 --- a/src/MessageHandler/ProcessDomainTriggerHandler.php +++ b/src/MessageHandler/ProcessDomainTriggerHandler.php @@ -5,6 +5,7 @@ namespace App\MessageHandler; use App\Config\TriggerAction; use App\Entity\Domain; use App\Entity\DomainEvent; +use App\Entity\OVHConnector; use App\Entity\User; use App\Entity\WatchList; use App\Entity\WatchListTrigger; @@ -53,6 +54,13 @@ final readonly class ProcessDomainTriggerHandler switch ($watchListTrigger->getAction()) { case TriggerAction::SendEmail: $this->sendEmailDomainUpdated($event, $watchList->getUser()); + break; + case TriggerAction::BuyDomain : + if ($watchListTrigger->getConnector() === null) throw new Exception('Connector is missing'); + $connector = $watchListTrigger->getConnector(); + if ($connector::class === OVHConnector::class) { + $connector->orderDomain($domain, true, true, true, true); + } } } }