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. $subscriptionId = null;
  45. if ($request->get('idSubscription')) {
  46. $subscriptionId = (int)$request->get('idSubscription');
  47. }
  48. $this->cartService->cleanCart((int)$cartId, $subscriptionId);
  49. }
  50. $parameters = [
  51. 'isNewShopSelected' => (int)$request->get('isNewShopSelected'),
  52. 'catalogId' => $request->get('catalogId'),
  53. 'themeId' => $request->get('themeId'),
  54. 'idSubscription' => $request->get('idSubscription'),
  55. 'goToStepServices' => (bool)$request->get('goToStepServices'),
  56. 'serviceProductId' => (int)$request->get('serviceProductId'),
  57. 'paypalSandbox' => \json_encode($this->parameterBag->get('paypal_sandbox')),
  58. 'paypalFraudNet' => $this->parameterBag->get('paypal_fraud_net'),
  59. 'sessionUuid' => $this->securityService->findSessionCustomerId().time().random_int(1, 999999),
  60. 'websideId' => $this->parameterBag->get('paypal_merchant_id').'_services_checkout',
  61. ];
  62. $this->subscriptionService->checkout($parameters);
  63. return $this->render('front/subscription/checkout_react.html.twig', $parameters);
  64. }
  65. /**
  66. * @Route("/subscription/ajaxGetDataToShowEndPurchase", name="ajaxGetDataToShowEndPurchase")
  67. *
  68. * @return JsonResponse
  69. */
  70. public function ajaxGetDataToShowEndPurchase(): JsonResponse
  71. {
  72. $subscription = new \subscriptionController();
  73. $response = ['receivedParams' => $subscription->ajaxGetDataToShowEndPurchase()];
  74. return new JsonResponse($response);
  75. }
  76. }