/**
  * Builds form given success and fail urls
  *
  * @param $responseRoute
  * @return FormBuilder
  */
 public function buildForm($responseRoute)
 {
     $formBuilder = $this->formFactory->createNamedBuilder(null);
     $orderId = $this->paymentBridge->getOrderId() . '#' . date('Ymdhis');
     $fields = array('usuario' => $this->user, 'gran_total' => $this->paymentBridge->getAmount(), 'referencia' => $this->paymentBridge->getOrderDescription(), 'url_respuesta' => $responseRoute);
     //echo $this->cps;die();
     $formKey = $this->encryptor->encrypt(implode('', $fields));
     $formBuilder->setAction($this->gateway)->setMethod('POST')->add('usuario', 'hidden', array('data' => $this->user))->add('gran_total', 'hidden', array('data' => $this->paymentBridge->getAmount()))->add('referencia_ext', 'hidden', array('data' => $this->paymentBridge->getOrderDescription()))->add('url_respuesta', 'hidden', array('data' => $responseRoute))->add('key', 'hidden', array('data' => $formKey))->add('order_id', 'hidden', array('data' => $orderId))->add('Submit', 'hidden', array('data' => 'Pagar'));
     return $formBuilder;
 }
 /**
  * Payment response
  *
  * @param Request $request Request element
  *
  * @return RedirectResponse
  *
  */
 public function responseAction(Request $request)
 {
     $paymentMethod = new BanwiregatewayMethod();
     $paymentBridge = $this->get('payment.bridge');
     $key = $request->request->get('key');
     $reference = $request->request->get('reference');
     //reference send to banwire in executeAction url_response
     $codeAuth = $request->request->get('code_auth');
     $response = $request->request->get('response');
     $codeError = $request->request->get('code');
     $banwireId = $request->request->get('id');
     $infoLog = array('key' => $key, 'reference' => $reference, 'code_auth' => $codeAuth, 'response' => $response, 'code_error' => $codeError, 'banwire_id' => $banwireId, 'action' => 'BanwireResponseAction');
     $this->get('logger')->addInfo($paymentMethod->getPaymentName(), $infoLog);
     $encrypt = new RC4($this->container->getParameter('banwire_gateway.cps'));
     $trans = $this->getDoctrine()->getRepository('BanwireGatewayBridgeBundle:BanwireGatewayOrderTransaction')->findOneBy(array('reference' => $reference));
     $order = $paymentBridge->findOrder($trans->getOrder()->getId());
     $paymentBridge->setOrder($order);
     $paymentMethod->setBanwireGatewayTransactionId($codeAuth);
     $paymentMethod->setReference($reference);
     $paymentMethod->setCodeError($codeError);
     $paymentMethod->setBanwireId($banwireId);
     $string = implode('', $request->request->all());
     if ($encrypt->encrypt($string) == $key) {
         if ($response == 'ok') {
             if ($paymentBridge->getAmount() - $request->request->get('monto') != 0) {
                 $this->get('payment.event.dispatcher')->notifyPaymentOrderFail($paymentBridge, $paymentMethod);
                 $redirectUrl = $this->container->getParameter('banwire_gateway.fail.route');
                 $redirectFailAppend = $this->container->getParameter('banwire_gateway.fail.order.append');
                 $redirectFailAppendField = $this->container->getParameter('banwire_gateway.fail.order.field');
                 $redirectData = $redirectFailAppend ? array($redirectFailAppendField => $trans->getOrder()->getId()) : array();
             } else {
                 $this->get('payment.event.dispatcher')->notifyPaymentOrderSuccess($paymentBridge, $paymentMethod);
                 $redirectUrl = $this->container->getParameter('banwire_gateway.success.route');
                 $redirectSuccessAppend = $this->container->getParameter('banwire_gateway.success.order.append');
                 $redirectSuccessAppendField = $this->container->getParameter('banwire_gateway.success.order.field');
                 $redirectData = $redirectSuccessAppend ? array($redirectSuccessAppendField => $trans->getOrder()->getId()) : array();
             }
         } else {
             $this->get('payment.event.dispatcher')->notifyPaymentOrderFail($paymentBridge, $paymentMethod);
             $redirectUrl = $this->container->getParameter('banwire_gateway.fail.route');
             $redirectFailAppend = $this->container->getParameter('banwire_gateway.fail.order.append');
             $redirectFailAppendField = $this->container->getParameter('banwire_gateway.fail.order.field');
             $redirectData = $redirectFailAppend ? array($redirectFailAppendField => $trans->getOrder()->getId()) : array();
         }
     } else {
         $this->get('payment.event.dispatcher')->notifyPaymentOrderFail($paymentBridge, $paymentMethod);
         $redirectUrl = $this->container->getParameter('banwire_gateway.fail.route');
         $redirectFailAppend = $this->container->getParameter('banwire_gateway.fail.order.append');
         $redirectFailAppendField = $this->container->getParameter('banwire_gateway.fail.order.field');
         $redirectData = $redirectFailAppend ? array($redirectFailAppendField => $trans->getOrder()->getId()) : array();
     }
     return $this->redirect($this->generateUrl($redirectUrl, $redirectData));
 }