diff --git a/src/Controller/TicketController.php b/src/Controller/TicketController.php index 97cc400..0a30335 100644 --- a/src/Controller/TicketController.php +++ b/src/Controller/TicketController.php @@ -28,8 +28,6 @@ final class TicketController extends AbstractController #[Route(path: '/ticket/submit', name: 'app_submit', methods: Request::METHOD_POST)] public function submit(Request $request): Response { - Stripe::setApiKey($_ENV['STRIPE_SECRET_KEY']); - $ticketData = $this->serializer->deserialize($request->getContent(), TicketFormData::class, 'json'); return $this->json(['id' => $this->service->handleTicketData($ticketData)->id]); diff --git a/src/Service/TicketService.php b/src/Service/TicketService.php index 46c4ad8..3570e73 100644 --- a/src/Service/TicketService.php +++ b/src/Service/TicketService.php @@ -11,6 +11,8 @@ use App\Enum\TicketData as TicketEnum; use App\Repository\PaymentRepository; use Doctrine\ORM\EntityManagerInterface; use Stripe\Checkout\Session; +use Stripe\Stripe; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class TicketService @@ -19,7 +21,10 @@ class TicketService private readonly UrlGeneratorInterface $generator, private readonly EntityManagerInterface $em, private readonly PaymentRepository $paymentRepository, + #[Autowire(env: 'STRIPE_SECRET_KEY')] + string $stripeKey ) { + Stripe::setApiKey($stripeKey); } public function handleTicketData(TicketFormData $data): Session