add success email
This commit is contained in:
parent
2ccba65185
commit
def4b27bcd
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Enum;
|
||||
|
||||
|
32
src/Service/TicketEmailService.php
Normal file
32
src/Service/TicketEmailService.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Payment;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Address;
|
||||
|
||||
class TicketEmailService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly MailerInterface $mailer,
|
||||
#[Autowire(env: 'SENDER_MAIL')]
|
||||
private readonly string $senderMail
|
||||
) {
|
||||
}
|
||||
|
||||
public function sendSuccessEmail(Payment $payment): void
|
||||
{
|
||||
$mail = (new TemplatedEmail())
|
||||
->htmlTemplate('email/order.html.twig')
|
||||
->subject('Abiball Ticket')
|
||||
->from(new Address($this->senderMail, 'Noreply'))
|
||||
->to($payment->getCustomer()?->getEmail())
|
||||
->context(['payment' => $payment]);
|
||||
|
||||
$this->mailer->send($mail);
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ class TicketService
|
||||
private readonly UrlGeneratorInterface $generator,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly PaymentRepository $paymentRepository,
|
||||
private readonly TicketEmailService $emailService,
|
||||
#[Autowire(env: 'STRIPE_SECRET_KEY')]
|
||||
string $stripeKey
|
||||
) {
|
||||
@ -36,18 +37,6 @@ class TicketService
|
||||
return $session;
|
||||
}
|
||||
|
||||
public function saveTicketData(TicketFormData $data, string $sessionId): void
|
||||
{
|
||||
$payment = (new Payment())
|
||||
->setSessionId($sessionId)
|
||||
->setCompleted(false)
|
||||
->setCustomer($this->createEntityFromData($data));
|
||||
|
||||
$this->em->persist($payment);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
|
||||
public function completePayment(string $sessionId): bool
|
||||
{
|
||||
if (!$payment = $this->paymentRepository->findOneBy(['sessionId' => $sessionId])) {
|
||||
@ -57,9 +46,23 @@ class TicketService
|
||||
$payment->setCompleted(true);
|
||||
$this->em->flush();
|
||||
|
||||
$this->emailService->sendSuccessEmail($payment);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private function saveTicketData(TicketFormData $data, string $sessionId): void
|
||||
{
|
||||
$payment = (new Payment())
|
||||
->setSessionId($sessionId)
|
||||
->setCompleted(false)
|
||||
->setCustomer($this->createEntityFromData($data));
|
||||
|
||||
$this->em->persist($payment);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
private function getLineItems(array $tickets): array
|
||||
{
|
||||
$lineItems = [];
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Twig;
|
||||
|
||||
@ -14,8 +15,7 @@ class Ticket extends AbstractExtension
|
||||
{
|
||||
return [
|
||||
new TwigFilter('food', $this->getFoodName(...)),
|
||||
new TwigFilter('ticket', $this->getTicket(...)),
|
||||
|
||||
new TwigFilter('ticket', $this->getTicket(...))
|
||||
];
|
||||
}
|
||||
|
||||
|
26
templates/email/order.html.twig
Normal file
26
templates/email/order.html.twig
Normal file
@ -0,0 +1,26 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Abiball Ticket</title>
|
||||
</head>
|
||||
<body>
|
||||
Hallo {{ payment.customer.firstname }}
|
||||
<br>
|
||||
text
|
||||
<br>
|
||||
{% for ticket in payment.customer.tickets %}
|
||||
{{ (ticket.type | ticket)['name'] }} ({{ (ticket.type | ticket)['price'] }}€)
|
||||
<br>
|
||||
{{ ticket.foodType | food }}
|
||||
<br>
|
||||
{% if ticket.note %}
|
||||
<br>
|
||||
{{ ticket.note }}
|
||||
{% endif %}
|
||||
{% if not loop.last %}
|
||||
<hr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user