Пример #1
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']);
     }
 }