public function newAction(Request $request)
    {
        $entity = new Plan();
        $form = $this->createForm('EcommerceBundle\Form\PlanType', $entity);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($entity);
            
            $checkoutManager = $this->get('checkout_manager');
            $checkoutManager->createPaypalPlan($entity);
            $checkoutManager->activePaypalPlan($entity);
            
            //if come from popup
            if ($request->isXMLHttpRequest()) {         
                return new JsonResponse(array(
                            'id' => $entity->getId(), 
                            'name' => $entity->getName()
                        ));
            }
            
            $this->get('session')->getFlashBag()->add('success', 'plan.created');

            return $this->redirectToRoute('ecommerce_plan_show', array('id' => $entity->getId()));
        }

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