EcommerceBundle/Controller/ContractController.php
public function createAction(Request $request)
    {
        $entity = new Contract();
        $form = $this->createCreateForm($entity);
        $planForm = $this->createForm(new PlanType(), new Plan(), array(
            'action' => $this->generateUrl('ecommerce_plan_new'),
            'method' => 'POST',
        ));
        
        $form->handleRequest($request);

        if ($form->isValid()) {
            
            //check payment method
            $data = $form->getNormData();
            print_r($data);die();
            
            $em = $this->getDoctrine()->getManager();
            
            
            
            $agreement = $entity->getAgreement();
            $agreement->setContract($entity);
            $agreement->setStatus('Created');
            
            
            try {
                $em->persist($entity);
                $em->persist($entity->getAgreement());
                $em->flush();
              
            } catch (\Exception $exc) {
                $this->get('session')->getFlashBag()->add('danger', 'contract.duplicated');
            }
            
           
            
            //paypal workflow
            $checkoutManager = $this->get('checkout_manager');
            //create agreement paypal
            $creditCard = $form->getNormData()->getAgreement()->getCreditCard();
            $cc = array(
                "number" => $creditCard['cardNo'],
                "type" => $creditCard['cardType'],
                "expire_month" => $creditCard['expirationDate']->format('m'),
                "expire_year" =>  $creditCard['expirationDate']->format('Y'),
                "cvv2" =>  $creditCard['CVV'],
                "first_name" => $creditCard['firstname'],
                "last_name" => $creditCard['lastname']
            );  
            $payPalAgreement = $checkoutManager->createPaypalAgreement($entity->getAgreement(), $cc);

            if($entity->getAgreement()->getPaymentMethod() == 'paypal'){
                $this->get('session')->getFlashBag()->add('success', 'contract.created.approval');
                $transactions = $entity->getAgreement()->getTransactions();
                return $this->redirect($this->generateUrl('ecommerce_transaction_show', array('id' => $transactions->last()->getId())));

            }else {
                $this->get('session')->getFlashBag()->add('success', 'contract.created');
            }

            return $this->redirect($this->generateUrl('ecommerce_contract_show', array('id' => $entity->getId())));

        }

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
            'planForm' => $planForm->createView(),
        );
    }
public function createAction(Request $request)
    {
        $entity = new Contract();
        $form = $this->createCreateForm($entity);
        $planForm = $this->createForm(new PlanType(), new Plan(), array(
            'action' => $this->generateUrl('ecommerce_plan_new'),
            'method' => 'POST',
        ));
        
        $form->handleRequest($request);

        if ($form->isValid()) {
            
            //check payment method
            $data = $form->getNormData();
            print_r($data);die();
            
            $em = $this->getDoctrine()->getManager();
            
            
            
            $agreement = $entity->getAgreement();
            $agreement->setContract($entity);
            $agreement->setStatus('Created');
            
            
            try {
                $em->persist($entity);
                $em->persist($entity->getAgreement());
                $em->flush();
              
            } catch (\Exception $exc) {
                $this->get('session')->getFlashBag()->add('danger', 'contract.duplicated');
            }
            
           
            
            //paypal workflow
            $checkoutManager = $this->get('checkout_manager');
            //create agreement paypal
            $creditCard = $form->getNormData()->getAgreement()->getCreditCard();
            $cc = array(
                "number" => $creditCard['cardNo'],
                "type" => $creditCard['cardType'],
                "expire_month" => $creditCard['expirationDate']->format('m'),
                "expire_year" =>  $creditCard['expirationDate']->format('Y'),
                "cvv2" =>  $creditCard['CVV'],
                "first_name" => $creditCard['firstname'],
                "last_name" => $creditCard['lastname']
            );  
            $payPalAgreement = $checkoutManager->createPaypalAgreement($entity->getAgreement(), $cc);

            if($entity->getAgreement()->getPaymentMethod() == 'paypal'){
                $this->get('session')->getFlashBag()->add('success', 'contract.created.approval');
                $transactions = $entity->getAgreement()->getTransactions();
                return $this->redirect($this->generateUrl('ecommerce_transaction_show', array('id' => $transactions->last()->getId())));

            }else {
                $this->get('session')->getFlashBag()->add('success', 'contract.created');
            }

            return $this->redirect($this->generateUrl('ecommerce_contract_show', array('id' => $entity->getId())));

        }

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
            'planForm' => $planForm->createView(),
        );
    }
public function createAction ( Request $ request ) { $ entity = new Contract ( ) ; $ form = $ this -> createCreateForm ( $ entity ) ; $ planForm = $ this -> createForm ( new PlanType ( ) , new Plan ( ) , array ( 'action' => $ this -> generateUrl ( 'ecommerce_plan_new' ) , 'method' => 'POST' , ) ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { //check payment method $ data = $ form -> getNormData ( ) ; print_r ( $ data ) ; die ( ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ agreement = $ entity -> getAgreement ( ) ; $ agreement -> setContract ( $ entity ) ; $ agreement -> setStatus ( 'Created' ) ; try { $ em -> persist ( $ entity ) ; $ em -> persist ( $ entity -> getAgreement ( ) ) ; $ em -> flush ( ) ; } catch ( \ Exception $ exc ) { $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'danger' , 'contract.duplicated' ) ; } //paypal workflow $ checkoutManager = $ this -> get ( 'checkout_manager' ) ; //create agreement paypal $ creditCard = $ form -> getNormData ( ) -> getAgreement ( ) -> getCreditCard ( ) ; $ cc = array ( "number" => $ creditCard [ 'cardNo' ] , "type" => $ creditCard [ 'cardType' ] , "expire_month" => $ creditCard [ 'expirationDate' ] -> format ( 'm' ) , "expire_year" => $ creditCard [ 'expirationDate' ] -> format ( 'Y' ) , "cvv2" => $ creditCard [ 'CVV' ] , "first_name" => $ creditCard [ 'firstname' ] , "last_name" => $ creditCard [ 'lastname' ] ) ; $ payPalAgreement = $ checkoutManager -> createPaypalAgreement ( $ entity -> getAgreement ( ) , $ cc ) ; if ( $ entity -> getAgreement ( ) -> getPaymentMethod ( ) == 'paypal' ) { $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'contract.created.approval' ) ; $ transactions = $ entity -> getAgreement ( ) -> getTransactions ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'ecommerce_transaction_show' , array ( 'id' => $ transactions -> last ( ) -> getId ( ) ) ) ) ; } else { $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'contract.created' ) ; } return $ this -> redirect ( $ this -> generateUrl ( 'ecommerce_contract_show' , array ( 'id' => $ entity -> getId ( ) ) ) ) ; } return array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , 'planForm' => $ planForm -> createView ( ) , ) ; }
Creates a new Contract entity.

@Route("/")
@Method("POST")
@Template("EcommerceBundle:Contract:new.html.twig")
Creates a new Contract entity .