<?php
namespace App\Controller\Front;
use App\Application\Service\Cart\CartService;
use App\Application\Service\Front\SubscriptionService;
use App\Application\Service\Session\SessionService;
use App\Service\SecurityService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class SubscriptionController extends AbstractController
{
private SubscriptionService $subscriptionService;
private ParameterBagInterface $parameterBag;
private SessionService $sessionService;
private CartService $cartService;
private SecurityService $securityService;
public function __construct(
SubscriptionService $subscriptionService,
ParameterBagInterface $parameterBag,
SessionService $sessionService,
CartService $cartService,
SecurityService $securityService
) {
$this->subscriptionService = $subscriptionService;
$this->parameterBag = $parameterBag;
$this->sessionService = $sessionService;
$this->cartService = $cartService;
$this->securityService = $securityService;
}
/**
* @Route("/{_locale}/subscription/checkout", name="checkout", defaults={"_locale":"es"})
* @Route("/subscription/checkout", name="checkout_wo_locale")
*
* @param Request $request
*
* @return Response
*/
public function checkout(Request $request): Response
{
if ($cartId = $this->sessionService->get('id_cart_services')) {
$this->cartService->cleanCart((int)$cartId);
}
$parameters = [
'isNewShopSelected' => (int)$request->get('isNewShopSelected'),
'catalogId' => $request->get('catalogId'),
'themeId' => $request->get('themeId'),
'idSubscription' => $request->get('idSubscription'),
'goToStepServices' => (bool)$request->get('goToStepServices'),
'serviceProductId' => (int)$request->get('serviceProductId'),
'paypalSandbox' => \json_encode($this->parameterBag->get('paypal_sandbox')),
'paypalFraudNet' => $this->parameterBag->get('paypal_fraud_net'),
'sessionUuid' => $this->securityService->findSessionCustomerId().time().random_int(1, 999999),
'websideId' => $this->parameterBag->get('paypal_merchant_id').'_services_checkout',
];
$this->subscriptionService->checkout($parameters);
return $this->render('front/subscription/checkout_react.html.twig', $parameters);
}
/**
* @Route("/subscription/ajaxGetDataToShowEndPurchase", name="ajaxGetDataToShowEndPurchase")
*
* @return JsonResponse
*/
public function ajaxGetDataToShowEndPurchase(): JsonResponse
{
$subscription = new \subscriptionController();
$response = ['receivedParams' => $subscription->ajaxGetDataToShowEndPurchase()];
return new JsonResponse($response);
}
}