add success email #14

Merged
csimonis merged 12 commits from feature/success-email into main 2025-02-13 20:14:35 +00:00
5 changed files with 76 additions and 14 deletions
Showing only changes of commit 5f68d12967 - Show all commits

View File

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace App\Enum;

View 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);
}
}

View File

@ -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 = [];

View File

@ -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(...))
];
}

View 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>