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

66 views Asked by At

I'm trying to implement JSMPayment and EtsPaymentOgoneBundle without success.

I get the error : "The controller must return a response". I'm agree with that but it's so written in the documentation. So am I something wrong or is it a bug/error in the documentation.

The error may be this but it's so written in doc...

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

Now, if I change this line and return to a twig template, I only get one radio button. Why ?

Any help will very help me because, I'm really lost.

My all controller

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

There are 1 answers

0
Evgeniy Kuzmin On BEST ANSWER

if you use

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

at the controller, then you should add @Template annotation to the controller action

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)

or you should return "render" with a template

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