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

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