add success email
This commit is contained in:
parent
7799a42825
commit
607a74e311
13
src/Enum/FoodData.php
Normal file
13
src/Enum/FoodData.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Enum;
|
||||
|
||||
class FoodData
|
||||
{
|
||||
public const FOOD_DATA = [
|
||||
1 => 'Mit Fleisch',
|
||||
2 => 'Vegetarisch',
|
||||
3 => 'Vegan'
|
||||
];
|
||||
}
|
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 = [];
|
||||
|
30
src/Twig/Ticket.php
Normal file
30
src/Twig/Ticket.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Enum\FoodData;
|
||||
use App\Enum\TicketData;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
class Ticket extends AbstractExtension
|
||||
{
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
new TwigFilter('food', $this->getFoodName(...)),
|
||||
new TwigFilter('ticket', $this->getTicket(...))
|
||||
];
|
||||
}
|
||||
|
||||
public function getFoodName(int $id): string
|
||||
{
|
||||
return FoodData::FOOD_DATA[$id] ?? 'N/A';
|
||||
}
|
||||
|
||||
public function getTicket(int $id): array
|
||||
{
|
||||
return TicketData::TICKET_DATA[$id] ?? ['name' => 'N/A', 'price' => 'N/A'];
|
||||
}
|
||||
}
|
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