src/project/OfficeBrain/CustomBundle/OrderBundle/Controller/OrderController.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\project\OfficeBrain\CustomBundle\OrderBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use App\project\OfficeBrain\CustomBundle\UserBundle\Form\ContactBookType;
  9. use App\project\OfficeBrain\CustomBundle\UserBundle\Entity\ContactBook;
  10. use App\OfficeBrain\Bundle\OrderBundle\Controller\OrderController as BaseOrderController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\DependencyInjection\ContainerInterface;
  13. use App\OfficeBrain\Bundle\CoreBundle\Service\OBCommon;
  14. use Symfony\Component\HttpFoundation\RequestStack;
  15. use Symfony\Component\Routing\RouterInterface;
  16. use Symfony\Component\Validator\Validator\ValidatorInterface;
  17. use App\OfficeBrain\Bundle\CoreBundle\Service\SessionManager;
  18. use App\OfficeBrain\Bundle\CoreBundle\Helper\Validation;
  19. use App\OfficeBrain\Bundle\OrderBundle\Manager\Service\OrderService;
  20. use App\OfficeBrain\Bundle\UserBundle\Manager\Service\UserService;
  21. use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductDetailService;
  22. use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsMediaLibraryService;
  23. use App\OfficeBrain\Bundle\CoreBundle\Manager\Service\CoreService;
  24. use App\OfficeBrain\Bundle\ShippingEstimatorBundle\Manager\Service\FedexShippingEstimatorService;
  25. use App\OfficeBrain\Bundle\ShippingEstimatorBundle\Manager\Service\UPSShippingEstimatorService;
  26. use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsThirdPartyService;
  27. use App\project\OfficeBrain\CustomBundle\UserBundle\Manager\Service\ContactBookService;
  28. use App\OfficeBrain\Bundle\QueueBundle\Manager\Service\ApiManager as QueueApiManager;
  29. /**
  30.  *
  31.  *
  32.  * @Route("", defaults={"rule_service"="rule_charges"})
  33.  */
  34. class OrderController extends BaseOrderController
  35. {
  36.     /**
  37.      *
  38.      * @author Employee Id: 5460
  39.      * To set member variables default value
  40.      * @return NULL
  41.      * 
  42.      *  
  43.     */
  44.     public function __construct(ContainerInterface $containerOrderService $orderServiceUserService $userServiceProductDetailService $productDetailServiceCmsMediaLibraryService $cmsMediaLibraryServiceCoreService $coreServiceFedexShippingEstimatorService $fedexShippingEstimatorServiceUPSShippingEstimatorService $upsShippingEstimatorServiceCmsThirdPartyService $cmsThirdPartyServiceContactBookService $contactBookServiceQueueApiManager $queueApiManagerRequestStack $requestStackRouterInterface $routerValidatorInterface $validatorInterfaceSessionManager $sessionManagerValidation $validation)
  45.     {
  46.         parent::__construct($container$orderService$userService$productDetailService$cmsMediaLibraryService$coreService$fedexShippingEstimatorService$upsShippingEstimatorService$cmsThirdPartyService$contactBookService$queueApiManager$requestStack$router$validatorInterface$sessionManager$validation);
  47.         $this->userContactBookManager $contactBookService->getContactBookExtended();
  48.     }
  49.     /**
  50.      *
  51.      * @author Employee Id: 5460
  52.      * To unset member variables
  53.      * @return NULL
  54.      */
  55.     public function __destruct()
  56.     {
  57.         parent::__destruct();
  58.     }
  59.     
  60.     public function initAction(Request $request){
  61.         parent::initAction($request);
  62.         // $this->userContactBookManager = $this->serviceContainer->get('office_brain_user_contact_book_manager_custom');
  63.         $this->userContactBookManager $this->userContactBookManager;
  64.         $this->tioryApiURL $this->serviceContainer->getParameter('tiory_url'); //die;
  65.         
  66.         //$this->tioryApiURL = 'https://arc1967.tiory.com/api/'; // Live
  67.     }
  68.     
  69.     /**
  70.      * @author Employee Id: 4471
  71.      * Description : use to copy image for art work
  72.      * @param 1 : No paramater
  73.      * @return type : Ajax response in image successfully uploaded
  74.      * @throws Exception: Null
  75.      *
  76.      * @Route("/{_locale}/order-upload-artwork-from-gallery",
  77.      * name="office_brain_orderbundle_order_uploadartworkfromgallery",
  78.      * options={"expose"=true}
  79.      * )
  80.      * @Template()
  81.      * @Method({"POST"})
  82.      */
  83.     public function uploadArtWorkFromGalleryAction(Request $request)
  84.     {
  85.         $this->initAction($request);
  86.         $logoId$this->request->get('logoId');
  87.         $originalImageName$this->request->get('imageName');
  88.         $imageUpload=$this->imageLibraryManager->copyMedia($this->mediaFilePath$this->artworkFilePath ,$originalImageName,$originalImageName);
  89.         if($imageUpload != '')
  90.         {
  91.             $this->response['logoId']=$logoId;
  92.             $this->response['uploadedImageName']= $this->artworkFileURL.'/'.$imageUpload;
  93.             $this->response ['iconFileName'] = $this->artworkFileURL '/' $imageUpload;
  94.             
  95.             /* code for replacing documents for related icons started */
  96.             $fileIconsAvailableFor $this->serviceContainer->getParameter('file_icons_available_for');
  97.             $fileIconsBaseUrl $this->serviceContainer->getParameter('file_icons_base_url');
  98.             if(isset($fileIconsAvailableFor) && is_array($fileIconsAvailableFor))
  99.             {
  100.                 foreach($fileIconsAvailableFor as $fileIconsExtension)
  101.                 {
  102.                     if(strstr($imageUpload,$fileIconsExtension))
  103.                     {
  104.                         $imageUpload str_replace('.','',$fileIconsExtension).'.png';
  105.                         $this->response['iconFileName']= $fileIconsBaseUrl.$imageUpload;
  106.                     }
  107.                 }
  108.             }
  109.             /* code for replacing documents for related icons ended */
  110.             
  111.             $this->response['status']='success';
  112.             $this->response['success_message']= $this->get('translator')->trans('order.print_position.artwork.upload_image_sucess');
  113.         }
  114.         else
  115.         {
  116.             $this->response['logoId']=$logoId;
  117.             $this->response['sucess']='error';
  118.         }
  119.         return new JsonResponse($this->response);
  120.     }
  121.     
  122.     /**
  123.      * @author Employee Id: 4248
  124.      * Description : Use to add the new shipping address
  125.      *
  126.      * @Route("/{_locale}/order-add-address",
  127.      * name="office_brain_orderbundle_order_saveorderaddress",
  128.      * )
  129.      * @Method({"GET"})
  130.      * @Template("project/OfficeBrain/CustomBundle/OrderBundle/Order/addContactBook.html.twig")
  131.      */
  132.     public function addContactBookAction(Request $request)
  133.     {
  134.         $this->initAction($request);
  135.         if( $this->userId==0){
  136.             if ($this->request->isXmlHttpRequest()) {
  137.                 $this->responseArray['status'] = 'error';
  138.                 $this->responseArray['error_type'] = 'loginError';
  139.                 $this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
  140.                 return new JsonResponse($this->responseArray);
  141.             }else{
  142.                 return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
  143.             }
  144.             $this->form $this->createForm(new OrderAddGuestShippingType($this->coreManager'add'));
  145.             $this->form->handleRequest($this->request);
  146.             return $this->render('OfficeBrainOrderBundle:Order:addGuestContactBook.html.twig', array('contactBookForm' => $this->form->createView()));
  147.         }
  148.         else
  149.         {
  150.             $this->form $this->createForm(new ContactBookType($this->serviceContainer,'order-add-address'), new ContactBook());
  151.             $this->form->handleRequest($this->request);
  152.             $this->responseArray['contactBookForm'] = $this->form->createView();
  153.             return  $this->responseArray;
  154.         }
  155.     }
  156.     /**
  157.      * @author Employee Id: 410175
  158.      * Description : Use to render Shipping Address By Id
  159.      * @param 1 : No paramater
  160.      * @return type : Ajax response in view.
  161.      * @throws Exception: Null
  162.      *
  163.      * @Route("/{_locale}/order-get-shipping-address-by-id",
  164.      * name="office_brain_orderbundle_order_getshippingaddressbyid",
  165.      * options={"expose"=true}
  166.      * )
  167.      * @Template("OfficeBrainOrderBundle:Order:getShippingAddressById.html.twig")
  168.      * @Method({"GET"})
  169.      */
  170.     public function getShippingAddressByIdAction(Request $request)
  171.     {
  172.         $this->initAction($request);
  173.         $this->response['result'] = $this->orderManager->getUserShippingAddresById();
  174.         $this->response['addressId'] = $this->request->get('contact_id',null);
  175.         return $this->response;
  176.     }
  177.     /**
  178.      * @author Employee Id: 4248
  179.      * Description : Use to add the new billing address
  180.      *
  181.      * @Route("/{_locale}/cheakout-add-billing-address",
  182.      * name="office_brain_orderbundle_order_addcheckoutshippingaddress",
  183.      * options={"expose"=true}
  184.      * )
  185.      * @Method({"GET"})
  186.      * @Template("project/OfficeBrain/CustomBundle/OrderBundle/Order/addCheckoutBillingAddress.html.twig")
  187.      */
  188.     public function addCheckoutBillingAddressAction(Request $request)
  189.     {
  190.         $this->initAction($request);
  191.         if( $this->userId==0){
  192.             if ($this->request->isXmlHttpRequest()) {
  193.                 $this->responseArray['error_type'] = 'loginError';
  194.                 $this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
  195.                 return new JsonResponse($this->responseArray);
  196.             }else{
  197.                 return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
  198.             }
  199.         }
  200.         else
  201.         {
  202.             // $this->form = $this->createForm(new ContactBookType($this->container), new ContactBook()); // symfony 4
  203.             
  204.             $this->form $this->createForm(ContactBookType::class, new ContactBook(), [
  205.                 'container' => $this->serviceContainer,
  206.             ]);
  207.             $this->form->handleRequest($this->request);
  208.             $this->responseArray['contactBookForm'] = $this->form->createView();
  209.             return  $this->responseArray;
  210.         }
  211.     }
  212.     /**
  213.      * @author Employee Id: 4248
  214.      * Description : Use to edit the existing shipping address
  215.      *
  216.      * @Route("/{_locale}/checkout-shipping-edit-address/{contactBookId}",
  217.      * name="office_brain_orderbundle_order_editcheckoutshippingaddress",
  218.      * )
  219.      * @Method({"GET"})
  220.      * @Template("project/OfficeBrain/CustomBundle/OrderBundle/Order/editCheckoutShippingAddress.html.twig")
  221.      */
  222.     public function editCheckoutShippingAddressAction(Request $request)
  223.     {
  224.         $this->initAction($request);
  225.         $contactBookId         $this->request->get('contactBookId');
  226.         $contactBookArray     $this->userContactBookManager->getSingleContactBook($contactBookId);
  227.         // $contactBookForm     = $this->createForm(new ContactBookType($this->container), $contactBookArray); // symfony 4
  228.         
  229.         $contactBookForm $this->createForm(ContactBookType::class, $contactBookArray, [
  230.             'container' => $this->serviceContainer,
  231.         ]);
  232.         
  233.         if($contactBookArray->getCountryId()=='739')
  234.         {
  235.             $othercountry=1;
  236.             return array('contactBookForm'=> $contactBookForm->createView(),'contactBookId'=>$contactBookId,'othercountry'=>$othercountry);
  237.         }
  238.         return array ('contactBookForm' => $contactBookForm->createView (),'contactBookId' => $contactBookId);
  239.     }
  240.     /**
  241.      * @author Employee Id: 5429
  242.      * Description :My shipping address
  243.      *
  244.      * @Route("/{_locale}/order-view-my-address",
  245.      * name="office_brain_orderbundle_order_addressBook",
  246.      * )
  247.      * @Method({"GET"})
  248.      * @Template("project/OfficeBrain/CustomBundle/OrderBundle/Order/viewMyContactBook.html.twig")
  249.      */
  250.     public function viewMyContactBookAction(Request $request)
  251.     {
  252.         $this->initAction($request);
  253.         $userId$this->request->get('userId');
  254.         $type$this->request->get('add-type');
  255.         $data['counter']= $this->request->get('counter');
  256.         $contactBookArray     $this->userContactBookManager->getMyAddressFromContactBook($userId,$type);
  257.         $data['contactBookArray']=$contactBookArray;
  258.         $data['addtype']=$type;
  259.         return $data;
  260.     }
  261.     /**
  262.      * @author Employee Id: 5429
  263.      * Description :My shipping address
  264.      *
  265.      * @Route("/{_locale}/order-view-my-address-ajax",
  266.      * name="office_brain_orderbundle_order_addressBook_ajax",options={"expose"=true}
  267.      * )
  268.      * @Method({"GET"})
  269.      * @Template("project/OfficeBrain/CustomBundle/OrderBundle/Order/viewMyContactBookAjax.html.twig")
  270.      */
  271.     public function viewMyContactBookAjaxAction(Request $request)
  272.     {
  273.         $this->initAction($request);
  274.         $userId$this->userId;
  275.         $type$this->request->get('add-type');
  276.         $data['counter']= $this->request->get('counter');
  277.         $contactBookArray     $this->userContactBookManager->getMyAddressFromContactBook($userId,$type,1,$this->request->get('option'),$this->request->get('keywords'));
  278.         $data['contactBookArray']=$contactBookArray;
  279.         $data['addtype']=$type;
  280.         return $data;
  281.     }
  282.     
  283.      /**
  284.      *
  285.      * @return json Response
  286.      *        
  287.      * @Route("/{_locale}/cc-payment",
  288.      *     name="officebrain_order_bundle_order_ccpayment",options={"expose"=true}
  289.      * )
  290.      * 
  291.      * 
  292.      */
  293.     public function ccPaymentAction(Request $request)
  294.     {
  295.         $this->initAction($request);
  296.         $userId$this->userId;
  297.         $data = array();
  298.         if ($this->request->isMethod('post')) {
  299.             $customerAccount $this->request->get('account');
  300.             $invoiceNumber $this->request->get('invoice');
  301.               $curl curl_init();
  302.               curl_setopt_array($curl, array(
  303.               CURLOPT_URL => $this->tioryApiURL.'orderInvoiceDetailAPI',
  304.               CURLOPT_RETURNTRANSFER => true,
  305.               CURLOPT_ENCODING => '',
  306.               CURLOPT_MAXREDIRS => 10,
  307.               CURLOPT_TIMEOUT => 0,
  308.               CURLOPT_FOLLOWLOCATION => true,
  309.               CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  310.               CURLOPT_CUSTOMREQUEST => 'POST',
  311.               CURLOPT_POSTFIELDS => json_encode(array('customer_account' => $customerAccount,'invoice_number' => $invoiceNumber)),
  312.               CURLOPT_HTTPHEADER => array(
  313.                 'Content-Type: application/json'
  314.               ),
  315.             ));
  316.             
  317.             $response curl_exec($curl);
  318.             //print_r($response); die;
  319.             curl_close($curl);
  320.             $result json_decode($response,true);
  321.             $accounts = array();
  322.             $data['no_rec_found']=true;
  323.             if(!$result['error']){
  324.                 if(is_array($result['result'])){
  325.                     $result $result['result'];
  326.                     $data['total_amount_due'] = (isset($result['total_amount_due'])) ? number_format($result['total_amount_due'],2) : 0.00;
  327.                     $data['invoice_number'] = (isset($result['invoice_number'])) ? $result['invoice_number'] : '';
  328.                     $data['customer_account'] = (isset($result['customer_account'])) ? $result['customer_account'] : '';
  329.                     $data['first_name'] = (isset($result['first_name'])) ? $result['first_name'] : '';
  330.                     $data['last_name'] = (isset($result['last_name'])) ? $result['last_name'] : '';
  331.                     $data['company_name'] = (isset($result['company_name'])) ? $result['company_name'] : '';
  332.                     $data['email'] = (isset($result['customer_email'])) ? $result['customer_email'] : '';
  333.                     $data['city'] = (isset($result['city'])) ? $result['city'] : '';
  334.                     $data['zipcode'] = (isset($result['zipcode'])) ? $result['zipcode'] : '';
  335.                     $data['country'] = (isset($result['country'])) ? $result['country'] : '';
  336.                     $data['state'] = (isset($result['state'])) ? $result['state'] : '';
  337.                     $data['address_line1'] = (isset($result['address_line1'])) ? $result['address_line1'] : '';
  338.                     //$data['url'] ="https://aakronruleuat.securepayments.cardpointe.com/pay?paymentType=cc&total=".$data['total_amount_due']."&invoice=".$data['invoice_number']."&customerId=".$data['customer_account']."&billFName=".$data['first_name']."&billLName=".$data['last_name']."&billCompany=".$data['company_name']."&billCity=".$data['city']."&tempBillState=".$data['state']."&billCountry=".$data['country']."&email=".$data['email']."&billZip=".$data['zipcode']."&billAddress1=".$data['address_line1'];
  339.                     $data['url'] ="https://aakronruleuat.securepayments.cardpointe.com/pay?paymentType=cc&total=".$data['total_amount_due']."&invoice=".$data['invoice_number']."&customerId=".$data['customer_account']."&billCompany=".$data['company_name'];
  340.                     $data['user_id']=$userId;
  341.                     $data['no_rec_found']=false;
  342.                 }
  343.             }
  344.             /*if($userId>0){
  345.                 return $this->render('OfficeBrainCustomBundleOrderBundle:Order:ccPayment.html.twig', $data);
  346.             }else{
  347.                 return $this->render('OfficeBrainCustomBundleOrderBundle:Order:ccPaymentload.html.twig', $data);
  348.             }*/
  349.             if($data['no_rec_found']){
  350.                 return new JsonResponse(array('no_record_found'=>"Invoice not found"));
  351.             }else{
  352.                 return new JsonResponse(array('payment_url'=>$data['url']));
  353.             }
  354.         }
  355.         die("Herere");
  356.         return array('user_id'=>$userId);
  357.     }
  358.     
  359.      /**
  360.      *
  361.      * @return json Response
  362.      *        
  363.      * @Route("/{_locale}/cc-payment-detail",
  364.      *     name="officebrain_order_bundle_order_ccpaymentdetail",options={"expose"=true}
  365.      * )
  366.      *
  367.      * 
  368.      */
  369.     public function ccpaymentdetailAction(Request $request)
  370.     {
  371.         $this->initAction($request);
  372.         if(isset($_POST['json'])){
  373.             $content =  json_decode($_POST['json'],true);
  374.             //$content =  json_decode('{"paymentType":"CC","type":"Pay","ipAddress":"167.99.14.79","token":"9514245733035100","btnID":"submitBtn","baseTotal":"2.00","overallTotal":"2.00","debitType":"credit","invoice":"22800980","customerId":"37519","total":"2.00","existingCard":"N","number":"***5100","expirationDateMonth":"03","expirationDateYear":"2025","billCompany":"Aakronline","billFName":"John","billLName":"Doe","billAddress1":"Greenpark","billCity":"Alberta","billZip":"42001","billCountry":"US","email":"nilesgh@gmail.com","billState":"AL","cardType":"Mastercard","gatewayTransactionId":"263531149707","avsResponseCode":"Z","cvvResponseCode":"M","authCode":"PPS667","responseCode":"000","responseText":"Approval","responseProc":"RPCT","URL":"aakronruleuat.securepayments.cardpointe.com","merchantId":"855000000122","date":"2023-09-20 12:48:27"}',true);
  375.             
  376.             $this->userManager $this->get('office_brain_user_manager');
  377.             if(isset($content['gatewayTransactionId'])){
  378.                 
  379.                 $userDetail $this->userManager->getUserDetailByAccountNo($content['customerId']); //269625
  380.                 $userId $this->userId;
  381.                 if($userId==0){
  382.                     if($userDetail[0]!=null){
  383.                         $userId $userDetail[0]->getId();
  384.                     }
  385.                 }
  386.                 $content['number'] = str_replace(' ','',$content['number']);
  387.                 $cardName strtolower(substr($content['cardType'],0,1));
  388.                 $start strlen($content['number'])-4;
  389.                 $cardNumber substr($content['number'],$start,4);
  390.                 $this->orderManager->setPaymentData($content,$userId,json_encode($content));   
  391.                 $reqdata['paymentType'] = $content['paymentType'];
  392.                 $reqdata['invoice'] = $content['invoice'];
  393.                 $reqdata['customerId'] = $content['customerId'];
  394.                 $reqdata['total'] = $content['total'];
  395.                 $reqdata['gatewayTransactionId'] = $content['gatewayTransactionId'];
  396.                 $reqdata['authCode'] = $content['authCode'];
  397.                 $reqdata['date'] = $content['date'];
  398.                 $reqdata['check_number'] = $cardName.$cardNumber;
  399.                 $curl curl_init();
  400.                   curl_setopt_array($curl, array(
  401.                   CURLOPT_URL => $this->tioryApiURL.'captureInvoicePaymentAPI',
  402.                   CURLOPT_RETURNTRANSFER => true,
  403.                   CURLOPT_ENCODING => '',
  404.                   CURLOPT_MAXREDIRS => 10,
  405.                   CURLOPT_TIMEOUT => 0,
  406.                   CURLOPT_FOLLOWLOCATION => true,
  407.                   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  408.                   CURLOPT_CUSTOMREQUEST => 'POST',
  409.                   CURLOPT_POSTFIELDS => json_encode($reqdata),
  410.                   CURLOPT_HTTPHEADER => array(
  411.                     'Content-Type: application/json'
  412.                   ),
  413.                 ));
  414.                 
  415.                 $response curl_exec($curl);
  416.                 curl_close($curl);
  417.             }
  418.         }
  419.         die("Hook Done");
  420.     }
  421. }