Beispiel #1
0
 /**
  * @param Order $order
  * @param array $details
  */
 public function __construct($order, $details)
 {
     $this->order = $order;
     $this->user = $order->getUser();
     $this->advertisement = $order->getAdvertisement();
     $this->details = $details;
     $this->hash = $order->getHash();
 }
Beispiel #2
0
 /**
  * @param object $form
  * @param Order $order
  * @return array
  */
 public static function CheckForm($form, $order)
 {
     $result = ['correct' => true, 'order' => null];
     $total = 0;
     if ($form->advOnMain['checked'] === true) {
         switch ($form->advOnMain['period']) {
             case '3':
                 $order->setAdvOnMainPeriod(3);
                 $total += 15;
                 break;
             case '7':
                 $order->setAdvOnMainPeriod(7);
                 $total += 30;
                 break;
             case '14':
                 $order->setAdvOnMainPeriod(14);
                 $total += 50;
                 break;
         }
         $order->setAdvOnMain(true);
     } else {
         $order->setAdvOnMain(false);
     }
     if ($form->advOnTop['checked'] === true) {
         switch ($form->advOnTop['period']) {
             case '3':
                 $order->setAdvOnTopPeriod(3);
                 $total += 15;
                 break;
             case '7':
                 $order->setAdvOnTopPeriod(7);
                 $total += 30;
                 break;
             case '14':
                 $order->setAdvOnTopPeriod(14);
                 $total += 50;
                 break;
         }
         $order->setAdvOnTop(true);
     } else {
         $order->setAdvOnTop(false);
     }
     if ($form->advFilled['checked'] === true) {
         switch ($form->advFilled['period']) {
             case '3':
                 $order->setAdvFilledPeriod(3);
                 $total += 15;
                 break;
             case '7':
                 $order->setAdvFilledPeriod(7);
                 $total += 30;
                 break;
             case '14':
                 $order->setAdvFilledPeriod(14);
                 $total += 50;
                 break;
         }
         $order->setAdvFilled(true);
     } else {
         $order->setAdvFilled(false);
     }
     if ($form->advUrgent['checked'] === true) {
         switch ($form->advUrgent['period']) {
             case '3':
                 $order->setAdvUrgentPeriod(3);
                 $total += 15;
                 break;
             case '7':
                 $order->setAdvUrgentPeriod(7);
                 $total += 30;
                 break;
             case '14':
                 $order->setAdvUrgentPeriod(14);
                 $total += 50;
                 break;
         }
         $order->setAdvUrgent(true);
     } else {
         $order->setAdvUrgent(false);
     }
     if ($form->advUpdate['checked'] === true) {
         $order->setAdvUpdate(true);
         $total += 15;
     } else {
         $order->setAdvUpdate(false);
     }
     if ($form->advBlock['checked'] === true) {
         switch ($form->advBlock['period']) {
             case '3':
                 $order->setAdvBlockPeriod(3);
                 $total += 15;
                 break;
             case '7':
                 $order->setAdvBlockPeriod(7);
                 $total += 30;
                 break;
             case '14':
                 $order->setAdvBlockPeriod(14);
                 $total += 50;
                 break;
         }
         $order->setAdvBlock(true);
     } else {
         $order->setAdvBlock(false);
     }
     $order->setAmount($total);
     $order->setPayWay($form->payWay);
     $result['correct'] = $form->total === $total;
     $result['order'] = $order;
     return $result;
 }
Beispiel #3
0
 /**
  * @param Order $order
  * @return null|Advertisment
  */
 public function activateAdditionalFeatures(Order $order)
 {
     $now = new \DateTime();
     if ($order !== null) {
         if ($order->getAdvOnMain() === true) {
             $this->setOnMainUntill($now->modify('+' . $order->getAdvOnMainPeriod() . ' days'));
         }
         if ($order->getAdvOnTop() === true) {
             $this->setOnTopUntill($now->modify('+' . $order->getAdvOnTopPeriod() . ' days'));
         }
         if ($order->getAdvFilled() === true) {
             $this->setFilledUntill($now->modify('+' . $order->getAdvFilledPeriod() . ' days'));
         }
         if ($order->getAdvUrgent() === true) {
             $this->setUrgentUntill($now->modify('+' . $order->getAdvUrgentPeriod() . ' days'));
         }
         if ($order->getAdvUpdate() === true) {
             $this->setDate($now);
         }
         if ($order->getAdvBlock() === true) {
             $this->setOnBlockUntill($now->modify('+' . $order->getAdvBlockPeriod() . ' days'));
         }
         return $this;
     } else {
         return null;
     }
 }
Beispiel #4
0
 /**
  * @param Order $order
  * @param array $details
  * @return JsonResponse
  */
 private function handleConfirmation($order, $details)
 {
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     if ($order !== null) {
         if ($order->getStatus() === 'new') {
             $payment = new Payment($order, $details);
             $em->persist($payment);
             $order->setStatus('confirmed');
             $em->persist($order);
             $adv = $em->find('NaidusvoeBundle:Advertisment', $order->getAdvertisementId());
             $adv = $adv->activateAdditionalFeatures($order);
             if ($adv !== null) {
                 $em->persist($adv);
             }
             $em->flush();
         }
         $mailer = $this->get('mailer');
         /** @var \Swift_Message $message */
         $message = $mailer->createMessage();
         $message->setTo($order->getUser()->getEmail());
         $message->setFrom($this->container->getParameter('system_mail'));
         $message->setSubject('Оплата додаткових послуг на сайті Znaidusvoe.com');
         $message->setBody($this->get('twig')->render('@Naidusvoe/payment-success.email.html.twig', ['adv' => $order->getAdvertisement()]), 'text/html');
         $mailer->send($message);
         return new JsonResponse(['status' => 'ok', 'details' => $details]);
     } else {
         return new JsonResponse(['status' => 'error', 'message' => 'ORDER_NOT_FOUND']);
     }
 }