Ejemplo n.º 1
0
 /**
  * @param FinancialTransactionInterface      $transaction
  * @param \Vifeed\PaymentBundle\Entity\Order $order
  *
  * @return ActionRequiredException
  */
 protected function createRedirectActionException(FinancialTransactionInterface $transaction, Order $order)
 {
     $actionRequest = new ActionRequiredException('Redirect to pay');
     $actionRequest->setFinancialTransaction($transaction);
     $url = $this->router->generate('order_bill', ['id' => $order->getId()], false);
     $actionRequest->setAction(new DownloadFile($url));
     return $actionRequest;
 }
Ejemplo n.º 2
0
 /**
  * Счёт для скачивания
  *
  * @param Order $order
  *
  *
  * @return Response
  */
 public function billAction(Order $order)
 {
     if ($this->getUser() !== $order->getUser()) {
         throw new AccessDeniedHttpException();
     }
     $method = $order->getPaymentInstruction()->getPaymentSystemName();
     if (!in_array($method, ['bank_transfer', 'bank_receipt'])) {
         throw new NotFoundHttpException();
     }
     $billData = $order->getBillData();
     if (!isset($billData['bill']) || !isset($billData['template'])) {
         throw new \Exception('Недостаточно данных о заказе');
     }
     $billGenerator = $this->get('vifeed.payment.bill_generator');
     $billGenerator->setOrderDetails($billData['bill'])->setTemplate($billData['template']);
     $response = new Response();
     $response->setContent($billGenerator->generate());
     $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'Счет-' . $order->getId() . '.pdf', 'Bill-' . $order->getId() . '.pdf');
     $response->headers->set('Content-Type', 'application/pdf');
     $response->headers->set('Content-Disposition', $disposition);
     return $response;
 }
Ejemplo n.º 3
0
 protected static function loadTestFixtures()
 {
     $userManager = self::getContainer()->get('fos_user.user_manager');
     $tokenManager = self::getContainer()->get('vifeed.user.wsse_token_manager');
     $ppc = self::getContainer()->get('payment.plugin_controller');
     /** @var User $publisher */
     $publisher = $userManager->createUser();
     $publisher->setEmail('*****@*****.**')->setUsername('*****@*****.**')->setBalance(100)->setEnabled(true)->setType(User::TYPE_PUBLISHER)->setPlainPassword('12345');
     $userManager->updateUser($publisher);
     $order = new Order();
     $order->setAmount(61)->setUser($publisher);
     $instruction = new PaymentInstruction($order->getAmount(), 'RUR', 'robokassa');
     $ppc->createPaymentInstruction($instruction);
     $order->setPaymentInstruction($instruction);
     self::$em->persist($order);
     self::$em->flush();
     $payment = $ppc->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount());
     $ppc->approveAndDeposit($payment->getId(), $payment->getTargetAmount());
     $tokenManager->createUserToken($publisher->getId());
     return ['orders' => [$order], 'users' => [$publisher]];
 }
Ejemplo n.º 4
0
 /**
  * Платёж совершён
  *
  * @param Order $order
  *
  * @Rest\Get("orders/{id}/complete", requirements={"id"="\d+"})
  * @ParamConverter("order", class="VifeedPaymentBundle:Order")
  * @ApiDoc(
  *     section="Billing API",
  *     requirements={
  *         {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="id заказа"}
  *     },
  *     statusCodes={
  *         200="Returned when successful",
  *         303="Returned when some user action is required by payment system",
  *         403="Returned when the user is not authorized to use this method",
  *         404="Returned when order is not found"
  *     }
  * )
  *
  * @throws \RuntimeException
  * @throws \JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException
  *
  * @return Response
  */
 public function getOrderCompleteAction(Order $order)
 {
     if ($this->getUser() !== $order->getUser()) {
         throw new AccessDeniedHttpException();
     }
     $instruction = $order->getPaymentInstruction();
     // если заказ уже оплачен, то нам тут нечего ловить
     if ($instruction->getAmount() != $instruction->getApprovedAmount()) {
         /** @var FinancialTransaction $pendingTransaction */
         $pendingTransaction = $instruction->getPendingTransaction();
         if (null === $pendingTransaction) {
             $payment = $this->ppc->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount());
         } else {
             $payment = $pendingTransaction->getPayment();
         }
         /** @var Result $result */
         $result = $this->ppc->approveAndDeposit($payment->getId(), $payment->getTargetAmount());
         if (Result::STATUS_PENDING === $result->getStatus()) {
             $ex = $result->getPluginException();
             $order->setStatus(Order::STATUS_PENDING);
             $this->em->persist($order);
             $this->em->flush($order);
             if ($ex instanceof ActionRequiredException) {
                 $action = $ex->getAction();
                 if ($action instanceof DownloadFile) {
                     return $this->handleView(new View(['url' => $action->getUrl()], 303));
                 } elseif ($action instanceof VisitUrl) {
                     $data = ['url' => $action->getUrl(), 'orderId' => $order->getId()];
                     return $this->handleView(new View($data, 303));
                 }
                 throw $ex;
             }
         }
     }
     $view = new View(['status' => $order->getStatus()]);
     return $this->handleView($view);
 }
Ejemplo n.º 5
0
 protected static function loadTestFixtures()
 {
     /** @var UserManager $userManager */
     $userManager = self::getContainer()->get('fos_user.user_manager');
     /** @var EntityManager $entityManager */
     $entityManager = self::$em;
     $campaignManager = self::getContainer()->get('vifeed.campaign.manager');
     $tokenManager = static::getContainer()->get('vifeed.user.wsse_token_manager');
     /** @var VideoViewPaymentManager $viewPaymentManager */
     $viewPaymentManager = self::getContainer()->get('vifeed.payment.video_view_payment_manager');
     $paymentPluginController = self::getContainer()->get('payment.plugin_controller');
     /** @var StatsManager $statsManager */
     $statsManager = self::getContainer()->get('vifeed.videoview.stats_manager');
     /** @var User $advertiser */
     $advertiser = $userManager->createUser();
     $advertiser->setEmail('*****@*****.**')->setUsername('*****@*****.**')->setBalance(26)->setEnabled(true)->setType(User::TYPE_ADVERTISER)->setPlainPassword('12345');
     $userManager->updateUser($advertiser, false);
     /** @var User $publisher */
     $publisher = $userManager->createUser();
     $publisher->setEmail('*****@*****.**')->setUsername('*****@*****.**')->setBalance(200)->setEnabled(true)->setType(User::TYPE_PUBLISHER)->setPlainPassword('12345');
     $userManager->updateUser($publisher, false);
     $campaign1 = new Campaign();
     $campaign1->setStatus(Campaign::STATUS_ON)->setBid(3)->setName('111')->setUser($advertiser)->setHash(substr(md5(mt_rand(1, 100)), 0, 11))->setDailyBudget(7)->setBalance(10)->setGeneralBudget(10);
     $campaignManager->save($campaign1);
     $campaign2 = new Campaign();
     $campaign2->setStatus(Campaign::STATUS_ON)->setBid(3)->setName('222')->setUser($advertiser)->setHash(substr(md5(mt_rand(1, 100)), 0, 11))->setDailyBudget(0)->setBalance(10)->setGeneralBudget(10)->setDeletedAt(new \DateTime('2014-02-10'));
     $campaignManager->save($campaign2);
     $platform1 = new Platform();
     $platform1->setName('111')->setUser($publisher)->setUrl('111')->setDescription('');
     $entityManager->persist($platform1);
     // плолщадка удалена (soft-delete)
     $platform2 = new Platform();
     $platform2->setName('222')->setUser($publisher)->setUrl('222')->setDescription('')->setDeletedAt(new \DateTime('2014-02-10'));
     $entityManager->persist($platform2);
     $view1 = new VideoView();
     $view1->setCampaign($campaign1)->setPlatform($platform1)->setCurrentTime(60)->setTimestamp((new \DateTime('2014-02-22 00:00:00'))->format('U'))->setTrackNumber(60)->setViewerId(md5(1));
     $entityManager->persist($view1);
     $entityManager->flush();
     $viewPaymentManager->reckon($view1);
     $view2 = new VideoView();
     $view2->setCampaign($campaign1)->setPlatform($platform2)->setCurrentTime(60)->setTimestamp((new \DateTime('2014-02-23 00:00:00'))->format('U'))->setTrackNumber(60)->setViewerId(md5(2));
     $entityManager->persist($view2);
     $entityManager->flush();
     $viewPaymentManager->reckon($view2);
     $view3 = new VideoView();
     $view3->setCampaign($campaign2)->setPlatform($platform1)->setCurrentTime(60)->setTimestamp((new \DateTime('2014-02-23 23:00:00'))->format('U'))->setTrackNumber(60)->setViewerId(md5(3));
     $entityManager->persist($view3);
     $entityManager->flush();
     $viewPaymentManager->reckon($view3);
     $view4 = new VideoView();
     $view4->setCampaign($campaign2)->setPlatform($platform1)->setCurrentTime(60)->setTimestamp((new \DateTime('2014-02-23 23:29:59'))->format('U'))->setTrackNumber(60)->setViewerId(md5(4));
     $entityManager->persist($view4);
     $entityManager->flush();
     $viewPaymentManager->reckon($view4);
     $view5 = new VideoView();
     $view5->setCampaign($campaign2)->setPlatform($platform1)->setCurrentTime(60)->setTimestamp((new \DateTime('2014-02-23 23:59:59'))->format('U'))->setTrackNumber(60)->setViewerId(md5(4));
     $entityManager->persist($view5);
     $entityManager->flush();
     $viewPaymentManager->reckon($view5);
     $instruction1 = new PaymentInstruction(100, 'RUR', 'robokassa');
     $paymentPluginController->createPaymentInstruction($instruction1);
     $instruction2 = new PaymentInstruction(50, 'RUR', 'robokassa');
     $paymentPluginController->createPaymentInstruction($instruction2);
     $instruction3 = new PaymentInstruction(50, 'RUR', 'robokassa');
     $paymentPluginController->createPaymentInstruction($instruction3);
     $order1 = new Order();
     $order1->setUser($advertiser)->setStatus(Order::STATUS_PAID)->setAmount(100)->setPaymentInstruction($instruction1);
     $entityManager->persist($order1);
     $order2 = new Order();
     $order2->setUser($advertiser)->setStatus(Order::STATUS_PAID)->setAmount(50)->setPaymentInstruction($instruction2);
     $entityManager->persist($order2);
     $order3 = new Order();
     $order3->setUser($advertiser)->setStatus(Order::STATUS_NEW)->setAmount(50)->setPaymentInstruction($instruction3);
     $entityManager->persist($order3);
     $wallet = new Wallet();
     $wallet->setUser($publisher)->setNumber(12345)->setType('yandex');
     $entityManager->persist($wallet);
     $withdrawal1 = new Withdrawal();
     $withdrawal1->setUser($publisher)->setAmount(50)->setWallet($wallet)->setCreatedAt(new \DateTime('2014-02-28 10:00:00'))->setStatus(Withdrawal::STATUS_OK);
     $entityManager->persist($withdrawal1);
     $withdrawal2 = new Withdrawal();
     $withdrawal2->setUser($publisher)->setAmount(100)->setWallet($wallet)->setCreatedAt(new \DateTime('2014-02-28 12:00:00'))->setStatus(Withdrawal::STATUS_OK);
     $entityManager->persist($withdrawal2);
     $withdrawal3 = new Withdrawal();
     $withdrawal3->setUser($publisher)->setAmount(20)->setWallet($wallet)->setCreatedAt(new \DateTime('2014-02-27 10:00:00'))->setStatus(Withdrawal::STATUS_CREATED);
     $entityManager->persist($withdrawal3);
     $withdrawal4 = new Withdrawal();
     $withdrawal4->setUser($publisher)->setAmount(30)->setWallet($wallet)->setCreatedAt(new \DateTime('2014-02-27 11:00:00'))->setStatus(Withdrawal::STATUS_ERROR);
     $entityManager->persist($withdrawal4);
     $entityManager->flush();
     $tokenManager->createUserToken($advertiser->getId());
     $tokenManager->createUserToken($publisher->getId());
     $statsManager->recollectAllStats();
     $statsManager->collectDailyStats((new \DateTime())->setTime(0, 0, 0));
     return array('advertiser' => $advertiser, 'publisher' => $publisher, 'platforms' => [$platform1, $platform2], 'campaigns' => array($campaign1, $campaign2));
 }