feat: add sendEmailDomainOrderError

This commit is contained in:
Maël Gangloff 2024-07-29 20:29:12 +02:00
parent 33f531a5bf
commit 3a9f22318f
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
2 changed files with 114 additions and 15 deletions

View File

@ -21,6 +21,7 @@ use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler; use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Mime\Email; use Symfony\Component\Mime\Email;
use Throwable;
#[AsMessageHandler] #[AsMessageHandler]
final readonly class ProcessDomainTriggerHandler final readonly class ProcessDomainTriggerHandler
@ -54,24 +55,27 @@ final readonly class ProcessDomainTriggerHandler
if ($watchListTrigger->getAction() === TriggerAction::BuyDomain) { if ($watchListTrigger->getAction() === TriggerAction::BuyDomain) {
if ($watchListTrigger->getConnector() === null) throw new Exception('Connector is missing'); try {
if ($watchListTrigger->getConnector() === null) throw new Exception('Connector is missing');
$connector = $watchListTrigger->getConnector();
$connector = $watchListTrigger->getConnector(); if ($connector->getProvider() === ConnectorProvider::OVH) {
$ovh = new OVHConnector($connector->getAuthData());
$isDebug = $this->kernel->isDebug();
if ($connector->getProvider() === ConnectorProvider::OVH) {
$ovh = new OVHConnector($connector->getAuthData());
$isDebug = $this->kernel->isDebug();
$ovh->orderDomain( $ovh->orderDomain(
$domain, $domain,
true, true,
true, true,
true, true,
$isDebug $isDebug
); );
$this->sendEmailDomainOrdered($domain, $connector, $watchList->getUser()); $this->sendEmailDomainOrdered($domain, $connector, $watchList->getUser());
} else throw new Exception("Unknown provider");
} else throw new Exception("Unknown provider"); } catch (Throwable) {
$this->sendEmailDomainOrderError($domain, $watchList->getUser());
}
} }
/** @var DomainEvent $event */ /** @var DomainEvent $event */
@ -103,6 +107,24 @@ final readonly class ProcessDomainTriggerHandler
$this->mailer->send($email); $this->mailer->send($email);
} }
/**
* @throws TransportExceptionInterface
*/
private function sendEmailDomainOrderError(Domain $domain, User $user): void
{
$email = (new TemplatedEmail())
->from($this->mailerSenderEmail)
->to($user->getEmail())
->subject('An error occurred while ordering a domain name')
->htmlTemplate('emails/errors/domain_order.html.twig')
->locale('en')
->context([
"domain" => $domain
]);
$this->mailer->send($email);
}
/** /**
* @throws TransportExceptionInterface * @throws TransportExceptionInterface
*/ */

View File

@ -0,0 +1,77 @@
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #f9f9f9;
}
.header {
text-align: center;
margin-bottom: 20px;
}
.header h1 {
font-size: 24px;
color: #d9534f;
}
.content {
margin-bottom: 20px;
}
.content p {
margin: 0 0 10px;
}
.footer {
text-align: center;
color: #777;
}
ul {
padding-left: 20px;
}
ul li {
margin-bottom: 10px;
}
</style>
<title>Domain Watchdog Error</title>
</head>
<body>
<div class="container">
<div class="header">
<h1>Domain Watchdog Error</h1>
</div>
<div class="content">
<p>Hello,</p>
<p>We would like to inform you that an error occurred while ordering the following domain name:</p>
<p><strong>Domain name:</strong> {{ domain.ldhName }}</p>
<p>Here are some possible explanations:</p>
<ul>
<li>The Connector configuration you provided is no longer valid.</li>
<li>It is likely that the domain is no longer available for registration.</li>
<li>A temporary interruption is affecting the registration of this domain name.</li>
</ul>
<p>Thank you for your understanding,</p>
<p>Sincerely,</p>
<p>Domain Watchdog</p>
</div>
<div class="footer">
<p>&copy; Domain Watchdog</p>
</div>
</div>
</body>
</html>