feat: start ovh API implement

This commit is contained in:
Maël Gangloff
2024-07-29 11:54:47 +02:00
parent 06182dc236
commit e744bbcef0
4 changed files with 26 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -6,4 +6,5 @@ namespace App\Config;
enum TriggerAction: string
{
case SendEmail = 'email';
case BuyDomain = 'buy';
}

View File

@@ -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
]);
*/
}
}

View File

@@ -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);
}
}
}
}