src/Controller/Front/PaymentController.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Model\Appointment;
  4. use App\Service\StripeService;
  5. use Stripe\PaymentIntent;
  6. use Stripe\Stripe;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * @Route("/payment", priority="1", options={"expose"=true}, name="payment_")
  13.  */
  14. class PaymentController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/create", name="stripe_create")
  18.      */
  19.     public function create(Request $requeststring $stripeClientIDStripeService $stripeService): JsonResponse
  20.     {
  21.         Stripe::setApiKey($stripeClientID);
  22.         /** @var Appointment $appointment */
  23.         $appointment $request->getSession()->get('appointment');
  24.         // Create a PaymentIntent with amount and currency
  25.         $paymentIntent $stripeService->createIntent($appointment);
  26.         return $this->json(['clientSecret' => $paymentIntent->client_secret]);
  27.     }
  28.     /**
  29.      * @Route("/amount", name="stripe_amount")
  30.      */
  31.     public function amount(Request $request): JsonResponse
  32.     {
  33.         /** @var Appointment $appointment */
  34.         $appointment $request->getSession()->get('appointment');
  35.         return $this->json([
  36.            'html' => $this->renderView('front/appointment/parts/payment_recap.html.twig', [
  37.                'services' => $appointment->getServices(),
  38.            ]),
  39.         ]);
  40.     }
  41. }