src/PHPDish/Bundle/PostBundle/Service/CategoryManager.php
public function payForCategory(CategoryInterface $category, UserInterface $user)
    {
        if ($category->isCharging()) {
            //发起付费
            $message = $category->isBook() ?
                $this->translator->trans('book.buy_book', [
                    '%book%' => sprintf('<a href="%s">%s</a>',
                        $this->router->generate('book_view', ['slug' => $category->getSlug()]),
                        $category->getName()
                    )
                ]):
                $this->translator->trans('category.subscribe_category', [
                    '%category%' => sprintf('<a href="%s">%s</a>',
                        $this->router->generate('category_view', ['slug' => $category->getSlug()]),
                        $category->getName()
                    )
                ]);

            //创建交易
            $payment = $this->paymentManager->createPayment($user)
                ->setAmount($category->getCharge())
                ->setDescription($message)
                ->setType($category->isBook() ? PaymentInterface::TYPE_BUY_BOOK
                    : PaymentInterface::TYPE_FOLLOW_CATEGORY)
                ->setPayableId($category->getId());


            $qrCode = $this->paymentManager->charge($payment);
        } else {
            throw new \LogicException($this->translator->trans('category.is_free'));
        }
        return $qrCode;
    }
public function payForCategory(CategoryInterface $category, UserInterface $user)
    {
        if ($category->isCharging()) {
            //发起付费
            $message = $category->isBook() ?
                $this->translator->trans('book.buy_book', [
                    '%book%' => sprintf('<a href="%s">%s</a>',
                        $this->router->generate('book_view', ['slug' => $category->getSlug()]),
                        $category->getName()
                    )
                ]):
                $this->translator->trans('category.subscribe_category', [
                    '%category%' => sprintf('<a href="%s">%s</a>',
                        $this->router->generate('category_view', ['slug' => $category->getSlug()]),
                        $category->getName()
                    )
                ]);

            //创建交易
            $payment = $this->paymentManager->createPayment($user)
                ->setAmount($category->getCharge())
                ->setDescription($message)
                ->setType($category->isBook() ? PaymentInterface::TYPE_BUY_BOOK
                    : PaymentInterface::TYPE_FOLLOW_CATEGORY)
                ->setPayableId($category->getId());


            $qrCode = $this->paymentManager->charge($payment);
        } else {
            throw new \LogicException($this->translator->trans('category.is_free'));
        }
        return $qrCode;
    }
{@inheritdoc}