jsmPayment etsPaymentOgone 给我一个错误 The controller must return a response

jsmPayment etsPaymentOgone gives me an error The controller must return a response

我正在尝试实施 JSMPayment 和 EtsPaymentOgoneBundle 但没有成功。

我收到错误:“控制器必须return 响应”。我同意这一点,但文档中是这样写的。那我是不是哪里有问题,还是文档中的bug/error。

可能是这个错误但是文档里是这么写的...

return array(
            'form' => $form->createView()
        );

现在,如果我将此行和 return 更改为一个树枝模板,我只会得到一个单选按钮。为什么?

任何帮助都会对我很有帮助,因为我真的迷路了。

我的全控

/**
 * 
 */
class PaymentController extends Controller
{
    /** @DI\Inject */
    private $request;

    /** @DI\Inject */
    private $router;

    /** @DI\Inject("doctrine.orm.entity_manager") */
    private $em;

    /** @DI\Inject("payment.plugin_controller") */
    private $ppc;

    
    /**
     * 
     * @param \CTC\Bundle\OrderBundle\Controller\Order $order
     * @return RedirectResponse
     */
    public function detailsAction(Order $order, Request $request)
    {
        
        $form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
            'amount'   => $order->getPackage()->getAmount(),
            'currency' => 'EUR',
            'default_method' => 'ogone_gateway', // Optional
            'predefined_data' => array(
                'ogone_gateway' => array(
                    'tp' => '',           // Optional
                    'PM' => $pm,                                            // Optional - Example value: "CreditCard" - Note: You can consult the list of PM values on Ogone documentation
                    'BRAND' => $brand,                                       // Optional - Example value: "VISA" - Note: If you send the BRAND field without sending a value in the PM field (‘CreditCard’ or ‘Purchasing Card’), the BRAND value will not be taken into account.
                    'CN' => $billingAddress->getFullName(),                 // Optional
                    'EMAIL' => $this->getUser()->getEmail(),            // Optional
                    'OWNERZIP' => $billingAddress->getPostalCode(),         // Optional
                    'OWNERADDRESS' => $billingAddress->getStreetLine(),     // Optional
                    'OWNERCTY' => $billingAddress->getCountry()->getName(), // Optional
                    'OWNERTOWN' => $billingAddress->getCity(),              // Optional
                    'OWNERTELNO' => $billingAddress->getPhoneNumber(),      // Optional
                    'lang'      => $request->getLocale(),                   // 5 characters maximum, for e.g: fr_FR
                    'ORDERID'   => '123456',                                // Optional, 30 characters maximum
                ),
            ),
        ));

        if ('POST' === $this->request->getMethod()) {
            $form->bindRequest($this->request);

            if ($form->isValid()) {
                $this->ppc->createPaymentInstruction($instruction = $form->getData());

                $order->setPaymentInstruction($instruction);
                $this->em->persist($order);
                $this->em->flush($order);

                return new RedirectResponse($this->router->generate('payment_complete', array(
                    'orderNumber' => $order->getOrderNumber(),
                )));
            }
        }

        return array(
            'form' => $form->createView()
        );
    }

    /**
     * 
     */
    public function completeAction(Order $order)
    {
        $instruction = $order->getPaymentInstruction();
        if (null === $pendingTransaction = $instruction->getPendingTransaction()) {
            $payment = $this->ppc->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount());
        } else {
            $payment = $pendingTransaction->getPayment();
        }

        $result = $this->ppc->approveAndDeposit($payment->getId(), $payment->getTargetAmount());
        if (Result::STATUS_PENDING === $result->getStatus()) {
            $ex = $result->getPluginException();

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

                if ($action instanceof VisitUrl) {
                    return new RedirectResponse($action->getUrl());
                }

                throw $ex;
            }
        } else if (Result::STATUS_SUCCESS !== $result->getStatus()) {
            throw new \RuntimeException('Transaction was not successful: '.$result->getReasonCode());
        }

        // payment was successful, do something interesting with the order
    }
    
    public function cancelAction(Order $order)
    {
        die('cancel the payment');
    }

    /** @DI\LookupMethod("form.factory") */
    protected function getFormFactory() { }
}

如果您使用

return array(
    'form' => $form->createView()
);

在controller处,那么你应该在controller action中添加@Template注解

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class PaymentController extends Controller
{
 ...   
        /**
         * 
         * @param \CTC\Bundle\OrderBundle\Controller\Order $order
         * @Template()
         * @return RedirectResponse
         */
        public function detailsAction(Order $order, Request $request)

或者您应该 return "render" 使用模板

return $this->render('MyAppSomeBundle:Payment:details.html.twig', array( 'form' => $form->createView());