Exemplo n.º 1
0
 public function response()
 {
     $this->load->model('checkout/order');
     $this->load->model('payment/allpay');
     $this->model_payment_allpay->invokeExt(DIR_CATALOG . 'model/payment/');
     $this->model_payment_allpay->logMsg(LogMsg::RESP_DES);
     $this->model_payment_allpay->logMsg(print_r($_POST, true), true);
     $AIO = null;
     $ACE = null;
     $upd_order_comment = 'Unknown.';
     try {
         $res_msg = '1|OK';
         $merchant_id = $this->config->get('allpay_merchant_id');
         $crt_order_status = $this->config->get('allpay_order_status_id');
         $upd_order_status = $this->config->get('allpay_paid_status_id');
         $AIO = new AllInOne();
         $ACE = new AllpayCartExt($merchant_id);
         # 取得付款結果
         $AIO->MerchantID = $merchant_id;
         $AIO->HashKey = $this->config->get('allpay_hash_key');
         $AIO->HashIV = $this->config->get('allpay_hash_iv');
         $checkout_feedback = $AIO->CheckOutFeedback();
         if (empty($checkout_feedback)) {
             throw new Exception(ErrorMsg::C_FD_EMPTY);
         }
         $rtn_code = $checkout_feedback['RtnCode'];
         $rtn_msg = $checkout_feedback['RtnMsg'];
         $type_pieces = explode('_', $checkout_feedback['PaymentType']);
         $payment_method = $type_pieces[0];
         # 取得購物車訂單明細
         $merchant_trade_no = $checkout_feedback['MerchantTradeNo'];
         $cart_order_id = $ACE->getCartOrderID($merchant_trade_no);
         $order_info = $this->model_checkout_order->getOrder($cart_order_id);
         $cart_order_total = $ACE->roundAmt($order_info['total'], $this->config->get('allpay_round_method'));
         # 反查歐付寶訂單明細
         $AIO->ServiceURL = $ACE->getServiceURL(URLType::QUERY_ORDER);
         $AIO->Query['MerchantTradeNo'] = $merchant_trade_no;
         $query_feedback = $AIO->QueryTradeInfo();
         if (empty($query_feedback)) {
             throw new Exception(ErrorMsg::Q_FD_EMPTY);
         }
         $trade_status = $query_feedback['TradeStatus'];
         # 金額檢查
         $ACE->validAmount($cart_order_total, $checkout_feedback['TradeAmt'], $query_feedback['TradeAmt']);
         # 付款方式檢查
         $query_payment = $ACE->parsePayment($query_feedback['PaymentType']);
         $ACE->validPayment($payment_method, $query_payment);
         # 訂單狀態檢查
         $ACE->validStatus($crt_order_status, $order_info['order_status_id']);
         # 取得訂單備註
         $comment_tpl = $ACE->getCommentTpl($payment_method, $trade_status, $rtn_code);
         $upd_order_comment = $ACE->getComment($payment_method, $comment_tpl, $checkout_feedback);
     } catch (Exception $e) {
         $exception_msg = $e->getMessage();
         $res_msg = '0|' . $exception_msg;
         if (!empty($ACE)) {
             $upd_order_comment = $ACE->getFailComment($exception_msg);
         }
         $upd_order_status = $this->config->get('allpay_unpaid_status_id');
     }
     # 更新訂單,並通知客戶
     $this->model_checkout_order->update($cart_order_id, $upd_order_status, $upd_order_comment, true);
     $this->model_payment_allpay->logMsg($res_msg, true);
     # 印出回應訊息
     echo $res_msg;
     exit;
 }