【问题标题】:Symfony 3 JMS payment Paypal ErrorSymfony 3 JMS 支付 Paypal 错误
【发布时间】:2018-01-26 05:32:58
【问题描述】:

我来找你是因为我真的不知道使用这个捆绑包进行贝宝结帐有什么问题。

http://jmspaymentcorebundle.readthedocs.io/en/stable/setup.html

这是关于捆绑包和文档的链接。

我的问题在教程的末尾,我有一个错误,我不知道如何解决。

CRITICAL - 未捕获的 PHP 异常 JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException:“用户 必须授权交易。”在 C:\wamp64\www\Wolk\vendor\jms\payment-paypal-bundle\JMS\Payment\PaypalBundle\Plugin\ExpressCheckoutPlugin.php 第 303 行

这是我的控制器代码:

<?php
namespace Wolk\PlatformBundle\Controller;

use Wolk\PlatformBundle\Entity\Order;
use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType;
use JMS\Payment\CoreBundle\PluginController\Result;
use JMS\Payment\CoreBundle\Plugin\AbstractPlugin;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

/**
 * @Route("/orders")
 */
class OrdersController extends Controller
{
    /**
 * @Route("/new/{amount}")
 */
public function newAction($amount, $game)
{
    $em = $this->getDoctrine()->getManager();

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

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

/**
 * @Route("/{id}/show")
 * @Template
 */
public function showAction(Request $request, Order $order, $game)
{
    $form = $this->createForm(ChoosePaymentMethodType::class, null, [
        'amount'   => $order->getAmount(),
        'currency' => 'EUR',
    ]);

        $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($order);

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

    return [
        'order' => $order,
        'form'  => $form->createView(),
        'game' => $game,
    ];
}

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

    if ($pendingTransaction !== null) {
        return $pendingTransaction->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(Order $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 $result->getPluginException();

    // In a real-world application you wouldn't throw the exception. You would,
    // for example, redirect to the showAction with a flash message informing
    // the user that the payment was not successful.
}

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


}

我的 config.yml(这只是沙盒帐户的参数)

jms_payment_paypal:
    username: <USERNAME> # not your account username
    password: <PASSWORD> # not your account password
    signature: <SIGNATURE>
    debug: true
    return_url: https://yourdomain.com
    cancel_url: https://yourdomain.com

我的路由文件

app_orders_new:
    path:     /orders/new/{amount}
    defaults: { _controller: "PlatformBundle:Orders:new" }


app_orders_show:
    path:     /orders/{id}/show
    defaults: { _controller: "PlatformBundle:Orders:show" }

app_orders_paymentcreate:
    path:     /orders/{id}/payment/create
    defaults: { _controller: "PlatformBundle:Orders:paymentCreate" }

app_orders_paymentcomplete:
    path:     /orders/{id}/payment/complete
    defaults: { _controller: "PlatformBundle:Orders:paymentComplete" }

最后一个文件,实体订单:

<?php

namespace Wolk\PlatformBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use JMS\Payment\CoreBundle\Entity\PaymentInstruction;

/**
 * @ORM\Table(name="orders")
 * @ORM\Entity
 */
class Order
{
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /** @ORM\OneToOne(targetEntity="JMS\Payment\CoreBundle\Entity\PaymentInstruction") */
    private $paymentInstruction;

    /** @ORM\Column(type="decimal", precision=10, scale=5) */
    private $amount;

    public function __construct($amount)
    {
        $this->amount = $amount;
    }

    public function getId()
    {
        return $this->id;
    }

    public function getAmount()
    {
        return $this->amount;
    }

    public function getPaymentInstruction()
    {
        return $this->paymentInstruction;
    }

    public function setPaymentInstruction(PaymentInstruction $instruction)
    {
        $this->paymentInstruction = $instruction;
    }
}

我尝试在谷歌上搜索所有内容,但我没有找到任何东西 x/

感谢您的帮助:)

【问题讨论】:

    标签: php symfony paypal


    【解决方案1】:

    我有同样的错误,我花了很多时间寻找解决方案。原来我忘了添加这些行:

    use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
    use JMS\Payment\CoreBundle\Plugin\Exception\Action\VisitUrl;
    use JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException;
    

    我把这个贴在这里,也许它可以帮助其他人。

    【讨论】:

      猜你喜欢
      • 2015-04-22
      • 2017-01-13
      • 2016-04-02
      • 2012-08-05
      • 2015-02-26
      • 2015-04-15
      • 2014-06-08
      • 2016-07-27
      • 2012-07-04
      相关资源
      最近更新 更多