refactor
All checks were successful
build / build (pull_request) Successful in 4m14s

This commit is contained in:
Constantin Simonis 2025-01-31 11:04:06 +01:00
parent 267a81a837
commit caa25c9e95
Signed by: csimonis
GPG Key ID: 758DD9C506603183
2 changed files with 5 additions and 2 deletions

View File

@ -28,8 +28,6 @@ final class TicketController extends AbstractController
#[Route(path: '/ticket/submit', name: 'app_submit', methods: Request::METHOD_POST)] #[Route(path: '/ticket/submit', name: 'app_submit', methods: Request::METHOD_POST)]
public function submit(Request $request): Response public function submit(Request $request): Response
{ {
Stripe::setApiKey($_ENV['STRIPE_SECRET_KEY']);
$ticketData = $this->serializer->deserialize($request->getContent(), TicketFormData::class, 'json'); $ticketData = $this->serializer->deserialize($request->getContent(), TicketFormData::class, 'json');
return $this->json(['id' => $this->service->handleTicketData($ticketData)->id]); return $this->json(['id' => $this->service->handleTicketData($ticketData)->id]);

View File

@ -11,6 +11,8 @@ use App\Enum\TicketData as TicketEnum;
use App\Repository\PaymentRepository; use App\Repository\PaymentRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Stripe\Checkout\Session; use Stripe\Checkout\Session;
use Stripe\Stripe;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class TicketService class TicketService
@ -19,7 +21,10 @@ class TicketService
private readonly UrlGeneratorInterface $generator, private readonly UrlGeneratorInterface $generator,
private readonly EntityManagerInterface $em, private readonly EntityManagerInterface $em,
private readonly PaymentRepository $paymentRepository, private readonly PaymentRepository $paymentRepository,
#[Autowire(env: 'STRIPE_SECRET_KEY')]
string $stripeKey
) { ) {
Stripe::setApiKey($stripeKey);
} }
public function handleTicketData(TicketFormData $data): Session public function handleTicketData(TicketFormData $data): Session