/**
* Redirect to allPay
*/
public function receipt_page($order_id)
{
# Clean the cart
global $woocommerce;
$woocommerce->cart->empty_cart();
$order = new WC_Order($order_id);
try {
$this->invoke_allpay_module();
$aio = new AllInOne();
$aio->Send['MerchantTradeNo'] = '';
$service_url = '';
if ($this->allpay_test_mode == 'yes') {
$service_url = 'http://payment-stage.allpay.com.tw/Cashier/AioCheckOut';
$aio->Send['MerchantTradeNo'] = date('YmdHis');
} else {
$service_url = 'https://payment.allpay.com.tw/Cashier/AioCheckOut';
}
$aio->MerchantID = $this->allpay_merchant_id;
$aio->HashKey = $this->allpay_hash_key;
$aio->HashIV = $this->allpay_hash_iv;
$aio->ServiceURL = $service_url;
$aio->Send['ReturnURL'] = add_query_arg('wc-api', 'WC_Gateway_Allpay', home_url('/'));
$aio->Send['ClientBackURL'] = home_url('?page_id=' . get_option('woocommerce_myaccount_page_id') . '&view-order=' . $order->id);
$aio->Send['MerchantTradeNo'] .= $order->id;
$aio->Send['MerchantTradeDate'] = date('Y/m/d H:i:s');
# Set the product info
$aio->Send['TotalAmount'] = $order->get_total();
array_push($aio->Send['Items'], array('Name' => '網路商品一批', 'Price' => $aio->Send['TotalAmount'], 'Currency' => $order->get_order_currency(), 'Quantity' => 1));
$aio->Send['TradeDesc'] = 'allPay_module_woocommerce_1_0_3';
# Get the chosen payment and installment
$notes = $order->get_customer_order_notes();
$choose_payment = '';
$choose_installment = '';
if (isset($notes[0])) {
list($choose_payment, $choose_installment) = explode('_', $notes[0]->comment_content);
}
$aio->Send['ChoosePayment'] = $choose_payment;
# Set the extend information
switch ($aio->Send['ChoosePayment']) {
case 'Credit':
# Do not support UnionPay
$aio->SendExtend['UnionPay'] = false;
# Credit installment parameters
if (!empty($choose_installment)) {
$aio->SendExtend['CreditInstallment'] = $choose_installment;
$aio->SendExtend['InstallmentAmount'] = $aio->Send['TotalAmount'];
$aio->SendExtend['Redeem'] = false;
}
break;
case 'WebATM':
break;
case 'ATM':
$aio->SendExtend['ExpireDate'] = 3;
$aio->SendExtend['PaymentInfoURL'] = $aio->Send['ReturnURL'];
break;
case 'CVS':
case 'BARCODE':
$aio->SendExtend['Desc_1'] = '';
$aio->SendExtend['Desc_2'] = '';
$aio->SendExtend['Desc_3'] = '';
$aio->SendExtend['Desc_4'] = '';
$aio->SendExtend['PaymentInfoURL'] = $aio->Send['ReturnURL'];
break;
case 'Alipay':
$aio->SendExtend['Email'] = $order->billing_email;
$aio->SendExtend['PhoneNo'] = $order->billing_phone;
$aio->SendExtend['UserName'] = $order->billing_first_name . ' ' . $order->billing_last_name;
break;
case 'Tenpay':
$aio->SendExtend['ExpireTime'] = date('Y/m/d H:i:s', strtotime('+3 days'));
break;
case 'TopUpUsed':
break;
default:
throw new Exception($this->tran('Invalid payment method.'));
break;
}
$aio->CheckOut();
exit;
} catch (Exception $e) {
$this->add_error($e->getMessage());
}
}