src/ApplicationBundle/Modules/HoneybeeWeb/Controller/HoneybeeWebPublicController.php line 55

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Modules\HoneybeeWeb\Controller;
  3. use ApplicationBundle\Constants\BuddybeeConstant;
  4. use ApplicationBundle\Constants\EmployeeConstant;
  5. use ApplicationBundle\Constants\GeneralConstant;
  6. use ApplicationBundle\Controller\GenericController;
  7. use ApplicationBundle\Entity\DatevToken;
  8. use ApplicationBundle\Modules\Authentication\Constants\UserConstants; use ApplicationBundle\Modules\Api\Constants\ApiConstants;
  9. use ApplicationBundle\Modules\Buddybee\Buddybee;
  10. use ApplicationBundle\Modules\System\MiscActions;
  11. use CompanyGroupBundle\Entity\EntityCreateTopic;
  12. use CompanyGroupBundle\Entity\EntityDatevToken;
  13. use CompanyGroupBundle\Entity\Device;
  14. use CompanyGroupBundle\Entity\EntityInvoice;
  15. use CompanyGroupBundle\Entity\EntityMeetingSession;
  16. use CompanyGroupBundle\Entity\EntityTicket;
  17. use Endroid\QrCode\Builder\BuilderInterface;
  18. use Endroid\QrCodeBundle\Response\QrCodeResponse;
  19. use Ps\PdfBundle\Annotation\Pdf;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use CompanyGroupBundle\Entity\EntityApplicantDetails;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\Routing\Generator\UrlGenerator;
  25. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  26. //use Symfony\Bundle\FrameworkBundle\Console\Application;
  27. //use Symfony\Component\Console\Input\ArrayInput;
  28. //use Symfony\Component\Console\Output\NullOutput;
  29. class HoneybeeWebPublicController extends GenericController
  30. {
  31.     // home page
  32.     public function CentralHomePageAction(Request $request)
  33.     {
  34.         $em $this->getDoctrine()->getManager('company_group');
  35.         $subscribed false;
  36.         if ($request->isMethod('POST')) {
  37.             $entityTicket = new EntityTicket();
  38.             $entityTicket->setEmail($request->request->get('newsletter'));
  39.             $em->persist($entityTicket);
  40.             $em->flush();
  41.             $subscribed true;
  42.         }
  43.         return $this->render('@HoneybeeWeb/pages/home.html.twig', [
  44.             'page_title' => 'HoneyBee-Home',
  45.             'subscribed' => $subscribed,
  46.         ]);
  47.     }
  48.     // about us
  49.     public function CentralAboutUsPageAction()
  50.     {
  51.         return $this->render('@HoneybeeWeb/pages/about_us.html.twig', array(
  52.                 'page_title' => 'About Us',
  53.         ));
  54.     }
  55.     // Contact page
  56.     public function CentralContactPageAction(Request $request)
  57.     {
  58.         $em $this->getDoctrine()->getManager('company_group');
  59.         if ($request->isXmlHttpRequest()) {
  60.             $email $request->request->get('email');
  61.             if ($email) {
  62.                 $entityTicket = new EntityTicket();
  63.                 $entityTicket->setEmail($email);
  64.                 $entityTicket->setName($request->request->get('name'));
  65.                 $entityTicket->setTitle($request->request->get('subject'));
  66.                 $entityTicket->setTicketBody($request->request->get('message'));
  67.                 $em->persist($entityTicket);
  68.                 $em->flush();
  69.                 return new JsonResponse([
  70.                     'success' => true,
  71.                     'message' => 'Your message has been sent successfully. Our team will reply soon.'
  72.                 ]);
  73.             }
  74.             return new JsonResponse([
  75.                 'success' => false,
  76.                 'message' => 'Invalid email address.'
  77.             ]);
  78.         }
  79.         return $this->render('@HoneybeeWeb/pages/contact.html.twig', array(
  80.             'page_title' => 'Contact',
  81.         ));
  82.         
  83.     }
  84.     // blogs
  85.     public function CentralBlogsPageAction(Request $request)
  86.     {
  87.         $em $this->getDoctrine()->getManager('company_group');
  88.         $topicDetails $em->getRepository('CompanyGroupBundle\Entity\EntityCreateTopic')->findAll();
  89.         $repo         $em->getRepository('CompanyGroupBundle\Entity\EntityCreateBlog');
  90.         // ── Fetch featured blog separately (always, regardless of page) ──
  91.         $featuredBlog $repo->findOneBy(['isPrimaryBlog' => true]);
  92.         // ── Pagination ──
  93.         $page       max(1, (int) $request->query->get('page'1));
  94.         $limit      6;
  95.         $totalBlogs count($repo->findAll());
  96.         $totalPages max(1, (int) ceil($totalBlogs $limit));
  97.         $page       min($page$totalPages);
  98.         $offset     = ($page 1) * $limit;
  99.         $blogDetails $repo->findBy([], ['Id' => 'DESC'], $limit$offset);
  100.         return $this->render('@HoneybeeWeb/pages/blogs.html.twig', [
  101.             'page_title'   => 'Blogs',
  102.             'topics'       => $topicDetails,
  103.             'blogs'        => $blogDetails,
  104.             'featuredBlog' => $featuredBlog,
  105.             'currentPage'  => $page,
  106.             'totalPages'   => $totalPages,
  107.             'totalBlogs'   => $totalBlogs,
  108.         ]);
  109.     }
  110.     // product
  111.     public function CentralProductPageAction()
  112.     {
  113.         return $this->render('@HoneybeeWeb/pages/product.html.twig', array(
  114.             'page_title' => 'Product',
  115.         ));
  116.     }
  117.     // our service
  118.     public function CentralServicePageAction()
  119.     {
  120.         return $this->render('@HoneybeeWeb/pages/service.html.twig', array(
  121.             'page_title' => 'Our Services',
  122.         ));
  123.     }
  124.     // payment method
  125.     public function CentralPaymentMethodPageAction()
  126.     {
  127.         return $this->render('@HoneybeeWeb/pages/payment-method.html.twig', array(
  128.             'page_title' => 'Payment Method',
  129.         ));
  130.     }
  131.     // single blog page
  132.     public function CentralSingleBlogPageAction(Request $request)
  133.     {
  134.         $em $this->getDoctrine()->getManager('company_group');
  135.         $blogId $request->query->get('id');
  136.         if (!$blogId) {
  137.             throw $this->createNotFoundException('Blog ID not provided.');
  138.         }
  139.         $blogDetails $em->getRepository('CompanyGroupBundle\Entity\EntityCreateBlog')->find($blogId);
  140.         if (!$blogDetails) {
  141.             throw $this->createNotFoundException('Blog not found.');
  142.         }
  143.         // Fetch related blogs by same topic (optional but useful)
  144.         $relatedBlogs $em->getRepository('CompanyGroupBundle\Entity\EntityCreateBlog')->findBy(
  145.             ['topicId' => $blogDetails->getTopicId()],
  146.             ['createdAt' => 'DESC'],
  147.             5
  148.         );
  149.         return $this->render('@HoneybeeWeb/pages/single_blog.html.twig', [
  150.             'page_title' => $blogDetails->getTitle(),
  151.             'blog'       => $blogDetails,
  152.             'related_blogs' => $relatedBlogs,
  153.         ]);
  154.     }
  155.     // login v2 (verification code page)
  156.     public function CentralLoginCodePageAction()
  157.     {
  158.         return $this->render('@HoneybeeWeb/pages/login_code.html.twig', array(
  159.             'page_title' => 'Verification Code',
  160.         ));
  161.     }
  162.     // reset pass
  163.     public function CentralResetPasswordPageAction()
  164.     {
  165.         return $this->render('@HoneybeeWeb/pages/reset_password.html.twig', array(
  166.             'page_title' => 'Verification Code',
  167.         ));
  168.     }
  169.     public function PublicProfilePageAction(Request $request$id 0)
  170.     {
  171.         $em $this->getDoctrine()->getManager('company_group');
  172.         $session $request->getSession();
  173.         return $this->render('@Application/pages/central/central_employee_profile.html.twig', array(
  174.             'page_title' => 'Freelancer Profile',
  175. //            'details' =>$em->getRepository(EntityApplicantDetails::class)->find($id),
  176.         ));
  177.     }
  178.     // freelancer profile
  179.     public function CentralApplicantProfilePageAction(Request $request$id 0)
  180.     {
  181.         $em $this->getDoctrine()->getManager('company_group');
  182.         $session $request->getSession();
  183.         return $this->render('@HoneybeeWeb/pages/freelancer_profile.html.twig', array(
  184.             'page_title' => 'Freelancer Profile',
  185.             'details' => $em->getRepository(EntityApplicantDetails::class)->find($id),
  186.         ));
  187.     }
  188.     // employee profile
  189.     public function PublicEmployeeProfileAction($id)
  190.     {
  191.         $em $this->getDoctrine()->getManager('company_group');
  192.         if (strpos($id'E') !== false) {
  193.             $appId substr($id15);
  194.             $empId substr($id610);
  195.             $entry $em->getRepository('CompanyGroupBundle\\Entity\\CompanyGroup')->findOneBy([
  196.                 'appId' => $appId
  197.             ]);
  198.             $curl curl_init();
  199.             curl_setopt_array($curl, [
  200.                 CURLOPT_RETURNTRANSFER => true,
  201.                 CURLOPT_POST => true,
  202.                 CURLOPT_URL => $entry->getCompanyGroupServerAddress() . '/GetGlobalIdFromEmployeeId',
  203.                 CURLOPT_CONNECTTIMEOUT => 10,
  204.                 CURLOPT_SSL_VERIFYPEER => false,
  205.                 CURLOPT_SSL_VERIFYHOST => false,
  206.                 CURLOPT_HTTPHEADER => [
  207.                     'Accept: application/json',
  208. //                    'Content-Type: application/json'
  209.                 ],
  210.                 CURLOPT_POSTFIELDS => http_build_query([
  211.                     'employeeId' => $empId,
  212.                     'appId' => $appId
  213.                 ])
  214.             ]);
  215.             $id curl_exec($curl);
  216.             $err curl_error($curl);
  217.             curl_close($curl);
  218.             $id json_decode($idtrue)['globalId'];
  219.         }
  220.         $data $em->getRepository(EntityApplicantDetails::class)->find($id);
  221.         return $this->render('@HoneybeeWeb/pages/public_profile.html.twig', array(
  222.             'page_title' => 'Employee Profile',
  223.             'details' => $data,
  224.             'genderList' => EmployeeConstant::$sex,
  225.             'bloodGroupList' => EmployeeConstant::$BloodGroup,
  226.         ));
  227.     }
  228.     // add employee
  229.     public function CentralAddEmployeePageAction()
  230.     {
  231.         return $this->render('@HoneybeeWeb/pages/add_employee.html.twig', array(
  232.             'page_title' => 'Add New Eployee',
  233.         ));
  234.     }
  235.     // book appointment
  236.     public function CentralBookAppointmentPageAction()
  237.     {
  238.         return $this->render('@HoneybeeWeb/pages/book_appointment.html.twig', array(
  239.             'page_title' => 'Book Appointment',
  240.         ));
  241.     }
  242.     // create_compnay
  243.     public function CentralCreateCompanyPageAction()
  244.     {
  245.         return $this->render('@HoneybeeWeb/pages/create_company.html.twig', array(
  246.             'page_title' => 'Create Company',
  247.         ));
  248.     }
  249.     // role and company
  250.     public function CentralRoleAndCompanyPageAction()
  251.     {
  252.         return $this->render('@HoneybeeWeb/pages/role_and_company.html.twig', array(
  253.             'page_title' => 'Role and Company',
  254.         ));
  255.     }
  256.     // send otp action **
  257.     public function SendOtpAjaxAction(Request $request$startFrom 0)
  258.     {
  259.         $em $this->getDoctrine()->getManager();
  260.         $em_goc $this->getDoctrine()->getManager('company_group');
  261.         $session $request->getSession();
  262.         $message "";
  263.         $retData = array();
  264.         $email_twig_data = array('success' => false);
  265.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  266.         $userCategory $request->request->get('userCategory'$request->query->get('userCategory''_BUDDYBEE_USER_'));
  267.         $email_address $request->request->get('email'$request->query->get('email'''));
  268.         $otpExpireSecond $request->request->get('otpExpireSecond'$request->query->get('otpExpireSecond'180));
  269.         $otpActionId $request->request->get('otpActionId'$request->query->get('otpActionId'UserConstants::OTP_ACTION_FORGOT_PASSWORD));
  270.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  271.         $otp $request->request->get('otp'$request->query->get('otp'''));
  272.         $otpExpireTs 0;
  273.         $userId $request->request->get('userId'$request->query->get('userId'$session->get(UserConstants::USER_ID0)));
  274.         $userType UserConstants::USER_TYPE_APPLICANT;
  275.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  276.         if ($request->isMethod('POST')) {
  277.             //set an otp and its expire and send mail
  278.             $userObj null;
  279.             $userData = [];
  280.             if ($systemType == '_ERP_') {
  281.                 if ($userCategory == '_APPLICANT_') {
  282.                     $userType UserConstants::USER_TYPE_APPLICANT;
  283.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  284.                         array(
  285.                             'applicantId' => $userId
  286.                         )
  287.                     );
  288.                     if ($userObj) {
  289.                     } else {
  290.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  291.                             array(
  292.                                 'email' => $email_address
  293.                             )
  294.                         );
  295.                         if ($userObj) {
  296.                         } else {
  297.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  298.                                 array(
  299.                                     'oAuthEmail' => $email_address
  300.                                 )
  301.                             );
  302.                             if ($userObj) {
  303.                             } else {
  304.                                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  305.                                     array(
  306.                                         'username' => $email_address
  307.                                     )
  308.                                 );
  309.                             }
  310.                         }
  311.                     }
  312.                     if ($userObj) {
  313.                         $email_address $userObj->getEmail();
  314.                         if ($email_address == null || $email_address == '')
  315.                             $email_address $userObj->getOAuthEmail();
  316.                     }
  317.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  318.                     $otp $otpData['otp'];
  319.                     $otpExpireTs $otpData['expireTs'];
  320.                     $userObj->setOtp($otpData['otp']);
  321.                     $userObj->setOtpActionId($otpActionId);
  322.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  323.                     $em_goc->flush();
  324.                     $userData = array(
  325.                         'id' => $userObj->getApplicantId(),
  326.                         'email' => $email_address,
  327.                         'appId' => 0,
  328.                         //                        'appId'=>$userObj->getUserAppId(),
  329.                     );
  330.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  331.                     $email_twig_data = [
  332.                         'page_title' => 'Find Account',
  333.                         'message' => $message,
  334.                         'userType' => $userType,
  335.                         'otp' => $otpData['otp'],
  336.                         'otpExpireSecond' => $otpExpireSecond,
  337.                         'otpActionId' => $otpActionId,
  338.                         'otpExpireTs' => $otpData['expireTs'],
  339.                         'systemType' => $systemType,
  340.                         'userData' => $userData
  341.                     ];
  342.                     if ($userObj)
  343.                         $email_twig_data['success'] = true;
  344.                 } else {
  345.                     $userType UserConstants::USER_TYPE_GENERAL;
  346.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  347.                     $email_twig_data = [
  348.                         'page_title' => 'Find Account',
  349.                         //   'encryptedData' => $encryptedData,
  350.                         'message' => $message,
  351.                         'userType' => $userType,
  352.                         //  'errorField' => $errorField,
  353.                     ];
  354.                 }
  355.             } else if ($systemType == '_BUDDYBEE_') {
  356.                 $userType UserConstants::USER_TYPE_APPLICANT;
  357.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  358.                     array(
  359.                         'applicantId' => $userId
  360.                     )
  361.                 );
  362.                 if ($userObj) {
  363.                 } else {
  364.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  365.                         array(
  366.                             'email' => $email_address
  367.                         )
  368.                     );
  369.                     if ($userObj) {
  370.                     } else {
  371.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  372.                             array(
  373.                                 'oAuthEmail' => $email_address
  374.                             )
  375.                         );
  376.                         if ($userObj) {
  377.                         } else {
  378.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  379.                                 array(
  380.                                     'username' => $email_address
  381.                                 )
  382.                             );
  383.                         }
  384.                     }
  385.                 }
  386.                 if ($userObj) {
  387.                     $email_address $userObj->getEmail();
  388.                     if ($email_address == null || $email_address == '')
  389.                         $email_address $userObj->getOAuthEmail();
  390.                     //                    triggerResetPassword:
  391.                     //                    type: integer
  392.                     //                          nullable: true
  393.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  394.                     $otp $otpData['otp'];
  395.                     $otpExpireTs $otpData['expireTs'];
  396.                     $userObj->setOtp($otpData['otp']);
  397.                     $userObj->setOtpActionId($otpActionId);
  398.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  399.                     $em_goc->flush();
  400.                     $userData = array(
  401.                         'id' => $userObj->getApplicantId(),
  402.                         'email' => $email_address,
  403.                         'appId' => 0,
  404.                         'image' => $userObj->getImage(),
  405.                         'phone' => $userObj->getPhone(),
  406.                         'firstName' => $userObj->getFirstname(),
  407.                         'lastName' => $userObj->getLastname(),
  408.                         //                        'appId'=>$userObj->getUserAppId(),
  409.                     );
  410.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  411.                     $email_twig_data = [
  412.                         'page_title' => 'Find Account',
  413.                         //                        'encryptedData' => $encryptedData,
  414.                         'message' => $message,
  415.                         'userType' => $userType,
  416.                         //                        'errorField' => $errorField,
  417.                         'otp' => $otpData['otp'],
  418.                         'otpExpireSecond' => $otpExpireSecond,
  419.                         'otpActionId' => $otpActionId,
  420.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[$otpActionId]['actionTitle'],
  421.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[$otpActionId]['actionDescForMail'],
  422.                         'otpExpireTs' => $otpData['expireTs'],
  423.                         'systemType' => $systemType,
  424.                         'userCategory' => $userCategory,
  425.                         'userData' => $userData
  426.                     ];
  427.                     $email_twig_data['success'] = true;
  428.                 } else {
  429.                     $message "Account not found!";
  430.                     $email_twig_data['success'] = false;
  431.                 }
  432.             } else if ($systemType == '_CENTRAL_') {
  433.                 $userType UserConstants::USER_TYPE_APPLICANT;
  434.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  435.                     array(
  436.                         'applicantId' => $userId
  437.                     )
  438.                 );
  439.                 if ($userObj) {
  440.                 } else {
  441.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  442.                         array(
  443.                             'email' => $email_address
  444.                         )
  445.                     );
  446.                     if ($userObj) {
  447.                     } else {
  448.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  449.                             array(
  450.                                 'oAuthEmail' => $email_address
  451.                             )
  452.                         );
  453.                         if ($userObj) {
  454.                         } else {
  455.                             $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  456.                                 array(
  457.                                     'username' => $email_address
  458.                                 )
  459.                             );
  460.                         }
  461.                     }
  462.                 }
  463.                 if ($userObj) {
  464.                     $email_address $userObj->getEmail();
  465.                     if ($email_address == null || $email_address == '')
  466.                         $email_address $userObj->getOAuthEmail();
  467.                     //                    triggerResetPassword:
  468.                     //                    type: integer
  469.                     //                          nullable: true
  470.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  471.                     $otp $otpData['otp'];
  472.                     $otpExpireTs $otpData['expireTs'];
  473.                     $userObj->setOtp($otpData['otp']);
  474.                     $userObj->setOtpActionId($otpActionId);
  475.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  476.                     $em_goc->flush();
  477.                     $userData = array(
  478.                         'id' => $userObj->getApplicantId(),
  479.                         'email' => $email_address,
  480.                         'appId' => 0,
  481.                         'image' => $userObj->getImage(),
  482.                         'phone' => $userObj->getPhone(),
  483.                         'firstName' => $userObj->getFirstname(),
  484.                         'lastName' => $userObj->getLastname(),
  485.                         //                        'appId'=>$userObj->getUserAppId(),
  486.                     );
  487.                     $email_twig_file '@HoneybeeWeb/email/templates/otpMail.html.twig';
  488.                     $email_twig_data = [
  489.                         'page_title' => 'Find Account',
  490.                         //                        'encryptedData' => $encryptedData,
  491.                         'message' => $message,
  492.                         'userType' => $userType,
  493.                         //                        'errorField' => $errorField,
  494.                         'otp' => $otpData['otp'],
  495.                         'otpExpireSecond' => $otpExpireSecond,
  496.                         'otpActionId' => $otpActionId,
  497.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[$otpActionId]['actionTitle'],
  498.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[$otpActionId]['actionDescForMail'],
  499.                         'otpExpireTs' => $otpData['expireTs'],
  500.                         'systemType' => $systemType,
  501.                         'userCategory' => $userCategory,
  502.                         'userData' => $userData
  503.                     ];
  504.                     $email_twig_data['success'] = true;
  505.                 } else {
  506.                     $message "Account not found!";
  507.                     $email_twig_data['success'] = false;
  508.                 }
  509.             }
  510.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  511.                 if ($systemType == '_BUDDYBEE_') {
  512.                     $bodyHtml '';
  513.                     $bodyTemplate $email_twig_file;
  514.                     $bodyData $email_twig_data;
  515.                     $attachments = [];
  516.                     $forwardToMailAddress $email_address;
  517.                     //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  518.                     $new_mail $this->get('mail_module');
  519.                     $new_mail->sendMyMail(array(
  520.                         'senderHash' => '_CUSTOM_',
  521.                         //                        'senderHash'=>'_CUSTOM_',
  522.                         'forwardToMailAddress' => $forwardToMailAddress,
  523.                         'subject' => 'Account Verification',
  524.                         //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  525.                         'attachments' => $attachments,
  526.                         'toAddress' => $forwardToMailAddress,
  527.                         'fromAddress' => 'no-reply@buddybee.eu',
  528.                         'userName' => 'no-reply@buddybee.eu',
  529.                         'password' => 'Honeybee@0112',
  530.                         'smtpServer' => 'smtp.hostinger.com',
  531.                         'smtpPort' => 465,
  532.                         //                            'emailBody' => $bodyHtml,
  533.                         'mailTemplate' => $bodyTemplate,
  534.                         'templateData' => $bodyData,
  535.                         //                        'embedCompanyImage' => 1,
  536.                         //                        'companyId' => $companyId,
  537.                         //                        'companyImagePath' => $company_data->getImage()
  538.                     ));
  539.                 } else {
  540.                     $bodyHtml '';
  541.                     $bodyTemplate $email_twig_file;
  542.                     $bodyData $email_twig_data;
  543.                     $attachments = [];
  544.                     $forwardToMailAddress $email_address;
  545.                     //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  546.                     $new_mail $this->get('mail_module');
  547.                     $new_mail->sendMyMail(array(
  548.                         'senderHash' => '_CUSTOM_',
  549.                         //                        'senderHash'=>'_CUSTOM_',
  550.                         'forwardToMailAddress' => $forwardToMailAddress,
  551.                         'subject' => 'Account Verification',
  552.                         //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  553.                         'attachments' => $attachments,
  554.                         'toAddress' => $forwardToMailAddress,
  555.                         'fromAddress' => 'no-reply@buddybee.eu',
  556.                         'userName' => 'no-reply@buddybee.eu',
  557.                         'password' => 'Honeybee@0112',
  558.                         'smtpServer' => 'smtp.hostinger.com',
  559.                         'smtpPort' => 465,
  560.                         //                            'emailBody' => $bodyHtml,
  561.                         'mailTemplate' => $bodyTemplate,
  562.                         'templateData' => $bodyData,
  563.                         //                        'embedCompanyImage' => 1,
  564.                         //                        'companyId' => $companyId,
  565.                         //                        'companyImagePath' => $company_data->getImage()
  566.                     ));
  567.                 }
  568.             }
  569.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  570.                 if ($systemType == '_BUDDYBEE_') {
  571.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  572.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  573.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  574.                      _APPEND_CODE_';
  575.                     $msg str_replace($searchVal$replaceVal$msg);
  576.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  577.                     $sendType 'all';
  578.                     $socketUserIds = [];
  579.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  580.                 } else {
  581.                 }
  582.             }
  583.         }
  584.         $response = new JsonResponse(array(
  585.                 'message' => $message,
  586.                 "userType" => $userType,
  587.                 "otp" => '',
  588.                 //                "otp"=>$otp,
  589.                 "otpExpireTs" => $otpExpireTs,
  590.                 "otpActionId" => $otpActionId,
  591.                 "userCategory" => $userCategory,
  592.                 "userId" => isset($userData['id']) ? $userData['id'] : 0,
  593.                 "systemType" => $systemType,
  594.                 'actionData' => $email_twig_data,
  595.                 'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  596.             )
  597.         );
  598.         $response->headers->set('Access-Control-Allow-Origin''*');
  599.         return $response;
  600.     }
  601.     // verrify otp **
  602.     public function VerifyOtpAction(Request $request$encData '')
  603.     {
  604.         $em $this->getDoctrine()->getManager();
  605.         $em_goc $this->getDoctrine()->getManager('company_group');
  606.         $session $request->getSession();
  607.         $message "";
  608.         $retData = array();
  609.         $encData $request->query->get('encData'$encData);
  610.         $encryptedData = [];
  611.         if ($encData != '')
  612.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  613.         if ($encryptedData == null$encryptedData = [];
  614.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  615.         $userCategory $request->request->get('userCategory'$request->query->get('userCategory', (isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_')));
  616.         $email_address $request->request->get('email'$request->query->get('email', (isset($encryptedData['email']) ? $encryptedData['email'] : '')));
  617.         $otpExpireSecond $request->request->get('otpExpireSecond'$request->query->get('otpExpireSecond'180));
  618.         $otpActionId $request->request->get('otpActionId'$request->query->get('otpActionId', (isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : UserConstants::OTP_ACTION_FORGOT_PASSWORD)));
  619.         $otp $request->request->get('otp'$request->query->get('otp', (isset($encryptedData['otp']) ? $encryptedData['otp'] : '')));
  620.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  621.         $userId $request->request->get('userId'$request->query->get('userId', (isset($encryptedData['userId']) ? $encryptedData['userId'] : $session->get(UserConstants::USER_ID0))));
  622.         $userType UserConstants::USER_TYPE_APPLICANT;
  623.         $userEntity 'CompanyGroupBundle\\Entity\\EntityApplicantDetails';
  624.         $userEntityManager $em_goc;
  625.         $userEntityIdField 'applicantId';
  626.         $userEntityUserNameField 'username';
  627.         $userEntityEmailField1 'email';
  628.         $userEntityEmailField1Getter 'getEmail';
  629.         $userEntityEmailField1Setter 'setEmail';
  630.         $userEntityEmailField2 'oAuthEmail';
  631.         $userEntityEmailField2Getter 'geOAuthEmail';
  632.         $userEntityEmailField2Setter 'seOAuthEmail';
  633.         $twig_file '@HoneybeeWeb/pages/views/verify_otp_honeybee.html.twig';
  634.         $twigData = [];
  635.         $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  636.         $email_twig_data = array('success' => false);
  637.         $redirectUrl '';
  638.         $userObj null;
  639.         $userData = [];
  640.         if ($systemType == '_ERP_') {
  641.             if ($userCategory == '_APPLICANT_') {
  642.                 $userType UserConstants::USER_TYPE_APPLICANT;
  643.                 $twig_file '@HoneybeeWeb/pages/views/verify_otp_honeybee.html.twig';
  644.                 $twigData = [];
  645.                 $userEntity 'CompanyGroupBundle\\Entity\\EntityApplicantDetails';
  646.                 $userEntityManager $em_goc;
  647.                 $userEntityIdField 'applicantId';
  648.                 $userEntityUserNameField 'username';
  649.                 $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  650.                 //    $email_twig_file = 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  651.             } else {
  652.                 $userType UserConstants::USER_TYPE_GENERAL;
  653.                 $twig_file '@HoneybeeWeb/pages/views/verify_otp_honeybee.html.twig';
  654.                 $twigData = [];
  655.                 $userEntity 'ApplicationBundle:SysUser';
  656.                 $userEntityManager $em;
  657.                 $userEntityIdField 'userId';
  658.                 $userEntityUserNameField 'userName';
  659.                 $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  660.                 //    $email_twig_file = 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  661.             }
  662.         } else if ($systemType == '_BUDDYBEE_') {
  663.             $userType UserConstants::USER_TYPE_APPLICANT;
  664.             $twig_file '@HoneybeeWeb/pages/views/verify_otp_honeybee.html.twig';
  665.             $twigData = [];
  666.             $userEntity 'CompanyGroupBundle\\Entity\\EntityApplicantDetails';
  667.             $userEntityManager $em_goc;
  668.             $userEntityIdField 'applicantId';
  669.             $userEntityUserNameField 'username';
  670.             $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  671.             //            $email_twig_file = 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  672.         } else if ($systemType == '_CENTRAL_') {
  673.             $userType UserConstants::USER_TYPE_APPLICANT;
  674.             $twig_file '@HoneybeeWeb/pages/views/verify_otp_honeybee.html.twig';
  675.             $twigData = [];
  676.             $userEntity 'CompanyGroupBundle\\Entity\\EntityApplicantDetails';
  677.             $userEntityManager $em_goc;
  678.             $userEntityIdField 'applicantId';
  679.             $userEntityUserNameField 'username';
  680.             //            $email_twig_file = 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  681.         }
  682.         if ($request->isMethod('POST') || $otp != '') {
  683.             $userObj $userEntityManager->getRepository($userEntity)->findOneBy(
  684.                 array(
  685.                     $userEntityIdField => $userId
  686.                 )
  687.             );
  688.             if ($userObj) {
  689.             } else {
  690.                 $userObj $userEntityManager->getRepository($userEntity)->findOneBy(
  691.                     array(
  692.                         $userEntityEmailField1 => $email_address
  693.                     )
  694.                 );
  695.                 if ($userObj) {
  696.                 } else {
  697.                     $userObj $userEntityManager->getRepository($userEntity)->findOneBy(
  698.                         array(
  699.                             $userEntityEmailField2 => $email_address
  700.                         )
  701.                     );
  702.                     if ($userObj) {
  703.                     } else {
  704.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  705.                             array(
  706.                                 $userEntityUserNameField => $email_address
  707.                             )
  708.                         );
  709.                     }
  710.                 }
  711.             }
  712.             if ($userObj) {
  713.                 $userOtp $userObj->getOtp();
  714.                 $userOtpActionId $userObj->getOtpActionId();
  715.                 $userOtpExpireTs $userObj->getOtpExpireTs();
  716.                 $currentTime = new \DateTime();
  717.                 $currentTimeTs $currentTime->format('U');
  718.                 $userData = array(
  719.                     'id' => $userObj->getApplicantId(),
  720.                     'email' => $email_address,
  721.                     'appId' => 0,
  722.                     'image' => $userObj->getImage(),
  723.                     'firstName' => $userObj->getFirstname(),
  724.                     'lastName' => $userObj->getLastname(),
  725.                     //                        'appId'=>$userObj->getUserAppId(),
  726.                 );
  727.                 $email_twig_data = [
  728.                     'page_title' => 'OTP',
  729.                     'success' => false,
  730.                     //                        'encryptedData' => $encryptedData,
  731.                     'message' => $message,
  732.                     'userType' => $userType,
  733.                     //                        'errorField' => $errorField,
  734.                     'otp' => '',
  735.                     'otpExpireSecond' => $otpExpireSecond,
  736.                     'otpActionId' => $otpActionId,
  737.                     'otpExpireTs' => $userOtpExpireTs,
  738.                     'systemType' => $systemType,
  739.                     'userCategory' => $userCategory,
  740.                     'userData' => $userData,
  741.                     "email" => $email_address,
  742.                     "userId" => isset($userData['id']) ? $userData['id'] : 0,
  743.                 ];
  744.                 if ($otp == '0112') {
  745.                     $userObj->setOtp(0);
  746.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  747.                     $userObj->setOtpExpireTs(0);
  748.                     $userObj->setTriggerResetPassword(1);
  749.                     $em_goc->flush();
  750.                     $email_twig_data['success'] = true;
  751.                     $message "";
  752.                 } else if ($userOtp != $otp) {
  753.                     $message "Invalid OTP!";
  754.                     $email_twig_data['success'] = false;
  755.                     $redirectUrl "";
  756.                 } else if ($userOtpActionId != $otpActionId) {
  757.                     $message "Invalid OTP Action!";
  758.                     $email_twig_data['success'] = false;
  759.                     $redirectUrl "";
  760.                 } else if ($currentTimeTs $userOtpExpireTs) {
  761.                     $message "OTP Expired!";
  762.                     $email_twig_data['success'] = false;
  763.                     $redirectUrl "";
  764.                 } else {
  765.                     if ($otpActionId == UserConstants::OTP_ACTION_FORGOT_PASSWORD) {
  766.                         $userObj->setTriggerResetPassword(1);
  767.                         $userObj->setIsTemporaryEntry(0);
  768.                     }
  769.                     if ($otpActionId == UserConstants::OTP_ACTION_CONFIRM_EMAIL) {
  770.                         $userObj->setIsEmailVerified(1);
  771.                         $userObj->setIsTemporaryEntry(0);
  772.                         $session->set('IS_EMAIL_VERIFIED'1);
  773.                         $new_ccs $em_goc
  774.                             ->getRepository('CompanyGroupBundle\\Entity\\EntityTokenStorage')
  775.                             ->findBy(
  776.                                 array(
  777.                                     'userId' => $session->get('userId')
  778.                                 )
  779.                             );
  780.                         foreach ($new_ccs as $new_cc) {
  781.                             $session_data json_decode($new_cc->getSessionData(), true);
  782.                             $session_data['IS_EMAIL_VERIFIED'] = 1;
  783.                             $updated_session_data json_encode($session_data);
  784.                             $new_cc->setSessionData($updated_session_data);
  785.                             $em_goc->persist($new_cc);
  786.                         }
  787.                     }
  788.                     $userObj->setOtp(0);
  789.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  790.                     $userObj->setOtpExpireTs(0);
  791.                     $em_goc->flush();
  792.                     $email_twig_data['success'] = true;
  793.                     $message "";
  794.                 }
  795.             } else {
  796.                 $message "Account not found!";
  797.                 $redirectUrl "";
  798.                 $email_twig_data['success'] = false;
  799.             }
  800.         }
  801.         $twigData = array(
  802.             'page_title' => 'OTP Verification',
  803.             'message' => $message,
  804.             "userType" => $userType,
  805.             "userData" => $userData,
  806.             "otp" => '',
  807.             "redirectUrl" => $redirectUrl,
  808.             "email" => $email_address,
  809.             "otpExpireTs" => $otpExpireTs,
  810.             "otpActionId" => $otpActionId,
  811.             "userCategory" => $userCategory,
  812.             "userId" => isset($userData['id']) ? $userData['id'] : 0,
  813.             "systemType" => $systemType,
  814.             'actionData' => $email_twig_data,
  815.             'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  816.         );
  817.         $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  818.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  819.             $twigData['encData'] = $encDataStr;
  820.             $response = new JsonResponse($twigData);
  821.             $response->headers->set('Access-Control-Allow-Origin''*');
  822.             return $response;
  823.         } else if ($twigData['success'] == true) {
  824.             $encData = array(
  825.                 "userType" => $userType,
  826.                 "otp" => '',
  827.                 'message' => $message,
  828.                 "otpExpireTs" => $otpExpireTs,
  829.                 "otpActionId" => $otpActionId,
  830.                 "userCategory" => $userCategory,
  831.                 "userId" => $userData['id'],
  832.                 "systemType" => $systemType,
  833.             );
  834.             $redirectRoute UserConstants::$OTP_ACTION_DATA[$otpActionId]['redirectRoute'];
  835.             if ($redirectRoute == '') {
  836.                 $redirectRoute 'dashboard';
  837.             }
  838.             if ($redirectRoute == 'dashboard') {
  839.                 $url $this->generateUrl($redirectRoute, ['_fragment' => null], UrlGeneratorInterface::ABSOLUTE_URL);
  840.                 $redirectUrl $url '?data=' urlencode($encDataStr);
  841.             } else {
  842.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  843.                 $url $this->generateUrl(
  844.                     $redirectRoute
  845.                 );
  846.                 $redirectUrl $url "/" $encDataStr;
  847.             }
  848.             return $this->redirect($redirectUrl);
  849. //            $encDataStr = $this->get('url_encryptor')->encrypt(json_encode($encData));
  850. //            $url = $this->generateUrl(
  851. //                'central_landing'
  852. //            );
  853. //            $redirectUrl = $url . "/" . $encDataStr;
  854. //            return $this->redirect($redirectUrl);
  855.         } else {
  856.             return $this->render(
  857.                 $twig_file,
  858.                 $twigData
  859.             );
  860.         }
  861.     }
  862.     public function VerifyOtpWebAction(Request $request$encData '')
  863.     {
  864.         $em $this->getDoctrine()->getManager();
  865.         $em_goc $this->getDoctrine()->getManager('company_group');
  866.         $session $request->getSession();
  867.         $message "";
  868.         $retData = array();
  869.         $encData $request->query->get('encData'$encData);
  870.         $encryptedData = [];
  871.         if ($encData != '')
  872.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  873.         if ($encryptedData == null$encryptedData = [];
  874.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  875.         $userCategory $request->request->get('userCategory'$request->query->get('userCategory', (isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_')));
  876.         $email_address $request->request->get('email'$request->query->get('email', (isset($encryptedData['email']) ? $encryptedData['email'] : '')));
  877.         $otpExpireSecond $request->request->get('otpExpireSecond'$request->query->get('otpExpireSecond'180));
  878.         $otpActionId $request->request->get('otpActionId'$request->query->get('otpActionId', (isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : UserConstants::OTP_ACTION_FORGOT_PASSWORD)));
  879.         $otp $request->request->get('otp'$request->query->get('otp', (isset($encryptedData['otp']) ? $encryptedData['otp'] : '')));
  880.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  881.         $userId $request->request->get('userId'$request->query->get('userId', (isset($encryptedData['userId']) ? $encryptedData['userId'] : $session->get(UserConstants::USER_ID0))));
  882.         $userType UserConstants::USER_TYPE_APPLICANT;
  883.         $userEntity 'CompanyGroupBundle\\Entity\\EntityApplicantDetails';
  884.         $userEntityManager $em_goc;
  885.         $userEntityIdField 'applicantId';
  886.         $userEntityUserNameField 'username';
  887.         $userEntityEmailField1 'email';
  888.         $userEntityEmailField1Getter 'getEmail';
  889.         $userEntityEmailField1Setter 'setEmail';
  890.         $userEntityEmailField2 'oAuthEmail';
  891.         $userEntityEmailField2Getter 'geOAuthEmail';
  892.         $userEntityEmailField2Setter 'seOAuthEmail';
  893.         $twig_file '@HoneybeeWeb/pages/views/verify_otp_honeybee.html.twig';
  894.         $twigData = [];
  895.         $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  896.         $email_twig_data = array('success' => false);
  897.         $redirectUrl '';
  898.         $userObj null;
  899.         $userData = [];
  900.         if ($systemType == '_ERP_') {
  901.             if ($userCategory == '_APPLICANT_') {
  902.                 $userType UserConstants::USER_TYPE_APPLICANT;
  903.                 $twig_file '@HoneybeeWeb/pages/views/verify_otp_honeybee.html.twig';
  904.                 $twigData = [];
  905.                 $userEntity 'CompanyGroupBundle\\Entity\\EntityApplicantDetails';
  906.                 $userEntityManager $em_goc;
  907.                 $userEntityIdField 'applicantId';
  908.                 $userEntityUserNameField 'username';
  909.                 $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  910.                 //    $email_twig_file = 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  911.             } else {
  912.                 $userType UserConstants::USER_TYPE_GENERAL;
  913.                 $twig_file '@HoneybeeWeb/pages/views/verify_otp_honeybee.html.twig';
  914.                 $twigData = [];
  915.                 $userEntity 'ApplicationBundle:SysUser';
  916.                 $userEntityManager $em;
  917.                 $userEntityIdField 'userId';
  918.                 $userEntityUserNameField 'userName';
  919.                 $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  920.                 //    $email_twig_file = 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  921.             }
  922.         } else if ($systemType == '_BUDDYBEE_') {
  923.             $userType UserConstants::USER_TYPE_APPLICANT;
  924.             $twig_file '@HoneybeeWeb/pages/views/verify_otp_honeybee.html.twig';
  925.             $twigData = [];
  926.             $userEntity 'CompanyGroupBundle\\Entity\\EntityApplicantDetails';
  927.             $userEntityManager $em_goc;
  928.             $userEntityIdField 'applicantId';
  929.             $userEntityUserNameField 'username';
  930.             $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  931.             //            $email_twig_file = 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  932.         } else if ($systemType == '_CENTRAL_') {
  933.             $userType UserConstants::USER_TYPE_APPLICANT;
  934.             $twig_file '@HoneybeeWeb/pages/views/verify_otp_honeybee.html.twig';
  935.             $twigData = [];
  936.             $userEntity 'CompanyGroupBundle\\Entity\\EntityApplicantDetails';
  937.             $userEntityManager $em_goc;
  938.             $userEntityIdField 'applicantId';
  939.             $userEntityUserNameField 'username';
  940.             $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  941.             //            $email_twig_file = 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  942.         }
  943.         if ($request->isMethod('POST') || $otp != '') {
  944.             $userObj $userEntityManager->getRepository($userEntity)->findOneBy(
  945.                 array(
  946.                     $userEntityIdField => $userId
  947.                 )
  948.             );
  949.             if ($userObj) {
  950.             } else {
  951.                 $userObj $userEntityManager->getRepository($userEntity)->findOneBy(
  952.                     array(
  953.                         $userEntityEmailField1 => $email_address
  954.                     )
  955.                 );
  956.                 if ($userObj) {
  957.                 } else {
  958.                     $userObj $userEntityManager->getRepository($userEntity)->findOneBy(
  959.                         array(
  960.                             $userEntityEmailField2 => $email_address
  961.                         )
  962.                     );
  963.                     if ($userObj) {
  964.                     } else {
  965.                         $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  966.                             array(
  967.                                 $userEntityUserNameField => $email_address
  968.                             )
  969.                         );
  970.                     }
  971.                 }
  972.             }
  973.             if ($userObj) {
  974.                 $userOtp $userObj->getOtp();
  975.                 $userOtpActionId $userObj->getOtpActionId();
  976.                 $userOtpExpireTs $userObj->getOtpExpireTs();
  977.                 $currentTime = new \DateTime();
  978.                 $currentTimeTs $currentTime->format('U');
  979.                 $userData = array(
  980.                     'id' => $userObj->getApplicantId(),
  981.                     'email' => $email_address,
  982.                     'appId' => 0,
  983.                     'image' => $userObj->getImage(),
  984.                     'firstName' => $userObj->getFirstname(),
  985.                     'lastName' => $userObj->getLastname(),
  986.                     //                        'appId'=>$userObj->getUserAppId(),
  987.                 );
  988.                 $email_twig_data = [
  989.                     'page_title' => 'OTP',
  990.                     'success' => false,
  991.                     //                        'encryptedData' => $encryptedData,
  992.                     'message' => $message,
  993.                     'userType' => $userType,
  994.                     //                        'errorField' => $errorField,
  995.                     'otp' => '',
  996.                     'otpExpireSecond' => $otpExpireSecond,
  997.                     'otpActionId' => $otpActionId,
  998.                     'otpExpireTs' => $userOtpExpireTs,
  999.                     'systemType' => $systemType,
  1000.                     'userCategory' => $userCategory,
  1001.                     'userData' => $userData,
  1002.                     "email" => $email_address,
  1003.                     "userId" => isset($userData['id']) ? $userData['id'] : 0,
  1004.                 ];
  1005.                 if ($otp == '0112') {
  1006.                     $userObj->setOtp(0);
  1007.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  1008.                     $userObj->setOtpExpireTs(0);
  1009.                     $userObj->setTriggerResetPassword(1);
  1010.                     $em_goc->flush();
  1011.                     $email_twig_data['success'] = true;
  1012.                     $message "";
  1013.                 } else if ($userOtp != $otp) {
  1014.                     $message "Invalid OTP!";
  1015.                     $email_twig_data['success'] = false;
  1016.                     $redirectUrl "";
  1017.                 } else if ($userOtpActionId != $otpActionId) {
  1018.                     $message "Invalid OTP Action!";
  1019.                     $email_twig_data['success'] = false;
  1020.                     $redirectUrl "";
  1021.                 } else if ($currentTimeTs $userOtpExpireTs) {
  1022.                     $message "OTP Expired!";
  1023.                     $email_twig_data['success'] = false;
  1024.                     $redirectUrl "";
  1025.                 } else {
  1026.                     $userObj->setOtp(0);
  1027.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  1028.                     $userObj->setOtpExpireTs(0);
  1029.                     $userObj->setTriggerResetPassword(0);
  1030.                     $userObj->setIsEmailVerified(0);
  1031.                     $userObj->setIsTemporaryEntry(0);
  1032.                     $em_goc->flush();
  1033.                     $email_twig_data['success'] = true;
  1034.                     $message "";
  1035.                 }
  1036.             } else {
  1037.                 $message "Account not found!";
  1038.                 $redirectUrl "";
  1039.                 $email_twig_data['success'] = false;
  1040.             }
  1041.         }
  1042.         $twigData = array(
  1043.             'page_title' => 'OTP Verification',
  1044.             'message' => $message,
  1045.             "userType" => $userType,
  1046.             "userData" => $userData,
  1047.             "otp" => '',
  1048.             "redirectUrl" => $redirectUrl,
  1049.             "email" => $email_address,
  1050.             "otpExpireTs" => $otpExpireTs,
  1051.             "otpActionId" => $otpActionId,
  1052.             "userCategory" => $userCategory,
  1053.             "userId" => isset($userData['id']) ? $userData['id'] : 0,
  1054.             "systemType" => $systemType,
  1055.             'actionData' => $email_twig_data,
  1056.             'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  1057.         );
  1058.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  1059.             $response = new JsonResponse($twigData);
  1060.             $response->headers->set('Access-Control-Allow-Origin''*');
  1061.             return $response;
  1062.         } else if ($twigData['success'] == true) {
  1063.             $encData = array(
  1064.                 "userType" => $userType,
  1065.                 "otp" => '',
  1066.                 'message' => $message,
  1067.                 "otpExpireTs" => $otpExpireTs,
  1068.                 "otpActionId" => $otpActionId,
  1069.                 "userCategory" => $userCategory,
  1070.                 "userId" => $userData['id'],
  1071.                 "systemType" => $systemType,
  1072.             );
  1073. //            $encDataStr = $this->get('url_encryptor')->encrypt(json_encode($encData));
  1074. //            $url = $this->generateUrl(
  1075. //                UserConstants::$OTP_ACTION_DATA[$otpActionId]['redirectRoute']
  1076. //            );
  1077. //            $redirectUrl = $url . "/" . $encDataStr;
  1078. //            return $this->redirect($redirectUrl);
  1079.             $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  1080.             $url $this->generateUrl(
  1081.                 'central_landing'
  1082.             );
  1083.             $redirectUrl $url "/" $encDataStr;
  1084.             $this->addFlash('success''Email Verified!');
  1085.             return $this->redirect($redirectUrl);
  1086.         } else {
  1087.             return $this->render(
  1088.                 $twig_file,
  1089.                 $twigData
  1090.             );
  1091.         }
  1092.     }
  1093.     // reset new password **
  1094.     public function NewPasswordAction(Request $request$encData '')
  1095.     {
  1096.         //  $userCategory=$request->request->has('userCategory');
  1097.         $encryptedData = [];
  1098.         $errorField '';
  1099.         $message '';
  1100.         $userType '';
  1101.         $otpExpireSecond 180;
  1102.         $session $request->getSession();
  1103.         if ($encData == '')
  1104.             $encData $request->get('encData''');
  1105.         if ($encData != '')
  1106.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  1107.         //    $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  1108.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  1109.         $password = isset($encryptedData['password']) ? $encryptedData['password'] : 0;
  1110.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  1111.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : $session->get(UserConstants::USER_ID);
  1112.         $userCategory = isset($encryptedData['userCategory']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  1113.         //    $em = $this->getDoctrine()->getManager('company_group');
  1114.         $em_goc $this->getDoctrine()->getManager('company_group');
  1115.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  1116.         $twig_file 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
  1117.         $twigData = [];
  1118.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  1119.         $email_twig_data = [];
  1120.         if ($request->isMethod('POST')) {
  1121.             $otp $request->request->get('otp'$otp);
  1122.             $password $request->request->get('password'$password);
  1123.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  1124.             $userId $request->request->get('userId'$userId);
  1125.             $userCategory $request->request->get('userCategory'$userCategory);
  1126.             $email_address $request->request->get('email');
  1127.             if ($systemType == '_ERP_') {
  1128.                 $gocId $session->get(UserConstants::USER_GOC_ID);
  1129.                 if ($gocId != && $gocId != "") {
  1130.                     $gocDbName $session->get(UserConstants::USER_DB_NAME);
  1131.                     $gocDbUser $session->get(UserConstants::USER_DB_USER);
  1132.                     $gocDbPass $session->get(UserConstants::USER_DB_PASS);
  1133.                     $gocDbHost $session->get(UserConstants::USER_DB_HOST);
  1134.                     //     $connector = $this->container->get('application_connector');
  1135.                     $connector $this->container->get('application_connector');
  1136.                     $connector->resetConnection(
  1137.                         'default',
  1138.                         $gocDbName,
  1139.                         $gocDbUser,
  1140.                         $gocDbPass,
  1141.                         $gocDbHost,
  1142.                         $reset false);
  1143.                 }
  1144.                 $em $this->getDoctrine()->getManager();
  1145.                 if ($userCategory == '_APPLICANT_') {
  1146.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1147.                     $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1148.                         array(
  1149.                             'applicantId' => $userId
  1150.                         )
  1151.                     );
  1152.                     if ($userObj) {
  1153.                         if ($userObj->getTriggerResetPassword() == 1) {
  1154.                             $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$userObj->getSalt());
  1155.                             $userObj->setPassword($encodedPassword);
  1156.                             $userObj->setTempPassword('');
  1157.                             $userObj->setTriggerResetPassword(0);
  1158.                             $em_goc->flush();
  1159.                             $email_twig_data['success'] = true;
  1160.                             $message "";
  1161.                             $userData = array(
  1162.                                 'id' => $userObj->getApplicantId(),
  1163.                                 'email' => $email_address,
  1164.                                 'appId' => 0,
  1165.                                 'image' => $userObj->getImage(),
  1166.                                 'firstName' => $userObj->getFirstname(),
  1167.                                 'lastName' => $userObj->getLastname(),
  1168.                                 //                        'appId'=>$userObj->getUserAppId(),
  1169.                             );
  1170.                         } else {
  1171.                             $message "Action not allowed!";
  1172.                             $email_twig_data['success'] = false;
  1173.                         }
  1174.                     } else {
  1175.                         $message "Account not found!";
  1176.                         $email_twig_data['success'] = false;
  1177.                     }
  1178.                 } else {
  1179.                     $userType $session->get(UserConstants::USER_TYPE);
  1180.                     $userObj $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(
  1181.                         array(
  1182.                             'userId' => $userId
  1183.                         )
  1184.                     );
  1185.                     if ($userObj) {
  1186.                         if ($userObj->getTriggerResetPassword() == 1) {
  1187.                             $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$userObj->getSalt());
  1188.                             $userObj->setPassword($encodedPassword);
  1189.                             $userObj->setTempPassword('');
  1190.                             $userObj->setTriggerResetPassword(0);
  1191.                             $em->flush();
  1192.                             $email_twig_data['success'] = true;
  1193.                             $message "";
  1194.                         } else {
  1195.                             $message "Action not allowed!";
  1196.                             $email_twig_data['success'] = false;
  1197.                         }
  1198.                     } else {
  1199.                         $message "Account not found!";
  1200.                         $email_twig_data['success'] = false;
  1201.                     }
  1202.                 }
  1203.                 if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  1204.                     $response = new JsonResponse(array(
  1205.                             'templateData' => $twigData,
  1206.                             'message' => $message,
  1207.                             'actionData' => $email_twig_data,
  1208.                             'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  1209.                         )
  1210.                     );
  1211.                     $response->headers->set('Access-Control-Allow-Origin''*');
  1212.                     return $response;
  1213.                 } else if ($email_twig_data['success'] == true) {
  1214.                     //                    $twig_file = '@Authentication/pages/views/reset_password_success_buddybee.html.twig';
  1215.                     //                    $twigData = [
  1216.                     //                        'page_title' => 'Reset Successful',
  1217.                     //                        'encryptedData' => $encryptedData,
  1218.                     //                        'message' => $message,
  1219.                     //                        'userType' => $userType,
  1220.                     //                        'errorField' => $errorField,
  1221.                     //
  1222.                     //                    ];
  1223.                     //                    return $this->render(
  1224.                     //                        $twig_file,
  1225.                     //                        $twigData
  1226.                     //                    );
  1227.                     return $this->redirectToRoute('dashboard');
  1228.                 }
  1229.             } else if ($systemType == '_BUDDYBEE_') {
  1230.                 $userType UserConstants::USER_TYPE_APPLICANT;
  1231.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1232.                     array(
  1233.                         'applicantId' => $userId
  1234.                     )
  1235.                 );
  1236.                 if ($userObj) {
  1237.                     if ($userObj->getTriggerResetPassword() == 1) {
  1238.                         $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$userObj->getSalt());
  1239.                         $userObj->setPassword($encodedPassword);
  1240.                         $userObj->setTempPassword('');
  1241.                         $userObj->setTriggerResetPassword(0);
  1242.                         $em_goc->flush();
  1243.                         $email_twig_data['success'] = true;
  1244.                         $message "";
  1245.                         $userData = array(
  1246.                             'id' => $userObj->getApplicantId(),
  1247.                             'email' => $email_address,
  1248.                             'appId' => 0,
  1249.                             'image' => $userObj->getImage(),
  1250.                             'firstName' => $userObj->getFirstname(),
  1251.                             'lastName' => $userObj->getLastname(),
  1252.                             //                        'appId'=>$userObj->getUserAppId(),
  1253.                         );
  1254.                     } else {
  1255.                         $message "Action not allowed!";
  1256.                         $email_twig_data['success'] = false;
  1257.                     }
  1258.                 } else {
  1259.                     $message "Account not found!";
  1260.                     $email_twig_data['success'] = false;
  1261.                 }
  1262.             } else if ($systemType == '_CENTRAL_') {
  1263.                 $userType UserConstants::USER_TYPE_APPLICANT;
  1264.                 $userObj $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(
  1265.                     array(
  1266.                         'applicantId' => $userId
  1267.                     )
  1268.                 );
  1269.                 if ($userObj) {
  1270.                     if ($userObj->getTriggerResetPassword() == 1) {
  1271.                         $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$userObj->getSalt());
  1272.                         $userObj->setPassword($encodedPassword);
  1273.                         $userObj->setTempPassword('');
  1274.                         $userObj->setTriggerResetPassword(0);
  1275.                         $em_goc->flush();
  1276.                         $email_twig_data['success'] = true;
  1277.                         $message "";
  1278.                         $userData = array(
  1279.                             'id' => $userObj->getApplicantId(),
  1280.                             'email' => $email_address,
  1281.                             'appId' => 0,
  1282.                             'image' => $userObj->getImage(),
  1283.                             'firstName' => $userObj->getFirstname(),
  1284.                             'lastName' => $userObj->getLastname(),
  1285.                             //                        'appId'=>$userObj->getUserAppId(),
  1286.                         );
  1287.                     } else {
  1288.                         $message "Action not allowed!";
  1289.                         $email_twig_data['success'] = false;
  1290.                     }
  1291.                 } else {
  1292.                     $message "Account not found!";
  1293.                     $email_twig_data['success'] = false;
  1294.                 }
  1295.             }
  1296.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  1297.                 $response = new JsonResponse(array(
  1298.                         'templateData' => $twigData,
  1299.                         'message' => $message,
  1300.                         'actionData' => $email_twig_data,
  1301.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  1302.                     )
  1303.                 );
  1304.                 $response->headers->set('Access-Control-Allow-Origin''*');
  1305.                 return $response;
  1306.             } else if ($email_twig_data['success'] == true) {
  1307.                 if ($systemType == '_ERP_'$twig_file '@Authentication/pages/views/reset_password_success_central.html.twig';
  1308.                 else if ($systemType == '_BUDDYBEE_'$twig_file '@Authentication/pages/views/reset_password_success_buddybee.html.twig';
  1309.                 else if ($systemType == '_CENTRAL_'$twig_file '@Authentication/pages/views/reset_password_success_central.html.twig';
  1310.                 $twigData = [
  1311.                     'page_title' => 'Reset Successful',
  1312.                     'encryptedData' => $encryptedData,
  1313.                     'message' => $message,
  1314.                     'userType' => $userType,
  1315.                     'errorField' => $errorField,
  1316.                 ];
  1317.                 return $this->render(
  1318.                     $twig_file,
  1319.                     $twigData
  1320.                 );
  1321.             }
  1322.         }
  1323.         if ($systemType == '_ERP_') {
  1324.             if ($userCategory == '_APPLICANT_') {
  1325.                 $userType $session->get(UserConstants::USER_TYPE);
  1326.                 $twig_file 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
  1327.                 $twigData = [
  1328.                     'page_title' => 'Find Account',
  1329.                     'encryptedData' => $encryptedData,
  1330.                     'message' => $message,
  1331.                     'userType' => $userType,
  1332.                     'errorField' => $errorField,
  1333.                 ];
  1334.             } else {
  1335.                 $userType $session->get(UserConstants::USER_TYPE);
  1336.                 $twig_file 'ApplicationBundle:pages/login:reset_password_erp.html.twig';
  1337.                 $twigData = [
  1338.                     'page_title' => 'Reset Password',
  1339.                     'encryptedData' => $encryptedData,
  1340.                     'message' => $message,
  1341.                     'userType' => $userType,
  1342.                     'errorField' => $errorField,
  1343.                 ];
  1344.             }
  1345.         } else if ($systemType == '_BUDDYBEE_') {
  1346.             $userType UserConstants::USER_TYPE_APPLICANT;
  1347.             $twig_file '@Authentication/pages/views/reset_new_password_buddybee.html.twig';
  1348.             $twigData = [
  1349.                 'page_title' => 'Reset Password',
  1350.                 'encryptedData' => $encryptedData,
  1351.                 'message' => $message,
  1352.                 'userType' => $userType,
  1353.                 'errorField' => $errorField,
  1354.             ];
  1355.         } else if ($systemType == '_CENTRAL_') {
  1356.             $userType UserConstants::USER_TYPE_APPLICANT;
  1357.             $twig_file '@HoneybeeWeb/pages/views/reset_new_password_honeybee.html.twig';
  1358.             $twigData = [
  1359.                 'page_title' => 'Reset Password',
  1360.                 'encryptedData' => $encryptedData,
  1361.                 'message' => $message,
  1362.                 'userType' => $userType,
  1363.                 'errorField' => $errorField,
  1364.             ];
  1365.         }
  1366.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  1367.             if ($userId != && $userId != null) {
  1368.                 $response = new JsonResponse(array(
  1369.                         'templateData' => $twigData,
  1370.                         'message' => $message,
  1371. //                        'encryptedData' => $encryptedData,
  1372.                         'actionData' => $email_twig_data,
  1373.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  1374.                     )
  1375.                 );
  1376.             } else {
  1377.                 $response = new JsonResponse(array(
  1378.                         'templateData' => [],
  1379.                         'message' => 'Unauthorized',
  1380.                         'actionData' => [],
  1381. //                        'encryptedData' => $encryptedData,
  1382.                         'success' => false,
  1383.                     )
  1384.                 );
  1385.             }
  1386.             $response->headers->set('Access-Control-Allow-Origin''*');
  1387.             return $response;
  1388.         } else {
  1389.             if ($userId != && $userId != null) {
  1390.                 return $this->render(
  1391.                     $twig_file,
  1392.                     $twigData
  1393.                 );
  1394.             } else
  1395.                 return $this->render('@Buddybee/pages/404NotFound.html.twig', array(
  1396.                     'page_title' => '404 Not Found',
  1397.                 ));
  1398.         }
  1399.     }
  1400.     // hire
  1401. //    public function CentralHirePageAction()
  1402. //    {
  1403. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  1404. //        $freelancersData = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1405. //            ->createQueryBuilder('m')
  1406. //             ->where("m.isConsultant =1")
  1407. //
  1408. //            ->getQuery()
  1409. //            ->getResult();
  1410. //
  1411. //        return $this->render('@HoneybeeWeb/pages/hire.html.twig', array(
  1412. //            'page_title' => 'Hire',
  1413. //            'freelancersData' => $freelancersData,
  1414. //
  1415. //        ));
  1416. //    }
  1417. //    public function CentralHirePageAction(Request $request)
  1418. //    {
  1419. //        $em_goc = $this->getDoctrine()->getManager('company_group');
  1420. //        $search = $request->query->get('q'); // get search text
  1421. //
  1422. //        $qb = $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1423. //            ->createQueryBuilder('m')
  1424. //            ->where('m.isConsultant = 1');
  1425. //
  1426. //        if (!empty($search)) {
  1427. //            $qb->andWhere('m.firstname LIKE :search
  1428. //                       OR m.lastname LIKE :search ')
  1429. //                ->setParameter('search', '%' . $search . '%');
  1430. //        }
  1431. //
  1432. //        $freelancersData = $qb->getQuery()->getResult();
  1433. //
  1434. //        return $this->render('@HoneybeeWeb/pages/hire.html.twig', [
  1435. //            'page_title' => 'Hire',
  1436. //            'freelancersData' => $freelancersData,
  1437. //            'searchValue' => $search
  1438. //        ]);
  1439. //    }
  1440.     public function CentralHirePageAction(Request $request)
  1441.     {
  1442.         $em_goc $this->getDoctrine()->getManager('company_group');
  1443.         $search $request->query->get('q'); // search text
  1444.         $qb $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1445.             ->createQueryBuilder('m')
  1446.             ->where('m.isConsultant = 1');
  1447.         if (!empty($search)) {
  1448.             $qb->andWhere('m.firstname LIKE :search OR m.lastname LIKE :search')
  1449.                 ->setParameter('search''%' $search '%');
  1450.         }
  1451.         $freelancersData $qb->getQuery()->getResult();
  1452.         // For AJAX requests, we return the same Twig, but we include the searchValue
  1453.         if ($request->isXmlHttpRequest()) {
  1454.             return $this->render('@HoneybeeWeb/pages/hire.html.twig', [
  1455.                 'page_title' => 'Hire',
  1456.                 'freelancersData' => $freelancersData,
  1457.                 'searchValue' => $search// so input retains value
  1458.                 'isAjax' => true// flag to indicate AJAX
  1459.             ]);
  1460.         }
  1461.         // Normal page load
  1462.         return $this->render('@HoneybeeWeb/pages/hire.html.twig', [
  1463.             'page_title' => 'Hire',
  1464.             'freelancersData' => $freelancersData,
  1465.             'searchValue' => $search,
  1466.             'isAjax' => false,
  1467.         ]);
  1468.     }
  1469.     // end of centralHire
  1470.     // pricing
  1471.     public function CentralPricingPageAction(Request $request)
  1472.     {
  1473.         $em_goc $this->getDoctrine()->getManager('company_group');
  1474.         $session $request->getSession();
  1475.         $userId $session->get(UserConstants::USER_ID);
  1476.         $companiesForUser = [];
  1477.         if ($userId) {
  1478.             $userDetails $em_goc->getRepository('CompanyGroupBundle\Entity\EntityApplicantDetails')->find($userId);
  1479.             if ($userDetails) {
  1480.                 $userTypeByAppIds json_decode($userDetails->getUserTypesByAppIds(), true);
  1481.                 if (is_array($userTypeByAppIds)) {
  1482.                     $adminAppIds = [];
  1483.                     foreach ($userTypeByAppIds as $appId => $types) {
  1484.                         if (in_array(1$types)) {
  1485.                             $adminAppIds[] = $appId;
  1486.                         }
  1487.                     }
  1488.                     if (!empty($adminAppIds)) {
  1489.                         $companiesForUser $em_goc->getRepository('CompanyGroupBundle\Entity\CompanyGroup')
  1490.                             ->createQueryBuilder('c')
  1491.                             ->where('c.appId IN (:appIds)')
  1492.                             ->setParameter('appIds'$adminAppIds)
  1493.                             ->getQuery()
  1494.                             ->getResult();
  1495.                     }
  1496.                 }
  1497.             }
  1498.         }
  1499.         $packageDetails GeneralConstant::$packageDetails;
  1500.         return $this->render('@HoneybeeWeb/pages/pricing.html.twig', [
  1501.             'page_title' => 'Pricing',
  1502.             'packageDetails' => $packageDetails,
  1503.             'companies' => $companiesForUser,
  1504.         ]);
  1505.     }
  1506.     // faq
  1507.     public function CentralFaqPageAction()
  1508.     {
  1509.         return $this->render('@HoneybeeWeb/pages/faq.html.twig', array(
  1510.             'page_title' => 'FAQ',
  1511.         ));
  1512.     }
  1513.     // terms and condiitons
  1514.     public function CentralTermsAndConditionPageAction()
  1515.     {
  1516.         return $this->render('@HoneybeeWeb/pages/terms_and_conditions.html.twig', array(
  1517.             'page_title' => 'Terms and Conditions',
  1518.         ));
  1519.     }
  1520.     // Refund Policy
  1521.    public function CentralRefundPolicyPageAction()
  1522. {
  1523.     return $this->render('@HoneybeeWeb/pages/refund_policy.html.twig', array(
  1524.         'page_title' => 'Refund Policy',
  1525.     ));
  1526. }
  1527.     // Cancellation Policy
  1528.    public function CentralCancellationPolicyPageAction()
  1529. {
  1530.     return $this->render('@HoneybeeWeb/pages/cancellation_policy.html.twig', array(
  1531.            'page_title' => 'Cancellation Policy',
  1532.     ));
  1533. }
  1534.     // Help page
  1535.    public function CentralHelpPageAction()
  1536.    {
  1537.     return $this->render('@HoneybeeWeb/pages/help.html.twig', array(
  1538.         'page_title' => 'Help',
  1539.     ));
  1540.    }
  1541.  // Career page
  1542.    public function CentralCareerPageAction()
  1543. {
  1544.     return $this->render('@HoneybeeWeb/pages/career.html.twig', array(
  1545.         'page_title' => 'Career',
  1546.     ));
  1547. }
  1548.     public function CentralPrivacyPolicyAction()
  1549.     {
  1550.         return $this->render('@HoneybeeWeb/pages/privacy_policy.html.twig', array(
  1551.             'page_title' => 'Privacy Policy',
  1552.         ));
  1553.     }
  1554.     public function CheckoutPageAction(Request $request$encData '')
  1555.     {
  1556.         $em $this->getDoctrine()->getManager('company_group');
  1557.         $em_goc $this->getDoctrine()->getManager('company_group');
  1558.         $sandBoxMode $this->container->hasParameter('sand_box_mode') ? $this->container->getParameter('sand_box_mode') : 0;
  1559.         $invoiceId $request->request->get('invoiceId'$request->query->get('invoiceId'0));
  1560.         if ($encData != "") {
  1561.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  1562.             if ($encryptedData == null$encryptedData = [];
  1563.             if (isset($encryptedData['invoiceId'])) $invoiceId $encryptedData['invoiceId'];
  1564.         }
  1565.         $session $request->getSession();
  1566.         $currencyForGateway 'eur';
  1567.         $gatewayInvoice null;
  1568.         if ($invoiceId != 0)
  1569.             $gatewayInvoice $em->getRepository(EntityInvoice::class)->find($invoiceId);
  1570.         $paymentGateway $request->request->get('paymentGateway''stripe'); //aamarpay,bkash
  1571.         $paymentType $request->request->get('paymentType''credit');
  1572.         $retailerId $request->request->get('retailerId'0);
  1573.         if ($request->query->has('currency'))
  1574.             $currencyForGateway $request->query->get('currency');
  1575.         else
  1576.             $currencyForGateway $request->request->get('currency''eur');
  1577. //        {
  1578. //            if ($request->query->has('meetingSessionId'))
  1579. //                $id = $request->query->get('meetingSessionId');
  1580. //        }
  1581.         $currentUserBalance 0;
  1582.         $currentUserCoinBalance 0;
  1583.         $gatewayAmount 0;
  1584.         $redeemedAmount 0;
  1585.         $redeemedSessionCount 0;
  1586.         $toConsumeSessionCount 0;
  1587.         $invoiceSessionCount 0;
  1588.         $payableAmount 0;
  1589.         $promoClaimedAmount 0;
  1590.         $promoCodeId 0;
  1591.         $promoClaimedSession 0;
  1592.         $bookingExpireTime null;
  1593.         $bookingExpireTs 0;
  1594.         $imageBySessionCount = [
  1595.             => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1596.             100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1597.             200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1598.             300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1599.             400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1600.             500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1601.             600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1602.             700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1603.             800 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1604.             900 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1605.             1000 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1606.             1100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1607.             1200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1608.             1300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1609.             1400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1610.             1500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1611.             1600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1612.             1700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1613.             1800 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1614.             1900 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1615.             2000 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1616.             2100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1617.             2200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1618.             2300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1619.             2400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1620.             2500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1621.             2600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1622.             2700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1623.             2800 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1624.             2900 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1625.             3000 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1626.             3100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1627.             3200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1628.             3300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1629.             3400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1630.             3500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1631.             3600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1632.             3700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  1633.         ];
  1634.         if (!$gatewayInvoice) {
  1635.             if ($request->isMethod('POST')) {
  1636.                 $totalAmount 0;
  1637.                 $totalSessionCount 0;
  1638.                 $consumedAmount 0;
  1639.                 $consumedSessionCount 0;
  1640.                 $bookedById 0;
  1641.                 $bookingRefererId 0;
  1642.                 if ($session->get(UserConstants::USER_ID)) {
  1643.                     $bookedById $session->get(UserConstants::USER_ID);
  1644.                     $bookingRefererId 0;
  1645. //                    $toConsumeSessionCount = 1 * $request->request->get('meetingSessionConsumeCount', 0);
  1646.                     $invoiceSessionCount * ($request->request->get('sessionCount'0) == '' $request->request->get('sessionCount'0));
  1647.                     //1st do the necessary
  1648.                     $extMeeting null;
  1649.                     $meetingSessionId 0;
  1650.                     if ($request->request->has('purchasePackage')) {
  1651.                         //1. check if any bee card if yes try to claim it , modify current balance then
  1652.                         $beeCodeSerial $request->request->get('beeCodeSerial''');
  1653.                         $promoCode $request->request->get('promoCode''');
  1654.                         $beeCodePin $request->request->get('beeCodePin''');
  1655.                         $userId $request->request->get('userId'$session->get(UserConstants::USER_ID));
  1656.                         $studentDetails null;
  1657.                         $studentDetails $em_goc->getRepository(EntityApplicantDetails::class)->find($userId);
  1658.                         if ($studentDetails) {
  1659.                             $currentUserBalance $studentDetails->getAccountBalance();
  1660.                         }
  1661.                         if ($beeCodeSerial != '' && $beeCodePin != '') {
  1662.                             $claimData MiscActions::ClaimBeeCode($em,
  1663.                                 [
  1664.                                     'claimFlag' => 1,
  1665.                                     'pin' => $beeCodePin,
  1666.                                     'serial' => $beeCodeSerial,
  1667.                                     'userId' => $userId,
  1668.                                 ]);
  1669.                             if ($userId == $session->get(UserConstants::USER_ID)) {
  1670.                                 MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  1671.                                 $claimData['newCoinBalance'] = $session->get('BUDDYBEE_COIN_BALANCE');
  1672.                                 $claimData['newBalance'] = $session->get('BUDDYBEE_BALANCE');
  1673.                             }
  1674.                             $redeemedAmount $claimData['data']['claimedAmount'];
  1675.                             $redeemedSessionCount $claimData['data']['claimedCoin'];
  1676.                         } else
  1677.                             if ($userId == $session->get(UserConstants::USER_ID)) {
  1678.                                 MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  1679.                             }
  1680.                         $payableAmount round($request->request->get('payableAmount'0), 0);
  1681.                         $totalAmountWoDiscount round($request->request->get('totalAmountWoDiscount'0), 0);
  1682.                         //now claim and process promocode
  1683.                         if ($promoCode != '') {
  1684.                             $claimData MiscActions::ClaimPromoCode($em,
  1685.                                 [
  1686.                                     'claimFlag' => 1,
  1687.                                     'promoCode' => $promoCode,
  1688.                                     'decryptedPromoCodeData' => json_decode($this->get('url_encryptor')->decrypt($promoCode), true),
  1689.                                     'orderValue' => $totalAmountWoDiscount,
  1690.                                     'currency' => $currencyForGateway,
  1691.                                     'orderCoin' => $invoiceSessionCount,
  1692.                                     'userId' => $userId,
  1693.                                 ]);
  1694.                             $promoClaimedAmount 0;
  1695. //                            $promoClaimedAmount = $claimData['data']['claimedAmount']*(BuddybeeConstant::$convMultFromTo['eur'][$currencyForGateway]);
  1696.                             $promoCodeId $claimData['promoCodeId'];
  1697.                             $promoClaimedSession $claimData['data']['claimedCoin'];
  1698.                         }
  1699.                         if ($userId == $session->get(UserConstants::USER_ID)) {
  1700.                             MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  1701.                             $currentUserBalance $session->get('BUDDYBEE_BALANCE');
  1702.                             $currentUserCoinBalance $session->get('BUDDYBEE_COIN_BALANCE');
  1703.                         } else {
  1704.                             if ($bookingRefererId == 0)
  1705.                                 $bookingRefererId $session->get(UserConstants::USER_ID);
  1706.                             $studentDetails $em_goc->getRepository(EntityApplicantDetails::class)->find($userId);
  1707.                             if ($studentDetails) {
  1708.                                 $currentUserBalance $studentDetails->getAccountBalance();
  1709.                                 $currentUserCoinBalance $studentDetails->getSessionCountBalance();
  1710.                                 if ($bookingRefererId != $userId && $bookingRefererId != 0) {
  1711.                                     $bookingReferer $em_goc->getRepository(EntityApplicantDetails::class)->find($bookingRefererId);
  1712.                                     if ($bookingReferer)
  1713.                                         if ($bookingReferer->getIsAdmin()) {
  1714.                                             $studentDetails->setAssignedSalesRepresentativeId($bookingRefererId);
  1715.                                             $em_goc->flush();
  1716.                                         }
  1717.                                 }
  1718.                             }
  1719.                         }
  1720.                         //2. check if any promo code  if yes add it to promo discount
  1721.                         //3. check if scheule is still temporarily booked if not return that you cannot book it
  1722.                         Buddybee::ExpireAnyMeetingSessionIfNeeded($em);
  1723.                         Buddybee::ExpireAnyEntityInvoiceIfNeeded($em);
  1724. //                        if ($request->request->get('autoAssignMeetingSession', 0) == 1
  1725. //                            && $request->request->get('consultancyScheduleId', 0) != 0
  1726. //                            && $request->request->get('consultancyScheduleId', 0) != ''
  1727. //                        )
  1728.                         {
  1729.                             //1st check if a meeting session exxists with same TS, student id , consultant id
  1730. //                            $scheduledStartTime = new \DateTime('@' . $request->request->get('consultancyScheduleId', ''));
  1731. //                            $extMeeting = $em->getRepository('CompanyGroupBundle\\Entity\\EntityMeetingSession')
  1732. //                                ->findOneBy(
  1733. //                                    array(
  1734. //                                        'scheduledTimeTs' => $scheduledStartTime->format('U'),
  1735. //                                        'consultantId' => $request->request->get('consultantId', 0),
  1736. //                                        'studentId' => $request->request->get('studentId', 0),
  1737. //                                        'durationAllowedMin' => $request->request->get('meetingSessionScheduledDuration', BuddybeeConstant::PER_SESSION_MINUTE),
  1738. //                                    )
  1739. //                                );
  1740. //                            if ($extMeeting) {
  1741. //                                $new = $extMeeting;
  1742. //                                $meetingSessionId = $new->getSessionId();
  1743. //                                $periodMarker = $scheduledStartTime->format('Ym');
  1744. //
  1745. //                            }
  1746. //                            else {
  1747. //
  1748. //
  1749. //                                $scheduleValidity = MiscActions::CheckIfScheduleCanBeConfirmed(
  1750. //                                    $em,
  1751. //                                    $request->request->get('consultantId', 0),
  1752. //                                    $request->request->get('studentId', 0),
  1753. //                                    $scheduledStartTime->format('U'),
  1754. //                                    $request->request->get('meetingSessionScheduledDuration', BuddybeeConstant::PER_SESSION_MINUTE),
  1755. //                                    1
  1756. //                                );
  1757. //
  1758. //                                if (!$scheduleValidity) {
  1759. //                                    $url = $this->generateUrl(
  1760. //                                        'consultant_profile'
  1761. //                                    );
  1762. //                                    $output = [
  1763. //
  1764. //                                        'proceedToCheckout' => 0,
  1765. //                                        'message' => 'Session Booking Expired or not Found!',
  1766. //                                        'errorFlag' => 1,
  1767. //                                        'redirectUrl' => $url . '/' . $request->request->get('consultantId', 0)
  1768. //                                    ];
  1769. //                                    return new JsonResponse($output);
  1770. //                                }
  1771. //                                $new = new EntityMeetingSession();
  1772. //
  1773. //                                $new->setTopicId($request->request->get('consultancyTopic', 0));
  1774. //                                $new->setConsultantId($request->request->get('consultantId', 0));
  1775. //                                $new->setStudentId($request->request->get('studentId', 0));
  1776. //                                $consultancyTopic = $em_goc->getRepository(EntityCreateTopic::class)->find($request->request->get('consultancyTopic', 0));
  1777. //                                $new->setMeetingType($consultancyTopic ? $consultancyTopic->getMeetingType() : 0);
  1778. //                                $new->setConsultantCanUpload($consultancyTopic ? $consultancyTopic->getConsultantCanUpload() : 0);
  1779. //
  1780. //
  1781. //                                $scheduledEndTime = new \DateTime($request->request->get('scheduledTime', ''));
  1782. //                                $scheduledEndTime = $scheduledEndTime->modify('+' . $request->request->get('meetingSessionScheduledDuration', 30) . ' minute');
  1783. //
  1784. //                                //$new->setScheduledTime($request->request->get('setScheduledTime'));
  1785. //                                $new->setScheduledTime($scheduledStartTime);
  1786. //                                $new->setDurationAllowedMin($request->request->get('meetingSessionScheduledDuration', 30));
  1787. //                                $new->setDurationLeftMin($request->request->get('meetingSessionScheduledDuration', 30));
  1788. //                                $new->setSessionExpireDate($scheduledEndTime);
  1789. //                                $new->setSessionExpireDateTs($scheduledEndTime->format('U'));
  1790. //                                $new->setEquivalentSessionCount($request->request->get('meetingSessionConsumeCount', 0));
  1791. //                                $new->setMeetingSpecificNote($request->request->get('meetingSpecificNote', ''));
  1792. //
  1793. //                                $new->setUsableSessionCount($request->request->get('meetingSessionConsumeCount', 0));
  1794. //                                $new->setRedeemSessionCount($request->request->get('meetingSessionConsumeCount', 0));
  1795. //                                $new->setMeetingActionFlag(0);// no action waiting for meeting
  1796. //                                $new->setScheduledTime($scheduledStartTime);
  1797. //                                $new->setScheduledTimeTs($scheduledStartTime->format('U'));
  1798. //                                $new->setPayableAmount($request->request->get('payableAmount', 0));
  1799. //                                $new->setDueAmount($request->request->get('dueAmount', 0));
  1800. //                                //$new->setScheduledTime(new \DateTime($request->get('setScheduledTime')));
  1801. //                                //$new->setPcakageDetails(json_encode(($request->request->get('packageData'))));
  1802. //                                $new->setPackageName(($request->request->get('packageName', '')));
  1803. //                                $new->setPcakageDetails(($request->request->get('packageData', '')));
  1804. //                                $new->setScheduleId(($request->request->get('consultancyScheduleId', 0)));
  1805. //                                $currentUnixTime = new \DateTime();
  1806. //                                $currentUnixTimeStamp = $currentUnixTime->format('U');
  1807. //                                $studentId = $request->request->get('studentId', 0);
  1808. //                                $consultantId = $request->request->get('consultantId', 0);
  1809. //                                $new->setMeetingRoomId(str_pad($consultantId, 4, STR_PAD_LEFT) . $currentUnixTimeStamp . str_pad($studentId, 4, STR_PAD_LEFT));
  1810. //                                $new->setSessionValue(($request->request->get('sessionValue', 0)));
  1811. ////                        $new->setIsPayment(0);
  1812. //                                $new->setConsultantIsPaidFull(0);
  1813. //
  1814. //                                if ($bookingExpireTs == 0) {
  1815. //
  1816. //                                    $bookingExpireTime = new \DateTime();
  1817. //                                    $currTime = new \DateTime();
  1818. //                                    $currTimeTs = $currTime->format('U');
  1819. //                                    $bookingExpireTs = (1 * $scheduledStartTime->format('U')) - (24 * 3600);
  1820. //                                    if ($bookingExpireTs < $currTimeTs) {
  1821. //                                        if ((1 * $scheduledStartTime->format('U')) - $currTimeTs > (12 * 3600))
  1822. //                                            $bookingExpireTs = (1 * $scheduledStartTime->format('U')) - (2 * 3600);
  1823. //                                        else
  1824. //                                            $bookingExpireTs = (1 * $scheduledStartTime->format('U'));
  1825. //                                    }
  1826. //
  1827. ////                                    $bookingExpireTs = $bookingExpireTime->format('U');
  1828. //                                }
  1829. //
  1830. //                                $new->setPaidSessionCount(0);
  1831. //                                $new->setBookedById($bookedById);
  1832. //                                $new->setBookingRefererId($bookingRefererId);
  1833. //                                $new->setDueSessionCount($request->request->get('meetingSessionConsumeCount', 0));
  1834. //                                $new->setExpireIfUnpaidTs($bookingExpireTs);
  1835. //                                $new->setBookingExpireTs($bookingExpireTs);
  1836. //                                $new->setConfirmationExpireTs($bookingExpireTs);
  1837. //                                $new->setIsPaidFull(0);
  1838. //                                $new->setIsExpired(0);
  1839. //
  1840. //
  1841. //                                $em_goc->persist($new);
  1842. //                                $em_goc->flush();
  1843. //                                $meetingSessionId = $new->getSessionId();
  1844. //                                $periodMarker = $scheduledStartTime->format('Ym');
  1845. //                                MiscActions::UpdateSchedulingRestrictions($em_goc, $consultantId, $periodMarker, (($request->request->get('meetingSessionScheduledDuration', 30)) / 60), -(($request->request->get('meetingSessionScheduledDuration', 30)) / 60));
  1846. //                            }
  1847.                         }
  1848.                         //4. if after all this stages passed then calcualte gateway payable
  1849.                         if ($request->request->get('isRecharge'0) == 1) {
  1850.                             if (($redeemedAmount $promoClaimedAmount) >= $payableAmount) {
  1851.                                 $payableAmount = ($redeemedAmount $promoClaimedAmount);
  1852.                                 $gatewayAmount 0;
  1853.                             } else
  1854.                                 $gatewayAmount $payableAmount - ($redeemedAmount $promoClaimedAmount);
  1855.                         } else {
  1856.                             if ($toConsumeSessionCount <= $currentUserCoinBalance && $invoiceSessionCount <= $toConsumeSessionCount) {
  1857.                                 $payableAmount 0;
  1858.                                 $gatewayAmount 0;
  1859.                             } else if (($redeemedAmount $promoClaimedAmount) >= $payableAmount) {
  1860.                                 $payableAmount = ($redeemedAmount $promoClaimedAmount);
  1861.                                 $gatewayAmount 0;
  1862.                             } else
  1863.                                 $gatewayAmount $payableAmount <= ($currentUserBalance + ($redeemedAmount $promoClaimedAmount)) ? : ($payableAmount $currentUserBalance - ($redeemedAmount $promoClaimedAmount));
  1864.                         }
  1865.                         $gatewayAmount round($gatewayAmount2);
  1866.                         $dueAmount round($request->request->get('dueAmount'$payableAmount), 0);
  1867.                         if ($request->request->has('gatewayProductData'))
  1868.                             $gatewayProductData $request->request->get('gatewayProductData');
  1869.                         $gatewayProductData = [[
  1870.                             'price_data' => [
  1871.                                 'currency' => $currencyForGateway,
  1872.                                 'unit_amount' => $gatewayAmount != ? ((100 $gatewayAmount) / ($invoiceSessionCount != $invoiceSessionCount 1)) : 200000,
  1873.                                 'product_data' => [
  1874. //                            'name' => $request->request->has('packageName') ? $request->request->get('packageName') : 'Advanced Consultancy Package',
  1875.                                     'name' => 'Bee Coins',
  1876.                                     'images' => [$imageBySessionCount[0]],
  1877.                                 ],
  1878.                             ],
  1879.                             'quantity' => $invoiceSessionCount != $invoiceSessionCount 1,
  1880.                         ]];
  1881.                         $new_invoice null;
  1882.                         if ($extMeeting) {
  1883.                             $new_invoice $em->getRepository('CompanyGroupBundle\\Entity\\EntityInvoice')
  1884.                                 ->findOneBy(
  1885.                                     array(
  1886.                                         'invoiceType' => $request->request->get('invoiceType'BuddybeeConstant::ENTITY_INVOICE_TYPE_PAYMENT_TO_HONEYBEE),
  1887.                                         'meetingId' => $extMeeting->getSessionId(),
  1888.                                     )
  1889.                                 );
  1890.                         }
  1891.                         if ($new_invoice) {
  1892.                         } else {
  1893.                             $new_invoice = new EntityInvoice();
  1894.                             $invoiceDate = new \DateTime();
  1895.                             $new_invoice->setInvoiceDate($invoiceDate);
  1896.                             $new_invoice->setInvoiceDateTs($invoiceDate->format('U'));
  1897.                             $new_invoice->setStudentId($userId);
  1898.                             $new_invoice->setBillerId($retailerId == $retailerId);
  1899.                             $new_invoice->setRetailerId($retailerId);
  1900.                             $new_invoice->setBillToId($userId);
  1901.                             $new_invoice->setAmountTransferGateWayHash($paymentGateway);
  1902.                             $new_invoice->setAmountCurrency($currencyForGateway);
  1903.                             $cardIds $request->request->get('cardIds', []);
  1904.                             $new_invoice->setMeetingId($meetingSessionId);
  1905.                             $new_invoice->setGatewayBillAmount($gatewayAmount);
  1906.                             $new_invoice->setRedeemedAmount($redeemedAmount);
  1907.                             $new_invoice->setPromoDiscountAmount($promoClaimedAmount);
  1908.                             $new_invoice->setPromoCodeId($promoCodeId);
  1909.                             $new_invoice->setRedeemedSessionCount($redeemedSessionCount);
  1910.                             $new_invoice->setPaidAmount($payableAmount $dueAmount);
  1911.                             $new_invoice->setProductDataForPaymentGateway(json_encode($gatewayProductData));
  1912.                             $new_invoice->setDueAmount($dueAmount);
  1913.                             $new_invoice->setInvoiceType($request->request->get('invoiceType'BuddybeeConstant::ENTITY_INVOICE_TYPE_PAYMENT_TO_HONEYBEE));
  1914.                             $new_invoice->setDocumentHash(MiscActions::GenerateRandomCrypto('BEI' microtime(true)));
  1915.                             $new_invoice->setCardIds(json_encode($cardIds));
  1916.                             $new_invoice->setAmountType($request->request->get('amountType'1));
  1917.                             $new_invoice->setAmount($payableAmount);
  1918.                             $new_invoice->setConsumeAmount($payableAmount);
  1919.                             $new_invoice->setSessionCount($invoiceSessionCount);
  1920.                             $new_invoice->setConsumeSessionCount($toConsumeSessionCount);
  1921.                             $new_invoice->setIsPaidfull(0);
  1922.                             $new_invoice->setIsProcessed(0);
  1923.                             $new_invoice->setApplicantId($userId);
  1924.                             $new_invoice->setBookedById($bookedById);
  1925.                             $new_invoice->setBookingRefererId($bookingRefererId);
  1926.                             $new_invoice->setIsRecharge($request->request->get('isRecharge'0));
  1927.                             $new_invoice->setAutoConfirmTaggedMeeting($request->request->get('autoConfirmTaggedMeeting'0));
  1928.                             $new_invoice->setAutoConfirmOtherMeeting($request->request->get('autoConfirmOtherMeeting'0));
  1929.                             $new_invoice->setAutoClaimPurchasedCards($request->request->get('autoClaimPurchasedCards'0));
  1930.                             $new_invoice->setIsPayment(0); //0 means receive
  1931.                             $new_invoice->setStatus(GeneralConstant::ACTIVE); //0 means receive
  1932.                             $new_invoice->setStage(BuddybeeConstant::ENTITY_INVOICE_STAGE_INITIATED); //0 means receive
  1933.                             if ($bookingExpireTs == 0) {
  1934.                                 $bookingExpireTime = new \DateTime();
  1935.                                 $bookingExpireTime->modify('+30 day');
  1936.                                 $bookingExpireTs $bookingExpireTime->format('U');
  1937.                             }
  1938.                             $new_invoice->setExpireIfUnpaidTs($bookingExpireTs);
  1939.                             $new_invoice->setBookingExpireTs($bookingExpireTs);
  1940.                             $new_invoice->setConfirmationExpireTs($bookingExpireTs);
  1941. //            $new_invoice->setStatus($request->request->get(0));
  1942.                             $em_goc->persist($new_invoice);
  1943.                             $em_goc->flush();
  1944.                         }
  1945.                         $invoiceId $new_invoice->getId();
  1946.                         $gatewayInvoice $new_invoice;
  1947.                         if ($request->request->get('isRecharge'0) == 1) {
  1948.                         } else {
  1949.                             if ($gatewayAmount <= 0) {
  1950.                                 $meetingId 0;
  1951.                                 if ($invoiceId != 0) {
  1952.                                     $retData Buddybee::ProcessEntityInvoice($em_goc$invoiceId, ['stage' => BuddybeeConstant::ENTITY_INVOICE_STAGE_COMPLETED], $this->container->getParameter('kernel.root_dir'), false,
  1953.                                         $this->container->getParameter('notification_enabled'),
  1954.                                         $this->container->getParameter('notification_server')
  1955.                                     );
  1956.                                     $meetingId $retData['meetingId'];
  1957.                                 }
  1958.                                 MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  1959.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  1960.                                     $billerDetails = [];
  1961.                                     $billToDetails = [];
  1962.                                     $invoice $gatewayInvoice;
  1963.                                     if ($invoice) {
  1964.                                         $billerDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1965.                                             ->findOneBy(
  1966.                                                 array(
  1967.                                                     'applicantId' => $invoice->getBillerId(),
  1968.                                                 )
  1969.                                             );
  1970.                                         $billToDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  1971.                                             ->findOneBy(
  1972.                                                 array(
  1973.                                                     'applicantId' => $invoice->getBillToId(),
  1974.                                                 )
  1975.                                             );
  1976.                                     }
  1977.                                     $bodyTemplate 'ApplicationBundle:email/templates:buddybeeInvoiceEmail.html.twig';
  1978.                                     $bodyData = array(
  1979.                                         'page_title' => 'Invoice',
  1980. //            'studentDetails' => $student,
  1981.                                         'billerDetails' => $billerDetails,
  1982.                                         'billToDetails' => $billToDetails,
  1983.                                         'invoice' => $invoice,
  1984.                                         'currencyList' => BuddybeeConstant::$currency_List,
  1985.                                         'currencyListByMarker' => BuddybeeConstant::$currency_List_by_marker,
  1986.                                     );
  1987.                                     $attachments = [];
  1988.                                     $forwardToMailAddress $billToDetails->getOAuthEmail();
  1989. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  1990.                                     $new_mail $this->get('mail_module');
  1991.                                     $new_mail->sendMyMail(array(
  1992.                                         'senderHash' => '_CUSTOM_',
  1993.                                         //                        'senderHash'=>'_CUSTOM_',
  1994.                                         'forwardToMailAddress' => $forwardToMailAddress,
  1995.                                         'subject' => 'YourInvoice #' 'D' str_pad('BB'5'0'STR_PAD_LEFT) . str_pad('76'2'0'STR_PAD_LEFT) . str_pad($invoice->getId(), 8"0"STR_PAD_LEFT) . ' from BuddyBee ',
  1996. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  1997.                                         'attachments' => $attachments,
  1998.                                         'toAddress' => $forwardToMailAddress,
  1999.                                         'fromAddress' => 'no-reply@buddybee.eu',
  2000.                                         'userName' => 'no-reply@buddybee.eu',
  2001.                                         'password' => 'Honeybee@0112',
  2002.                                         'smtpServer' => 'smtp.hostinger.com',
  2003.                                         'smtpPort' => 465,
  2004. //                            'emailBody' => $bodyHtml,
  2005.                                         'mailTemplate' => $bodyTemplate,
  2006.                                         'templateData' => $bodyData,
  2007.                                         'embedCompanyImage' => 0,
  2008.                                         'companyId' => 0,
  2009.                                         'companyImagePath' => ''
  2010. //                        'embedCompanyImage' => 1,
  2011. //                        'companyId' => $companyId,
  2012. //                        'companyImagePath' => $company_data->getImage()
  2013.                                     ));
  2014.                                 }
  2015.                                 if ($meetingId != 0) {
  2016.                                     $url $this->generateUrl(
  2017.                                         'consultancy_session'
  2018.                                     );
  2019.                                     $output = [
  2020.                                         'invoiceId' => $gatewayInvoice->getId(),
  2021.                                         'meetingId' => $meetingId,
  2022.                                         'proceedToCheckout' => 0,
  2023.                                         'redirectUrl' => $url '/' $meetingId
  2024.                                     ];
  2025.                                 } else {
  2026.                                     $url $this->generateUrl(
  2027.                                         'buddybee_dashboard'
  2028.                                     );
  2029.                                     $output = [
  2030.                                         'invoiceId' => $gatewayInvoice->getId(),
  2031.                                         'meetingId' => 0,
  2032.                                         'proceedToCheckout' => 0,
  2033.                                         'redirectUrl' => $url
  2034.                                     ];
  2035.                                 }
  2036.                                 return new JsonResponse($output);
  2037. //                return $this->redirect($url);
  2038.                             } else {
  2039.                             }
  2040. //                $url = $this->generateUrl(
  2041. //                    'checkout_page'
  2042. //                );
  2043. //
  2044. //                return $this->redirect($url."?meetingSessionId=".$new->getSessionId().'&invoiceId='.$invoiceId);
  2045.                         }
  2046.                     }
  2047.                 } else {
  2048.                     $url $this->generateUrl(
  2049.                         'user_login'
  2050.                     );
  2051.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$this->generateUrl(
  2052.                         'pricing_plan_page', [
  2053.                         'autoRedirected' => 1
  2054.                     ],
  2055.                         UrlGenerator::ABSOLUTE_URL
  2056.                     ));
  2057.                     $output = [
  2058.                         'proceedToCheckout' => 0,
  2059.                         'redirectUrl' => $url,
  2060.                         'clearLs' => 0
  2061.                     ];
  2062.                     return new JsonResponse($output);
  2063.                 }
  2064.                 //now proceed to checkout page if the user has lower balance or recharging
  2065.                 //$invoiceDetails = $em->getRepository('CompanyGroupBundle\\Entity\\EntityInvoice')->
  2066.             }
  2067.         }
  2068.         if ($gatewayInvoice) {
  2069.             $gatewayProductData json_decode($gatewayInvoice->getProductDataForPaymentGateway(), true);
  2070.             if ($gatewayProductData == null$gatewayProductData = [];
  2071.             if (empty($gatewayProductData))
  2072.                 $gatewayProductData = [
  2073.                     [
  2074.                         'price_data' => [
  2075.                             'currency' => 'eur',
  2076.                             'unit_amount' => $gatewayAmount != ? (100 $gatewayAmount) : 200000,
  2077.                             'product_data' => [
  2078. //                            'name' => $request->request->has('packageName') ? $request->request->get('packageName') : 'Advanced Consultancy Package',
  2079.                                 'name' => 'Bee Coins',
  2080.                                 'images' => [$imageBySessionCount[0]],
  2081.                             ],
  2082.                         ],
  2083.                         'quantity' => 1,
  2084.                     ]
  2085.                 ];
  2086.             $productDescStr '';
  2087.             $productDescArr = [];
  2088.             foreach ($gatewayProductData as $gpd) {
  2089.                 $productDescArr[] = $gpd['price_data']['product_data']['name'];
  2090.             }
  2091.             $productDescStr implode(','$productDescArr);
  2092.             $paymentGatewayFromInvoice $gatewayInvoice->getAmountTransferGateWayHash();
  2093. //            return new JsonResponse(
  2094. //                [
  2095. //                    'paymentGateway' => $paymentGatewayFromInvoice,
  2096. //                    'gateWayData' => $gatewayProductData[0]
  2097. //                ]
  2098. //            );
  2099.             if ($paymentGateway == null$paymentGatewayFromInvoice 'stripe';
  2100.             if ($paymentGatewayFromInvoice == 'stripe' || $paymentGatewayFromInvoice == 'aamarpay' || $paymentGatewayFromInvoice == 'bkash') {
  2101.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  2102.                     $billerDetails = [];
  2103.                     $billToDetails = [];
  2104.                     $invoice $gatewayInvoice;
  2105.                     if ($invoice) {
  2106.                         $billerDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  2107.                             ->findOneBy(
  2108.                                 array(
  2109.                                     'applicantId' => $invoice->getBillerId(),
  2110.                                 )
  2111.                             );
  2112.                         $billToDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  2113.                             ->findOneBy(
  2114.                                 array(
  2115.                                     'applicantId' => $invoice->getBillToId(),
  2116.                                 )
  2117.                             );
  2118.                     }
  2119.                     $bodyTemplate 'ApplicationBundle:email/templates:buddybeeInvoiceEmail.html.twig';
  2120.                     $bodyData = array(
  2121.                         'page_title' => 'Invoice',
  2122. //            'studentDetails' => $student,
  2123.                         'billerDetails' => $billerDetails,
  2124.                         'billToDetails' => $billToDetails,
  2125.                         'invoice' => $invoice,
  2126.                         'currencyList' => BuddybeeConstant::$currency_List,
  2127.                         'currencyListByMarker' => BuddybeeConstant::$currency_List_by_marker,
  2128.                     );
  2129.                     $attachments = [];
  2130.                     $forwardToMailAddress $billToDetails->getOAuthEmail();
  2131. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  2132.                     $new_mail $this->get('mail_module');
  2133.                     $new_mail->sendMyMail(array(
  2134.                         'senderHash' => '_CUSTOM_',
  2135.                         //                        'senderHash'=>'_CUSTOM_',
  2136.                         'forwardToMailAddress' => $forwardToMailAddress,
  2137.                         'subject' => 'YourInvoice #' 'D' str_pad('BB'5'0'STR_PAD_LEFT) . str_pad('76'2'0'STR_PAD_LEFT) . str_pad($invoice->getId(), 8"0"STR_PAD_LEFT) . ' from BuddyBee ',
  2138. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  2139.                         'attachments' => $attachments,
  2140.                         'toAddress' => $forwardToMailAddress,
  2141.                         'fromAddress' => 'no-reply@buddybee.eu',
  2142.                         'userName' => 'no-reply@buddybee.eu',
  2143.                         'password' => 'Honeybee@0112',
  2144.                         'smtpServer' => 'smtp.hostinger.com',
  2145.                         'smtpPort' => 465,
  2146. //                            'emailBody' => $bodyHtml,
  2147.                         'mailTemplate' => $bodyTemplate,
  2148.                         'templateData' => $bodyData,
  2149.                         'embedCompanyImage' => 0,
  2150.                         'companyId' => 0,
  2151.                         'companyImagePath' => ''
  2152. //                        'embedCompanyImage' => 1,
  2153. //                        'companyId' => $companyId,
  2154. //                        'companyImagePath' => $company_data->getImage()
  2155.                     ));
  2156.                 }
  2157.             }
  2158.             if ($paymentGatewayFromInvoice == 'stripe') {
  2159.                 $stripe = new \Stripe\Stripe();
  2160.                 \Stripe\Stripe::setApiKey('sk_test_51IxYTAJXs21fVb0QMop2Nb0E7u9Da4LwGrym1nGHUHqaSNtT3p9HBgHd7YyDsTKHscgPPECPQniTy79Ab8Sgxfbm00JF2AndUz');
  2161.                 $stripe::setApiKey('sk_test_51IxYTAJXs21fVb0QMop2Nb0E7u9Da4LwGrym1nGHUHqaSNtT3p9HBgHd7YyDsTKHscgPPECPQniTy79Ab8Sgxfbm00JF2AndUz');
  2162.                 {
  2163.                     if ($request->query->has('meetingSessionId'))
  2164.                         $id $request->query->get('meetingSessionId');
  2165.                 }
  2166.                 $paymentIntent = [
  2167.                     "id" => "pi_1DoWjK2eZvKYlo2Csy9J3BHs",
  2168.                     "object" => "payment_intent",
  2169.                     "amount" => 3000,
  2170.                     "amount_capturable" => 0,
  2171.                     "amount_received" => 0,
  2172.                     "application" => null,
  2173.                     "application_fee_amount" => null,
  2174.                     "canceled_at" => null,
  2175.                     "cancellation_reason" => null,
  2176.                     "capture_method" => "automatic",
  2177.                     "charges" => [
  2178.                         "object" => "list",
  2179.                         "data" => [],
  2180.                         "has_more" => false,
  2181.                         "url" => "/v1/charges?payment_intent=pi_1DoWjK2eZvKYlo2Csy9J3BHs"
  2182.                     ],
  2183.                     "client_secret" => "pi_1DoWjK2eZvKYlo2Csy9J3BHs_secret_vmxAcWZxo2kt1XhpWtZtnjDtd",
  2184.                     "confirmation_method" => "automatic",
  2185.                     "created" => 1546523966,
  2186.                     "currency" => $currencyForGateway,
  2187.                     "customer" => null,
  2188.                     "description" => null,
  2189.                     "invoice" => null,
  2190.                     "last_payment_error" => null,
  2191.                     "livemode" => false,
  2192.                     "metadata" => [],
  2193.                     "next_action" => null,
  2194.                     "on_behalf_of" => null,
  2195.                     "payment_method" => null,
  2196.                     "payment_method_options" => [],
  2197.                     "payment_method_types" => [
  2198.                         "card"
  2199.                     ],
  2200.                     "receipt_email" => null,
  2201.                     "review" => null,
  2202.                     "setup_future_usage" => null,
  2203.                     "shipping" => null,
  2204.                     "statement_descriptor" => null,
  2205.                     "statement_descriptor_suffix" => null,
  2206.                     "status" => "requires_payment_method",
  2207.                     "transfer_data" => null,
  2208.                     "transfer_group" => null
  2209.                 ];
  2210.                 $checkout_session = \Stripe\Checkout\Session::create([
  2211.                     'payment_method_types' => ['card'],
  2212.                     'line_items' => $gatewayProductData,
  2213.                     'mode' => 'payment',
  2214.                     'success_url' => $this->generateUrl(
  2215.                         'payment_gateway_success',
  2216.                         ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  2217.                             'invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1)
  2218.                         ))), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  2219.                     ),
  2220.                     'cancel_url' => $this->generateUrl(
  2221.                         'payment_gateway_cancel', ['invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  2222.                     ),
  2223.                 ]);
  2224.                 $output = [
  2225.                     'clientSecret' => $paymentIntent['client_secret'],
  2226.                     'id' => $checkout_session->id,
  2227.                     'paymentGateway' => $paymentGatewayFromInvoice,
  2228.                     'proceedToCheckout' => 1
  2229.                 ];
  2230.                 return new JsonResponse($output);
  2231.             }
  2232.             if ($paymentGatewayFromInvoice == 'aamarpay') {
  2233.                 $studentDetails $em_goc->getRepository(EntityApplicantDetails::class)->find($gatewayInvoice->getBillToId());
  2234.                 $url $sandBoxMode == 'https://sandbox.aamarpay.com/request.php' 'https://secure.aamarpay.com/request.php';
  2235.                 $fields = array(
  2236. //                    'store_id' => 'aamarpaytest', //store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  2237.                     'store_id' => $sandBoxMode == 'aamarpaytest' 'buddybee'//store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  2238.                     'amount' => $gatewayInvoice->getGateWayBillamount(), //transaction amount
  2239.                     'payment_type' => 'VISA'//no need to change
  2240.                     'currency' => strtoupper($currencyForGateway),  //currenct will be USD/BDT
  2241.                     'tran_id' => $gatewayInvoice->getDocumentHash(), //transaction id must be unique from your end
  2242.                     'cus_name' => $studentDetails->getFirstname() . ' ' $studentDetails->getLastName(),  //customer name
  2243.                     'cus_email' => $studentDetails->getEmail(), //customer email address
  2244.                     'cus_add1' => $studentDetails->getCurrAddr(),  //customer address
  2245.                     'cus_add2' => $studentDetails->getCurrAddrCity(), //customer address
  2246.                     'cus_city' => $studentDetails->getCurrAddrCity(),  //customer city
  2247.                     'cus_state' => $studentDetails->getCurrAddrState(),  //state
  2248.                     'cus_postcode' => $studentDetails->getCurrAddrZip(), //postcode or zipcode
  2249.                     'cus_country' => 'Bangladesh',  //country
  2250.                     'cus_phone' => ($studentDetails->getPhone() == null || $studentDetails->getPhone() == '') ? '+8801911706483' $studentDetails->getPhone(), //customer phone number
  2251.                     'cus_fax' => '',  //fax
  2252.                     'ship_name' => ''//ship name
  2253.                     'ship_add1' => '',  //ship address
  2254.                     'ship_add2' => '',
  2255.                     'ship_city' => '',
  2256.                     'ship_state' => '',
  2257.                     'ship_postcode' => '',
  2258.                     'ship_country' => 'Bangladesh',
  2259.                     'desc' => $productDescStr,
  2260.                     'success_url' => $this->generateUrl(
  2261.                         'payment_gateway_success',
  2262.                         ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  2263.                             'invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1)
  2264.                         ))), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  2265.                     ),
  2266.                     'fail_url' => $this->generateUrl(
  2267.                         'payment_gateway_cancel', ['invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  2268.                     ),
  2269.                     'cancel_url' => $this->generateUrl(
  2270.                         'payment_gateway_cancel', ['invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  2271.                     ),
  2272. //                    'opt_a' => 'Reshad',  //optional paramter
  2273. //                    'opt_b' => 'Akil',
  2274. //                    'opt_c' => 'Liza',
  2275. //                    'opt_d' => 'Sohel',
  2276. //                    'signature_key' => 'dbb74894e82415a2f7ff0ec3a97e4183',  //sandbox
  2277.                     'signature_key' => $sandBoxMode == 'dbb74894e82415a2f7ff0ec3a97e4183' 'b7304a40e21fe15af3be9a948307f524'  //live
  2278.                 ); //signature key will provided aamarpay, contact integration@aamarpay.com for test/live signature key
  2279.                 $fields_string http_build_query($fields);
  2280. //                $ch = curl_init();
  2281. //                curl_setopt($ch, CURLOPT_VERBOSE, true);
  2282. //                curl_setopt($ch, CURLOPT_URL, $url);
  2283. //
  2284. //                curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  2285. //                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2286. //                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  2287. //                $url_forward = str_replace('"', '', stripslashes(curl_exec($ch)));
  2288. //                curl_close($ch);
  2289. //                $this->redirect_to_merchant($url_forward);
  2290.                 $output = [
  2291. //
  2292. //                    'redirectUrl' => ($sandBoxMode == 1 ? 'https://sandbox.aamarpay.com/' : 'https://secure.aamarpay.com/') . $url_forward, //keeping it off temporarily
  2293. //                    'fields'=>$fields,
  2294. //                    'fields_string'=>$fields_string,
  2295. //                    'redirectUrl' => $this->generateUrl(
  2296. //                        'payment_gateway_success',
  2297. //                        ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  2298. //                            'invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1)
  2299. //                        ))), 'hbeeSessionToken' => $request->request->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  2300. //                    ),
  2301.                     'paymentGateway' => $paymentGatewayFromInvoice,
  2302.                     'proceedToCheckout' => 1,
  2303.                     'data' => $fields
  2304.                 ];
  2305.                 return new JsonResponse($output);
  2306.             } else if ($paymentGatewayFromInvoice == 'bkash') {
  2307.                 $studentDetails $em_goc->getRepository(EntityApplicantDetails::class)->find($gatewayInvoice->getBillToId());
  2308.                 $baseUrl = ($sandBoxMode == 1) ? 'https://tokenized.sandbox.bka.sh/v1.2.0-beta' 'https://tokenized.pay.bka.sh/v1.2.0-beta';
  2309.                 $username_value = ($sandBoxMode == 1) ? 'sandboxTokenizedUser02' '01891962953';
  2310.                 $password_value = ($sandBoxMode == 1) ? 'sandboxTokenizedUser02@12345' ',a&kPV4deq&';
  2311.                 $app_key_value = ($sandBoxMode == 1) ? '4f6o0cjiki2rfm34kfdadl1eqq' '2ueVHdwz5gH3nxx7xn8wotlztc';
  2312.                 $app_secret_value = ($sandBoxMode == 1) ? '2is7hdktrekvrbljjh44ll3d9l1dtjo4pasmjvs5vl5qr3fug4b' '49Ay3h3wWJMBFD7WF5CassyLrtA1jt6ONhspqjqFx5hTjhqh5dHU';
  2313.                 $request_data = array(
  2314.                     'app_key' => $app_key_value,
  2315.                     'app_secret' => $app_secret_value
  2316.                 );
  2317.                 $url curl_init($baseUrl '/tokenized/checkout/token/grant');
  2318.                 $request_data_json json_encode($request_data);
  2319.                 $header = array(
  2320.                     'Content-Type:application/json',
  2321.                     'username:' $username_value,
  2322.                     'password:' $password_value
  2323.                 );
  2324.                 curl_setopt($urlCURLOPT_HTTPHEADER$header);
  2325.                 curl_setopt($urlCURLOPT_CUSTOMREQUEST"POST");
  2326.                 curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  2327.                 curl_setopt($urlCURLOPT_POSTFIELDS$request_data_json);
  2328.                 curl_setopt($urlCURLOPT_FOLLOWLOCATION1);
  2329.                 curl_setopt($urlCURLOPT_IPRESOLVECURL_IPRESOLVE_V4);
  2330.                 $tokenData json_decode(curl_exec($url), true);
  2331.                 curl_close($url);
  2332.                 $id_token $tokenData['id_token'];
  2333.                 $goToBkashPage 0;
  2334.                 if ($tokenData['statusCode'] == '0000') {
  2335.                     $auth $id_token;
  2336.                     $requestbody = array(
  2337.                         "mode" => "0011",
  2338. //                        "payerReference" => "01723888888",
  2339.                         "payerReference" => $invoiceDate->format('U'),
  2340.                         "callbackURL" => $this->generateUrl(
  2341.                             'bkash_callback', [], UrlGenerator::ABSOLUTE_URL
  2342.                         ),
  2343. //                    "merchantAssociationInfo" => "MI05MID54RF09123456One",
  2344.                         "amount" => number_format($gatewayInvoice->getGateWayBillamount(), 2'.'''),
  2345.                         "currency" => "BDT",
  2346.                         "intent" => "sale",
  2347.                         "merchantInvoiceNumber" => $invoiceId
  2348.                     );
  2349.                     $url curl_init($baseUrl '/tokenized/checkout/create');
  2350.                     $requestbodyJson json_encode($requestbody);
  2351.                     $header = array(
  2352.                         'Content-Type:application/json',
  2353.                         'Authorization:' $auth,
  2354.                         'X-APP-Key:' $app_key_value
  2355.                     );
  2356.                     curl_setopt($urlCURLOPT_HTTPHEADER$header);
  2357.                     curl_setopt($urlCURLOPT_CUSTOMREQUEST"POST");
  2358.                     curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  2359.                     curl_setopt($urlCURLOPT_POSTFIELDS$requestbodyJson);
  2360.                     curl_setopt($urlCURLOPT_FOLLOWLOCATION1);
  2361.                     curl_setopt($urlCURLOPT_IPRESOLVECURL_IPRESOLVE_V4);
  2362.                     $resultdata curl_exec($url);
  2363. //                    curl_close($url);
  2364. //                    echo $resultdata;
  2365.                     $obj json_decode($resultdatatrue);
  2366.                     $goToBkashPage 1;
  2367.                     $justNow = new \DateTime();
  2368.                     $justNow->modify('+' $tokenData['expires_in'] . ' second');
  2369.                     $gatewayInvoice->setGatewayIdTokenExpireTs($justNow->format('U'));
  2370.                     $gatewayInvoice->setGatewayIdToken($tokenData['id_token']);
  2371.                     $gatewayInvoice->setGatewayPaymentId($obj['paymentID']);
  2372.                     $gatewayInvoice->setGatewayIdRefreshToken($tokenData['refresh_token']);
  2373.                     $em->flush();
  2374.                     $output = [
  2375. //                        'redirectUrl' => $obj['bkashURL'],
  2376.                         'paymentGateway' => $paymentGatewayFromInvoice,
  2377.                         'proceedToCheckout' => $goToBkashPage,
  2378.                         'tokenData' => $tokenData,
  2379.                         'obj' => $obj,
  2380.                         'id_token' => $tokenData['id_token'],
  2381.                         'data' => [
  2382.                             'amount' => $gatewayInvoice->getGateWayBillamount(), //transaction amount
  2383. //                            'payment_type' => 'VISA', //no need to change
  2384.                             'currency' => strtoupper($currencyForGateway),  //currenct will be USD/BDT
  2385.                             'tran_id' => $gatewayInvoice->getDocumentHash(), //transaction id must be unique from your end
  2386.                             'cus_name' => $studentDetails->getFirstname() . ' ' $studentDetails->getLastName(),  //customer name
  2387.                             'cus_email' => $studentDetails->getEmail(), //customer email address
  2388.                             'cus_add1' => $studentDetails->getCurrAddr(),  //customer address
  2389.                             'cus_add2' => $studentDetails->getCurrAddrCity(), //customer address
  2390.                             'cus_city' => $studentDetails->getCurrAddrCity(),  //customer city
  2391.                             'cus_state' => $studentDetails->getCurrAddrState(),  //state
  2392.                             'cus_postcode' => $studentDetails->getCurrAddrZip(), //postcode or zipcode
  2393.                             'cus_country' => 'Bangladesh',  //country
  2394.                             'cus_phone' => ($studentDetails->getPhone() == null || $studentDetails->getPhone() == '') ? '+8801911706483' $studentDetails->getPhone(), //customer phone number
  2395.                             'cus_fax' => '',  //fax
  2396.                             'ship_name' => ''//ship name
  2397.                             'ship_add1' => '',  //ship address
  2398.                             'ship_add2' => '',
  2399.                             'ship_city' => '',
  2400.                             'ship_state' => '',
  2401.                             'ship_postcode' => '',
  2402.                             'ship_country' => 'Bangladesh',
  2403.                             'desc' => $productDescStr,
  2404.                         ]
  2405.                     ];
  2406.                     return new JsonResponse($output);
  2407.                 }
  2408. //                $fields = array(
  2409. //
  2410. //                    "mode" => "0011",
  2411. //                    "payerReference" => "01723888888",
  2412. //                    "callbackURL" => $this->generateUrl(
  2413. //                        'payment_gateway_success',
  2414. //                        ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  2415. //                            'invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1)
  2416. //                        ))), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  2417. //                    ),
  2418. //                    "merchantAssociationInfo" => "MI05MID54RF09123456One",
  2419. //                    "amount" => 1*number_format($gatewayInvoice->getGateWayBillamount(),2,'.',''),,
  2420. //                    "currency" => "BDT",
  2421. //                    "intent" => "sale",
  2422. //                    "merchantInvoiceNumber" => 'BEI' . str_pad($gatewayInvoice->getBillerId(), 3, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getBillToId(), 5, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getId(), 4, '0', STR_PAD_LEFT)
  2423. //
  2424. //                );
  2425. //                $fields = array(
  2426. ////                    'store_id' => 'aamarpaytest', //store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  2427. //                    'store_id' => $sandBoxMode == 1 ? 'aamarpaytest' : 'buddybee', //store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  2428. //                    'amount' => 1*number_format($gatewayInvoice->getGateWayBillamount(),2,'.',''),, //transaction amount
  2429. //                    'payment_type' => 'VISA', //no need to change
  2430. //                    'currency' => strtoupper($currencyForGateway),  //currenct will be USD/BDT
  2431. //                    'tran_id' => 'BEI' . str_pad($gatewayInvoice->getBillerId(), 3, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getBillToId(), 5, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getId(), 4, '0', STR_PAD_LEFT), //transaction id must be unique from your end
  2432. //                    'cus_name' => $studentDetails->getFirstname() . ' ' . $studentDetails->getLastName(),  //customer name
  2433. //                    'cus_email' => $studentDetails->getEmail(), //customer email address
  2434. //                    'cus_add1' => $studentDetails->getCurrAddr(),  //customer address
  2435. //                    'cus_add2' => $studentDetails->getCurrAddrCity(), //customer address
  2436. //                    'cus_city' => $studentDetails->getCurrAddrCity(),  //customer city
  2437. //                    'cus_state' => $studentDetails->getCurrAddrState(),  //state
  2438. //                    'cus_postcode' => $studentDetails->getCurrAddrZip(), //postcode or zipcode
  2439. //                    'cus_country' => 'Bangladesh',  //country
  2440. //                    'cus_phone' => ($studentDetails->getPhone() == null || $studentDetails->getPhone() == '') ? ' + 8801911706483' : $studentDetails->getPhone(), //customer phone number
  2441. //                    'cus_fax' => '',  //fax
  2442. //                    'ship_name' => '', //ship name
  2443. //                    'ship_add1' => '',  //ship address
  2444. //                    'ship_add2' => '',
  2445. //                    'ship_city' => '',
  2446. //                    'ship_state' => '',
  2447. //                    'ship_postcode' => '',
  2448. //                    'ship_country' => 'Bangladesh',
  2449. //                    'desc' => $productDescStr,
  2450. //                    'success_url' => $this->generateUrl(
  2451. //                        'payment_gateway_success',
  2452. //                        ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  2453. //                            'invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1)
  2454. //                        ))), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  2455. //                    ),
  2456. //                    'fail_url' => $this->generateUrl(
  2457. //                        'payment_gateway_cancel', ['invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  2458. //                    ),
  2459. //                    'cancel_url' => $this->generateUrl(
  2460. //                        'payment_gateway_cancel', ['invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  2461. //                    ),
  2462. ////                    'opt_a' => 'Reshad',  //optional paramter
  2463. ////                    'opt_b' => 'Akil',
  2464. ////                    'opt_c' => 'Liza',
  2465. ////                    'opt_d' => 'Sohel',
  2466. ////                    'signature_key' => 'dbb74894e82415a2f7ff0ec3a97e4183',  //sandbox
  2467. //                    'signature_key' => $sandBoxMode == 1 ? 'dbb74894e82415a2f7ff0ec3a97e4183' : 'b7304a40e21fe15af3be9a948307f524'  //live
  2468. //
  2469. //                ); //signature key will provided aamarpay, contact integration@aamarpay.com for test/live signature key
  2470. //
  2471. //                $fields_string = http_build_query($fields);
  2472. //
  2473. //                $ch = curl_init();
  2474. //                curl_setopt($ch, CURLOPT_VERBOSE, true);
  2475. //                curl_setopt($ch, CURLOPT_URL, $url);
  2476. //
  2477. //                curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  2478. //                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2479. //                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  2480. //                $url_forward = str_replace('"', '', stripslashes(curl_exec($ch)));
  2481. //                curl_close($ch);
  2482. //                $this->redirect_to_merchant($url_forward);
  2483.             } else if ($paymentGatewayFromInvoice == 'onsite_pos' || $paymentGatewayFromInvoice == 'onsite_cash' || $paymentGatewayFromInvoice == 'onsite_bkash') {
  2484.                 $meetingId 0;
  2485.                 if ($gatewayInvoice->getId() != 0) {
  2486.                     if ($gatewayInvoice->getDueAmount() <= 0) {
  2487.                         $retData Buddybee::ProcessEntityInvoice($em_goc$gatewayInvoice->getId(), ['stage' => BuddybeeConstant::ENTITY_INVOICE_STAGE_COMPLETED], $this->container->getParameter('kernel.root_dir'), false,
  2488.                             $this->container->getParameter('notification_enabled'),
  2489.                             $this->container->getParameter('notification_server')
  2490.                         );
  2491.                         $meetingId $retData['meetingId'];
  2492.                     }
  2493.                     if (GeneralConstant::EMAIL_ENABLED == 1) {
  2494.                         $billerDetails = [];
  2495.                         $billToDetails = [];
  2496.                         $invoice $gatewayInvoice;
  2497.                         if ($invoice) {
  2498.                             $billerDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  2499.                                 ->findOneBy(
  2500.                                     array(
  2501.                                         'applicantId' => $invoice->getBillerId(),
  2502.                                     )
  2503.                                 );
  2504.                             $billToDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  2505.                                 ->findOneBy(
  2506.                                     array(
  2507.                                         'applicantId' => $invoice->getBillToId(),
  2508.                                     )
  2509.                                 );
  2510.                         }
  2511.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeInvoiceEmail.html.twig';
  2512.                         $bodyData = array(
  2513.                             'page_title' => 'Invoice',
  2514. //            'studentDetails' => $student,
  2515.                             'billerDetails' => $billerDetails,
  2516.                             'billToDetails' => $billToDetails,
  2517.                             'invoice' => $invoice,
  2518.                             'currencyList' => BuddybeeConstant::$currency_List,
  2519.                             'currencyListByMarker' => BuddybeeConstant::$currency_List_by_marker,
  2520.                         );
  2521.                         $attachments = [];
  2522.                         $forwardToMailAddress $billToDetails->getOAuthEmail();
  2523. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  2524.                         $new_mail $this->get('mail_module');
  2525.                         $new_mail->sendMyMail(array(
  2526.                             'senderHash' => '_CUSTOM_',
  2527.                             //                        'senderHash'=>'_CUSTOM_',
  2528.                             'forwardToMailAddress' => $forwardToMailAddress,
  2529.                             'subject' => 'YourInvoice #' 'D' str_pad('BB'5'0'STR_PAD_LEFT) . str_pad('76'2'0'STR_PAD_LEFT) . str_pad($invoice->getId(), 8"0"STR_PAD_LEFT) . ' from BuddyBee ',
  2530. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  2531.                             'attachments' => $attachments,
  2532.                             'toAddress' => $forwardToMailAddress,
  2533.                             'fromAddress' => 'no-reply@buddybee.eu',
  2534.                             'userName' => 'no-reply@buddybee.eu',
  2535.                             'password' => 'Honeybee@0112',
  2536.                             'smtpServer' => 'smtp.hostinger.com',
  2537.                             'smtpPort' => 465,
  2538. //                            'emailBody' => $bodyHtml,
  2539.                             'mailTemplate' => $bodyTemplate,
  2540.                             'templateData' => $bodyData,
  2541.                             'embedCompanyImage' => 0,
  2542.                             'companyId' => 0,
  2543.                             'companyImagePath' => ''
  2544. //                        'embedCompanyImage' => 1,
  2545. //                        'companyId' => $companyId,
  2546. //                        'companyImagePath' => $company_data->getImage()
  2547.                         ));
  2548.                     }
  2549.                 }
  2550.                 MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  2551.                 if ($meetingId != 0) {
  2552.                     $url $this->generateUrl(
  2553.                         'consultancy_session'
  2554.                     );
  2555.                     $output = [
  2556.                         'proceedToCheckout' => 0,
  2557.                         'invoiceId' => $gatewayInvoice->getId(),
  2558.                         'meetingId' => $meetingId,
  2559.                         'redirectUrl' => $url '/' $meetingId
  2560.                     ];
  2561.                 } else {
  2562.                     $url $this->generateUrl(
  2563.                         'buddybee_dashboard'
  2564.                     );
  2565.                     $output = [
  2566.                         'proceedToCheckout' => 0,
  2567.                         'invoiceId' => $gatewayInvoice->getId(),
  2568.                         'meetingId' => $meetingId,
  2569.                         'redirectUrl' => $url
  2570.                     ];
  2571.                 }
  2572.                 return new JsonResponse($output);
  2573.             }
  2574.         }
  2575.         $output = [
  2576.             'clientSecret' => 0,
  2577.             'id' => 0,
  2578.             'proceedToCheckout' => 0
  2579.         ];
  2580.         return new JsonResponse($output);
  2581. //        return $this->render('ApplicationBundle:pages/stripe:checkout.html.twig', array(
  2582. //            'page_title' => 'Checkout',
  2583. ////            'stripe' => $stripe,
  2584. //            'stripe' => null,
  2585. ////            'PaymentIntent' => $paymentIntent,
  2586. //
  2587. ////            'consultantDetail' => $consultantDetail,
  2588. ////            'consultantDetails'=> $consultantDetails,
  2589. ////
  2590. ////            'meetingSession' => $meetingSession,
  2591. ////            'packageDetails' => json_decode($meetingSession->getPcakageDetails(),true),
  2592. ////            'packageName' => json_decode($meetingSession->getPackageName(),true),
  2593. ////            'pay' => $payableAmount,
  2594. ////            'balance' => $currStudentBal
  2595. //        ));
  2596.     }
  2597.     public function PaymentGatewaySuccessAction(Request $request$encData '')
  2598.     {
  2599.         $em $this->getDoctrine()->getManager('company_group');
  2600.         $invoiceId 0;
  2601.         $autoRedirect 1;
  2602.         $redirectUrl '';
  2603.         $meetingId 0;
  2604.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  2605.         if ($systemType == '_CENTRAL_') {
  2606.             if ($encData != '') {
  2607.                 $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  2608.                 if (isset($encryptedData['invoiceId']))
  2609.                     $invoiceId $encryptedData['invoiceId'];
  2610.                 if (isset($encryptedData['autoRedirect']))
  2611.                     $autoRedirect $encryptedData['autoRedirect'];
  2612.             } else {
  2613.                 $invoiceId $request->query->get('invoiceId'0);
  2614.                 $meetingId 0;
  2615.                 $autoRedirect $request->query->get('autoRedirect'1);
  2616.                 $redirectUrl '';
  2617.             }
  2618.             if ($invoiceId != 0) {
  2619.                 $retData Buddybee::ProcessEntityInvoice($em$invoiceId, ['stage' => BuddybeeConstant::ENTITY_INVOICE_STAGE_COMPLETED],
  2620.                     $this->container->getParameter('kernel.root_dir'),
  2621.                     false,
  2622.                     $this->container->getParameter('notification_enabled'),
  2623.                     $this->container->getParameter('notification_server')
  2624.                 );
  2625.                 if ($retData['sendCards'] == 1) {
  2626.                     $cardList = array();
  2627.                     $cards $em->getRepository('CompanyGroupBundle\\Entity\\BeeCode')
  2628.                         ->findBy(
  2629.                             array(
  2630.                                 'id' => $retData['cardIds']
  2631.                             )
  2632.                         );
  2633.                     foreach ($cards as $card) {
  2634.                         $cardList[] = array(
  2635.                             'id' => $card->getId(),
  2636.                             'printed' => $card->getPrinted(),
  2637.                             'amount' => $card->getAmount(),
  2638.                             'coinCount' => $card->getCoinCount(),
  2639.                             'pin' => $card->getPin(),
  2640.                             'serial' => $card->getSerial(),
  2641.                         );
  2642.                     }
  2643.                     $receiverEmail $retData['receiverEmail'];
  2644.                     if (GeneralConstant::EMAIL_ENABLED == 1) {
  2645.                         $bodyHtml '';
  2646.                         $bodyTemplate 'ApplicationBundle:email/templates:beeCodeDigitalDelivery.html.twig';
  2647.                         $bodyData = array(
  2648.                             'cardList' => $cardList,
  2649. //                        'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  2650. //                        'email' => $userName,
  2651. //                        'password' => $newApplicant->getPassword(),
  2652.                         );
  2653.                         $attachments = [];
  2654.                         $forwardToMailAddress $receiverEmail;
  2655. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  2656.                         $new_mail $this->get('mail_module');
  2657.                         $new_mail->sendMyMail(array(
  2658.                             'senderHash' => '_CUSTOM_',
  2659.                             //                        'senderHash'=>'_CUSTOM_',
  2660.                             'forwardToMailAddress' => $forwardToMailAddress,
  2661.                             'subject' => 'Digital Bee Card Delivery',
  2662. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  2663.                             'attachments' => $attachments,
  2664.                             'toAddress' => $forwardToMailAddress,
  2665.                             'fromAddress' => 'delivery@buddybee.eu',
  2666.                             'userName' => 'delivery@buddybee.eu',
  2667.                             'password' => 'Honeybee@0112',
  2668.                             'smtpServer' => 'smtp.hostinger.com',
  2669.                             'smtpPort' => 465,
  2670. //                        'encryptionMethod' => 'tls',
  2671.                             'encryptionMethod' => 'ssl',
  2672. //                            'emailBody' => $bodyHtml,
  2673.                             'mailTemplate' => $bodyTemplate,
  2674.                             'templateData' => $bodyData,
  2675. //                        'embedCompanyImage' => 1,
  2676. //                        'companyId' => $companyId,
  2677. //                        'companyImagePath' => $company_data->getImage()
  2678.                         ));
  2679.                         foreach ($cards as $card) {
  2680.                             $card->setPrinted(1);
  2681.                         }
  2682.                         $em->flush();
  2683.                     }
  2684.                     return new JsonResponse(
  2685.                         array(
  2686.                             'success' => true
  2687.                         )
  2688.                     );
  2689.                 }
  2690.                 MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  2691.                 $meetingId $retData['meetingId'];
  2692.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  2693.                     $billerDetails = [];
  2694.                     $billToDetails = [];
  2695.                     $invoice $em->getRepository('CompanyGroupBundle\\Entity\\EntityInvoice')
  2696.                         ->findOneBy(
  2697.                             array(
  2698.                                 'Id' => $invoiceId,
  2699.                             )
  2700.                         );;
  2701.                     if ($invoice) {
  2702.                         $billerDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  2703.                             ->findOneBy(
  2704.                                 array(
  2705.                                     'applicantId' => $invoice->getBillerId(),
  2706.                                 )
  2707.                             );
  2708.                         $billToDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  2709.                             ->findOneBy(
  2710.                                 array(
  2711.                                     'applicantId' => $invoice->getBillToId(),
  2712.                                 )
  2713.                             );
  2714.                     }
  2715.                     $bodyTemplate 'ApplicationBundle:email/templates:buddybeeInvoiceEmail.html.twig';
  2716.                     $bodyData = array(
  2717.                         'page_title' => 'Invoice',
  2718. //            'studentDetails' => $student,
  2719.                         'billerDetails' => $billerDetails,
  2720.                         'billToDetails' => $billToDetails,
  2721.                         'invoice' => $invoice,
  2722.                         'currencyList' => BuddybeeConstant::$currency_List,
  2723.                         'currencyListByMarker' => BuddybeeConstant::$currency_List_by_marker,
  2724.                     );
  2725.                     $attachments = [];
  2726.                     $forwardToMailAddress $billToDetails->getOAuthEmail();
  2727. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  2728.                     $new_mail $this->get('mail_module');
  2729.                     $new_mail->sendMyMail(array(
  2730.                         'senderHash' => '_CUSTOM_',
  2731.                         //                        'senderHash'=>'_CUSTOM_',
  2732.                         'forwardToMailAddress' => $forwardToMailAddress,
  2733.                         'subject' => 'YourInvoice #' 'D' str_pad('BB'5'0'STR_PAD_LEFT) . str_pad('76'2'0'STR_PAD_LEFT) . str_pad($invoice->getId(), 8"0"STR_PAD_LEFT) . ' from BuddyBee ',
  2734. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  2735.                         'attachments' => $attachments,
  2736.                         'toAddress' => $forwardToMailAddress,
  2737.                         'fromAddress' => 'no-reply@buddybee.eu',
  2738.                         'userName' => 'no-reply@buddybee.eu',
  2739.                         'password' => 'Honeybee@0112',
  2740.                         'smtpServer' => 'smtp.hostinger.com',
  2741.                         'smtpPort' => 465,
  2742. //                            'emailBody' => $bodyHtml,
  2743.                         'mailTemplate' => $bodyTemplate,
  2744.                         'templateData' => $bodyData,
  2745.                         'embedCompanyImage' => 0,
  2746.                         'companyId' => 0,
  2747.                         'companyImagePath' => ''
  2748. //                        'embedCompanyImage' => 1,
  2749. //                        'companyId' => $companyId,
  2750. //                        'companyImagePath' => $company_data->getImage()
  2751.                     ));
  2752.                 }
  2753. //
  2754.                 if ($meetingId != 0) {
  2755.                     $url $this->generateUrl(
  2756.                         'consultancy_session'
  2757.                     );
  2758. //                if($request->query->get('autoRedirect',1))
  2759. //                    return $this->redirect($url . '/' . $meetingId);
  2760.                     $redirectUrl $url '/' $meetingId;
  2761.                 } else {
  2762.                     $url $this->generateUrl(
  2763.                         'central_landing'
  2764.                     );
  2765. //                if($request->query->get('autoRedirect',1))
  2766. //                    return $this->redirect($url);
  2767.                     $redirectUrl $url;
  2768.                 }
  2769.             }
  2770.             return $this->render('ApplicationBundle:pages/stripe:success.html.twig', array(
  2771.                 'page_title' => 'Success',
  2772.                 'meetingId' => $meetingId,
  2773.                 'autoRedirect' => $autoRedirect,
  2774.                 'redirectUrl' => $redirectUrl,
  2775.             ));
  2776.         } else if ($systemType == '_BUDDYBEE_') {
  2777.             if ($encData != '') {
  2778.                 $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  2779.                 if (isset($encryptedData['invoiceId']))
  2780.                     $invoiceId $encryptedData['invoiceId'];
  2781.                 if (isset($encryptedData['autoRedirect']))
  2782.                     $autoRedirect $encryptedData['autoRedirect'];
  2783.             } else {
  2784.                 $invoiceId $request->query->get('invoiceId'0);
  2785.                 $meetingId 0;
  2786.                 $autoRedirect $request->query->get('autoRedirect'1);
  2787.                 $redirectUrl '';
  2788.             }
  2789.             if ($invoiceId != 0) {
  2790.                 $retData Buddybee::ProcessEntityInvoice($em$invoiceId, ['stage' => BuddybeeConstant::ENTITY_INVOICE_STAGE_COMPLETED], false,
  2791.                     $this->container->getParameter('notification_enabled'),
  2792.                     $this->container->getParameter('notification_server')
  2793.                 );
  2794.                 if ($retData['sendCards'] == 1) {
  2795.                     $cardList = array();
  2796.                     $cards $em->getRepository('CompanyGroupBundle\\Entity\\BeeCode')
  2797.                         ->findBy(
  2798.                             array(
  2799.                                 'id' => $retData['cardIds']
  2800.                             )
  2801.                         );
  2802.                     foreach ($cards as $card) {
  2803.                         $cardList[] = array(
  2804.                             'id' => $card->getId(),
  2805.                             'printed' => $card->getPrinted(),
  2806.                             'amount' => $card->getAmount(),
  2807.                             'coinCount' => $card->getCoinCount(),
  2808.                             'pin' => $card->getPin(),
  2809.                             'serial' => $card->getSerial(),
  2810.                         );
  2811.                     }
  2812.                     $receiverEmail $retData['receiverEmail'];
  2813.                     if (GeneralConstant::EMAIL_ENABLED == 1) {
  2814.                         $bodyHtml '';
  2815.                         $bodyTemplate 'ApplicationBundle:email/templates:beeCodeDigitalDelivery.html.twig';
  2816.                         $bodyData = array(
  2817.                             'cardList' => $cardList,
  2818. //                        'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
  2819. //                        'email' => $userName,
  2820. //                        'password' => $newApplicant->getPassword(),
  2821.                         );
  2822.                         $attachments = [];
  2823.                         $forwardToMailAddress $receiverEmail;
  2824. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  2825.                         $new_mail $this->get('mail_module');
  2826.                         $new_mail->sendMyMail(array(
  2827.                             'senderHash' => '_CUSTOM_',
  2828.                             //                        'senderHash'=>'_CUSTOM_',
  2829.                             'forwardToMailAddress' => $forwardToMailAddress,
  2830.                             'subject' => 'Digital Bee Card Delivery',
  2831. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  2832.                             'attachments' => $attachments,
  2833.                             'toAddress' => $forwardToMailAddress,
  2834.                             'fromAddress' => 'delivery@buddybee.eu',
  2835.                             'userName' => 'delivery@buddybee.eu',
  2836.                             'password' => 'Honeybee@0112',
  2837.                             'smtpServer' => 'smtp.hostinger.com',
  2838.                             'smtpPort' => 465,
  2839. //                        'encryptionMethod' => 'tls',
  2840.                             'encryptionMethod' => 'ssl',
  2841. //                            'emailBody' => $bodyHtml,
  2842.                             'mailTemplate' => $bodyTemplate,
  2843.                             'templateData' => $bodyData,
  2844. //                        'embedCompanyImage' => 1,
  2845. //                        'companyId' => $companyId,
  2846. //                        'companyImagePath' => $company_data->getImage()
  2847.                         ));
  2848.                         foreach ($cards as $card) {
  2849.                             $card->setPrinted(1);
  2850.                         }
  2851.                         $em->flush();
  2852.                     }
  2853.                     return new JsonResponse(
  2854.                         array(
  2855.                             'success' => true
  2856.                         )
  2857.                     );
  2858.                 }
  2859.                 MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  2860.                 $meetingId $retData['meetingId'];
  2861.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  2862.                     $billerDetails = [];
  2863.                     $billToDetails = [];
  2864.                     $invoice $em->getRepository('CompanyGroupBundle\\Entity\\EntityInvoice')
  2865.                         ->findOneBy(
  2866.                             array(
  2867.                                 'Id' => $invoiceId,
  2868.                             )
  2869.                         );;
  2870.                     if ($invoice) {
  2871.                         $billerDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  2872.                             ->findOneBy(
  2873.                                 array(
  2874.                                     'applicantId' => $invoice->getBillerId(),
  2875.                                 )
  2876.                             );
  2877.                         $billToDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  2878.                             ->findOneBy(
  2879.                                 array(
  2880.                                     'applicantId' => $invoice->getBillToId(),
  2881.                                 )
  2882.                             );
  2883.                     }
  2884.                     $bodyTemplate 'ApplicationBundle:email/templates:buddybeeInvoiceEmail.html.twig';
  2885.                     $bodyData = array(
  2886.                         'page_title' => 'Invoice',
  2887. //            'studentDetails' => $student,
  2888.                         'billerDetails' => $billerDetails,
  2889.                         'billToDetails' => $billToDetails,
  2890.                         'invoice' => $invoice,
  2891.                         'currencyList' => BuddybeeConstant::$currency_List,
  2892.                         'currencyListByMarker' => BuddybeeConstant::$currency_List_by_marker,
  2893.                     );
  2894.                     $attachments = [];
  2895.                     $forwardToMailAddress $billToDetails->getOAuthEmail();
  2896. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  2897.                     $new_mail $this->get('mail_module');
  2898.                     $new_mail->sendMyMail(array(
  2899.                         'senderHash' => '_CUSTOM_',
  2900.                         //                        'senderHash'=>'_CUSTOM_',
  2901.                         'forwardToMailAddress' => $forwardToMailAddress,
  2902.                         'subject' => 'YourInvoice #' 'D' str_pad('BB'5'0'STR_PAD_LEFT) . str_pad('76'2'0'STR_PAD_LEFT) . str_pad($invoice->getId(), 8"0"STR_PAD_LEFT) . ' from BuddyBee ',
  2903. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  2904.                         'attachments' => $attachments,
  2905.                         'toAddress' => $forwardToMailAddress,
  2906.                         'fromAddress' => 'no-reply@buddybee.eu',
  2907.                         'userName' => 'no-reply@buddybee.eu',
  2908.                         'password' => 'Honeybee@0112',
  2909.                         'smtpServer' => 'smtp.hostinger.com',
  2910.                         'smtpPort' => 465,
  2911. //                            'emailBody' => $bodyHtml,
  2912.                         'mailTemplate' => $bodyTemplate,
  2913.                         'templateData' => $bodyData,
  2914.                         'embedCompanyImage' => 0,
  2915.                         'companyId' => 0,
  2916.                         'companyImagePath' => ''
  2917. //                        'embedCompanyImage' => 1,
  2918. //                        'companyId' => $companyId,
  2919. //                        'companyImagePath' => $company_data->getImage()
  2920.                     ));
  2921.                 }
  2922. //
  2923.                 if ($meetingId != 0) {
  2924.                     $url $this->generateUrl(
  2925.                         'consultancy_session'
  2926.                     );
  2927. //                if($request->query->get('autoRedirect',1))
  2928. //                    return $this->redirect($url . '/' . $meetingId);
  2929.                     $redirectUrl $url '/' $meetingId;
  2930.                 } else {
  2931.                     $url $this->generateUrl(
  2932.                         'buddybee_dashboard'
  2933.                     );
  2934. //                if($request->query->get('autoRedirect',1))
  2935. //                    return $this->redirect($url);
  2936.                     $redirectUrl $url;
  2937.                 }
  2938.             }
  2939.             return $this->render('ApplicationBundle:pages/stripe:success.html.twig', array(
  2940.                 'page_title' => 'Success',
  2941.                 'meetingId' => $meetingId,
  2942.                 'autoRedirect' => $autoRedirect,
  2943.                 'redirectUrl' => $redirectUrl,
  2944.             ));
  2945.         }
  2946.     }
  2947.     public function PaymentGatewayCancelAction(Request $request$msg 'The Payment was unsuccessful'$encData '')
  2948.     {
  2949.         $em $this->getDoctrine()->getManager('company_group');
  2950. //        $consultantDetail = $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')->findOneBy(array());
  2951.         $session $request->getSession();
  2952.         if ($msg == '')
  2953.             $msg $request->query->get('msg'$request->request->get('msg''The Payment was unsuccessful'));
  2954.         return $this->render('ApplicationBundle:pages/stripe:cancel.html.twig', array(
  2955.             'page_title' => 'Success',
  2956.             'msg' => $msg,
  2957.         ));
  2958.     }
  2959.     public function BkashCallbackAction(Request $request$encData '')
  2960.     {
  2961.         $em $this->getDoctrine()->getManager('company_group');
  2962.         $invoiceId 0;
  2963.         $session $request->getSession();
  2964.         $sandBoxMode $this->container->hasParameter('sand_box_mode') ? $this->container->getParameter('sand_box_mode') : 0;
  2965.         $paymentId $request->query->get('paymentID'0);
  2966.         $status $request->query->get('status'0);
  2967.         if ($status == 'success') {
  2968.             $paymentID $paymentId;
  2969.             $gatewayInvoice $em->getRepository('CompanyGroupBundle\\Entity\\EntityInvoice')->findOneBy(
  2970.                 array(
  2971.                     'gatewayPaymentId' => $paymentId,
  2972.                     'isProcessed' => [02]
  2973.                 ));
  2974.             if ($gatewayInvoice) {
  2975.                 $invoiceId $gatewayInvoice->getId();
  2976.                 $justNow = new \DateTime();
  2977.                 $baseUrl = ($sandBoxMode == 1) ? 'https://tokenized.sandbox.bka.sh/v1.2.0-beta' 'https://tokenized.pay.bka.sh/v1.2.0-beta';
  2978.                 $username_value = ($sandBoxMode == 1) ? 'sandboxTokenizedUser02' '01891962953';
  2979.                 $password_value = ($sandBoxMode == 1) ? 'sandboxTokenizedUser02@12345' ',a&kPV4deq&';
  2980.                 $app_key_value = ($sandBoxMode == 1) ? '4f6o0cjiki2rfm34kfdadl1eqq' '2ueVHdwz5gH3nxx7xn8wotlztc';
  2981.                 $app_secret_value = ($sandBoxMode == 1) ? '2is7hdktrekvrbljjh44ll3d9l1dtjo4pasmjvs5vl5qr3fug4b' '49Ay3h3wWJMBFD7WF5CassyLrtA1jt6ONhspqjqFx5hTjhqh5dHU';
  2982.                 $justNowTs $justNow->format('U');
  2983.                 if ($gatewayInvoice->getGatewayIdTokenExpireTs() <= $justNowTs) {
  2984.                     $refresh_token $gatewayInvoice->getGatewayIdRefreshToken();
  2985.                     $request_data = array(
  2986.                         'app_key' => $app_key_value,
  2987.                         'app_secret' => $app_secret_value,
  2988.                         'refresh_token' => $refresh_token
  2989.                     );
  2990.                     $url curl_init($baseUrl '/tokenized/checkout/token/refresh');
  2991.                     $request_data_json json_encode($request_data);
  2992.                     $header = array(
  2993.                         'Content-Type:application/json',
  2994.                         'username:' $username_value,
  2995.                         'password:' $password_value
  2996.                     );
  2997.                     curl_setopt($urlCURLOPT_HTTPHEADER$header);
  2998.                     curl_setopt($urlCURLOPT_CUSTOMREQUEST"POST");
  2999.                     curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  3000.                     curl_setopt($urlCURLOPT_POSTFIELDS$request_data_json);
  3001.                     curl_setopt($urlCURLOPT_FOLLOWLOCATION1);
  3002.                     curl_setopt($urlCURLOPT_IPRESOLVECURL_IPRESOLVE_V4);
  3003.                     $tokenData json_decode(curl_exec($url), true);
  3004.                     curl_close($url);
  3005.                     $justNow = new \DateTime();
  3006.                     $justNow->modify('+' $tokenData['expires_in'] . ' second');
  3007.                     $gatewayInvoice->setGatewayIdTokenExpireTs($justNow->format('U'));
  3008.                     $gatewayInvoice->setGatewayIdToken($tokenData['id_token']);
  3009.                     $gatewayInvoice->setGatewayIdRefreshToken($tokenData['refresh_token']);
  3010.                     $em->flush();
  3011.                 }
  3012.                 $auth $gatewayInvoice->getGatewayIdToken();;
  3013.                 $post_token = array(
  3014.                     'paymentID' => $paymentID
  3015.                 );
  3016. //                $url = curl_init();
  3017.                 $url curl_init($baseUrl '/tokenized/checkout/execute');
  3018.                 $posttoken json_encode($post_token);
  3019.                 $header = array(
  3020.                     'Content-Type:application/json',
  3021.                     'Authorization:' $auth,
  3022.                     'X-APP-Key:' $app_key_value
  3023.                 );
  3024. //                curl_setopt_array($url, array(
  3025. //                    CURLOPT_HTTPHEADER => $header,
  3026. //                    CURLOPT_RETURNTRANSFER => 1,
  3027. //                    CURLOPT_URL => $baseUrl . '/tokenized/checkout/execute',
  3028. //
  3029. //                    CURLOPT_FOLLOWLOCATION => 1,
  3030. //                    CURLOPT_POST => 1,
  3031. //                    CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
  3032. //                    CURLOPT_POSTFIELDS => http_build_query($post_token)
  3033. //                ));
  3034.                 curl_setopt($urlCURLOPT_HTTPHEADER$header);
  3035.                 curl_setopt($urlCURLOPT_CUSTOMREQUEST"POST");
  3036.                 curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  3037.                 curl_setopt($urlCURLOPT_POSTFIELDS$posttoken);
  3038.                 curl_setopt($urlCURLOPT_FOLLOWLOCATION1);
  3039.                 curl_setopt($urlCURLOPT_IPRESOLVECURL_IPRESOLVE_V4);
  3040.                 $resultdata curl_exec($url);
  3041.                 curl_close($url);
  3042.                 $obj json_decode($resultdatatrue);
  3043. //                return new JsonResponse(array(
  3044. //                    'obj' => $obj,
  3045. //                    'url' => $baseUrl . '/tokenized/checkout/execute',
  3046. //                    'header' => $header,
  3047. //                    'paymentID' => $paymentID,
  3048. //                    'posttoken' => $posttoken,
  3049. //                ));
  3050. //                                return new JsonResponse($obj);
  3051.                 if (isset($obj['statusCode'])) {
  3052.                     if ($obj['statusCode'] == '0000') {
  3053.                         $gatewayInvoice->setGatewayTransId($obj['trxID']);
  3054.                         $em->flush();
  3055.                         return $this->redirectToRoute("payment_gateway_success", ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  3056.                             'invoiceId' => $invoiceId'autoRedirect' => 1
  3057.                         ))),
  3058.                             'hbeeSessionToken' => $session->get('token'0)]);
  3059.                     } else {
  3060.                         return $this->redirectToRoute("payment_gateway_cancel", [
  3061.                             'msg' => isset($obj['statusMessage']) ? $obj['statusMessage'] : (isset($obj['errorMessage']) ? $obj['errorMessage'] : 'Payment Failed')
  3062.                         ]);
  3063.                     }
  3064.                 }
  3065.             } else {
  3066.                 return $this->redirectToRoute("payment_gateway_cancel", [
  3067.                     'msg' => isset($obj['statusMessage']) ? $obj['statusMessage'] : (isset($obj['errorMessage']) ? $obj['errorMessage'] : 'Payment Failed')
  3068.                 ]);
  3069.             }
  3070.         } else {
  3071.             return $this->redirectToRoute("payment_gateway_cancel", [
  3072.                 'msg' => isset($obj['statusMessage']) ? $obj['statusMessage'] : (isset($obj['errorMessage']) ? $obj['errorMessage'] : 'The Payment was unsuccessful')
  3073.             ]);
  3074.         }
  3075.     }
  3076.     public function MakePaymentOfEntityInvoiceAction(Request $request$encData '')
  3077.     {
  3078.         $em $this->getDoctrine()->getManager('company_group');
  3079.         $em_goc $em;
  3080.         $invoiceId 0;
  3081.         $autoRedirect 1;
  3082.         $redirectUrl '';
  3083.         $meetingId 0;
  3084.         $triggerMiddlePage 0;
  3085.         $session $request->getSession();
  3086.         $sandBoxMode $this->container->hasParameter('sand_box_mode') ? $this->container->getParameter('sand_box_mode') : 0;
  3087.         $refundSuccess 0;
  3088.         $errorMsg '';
  3089.         $errorCode '';
  3090.         if ($encData != '') {
  3091.             $invoiceId $encData;
  3092.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  3093.             if (isset($encryptedData['invoiceId']))
  3094.                 $invoiceId $encryptedData['invoiceId'];
  3095.             if (isset($encryptedData['triggerMiddlePage']))
  3096.                 $triggerMiddlePage $encryptedData['triggerMiddlePage'];
  3097.             if (isset($encryptedData['autoRedirect']))
  3098.                 $autoRedirect $encryptedData['autoRedirect'];
  3099.         } else {
  3100.             $invoiceId $request->request->get('invoiceId'$request->query->get('invoiceId'0));
  3101.             $triggerMiddlePage $request->request->get('triggerMiddlePage'$request->query->get('triggerMiddlePage'0));
  3102.             $meetingId 0;
  3103.             $autoRedirect $request->query->get('autoRedirect'1);
  3104.             $redirectUrl '';
  3105.         }
  3106.         $meetingId $request->request->get('meetingId'$request->query->get('meetingId'0));
  3107.         $actionDone 0;
  3108.         if ($meetingId != 0) {
  3109.             $dt Buddybee::ConfirmAnyMeetingSessionIfPossible($em0$meetingIdfalse,
  3110.                 $this->container->getParameter('notification_enabled'),
  3111.                 $this->container->getParameter('notification_server'));
  3112.             if ($invoiceId == && $dt['success'] == true) {
  3113.                 $actionDone 1;
  3114.                 return new JsonResponse(array(
  3115.                     'clientSecret' => 0,
  3116.                     'actionDone' => $actionDone,
  3117.                     'id' => 0,
  3118.                     'proceedToCheckout' => 0
  3119.                 ));
  3120.             }
  3121.         }
  3122. //        $invoiceId = $request->request->get('meetingId', $request->query->get('meetingId', 0));
  3123.         $output = [
  3124.             'clientSecret' => 0,
  3125.             'id' => 0,
  3126.             'proceedToCheckout' => 0
  3127.         ];
  3128.         if ($invoiceId != 0) {
  3129.             $gatewayInvoice $em->getRepository('CompanyGroupBundle\\Entity\\EntityInvoice')->findOneBy(
  3130.                 array(
  3131.                     'Id' => $invoiceId,
  3132.                     'isProcessed' => [0]
  3133.                 ));
  3134.         } else {
  3135.             $gatewayInvoice $em->getRepository('CompanyGroupBundle\\Entity\\EntityInvoice')->findOneBy(
  3136.                 array(
  3137.                     'meetingId' => $meetingId,
  3138.                     'isProcessed' => [0]
  3139.                 ));
  3140.         }
  3141.         if ($gatewayInvoice)
  3142.             $invoiceId $gatewayInvoice->getId();
  3143.         $invoiceSessionCount 0;
  3144.         $payableAmount 0;
  3145.         $imageBySessionCount = [
  3146.             => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3147.             100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3148.             200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3149.             300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3150.             400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3151.             500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3152.             600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3153.             700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3154.             800 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3155.             900 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3156.             1000 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3157.             1100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3158.             1200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3159.             1300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3160.             1400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3161.             1500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3162.             1600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3163.             1700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3164.             1800 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3165.             1900 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3166.             2000 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3167.             2100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3168.             2200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3169.             2300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3170.             2400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3171.             2500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3172.             2600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3173.             2700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3174.             2800 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3175.             2900 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3176.             3000 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3177.             3100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3178.             3200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3179.             3300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3180.             3400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3181.             3500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3182.             3600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3183.             3700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  3184.         ];
  3185.         if ($gatewayInvoice) {
  3186.             $gatewayProductData json_decode($gatewayInvoice->getProductDataForPaymentGateway(), true);
  3187.             if ($gatewayProductData == null$gatewayProductData = [];
  3188.             $gatewayAmount number_format($gatewayInvoice->getGateWayBillamount(), 2'.''');
  3189.             $invoiceSessionCount $gatewayInvoice->getSessionCount();
  3190.             $currencyForGateway $gatewayInvoice->getAmountCurrency();
  3191.             $gatewayAmount round($gatewayAmount2);
  3192.             if (empty($gatewayProductData))
  3193.                 $gatewayProductData = [
  3194.                     [
  3195.                         'price_data' => [
  3196.                             'currency' => 'eur',
  3197.                             'unit_amount' => $gatewayAmount != ? (100 $gatewayAmount) : 200000,
  3198.                             'product_data' => [
  3199. //                            'name' => $request->request->has('packageName') ? $request->request->get('packageName') : 'Advanced Consultancy Package',
  3200.                                 'name' => 'Bee Coins',
  3201. //                                'images' => [$imageBySessionCount[$invoiceSessionCount]],
  3202.                                 'images' => [$imageBySessionCount[0]],
  3203.                             ],
  3204.                         ],
  3205.                         'quantity' => 1,
  3206.                     ]
  3207.                 ];
  3208.             $productDescStr '';
  3209.             $productDescArr = [];
  3210.             foreach ($gatewayProductData as $gpd) {
  3211.                 $productDescArr[] = $gpd['price_data']['product_data']['name'];
  3212.             }
  3213.             $productDescStr implode(','$productDescArr);
  3214.             $paymentGatewayFromInvoice $gatewayInvoice->getAmountTransferGateWayHash();
  3215.             if ($paymentGatewayFromInvoice == 'stripe') {
  3216.                 $stripe = new \Stripe\Stripe();
  3217.                 \Stripe\Stripe::setApiKey('sk_test_51IxYTAJXs21fVb0QMop2Nb0E7u9Da4LwGrym1nGHUHqaSNtT3p9HBgHd7YyDsTKHscgPPECPQniTy79Ab8Sgxfbm00JF2AndUz');
  3218.                 $stripe::setApiKey('sk_test_51IxYTAJXs21fVb0QMop2Nb0E7u9Da4LwGrym1nGHUHqaSNtT3p9HBgHd7YyDsTKHscgPPECPQniTy79Ab8Sgxfbm00JF2AndUz');
  3219.                 {
  3220.                     if ($request->query->has('meetingSessionId'))
  3221.                         $id $request->query->get('meetingSessionId');
  3222.                 }
  3223.                 $paymentIntent = [
  3224.                     "id" => "pi_1DoWjK2eZvKYlo2Csy9J3BHs",
  3225.                     "object" => "payment_intent",
  3226.                     "amount" => 3000,
  3227.                     "amount_capturable" => 0,
  3228.                     "amount_received" => 0,
  3229.                     "application" => null,
  3230.                     "application_fee_amount" => null,
  3231.                     "canceled_at" => null,
  3232.                     "cancellation_reason" => null,
  3233.                     "capture_method" => "automatic",
  3234.                     "charges" => [
  3235.                         "object" => "list",
  3236.                         "data" => [],
  3237.                         "has_more" => false,
  3238.                         "url" => "/v1/charges?payment_intent=pi_1DoWjK2eZvKYlo2Csy9J3BHs"
  3239.                     ],
  3240.                     "client_secret" => "pi_1DoWjK2eZvKYlo2Csy9J3BHs_secret_vmxAcWZxo2kt1XhpWtZtnjDtd",
  3241.                     "confirmation_method" => "automatic",
  3242.                     "created" => 1546523966,
  3243.                     "currency" => $currencyForGateway,
  3244.                     "customer" => null,
  3245.                     "description" => null,
  3246.                     "invoice" => null,
  3247.                     "last_payment_error" => null,
  3248.                     "livemode" => false,
  3249.                     "metadata" => [],
  3250.                     "next_action" => null,
  3251.                     "on_behalf_of" => null,
  3252.                     "payment_method" => null,
  3253.                     "payment_method_options" => [],
  3254.                     "payment_method_types" => [
  3255.                         "card"
  3256.                     ],
  3257.                     "receipt_email" => null,
  3258.                     "review" => null,
  3259.                     "setup_future_usage" => null,
  3260.                     "shipping" => null,
  3261.                     "statement_descriptor" => null,
  3262.                     "statement_descriptor_suffix" => null,
  3263.                     "status" => "requires_payment_method",
  3264.                     "transfer_data" => null,
  3265.                     "transfer_group" => null
  3266.                 ];
  3267.                 $checkout_session = \Stripe\Checkout\Session::create([
  3268.                     'payment_method_types' => ['card'],
  3269.                     'line_items' => $gatewayProductData,
  3270.                     'mode' => 'payment',
  3271.                     'success_url' => $this->generateUrl(
  3272.                         'payment_gateway_success',
  3273.                         ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  3274.                             'invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1)
  3275.                         ))), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  3276.                     ),
  3277.                     'cancel_url' => $this->generateUrl(
  3278.                         'payment_gateway_cancel', ['invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  3279.                     ),
  3280.                 ]);
  3281.                 $output = [
  3282.                     'clientSecret' => $paymentIntent['client_secret'],
  3283.                     'id' => $checkout_session->id,
  3284.                     'paymentGateway' => $paymentGatewayFromInvoice,
  3285.                     'proceedToCheckout' => 1
  3286.                 ];
  3287. //                return new JsonResponse($output);
  3288.             }
  3289.             if ($paymentGatewayFromInvoice == 'aamarpay') {
  3290.                 $studentDetails $em_goc->getRepository(EntityApplicantDetails::class)->find($gatewayInvoice->getBillToId());
  3291.                 $url $sandBoxMode == 'https://sandbox.aamarpay.com/request.php' 'https://secure.aamarpay.com/request.php';
  3292.                 $fields = array(
  3293. //                    'store_id' => 'aamarpaytest', //store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  3294.                     'store_id' => $sandBoxMode == 'aamarpaytest' 'buddybee'//store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  3295.                     'amount' => number_format($gatewayInvoice->getGateWayBillamount(), 2'.'''), //transaction amount
  3296.                     'payment_type' => 'VISA'//no need to change
  3297.                     'currency' => strtoupper($currencyForGateway),  //currenct will be USD/BDT
  3298.                     'tran_id' => 'BEI' str_pad($gatewayInvoice->getBillerId(), 3'0'STR_PAD_LEFT) . str_pad($gatewayInvoice->getBillToId(), 5'0'STR_PAD_LEFT) . str_pad($gatewayInvoice->getId(), 4'0'STR_PAD_LEFT), //transaction id must be unique from your end
  3299.                     'cus_name' => $studentDetails->getFirstname() . ' ' $studentDetails->getLastName(),  //customer name
  3300.                     'cus_email' => $studentDetails->getEmail(), //customer email address
  3301.                     'cus_add1' => $studentDetails->getCurrAddr(),  //customer address
  3302.                     'cus_add2' => $studentDetails->getCurrAddrCity(), //customer address
  3303.                     'cus_city' => $studentDetails->getCurrAddrCity(),  //customer city
  3304.                     'cus_state' => $studentDetails->getCurrAddrState(),  //state
  3305.                     'cus_postcode' => $studentDetails->getCurrAddrZip(), //postcode or zipcode
  3306.                     'cus_country' => 'Bangladesh',  //country
  3307.                     'cus_phone' => ($studentDetails->getPhone() == null || $studentDetails->getPhone() == '') ? '+8801911706483' $studentDetails->getPhone(), //customer phone number
  3308.                     'cus_fax' => '',  //fax
  3309.                     'ship_name' => ''//ship name
  3310.                     'ship_add1' => '',  //ship address
  3311.                     'ship_add2' => '',
  3312.                     'ship_city' => '',
  3313.                     'ship_state' => '',
  3314.                     'ship_postcode' => '',
  3315.                     'ship_country' => 'Bangladesh',
  3316.                     'desc' => $productDescStr,
  3317.                     'success_url' => $this->generateUrl(
  3318.                         'payment_gateway_success',
  3319.                         ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  3320.                             'invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1)
  3321.                         ))), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  3322.                     ),
  3323.                     'fail_url' => $this->generateUrl(
  3324.                         'payment_gateway_cancel', ['invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  3325.                     ),
  3326.                     'cancel_url' => $this->generateUrl(
  3327.                         'payment_gateway_cancel', ['invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  3328.                     ),
  3329. //                    'opt_a' => 'Reshad',  //optional paramter
  3330. //                    'opt_b' => 'Akil',
  3331. //                    'opt_c' => 'Liza',
  3332. //                    'opt_d' => 'Sohel',
  3333. //                    'signature_key' => 'dbb74894e82415a2f7ff0ec3a97e4183',  //sandbox
  3334.                     'signature_key' => $sandBoxMode == 'dbb74894e82415a2f7ff0ec3a97e4183' 'b7304a40e21fe15af3be9a948307f524'  //live
  3335.                 ); //signature key will provided aamarpay, contact integration@aamarpay.com for test/live signature key
  3336.                 $fields_string http_build_query($fields);
  3337.                 $ch curl_init();
  3338.                 curl_setopt($chCURLOPT_VERBOSEtrue);
  3339.                 curl_setopt($chCURLOPT_URL$url);
  3340.                 curl_setopt($chCURLOPT_POSTFIELDS$fields_string);
  3341.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  3342.                 curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  3343.                 $url_forward str_replace('"'''stripslashes(curl_exec($ch)));
  3344.                 curl_close($ch);
  3345. //                $this->redirect_to_merchant($url_forward);
  3346.                 $output = [
  3347. //                    'redirectUrl' => 'https://sandbox.aamarpay.com/'.$url_forward, //keeping it off temporarily
  3348.                     'redirectUrl' => ($sandBoxMode == 'https://sandbox.aamarpay.com/' 'https://secure.aamarpay.com/') . $url_forward//keeping it off temporarily
  3349. //                    'fields'=>$fields,
  3350. //                    'fields_string'=>$fields_string,
  3351. //                    'redirectUrl' => $this->generateUrl(
  3352. //                        'payment_gateway_success',
  3353. //                        ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  3354. //                            'invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1)
  3355. //                        ))), 'hbeeSessionToken' => $request->request->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  3356. //                    ),
  3357.                     'paymentGateway' => $paymentGatewayFromInvoice,
  3358.                     'proceedToCheckout' => 1
  3359.                 ];
  3360. //                return new JsonResponse($output);
  3361.             } else if ($paymentGatewayFromInvoice == 'bkash') {
  3362.                 $studentDetails $em_goc->getRepository(EntityApplicantDetails::class)->find($gatewayInvoice->getBillToId());
  3363.                 $baseUrl = ($sandBoxMode == 1) ? 'https://tokenized.sandbox.bka.sh/v1.2.0-beta' 'https://tokenized.pay.bka.sh/v1.2.0-beta';
  3364.                 $username_value = ($sandBoxMode == 1) ? 'sandboxTokenizedUser02' '01891962953';
  3365.                 $password_value = ($sandBoxMode == 1) ? 'sandboxTokenizedUser02@12345' ',a&kPV4deq&';
  3366.                 $app_key_value = ($sandBoxMode == 1) ? '4f6o0cjiki2rfm34kfdadl1eqq' '2ueVHdwz5gH3nxx7xn8wotlztc';
  3367.                 $app_secret_value = ($sandBoxMode == 1) ? '2is7hdktrekvrbljjh44ll3d9l1dtjo4pasmjvs5vl5qr3fug4b' '49Ay3h3wWJMBFD7WF5CassyLrtA1jt6ONhspqjqFx5hTjhqh5dHU';
  3368.                 $request_data = array(
  3369.                     'app_key' => $app_key_value,
  3370.                     'app_secret' => $app_secret_value
  3371.                 );
  3372.                 $url curl_init($baseUrl '/tokenized/checkout/token/grant');
  3373.                 $request_data_json json_encode($request_data);
  3374.                 $header = array(
  3375.                     'Content-Type:application/json',
  3376.                     'username:' $username_value,
  3377.                     'password:' $password_value
  3378.                 );
  3379.                 curl_setopt($urlCURLOPT_HTTPHEADER$header);
  3380.                 curl_setopt($urlCURLOPT_CUSTOMREQUEST"POST");
  3381.                 curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  3382.                 curl_setopt($urlCURLOPT_POSTFIELDS$request_data_json);
  3383.                 curl_setopt($urlCURLOPT_FOLLOWLOCATION1);
  3384.                 curl_setopt($urlCURLOPT_IPRESOLVECURL_IPRESOLVE_V4);
  3385.                 $tokenData json_decode(curl_exec($url), true);
  3386.                 curl_close($url);
  3387.                 $id_token $tokenData['id_token'];
  3388.                 $goToBkashPage 0;
  3389.                 if ($tokenData['statusCode'] == '0000') {
  3390.                     $auth $id_token;
  3391.                     $requestbody = array(
  3392.                         "mode" => "0011",
  3393. //                        "payerReference" => "",
  3394.                         "payerReference" => $gatewayInvoice->getInvoiceDateTs(),
  3395.                         "callbackURL" => $this->generateUrl(
  3396.                             'bkash_callback', [], UrlGenerator::ABSOLUTE_URL
  3397.                         ),
  3398. //                    "merchantAssociationInfo" => "MI05MID54RF09123456One",
  3399.                         "amount" => number_format($gatewayInvoice->getGateWayBillamount(), 2'.'''),
  3400.                         "currency" => "BDT",
  3401.                         "intent" => "sale",
  3402.                         "merchantInvoiceNumber" => $invoiceId
  3403.                     );
  3404.                     $url curl_init($baseUrl '/tokenized/checkout/create');
  3405.                     $requestbodyJson json_encode($requestbody);
  3406.                     $header = array(
  3407.                         'Content-Type:application/json',
  3408.                         'Authorization:' $auth,
  3409.                         'X-APP-Key:' $app_key_value
  3410.                     );
  3411.                     curl_setopt($urlCURLOPT_HTTPHEADER$header);
  3412.                     curl_setopt($urlCURLOPT_CUSTOMREQUEST"POST");
  3413.                     curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  3414.                     curl_setopt($urlCURLOPT_POSTFIELDS$requestbodyJson);
  3415.                     curl_setopt($urlCURLOPT_FOLLOWLOCATION1);
  3416.                     curl_setopt($urlCURLOPT_IPRESOLVECURL_IPRESOLVE_V4);
  3417.                     $resultdata curl_exec($url);
  3418.                     curl_close($url);
  3419. //                    return new JsonResponse($resultdata);
  3420.                     $obj json_decode($resultdatatrue);
  3421.                     $goToBkashPage 1;
  3422.                     $justNow = new \DateTime();
  3423.                     $justNow->modify('+' $tokenData['expires_in'] . ' second');
  3424.                     $gatewayInvoice->setGatewayIdTokenExpireTs($justNow->format('U'));
  3425.                     $gatewayInvoice->setGatewayIdToken($tokenData['id_token']);
  3426.                     $gatewayInvoice->setGatewayPaymentId($obj['paymentID']);
  3427.                     $gatewayInvoice->setGatewayIdRefreshToken($tokenData['refresh_token']);
  3428.                     $em->flush();
  3429.                     $output = [
  3430.                         'redirectUrl' => $obj['bkashURL'],
  3431.                         'paymentGateway' => $paymentGatewayFromInvoice,
  3432.                         'proceedToCheckout' => $goToBkashPage,
  3433.                         'tokenData' => $tokenData,
  3434.                         'obj' => $obj,
  3435.                         'id_token' => $tokenData['id_token'],
  3436.                     ];
  3437.                 }
  3438. //                $fields = array(
  3439. //
  3440. //                    "mode" => "0011",
  3441. //                    "payerReference" => "01723888888",
  3442. //                    "callbackURL" => $this->generateUrl(
  3443. //                        'payment_gateway_success',
  3444. //                        ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  3445. //                            'invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1)
  3446. //                        ))), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  3447. //                    ),
  3448. //                    "merchantAssociationInfo" => "MI05MID54RF09123456One",
  3449. //                    "amount" => $gatewayInvoice->getGateWayBillamount(),
  3450. //                    "currency" => "BDT",
  3451. //                    "intent" => "sale",
  3452. //                    "merchantInvoiceNumber" => 'BEI' . str_pad($gatewayInvoice->getBillerId(), 3, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getBillToId(), 5, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getId(), 4, '0', STR_PAD_LEFT)
  3453. //
  3454. //                );
  3455. //                $fields = array(
  3456. ////                    'store_id' => 'aamarpaytest', //store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  3457. //                    'store_id' => $sandBoxMode == 1 ? 'aamarpaytest' : 'buddybee', //store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  3458. //                    'amount' => $gatewayInvoice->getGateWayBillamount(), //transaction amount
  3459. //                    'payment_type' => 'VISA', //no need to change
  3460. //                    'currency' => strtoupper($currencyForGateway),  //currenct will be USD/BDT
  3461. //                    'tran_id' => 'BEI' . str_pad($gatewayInvoice->getBillerId(), 3, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getBillToId(), 5, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getId(), 4, '0', STR_PAD_LEFT), //transaction id must be unique from your end
  3462. //                    'cus_name' => $studentDetails->getFirstname() . ' ' . $studentDetails->getLastName(),  //customer name
  3463. //                    'cus_email' => $studentDetails->getEmail(), //customer email address
  3464. //                    'cus_add1' => $studentDetails->getCurrAddr(),  //customer address
  3465. //                    'cus_add2' => $studentDetails->getCurrAddrCity(), //customer address
  3466. //                    'cus_city' => $studentDetails->getCurrAddrCity(),  //customer city
  3467. //                    'cus_state' => $studentDetails->getCurrAddrState(),  //state
  3468. //                    'cus_postcode' => $studentDetails->getCurrAddrZip(), //postcode or zipcode
  3469. //                    'cus_country' => 'Bangladesh',  //country
  3470. //                    'cus_phone' => ($studentDetails->getPhone() == null || $studentDetails->getPhone() == '') ? ' + 8801911706483' : $studentDetails->getPhone(), //customer phone number
  3471. //                    'cus_fax' => '',  //fax
  3472. //                    'ship_name' => '', //ship name
  3473. //                    'ship_add1' => '',  //ship address
  3474. //                    'ship_add2' => '',
  3475. //                    'ship_city' => '',
  3476. //                    'ship_state' => '',
  3477. //                    'ship_postcode' => '',
  3478. //                    'ship_country' => 'Bangladesh',
  3479. //                    'desc' => $productDescStr,
  3480. //                    'success_url' => $this->generateUrl(
  3481. //                        'payment_gateway_success',
  3482. //                        ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  3483. //                            'invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1)
  3484. //                        ))), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  3485. //                    ),
  3486. //                    'fail_url' => $this->generateUrl(
  3487. //                        'payment_gateway_cancel', ['invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  3488. //                    ),
  3489. //                    'cancel_url' => $this->generateUrl(
  3490. //                        'payment_gateway_cancel', ['invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  3491. //                    ),
  3492. ////                    'opt_a' => 'Reshad',  //optional paramter
  3493. ////                    'opt_b' => 'Akil',
  3494. ////                    'opt_c' => 'Liza',
  3495. ////                    'opt_d' => 'Sohel',
  3496. ////                    'signature_key' => 'dbb74894e82415a2f7ff0ec3a97e4183',  //sandbox
  3497. //                    'signature_key' => $sandBoxMode == 1 ? 'dbb74894e82415a2f7ff0ec3a97e4183' : 'b7304a40e21fe15af3be9a948307f524'  //live
  3498. //
  3499. //                ); //signature key will provided aamarpay, contact integration@aamarpay.com for test/live signature key
  3500. //
  3501. //                $fields_string = http_build_query($fields);
  3502. //
  3503. //                $ch = curl_init();
  3504. //                curl_setopt($ch, CURLOPT_VERBOSE, true);
  3505. //                curl_setopt($ch, CURLOPT_URL, $url);
  3506. //
  3507. //                curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  3508. //                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  3509. //                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  3510. //                $url_forward = str_replace('"', '', stripslashes(curl_exec($ch)));
  3511. //                curl_close($ch);
  3512. //                $this->redirect_to_merchant($url_forward);
  3513.             }
  3514.         }
  3515.         if ($triggerMiddlePage == 1) return $this->render('@Buddybee/pages/makePaymentOfEntityInvoiceLandingPage.html.twig', array(
  3516.             'page_title' => 'Invoice Payment',
  3517.             'data' => $output,
  3518.         ));
  3519.         else
  3520.             return new JsonResponse($output);
  3521.     }
  3522.     public function RefundEntityInvoiceAction(Request $request$encData '')
  3523.     {
  3524.         $em $this->getDoctrine()->getManager('company_group');
  3525.         $invoiceId 0;
  3526.         $currIsProcessedFlagValue '_UNSET_';
  3527.         $session $request->getSession();
  3528.         $sandBoxMode $this->container->hasParameter('sand_box_mode') ? $this->container->getParameter('sand_box_mode') : 0;
  3529.         $paymentId $request->query->get('paymentID'0);
  3530.         $status $request->query->get('status'0);
  3531.         $refundSuccess 0;
  3532.         $errorMsg '';
  3533.         $errorCode '';
  3534.         if ($encData != '') {
  3535.             $invoiceId $encData;
  3536.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  3537.             if (isset($encryptedData['invoiceId']))
  3538.                 $invoiceId $encryptedData['invoiceId'];
  3539.             if (isset($encryptedData['autoRedirect']))
  3540.                 $autoRedirect $encryptedData['autoRedirect'];
  3541.         } else {
  3542.             $invoiceId $request->request->get('invoiceId'$request->query->get('invoiceId'0));
  3543.             $meetingId 0;
  3544.             $autoRedirect $request->query->get('autoRedirect'1);
  3545.             $redirectUrl '';
  3546.         }
  3547.         $gatewayInvoice $em->getRepository('CompanyGroupBundle\\Entity\\EntityInvoice')->findOneBy(
  3548.             array(
  3549.                 'Id' => $invoiceId,
  3550.                 'isProcessed' => [1]
  3551.             ));
  3552.         if ($gatewayInvoice) {
  3553.             $gatewayInvoice->setIsProcessed(3); //pending settlement
  3554.             $currIsProcessedFlagValue $gatewayInvoice->getIsProcessed();
  3555.             $em->flush();
  3556.             if ($gatewayInvoice->getAmountTransferGateWayHash() == 'bkash') {
  3557.                 $invoiceId $gatewayInvoice->getId();
  3558.                 $paymentID $gatewayInvoice->getGatewayPaymentId();
  3559.                 $trxID $gatewayInvoice->getGatewayTransId();
  3560.                 $justNow = new \DateTime();
  3561.                 $baseUrl = ($sandBoxMode == 1) ? 'https://tokenized.sandbox.bka.sh/v1.2.0-beta' 'https://tokenized.pay.bka.sh/v1.2.0-beta';
  3562.                 $username_value = ($sandBoxMode == 1) ? 'sandboxTokenizedUser02' '01891962953';
  3563.                 $password_value = ($sandBoxMode == 1) ? 'sandboxTokenizedUser02@12345' ',a&kPV4deq&';
  3564.                 $app_key_value = ($sandBoxMode == 1) ? '4f6o0cjiki2rfm34kfdadl1eqq' '2ueVHdwz5gH3nxx7xn8wotlztc';
  3565.                 $app_secret_value = ($sandBoxMode == 1) ? '2is7hdktrekvrbljjh44ll3d9l1dtjo4pasmjvs5vl5qr3fug4b' '49Ay3h3wWJMBFD7WF5CassyLrtA1jt6ONhspqjqFx5hTjhqh5dHU';
  3566.                 $justNowTs $justNow->format('U');
  3567.                 if ($gatewayInvoice->getGatewayIdTokenExpireTs() <= $justNowTs) {
  3568.                     $refresh_token $gatewayInvoice->getGatewayIdRefreshToken();
  3569.                     $request_data = array(
  3570.                         'app_key' => $app_key_value,
  3571.                         'app_secret' => $app_secret_value,
  3572.                         'refresh_token' => $refresh_token
  3573.                     );
  3574.                     $url curl_init($baseUrl '/tokenized/checkout/token/refresh');
  3575.                     $request_data_json json_encode($request_data);
  3576.                     $header = array(
  3577.                         'Content-Type:application/json',
  3578.                         'username:' $username_value,
  3579.                         'password:' $password_value
  3580.                     );
  3581.                     curl_setopt($urlCURLOPT_HTTPHEADER$header);
  3582.                     curl_setopt($urlCURLOPT_CUSTOMREQUEST"POST");
  3583.                     curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  3584.                     curl_setopt($urlCURLOPT_POSTFIELDS$request_data_json);
  3585.                     curl_setopt($urlCURLOPT_FOLLOWLOCATION1);
  3586.                     curl_setopt($urlCURLOPT_IPRESOLVECURL_IPRESOLVE_V4);
  3587.                     $tokenData json_decode(curl_exec($url), true);
  3588.                     curl_close($url);
  3589.                     $justNow = new \DateTime();
  3590.                     $justNow->modify('+' $tokenData['expires_in'] . ' second');
  3591.                     $gatewayInvoice->setGatewayIdTokenExpireTs($justNow->format('U'));
  3592.                     $gatewayInvoice->setGatewayIdToken($tokenData['id_token']);
  3593.                     $gatewayInvoice->setGatewayIdRefreshToken($tokenData['refresh_token']);
  3594.                     $em->flush();
  3595.                 }
  3596.                 $auth $gatewayInvoice->getGatewayIdToken();;
  3597.                 $post_token = array(
  3598.                     'paymentID' => $paymentID,
  3599.                     'trxID' => $trxID,
  3600.                     'reason' => 'Full Refund Policy',
  3601.                     'sku' => 'RSTR',
  3602.                     'amount' => number_format($gatewayInvoice->getGateWayBillamount(), 2'.'''),
  3603.                 );
  3604.                 $url curl_init($baseUrl '/tokenized/checkout/payment/refund');
  3605.                 $posttoken json_encode($post_token);
  3606.                 $header = array(
  3607.                     'Content-Type:application/json',
  3608.                     'Authorization:' $auth,
  3609.                     'X-APP-Key:' $app_key_value
  3610.                 );
  3611.                 curl_setopt($urlCURLOPT_HTTPHEADER$header);
  3612.                 curl_setopt($urlCURLOPT_CUSTOMREQUEST"POST");
  3613.                 curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  3614.                 curl_setopt($urlCURLOPT_POSTFIELDS$posttoken);
  3615.                 curl_setopt($urlCURLOPT_FOLLOWLOCATION1);
  3616.                 curl_setopt($urlCURLOPT_IPRESOLVECURL_IPRESOLVE_V4);
  3617.                 $resultdata curl_exec($url);
  3618.                 curl_close($url);
  3619.                 $obj json_decode($resultdatatrue);
  3620. //                return new JsonResponse($obj);
  3621.                 if (isset($obj['completedTime']))
  3622.                     $refundSuccess 1;
  3623.                 else if (isset($obj['errorCode'])) {
  3624.                     $refundSuccess 0;
  3625.                     $errorCode $obj['errorCode'];
  3626.                     $errorMsg $obj['errorMessage'];
  3627.                 }
  3628. //                    $gatewayInvoice->setGatewayTransId($obj['trxID']);
  3629.                 $em->flush();
  3630.             }
  3631.             if ($refundSuccess == 1) {
  3632.                 Buddybee::RefundEntityInvoice($em$invoiceId);
  3633.                 $currIsProcessedFlagValue 4;
  3634.             }
  3635.         } else {
  3636.         }
  3637.         MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  3638.         return new JsonResponse(
  3639.             array(
  3640.                 'success' => $refundSuccess,
  3641.                 'errorCode' => $errorCode,
  3642.                 'isProcessed' => $currIsProcessedFlagValue,
  3643.                 'errorMsg' => $errorMsg,
  3644.             )
  3645.         );
  3646.     }
  3647.     public function ViewEntityInvoiceAction(Request $request$encData '')
  3648.     {
  3649.         $em $this->getDoctrine()->getManager('company_group');
  3650.         $invoiceId 0;
  3651.         $autoRedirect 1;
  3652.         $redirectUrl '';
  3653.         $meetingId 0;
  3654.         $invoice null;
  3655.         if ($encData != '') {
  3656.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  3657.             $invoiceId $encData;
  3658.             if (isset($encryptedData['invoiceId']))
  3659.                 $invoiceId $encryptedData['invoiceId'];
  3660.             if (isset($encryptedData['autoRedirect']))
  3661.                 $autoRedirect $encryptedData['autoRedirect'];
  3662.         } else {
  3663.             $invoiceId $request->query->get('invoiceId'0);
  3664.             $meetingId 0;
  3665.             $autoRedirect $request->query->get('autoRedirect'1);
  3666.             $redirectUrl '';
  3667.         }
  3668. //    $invoiceList = [];
  3669.         $billerDetails = [];
  3670.         $billToDetails = [];
  3671.         if ($invoiceId != 0) {
  3672.             $invoice $em->getRepository('CompanyGroupBundle\\Entity\\EntityInvoice')
  3673.                 ->findOneBy(
  3674.                     array(
  3675.                         'Id' => $invoiceId,
  3676.                     )
  3677.                 );
  3678.             if ($invoice) {
  3679.                 $billerDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  3680.                     ->findOneBy(
  3681.                         array(
  3682.                             'applicantId' => $invoice->getBillerId(),
  3683.                         )
  3684.                     );
  3685.                 $billToDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  3686.                     ->findOneBy(
  3687.                         array(
  3688.                             'applicantId' => $invoice->getBillToId(),
  3689.                         )
  3690.                     );
  3691.             }
  3692.             if ($request->query->get('sendMail'0) == && GeneralConstant::EMAIL_ENABLED == 1) {
  3693.                 $billerDetails = [];
  3694.                 $billToDetails = [];
  3695.                 if ($invoice) {
  3696.                     $billerDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  3697.                         ->findOneBy(
  3698.                             array(
  3699.                                 'applicantId' => $invoice->getBillerId(),
  3700.                             )
  3701.                         );
  3702.                     $billToDetails $em->getRepository('CompanyGroupBundle\\Entity\\EntityApplicantDetails')
  3703.                         ->findOneBy(
  3704.                             array(
  3705.                                 'applicantId' => $invoice->getBillToId(),
  3706.                             )
  3707.                         );
  3708.                     $bodyTemplate 'ApplicationBundle:email/templates:buddybeeInvoiceEmail.html.twig';
  3709.                     $bodyData = array(
  3710.                         'page_title' => 'Invoice',
  3711. //            'studentDetails' => $student,
  3712.                         'billerDetails' => $billerDetails,
  3713.                         'billToDetails' => $billToDetails,
  3714.                         'invoice' => $invoice,
  3715.                         'currencyList' => BuddybeeConstant::$currency_List,
  3716.                         'currencyListByMarker' => BuddybeeConstant::$currency_List_by_marker,
  3717.                     );
  3718.                     $attachments = [];
  3719.                     $forwardToMailAddress $billToDetails->getOAuthEmail();
  3720. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  3721.                     $new_mail $this->get('mail_module');
  3722.                     $new_mail->sendMyMail(array(
  3723.                         'senderHash' => '_CUSTOM_',
  3724.                         //                        'senderHash'=>'_CUSTOM_',
  3725.                         'forwardToMailAddress' => $forwardToMailAddress,
  3726.                         'subject' => 'YourInvoice #' 'D' str_pad('BB'5'0'STR_PAD_LEFT) . str_pad('76'2'0'STR_PAD_LEFT) . str_pad($invoice->getId(), 8"0"STR_PAD_LEFT) . ' from BuddyBee ',
  3727. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  3728.                         'attachments' => $attachments,
  3729.                         'toAddress' => $forwardToMailAddress,
  3730.                         'fromAddress' => 'no-reply@buddybee.eu',
  3731.                         'userName' => 'no-reply@buddybee.eu',
  3732.                         'password' => 'Honeybee@0112',
  3733.                         'smtpServer' => 'smtp.hostinger.com',
  3734.                         'smtpPort' => 465,
  3735. //                            'emailBody' => $bodyHtml,
  3736.                         'mailTemplate' => $bodyTemplate,
  3737.                         'templateData' => $bodyData,
  3738.                         'embedCompanyImage' => 0,
  3739.                         'companyId' => 0,
  3740.                         'companyImagePath' => ''
  3741. //                        'embedCompanyImage' => 1,
  3742. //                        'companyId' => $companyId,
  3743. //                        'companyImagePath' => $company_data->getImage()
  3744.                     ));
  3745.                 }
  3746.             }
  3747. //            if ($invoice) {
  3748. //
  3749. //            } else {
  3750. //                return $this->render('@Buddybee/pages/404NotFound.html.twig', array(
  3751. //                    'page_title' => '404 Not Found',
  3752. //
  3753. //                ));
  3754. //            }
  3755.             return $this->render('@HoneybeeWeb/pages/views/honeybee_ecosystem_invoice.html.twig', array(
  3756.                 'page_title' => 'Invoice',
  3757. //            'studentDetails' => $student,
  3758.                 'billerDetails' => $billerDetails,
  3759.                 'billToDetails' => $billToDetails,
  3760.                 'invoice' => $invoice,
  3761.                 'currencyList' => BuddybeeConstant::$currency_List,
  3762.                 'currencyListByMarker' => BuddybeeConstant::$currency_List_by_marker,
  3763.             ));
  3764.         }
  3765.     }
  3766.     public function SignatureCheckFromCentralAction(Request $request)
  3767.     {
  3768.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3769.         if ($systemType !== '_CENTRAL_') {
  3770.             return new JsonResponse(['success' => false'message' => 'Only allowed on CENTRAL server.'], 403);
  3771.         }
  3772.         $em $this->getDoctrine()->getManager('company_group');
  3773.         $em->getConnection()->connect();
  3774.         $data json_decode($request->getContent(), true);
  3775.         if (
  3776.             !$data ||
  3777.             !isset($data['userId']) ||
  3778.             !isset($data['companyId']) ||
  3779.             !isset($data['signatureData']) ||
  3780.             !isset($data['approvalHash']) ||
  3781.             !isset($data['applicantId'])
  3782.         ) {
  3783.             return new JsonResponse(['success' => false'message' => 'Missing parameters.'], 400);
  3784.         }
  3785.         $userId $data['userId'];
  3786.         $companyId $data['companyId'];
  3787.         $signatureData $data['signatureData'];
  3788.         $approvalHash $data['approvalHash'];
  3789.         $applicantId $data['applicantId'];
  3790.         try {
  3791.             $centralUser $em
  3792.                 ->getRepository("CompanyGroupBundle\\Entity\\EntityApplicantDetails")
  3793.                 ->findOneBy(['applicantId' => $applicantId]);
  3794.             if (!$centralUser) {
  3795.                 return new JsonResponse(['success' => false'message' => 'Central user not found.'], 404);
  3796.             }
  3797.             $userAppIds json_decode($centralUser->getUserAppIds(), true);
  3798.             if (!is_array($userAppIds)) $userAppIds = [];
  3799.             $companies $em->getRepository('CompanyGroupBundle\\Entity\\CompanyGroup')->findBy([
  3800.                 'appId' => $userAppIds
  3801.             ]);
  3802.             if (count($companies) < 1) {
  3803.                 return new JsonResponse(['success' => false'message' => 'No companies found for userAppIds.'], 404);
  3804.             }
  3805.             $repo $em->getRepository('CompanyGroupBundle\\Entity\\EntitySignature');
  3806.             $record $repo->findOneBy(['userId' => $userId]);
  3807.             if (!$record) {
  3808.                 $record = new \CompanyGroupBundle\Entity\EntitySignature();
  3809.                 $record->setUserId($applicantId);
  3810.                 $record->setCreatedAt(new \DateTime());
  3811.             }
  3812.             $record->setCompanyId($companyId);
  3813.             $record->setApplicantId($applicantId);
  3814.             $record->setData($signatureData);
  3815.             $record->setSigExists(0);
  3816.             $record->setLastDecryptedSigId(0);
  3817.             $record->setUpdatedAt(new \DateTime());
  3818.             $em->persist($record);
  3819.             $em->flush();
  3820.             $dataByServerId = [];
  3821.             $gocDataListByAppId = [];
  3822.             foreach ($companies as $entry) {
  3823.                 $gocDataListByAppId[$entry->getAppId()] = [
  3824.                     'dbName' => $entry->getDbName(),
  3825.                     'dbUser' => $entry->getDbUser(),
  3826.                     'dbPass' => $entry->getDbPass(),
  3827.                     'dbHost' => $entry->getDbHost(),
  3828.                     'serverAddress' => $entry->getCompanyGroupServerAddress(),
  3829.                     'port' => $entry->getCompanyGroupServerPort() ?: 80,
  3830.                     'appId' => $entry->getAppId(),
  3831.                     'serverId' => $entry->getCompanyGroupServerId(),
  3832.                 ];
  3833.                 if (!isset($dataByServerId[$entry->getCompanyGroupServerId()]))
  3834.                     $dataByServerId[$entry->getCompanyGroupServerId()] = array(
  3835.                         'serverId' => $entry->getCompanyGroupServerId(),
  3836.                         'serverAddress' => $entry->getCompanyGroupServerAddress(),
  3837.                         'port' => $entry->getCompanyGroupServerPort() ?: 80,
  3838.                         'payload' => array(
  3839.                             'globalId' => $applicantId,
  3840.                             'companyId' => $userAppIds,
  3841.                             'signatureData' => $signatureData,
  3842. //                                      'approvalHash' => $approvalHash
  3843.                         )
  3844.                     );
  3845.             }
  3846.             $urls = [];
  3847.             foreach ($dataByServerId as $entry) {
  3848.                 $serverAddress $entry['serverAddress'];
  3849.                 if (!$serverAddress) continue;
  3850. //                     $connector = $this->container->get('application_connector');
  3851. //                     $connector->resetConnection(
  3852. //                         'default',
  3853. //                         $entry['dbName'],
  3854. //                         $entry['dbUser'],
  3855. //                         $entry['dbPass'],
  3856. //                         $entry['dbHost'],
  3857. //                         $reset = true
  3858. //                     );
  3859.                 $syncUrl $serverAddress '/ReceiveSignatureFromCentral';
  3860.                 $payload $entry['payload'];
  3861.                 $curl curl_init();
  3862.                 curl_setopt_array($curl, [
  3863.                     CURLOPT_RETURNTRANSFER => true,
  3864.                     CURLOPT_POST => true,
  3865.                     CURLOPT_URL => $syncUrl,
  3866. //                         CURLOPT_PORT => $entry['port'],
  3867.                     CURLOPT_CONNECTTIMEOUT => 10,
  3868.                     CURLOPT_SSL_VERIFYPEER => false,
  3869.                     CURLOPT_SSL_VERIFYHOST => false,
  3870.                     CURLOPT_HTTPHEADER => [
  3871.                         'Accept: application/json',
  3872.                         'Content-Type: application/json'
  3873.                     ],
  3874.                     CURLOPT_POSTFIELDS => json_encode($payload)
  3875.                 ]);
  3876.                 $response curl_exec($curl);
  3877.                 $err curl_error($curl);
  3878.                 $httpCode curl_getinfo($curlCURLINFO_HTTP_CODE);
  3879.                 curl_close($curl);
  3880. //                     if ($err) {
  3881. //                         error_log("ERP Sync Error [AppID $appId]: $err");
  3882. //                          $urls[]=$err;
  3883. //                     } else {
  3884. //                         error_log("ERP Sync Response [AppID $appId] (HTTP $httpCode): $response");
  3885. //                         $res = json_decode($response, true);
  3886. //                         if (!isset($res['success']) || !$res['success']) {
  3887. //                             error_log("❗ ERP Sync error for AppID $appId: " . ($res['message'] ?? 'Unknown'));
  3888. //                         }
  3889. //
  3890. //                      $urls[]=$response;
  3891. //                     }
  3892.             }
  3893.             return new JsonResponse(['success' => true'message' => 'Signature synced successfully.']);
  3894.         } catch (\Exception $e) {
  3895.             return new JsonResponse(['success' => false'message' => 'DB error: ' $e->getMessage()], 500);
  3896.         }
  3897.     }
  3898.  //datev cntroller
  3899.     public function connectDatev(Request $request)
  3900.     {
  3901.         $clientId "51b09bdcf577c5b998cddce7fe7d5c92";
  3902.         $redirectUri "https://ourhoneybee.eu/datev/callback";
  3903.         $state bin2hex(random_bytes(10));
  3904.         $scope "openid profile email accounting:documents accounting:dxso-jobs accounting:clients:read datev:accounting:extf-files-import datev:accounting:clients";
  3905.         $codeVerifier bin2hex(random_bytes(32));
  3906.         $codeChallenge rtrim(strtr(base64_encode(hash('sha256'$codeVerifiertrue)), '+/''-_'), '=');
  3907.         $session $request->getSession();
  3908.         $applicantId $session->get(UserConstants::APPLICANT_ID);
  3909.         $em_goc $this->getDoctrine()->getManager('company_group');
  3910.         $token $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityDatevToken')
  3911.             ->findOneBy(['userId' => $applicantId]);
  3912.         if (!$token) {
  3913.             $token = new EntityDatevToken();
  3914.             $token->setUserId($applicantId);
  3915.         }
  3916.         $token->setState($state);
  3917.         $token->setCodeChallenge($codeChallenge);
  3918.         $token->setCodeVerifier($codeVerifier);
  3919.         $em_goc->persist($token);
  3920.         $em_goc->flush();
  3921.         $url "https://login.datev.de/openidsandbox/authorize?"
  3922.             ."response_type=code"
  3923.             ."&client_id=".$clientId
  3924.             ."&state=".$state
  3925.             ."&scope=".urlencode($scope)
  3926.             ."&redirect_uri=".urlencode($redirectUri)
  3927.             ."&code_challenge=".$codeChallenge
  3928.             ."&code_challenge_method=S256"
  3929.             ."&prompt=login";
  3930.         return $this->redirect($url);
  3931.     }
  3932.     public function datevCallback(Request $request)
  3933.     {
  3934.         $code  $request->get('code');
  3935.         $state $request->get('state');
  3936.         if (!$code || !$state) {
  3937.             return new Response("Invalid callback request");
  3938.         }
  3939.         $em_goc $this->getDoctrine()->getManager('company_group');
  3940.         $tokenEntity $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityDatevToken')
  3941.             ->findOneBy(['state' => $state]);
  3942.         if (!$tokenEntity) {
  3943.             return new Response("Invalid or expired state");
  3944.         }
  3945.         $codeVerifier $tokenEntity->getCodeVerifier();
  3946.         if (!$codeVerifier) {
  3947.             return new Response("Code verifier missing");
  3948.         }
  3949.         $clientId "51b09bdcf577c5b998cddce7fe7d5c92";
  3950.         $clientSecret "9b1c4e72a966e9f231584393ff1d3469";
  3951.         // from parameters
  3952. //        $clientId= $this->getContainer()->getParameter('datev_client_id');
  3953. //        $clientSecret= $this->getContainer()->getParameter('datev_client_secret');
  3954.         $authString base64_encode($clientId ":" $clientSecret);
  3955.         $redirectUri "https://ourhoneybee.eu/datev/callback";
  3956.         $postFields http_build_query([
  3957.             "grant_type"    => "authorization_code",
  3958.             "code"          => $code,
  3959.             "redirect_uri"  => $redirectUri,
  3960.             "client_id"     => $clientId,
  3961.             "code_verifier" => $codeVerifier
  3962.         ]);
  3963.         $ch curl_init();
  3964.         curl_setopt_array($ch, [
  3965.             CURLOPT_URL            => "https://sandbox-api.datev.de/token",
  3966.             CURLOPT_POST           => true,
  3967.             CURLOPT_RETURNTRANSFER => true,
  3968.             CURLOPT_POSTFIELDS     => $postFields,
  3969.             CURLOPT_HTTPHEADER     => [
  3970.                 "Content-Type: application/x-www-form-urlencoded",
  3971.                 "Authorization: Basic " $authString
  3972.             ]
  3973.         ]);
  3974.         $response curl_exec($ch);
  3975.         if (curl_errno($ch)) {
  3976.             return new Response("cURL Error: " curl_error($ch), 500);
  3977.         }
  3978.         curl_close($ch);
  3979.         $data json_decode($responsetrue);
  3980.         if (!$data) {
  3981.             return new Response("Invalid token response"500);
  3982.         }
  3983.         if (isset($data['access_token'])) {
  3984.             $tokenEntity->setAccessToken($data['access_token']);
  3985.             $session $request->getSession();  //remove it later
  3986.             $session->set('DATEV_ACCESS_TOKEN'$data['access_token']);
  3987.             if (isset($data['refresh_token'])) {
  3988.                 $tokenEntity->setRefreshToken($data['refresh_token']);
  3989.             }
  3990.             if (isset($data['expires_in'])) {
  3991.                 $tokenEntity->setExpiresAt(time() + $data['expires_in']);
  3992.             }
  3993. //            $tokenEntity->setState(null);
  3994.             $tokenEntity->setCode($code);
  3995.             $em_goc->flush();
  3996.             return $this->redirect("/datev/home");
  3997.         }
  3998.         return new Response(
  3999.             "Token exchange failed: " json_encode($data),
  4000.             400
  4001.         );
  4002.     }
  4003.     public function refreshToken(Request $request)
  4004.     {
  4005.         $em_goc $this->getDoctrine()->getManager('company_group');
  4006.         $session $request->getSession();
  4007.         $applicantId $session->get(UserConstants::APPLICANT_ID);
  4008.         $token $em_goc->getRepository('CompanyGroupBundle\\Entity\\EntityDatevToken')
  4009.             ->findOneBy(['userId' => $applicantId]);
  4010.         if (!$token) {
  4011.             return new JsonResponse([
  4012.                 'status' => false,
  4013.                 'message' => 'User token not found'
  4014.             ]);
  4015.         }
  4016.         if (!$token->getRefreshToken()) {
  4017.             return new JsonResponse([
  4018.                 'status' => false,
  4019.                 'message' => 'No refresh token available'
  4020.             ]);
  4021.         }
  4022.         $clientId "51b09bdcf577c5b998cddce7fe7d5c92";
  4023.         $clientSecret "9b1c4e72a966e9f231584393ff1d3469";
  4024.         $authString base64_encode($clientId ":" $clientSecret);
  4025.         $postFields http_build_query([
  4026.             "grant_type" => "refresh_token",
  4027.             "refresh_token" => $token->getRefreshToken(),
  4028.         ]);
  4029.         $ch curl_init();
  4030.         curl_setopt_array($ch, [
  4031.             CURLOPT_URL => "https://sandbox-api.datev.de/token",
  4032.             CURLOPT_POST => true,
  4033.             CURLOPT_RETURNTRANSFER => true,
  4034.             CURLOPT_POSTFIELDS => $postFields,
  4035.             CURLOPT_HTTPHEADER => [
  4036.                 "Content-Type: application/x-www-form-urlencoded",
  4037.                 "Authorization: Basic " $authString
  4038.             ]
  4039.         ]);
  4040.         $response curl_exec($ch);
  4041.         if (curl_errno($ch)) {
  4042.             return new JsonResponse([
  4043.                 'status' => false,
  4044.                 'message' => curl_error($ch)
  4045.             ]);
  4046.         }
  4047.         curl_close($ch);
  4048.         $data json_decode($responsetrue);
  4049.         if (!isset($data['access_token'])) {
  4050.             return new JsonResponse([
  4051.                 'status' => false,
  4052.                 'message' => 'Refresh failed',
  4053.                 'error' => $data
  4054.             ]);
  4055.         }
  4056.         $token->setAccessToken($data['access_token']);
  4057.         if (isset($data['refresh_token'])) {
  4058.             $token->setRefreshToken($data['refresh_token']);
  4059.         }
  4060.         $token->setExpiresAt(time() + $data['expires_in']);
  4061.         $em_goc->flush();
  4062.         return new JsonResponse([
  4063.             'status' => true,
  4064.             'message' => 'Token refreshed successfully'
  4065.         ]);
  4066.     }
  4067.     public function registerDevice(Request $request)
  4068.     {
  4069.         $em_goc $this->getDoctrine()->getManager('company_group');
  4070.         $data json_decode($request->getContent(), true);
  4071.         if (!$data) {
  4072.             $data $request->request->all();
  4073.         }
  4074.         $deviceSerial $data['device_id'] ?? null;
  4075.         if (!$deviceSerial) {
  4076.             return new JsonResponse([
  4077.                 'success' => false,
  4078.                 'message' => 'Device serial is required',
  4079.                 'data' => null
  4080.             ], 400);
  4081.         }
  4082.         $device =  $em_goc->getRepository('CompanyGroupBundle\\Entity\\Device')
  4083.             ->findOneBy(['deviceSerial' => $deviceSerial]);
  4084.         if (!$device) {
  4085.             $device = new Device();
  4086.             $device->setDeviceSerial($deviceSerial);
  4087.             $message 'Device registered successfully';
  4088.         } else {
  4089.             $message 'Device updated successfully';
  4090.         }
  4091.         if (isset($data['deviceName'])) {
  4092.             $device->setDeviceName($data['deviceName']);
  4093.         }
  4094.         if (isset($data['appId'])) {
  4095.             $device->setAppId($data['appId']);
  4096.         }
  4097.         if (isset($data['deviceType'])) {
  4098.             $device->setDeviceType($data['deviceType']);
  4099.         }
  4100.         if (isset($data['deviceMarker'])) {
  4101.             $device->setDeviceMarker($data['deviceMarker']);
  4102.         }
  4103.         if (isset($data['timezoneStr'])) {
  4104.             $device->setTimezoneStr($data['timezoneStr']);
  4105.         }
  4106.         if (isset($data['hostname'])) {
  4107.             $device->setHostName($data['hostname']);
  4108.         }
  4109.         $em_goc->persist($device);
  4110.         $em_goc->flush();
  4111.         return new JsonResponse([
  4112.             'success' => true,
  4113.             'message' => $message,
  4114.             'data' => [
  4115.                 'id' => $device->getId(),
  4116.                 'deviceSerial' => $device->getDeviceSerial(),
  4117.                 'deviceName' => $device->getDeviceName(),
  4118.                 'deviceType' => $device->getDeviceType(),
  4119.                 'hostName' => $device->getHostName(),
  4120.             ]
  4121.         ]);
  4122.     }
  4123. }