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

问题描述 投票:0回答:1

我是Symfony的新手,我正在尝试实现用于处理付款JMSPaymentCoreBundle的捆绑软件。我遵循了指南:http://jmspaymentcorebundle.readthedocs.io/en/stable/guides/accepting_payments.html

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

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

我遵循了所有步骤,但不知道可能出什么问题。

我输入了代码,也许您能帮我一把! :D

订单类:

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

php symfony paypal bundle payment
1个回答
0
投票

@ david您是否曾经找到导致该错误的原因?

© www.soinside.com 2019 - 2024. All rights reserved.