mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
fix: XML traversal, container autowire
This commit is contained in:
@@ -12,8 +12,11 @@ use App\Entity\WatchListTrigger;
|
|||||||
use App\Message\ProcessDomainTrigger;
|
use App\Message\ProcessDomainTrigger;
|
||||||
use App\Repository\DomainRepository;
|
use App\Repository\DomainRepository;
|
||||||
use App\Repository\WatchListRepository;
|
use App\Repository\WatchListRepository;
|
||||||
|
use App\Service\Connector\ConnectorInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\HttpKernel\KernelInterface;
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Component\Mailer\MailerInterface;
|
use Symfony\Component\Mailer\MailerInterface;
|
||||||
@@ -21,8 +24,6 @@ use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
|||||||
use Symfony\Component\Mime\Address;
|
use Symfony\Component\Mime\Address;
|
||||||
use Symfony\Component\Mime\Email;
|
use Symfony\Component\Mime\Email;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
use App\Service\Connector\ConnectorInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
|
|
||||||
|
|
||||||
#[AsMessageHandler]
|
#[AsMessageHandler]
|
||||||
final readonly class ProcessDomainTriggerHandler
|
final readonly class ProcessDomainTriggerHandler
|
||||||
@@ -36,7 +37,8 @@ final readonly class ProcessDomainTriggerHandler
|
|||||||
private KernelInterface $kernel,
|
private KernelInterface $kernel,
|
||||||
private LoggerInterface $logger,
|
private LoggerInterface $logger,
|
||||||
private HttpClientInterface $client,
|
private HttpClientInterface $client,
|
||||||
private ContainerBagInterface $container
|
#[Autowire(service: 'service_container')]
|
||||||
|
private ContainerInterface $locator
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,12 +70,14 @@ final readonly class ProcessDomainTriggerHandler
|
|||||||
$connectorProviderClass = $provider->getConnectorProvider();
|
$connectorProviderClass = $provider->getConnectorProvider();
|
||||||
|
|
||||||
/** @var ConnectorInterface $connectorProvider */
|
/** @var ConnectorInterface $connectorProvider */
|
||||||
$connectorProvider = $this->container->get($connectorProviderClass);
|
$connectorProvider = $this->locator->get($connectorProviderClass);
|
||||||
|
|
||||||
$connectorProvider->orderDomain($domain, $this->kernel->isDebug());
|
$connectorProvider->authenticate($connector->getAuthData());
|
||||||
|
$connectorProvider->orderDomain($domain, /* $this->kernel->isDebug() */ false);
|
||||||
|
|
||||||
$this->sendEmailDomainOrdered($domain, $connector, $watchList->getUser());
|
$this->sendEmailDomainOrdered($domain, $connector, $watchList->getUser());
|
||||||
} catch (\Throwable $t) {
|
} catch (\Throwable $t) {
|
||||||
|
dump($t);
|
||||||
$this->logger->error('Unable to complete purchase. An error message is sent to user {username}.', [
|
$this->logger->error('Unable to complete purchase. An error message is sent to user {username}.', [
|
||||||
'username' => $watchList->getUser()->getUserIdentifier(),
|
'username' => $watchList->getUser()->getUserIdentifier(),
|
||||||
'error' => $t,
|
'error' => $t,
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
namespace App\Service\Connector;
|
namespace App\Service\Connector;
|
||||||
|
|
||||||
use App\Entity\Domain;
|
use App\Entity\Domain;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
|
#[Autoconfigure(public: true)]
|
||||||
class NamecheapConnector extends AbstractConnector
|
class NamecheapConnector extends AbstractConnector
|
||||||
{
|
{
|
||||||
public const BASE_URL = 'https://api.namecheap.com/xml.response';
|
public const BASE_URL = 'https://api.namecheap.com/xml.response';
|
||||||
@@ -17,14 +19,19 @@ class NamecheapConnector extends AbstractConnector
|
|||||||
|
|
||||||
public function orderDomain(Domain $domain, $dryRun): void
|
public function orderDomain(Domain $domain, $dryRun): void
|
||||||
{
|
{
|
||||||
$addresses = $this->call('namecheap.users.address.getList', [], $dryRun);
|
$addressesRes = $this->call('namecheap.users.address.getList', [], $dryRun);
|
||||||
|
$addresses = $addressesRes->AddressGetListResult->List;
|
||||||
|
|
||||||
if (count($addresses) < 1) {
|
if (count($addresses) < 1) {
|
||||||
throw new \Exception('Namecheap account requires at least one address to purchase a domain');
|
throw new \Exception('Namecheap account requires at least one address to purchase a domain');
|
||||||
}
|
}
|
||||||
|
|
||||||
$addressId = $addresses->{0}->AddressId;
|
$addressId = (string) $addresses->attributes()['AddressId'];
|
||||||
$address = $this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId], $dryRun);
|
$address = (array) $this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId], $dryRun)->GetAddressInfoResult;
|
||||||
|
|
||||||
|
if (empty($address['PostalCode'])) {
|
||||||
|
$address['PostalCode'] = $address['Zip'];
|
||||||
|
}
|
||||||
|
|
||||||
$domainAddresses = [];
|
$domainAddresses = [];
|
||||||
|
|
||||||
@@ -33,6 +40,7 @@ class NamecheapConnector extends AbstractConnector
|
|||||||
self::mergePrefixKeys('Admin', $address, $domainAddresses);
|
self::mergePrefixKeys('Admin', $address, $domainAddresses);
|
||||||
self::mergePrefixKeys('AuxBilling', $address, $domainAddresses);
|
self::mergePrefixKeys('AuxBilling', $address, $domainAddresses);
|
||||||
|
|
||||||
|
|
||||||
$this->call('namecheap.domains.create', array_merge([
|
$this->call('namecheap.domains.create', array_merge([
|
||||||
'DomainName' => $domain->getLdhName(),
|
'DomainName' => $domain->getLdhName(),
|
||||||
'Years' => 1,
|
'Years' => 1,
|
||||||
@@ -52,6 +60,7 @@ class NamecheapConnector extends AbstractConnector
|
|||||||
{
|
{
|
||||||
$actualParams = array_merge([
|
$actualParams = array_merge([
|
||||||
'Command' => $command,
|
'Command' => $command,
|
||||||
|
'UserName' => $this->authData['ApiUser'],
|
||||||
'ApiUser' => $this->authData['ApiUser'],
|
'ApiUser' => $this->authData['ApiUser'],
|
||||||
'ApiKey' => $this->authData['ApiKey'],
|
'ApiKey' => $this->authData['ApiKey'],
|
||||||
'ClientIp' => $this->outgoingIp,
|
'ClientIp' => $this->outgoingIp,
|
||||||
@@ -63,8 +72,8 @@ class NamecheapConnector extends AbstractConnector
|
|||||||
|
|
||||||
$data = new \SimpleXMLElement($response->getContent());
|
$data = new \SimpleXMLElement($response->getContent());
|
||||||
|
|
||||||
if ($data->errors->error) {
|
if ($data->Errors->Error) {
|
||||||
throw new \Exception(implode(', ', $data->errors->error)); // FIXME better exception type
|
throw new \Exception($data->Errors->Error); // FIXME better exception type
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data->CommandResponse;
|
return $data->CommandResponse;
|
||||||
|
|||||||
Reference in New Issue
Block a user