Example #1
0
 /**
  * 付款完成通知
  * %數請參考 https://www.allpay.com.tw/Business/payment_fees
  * 
  * @Route("/que/return", name="front_que_return", options={"expose"=true})
  */
 public function returnAction(Request $request)
 {
     $adapter = new Adapter();
     $adapter->init($this->container->getParameter('allpay_hashkey'), $this->container->getParameter('allpay_hashiv'), $this->container->getParameter('allpay_merchantid'), true);
     //$adapter->initTest();
     $fp = fopen($request->server->get('DOCUMENT_ROOT') . '/uploads/' . date('Y-m-d H:i:s') . '.txt', 'w');
     fwrite($fp, json_encode($_POST) . "\r\n");
     if (!$adapter->isValid($_POST)) {
         fwrite($fp, "\r\n" . '檢查碼錯誤:' . "\r\n" . $adapter->getCheckVal($_POST) . "\r\n" . $_POST['ChechMacValue']);
         fclose($fp);
         throw new \Exception('valid error');
     }
     fwrite($fp, "\r\n" . '檢查碼正確');
     $post = $request->request;
     if ($post->get('RtnCode') != 1) {
         fwrite($fp, "\r\n" . '狀態碼錯誤');
         fclose($fp);
         return new Response('0|ErrorMessage');
     }
     fwrite($fp, "\r\n" . '狀態碼正確');
     $invoiceSn = $post->get('MerchantTradeNo');
     $em = $this->getDoctrine()->getManager();
     $invoice = $em->getRepository('WoojinOrderBundle:Invoice')->findOneBy(array('sn' => $invoiceSn));
     if (!$invoice) {
         fwrite($fp, "\r\n" . '兄弟我找不到發票');
         fclose($fp);
         return new Response('0|ErrorMessage');
     }
     try {
         $invoice->setTradeNo($post->get('TradeNo'))->setPaymentType($post->get('PaymentType'))->setPayAt(new \DateTime($post->get('PaymentDate')))->setStatus(Avenue::IV_GET);
         foreach ($invoice->getOrders() as $order) {
             $order->setPaid($order->getRequired())->setOrgPaid($order->getOrgRequired())->setStatus($em->getRepository('WoojinOrderBundle:OrdersStatus')->find(Avenue::OS_COMPLETE));
             $em->persist($order);
         }
         $em->persist($invoice);
         $em->flush();
         fwrite($fp, "\r\n" . '應該要成功才對, 這是交易編號' . $invoice->getTradeNo());
         fclose($fp);
     } catch (\Exception $e) {
         fwrite($fp, "\r\n" . $e->getMessage() . $invoice->getTradeNo());
         fclose($fp);
     }
     // 發送通知信給店長處理
     $notifier = $this->get('avenue.notifier');
     $notifier->ship($invoice);
     return new Response('1|OK');
 }
Example #2
0
 /**
  * 將訂單送交給歐付寶處理(新開視窗)
  * 
  * @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' => '描述')));
 }