mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-17 17:55:42 +00:00
feat: domain order call
a bisto de nas
This commit is contained in:
parent
f225213c49
commit
700e531e22
@ -73,7 +73,8 @@
|
||||
"symfony/yaml": "7.1.*",
|
||||
"symfonycasts/verify-email-bundle": "*",
|
||||
"twig/extra-bundle": "^2.12|^3.0",
|
||||
"twig/twig": "^2.12|^3.0"
|
||||
"twig/twig": "^2.12|^3.0",
|
||||
"ext-simplexml": "*"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
|
||||
@ -1,35 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Connector;
|
||||
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use App\Entity\Domain;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class NamecheapConnector implements ConnectorInterface
|
||||
readonly class NamecheapConnector implements ConnectorInterface
|
||||
{
|
||||
public const BASE_URL = 'https://api.namecheap.com/xml.response';
|
||||
|
||||
const BASE_URL = 'https://api.namecheap.com/xml.response';
|
||||
|
||||
const SANDBOX_BASE_URL = 'http://www.sandbox.namecheap.com';
|
||||
public const SANDBOX_BASE_URL = 'http://api.sandbox.namecheap.com/xml.response';
|
||||
|
||||
public function __construct(private array $authData, private HttpClientInterface $client)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
public function orderDomain(Domain $domain, $dryRun): void
|
||||
{}
|
||||
{
|
||||
$addresses = $this->call('namecheap.users.address.getList');
|
||||
|
||||
private function call(string $command, array $parameters, array $authData = null): object
|
||||
if (count($addresses) < 1) {
|
||||
throw new \Exception('Namecheap account requires at least one address to purchase a domain');
|
||||
}
|
||||
|
||||
$addressId = $addresses->{0}->AddressId;
|
||||
$address = $this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId]);
|
||||
|
||||
$domainAddresses = [];
|
||||
|
||||
self::mergePrefixKeys('Registrant', $address, $domainAddresses);
|
||||
self::mergePrefixKeys('Tech', $address, $domainAddresses);
|
||||
self::mergePrefixKeys('Admin', $address, $domainAddresses);
|
||||
self::mergePrefixKeys('AuxBilling', $address, $domainAddresses);
|
||||
|
||||
$this->call('namecheap.domains.create', array_merge([
|
||||
'DomainName' => $domain->getLdhName(),
|
||||
'Years' => 1,
|
||||
'AddFreeWhoisguard' => 'yes',
|
||||
'WGEnabled' => 'yes',
|
||||
], $domainAddresses));
|
||||
}
|
||||
|
||||
private static function mergePrefixKeys(string $prefix, array|object $src, array &$dest)
|
||||
{
|
||||
foreach ($src as $key => $value) {
|
||||
$dest[$prefix.$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
private function call(string $command, array $parameters = [], ?array $authData = null): object
|
||||
{
|
||||
if (is_null($authData)) {
|
||||
$authData = $this->authData;
|
||||
}
|
||||
|
||||
$actualParams = array_merge([
|
||||
'Command' => $command,
|
||||
'ApiUser' => $authData['ApiUser'],
|
||||
'ApiKey' => $authData['ApiKey']
|
||||
'ApiKey' => $authData['ApiKey'],
|
||||
'ClientIp' => '', // TODO DW instance IP envvar
|
||||
], $parameters);
|
||||
|
||||
$response = $this->client->request('POST', BASE_URL, [
|
||||
'query' => $actualParams
|
||||
$response = $this->client->request('POST', self::BASE_URL, [
|
||||
'query' => $actualParams,
|
||||
]);
|
||||
|
||||
$data = new \SimpleXMLElement($response->getContent());
|
||||
@ -45,4 +78,3 @@ class NamecheapConnector implements ConnectorInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user