Exemplo n.º 1
0
 public function postUpdate(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $this->mailer = $this->container->get('mailer');
     $this->mailerHelper = $this->container->get('stfalcon_event.mailer_helper');
     $this->pdfGeneratorHelper = $this->container->get('stfalcon_event.pdf_generator.helper');
     if ($entity instanceof Payment) {
         if ($entity->getStatus() === Payment::STATUS_PAID) {
             $tickets = $this->container->get('doctrine')->getManager()->getRepository('StfalconEventBundle:Ticket')->getAllTicketsByPayment($entity);
             /** @var Ticket $ticket */
             foreach ($tickets as $ticket) {
                 /** @var $user User */
                 $user = $ticket->getUser();
                 /** @var Event $event */
                 $event = $ticket->getEvent();
                 $successPaymentTemplateContent = $this->mailerHelper->renderTwigTemplate('StfalconEventBundle:Interkassa:_mail.html.twig', ['user' => $user, 'event' => $event]);
                 $mail = new Mail();
                 $mail->addEvent($event);
                 $mail->setText($successPaymentTemplateContent);
                 $html = $this->pdfGeneratorHelper->generateHTML($ticket);
                 $message = $this->mailerHelper->formatMessage($user, $mail);
                 $message->setSubject($event->getName())->attach(\Swift_Attachment::newInstance($this->pdfGeneratorHelper->generatePdfFile($ticket, $html), $ticket->generatePdfFilename()));
                 $this->mailer->send($message);
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $userDefault = $manager->merge($this->getReference('user-default'));
     $mail = new Mail();
     $mail->setTitle('test');
     $mail->setText('test');
     $mail->setPaymentStatus($manager->merge($this->getReference('payment')));
     $mail->addEvent($manager->merge($this->getReference('event-zfday')));
     $manager->persist($mail);
     $mq = new MailQueue();
     $mq->setMail($mail);
     $mq->setUser($userDefault);
     $manager->persist($mq);
     $manager->flush();
     $this->addReference('mail_queue', $mq);
 }
Exemplo n.º 3
0
 /**
  * Здесь мы получаем уведомления о статусе платежа и отмечаем платеж как успешный (или не отмечаем)
  * Также рассылаем письма и билеты всем, кто был привязан к платежу
  *
  * @Route("/payment/interaction", name="payment_interaction")
  * @Template()
  *
  * @param Request $request
  *
  * @return array
  */
 public function interactionAction(Request $request)
 {
     /** @var Payment $payment */
     $payment = $this->getDoctrine()->getRepository('StfalconPaymentBundle:Payment')->findOneBy(array('id' => $request->get('ik_pm_no')));
     if (!$payment) {
         throw new Exception('Платеж №' . $request->get('ik_pm_no') . ' не найден!');
     }
     // @var InterkassaService $interkassa
     $interkassa = $this->container->get('stfalcon_event.interkassa.service');
     if ($payment->isPending() && 1) {
         //$interkassa->checkPayment($payment, $request)) {
         $payment->markedAsPaid();
         $em = $this->getDoctrine()->getManager();
         $em->flush();
         /** @var Ticket  $ticket */
         foreach ($payment->getTickets() as $ticket) {
             // розсилка квитків
             // @todo тут має смикатись сервіс який розсилає мильники про успішну оплату квитків + пдф в аттачі
             $user = $ticket->getUser();
             $event = $ticket->getEvent();
             $twig = $this->get('twig');
             // @todo ачуметь.. екшн в одному бандлі. вьюшка в іншому
             $successPaymentTemplateContent = $twig->loadTemplate('StfalconEventBundle:Interkassa:success_payment.html.twig')->render(array('event_slug' => $event->getSlug()));
             $mail = new Mail();
             $mail->addEvent($event);
             $mail->setText($successPaymentTemplateContent);
             // Get base template for email
             $emailTemplateContent = $twig->loadTemplate('StfalconEventBundle::email.html.twig');
             $dateFormatter = new \IntlDateFormatter('ru-RU', \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, 'd MMMM Y');
             $text = $mail->replace(array('%fullname%' => $user->getFullName(), '%event%' => $event->getName(), '%date%' => $dateFormatter->format($event->getDate()), '%place%' => $event->getPlace()));
             $body = $emailTemplateContent->render(array('text' => $text, 'mail' => $mail, 'add_bottom_padding' => true));
             /** @var $pdfGen \Stfalcon\Bundle\EventBundle\Helper\PdfGeneratorHelper */
             $pdfGen = $this->get('stfalcon_event.pdf_generator.helper');
             $html = $pdfGen->generateHTML($ticket);
             $outputFile = 'ticket-' . $event->getSlug() . '.pdf';
             $message = \Swift_Message::newInstance()->setSubject($event->getName())->setFrom('*****@*****.**', 'Frameworks Days')->setTo($user->getEmail())->setBody($body, 'text/html')->attach(\Swift_Attachment::newInstance($pdfGen->generatePdfFile($html, $outputFile), $outputFile));
             $this->get('mailer')->send($message);
         }
         return new Response('SUCCESS', 200);
     }
     return new Response('FAIL', 400);
 }