protected function AutoSubmit() { $oOrder = $this->_getOrder(); $oBilling = $oOrder->getBillingAddress(); $szHtml = ''; if ($oOrder) { try { $oPayment = new AllInOne(); $oPayment->ServiceURL = $this->_getConfigData('test_mode') ? 'http://payment-stage.allpay.com.tw/Cashier/AioCheckOut' : 'https://payment.allpay.com.tw/Cashier/AioCheckOut'; $oPayment->HashKey = $this->_getConfigData('hash_key'); $oPayment->HashIV = $this->_getConfigData('hash_iv'); $oPayment->MerchantID = $this->_getConfigData('merchant_id'); $oPayment->Send['ReturnURL'] = Mage::getUrl('alipay/processing/response'); $oPayment->Send['ClientBackURL'] = Mage::getUrl(''); $oPayment->Send['OrderResultURL'] = Mage::getUrl('alipay/processing/result'); $oPayment->Send['MerchantTradeNo'] = ($this->_getConfigData('test_mode') ? $this->_getConfigData('test_order_prefix') : '') . $oOrder->getIncrementId(); $oPayment->Send['MerchantTradeDate'] = date('Y/m/d H:i:s'); $oPayment->Send['TotalAmount'] = (int) $oOrder->getGrandTotal(); $oPayment->Send['TradeDesc'] = "AllPay_Magento_Module"; $oPayment->Send['ChoosePayment'] = PaymentMethod::Alipay; $oPayment->Send['Remark'] = ''; $oPayment->Send['ChooseSubPayment'] = PaymentMethodItem::None; $oPayment->Send['NeedExtraPaidInfo'] = ExtraPaymentInfo::No; $oPayment->Send['DeviceSource'] = DeviceType::PC; array_push($oPayment->Send['Items'], array('Name' => Mage::helper('alipay')->__('Commodity Group'), 'Price' => (int) $oOrder->getGrandTotal(), 'Currency' => Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(), 'Quantity' => 1, 'URL' => '')); $oPayment->SendExtend['Email'] = $oBilling->getEmail(); $oPayment->SendExtend['PhoneNo'] = $oBilling->getTelephone(); $oPayment->SendExtend['UserName'] = $oBilling->getName(); $szHtml = $oPayment->CheckOutString(); } catch (Exception $e) { Mage::throwException($e->getMessage()); } } return $szHtml; }
/** * @method hikashop 原生功能: 訂單確認後觸發 * @param object $order 訂單資訊 * @param array $methods 方法資訊 * @param int $method_id 方法 ID * @return boolean 執行結果 */ public function onAfterOrderConfirm(&$order, &$methods, $method_id) { if (!class_exists('AllInOne')) { require_once 'AllPay.Payment.Integration.php'; } try { # 設定服務參數 $aio = new AllInOne(); $allpay_param = $methods[$order->order_payment_id]->payment_params; $order_info = isset($order->cart) ? $order->cart : $order; if ($allpay_param->allpay_test_mode) { $service_url = 'http://payment-stage.allpay.com.tw/Cashier/AioCheckOut'; $merchant_trade_no = date('is') . $order_info->order_number; } else { $service_url = 'https://payment.allpay.com.tw/Cashier/AioCheckOut'; $merchant_trade_no = $order_info->order_number; } $aio->MerchantID = $allpay_param->allpay_merchant_id; $aio->HashKey = $allpay_param->allpay_hash_key; $aio->HashIV = $allpay_param->allpay_hash_iv; $aio->ServiceURL = $service_url; unset($allpay_param); # 設定基本參數 $aio->Send['ReturnURL'] = JURI::root() . 'plugins/hikashoppayment/allpay/response.php'; $aio->Send['ClientBackURL'] = JURI::root() . 'index.php/hikashop-menu-for-products-listing/order'; $aio->Send['MerchantTradeNo'] = $merchant_trade_no; $aio->Send['MerchantTradeDate'] = date('Y/m/d H:i:s'); # 設定訂單商品資訊 $order_total = round($order_info->full_total->prices[0]->price_value_with_tax, 0); $aio->Send['TotalAmount'] = $order_total; array_push($aio->Send['Items'], array('Name' => '網路商品一批', 'Price' => $order_total, 'Currency' => 'NTD', 'Quantity' => 1)); unset($order_info); $aio->Send['TradeDesc'] = 'Hikashop_Payment_Plugin_AllPay'; # 產生訂單 HTML Code $szHtml = $aio->CheckOutString(null); unset($aio); echo $szHtml; unset($szHtml); } catch (Exception $e) { JFactory::getApplication()->enqueueMessage('付款失敗<br />' . $e->getMessage(), 'error'); return false; } return true; }
$payment_config = array(); if (!empty($split_colon_quote)) { # 取得「";」之前的內容設定屬性名稱跟屬性值 for ($i = 1; $i < count($split_colon_quote) - 1; $i += 2) { $payment_config[strstr($split_colon_quote[$i], '";', true)] = strstr($split_colon_quote[$i + 1], '";', true); } 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'];
/** * 構造函數 * * @access public * @param * * @return void */ function __construct() { parent::__construct(); $this->ecshop_allpay_card(); }
/** * 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'); } }
/** * 構造函數 * * @access public * @param * * @return void */ function __construct() { parent::__construct(); $this->ecshop_ecpay_barcode(); }
/** * 構造函數 * * @access public * @param * * @return void */ function __construct() { parent::__construct(); $this->ecshop_ecpay_card12(); }
/** * 構造函數 * * @access public * @param * * @return void */ function __construct() { parent::__construct(); $this->ecshop_ecpay_webatm(); }
public function Refund(Varien_Object $payment, $amount) { try { $oPayment = new AllInOne(); $oPayment->ServiceURL = $this->_getConfigData('test_mode') ? 'http://payment-stage.allpay.com.tw/CreditDetail/DoAction' : 'https://payment.allpay.com.tw/CreditDetail/DoAction'; $oPayment->HashKey = $this->_getConfigData('hash_key'); $oPayment->HashIV = $this->_getConfigData('hash_iv'); $oPayment->MerchantID = $this->_getConfigData('merchant_id'); $oPayment->Action['MerchantTradeNo'] = ($this->_getConfigData('test_mode') ? $this->_getConfigData('test_order_prefix') : '') . $this->_getOrder()->getRealOrderId(); $oPayment->Action['TradeNo'] = $payment->getLastTransId(); $oPayment->Action['Action'] = ActionType::R; $oPayment->Action['TotalAmount'] = (int) $amount; $arFeedback = $oPayment->DoAction(); } catch (Exception $e) { Mage::throwException($e->getMessage()); } return $this; }
<?php /** * WebATM產生訂單範例,參數說明請參考SDK技術文件(https://www.allpay.com.tw/Content/files/allpay_047.pdf) */ //載入SDK(路徑可依系統規劃自行調整) include 'AllPay.Payment.Integration.php'; try { $obj = new AllInOne(); //服務參數 $obj->ServiceURL = "https://payment-stage.allpay.com.tw/Cashier/AioCheckOut/V2"; //服務位置 $obj->HashKey = '5294y06JbISpM5x9'; //測試用Hashkey,請自行帶入AllPay提供的HashKey $obj->HashIV = 'v77hoKGq4kWxNNIS'; //測試用HashIV,請自行帶入AllPay提供的HashIV $obj->MerchantID = '2000132'; //測試用MerchantID,請自行帶入AllPay提供的MerchantID //基本參數(請依系統規劃自行調整) $MerchantTradeNo = "Test" . time(); $obj->Send['ReturnURL'] = "http://www.allpay.com.tw/receive.php"; //付款完成通知回傳的網址 $obj->Send['MerchantTradeNo'] = $MerchantTradeNo; //訂單編號 $obj->Send['MerchantTradeDate'] = date('Y/m/d H:i:s'); //交易時間 $obj->Send['TotalAmount'] = 2000; //交易金額 $obj->Send['TradeDesc'] = "good to drink"; //交易描述 $obj->Send['ChoosePayment'] = PaymentMethod::WebATM;
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; }
/** * 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 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(); } }
<?php /** * TenPay財付通產生訂單範例,參數說明請參考SDK技術文件(https://www.allpay.com.tw/Content/files/allpay_047.pdf) */ //載入SDK(路徑可依系統規劃自行調整) include 'AllPay.Payment.Integration.php'; try { $obj = new AllInOne(); //服務參數 $obj->ServiceURL = "https://payment-stage.allpay.com.tw/Cashier/AioCheckOut/V2"; //服務位置 $obj->HashKey = '5294y06JbISpM5x9'; //測試用Hashkey,請自行帶入AllPay提供的HashKey $obj->HashIV = 'v77hoKGq4kWxNNIS'; //測試用HashIV,請自行帶入AllPay提供的HashIV $obj->MerchantID = '2000132'; //測試用MerchantID,請自行帶入AllPay提供的MerchantID //基本參數(請依系統規劃自行調整) $obj->Send['ReturnURL'] = "http://www.allpay.com.tw/receive.php"; //付款完成通知回傳的網址 $obj->Send['MerchantTradeNo'] = "Test" . time(); //訂單編號 $obj->Send['MerchantTradeDate'] = date('Y/m/d H:i:s'); //交易時間 $obj->Send['TotalAmount'] = 2000; //交易金額 $obj->Send['TradeDesc'] = "good to drink"; //交易描述 $obj->Send['ChoosePayment'] = PaymentMethod::Tenpay; //付款方式:Tenpay財付通