mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: start webhook support
This commit is contained in:
49
src/Notifier/DomainOrderNotification.php
Normal file
49
src/Notifier/DomainOrderNotification.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifier;
|
||||
|
||||
use App\Entity\Connector;
|
||||
use App\Entity\Domain;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Notifier\Message\ChatMessage;
|
||||
use Symfony\Component\Notifier\Message\EmailMessage;
|
||||
use Symfony\Component\Notifier\Notification\ChatNotificationInterface;
|
||||
use Symfony\Component\Notifier\Notification\EmailNotificationInterface;
|
||||
use Symfony\Component\Notifier\Notification\Notification;
|
||||
use Symfony\Component\Notifier\Recipient\EmailRecipientInterface;
|
||||
use Symfony\Component\Notifier\Recipient\RecipientInterface;
|
||||
|
||||
class DomainOrderNotification extends Notification implements ChatNotificationInterface, EmailNotificationInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Address $sender,
|
||||
private readonly Domain $domain,
|
||||
private readonly Connector $connector
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
|
||||
{
|
||||
$this->subject('Domain Ordered');
|
||||
|
||||
return ChatMessage::fromNotification($this);
|
||||
}
|
||||
|
||||
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): EmailMessage
|
||||
{
|
||||
return new EmailMessage((new TemplatedEmail())
|
||||
->from($this->sender)
|
||||
->to($recipient->getEmail())
|
||||
->priority(Email::PRIORITY_HIGHEST)
|
||||
->subject('A domain name has been ordered')
|
||||
->htmlTemplate('emails/success/domain_ordered.html.twig')
|
||||
->locale('en')
|
||||
->context([
|
||||
'domain' => $this->domain,
|
||||
'provider' => $this->connector->getProvider()->value,
|
||||
]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user