예제 #1
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;
 }
예제 #2
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);
 }