/**
  * 將訂單送交給歐付寶處理(新開視窗)
  * 
  * @Route("/payment/allpay", name="front_payment_passAllpay", options={"expose"=true})
  * @Method("POST")
  */
 public function passAllPayAction(Request $request)
 {
     if (!$this->get('security.csrf.token_manager')->isCsrfTokenValid('invoice', $request->request->get('avenue_token'))) {
         throw new AccessDeniedHttpException('Invalid CSRF token.');
     }
     $paymentHelper = new PaymentHelper();
     /**
      * Entity Manager
      */
     $em = $this->getDoctrine()->getManager();
     /**
      * Session
      * 
      * @var Session
      */
     $session = $this->get('session');
     /**
      * 訂單總金額
      * 
      * @var integer
      */
     $price = 0;
     /**
      * Items to AllPay
      * 
      * @var array
      */
     $items = array();
     /**
      * 客戶index
      * 
      * @var integer
      */
     $customId = $paymentHelper->getCustomIdFromSession($session);
     $invoiceId = $request->request->get('id');
     /**
      * Custom
      * 
      * @var \Woojin\OrderBundle\Entity\Custom
      */
     if (!($custom = $paymentHelper->getValidCustom($em, $request, $customId))) {
         return $this->redirect($this->get('router')->generate('front_payment_checkout'));
     }
     /**
      * Invoice
      * 
      * @var \Woojin\OrderBundle\Entity\Invoice
      */
     $invoice = $paymentHelper->getValidInvoice($em, $invoiceId, $customId);
     $invoice->shiftSn();
     $em->persist($invoice);
     $em->flush();
     $logger = $this->get('logger.custom');
     $logger->write($invoice->getCustom(), array('entity' => 'invoice', 'id' => $invoice->getId(), 'method' => 'cancel', 'url' => 'front_invoice_cancel'));
     // 建立發送給歐付寶的資訊封包( items & price passby reference )
     $paymentHelper->setBenefitHelper($this->get('helper.benefit'));
     $paymentHelper->buildAllPayInfo($invoice, $items, $price);
     $adapter = new Adapter();
     $adapter->init($this->container->getParameter('allpay_hashkey'), $this->container->getParameter('allpay_hashiv'), $this->container->getParameter('allpay_merchantid'), true);
     if ($invoice->getCreditInstallment() > 0) {
         $adapter->allInOne->Send['ChoosePayment'] = 'Credit';
         $adapter->allInOne->SendExtend['CreditInstallment'] = $invoice->getCreditInstallment();
     }
     // 發送通知信, 請大家注意該單後續有無結帳
     $notifier = $this->get('avenue.notifier');
     $notifier->noticeOrder($invoice);
     return new Response($adapter->pay(array('ReturnURL' => $this->get('router')->generate('front_que_return', array(), true), 'ClientBackURL' => $this->get('router')->generate('front_profile_orders', array(), true), 'IgnorePayment' => 'CVS#BARCODE', 'Items' => $items, 'TotalAmount' => (int) $price, 'MerchantTradeNo' => $invoice->getSn(), 'MerchantTradeDate' => date('Y/m/d H:i:s'), 'TradeDesc' => '描述')));
 }