Esempio n. 1
1
 /**
  * @Security("has_role('ROLE_USER')")
  * @Route("/pay/add/{adv_id}", name="get-pay-form", options={"expose"=true})
  * @param Request $request
  * @param integer $adv_id
  * @return JsonResponse
  */
 public function payAction(Request $request, $adv_id)
 {
     $data = (object) json_decode($request->getContent(), true);
     /** @var User $user */
     $user = $this->getUser();
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $user = $em->getReference('NaidusvoeBundle:User', $user->getId());
     $adv = $em->find('NaidusvoeBundle:Advertisment', $adv_id);
     $order = new Order($user, $adv);
     $hash = Order::generateHash($em, $user->getId(), $adv_id);
     $result = Order::CheckForm($data, $order);
     if ($result['correct'] === true) {
         /** @var Order $order */
         $order = $result['order'];
         $order->setHash($hash);
         $order->setStatus('new');
         $em->persist($order);
         $em->flush();
         $liqpay = new \LiqPay($this->public_key, $this->private_key);
         $html = $liqpay->cnb_form(array('version' => '3', 'amount' => $order->getAmount(), 'currency' => 'UAH', 'description' => 'Оплата додаткових послуг для сайту ZnaiduSvoe.com', 'order_id' => $hash, 'sandbox' => 1, 'pay_way' => $order->getPayWay(), 'server_url' => $this->generateUrl('confirm-payment-callback', ['hash' => $hash], UrlGeneratorInterface::ABSOLUTE_URL), 'result_url' => $this->generateUrl('advertisement-page', ['type' => $adv->getType()->getSlug(), 'adv_id' => $adv->getId()], UrlGeneratorInterface::ABSOLUTE_URL)));
         return new JsonResponse(['status' => 'ok', 'form' => $html]);
     } else {
         return new JsonResponse(['status' => 'error', 'message' => 'PAYMENT_INCORRECT_DATA']);
     }
 }