src/Controller/LicenseRecovery/LicenseRecoveryController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\LicenseRecovery;
  3. use App\Controller\BaseController;
  4. use App\Entity\LicenseRecovery\LicenseRecovery;
  5. use App\Entity\Order\Order;
  6. use App\Entity\VignetteInvoice\VignetteInvoice;
  7. use App\Manager\Cart\CartManager;
  8. use App\Manager\LicenseRecovery\LicenseRecoveryManager;
  9. use App\Manager\Partner\PartnerManager;
  10. use App\Service\AuthTokenService;
  11. use App\Service\InvoiceApiService;
  12. use App\Service\InvoiceService;
  13. use App\Service\SystemService;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  17. class LicenseRecoveryController extends BaseController
  18. {
  19.     public function indexAction(): Response
  20.     {
  21.         return $this->render('@templates/Front/LicenseRecovery/license-recovery.html.twig');
  22.     }
  23.     public function submitData(): Response
  24.     {
  25.         $licenseRecoveryResponse $this->getContainer()->get('app.service.license_recovery.license_recovery')
  26.             ->storeNewLicenseRecoveryInCart(LicenseRecovery::FLAG_SOURCE_PRODUCT_PAGE);
  27.         return new Response(json_encode($licenseRecoveryResponse));
  28.     }
  29.     public function removeFromCart(Request $request): Response
  30.     {
  31.         $licenseRecoveryService $this->getContainer()->get('app.service.license_recovery.license_recovery');
  32.         $result $licenseRecoveryService->removeLicenseRecoveryFromCartSessionByCnp($request->get('cnp'));
  33.         return new Response(json_encode(['result' => $result]));
  34.     }
  35.     public function iframe(Request $request): Response
  36.     {
  37.         $partnerService $this->getContainer()->get('app.service.partner.partner');
  38.         $partnerService->verifyToken($requestPartnerManager::CAN_ISSUE_LICENSE_RECOVERY_INDEX);
  39.         $token['partnerPublicToken'] = $request->get(PartnerManager::SESSION_PARTNER_PUBLIC_TOKEN_NAME);
  40.         $request->getSession()->set('iframeSourceLink'$this->generateUrl('app_shop_lr_iframe'$token));
  41.         $partner $partnerService->retrievePartner($token['partnerPublicToken']);
  42.         if ($partner->getWithoutLocalStorage()) {
  43.             CartManager::removeAllProductsFromCartBySession($request->getSession());
  44.         }
  45.         PartnerManager::checkQRCodeFlow($request);
  46.         return $this->render('@templates/Front/LicenseRecovery/iframe.html.twig', [
  47.             'guid' => $request->get('guid'),
  48.             'publicToken' => $partner->getPublicToken()
  49.         ]);
  50.     }
  51.     public function addToCartById(Order $orderRequest $request)
  52.     {
  53.         $clientIp $request->getClientIp();
  54.         $session $request->getSession();
  55.         foreach ($order->getLicenseRecovery() as $licenseRecovery) {
  56.             if (!LicenseRecoveryManager::isLicenseRecoveryAlreadyInCart($session)) {
  57.                 $cartItem LicenseRecoveryManager::constructLicenseRecoveryForCartFromObject(
  58.                     $licenseRecovery$clientIpLicenseRecovery::FLAG_SOURCE_REMARKETING
  59.                 );
  60.                 LicenseRecoveryManager::addNewLicenseRecoveryInCart($session$cartItem);
  61.             }
  62.         }
  63.         $authTokenService = new AuthTokenService();
  64.         if ($token $authTokenService->authenticateUserWithToken($request$this->getEntityManager())) {
  65.             $this->get('security.token_storage')->setToken($token);
  66.             $event = new InteractiveLoginEvent($request$token);
  67.             $this->dispatcher->dispatch($event'security.interactive_login');
  68.             $session $request->getSession();
  69.             $session->set('_sylius.cart.FASHION_WEB'180);
  70.             $session->save();
  71.         }
  72.         $utm = [
  73.             'utm_source' => $request->get('utm_source'),
  74.             'utm_medium' => $request->get('utm_medium'),
  75.             'utm_campaign' => $request->get('utm_campaign'),
  76.             'utm_term' => $request->get('utm_term'),
  77.             'utm_content' => $request->get('utm_content'),
  78.             'utm_id' => $request->get('utm_id')
  79.         ];
  80.         return $this->render('@templates/ShopCustom/Redirect/wait_to_be_redirected.html.twig',[
  81.             'url' => $this->generateUrl('app_shop_customer_info'$utm)
  82.         ]);
  83.     }
  84.     public function showPolicyForPartner(Request $request): Response
  85.     {
  86.         $id base64_decode($request->get('order_id'));
  87.         $em $this->getEntityManager();
  88.         /** @var Order $order */
  89.         $order $em->getRepository(Order::class)->find($id);
  90.         if (!$order->hasLicenseRecovery()) {
  91.             return new Response('error');
  92.         }
  93.         $apiInvoiceService = new InvoiceApiService();
  94.         $invoice $em->getRepository(VignetteInvoice::class)
  95.             ->findOneBy(['order' => $id'productType' => VignetteInvoice::PRODUCT_LICENSE_RECOVERY]);
  96.         $pdfContent $apiInvoiceService->getInvoicePDFViaBillingService($invoice->getApiInvoiceId());
  97.         if (!$pdfContent) {
  98.             return new Response('error');
  99.         }
  100.         $invoiceFileName SystemService::retrieveMessage('invoice'$this->getContainer()->get('translator'));
  101.         $filename "{$invoiceFileName} {$invoice->getSeries()} {$invoice->getNumber()}";
  102.         InvoiceService::openPDFContent($pdfContent$filename);
  103.         return new Response();
  104.     }
  105. }