/**
  * Returns the price per period for a subscription in an order.
  * 
  * There must be only one subscription in an order for this to be accurate. 
  * 
  * @param $order mixed A WC_Order object or the ID of the order which the subscription was purchased in.
  * @param $product_id int (optional) The post ID of the subscription WC_Product object purchased in the order. Defaults to the ID of the first product purchased in the order.
  * @since 1.0
  */
 public static function get_price_per_period($order, $product_id = '')
 {
     if (!is_object($order)) {
         $order = new WC_Order($order);
     }
     return $order->get_order_total();
 }
 /**
  * Process the payment and return the result
  **/
 function process_payment($order_id)
 {
     global $woocommerce;
     require_once CI_WC_PATH . "/lib/alipay.config.php";
     require_once CI_WC_PATH . "/lib/alipay_service.class.php";
     $order = new WC_Order($order_id);
     if (sizeof($order->get_items()) > 0) {
         foreach ($order->get_items() as $item) {
             if ($item['qty']) {
                 $item_names[] = $item['name'] . ' x ' . $item['qty'];
             }
         }
     }
     //////////////////////////////////////
     /**************************请求参数**************************/
     //必填参数//
     $out_trade_no = 'CIP' . $order_id;
     //请与贵网站订单系统中的唯一订单号匹配
     $subject = implode(',', $item_names);
     //订单名称,显示在支付宝收银台里的“商品名称”里,显示在支付宝的交易管理的“商品名称”的列表里。
     $body = implode(',', $item_names);
     //订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述”里
     $price = number_format($order->get_order_total() - $order->get_total_discount(), 2, '.', '');
     //订单总金额,显示在支付宝收银台里的“应付总额”里
     $logistics_fee = "0.00";
     //物流费用,即运费。
     $logistics_type = "EXPRESS";
     //物流类型,三个值可选:EXPRESS(快递)、POST(平邮)、EMS(EMS)
     $logistics_payment = "SELLER_PAY";
     //物流支付方式,两个值可选:SELLER_PAY(卖家承担运费)、BUYER_PAY(买家承担运费)
     $quantity = "1";
     //商品数量,建议默认为1,不改变值,把一次交易看成是一次下订单而非购买一件商品。
     $receive_name = "";
     //收货人姓名,如:张三
     $receive_address = "";
     //收货人地址,如:XX省XXX市XXX区XXX路XXX小区XXX栋XXX单元XXX号
     $receive_zip = "";
     //收货人邮编,如:123456
     $receive_phone = "";
     //收货人电话号码,如:0571-81234567
     $receive_mobile = "";
     //收货人手机号码,如:13312341234
     //网站商品的展示地址,不允许加?id=123这类自定义参数
     $show_url = get_bloginfo('url');
     /************************************************************/
     //构造要请求的参数数组
     $parameter = array("service" => "trade_create_by_buyer", "payment_type" => "1", "partner" => trim($aliapy_config['partner']), "_input_charset" => trim(strtolower($aliapy_config['input_charset'])), "seller_email" => trim($aliapy_config['seller_email']), "return_url" => trim($aliapy_config['return_url']), "notify_url" => trim($aliapy_config['notify_url']), "out_trade_no" => $out_trade_no, "subject" => $subject, "body" => $body, "price" => $price, "quantity" => $quantity, "logistics_fee" => $logistics_fee, "logistics_type" => $logistics_type, "logistics_payment" => $logistics_payment, "receive_name" => $receive_name, "receive_address" => $receive_address, "receive_zip" => $receive_zip, "receive_phone" => $receive_phone, "receive_mobile" => $receive_mobile, "show_url" => $show_url);
     //构造标准双接口
     $alipayService = new AlipayService($aliapy_config);
     $html_text = $alipayService->trade_create_by_buyer($parameter);
     //param end
     $output = "\r\n\t\t\t<html>\r\n\t\t    <head>\r\n\t\t\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n\t\t        <title>正在前往支付宝...</title>\r\n\t\t    </head>\r\n\t\t    <body><div  style='display:none'>{$html_text}</div>'</body></html>";
     echo $output;
     exit;
     return array('result' => 'success', 'redirect' => $output);
 }
 /**
  * Process the payment and return the result
  *
  * @access public
  * @param int $order_id
  * @return array
  */
 public function process_payment($order_id)
 {
     global $woocommerce;
     $this->init_mijireh();
     $mj_order = new Mijireh_Order();
     $wc_order = new WC_Order($order_id);
     // add items to order
     $items = $wc_order->get_items();
     foreach ($items as $item) {
         $product = $wc_order->get_product_from_item($item);
         $mj_order->add_item($item['name'], $wc_order->get_item_subtotal($item), $item['qty'], $product->get_sku());
     }
     // add billing address to order
     $billing = new Mijireh_Address();
     $billing->first_name = $wc_order->billing_first_name;
     $billing->last_name = $wc_order->billing_last_name;
     $billing->street = $wc_order->billing_address_1;
     $billing->apt_suite = $wc_order->billing_address_2;
     $billing->city = $wc_order->billing_city;
     $billing->state_province = $wc_order->billing_state;
     $billing->zip_code = $wc_order->billing_postcode;
     $billing->country = $wc_order->billing_country;
     $billing->company = $wc_order->billing_company;
     $billing->phone = $wc_order->billing_phone;
     if ($billing->validate()) {
         $mj_order->set_billing_address($billing);
     }
     // add shipping address to order
     $shipping = new Mijireh_Address();
     $shipping->first_name = $wc_order->shipping_first_name;
     $shipping->last_name = $wc_order->shipping_last_name;
     $shipping->street = $wc_order->shipping_address_1;
     $shipping->apt_suite = $wc_order->shipping_address_2;
     $shipping->city = $wc_order->shipping_city;
     $shipping->state_province = $wc_order->shipping_state;
     $shipping->zip_code = $wc_order->shipping_postcode;
     $shipping->country = $wc_order->shipping_country;
     $shipping->company = $wc_order->shipping_company;
     if ($shipping->validate()) {
         $mj_order->set_shipping_address($shipping);
     }
     // set order name
     $mj_order->first_name = $wc_order->billing_first_name;
     $mj_order->last_name = $wc_order->billing_last_name;
     $mj_order->email = $wc_order->billing_email;
     // set order totals
     $mj_order->total = $wc_order->get_order_total();
     $mj_order->tax = $wc_order->get_total_tax();
     $mj_order->discount = $wc_order->get_total_discount();
     $mj_order->shipping = $wc_order->get_shipping();
     // add meta data to identify woocommerce order
     $mj_order->add_meta_data('wc_order_id', $order_id);
     // Set URL for mijireh payment notificatoin - use WC API
     $mj_order->return_url = str_replace('https:', 'http:', add_query_arg('wc-api', 'WC_Mijireh_Checkout', home_url('/')));
     // Identify woocommerce
     $mj_order->partner_id = 'woo';
     try {
         $mj_order->create();
         $result = array('result' => 'success', 'redirect' => $mj_order->checkout_url);
         return $result;
     } catch (Mijireh_Exception $e) {
         $woocommerce->add_error(__('Mijireh error:', 'woocommerce') . $e->getMessage());
     }
 }
 /**
  * Process the payment and return the result
  **/
 function process_payment($order_id)
 {
     global $woocommerce;
     require_once "alipay_config.php";
     require_once "class/alipay_service.php";
     $order = new WC_Order($order_id);
     if (sizeof($order->get_items()) > 0) {
         foreach ($order->get_items() as $item) {
             if ($item['qty']) {
                 $item_names[] = $item['name'] . ' x ' . $item['qty'];
             }
         }
     }
     //扩展功能参数——默认支付方式
     $paymethod = "directPay";
     //默认支付方式,四个值可选:bankPay(网银); cartoon(卡通); directPay(余额); CASH(网点支付)
     $defaultbank = "";
     //扩展功能参数——防钓鱼
     //请慎重选择是否开启防钓鱼功能
     //exter_invoke_ip、anti_phishing_key一旦被使用过,那么它们就会成为必填参数
     //开启防钓鱼功能后,服务器、本机电脑必须支持远程XML解析,请配置好该环境。
     //若要使用防钓鱼功能,请打开class文件夹中alipay_function.php文件,找到该文件最下方的query_timestamp函数,根据注释对该函数进行修改
     //建议使用POST方式请求数据
     $anti_phishing_key = '';
     //防钓鱼时间戳
     $exter_invoke_ip = '';
     //获取客户端的IP地址,建议:编写获取客户端IP地址的程序
     //如:
     //$exter_invoke_ip = '202.1.1.1';
     //$anti_phishing_key = query_timestamp($partner);		//获取防钓鱼时间戳函数
     //扩展功能参数——其他
     $extra_common_param = '';
     //自定义参数,可存放任何内容(除=、&等特殊字符外),不会显示在页面上
     $buyer_email = '';
     //默认买家支付宝账号
     //扩展功能参数——分润(若要使用,请按照注释要求的格式赋值)
     $royalty_type = "";
     //提成类型,该值为固定值:10,不需要修改
     $royalty_parameters = "";
     //提成信息集,与需要结合商户网站自身情况动态获取每笔交易的各分润收款账号、各分润金额、各分润说明。最多只能设置10条
     //各分润金额的总和须小于等于total_fee
     //提成信息集格式为:收款方Email_1^金额1^备注1|收款方Email_2^金额2^备注2
     //如:
     //royalty_type = "10"
     //royalty_parameters	= "111@126.com^0.01^分润备注一|222@126.com^0.01^分润备注二"
     /////////////////////////////////////////////////
     //构造要请求的参数数组,无需改动
     $parameter = array("service" => "create_direct_pay_by_user", "payment_type" => "1", "partner" => $partner, "seller_email" => $seller_email, "return_url" => $return_url, "notify_url" => $notify_url, "_input_charset" => $_input_charset, "show_url" => get_bloginfo('wpurl'), "out_trade_no" => 'CIP' . $order_id, "subject" => implode(',', $item_names), "body" => implode(',', $item_names), "total_fee" => number_format($order->get_order_total() - $order->get_total_discount(), 2, '.', ''), "paymethod" => $paymethod, "defaultbank" => $defaultbank, "anti_phishing_key" => $anti_phishing_key, "exter_invoke_ip" => $exter_invoke_ip, "buyer_email" => $buyer_email, "extra_common_param" => $extra_common_param, "royalty_type" => $royalty_type, "royalty_parameters" => $royalty_parameters);
     //构造请求函数
     $alipay = new alipay_service($parameter, $key, $sign_type);
     $sHtmlText = $alipay->build_form();
     $html = "<html>\r\n\t\t\t<head>\r\n\t\t\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n\t\t\t\t<title>正在前往支付宝...</title>\r\n\t\t\t</head>\r\n\t\t\t<body><div  style='display:none'>{$sHtmlText}</div";
     echo $html;
     exit;
     return array('result' => 'success', 'redirect' => $sHtmlText);
 }
    /**
     * Process the payment and return the result
     **/
    function process_payment($order_id)
    {
        global $woocommerce;
        require_once "classes/RequestHandler.class.php";
        $order = new WC_Order($order_id);
        if (sizeof($order->get_items()) > 0) {
            foreach ($order->get_items() as $item) {
                if ($item['qty']) {
                    $item_names[] = $item['name'] . ' x ' . $item['qty'];
                }
            }
        }
        //////////////////////////////
        /* 商户号 */
        $partner = $this->tenpayUid;
        /* 密钥 */
        $key = $this->tenpayKey;
        //订单号,此处用时间加随机数生成,商户根据自己情况调整,只要保持全局唯一就行
        $out_trade_no = 'CIP' . $order_id;
        /* 创建支付请求对象 */
        $reqHandler = new RequestHandler();
        $reqHandler->init();
        $reqHandler->setKey($key);
        $reqHandler->setGateUrl("https://gw.tenpay.com/gateway/pay.htm");
        //----------------------------------------
        //设置支付参数
        //----------------------------------------
        $reqHandler->setParameter("partner", $partner);
        $reqHandler->setParameter("out_trade_no", $out_trade_no);
        $reqHandler->setParameter("total_fee", ($order->get_order_total() - $order->get_total_discount()) * 100);
        //总金额
        $reqHandler->setParameter("return_url", CI_WC_ALI_PATH . "/payReturnUrl.php");
        $reqHandler->setParameter("notify_url", CI_WC_ALI_PATH . "/payNotifyUrl.php");
        $reqHandler->setParameter("body", implode(',', $item_names));
        $reqHandler->setParameter("bank_type", "DEFAULT");
        //银行类型,默认为财付通
        //用户ip
        $reqHandler->setParameter("spbill_create_ip", $_SERVER['REMOTE_ADDR']);
        //客户端IP
        $reqHandler->setParameter("fee_type", "1");
        //币种
        $reqHandler->setParameter("subject", '');
        //商品名称,(中介交易时必填)
        //系统可选参数
        $reqHandler->setParameter("sign_type", "MD5");
        //签名方式,默认为MD5,可选RSA
        $reqHandler->setParameter("service_version", "1.0");
        //接口版本号
        $reqHandler->setParameter("input_charset", "UTF-8");
        //字符集
        $reqHandler->setParameter("sign_key_index", "1");
        //密钥序号
        //业务可选参数
        $reqHandler->setParameter("attach", "");
        //附件数据,原样返回就可以了
        $reqHandler->setParameter("product_fee", "");
        //商品费用
        $reqHandler->setParameter("transport_fee", "0");
        //物流费用
        $reqHandler->setParameter("time_start", date("YmdHis"));
        //订单生成时间
        $reqHandler->setParameter("time_expire", "");
        //订单失效时间
        $reqHandler->setParameter("buyer_id", "");
        //买方财付通帐号
        $reqHandler->setParameter("goods_tag", "");
        //商品标记
        $reqHandler->setParameter("trade_mode", "1");
        //交易模式(1.即时到帐模式,2.中介担保模式,3.后台选择(卖家进入支付中心列表选择))
        $reqHandler->setParameter("transport_desc", "");
        //物流说明
        $reqHandler->setParameter("trans_type", "1");
        //交易类型
        $reqHandler->setParameter("agentid", "");
        //平台ID
        $reqHandler->setParameter("agent_type", "");
        //代理模式(0.无代理,1.表示卡易售模式,2.表示网店模式)
        $reqHandler->setParameter("seller_id", "");
        //卖家的商户号
        $reqUrl = $reqHandler->getRequestURL();
        $html_text = '
	<script>window.location.href="' . $reqUrl . '"</script>';
        //param end
        $output = "\r\n\t\t\t<html>\r\n\t\t    <head>\r\n\t\t\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n\t\t        <title>正在前往财付通...</title>\r\n\t\t    </head>\r\n\t\t    <body>{$html_text}</body></html>";
        echo $output;
        exit;
        return array('result' => 'success', 'redirect' => $output);
    }
 /**
  * Successful Payment!
  **/
 function successful_request($posted)
 {
     // Custom holds post ID
     if (!empty($posted['custom']) && !empty($posted['invoice'])) {
         $order = new WC_Order((int) $posted['custom']);
         if ($order->order_key !== $posted['invoice']) {
             if ($this->debug == 'yes') {
                 $this->log->add('paypal', 'Error: Order Key does not match invoice.');
             }
             exit;
         }
         // Lowercase
         $posted['payment_status'] = strtolower($posted['payment_status']);
         $posted['txn_type'] = strtolower($posted['txn_type']);
         // Sandbox fix
         if ($posted['test_ipn'] == 1 && $posted['payment_status'] == 'pending') {
             $posted['payment_status'] = 'completed';
         }
         if ($this->debug == 'yes') {
             $this->log->add('paypal', 'Payment status: ' . $posted['payment_status']);
         }
         // We are here so lets check status and do actions
         switch ($posted['payment_status']) {
             case 'completed':
                 // Check order not already completed
                 if ($order->status == 'completed') {
                     if ($this->debug == 'yes') {
                         $this->log->add('paypal', 'Aborting, Order #' . $posted['custom'] . ' is already complete.');
                     }
                     exit;
                 }
                 // Check valid txn_type
                 $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money');
                 if (!in_array($posted['txn_type'], $accepted_types)) {
                     if ($this->debug == 'yes') {
                         $this->log->add('paypal', 'Aborting, Invalid type:' . $posted['txn_type']);
                     }
                 }
                 // Store PP Details
                 update_post_meta((int) $posted['custom'], 'Payer PayPal address', $posted['payer_email']);
                 update_post_meta((int) $posted['custom'], 'Transaction ID', $posted['txn_id']);
                 update_post_meta((int) $posted['custom'], 'Payer first name', $posted['first_name']);
                 update_post_meta((int) $posted['custom'], 'Payer last name', $posted['last_name']);
                 update_post_meta((int) $posted['custom'], 'Payment type', $posted['payment_type']);
                 // Payment completed
                 $order->add_order_note(__('IPN payment completed', 'woocommerce'));
                 $order->payment_complete();
                 if ($this->debug == 'yes') {
                     $this->log->add('paypal', 'Payment complete.');
                 }
                 break;
             case 'denied':
             case 'expired':
             case 'failed':
             case 'voided':
                 // Order failed
                 $order->update_status('failed', sprintf(__('Payment %s via IPN.', 'woocommerce'), strtolower($posted['payment_status'])));
                 break;
             case "refunded":
                 // Only handle full refunds, not partial
                 if ($order->get_order_total() == $posted['mc_gross'] * -1) {
                     // Mark order as refunded
                     $order->update_status('refunded', sprintf(__('Payment %s via IPN.', 'woocommerce'), strtolower($posted['payment_status'])));
                     $message = woocommerce_mail_template(__('Order refunded/reversed', 'woocommerce'), sprintf(__('Order #%s has been marked as refunded - PayPal reason code: %s', 'woocommerce'), $order->id, $posted['reason_code']));
                     // Send the mail
                     woocommerce_mail(get_option('woocommerce_new_order_email_recipient'), sprintf(__('Payment for order #%s refunded/reversed', 'woocommerce'), $order->id), $message);
                 }
                 break;
             case "reversed":
             case "chargeback":
                 // Mark order as refunded
                 $order->update_status('refunded', sprintf(__('Payment %s via IPN.', 'woocommerce'), strtolower($posted['payment_status'])));
                 $message = woocommerce_mail_template(__('Order refunded/reversed', 'woocommerce'), sprintf(__('Order #%s has been marked as refunded - PayPal reason code: %s', 'woocommerce'), $order->id, $posted['reason_code']));
                 // Send the mail
                 woocommerce_mail(get_option('woocommerce_new_order_email_recipient'), sprintf(__('Payment for order #%s refunded/reversed', 'woocommerce'), $order->id), $message);
                 break;
             default:
                 // No action
                 break;
         }
         exit;
     }
 }
Example #7
0
" title="<?php 
        echo esc_attr(strtotime($order->order_date));
        ?>
"><?php 
        echo date_i18n(get_option('date_format'), strtotime($order->order_date));
        ?>
</time>
					</td>
					<td class="order-status">
						<?php 
        echo ucfirst(__($status->name, 'woocommerce'));
        ?>
					</td>
					<td class="order-total">
						<?php 
        echo sprintf('%s / week', $order->get_order_total(), 'woocommerce');
        ?>
					</td>
					<td class="order-actions">
						<?php 
        $actions = array();
        if (in_array($order->status, apply_filters('woocommerce_valid_order_statuses_for_payment', array('pending', 'failed'), $order))) {
            $actions['pay'] = array('url' => $order->get_checkout_payment_url(), 'name' => __('Pay', 'woocommerce'));
        }
        if (in_array($order->status, apply_filters('woocommerce_valid_order_statuses_for_cancel', array('pending', 'failed'), $order))) {
            $actions['cancel'] = array('url' => $order->get_cancel_order_url(), 'name' => __('Cancel', 'woocommerce'));
        }
        $actions['view'] = array('url' => add_query_arg('order', $order->id, get_permalink(woocommerce_get_page_id('view_order'))), 'name' => __('View', 'woocommerce'));
        $actions = apply_filters('woocommerce_my_account_my_orders_actions', $actions, $order);
        foreach ($actions as $key => $action) {
            echo '<a href="' . esc_url($action['url']) . '" class="button ' . sanitize_html_class($key) . '">' . esc_html($action['name']) . '</a>';
    /**
     * Process the payment and return the result
     **/
    function process_payment($order_id)
    {
        global $woocommerce;
        $order = new WC_Order($order_id);
        if (sizeof($order->get_items()) > 0) {
            foreach ($order->get_items() as $item) {
                if ($item['qty']) {
                    $item_names[] = $item['name'] . ' x ' . $item['qty'];
                }
            }
        }
        //
        $v_mid = $this->bankUid;
        // 商户号,这里为测试商户号1001,替换为自己的商户号(老版商户号为4位或5位,新版为8位)即可
        $v_url = CI_WC_ALI_PATH . '/chinabank/receive.php';
        // 请填写返回url,地址应为绝对路径,带有http协议
        $key = $this->bankKey;
        $v_oid = 'CIP' . $order_id;
        $v_amount = number_format($order->get_order_total() - $order->get_total_discount(), 2, '.', '');
        //支付金额
        $v_moneytype = "CNY";
        //币种
        $text = $v_amount . $v_moneytype . $v_oid . $v_mid . $v_url . $key;
        //md5加密拼凑串,注意顺序不能变
        $v_md5info = strtoupper(md5($text));
        //md5函数加密并转化成大写字母
        $remark1 = '';
        //备注字段1
        $remark2 = '';
        //备注字段2
        $v_rcvname = '';
        // 收货人
        $v_rcvaddr = '';
        // 收货地址
        $v_rcvtel = '';
        // 收货人电话
        $v_rcvpost = '';
        // 收货人邮编
        $v_rcvemail = '';
        // 收货人邮件
        $v_rcvmobile = '';
        // 收货人手机号
        $v_ordername = '';
        // 订货人姓名
        $v_orderaddr = '';
        // 订货人地址
        $v_ordertel = '';
        // 订货人电话
        $v_orderpost = '';
        // 订货人邮编
        $v_orderemail = '';
        // 订货人邮件
        $v_ordermobile = '';
        // 订货人手机号
        $html_text = '
	<form method="post" name="E_FORM" action="https://pay3.chinabank.com.cn/PayGate">
	<input type="hidden" name="v_mid"         value="' . $v_mid . '">
	<input type="hidden" name="v_oid"         value="' . $v_oid . '">
	<input type="hidden" name="v_amount"      value="' . $v_amount . '">
	<input type="hidden" name="v_moneytype"   value="' . $v_moneytype . '">
	<input type="hidden" name="v_url"         value="' . $v_url . '">
	<input type="hidden" name="v_md5info"     value="' . $v_md5info . '">
	<input type="hidden" name="remark1"       value="' . $remark1 . '">
	<input type="hidden" name="remark2"       value="' . $remark2 . '">
	</form>
	<script>document.E_FORM.submit();</script>';
        $output = "\r\n\t\t\t<html>\r\n\t\t    <head>\r\n\t\t\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n\t\t        <title>正在前往网银在线...</title>\r\n\t\t    </head>\r\n\t\t    <body><div  style='display:none'>{$html_text}</div>'</body></html>";
        echo $output;
        exit;
        return array('result' => 'success', 'redirect' => $output);
    }