src/Controller/Front/SubscriptionController.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Application\Service\Cart\CartService;
  4. use App\Application\Service\Front\SubscriptionService;
  5. use App\Application\Service\Session\SessionService;
  6. use App\Service\SecurityService;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class SubscriptionController extends AbstractController
  14. {
  15.     private SubscriptionService $subscriptionService;
  16.     private ParameterBagInterface $parameterBag;
  17.     private SessionService $sessionService;
  18.     private CartService $cartService;
  19.     private SecurityService $securityService;
  20.     public function __construct(
  21.         SubscriptionService $subscriptionService,
  22.         ParameterBagInterface $parameterBag,
  23.         SessionService $sessionService,
  24.         CartService $cartService,
  25.         SecurityService $securityService
  26.     ) {
  27.         $this->subscriptionService $subscriptionService;
  28.         $this->parameterBag $parameterBag;
  29.         $this->sessionService $sessionService;
  30.         $this->cartService $cartService;
  31.         $this->securityService $securityService;
  32.     }
  33.     /**
  34.      * @Route("/{_locale}/subscription/checkout", name="checkout", defaults={"_locale":"es"})
  35.      * @Route("/subscription/checkout", name="checkout_wo_locale")
  36.      *
  37.      * @param Request $request
  38.      *
  39.      * @return Response
  40.      */
  41.     public function checkout(Request $request): Response
  42.     {
  43.         if ($cartId $this->sessionService->get('id_cart_services')) {
  44.             $this->cartService->cleanCart((int)$cartId);
  45.         }
  46.         $parameters = [
  47.             'isNewShopSelected' => (int)$request->get('isNewShopSelected'),
  48.             'catalogId' => $request->get('catalogId'),
  49.             'themeId' => $request->get('themeId'),
  50.             'idSubscription' => $request->get('idSubscription'),
  51.             'goToStepServices' => (bool)$request->get('goToStepServices'),
  52.             'serviceProductId' => (int)$request->get('serviceProductId'),
  53.             'paypalSandbox' => \json_encode($this->parameterBag->get('paypal_sandbox')),
  54.             'paypalFraudNet' => $this->parameterBag->get('paypal_fraud_net'),
  55.             'sessionUuid' => $this->securityService->findSessionCustomerId().time().random_int(1999999),
  56.             'websideId' => $this->parameterBag->get('paypal_merchant_id').'_services_checkout',
  57.         ];
  58.         $this->subscriptionService->checkout($parameters);
  59.         return $this->render('front/subscription/checkout_react.html.twig'$parameters);
  60.     }
  61.     /**
  62.      * @Route("/subscription/ajaxGetDataToShowEndPurchase", name="ajaxGetDataToShowEndPurchase")
  63.      *
  64.      * @return JsonResponse
  65.      */
  66.     public function ajaxGetDataToShowEndPurchase(): JsonResponse
  67.     {
  68.         $subscription = new \subscriptionController();
  69.         $response = ['receivedParams' => $subscription->ajaxGetDataToShowEndPurchase()];
  70.         return new JsonResponse($response);
  71.     }
  72. }