mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: start ovh API implement
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Config;
|
namespace App\Config;
|
||||||
|
|
||||||
|
use App\Entity\Domain;
|
||||||
|
|
||||||
interface ConnectorInterface
|
interface ConnectorInterface
|
||||||
{
|
{
|
||||||
|
public function orderDomain(Domain $domain, bool $acceptConditions, bool $ownerLegalAge, bool $waiveRetractationPeriod): void;
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,6 @@ namespace App\Entity;
|
|||||||
|
|
||||||
use App\Config\ConnectorProvider;
|
use App\Config\ConnectorProvider;
|
||||||
use App\Repository\ConnectorRepository;
|
use App\Repository\ConnectorRepository;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
|
||||||
use Doctrine\Common\Collections\Collection;
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Doctrine\ORM\Mapping\DiscriminatorColumn;
|
use Doctrine\ORM\Mapping\DiscriminatorColumn;
|
||||||
use Doctrine\ORM\Mapping\DiscriminatorMap;
|
use Doctrine\ORM\Mapping\DiscriminatorMap;
|
||||||
@@ -31,17 +29,6 @@ class Connector
|
|||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
private array $authData = [];
|
private array $authData = [];
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Collection<int, WatchListTrigger>
|
|
||||||
*/
|
|
||||||
#[ORM\OneToMany(targetEntity: WatchListTrigger::class, mappedBy: 'connector')]
|
|
||||||
private Collection $watchListTriggers;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->watchListTriggers = new ArrayCollection();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@@ -83,34 +70,4 @@ class Connector
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection<int, WatchListTrigger>
|
|
||||||
*/
|
|
||||||
public function getWatchListTriggers(): Collection
|
|
||||||
{
|
|
||||||
return $this->watchListTriggers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addWatchListTrigger(WatchListTrigger $watchListTrigger): static
|
|
||||||
{
|
|
||||||
if (!$this->watchListTriggers->contains($watchListTrigger)) {
|
|
||||||
$this->watchListTriggers->add($watchListTrigger);
|
|
||||||
$watchListTrigger->setConnector($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeWatchListTrigger(WatchListTrigger $watchListTrigger): static
|
|
||||||
{
|
|
||||||
if ($this->watchListTriggers->removeElement($watchListTrigger)) {
|
|
||||||
// set the owning side to null (unless already changed)
|
|
||||||
if ($watchListTrigger->getConnector() === $this) {
|
|
||||||
$watchListTrigger->setConnector(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,91 @@
|
|||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Config\ConnectorInterface;
|
use App\Config\ConnectorInterface;
|
||||||
|
use App\Repository\OVHConnectorRepository;
|
||||||
use Doctrine\ORM\Mapping\Entity;
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
|
use Exception;
|
||||||
|
use Ovh\Api;
|
||||||
|
|
||||||
#[Entity]
|
#[Entity(repositoryClass: OVHConnectorRepository::class)]
|
||||||
class OVHConnector extends Connector implements ConnectorInterface
|
class OVHConnector extends Connector implements ConnectorInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function orderDomain(Domain $domain, bool $acceptConditions, bool $ownerLegalAge, bool $waiveRetractationPeriod): void
|
||||||
|
{
|
||||||
|
$ldhName = $domain->getLdhName();
|
||||||
|
if (!$ldhName) throw new Exception("Domain name cannot be null.");
|
||||||
|
|
||||||
|
$authData = $this->getAuthData();
|
||||||
|
|
||||||
|
$appKey = $authData['appKey'];
|
||||||
|
$appSecret = $authData['appSecret'];
|
||||||
|
$apiEndpoint = $authData['apiEndpoint'];
|
||||||
|
$consumerKey = $authData['consumerKey'];
|
||||||
|
$ovhSubsidiary = $authData['ovhSubsidiary'];
|
||||||
|
$pricingMode = $authData['pricingMode'];
|
||||||
|
|
||||||
|
if (!$appKey ||
|
||||||
|
!$appSecret ||
|
||||||
|
!$apiEndpoint ||
|
||||||
|
!$consumerKey ||
|
||||||
|
!$ovhSubsidiary ||
|
||||||
|
!$pricingMode
|
||||||
|
) throw new Exception("Auth data cannot be null.");
|
||||||
|
|
||||||
|
$conn = new Api(
|
||||||
|
$appKey,
|
||||||
|
$appSecret,
|
||||||
|
$apiEndpoint,
|
||||||
|
$consumerKey
|
||||||
|
);
|
||||||
|
|
||||||
|
$cart = $conn->post('/order/cart', [
|
||||||
|
"ovhSubsidiary" => $ovhSubsidiary,
|
||||||
|
"description" => "Domain Watchdog"
|
||||||
|
]);
|
||||||
|
$cartId = $cart['cartId'];
|
||||||
|
|
||||||
|
$offers = $conn->get("/order/cart/{$cartId}/domain", [
|
||||||
|
"domain" => $ldhName
|
||||||
|
]);
|
||||||
|
$offer = array_filter($offers, fn($offer) => $offer['action'] === 'create' &&
|
||||||
|
$offer['orderable'] === true &&
|
||||||
|
$offers['pricingMode'] === $pricingMode
|
||||||
|
);
|
||||||
|
if (empty($offer)) throw new Exception('Cannot buy this domain name.');
|
||||||
|
|
||||||
|
$item = $conn->post("/order/cart/{$cartId}/domain", [
|
||||||
|
"domain" => $ldhName,
|
||||||
|
"duration" => "P1Y"
|
||||||
|
]);
|
||||||
|
$itemId = $item['itemId'];
|
||||||
|
|
||||||
|
//$conn->get("/order/cart/{$cartId}/summary");
|
||||||
|
$conn->post("/order/cart/{$cartId}/assign");
|
||||||
|
$conn->get("/order/cart/{$cartId}/item/{$itemId}/requiredConfiguration");
|
||||||
|
|
||||||
|
$configuration = [
|
||||||
|
"ACCEPT_CONDITIONS" => $acceptConditions,
|
||||||
|
"OWNER_LEGAL_AGE" => $ownerLegalAge
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($configuration as $label => $value) {
|
||||||
|
$conn->post("/order/cart/{$cartId}/item/{$itemId}/configuration", [
|
||||||
|
"cartId" => $cartId,
|
||||||
|
"itemId" => $itemId,
|
||||||
|
"label" => $label,
|
||||||
|
"value" => $value
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$conn->get("/order/cart/{$cartId}/checkout");
|
||||||
|
/*
|
||||||
|
$conn->post("/order/cart/{$cartId}/checkout", [
|
||||||
|
"autoPayWithPreferredPaymentMethod" => true,
|
||||||
|
"waiveRetractationPeriod" => $waiveRetractationPeriod
|
||||||
|
]);
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Config\EventAction;
|
|
||||||
use App\Config\TriggerAction;
|
use App\Config\TriggerAction;
|
||||||
use App\Repository\EventTriggerRepository;
|
use App\Repository\EventTriggerRepository;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
@@ -26,9 +25,6 @@ class WatchListTrigger
|
|||||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
||||||
private ?TriggerAction $action = null;
|
private ?TriggerAction $action = null;
|
||||||
|
|
||||||
#[ORM\ManyToOne(inversedBy: 'watchListTriggers')]
|
|
||||||
private ?Connector $connector = null;
|
|
||||||
|
|
||||||
public function getEvent(): ?string
|
public function getEvent(): ?string
|
||||||
{
|
{
|
||||||
return $this->event;
|
return $this->event;
|
||||||
@@ -64,16 +60,4 @@ class WatchListTrigger
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConnector(): ?Connector
|
|
||||||
{
|
|
||||||
return $this->connector;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setConnector(?Connector $connector): static
|
|
||||||
{
|
|
||||||
$this->connector = $connector;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/Repository/OVHConnectorRepository.php
Normal file
21
src/Repository/OVHConnectorRepository.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\OVHConnector;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method OVHConnector|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
|
* @method OVHConnector|null findOneBy(array $criteria, array $orderBy = null)
|
||||||
|
* @method OVHConnector[] findAll()
|
||||||
|
* @method OVHConnector[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||||
|
*/
|
||||||
|
class OVHConnectorRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, OVHConnector::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user