Пример #1
0
 /**
  * @param \Doctrine\Common\Persistence\ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     /** @var User $userDefault */
     $userDefault = $manager->merge($this->getReference('user-default'));
     $payment = new Payment();
     $payment->setUser($userDefault);
     $payment->setAmount(0);
     $payment->setBaseAmount(0);
     $payment->setStatus(Payment::STATUS_PAID);
     $manager->persist($payment);
     $this->addReference('payment', $payment);
     $payment = new Payment();
     $payment->setUser($userDefault);
     $payment->setAmount(0);
     $payment->setBaseAmount(0);
     $payment->setStatus(Payment::STATUS_PENDING);
     $manager->persist($payment);
     $this->addReference('pending', $payment);
     /** @var User $userDefault2 */
     $userDefault2 = $manager->merge($this->getReference('user-default2'));
     $payment = new Payment();
     $payment->setUser($userDefault2);
     $payment->setAmount(0);
     $payment->setBaseAmount(0);
     $payment->setStatus(Payment::STATUS_PAID);
     $manager->persist($payment);
     $this->addReference('payment2', $payment);
     $payment = new Payment();
     $payment->setUser($userDefault2);
     $payment->setAmount(0);
     $payment->setBaseAmount(0);
     $payment->setStatus(Payment::STATUS_PENDING);
     $manager->persist($payment);
     $this->addReference('pending2', $payment);
     $manager->flush();
 }
Пример #2
0
 /**
  * @Route("/admin/event/{slug}/users/add", name="adminusersadd")
  * @Secure(roles="ROLE_ADMIN")
  * @Template()
  */
 public function addUsersAction(Event $event)
 {
     // @todo удалить этот метод. одноразовый харкод
     $em = $this->getDoctrine()->getManager();
     if (isset($_POST['users'])) {
         $users = explode("\r\n", $_POST['users']);
         foreach ($users as $data) {
             // данные с формы
             $dt = explode(' ', $data);
             unset($data);
             $data['name'] = $dt[0] . ' ' . $dt[1];
             $data['email'] = $dt[2];
             $data['discount'] = isset($dt[3]);
             $user = $this->get('fos_user.user_manager')->findUserBy(array('email' => $data['email']));
             // создаем нового пользователя
             if (!$user) {
                 $user = $this->get('fos_user.user_manager')->createUser();
                 $user->setEmail($data['email']);
                 $user->setFullname($data['name']);
                 // генерация временного пароля
                 $password = substr(str_shuffle(md5(time())), 5, 8);
                 $user->setPlainPassword($password);
                 $user->setEnabled(true);
                 $this->get('fos_user.user_manager')->updateUser($user);
                 // отправляем сообщение о регистрации
                 $text = "Приветствуем " . $user->getFullname() . "!\n\nВы были автоматически зарегистрированы на сайте Frameworks Days.\n\nВаш временный пароль: " . $password . "\nЕго можно сменить на странице " . $this->generateUrl('fos_user_change_password', array(), true) . "\n\n\n---\nС уважением,\nКоманда Frameworks Days";
                 $message = \Swift_Message::newInstance()->setSubject("Регистрация на сайте Frameworks Days")->setFrom('*****@*****.**', 'Frameworks Days')->setTo($user->getEmail())->setBody($text);
                 // @todo каждый вызов отнимает память
                 $this->get('mailer')->send($message);
                 echo "#{$user->getId()} {$user->getFullname()} — Create a new user<br>";
             } else {
                 echo "<b>#{$user->getId()} {$user->getFullname()} — already registered</b><br>";
             }
             // обновляем информацию о компании
             $user->setCountry('Украина');
             if (isset($_POST['city'])) {
                 $user->setCity($_POST['city']);
             }
             $user->setCompany($_POST['company']);
             $em->persist($user);
             $em->flush();
             // проверяем или у него нет билетов на этот ивент
             /** @var Ticket $ticket */
             $ticket = $em->getRepository('StfalconEventBundle:Ticket')->findOneBy(array('event' => $event->getId(), 'user' => $user->getId()));
             if (!$ticket) {
                 $ticket = new Ticket();
                 $ticket->setEvent($event);
                 $ticket->setUser($user);
                 $em->persist($ticket);
             }
             if ($ticket->isPaid()) {
                 echo "<b>he has already paid participation in the conference!</b><br>";
             } else {
                 // цена участия (с учетом скидки)
                 $amount = $data['discount'] ? $_POST['amount'] * 0.8 : $_POST['amount'];
                 $ticket->setAmount($amount);
                 $ticket->setHasDiscount($data['discount']);
                 $ticket->setAmountWithoutDiscount($_POST['amount']);
                 $oldPayment = $ticket->getPayment();
                 if ($oldPayment) {
                     $oldPayment->removeTicket($ticket);
                     $em->persist($oldPayment);
                 }
                 echo "create a new payment<br>";
                 $payment = new Payment();
                 $payment->setUser($user);
                 $payment->addTicket($ticket);
                 $em->persist($payment);
                 $em->flush();
                 // обновляем шлюз и статус платежа
                 $payment->setGate('admin');
                 $payment->markedAsPaid();
                 $em->persist($payment);
                 $em->persist($ticket);
                 // сохраняем все изменения
                 $em->flush();
                 echo "mark as paid<br>";
             }
         }
         echo 'complete';
         exit;
     }
     return [];
 }
Пример #3
0
 /**
  * Event pay
  *
  * @param Event $event
  * @throws \Exception
  *
  * @Secure(roles="ROLE_USER")
  * @Route("/event/{event_slug}/pay", name="event_pay")
  * @ParamConverter("event", options={"mapping": {"event_slug": "slug"}})
  * @Template()
  *
  * @return array
  */
 public function payAction(Event $event)
 {
     if (!$event->getReceivePayments()) {
         throw new \Exception("Оплата за участие в {$event->getName()} не принимается.");
     }
     $em = $this->getDoctrine()->getManager();
     /* @var  User $user */
     $user = $this->container->get('security.token_storage')->getToken()->getUser();
     /* @var $ticket Ticket */
     $ticket = $this->container->get('stfalcon_event.ticket.service')->findTicketForEventByCurrentUser($event);
     if (!($payment = $ticket->getPayment())) {
         $payment = new Payment();
         $payment->setUser($user);
         $em->persist($payment);
         $payment->addTicket($ticket);
         $em->persist($ticket);
     }
     if (!$payment->isPaid()) {
         $this->get('stfalcon_event.payment_manager')->checkTicketsPricesInPayment($payment, $event);
         // покупка за реферальные средства
         if ($user->getBalance() > 0) {
             if ($payment->getAmount() < $user->getBalance()) {
                 //Билет бесплатно
                 $referralService = $this->get('stfalcon_event.referral.service');
                 $payment->setAmount(0);
                 $payment->setFwdaysAmount($payment->getBaseAmount());
                 $payment->markedAsPaid();
                 // списываем реферельные средства
                 $referralService->utilizeBalance($payment);
                 $em->persist($payment);
                 $em->flush();
                 return $this->redirect($this->generateUrl('payment_success'));
             } else {
                 $amount = $payment->getAmount() - $user->getBalance();
                 $payment->setAmount($amount);
                 $payment->setFwdaysAmount($user->getBalance());
             }
             $em->persist($payment);
         }
     }
     $em->flush();
     /**
      * Обработка формы промо кода
      */
     $promoCodeForm = $this->createForm('stfalcon_event_promo_code');
     $promoCode = $payment->getPromoCodeFromTickets();
     $request = $this->getRequest();
     // процент скидки для постоянных участников
     $paymentsConfig = $this->container->getParameter('stfalcon_event.config');
     $discountAmount = 100 * (double) $paymentsConfig['discount'];
     if ($request->isMethod('post')) {
         $promoCodeForm->bind($request);
         $code = $promoCodeForm->get('code')->getData();
         $promoCode = $em->getRepository('StfalconEventBundle:PromoCode')->findActivePromoCodeByCodeAndEvent($code, $event);
         if ($promoCode) {
             $notUsedPromoCode = $payment->addPromoCodeForTickets($promoCode, $discountAmount);
             $em->flush();
             if (!empty($notUsedPromoCode)) {
                 $this->get('session')->getFlashBag()->add('not_used_promocode', implode(', ', $notUsedPromoCode));
             }
         } else {
             $promoCodeForm->get('code')->addError(new FormError('Такой промокод не найден'));
         }
     }
     $this->get('session')->set('active_payment_id', $payment->getId());
     return array('data' => $this->get('stfalcon_event.interkassa.service')->getData($payment, $event), 'event' => $event, 'payment' => $payment, 'promoCodeForm' => $promoCodeForm->createView(), 'promoCode' => $promoCode, 'ticketForm' => $this->createForm('stfalcon_event_ticket')->createView(), 'discountAmount' => $discountAmount, 'balance' => $user->getBalance());
 }