2024-07-28 23:05:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
2024-07-28 23:39:38 +02:00
|
|
|
use App\Config\ConnectorInterface;
|
2024-07-29 03:27:55 +02:00
|
|
|
use App\Repository\OVHConnectorRepository;
|
2024-07-28 23:05:41 +02:00
|
|
|
use Doctrine\ORM\Mapping\Entity;
|
2024-07-29 03:27:55 +02:00
|
|
|
use Exception;
|
|
|
|
|
use Ovh\Api;
|
2024-07-28 23:05:41 +02:00
|
|
|
|
2024-07-29 03:27:55 +02:00
|
|
|
#[Entity(repositoryClass: OVHConnectorRepository::class)]
|
2024-07-28 23:39:38 +02:00
|
|
|
class OVHConnector extends Connector implements ConnectorInterface
|
2024-07-28 23:05:41 +02:00
|
|
|
{
|
2024-07-28 23:39:38 +02:00
|
|
|
|
2024-07-29 03:27:55 +02:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
]);
|
|
|
|
|
*/
|
|
|
|
|
}
|
2024-07-28 23:05:41 +02:00
|
|
|
}
|