Symfony 3 JMSPaymentCoreBundle - 类名必须是有效对象或字符串

时间:2017-05-24 15:09:07

标签: php symfony paypal bundle payment

我是Symfony的新手,我正在尝试实施捆绑处理付款JMSPaymentCoreBundle。我按照指南:http://jmspaymentcorebundle.readthedocs.io/en/stable/guides/accepting_payments.html

但是当我创建服务“payment.plugin_controller”时,我在插件控制器中得到一个异常(类名必须是有效对象或字符串)

https://i.stack.imgur.com/9Ehqw.png

我遵循了所有步骤,我不知道可能出现的问题。

我把代码放了,也许你可以帮我一把! :d

Order类:      

use AppBundle\Entity\Orders;
use JMS\Payment\CoreBundle\Exception\Exception;
use Symfony\Component\HttpFoundation\Request;
use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
use JMS\Payment\CoreBundle\PluginController\Result;
use JMS\DiExtraBundle\Annotation as DI;
use JMS\Payment\CoreBundle\Plugin\Exception\Action\VisitUrl;
use JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException;

/**
 * Class OrdersController
 * @package AppBundle\Controller
 * @Route("/orders")
 */
class OrdersController extends Controller
{
    /**
     * @param Request $request
     * @param $amount
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     * @Route("/new/{amount}")
     */
    public function newAction(Request $request, $amount) {
        $em = $this->getDoctrine()->getManager();

        $order = new Orders($amount);
        $em->persist($order);
        $em->flush();

        return $this->redirect($this->generateUrl('app_orders_show', ['request' => $request,'id' => $order->getId()]));
    }

    /**
     * @Route("/{id}/show")
     */
    public function showAction(Request $request, Orders $order)
    {
        $form = $this->createForm(ChoosePaymentMethodType::class, null, [
            'amount' => $order->getAmount(),
            'currency' => 'EUR',
            'default_method' => 'payment_paypal', // Optional
            'predefined_data' => array(
                'paypal_express_checkout' => array(
                    'return_url' => $this->generateUrl('app_orders_paymentcreate', array(
                        'id' => $order->getId()
                    ), true),
                    'cancel_url' => $this->generateUrl('payment_cancel', array(
                        'id' => $order->getId()
                    ), true)
                ),
            ),
        ]);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $ppc = $this->get('payment.plugin_controller');
            $ppc->createPaymentInstruction($instruction = $form->getData());
            $order->setPaymentInstruction($instruction);

            $em = $this->getDoctrine()->getManager();
            $em->persist($order);
            $em->flush();

            return $this->redirect($this->generateUrl('app_orders_paymentcreate', [
                'id' => $order->getId()
            ]));
        }

        return $this->render('AppBundle:Orders:show.html.twig', array('order'=>$order, 'form' => $form->createView()));
    }

    private function createPayment(Orders $order) {
        $instruction = $order->getPaymentInstruction();
        $pendingTranstaction = $instruction->getPendingTransaction();

        if($pendingTranstaction !== null) {
            return $pendingTranstaction->getPayment();
        }
        $ppc = $this->get('payment.plugin_controller');
        $amount = $instruction->getAmount() - $instruction->getDepositedAmount();

        return $ppc->createPayment($instruction->getId(), $amount);
    }

    /**
     * @Route("/{id}/payment/create")
     */
    public function paymentCreateAction(Orders $order) {
        $payment = $this->createPayment($order);

        $ppc = $this->get('payment.plugin_controller');
        $result = $ppc->approveAndDeposit($payment->getId(), $payment->getTargetAmount());

        if ($result->getStatus() === Result::STATUS_PENDING) {
            $ex = $result->getPluginException();

            if ($ex instanceof ActionRequiredException) {
                $action = $ex->getAction();

                if ($action instanceof VisitUrl) {
                    return $this->redirect($action->getUrl());
                }
            }
        }

        throw new Exception("0");
    }


    /**
     * @Route("/{id}/payment/complete")
     */
    public function paymentCompleteAction(Orders $order)
    {
        return new Response('Payment complete');
    }

    /**
     * @Route("/cancel", name = "payment_cancel")
     */
    public function CancelAction( )
    {
        $this->get('session')->getFlashBag()->add('info', 'Transaction annulée.');
        return new Response('Payment fail');
    }
}

服务:

services:
  payment.plugin_controller:
    class: JMS\Payment\CoreBundle\PluginController\EntityPluginController
    arguments:
       EntityManager: "@doctrine.orm.entity_manager"

捆绑

public function registerBundles()
    {
        $bundles = [
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),
            new JMS\Payment\CoreBundle\JMSPaymentCoreBundle(),
            new JMS\Payment\PaypalBundle\JMSPaymentPaypalBundle(),
            new JMS\DiExtraBundle\JMSDiExtraBundle(),
            new JMS\AopBundle\JMSAopBundle()
        ];

配置:

jms_payment_core:
    encryption:
      secret: xxx

jms_payment_paypal:
    username: xxx
    password: xxx
    signature: xxx-xxx
    debug: false

我必须创建一个服务,因为在指南中会调用依赖payment.plugin_controller($ this-> get('payment.plugin_controller')。我没错吗?

非常感谢你的帮助!

编辑:

日志: https://i.stack.imgur.com/09quW.png

0 个答案:

没有答案