} unset($i); } unset($split_colon_quote); if (empty($payment_config)) { throw new Exception('Payment Config Error.'); } else { # 取得整合金流 SDK _requireFile('AllInOne', 'AllPay.Payment.Integration.php'); # 設定金流 SDK必要參數 $aio = new AllInOne(); $aio->HashKey = $payment_config['allpay_hash_key']; $aio->HashIV = $payment_config['allpay_hash_iv']; $aio->MerchantID = $payment_config['allpay_merchant_id']; # 取得付款結果 $pay_result = $aio->CheckOutFeedback(); unset($aio); if (count($pay_result) < 1) { throw new Exception('Get Allpay Feedback Failed.'); } else { # 訂單編號檢查, 並設定查詢 SQL $order_table = $table_prefix . 'hikashop_order'; if ($payment_config['allpay_test_mode']) { $order_no = substr($pay_result['MerchantTradeNo'], 4); } else { $order_no = $pay_result['MerchantTradeNo']; } $sql_get_order_info = ''; if (preg_match('/^[A-Z0-9]+$/', $order_no)) { # order_id: 訂單 ID # order_full_price: 訂單金額
/** * AllPay returns POST variables to this action */ public function resultAction() { $isSuccess = FALSE; try { $oSession = $this->_getSession(); $oSession->unsAllpayRealOrderId(); $oSession->setQuoteId($oSession->getAllpayQuoteId(true)); $oSession->setLastSuccessQuoteId($oSession->getAllpaySuccessQuoteId(true)); $oPayment = new AllInOne(); $oPayment->HashKey = $this->_getConfigData('hash_key'); $oPayment->HashIV = $this->_getConfigData('hash_iv'); $oPayment->MerchantID = $this->_getConfigData('merchant_id'); $arFeedback = $oPayment->CheckOutFeedback(); if (sizeof($arFeedback) > 0) { $isSuccess = $this->_processSale($arFeedback); } } catch (Mage_Core_Exception $e) { $this->_getCheckout()->addError($e->getMessage()); } catch (Exception $e) { Mage::logException($e); } if ($isSuccess) { $this->_redirect('checkout/onepage/success'); } else { $this->_redirect('checkout/onepage/failure'); } }
/** * Process the callback */ public function receive_response() { $result_msg = '1|OK'; $order = null; try { # Retrieve the check out result $this->invoke_allpay_module(); $aio = new AllInOne(); $aio->HashKey = $this->allpay_hash_key; $aio->HashIV = $this->allpay_hash_iv; $aio->MerchantID = $this->allpay_merchant_id; $allpay_feedback = $aio->CheckOutFeedback(); unset($aio); if (count($allpay_feedback) < 1) { throw new Exception('Get allPay feedback failed.'); } else { # Get the cart order id $cart_order_id = $allpay_feedback['MerchantTradeNo']; if ($this->allpay_test_mode == 'yes') { $cart_order_id = substr($allpay_feedback['MerchantTradeNo'], 14); } # Get the cart order amount $order = new WC_Order($cart_order_id); $cart_amount = $order->get_total(); # Check the amounts $allpay_amount = $allpay_feedback['TradeAmt']; if (round($cart_amount) != $allpay_amount) { throw new Exception('Order ' . $cart_order_id . ' amount are not identical.'); } else { # Set the common comments $comments = sprintf($this->tran('Payment Method : %s<br />Trade Time : %s<br />'), $allpay_feedback['PaymentType'], $allpay_feedback['TradeDate']); # Set the getting code comments $return_code = $allpay_feedback['RtnCode']; $return_message = $allpay_feedback['RtnMsg']; $get_code_result_comments = sprintf($this->tran('Getting Code Result : (%s)%s'), $return_code, $return_message); # Set the payment result comments $payment_result_comments = sprintf($this->tran('Payment Result : (%s)%s'), $return_code, $return_message); # Set the fail message $fail_message = sprintf('Order %s Exception.(%s: %s)', $cart_order_id, $return_code, $return_message); # Get allPay payment method $allpay_payment_method = $this->get_payment_method($allpay_feedback['PaymentType']); # Set the order comments $paid_succeeded_status = 'completed'; switch ($allpay_payment_method) { case PaymentMethod::Credit: case PaymentMethod::WebATM: case PaymentMethod::Alipay: case PaymentMethod::Tenpay: case PaymentMethod::TopUpUsed: if ($return_code != 1 and $return_code != 800) { throw new Exception($fail_msg); } else { if (!$this->is_order_complete($order)) { $order->update_status($paid_succeeded_status, $payment_result_comments); } else { # The order already paid or not in the standard procedure, do nothing } } break; case PaymentMethod::ATM: if ($return_code != 1 and $return_code != 2 and $return_code != 800) { throw new Exception($fail_msg); } else { if ($return_code == 2) { # Set the getting code result $comments .= $this->get_order_comments($allpay_feedback); $comments .= $get_code_result_comments; $order->add_order_note($comments); } else { if (!$this->is_order_complete($order)) { $order->update_status($paid_succeeded_status, $payment_result_comments); } else { # The order already paid or not in the standard procedure, do nothing } } } break; case PaymentMethod::CVS: case PaymentMethod::BARCODE: if ($return_code != 1 and $return_code != 800 and $return_code != 10100073) { throw new Exception($fail_msg); } else { if ($return_code == 10100073) { # Set the getting code result $comments .= $this->get_order_comments($allpay_feedback); $comments .= $get_code_result_comments; $order->add_order_note($comments); } else { if (!$this->is_order_complete($order)) { $order->update_status($paid_succeeded_status, $payment_result_comments); } else { # The order already paid or not in the standard procedure, do nothing } } } break; default: throw new Exception('Invalid payment method of the order ' . $cart_order_id . '.'); break; } } } } catch (Exception $e) { $error = $e->getMessage(); if (!empty($order)) { $comments .= sprintf($this->tran('Faild To Pay<br />Error : %s<br />'), $error); $order->update_status('failed', $comments); } # Set the failure result $result_msg = '0|' . $error; } echo $result_msg; exit; }
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; }
public function payment_return($id, $token) { $this->load->helper('allpay_payment'); $this->load->model('model_booking'); $booking = $this->model_booking->getBooking($id, $token, null, true); if (empty($booking)) { return show_404(); } $this->load->helper('allpay_payment'); include APPPATH . 'config/allpay_payment.php'; try { $aio = new AllInOne(); $aio->ServiceURL = $allpay_config['ServiceURL']; $aio->HashKey = $allpay_config['HashKey']; $aio->HashIV = $allpay_config['HashIV']; $aio->MerchantID = $allpay_config['MerchantID']; $aio_feedback = $aio->CheckOutFeedback(); if (count($aio_feedback > 1)) { switch ($aio_feedback['RtnCode']) { case 1: case 800: //AIO 付款成功 $this->model_booking->editBooking($id, ['paid' => true]); $message = '付款成功'; break; case 2: //ATM 取號成功 $message = "ATM 取號成功:\n繳款銀行代碼:{$aio_feedback['BankCode']}\n繳款虛擬帳號:{$aio_feedback['vAccount']}\n繳費期限:{$aio_feedback['ExpireDate']}"; break; case 10100073: //CVS/BARCODE 取號成功 switch ($aio_feedback['PaymentType']) { case PaymentMethod::CVS: $message = "超商代碼取號成功:\n超商代碼:{$aio_feedback['PaymentNo']}\n繳費期限:{$aio_feedback['ExpireDate']}"; break; case PaymentMethod::BARCODE: $message = "超商條碼取號成功:\n第一段條碼:{$aio_feedback['Barcode1']}\n第二段條碼:{$aio_feedback['Barcode2']}\n第二段條碼:{$aio_feedback['Barcode2']}\n繳費期限:{$aio_feedback['ExpireDate']}"; break; default: throw new Exception('0|Invalid PaymentType'); break; } break; default: throw new Exception('0|Invalid RtnCode'); break; } $this->model_booking->addPayment(['booking' => $id, 'payment_type' => $aio_feedback['PaymentType'], 'amount' => $aio_feedback['TradeAmt'], 'allpay' => $aio_feedback['TradeNo'], 'payment_at' => strtotime($aio_feedback['PaymentDate']), 'created_at' => strtotime($aio_feedback['TradeDate']), 'message' => $message]); //Sending E-Mail: include APPPATH . 'config/mailgun.php'; $mg = new Mailgun\Mailgun($mailgun_config['appkey']); $mg_result = $mg->sendMessage($mailgun_config['domain'], ['from' => $mailgun_config['sender'], 'to' => "{$booking->name} <{$booking->email}>", 'subject' => '付款狀態更新 | 開源!資訊萌芽營', 'text' => "Hi, {$booking->name}!\n您的報名資料付款狀態已更新,詳情如下:\n{$message}\n\nSOSCET, 東部學生開源社群"]); if ($this->input->get('is_browser')) { redirect("event/review/{$id}/{$token}"); } else { $this->output->set_output('1|OK'); } } else { throw new Exception('Return Value Errors'); } } catch (Exception $e) { return show_404(); } }