<?php
namespace App\Controller\Front;
use App\Model\Appointment;
use App\Service\StripeService;
use Stripe\PaymentIntent;
use Stripe\Stripe;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/payment", priority="1", options={"expose"=true}, name="payment_")
*/
class PaymentController extends AbstractController
{
/**
* @Route("/create", name="stripe_create")
*/
public function create(Request $request, string $stripeClientID, StripeService $stripeService): JsonResponse
{
Stripe::setApiKey($stripeClientID);
/** @var Appointment $appointment */
$appointment = $request->getSession()->get('appointment');
// Create a PaymentIntent with amount and currency
$paymentIntent = $stripeService->createIntent($appointment);
return $this->json(['clientSecret' => $paymentIntent->client_secret]);
}
/**
* @Route("/amount", name="stripe_amount")
*/
public function amount(Request $request): JsonResponse
{
/** @var Appointment $appointment */
$appointment = $request->getSession()->get('appointment');
return $this->json([
'html' => $this->renderView('front/appointment/parts/payment_recap.html.twig', [
'services' => $appointment->getServices(),
]),
]);
}
}