【问题标题】:jsmPayment etsPaymentOgone gives me an error The controller must return a responsejsmPayment etsPaymentOgone 给我一个错误控制器必须返回响应
【发布时间】:2015-07-30 01:37:24
【问题描述】:

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

我收到错误:“控制器必须返回响应”。我同意这一点,但它在文档中是这么写的。那么我有什么问题还是文档中的错误/错误。

错误可能是这个,但它是这样写在文档中的......

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

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

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

我的所有控制器

/**
 * 
 */
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() { }
}

【问题讨论】:

    标签: symfony payment jmspaymentpaypalbundle


    【解决方案1】:

    如果你使用

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

    在控制器上,那么你应该在控制器动作中添加@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 $this->render('MyAppSomeBundle:Payment:details.html.twig', array( 'form' => $form->createView());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-15
      • 2014-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-04
      相关资源
      最近更新 更多