/**
  * Get the total amount with or without refunds
  * @return string
  */
 public function get_total()
 {
     $total = '';
     if ($this->order->get_total_refunded() > 0) {
         $total_after_refund = $this->order->get_total() - $this->order->get_total_refunded();
         $total = '<del class="total-without-refund">' . strip_tags($this->order->get_formatted_order_total()) . '</del> <ins>' . wc_price($total_after_refund, array('currency' => $this->order->get_order_currency())) . '</ins>';
     } else {
         $total = $this->order->get_formatted_order_total();
     }
     return $total;
 }
    /**
     * Output the order tracking code for enabled networks
     *
     * @param int $order_id
     *
     * @return string
     */
    public function output_order_tracking_code($order_id)
    {
        $order = new WC_Order($order_id);
        $code = "<script>fbq('track', 'Purchase', {value: '" . esc_js($order->get_total()) . "', currency: '" . esc_js($order->get_order_currency()) . "'});</script>";
        $code .= '<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=' . esc_js($this->facebook_id) . '&ev=Purchase&amp;cd[value]=' . urlencode($order->get_total()) . '&amp;cd[currency]=' . urlencode($order->get_order_currency()) . '&noscript=1"
/></noscript>';
        echo $code;
    }
 /**
  * Track custom user properties via the Mixpanel API
  *
  * This example illustrates how to add/update the "Last Subscription Billing Amount"
  * user property when a subscription is renewed.
  *
  * @param \WC_Order  $renewal_order
  * @param \WC_Order  $original_order
  * @param int        $product_id the
  * @param \WC_Order  $new_order_role
  */
 function sv_wc_mixpanel_renewed_subscription($renewal_order, $original_order, $product_id, $new_order_role)
 {
     if (!function_exists('wc_mixpanel')) {
         return;
     }
     $properties = array('Last Subscription Billing Amount' => $renewal_order->get_total());
     wc_mixpanel()->get_integration()->custom_user_properties_api($properties, $renewal_order->user_id);
 }
 public function payfort_payment_fields($order_id)
 {
     $order = new WC_Order($order_id);
     $argsArr = ['PSPID' => $this->payfort_production_mode ? $this->payfort_production_pspid : $this->payfort_test_pspid, 'AMOUNT' => $order->get_total() * 100, 'ORDERID' => $order->id, 'CURRENCY' => 'EGP', 'LANGUAGE' => 'en_US', 'CN' => $order->billing_first_name . ' ' . $order->billing_last_name, 'EMAIL' => $order->billing_email, 'OWNERZIP' => $order->billing_postcode, 'OWNERADDRESS' => $order->billing_address_1 . ',' . $order->billing_address_2, 'OWNERCTY' => $order->billing_country, 'OWNERTOWN' => $order->billing_city, 'OWNERTELNO' => $order->billing_phone, 'HOMEURL' => home_url(), 'TITLE' => $this->title, 'BGCOLOR' => $this->payfort_payment_page_bg_color, 'TXTCOLOR' => $this->payfort_payment_page_text_color, 'TBLBGCOLOR' => $this->payfort_payment_page_table_bg_color, 'TBLTXTCOLOR' => $this->payfort_payment_page_table_text_color, 'BUTTONBGCOLOR' => $this->payfort_payment_page_btn_bg_color, 'BUTTONTXTCOLOR' => $this->payfort_payment_page_btn_text_color, 'ACCEPTURL' => $this->payfort_accept_url, 'DECLINEURL' => $this->payfort_accept_url, 'EXCEPTIONURL' => $this->payfort_accept_url, 'CANCELURL' => $this->payfort_accept_url];
     if (isset($this->payment_page_logo) && !empty($this->payfort_payment_page_logo)) {
         $argsArr['LOGO'] = $this->payfort_payment_page_logo;
     }
     return $argsArr;
 }
Пример #5
0
 /**
  * Returns the order total, in order currency.
  *
  * @since WooCommerce 2.1.
  */
 public function get_total()
 {
     // If parent has this method, let's use it. It means we are in WooCommerce 2.1+
     if (method_exists(get_parent_class($this), __FUNCTION__)) {
         return parent::get_total();
     }
     // Fall back to legacy method in WooCommerce 2.0 and earlier
     return $this->get_order_total();
 }
	 public function process_payment( $order_id ) {
		global $woocommerce;
		
		$order = new WC_Order( $order_id );
		
		//get payment tendered amount
		$payment_amount = $_POST['payment_amount'];
		
		//get order total
		$order_total = $order->get_total();
		
		//check for previous payments tendered and add to total payment
		$tendered = get_post_meta( $order->id, 'payment_tendered', true );
		$payment_amount = (float)$payment_amount + (float)$tendered;
			
		//calculate balance after payment applied	
		$balance = $order_total - $payment_amount;
		
		//if payment still needed
		if( $balance > 0 ) {
			
			//document transaction and create order note
			update_post_meta( $order->id, 'payment_tendered', $payment_amount );
			$order->add_order_note( __( '$ ' . round( $payment_amount, 2 ) . ' payment tendered. $ ' . round( $balance, 2 ) . ' remaining.', 'instore' ) );
			$order->update_status('pending', __( 'Awaiting additional payment', 'instore' ) );	
			$payment_complete = false;
			
		} else {
			
			//resuce stock and add order note
			$order->reduce_order_stock();
			$order->add_order_note( __( '$ ' . round( $payment_amount, 2 ) . ' payment Tendered. Change Due $ ' . round( $balance, 2 ) . ' .', 'instore' ) );
			
			//complete order
			$order->payment_complete();
			$payment_complete = true;
			
			//empty cart
			$woocommerce->cart->empty_cart();
		};
		
		//create return array
		$results = array(
			'result'		    => 'success',
			'order_id'		    => $order_id,
			'order_total'	    => $order_total,
			'balance' 		    => $balance,
			'balance_formatted' => wc_price( -$balance ),
			'payment_tendered'  => wc_price( $payment_amount ),
			'payment_complete'  => $payment_complete,
		);
		
		//return results
		return $results;
			
	 }
Пример #7
0
 /**
  * Get the order total in checkout and pay_for_order.
  *
  * @return bool
  */
 protected function get_order_total()
 {
     $total = 0;
     $order_id = absint(get_query_var('order-pay'));
     // Gets order total from "pay for order" page.
     if (0 < $order_id) {
         $order = new WC_Order($order_id);
         $total = (double) $order->get_total();
         // Gets order total from cart/checkout.
     } elseif (0 < WC()->cart->total) {
         $total = (double) WC()->cart->total;
     }
     return $total;
 }
Пример #8
0
 function successful_request($posted)
 {
     //print_r($posted);
     global $woocommerce;
     $order_id_key = $posted['customerReference'];
     $order_id_key = explode("-", $order_id_key);
     $order_id = $order_id_key[0];
     $order_key = $order_id_key[1];
     $responseCode = $posted['responseCode'];
     $responseText = $posted['responseText'];
     $txnreference = $posted['txnreference'];
     $order = new WC_Order($order_id);
     if ($order->order_key !== $order_key) {
         echo 'Error: Order Key does not match invoice.';
         exit;
     }
     if ($order->get_total() != $posted['amount']) {
         echo 'Error: Amount not match.';
         $order->update_status('on-hold', sprintf(__('Validation error: BrainTree amounts do not match (%s).', 'woocommerce'), $posted['amount']));
         exit;
     }
     // if TXN is approved
     if ($responseCode == "00" || $responseCode == "08" || $responseCode == "77") {
         // Payment completed
         $order->add_order_note(__('payment completed', 'woocommerce'));
         // Mark order complete
         $order->payment_complete();
         // Empty cart and clear session
         $woocommerce->cart->empty_cart();
         // Redirect to thank you URL
         wp_redirect($this->get_return_url($order));
         exit;
     } else {
         // Change the status to pending / unpaid
         $order->update_status('pending', __('Payment declined', 'woothemes'));
         // Add a note with the IPG details on it
         $order->add_order_note(__('Braintree payment Failed - TransactionReference: ' . $txnreference . " - ResponseCode: " . $responseCode, 'woocommerce'));
         // FAILURE NOTE
         // Add error for the customer when we return back to the cart
         $woocommerce->add_error(__('TRANSACTION DECLINED: ', 'woothemes') . $posted['responseText'] . "<br/>Reference: " . $txnreference);
         // Redirect back to the last step in the checkout process
         wp_redirect($woocommerce->cart->get_checkout_url());
         exit;
     }
 }
Пример #9
0
 /**
  * Get order total.
  *
  * @return float
  */
 public function get_order_total()
 {
     global $woocommerce;
     $order_total = 0;
     if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.1', '>=')) {
         $order_id = absint(get_query_var('order-pay'));
     } else {
         $order_id = isset($_GET['order_id']) ? absint($_GET['order_id']) : 0;
     }
     // Gets order total from "pay for order" page.
     if (0 < $order_id) {
         $order = new WC_Order($order_id);
         $order_total = (double) $order->get_total();
         // Gets order total from cart/checkout.
     } elseif (0 < $woocommerce->cart->total) {
         $order_total = (double) $woocommerce->cart->total;
     }
     return $order_total;
 }
 public function confirm_url_callback()
 {
     $transaction_id = $_GET['transactionId'];
     $results = get_posts(array('post_type' => 'shop_order', 'meta_query' => array(array('key' => '_hpd_linepay_transactionId', 'value' => $transaction_id))));
     if (!$results) {
         http_response_code(404);
         exit;
     }
     $order_data = $results[0];
     $order_id = $order_data->ID;
     $order = new WC_Order($order_id);
     $response_data = $this->client->confirm($transaction_id, $order->get_total(), get_woocommerce_currency());
     if ($response_data->returnCode != '0000') {
         $order->update_status('failed', sprintf(__('Error return code: %1$s, message: %2$s', 'wc-payment-gateway-line-pay'), $response_data->returnCode, $response_data->returnMessage));
     } else {
         $order->payment_complete();
     }
     wp_redirect($order->get_checkout_order_received_url());
     exit;
 }
Пример #11
0
/**
 * Bundle and format the order information
 * @param WC_Order $order
 * Send as much information about the order as possible to Conekta
 */
function getRequestData($order)
{
    if ($order and $order != null) {
        // custom fields
        $custom_fields = array("total_discount" => (double) $order->get_total_discount() * 100);
        // $user_id = $order->get_user_id();
        // $is_paying_customer = false;
        $order_coupons = $order->get_used_coupons();
        // if ($user_id != 0) {
        //     $custom_fields = array_merge($custom_fields, array(
        //         "is_paying_customer" => is_paying_customer($user_id)
        //     ));
        // }
        if (count($order_coupons) > 0) {
            $custom_fields = array_merge($custom_fields, array("coupon_code" => $order_coupons[0]));
        }
        return array("amount" => (double) $order->get_total() * 100, "token" => $_POST['conektaToken'], "shipping_method" => $order->get_shipping_method(), "shipping_carrier" => $order->get_shipping_method(), "shipping_cost" => (double) $order->get_total_shipping() * 100, "monthly_installments" => (int) $_POST['monthly_installments'], "currency" => strtolower(get_woocommerce_currency()), "description" => sprintf("Charge for %s", $order->billing_email), "card" => array_merge(array("name" => sprintf("%s %s", $order->billing_first_name, $order->billing_last_name), "address_line1" => $order->billing_address_1, "address_line2" => $order->billing_address_2, "billing_company" => $order->billing_company, "phone" => $order->billing_phone, "email" => $order->billing_email, "address_city" => $order->billing_city, "address_zip" => $order->billing_postcode, "address_state" => $order->billing_state, "address_country" => $order->billing_country, "shipping_address_line1" => $order->shipping_address_1, "shipping_address_line2" => $order->shipping_address_2, "shipping_phone" => $order->shipping_phone, "shipping_email" => $order->shipping_email, "shipping_address_city" => $order->shipping_city, "shipping_address_zip" => $order->shipping_postcode, "shipping_address_state" => $order->shipping_state, "shipping_address_country" => $order->shipping_country), $custom_fields));
    }
    return false;
}
Пример #12
0
/**
 * Insert a order in sync table once a order is created
 *
 * @global object $wpdb
 * @param int $order_id
 */
function dokan_sync_insert_order($order_id)
{
    global $wpdb;
    $order = new WC_Order($order_id);
    $seller_id = dokan_get_seller_id_by_order($order_id);
    $percentage = dokan_get_seller_percentage($seller_id);
    $order_total = $order->get_total();
    $order_status = $order->post_status;
    $wpdb->insert($wpdb->prefix . 'dokan_orders', array('order_id' => $order_id, 'seller_id' => $seller_id, 'order_total' => $order_total, 'net_amount' => $order_total * $percentage / 100, 'order_status' => $order_status), array('%d', '%d', '%f', '%f', '%s'));
}
        function generate_alphabank_form($order_id)
        {
            global $wpdb;
            $order = new WC_Order($order_id);
            $merchantreference = substr(sha1(rand()), 0, 30);
            if ($this->mode == "yes") {
                //test mode
                $post_url = 'https://alpha.test.modirum.com/vpos/shophandlermpi';
            } else {
                //live mode
                $post_url = 'https://www.alphaecommerce.gr/vpos/shophandlermpi';
            }
            //Alpha.rand(0,99).date("YmdHms")
            $form_data = "";
            $form_data_array = array();
            $form_mid = $this->alphabank_Merchant_ID;
            $form_data_array[1] = $form_mid;
            //Req
            $form_lang = "el";
            $form_data_array[2] = $form_lang;
            //Opt
            $form_device_cate = "";
            $form_data_array[3] = $form_device_cate;
            //Opt
            $form_order_id = $order_id;
            $form_data_array[4] = $form_order_id;
            //Req
            $form_order_desc = "";
            $form_data_array[5] = $form_order_desc;
            //Opt
            $form_order_amount = $order->get_total();
            $form_data_array[6] = $form_order_amount;
            //Req
            //        $form_order_amount = 0.10;					$form_data_array[6] = $form_order_amount;			//Req
            $form_currency = "EUR";
            $form_data_array[7] = $form_currency;
            //Req
            $form_email = $order->billing_email;
            $form_data_array[8] = $form_email;
            //Req
            $form_phone = "";
            $form_data_array[9] = $form_phone;
            //Opt
            $form_bill_country = "";
            $form_data_array[10] = $form_bill_country;
            //Opt
            $form_bill_state = "";
            $form_data_array[11] = $form_bill_state;
            //Opt
            $form_bill_zip = "";
            $form_data_array[12] = $form_bill_zip;
            //Opt
            $form_bill_city = "";
            $form_data_array[13] = $form_bill_city;
            //Opt
            $form_bill_addr = "";
            $form_data_array[14] = $form_bill_addr;
            //Opt
            $form_weight = "";
            $form_data_array[15] = $form_weight;
            //Opt
            $form_dimension = "";
            $form_data_array[16] = $form_dimension;
            //Opt
            $form_ship_counrty = "";
            $form_data_array[17] = $form_ship_counrty;
            //Opt
            $form_ship_state = "";
            $form_data_array[18] = $form_ship_state;
            //Opt
            $form_ship_zip = "";
            $form_data_array[19] = $form_ship_zip;
            //Opt
            $form_ship_city = "";
            $form_data_array[20] = $form_ship_city;
            //Opt
            $form_ship_addr = "";
            $form_data_array[21] = $form_ship_addr;
            //Opt
            $form_add_fraud_score = "";
            $form_data_array[22] = $form_add_fraud_score;
            //Opt
            $form_max_pay_retries = "";
            $form_data_array[23] = $form_max_pay_retries;
            //Opt
            $form_reject3dsU = "";
            $form_data_array[24] = $form_reject3dsU;
            //Opt
            $form_pay_method = "";
            $form_data_array[25] = $form_pay_method;
            //Opt
            $form_trytpe = "";
            $form_data_array[26] = $form_trytpe;
            //Opt
            $form_ext_install_offset = "";
            $form_data_array[27] = $form_ext_install_offset;
            //Opt
            $form_ext_install_period = "";
            $form_data_array[28] = $form_ext_install_period;
            //Opt
            $form_ext_reccuring_freq = "";
            $form_data_array[29] = $form_ext_reccuring_freq;
            //Opt
            $form_ext_reccuring_enddate = "";
            $form_data_array[30] = $form_ext_reccuring_enddate;
            //Opt
            $form_block_score = "";
            $form_data_array[31] = $form_block_score;
            //Opt
            $form_cssurl = "";
            $form_data_array[32] = $form_cssurl;
            //Opt
            $form_confirm_url = $this->redirect_page_id;
            $form_data_array[33] = $form_confirm_url;
            //Req
            $form_cancel_url = $this->redirect_fail_page_id;
            $form_data_array[34] = $form_cancel_url;
            //Req
            $form_var1 = "";
            $form_data_array[35] = $form_var1;
            $form_var2 = "";
            $form_data_array[36] = $form_var2;
            $form_var3 = "";
            $form_data_array[37] = $form_var3;
            $form_var4 = "";
            $form_data_array[38] = $form_var4;
            $form_var5 = "";
            $form_data_array[39] = $form_var5;
            $form_secret = $this->alphabank_Secret_key;
            $form_data_array[40] = $form_secret;
            //Req
            $form_data = implode("", $form_data_array);
            $digest = base64_encode(sha1(utf8_encode($form_data), true));
            //    if ($digest)
            //	{
            //If response success save data in DB and redirect
            $wpdb->insert($wpdb->prefix . 'alphabank_transactions', array('reference' => $form_email, 'merchantreference' => $merchantreference, 'orderid' => $order_id, 'timestamp' => current_time('mysql', 1)));
            /* */
            wc_enqueue_js('
				$.blockUI({
						message: "' . esc_js(__('Thank you for your order. We are now redirecting you to Alpha Bank Greece to make payment.', 'woocommerce-alphabank-payment-gateway')) . '",
						baseZ: 99999,
						overlayCSS:
						{
							background: "#fff",
							opacity: 0.6
						},
						css: {
							padding:        "20px",
							zindex:         "9999999",
							textAlign:      "center",
							color:          "#555",
							border:         "3px solid #aaa",
							backgroundColor:"#fff",
							cursor:         "wait",
							lineHeight:		"24px",
						}
					});
				jQuery("#submit_alphabank_payment_form").click();
			');
            return '<form action="' . $post_url . '" method="post" id="alphabank_payment_form" target="_top">
                    <input type="hidden" name="mid" value="' . $form_mid . '"/>
                    <input type="hidden" name="lang" value="' . $form_lang . '"/>
                    <input type="hidden" name="deviceCategory" value="' . $form_device_cate . '"/>
                    <input type="hidden" name="orderid" value="' . $form_order_id . '"/>
                    <input type="hidden" name="orderDesc" value="' . $form_order_desc . '"/>
                    <input type="hidden" name="orderAmount" value="' . $form_order_amount . '"/>
                    <input type="hidden" name="currency" value="' . $form_currency . '"/>
                    <input type="hidden" name="payerEmail" value="' . $form_email . '"/>
                    <input type="hidden" name="payerPhone" value="' . $form_phone . '"/>
                    <input type="hidden" name="billCountry" value="' . $form_bill_country . '"/>
                    <input type="hidden" name="billState" value="' . $form_bill_state . '"/>
                    <input type="hidden" name="billZip" value="' . $form_bill_zip . '"/>
                    <input type="hidden" name="billCity" value="' . $form_bill_city . '"/>
                    <input type="hidden" name="billAddress" value="' . $form_bill_addr . '"/>
                    <input type="hidden" name="weight" value="' . $form_weight . '"/>
                    <input type="hidden" name="dimensions" value="' . $form_dimension . '"/>
                    <input type="hidden" name="shipCountry" value="' . $form_ship_counrty . '"/>
                    <input type="hidden" name="shipState" value="' . $form_ship_state . '"/>
                    <input type="hidden" name="shipZip" value="' . $form_ship_zip . '"/>
                    <input type="hidden" name="shipCity" value="' . $form_ship_city . '"/>
                    <input type="hidden" name="shipAddress" value="' . $form_ship_addr . '"/>
                    <input type="hidden" name="addFraudScore" value="' . $form_add_fraud_score . '"/>
                    <input type="hidden" name="maxPayRetries" value="' . $form_max_pay_retries . '"/>
                    <input type="hidden" name="reject3dsU" value="' . $form_reject3dsU . '"/>
                    <input type="hidden" name="payMethod" value="' . $form_pay_method . '"/>
                    <input type="hidden" name="trType" value="' . $form_trytpe . '"/>
                    <input type="hidden" name="extInstallmentoffset" value="' . $form_ext_install_offset . '"/>
                    <input type="hidden" name="extInstallmentperiod" value="' . $form_ext_install_period . '"/>
                    <input type="hidden" name="extRecurringfrequency" value="' . $form_ext_reccuring_freq . '"/>
                    <input type="hidden" name="extRecurringenddate" value="' . $form_ext_reccuring_enddate . '"/>
                    <input type="hidden" name="blockScore" value="' . $form_block_score . '"/>
                    <input type="hidden" name="cssUrl" value="' . $form_cssurl . '"/>
                    <input type="hidden" name="confirmUrl" value="' . $form_confirm_url . '"/>
                    <input type="hidden" name="cancelUrl" value="' . $form_cancel_url . '"/>
                    <input type="hidden" name="var1" value="' . $form_var1 . '"/>
                    <input type="hidden" name="var2" value="' . $form_var2 . '"/>
                    <input type="hidden" name="var3" value="' . $form_var3 . '"/>
                    <input type="hidden" name="var4" value="' . $form_var4 . '"/>
                    <input type="hidden" name="var5" value="' . $form_var5 . '"/>
                    <input type="hidden" name="digest" value="' . $digest . '"/>
				
					<!-- Button Fallback -->
					<div class="payment_buttons">
						<input type="submit" class="button alt" id="submit_alphabank_payment_form" value="' . __('Pay via alphabank', 'woocommerce-alphabank-payment-gateway') . '" /> <a class="button cancel" href="' . esc_url($order->get_cancel_order_url()) . '">' . __('Cancel order &amp; restore cart', 'woocommerce-alphabank-payment-gateway') . '</a>
					</div>
					<script type="text/javascript">
						jQuery(".payment_buttons").hide();
					</script>
				</form>';
            //}
        }
Пример #14
0
 /**
  * Get the order data for the given ID.
  *
  * @since  2.5.0
  * @param  WC_Order $order The order instance
  * @return array
  */
 protected function get_order_data($order)
 {
     $order_post = get_post($order->id);
     $dp = wc_get_price_decimals();
     $order_data = array('id' => $order->id, 'order_number' => $order->get_order_number(), 'created_at' => $this->format_datetime($order_post->post_date_gmt), 'updated_at' => $this->format_datetime($order_post->post_modified_gmt), 'completed_at' => $this->format_datetime($order->completed_date, true), 'status' => $order->get_status(), 'currency' => $order->get_order_currency(), 'total' => wc_format_decimal($order->get_total(), $dp), 'subtotal' => wc_format_decimal($order->get_subtotal(), $dp), 'total_line_items_quantity' => $order->get_item_count(), 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp), 'total_shipping' => wc_format_decimal($order->get_total_shipping(), $dp), 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp), 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp), 'total_discount' => wc_format_decimal($order->get_total_discount(), $dp), 'shipping_methods' => $order->get_shipping_method(), 'payment_details' => array('method_id' => $order->payment_method, 'method_title' => $order->payment_method_title, 'paid' => isset($order->paid_date)), 'billing_address' => array('first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_1' => $order->billing_address_1, 'address_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postcode' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'phone' => $order->billing_phone), 'shipping_address' => array('first_name' => $order->shipping_first_name, 'last_name' => $order->shipping_last_name, 'company' => $order->shipping_company, 'address_1' => $order->shipping_address_1, 'address_2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postcode' => $order->shipping_postcode, 'country' => $order->shipping_country), 'note' => $order->customer_note, 'customer_ip' => $order->customer_ip_address, 'customer_user_agent' => $order->customer_user_agent, 'customer_id' => $order->get_user_id(), 'view_order_url' => $order->get_view_order_url(), 'line_items' => array(), 'shipping_lines' => array(), 'tax_lines' => array(), 'fee_lines' => array(), 'coupon_lines' => array());
     // add line items
     foreach ($order->get_items() as $item_id => $item) {
         $product = $order->get_product_from_item($item);
         $product_id = null;
         $product_sku = null;
         // Check if the product exists.
         if (is_object($product)) {
             $product_id = isset($product->variation_id) ? $product->variation_id : $product->id;
             $product_sku = $product->get_sku();
         }
         $meta = new WC_Order_Item_Meta($item, $product);
         $item_meta = array();
         foreach ($meta->get_formatted(null) as $meta_key => $formatted_meta) {
             $item_meta[] = array('key' => $meta_key, 'label' => $formatted_meta['label'], 'value' => $formatted_meta['value']);
         }
         $order_data['line_items'][] = array('id' => $item_id, 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp), 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp), 'total_tax' => wc_format_decimal($item['line_tax'], $dp), 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'quantity' => wc_stock_amount($item['qty']), 'tax_class' => !empty($item['tax_class']) ? $item['tax_class'] : null, 'name' => $item['name'], 'product_id' => $product_id, 'sku' => $product_sku, 'meta' => $item_meta);
     }
     // Add shipping.
     foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
         $order_data['shipping_lines'][] = array('id' => $shipping_item_id, 'method_id' => $shipping_item['method_id'], 'method_title' => $shipping_item['name'], 'total' => wc_format_decimal($shipping_item['cost'], $dp));
     }
     // Add taxes.
     foreach ($order->get_tax_totals() as $tax_code => $tax) {
         $order_data['tax_lines'][] = array('id' => $tax->id, 'rate_id' => $tax->rate_id, 'code' => $tax_code, 'title' => $tax->label, 'total' => wc_format_decimal($tax->amount, $dp), 'compound' => (bool) $tax->is_compound);
     }
     // Add fees.
     foreach ($order->get_fees() as $fee_item_id => $fee_item) {
         $order_data['fee_lines'][] = array('id' => $fee_item_id, 'title' => $fee_item['name'], 'tax_class' => !empty($fee_item['tax_class']) ? $fee_item['tax_class'] : null, 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp));
     }
     // Add coupons.
     foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
         $order_data['coupon_lines'][] = array('id' => $coupon_item_id, 'code' => $coupon_item['name'], 'amount' => wc_format_decimal($coupon_item['discount_amount'], $dp));
     }
     $order_data = apply_filters('woocommerce_cli_order_data', $order_data);
     return $this->flatten_array($order_data);
 }
Пример #15
0
 /**
  * Process the payment and return the result
  *
  * @access public
  * @param int $order_id
  * @return array
  */
 function process_payment($order_id)
 {
     global $woocommerce;
     $order = new WC_Order($order_id);
     $token = $_POST['payfortToken'];
     try {
         if (empty($token)) {
             $error_msg = __('Please make sure your card details have been entered correctly.', 'woocommerce');
             throw new Start_Error($error_msg);
         }
         $charge_description = $order->id . ": WooCommerce charge for " . $order->billing_email;
         $order_items = $order->get_items();
         $order_items_array_full = array();
         $user_info = wp_get_current_user();
         $user_name = $user_info->user_login;
         $udata = get_userdata($user_info->ID);
         if (isset($udata->user_registered)) {
             $registered_at = date(DATE_ISO8601, strtotime($udata->user_registered));
         } else {
             $registered_at = date(DATE_ISO8601, strtotime(date("Y-m-d H:i:s")));
         }
         foreach ($order_items as $key => $items) {
             $itemClass = new WC_Product($items['product_id']);
             $order_items_array['title'] = $items['name'];
             $order_items_array['amount'] = round($itemClass->get_price(), 2) * $this->currency_multiplier[get_woocommerce_currency()];
             $order_items_array['quantity'] = $items['qty'];
             array_push($order_items_array_full, $order_items_array);
         }
         $billing_address = array("first_name" => $order->billing_first_name, "last_name" => $order->billing_last_name, "country" => $order->billing_country, "city" => $order->billing_city, "address_1" => $order->billing_address_1, "address_2" => $order->billing_address_2, "phone" => $order->billing_phone, "postcode" => $order->billing_postcode);
         $shipping_address = array("first_name" => $order->shipping_first_name, "last_name" => $order->shipping_last_name, "country" => $order->shipping_country, "city" => $order->shipping_city, "address_1" => $order->shipping_address_1, "address_2" => $order->shipping_address_2, "phone" => $order->shipping_phone, "postcode" => $order->shipping_postcode);
         $shopping_cart_array = array('user_name' => $user_name, 'registered_at' => $registered_at, 'items' => $order_items_array_full, 'billing_address' => $billing_address, 'shipping_address' => $shipping_address);
         $charge_args = array('description' => $charge_description, 'card' => $token, 'currency' => strtoupper(get_woocommerce_currency()), 'email' => $order->billing_email, 'ip' => $_SERVER['REMOTE_ADDR'], 'amount' => $order->get_total() * $this->currency_multiplier[get_woocommerce_currency()], 'shopping_cart' => $shopping_cart_array, 'shipping_amount' => round($order->get_total_shipping(), 2) * $this->currency_multiplier[get_woocommerce_currency()], 'metadata' => array('reference_id' => $order_id));
         if ($this->test_mode == 'yes') {
             Start::setApiKey($this->test_secret_key);
         } else {
             Start::setApiKey($this->live_secret_key);
         }
         $start_plugin_data = get_file_data('wp-content/plugins/payfort/woocommerce-payfort.php', array('Version'), 'plugin');
         $woo_plugin_data = get_file_data('wp-content/plugins/woocommerce/woocommerce.php', array('Version'), 'plugin');
         $userAgent = 'WooCommerce ' . $woo_plugin_data['0'] . ' / Start Plugin ' . $start_plugin_data['0'];
         Start::setUserAgent($userAgent);
         $charge = Start_Charge::create($charge_args);
         // No exceptions? Yaay, all done!
         $order->payment_complete();
         return array('result' => 'success', 'redirect' => $this->get_return_url($order));
     } catch (Start_Error $e) {
         // TODO: Can we get the extra params (so the error is more apparent)?
         // e.g. Instead of "request params are invalid", we get
         // "extras":{"amount":["minimum amount (in the smallest currency unit) is 185 for AED"]
         $error_code = $e->getErrorCode();
         if ($error_code === "card_declined") {
             $message = __('Error: ', 'woothemes') . $e->getMessage() . " Please, try with another card";
         } else {
             $message = __('Error: ', 'woothemes') . $e->getMessage();
         }
         // If function should we use?
         if (function_exists("wc_add_notice")) {
             // Use the new version of the add_error method
             wc_add_notice($message, 'error');
         } else {
             // Use the old version
             $woocommerce->add_error($message);
         }
         // we raise 'update_checkout' event for javscript
         // to remove card token
         WC()->session->set('refresh_totals', true);
         return array('result' => 'fail', 'redirect' => '');
     }
 }
 /**
  * Hosted payment args.
  *
  * @param  WC_Order $order
  *
  * @return array
  */
 protected function get_hosted_payments_args($order)
 {
     $args = apply_filters('woocommerce_simplify_commerce_hosted_args', array('sc-key' => $this->public_key, 'amount' => $order->get_total() * 100, 'reference' => $order->get_id(), 'name' => esc_html(get_bloginfo('name', 'display')), 'description' => sprintf(__('Order #%s', 'woocommerce'), $order->get_order_number()), 'receipt' => 'false', 'color' => $this->modal_color, 'redirect-url' => WC()->api_request_url('WC_Gateway_Simplify_Commerce'), 'address' => $order->get_billing_address_1() . ' ' . $order->get_billing_address_2(), 'address-city' => $order->get_billing_city(), 'address-state' => $order->get_billing_state(), 'address-zip' => $order->get_billing_postcode(), 'address-country' => $order->get_billing_country(), 'operation' => 'create.token'), $order->get_id());
     return $args;
 }
 /**
  * Automatically set a switch order's status to complete (even if the items require shipping because 
  * the order is simply a record of the switch and not indicative of an item needing to be shipped)
  *
  * @since 1.5.17
  */
 public static function order_autocomplete($new_order_status, $order_id)
 {
     if ('processing' == $new_order_status && self::order_contains_synced_subscription($order_id)) {
         $order = new WC_Order($order_id);
         if (1 == count($order->get_items()) && 0 == $order->get_total()) {
             // Can't use $order->get_item_count() because it takes quantity into account
             $new_order_status = 'completed';
         }
     }
     return $new_order_status;
 }
 /**
  * Payment fields.
  *
  * @return string
  */
 public function payment_fields()
 {
     global $woocommerce;
     wp_enqueue_script('wc-credit-card-form');
     $cart_total = 0;
     if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.1', '>=')) {
         $order_id = absint(get_query_var('order-pay'));
     } else {
         $order_id = isset($_GET['order_id']) ? absint($_GET['order_id']) : 0;
     }
     // Gets order total from "pay for order" page.
     if (0 < $order_id) {
         $order = new WC_Order($order_id);
         $cart_total = (double) $order->get_total();
         // Gets order total from cart/checkout.
     } elseif (0 < $woocommerce->cart->total) {
         $cart_total = (double) $woocommerce->cart->total;
     }
     if ($description = $this->get_description()) {
         echo wpautop(wptexturize($description));
     }
     if ('transparent' == $this->method) {
         woocommerce_get_template('transparent-checkout-form.php', array('cart_total' => $cart_total, 'tc_credit' => $this->tc_credit, 'tc_transfer' => $this->tc_transfer, 'tc_ticket' => $this->tc_ticket, 'tc_ticket_message' => $this->tc_ticket_message), 'woocommerce/pagseguro/', WC_PagSeguro::get_templates_path());
     }
 }
/**
 * ecommerce tracking with piwik.
 *
 * @access public
 * @param int $order_id
 * @return void
 */
function woocommerce_ecommerce_tracking_piwik($order_id)
{
    global $woocommerce;
    // Don't track admin
    if (current_user_can('manage_options')) {
        return;
    }
    // Call the Piwik ecommerce function if WP-Piwik is configured to add tracking codes to the page
    $wp_piwik_global_settings = get_option('wp-piwik_global-settings');
    // Return if Piwik settings are not here, or if global is not set
    if (!isset($wp_piwik_global_settings['add_tracking_code']) || !$wp_piwik_global_settings['add_tracking_code']) {
        return;
    }
    if (!isset($GLOBALS['wp_piwik'])) {
        return;
    }
    // Get the order and get tracking code
    $order = new WC_Order($order_id);
    ob_start();
    ?>
	try {
		// Add order items
		<?php 
    if ($order->get_items()) {
        foreach ($order->get_items() as $item) {
            $_product = $order->get_product_from_item($item);
            ?>

			piwikTracker.addEcommerceItem(
				"<?php 
            echo esc_js($_product->get_sku());
            ?>
",			// (required) SKU: Product unique identifier
				"<?php 
            echo esc_js($item['name']);
            ?>
",					// (optional) Product name
				"<?php 
            if (isset($_product->variation_data)) {
                echo esc_js(woocommerce_get_formatted_variation($_product->variation_data, true));
            }
            ?>
",	// (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
				<?php 
            echo esc_js($order->get_item_total($item));
            ?>
,	// (recommended) Product price
				<?php 
            echo esc_js($item['qty']);
            ?>
 						// (optional, default to 1) Product quantity
			);

		<?php 
        }
    }
    ?>

		// Track order
		piwikTracker.trackEcommerceOrder(
			"<?php 
    echo esc_js($order->get_order_number());
    ?>
",	// (required) Unique Order ID
			<?php 
    echo esc_js($order->get_total());
    ?>
,			// (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
			false,													// (optional) Order sub total (excludes shipping)
			<?php 
    echo esc_js($order->get_total_tax());
    ?>
,		// (optional) Tax amount
			<?php 
    echo esc_js($order->get_shipping());
    ?>
,		// (optional) Shipping amount
			false 													// (optional) Discount offered (set to false for unspecified parameter)
		);
	} catch( err ) {}
	<?php 
    $code = ob_get_clean();
    $woocommerce->add_inline_js($code);
}
Пример #20
0
 function charge_payment($order_id)
 {
     global $woocommerce;
     $order_items = array();
     $order = new WC_Order($order_id);
     MEOWallet_Config::$isProduction = $this->environment == 'production' ? TRUE : FALSE;
     MEOWallet_Config::$apikey = MEOWallet_Config::$isProduction ? $this->apikey_live : $this->apikey_sandbox;
     //MEOWallet_Config::$isTuned = 'yes';
     $params = array('payment' => array('client' => array('name' => $order->billing_first_name . ' ' . $order->billing_last_name, 'email' => $_POST['billing_email'], 'address' => array('country' => $_POST['billing_country'], 'address' => $_POST['billing_address_1'], 'city' => $_POST['billing_city'], 'postalcode' => $_POST['billing_postcode'])), 'amount' => $order->get_total(), 'currency' => 'EUR', 'items' => $items, 'url_confirm' => get_permalink(woocommerce_get_page_id('shop')) . '?' . $post_result_array->id, 'url_cancel' => get_permalink(woocommerce_get_page_id('shop')) . '?' . $post_result_array->id));
     $client_details = array();
     $client_details['name'] = $_POST['billing_first_name'] . ' ' . $_POST['billing_last_name'];
     $client_details['email'] = $_POST['billing_email'];
     //$client_details['address'] = $client_address;
     $client_address = array();
     $client_address['country'] = $_POST['billing_country'];
     $client_address['address'] = $_POST['billing_address_1'];
     $client_address['city'] = $_POST['billing_city'];
     $client_address['postalcode'] = $_POST['billing_postcode'];
     //$params['payment']['client'] = $client_details;
     //$params['payment']['client']['address'] = $client_address;
     $items = array();
     if (sizeof($order->get_items()) > 0) {
         foreach ($order->get_items() as $item) {
             if ($item['qty']) {
                 $product = $order->get_product_from_item($item);
                 $client_items = array();
                 $client_items['client']['id'] = $item['id'];
                 $client_item['client']['name'] = $item['name'];
                 $client_items['client']['description'] = $item['name'];
                 $client_item['client']['qt'] = $item['qty'];
                 $items['client'][] = $client_items;
             }
         }
     }
     if ($order->get_total_shipping() > 0) {
         $items[] = array('id' => 'shippingfee', 'price' => $order->get_total_shipping(), 'quantity' => 1, 'name' => 'Shipping Fee');
     }
     if ($order->get_total_tax() > 0) {
         $items[] = array('id' => 'taxfee', 'price' => $order->get_total_tax(), 'quantity' => 1, 'name' => 'Tax');
     }
     if ($order->get_order_discount() > 0) {
         $items[] = array('id' => 'totaldiscount', 'price' => $order->get_total_discount() * -1, 'quantity' => 1, 'name' => 'Total Discount');
     }
     if (sizeof($order->get_fees()) > 0) {
         $fees = $order->get_fees();
         $i = 0;
         foreach ($fees as $item) {
             $items[] = array('id' => 'itemfee' . $i, 'price' => $item['line_total'], 'quantity' => 1, 'name' => $item['name']);
             $i++;
         }
     }
     //$params['client']['amount'] = $order->get_total();
     //if (get_woocommerce_currency() != 'EUR'){
     //	foreach ($items as &$item){
     //		$item['price'] = $item['price'] * $this->to_euro_rate;
     //	}
     //	unset($item);
     //	$params['payment']['amount'] *= $this->to_euro_rate;
     //}
     //$params['payment']['items'] = $items;
     //$woocommerce->cart->empty_cart();
     return MEOWallet_Checkout::getRedirectionUrl($params);
 }
 /**
  * Add payment and transaction information as class members of WC_Order
  * instance for use in credit card capture transactions.  Standard information
  * can include:
  *
  * $order->capture_total - the capture total
  *
  * @since 2.0.0
  * @param WC_Order $order order being processed
  * @return WC_Order object with payment and transaction information attached
  */
 protected function get_order_for_capture($order)
 {
     // set capture total here so it can be modified later as needed prior to capture
     $order->capture_total = number_format($order->get_total(), 2, '.', '');
     // capture-specific order description
     $order->description = sprintf(_x('%s - Capture for Order %s', 'Capture order description', $this->text_domain), esc_html(get_bloginfo('name')), $order->get_order_number());
     return apply_filters('wc_payment_gateway_' . $this->get_id() . '_get_order_for_capture', $order, $this);
 }
Пример #22
0
 $shop_name = get_bloginfo('name');
 // Sets the boleto data.
 $data = array();
 foreach ($order_data as $key => $value) {
     $data[$key] = sanitize_text_field($value);
 }
 // Sets the settings data.
 foreach ($settings as $key => $value) {
     if (in_array($key, array('demonstrativo1', 'demonstrativo2', 'demonstrativo3'))) {
         $data[$key] = str_replace('[number]', '#' . $data['nosso_numero'], sanitize_text_field($value));
     } else {
         $data[$key] = sanitize_text_field($value);
     }
 }
 // Set the ticket total.
 $data['valor_boleto'] = number_format((double) $order->get_total(), 2, ',', '');
 // Shop data.
 $data['identificacao'] = $shop_name;
 // Client data.
 if (!empty($order->billing_cnpj)) {
     $data['sacado'] = $order->billing_company;
 } else {
     $data['sacado'] = $order->billing_first_name . ' ' . $order->billing_last_name;
 }
 // Formatted Addresses
 $address_fields = apply_filters('woocommerce_order_formatted_billing_address', array('first_name' => '', 'last_name' => '', 'company' => '', 'address_1' => $order->billing_address_1, 'address_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postcode' => $order->billing_postcode, 'country' => $order->billing_country), $order);
 if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.1', '>=')) {
     $address = WC()->countries->get_formatted_address($address_fields);
 } else {
     global $woocommerce;
     $address = $woocommerce->countries->get_formatted_address($address_fields);
 public function process_payment($order_id)
 {
     global $woocommerce;
     global $current_user;
     //get user details
     $current_user = wp_get_current_user();
     $user_email = $current_user->user_email;
     $first_name = $current_user->shipping_first_name;
     $last_name = $current_user->shipping_last_name;
     $phone_number = $current_user->billing_phone;
     $country = $current_user->shipping_country;
     $state = $current_user->shipping_state;
     $city = $current_user->shipping_city;
     $postcode = $current_user->shipping_postcode;
     $address_1 = $current_user->shipping_address_1;
     $address_2 = $current_user->shipping_address_2;
     $udf1 = $first_name . " " . $last_name;
     $udf2 = $user_email;
     $udf3 = $phone_number;
     $udf4 = $country . " " . $state . " " . shipping_city . " " . $address_1 . " " . $address_2 . " " . $postcode;
     if ($user_email == '') {
         $user_email = $_POST['billing_email'];
         $first_name = $_POST['billing_first_name'];
         $last_name = $_POST['billing_last_name'];
         $phone_number = $_POST['billing_phone'];
         $country = $_POST['billing_country'];
         $state = $_POST['billing_state'];
         $city = $_POST['billing_city'];
         $postcode = $_POST['billing_postcode'];
         $address_1 = $_POST['billing_address_1'];
         $address_2 = $_POST['billing_address_2'];
         $udf1 = $first_name . " " . $last_name;
         $udf2 = $user_email;
         $udf3 = $phone_number;
         $udf4 = $country . " " . $state . " " . shipping_city . " " . $address_1 . " " . $address_2 . " " . $postcode;
     }
     $order = new WC_Order($order_id);
     $atom_login_id = $this->login_id;
     $atom_password = $this->password;
     $atom_prod_id = $this->atom_product_id;
     $amount = $order->get_total();
     $currency = "INR";
     $custacc = "1234567890";
     $txnid = $order_id;
     $clientcode = urlencode(base64_encode(07));
     $datenow = date("d/m/Y h:m:s");
     $encodedDate = str_replace(" ", "%20", $datenow);
     $ru = $this->notify_url;
     $param = "&login="******"&pass="******"&ttype=NBFundTransfer" . "&prodid=" . $atom_prod_id . "&amt=" . $amount . "&txncurr=" . $currency . "&txnscamt=0" . "&clientcode=" . $clientcode . "&txnid=" . $txnid . "&date=" . $encodedDate . "&custacc=" . $custacc . "&udf1=" . $udf1 . "&udf2=" . $udf2 . "&udf3=" . $udf3 . "&udf4=" . $udf4 . "&ru=" . $ru;
     global $wpdb, $woocommerce;
     $ch = curl_init();
     $useragent = 'woo-commerce plugin';
     curl_setopt($ch, CURLOPT_URL, $this->url);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_PORT, $this->atom_port);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
     curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //information received from gateway is stored in $response.
     $response = curl_exec($ch);
     if (curl_errno($ch)) {
         echo '<div class="woocommerce-error">Curl error: "' . curl_error($ch) . ". Error in gateway credentials.</div>";
         die;
     }
     curl_close($ch);
     $parser = xml_parser_create('');
     xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_parse_into_struct($parser, trim($response), $xml_values);
     xml_parser_free($parser);
     $returnArray = array();
     $returnArray['url'] = $xml_values[3]['value'];
     $returnArray['tempTxnId'] = $xml_values[5]['value'];
     $returnArray['token'] = $xml_values[6]['value'];
     //code to generate form action
     $xmlObjArray = $returnArray;
     $url = $xmlObjArray['url'];
     $postFields = "";
     $postFields .= "&ttype=NBfundTransfer";
     $postFields .= "&tempTxnId=" . $xmlObjArray['tempTxnId'];
     $postFields .= "&token=" . $xmlObjArray['token'];
     $postFields .= "&txnStage=1";
     $q = $url . "?" . $postFields;
     return array('result' => 'success', 'redirect' => $q);
     exit;
 }
<?php

add_action('woocommerce_thankyou', function ($order) {
    $trans = new WC_Order($order);
    $items = $trans->get_items();
    $length = count($items);
    foreach ($items as $key => $item) {
        if ($key + 1 < $length) {
            $cartProducts[$key] = "\n\t\t{\n\t\t'sku': '" . $item['product_id'] . "',\n\t\t'name': '" . $item['name'] . "',\n\t\t'category': '',\n\t\t'price': '" . $item['line_total'] . "',\n\t\t'quantity': '" . $item['qty'] . "'\n\t\t},";
        } else {
            $cartProducts[$key] = "\n\t\t{\n\t\t'sku': '" . $item['product_id'] . "',\n\t\t'name': '" . $item['name'] . "',\n\t\t'category': '',\n\t\t'price': '" . $item['line_total'] . "',\n\t\t'quantity': '" . $item['qty'] . "'\n\t\t}";
        }
    }
    echo "<script>dataLayer.push({'transactionId': '" . $trans->get_order_number() . "','transactionAffiliation': '','transactionTotal': '" . $trans->get_total() . "','transactionTax': '" . $trans->get_total_tax() . "','transactionShipping': '" . $trans->get_total_shipping() . "','transactionProducts': [";
    foreach ($cartProducts as $row) {
        echo $row;
    }
    echo "]});</script>";
});
 function get_monthly_sales_report()
 {
     $execution_time_start = microtime(true);
     $months_array = array('');
     $months_days_array = array(__('Days', 'woocommerce-jetpack'));
     $total_orders_array = array(__('Total Orders', 'woocommerce-jetpack'));
     $total_orders_average_array = array(__('Orders Average / Day', 'woocommerce-jetpack'));
     $total_orders_sum_array = array(__('Total Sum', 'woocommerce-jetpack'));
     $total_orders_sum_excl_tax_array = array(__('Total Sum (excl. TAX)', 'woocommerce-jetpack'));
     $total_orders_sum_average_order_array = array(__('Average / Order (excl. TAX)', 'woocommerce-jetpack'));
     $total_orders_sum_average_array = array(__('Average / Day (excl. TAX)', 'woocommerce-jetpack'));
     $currency_rates_array = array(__('Currency Rates', 'woocommerce-jetpack'));
     $total_months_days = 0;
     $total_orders_total = 0;
     $total_orders_sum_total = 0;
     $total_orders_sum_excl_tax_total = 0;
     $order_currencies_array = array();
     $report_currency = isset($_GET['currency']) && 'merge' != $_GET['currency'] ? $_GET['currency'] : get_woocommerce_currency();
     $block_size = 96;
     $table_data = array();
     for ($i = 1; $i <= 12; $i++) {
         $current_months_averages = array();
         $total_orders = 0;
         $total_orders_sum = 0;
         $total_orders_sum_excl_tax = 0;
         $offset = 0;
         $day_for_average = $i == date('m') && $this->year == date('Y') ? date('d') - 1 : date('t', strtotime($this->year . '-' . sprintf('%02d', $i) . '-' . '01'));
         if (0 == $day_for_average) {
             $months_array[] = date_i18n('F', mktime(0, 0, 0, $i, 1, $this->year));
             $months_days_array[] = '-';
             $total_orders_array[] = '-';
             $total_orders_average_array[] = '-';
             $total_orders_sum_array[] = '-';
             $total_orders_sum_excl_tax_array[] = '-';
             $total_orders_sum_average_order_array[] = '-';
             $total_orders_sum_average_array[] = '-';
             $currency_rates_array[] = '';
             continue;
         }
         while (true) {
             $args_orders = array('post_type' => 'shop_order', 'post_status' => 'wc-completed', 'posts_per_page' => $block_size, 'orderby' => 'date', 'order' => 'DESC', 'offset' => $offset, 'date_query' => array('after' => array('year' => $this->year, 'month' => $i, 'day' => 1), 'before' => array('year' => $this->year, 'month' => $i, 'day' => $day_for_average), 'inclusive' => true));
             $loop_orders = new WP_Query($args_orders);
             if (!$loop_orders->have_posts()) {
                 break;
             }
             while ($loop_orders->have_posts()) {
                 $loop_orders->the_post();
                 $order_id = $loop_orders->post->ID;
                 $order = new WC_Order($order_id);
                 $order_currency = $order->get_order_currency();
                 if (!isset($order_currencies_array[$order_currency])) {
                     $order_currencies_array[$order_currency] = 0;
                 }
                 $order_currencies_array[$order_currency]++;
                 $total_orders++;
                 $order_total = $order->get_total();
                 $order_total_excl_tax = $order->get_total() - $order->get_total_tax();
                 if (!isset($current_months_averages[$order_currency][$report_currency])) {
                     $start_date = $this->year . '-' . sprintf('%02d', $i) . '-' . '01';
                     $end_date = date('Y-m-t', strtotime($start_date));
                     $the_rate = $this->get_exchange_rate_average($order_currency, $report_currency, $start_date, $end_date);
                     if (false === $the_rate) {
                         // Try previous month
                         $start_date_prev_month = date('Y-m-d', strtotime('first day of last month', strtotime($start_date)));
                         $end_date_prev_month = date('Y-m-t', strtotime($start_date_prev_month));
                         $the_rate = $this->get_exchange_rate_average($order_currency, $report_currency, $start_date_prev_month, $end_date_prev_month);
                         if (false === $the_rate) {
                             return '<p>' . sprintf(__('Error getting currency rate for %s', 'woocommerce-jetpack'), $order_currency . $report_currency) . '</p>';
                         }
                     }
                     $current_months_averages[$order_currency][$report_currency] = $the_rate;
                 }
                 $total_orders_sum += $order_total * $current_months_averages[$order_currency][$report_currency];
                 $total_orders_sum_excl_tax += $order_total_excl_tax * $current_months_averages[$order_currency][$report_currency];
             }
             $offset += $block_size;
         }
         // Month Name
         $months_array[] = date_i18n('F', mktime(0, 0, 0, $i, 1, $this->year));
         // Month Days
         $months_days_array[] = date('m') >= $i || $this->year != date('Y') ? $day_for_average : '-';
         $total_months_days += date('m') >= $i || $this->year != date('Y') ? $day_for_average : 0;
         // Sales
         $total_orders_array[] = $total_orders > 0 ? $total_orders : '-';
         $total_orders_total += $total_orders;
         // Sales Average
         $average_sales_result = $total_orders / $day_for_average;
         $total_orders_average_array[] = $average_sales_result > 0 ? number_format($average_sales_result, 2, '.', ',') : '-';
         // Sum
         $total_orders_sum_array[] = $total_orders_sum > 0 ? $report_currency . ' ' . number_format($total_orders_sum, 2, '.', ',') : '-';
         $total_orders_sum_total += $total_orders_sum;
         // Sum excl. Tax
         //if ( $total_orders_sum != $total_orders_sum_excl_tax) {
         $total_orders_sum_excl_tax_array[] = $total_orders_sum_excl_tax > 0 ? $report_currency . ' ' . number_format($total_orders_sum_excl_tax, 2, '.', ',') : '-';
         $total_orders_sum_excl_tax_total += $total_orders_sum_excl_tax;
         //}
         // Order Average
         $total_orders_sum_average_order_array[] = $total_orders_sum_excl_tax > 0 && $total_orders > 0 ? $report_currency . ' ' . number_format($total_orders_sum_excl_tax / $total_orders, 2, '.', ',') : '-';
         // Sum Average
         $average_result = $total_orders_sum_excl_tax / $day_for_average;
         $total_orders_sum_average_array[] = $average_result > 0 ? $report_currency . ' ' . number_format($average_result, 2, '.', ',') : '-';
         // Currency Rates
         //			if ( isset( $_GET['show_rates'] ) ) {
         ksort($current_months_averages, true);
         //				$currency_rates_html = '<pre style="font-size:8px;">' . print_r( $current_months_averages, true ) . '</pre>';
         $currency_rates_html = '<pre style="font-size:x-small;">';
         foreach ($current_months_averages as $currency_from => $currencies_to) {
             foreach ($currencies_to as $currency_to => $rate) {
                 if ($currency_from != $currency_to) {
                     $currency_rates_html .= $currency_from . $currency_to . '~' . number_format($rate, 4) . '<br>';
                 }
             }
         }
         $currency_rates_html .= '</pre>';
         //			}
         $currency_rates_array[] = $currency_rates_html;
     }
     // Totals
     $months_array[] = __('Totals', 'woocommerce-jetpack');
     $months_days_array[] = $total_months_days;
     $total_orders_array[] = $total_orders_total;
     $total_orders_average_array[] = $total_months_days > 0 ? number_format($total_orders_total / $total_months_days, 2, '.', ',') : '-';
     $total_orders_sum_array[] = $report_currency . ' ' . number_format($total_orders_sum_total, 2, '.', ',');
     $total_orders_sum_excl_tax_array[] = $report_currency . ' ' . number_format($total_orders_sum_excl_tax_total, 2, '.', ',');
     $total_orders_sum_average_order_array[] = $total_orders_total > 0 ? $report_currency . ' ' . number_format($total_orders_sum_excl_tax_total / $total_orders_total, 2, '.', ',') : '-';
     $total_orders_sum_average_array[] = $total_months_days > 0 ? $report_currency . ' ' . number_format($total_orders_sum_excl_tax_total / $total_months_days, 2, '.', ',') : '-';
     $currency_rates_array[] = '';
     // Table
     $table_data[] = $months_array;
     $table_data[] = $months_days_array;
     $table_data[] = $total_orders_array;
     $table_data[] = $total_orders_average_array;
     $table_data[] = $total_orders_sum_array;
     $table_data[] = $total_orders_sum_excl_tax_array;
     $table_data[] = $total_orders_sum_average_order_array;
     $table_data[] = $total_orders_sum_average_array;
     $table_data[] = $currency_rates_array;
     /* foreach ( $order_currencies_array as $order_currency => $total_currency_orders ) {
     			$table_data[] = array( $order_currency . ' (' . $total_currency_orders . ')' );
     		} */
     $execution_time_end = microtime(true);
     // HTML
     $html = '';
     $menu = '';
     $menu .= '<ul class="subsubsub">';
     $menu .= '<li><a href="' . add_query_arg('year', date('Y')) . '" class="' . ($this->year == date('Y') ? 'current' : '') . '">' . date('Y') . '</a> | </li>';
     $menu .= '<li><a href="' . add_query_arg('year', date('Y') - 1) . '" class="' . ($this->year == date('Y') - 1 ? 'current' : '') . '">' . (date('Y') - 1) . '</a> | </li>';
     $menu .= '</ul>';
     $menu .= '<br class="clear">';
     $html .= $menu;
     $html .= '<h4>' . __('Report currency', 'woocommerce-jetpack') . ': ' . $report_currency . '</h4>';
     $months_styles = array();
     for ($i = 1; $i <= 12; $i++) {
         $months_styles[] = 'width:6%;';
     }
     $html .= wcj_get_table_html($table_data, array('table_class' => 'widefat striped', 'table_heading_type' => 'horizontal', 'columns_styles' => array_merge(array('width:16%;'), $months_styles, array('width:12%;font-weight:bold;'))));
     $html .= '<p style="font-size:x-small;"><em>' . sprintf(__('Report generated in: %s s', 'woocommerce-jetpack'), number_format($execution_time_end - $execution_time_start, 2, '.', ',')) . '</em></p>';
     $html .= '<form method="post" action="">' . '<input name="wcj_reset_currency_rates" type="submit" class="button button-primary" value="' . __('Reset Currency Rates', 'woocommerce-jetpack') . '">' . '</form>';
     //		$html .= '<pre>' . print_r( get_option( 'wcj_reports_currency_rates' ), true ) . '</pre>';
     return $html;
 }
 /**
  * Process a void
  *
  * @since 3.1.0
  * @param WC_Order $order order object (with refund class member already added)
  * @return bool|WP_Error true on success, or a WP_Error object on failure/error
  */
 protected function process_void(WC_Order $order)
 {
     // partial voids are not supported
     if ($order->refund->amount != $order->get_total()) {
         return new WP_Error('wc_' . $this->get_id() . '_void_error', esc_html__('Oops, you cannot partially void this order. Please use the full order amount.', 'woocommerce-plugin-framework'));
     }
     try {
         $response = $this->get_api()->void($order);
         if ($response->transaction_approved()) {
             // add standard void-specific transaction data
             $this->add_void_data($order, $response);
             // let payment gateway implementations add their own data
             $this->add_payment_gateway_void_data($order, $response);
             // update order status to "refunded" and add an order note
             $this->mark_order_as_voided($order, $response);
             return true;
         } else {
             $error = $this->get_void_failed_wp_error($response->get_status_code(), $response->get_status_message());
             $order->add_order_note($error->get_error_message());
             return $error;
         }
     } catch (SV_WC_Plugin_Exception $e) {
         $error = $this->get_void_failed_wp_error($e->getCode(), $e->getMessage());
         $order->add_order_note($error->get_error_message());
         return $error;
     }
 }
Пример #27
0
 /**
  * Process the payment and return the result
  *
  * @access public
  * @param int $order_id
  * @return array
  */
 function process_payment($order_id)
 {
     global $woocommerce;
     $order = new WC_Order($order_id);
     if ('yes' == $this->debug) {
         $this->log('Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url);
     }
     // 2Checkout Args
     $twocheckout_args = array('token' => $_POST['token'], 'sellerId' => $this->seller_id, 'currency' => get_woocommerce_currency(), 'total' => $order->get_total(), 'merchantOrderId' => $order->get_order_number(), "billingAddr" => array('name' => $order->billing_first_name . ' ' . $order->billing_last_name, 'addrLine1' => $order->billing_address_1, 'addrLine2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zipCode' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'phoneNumber' => $order->billing_phone));
     try {
         if ($this->sandbox == 'yes') {
             TwocheckoutApi::setCredentials($this->seller_id, $this->private_key, 'sandbox');
         } else {
             TwocheckoutApi::setCredentials($this->seller_id, $this->private_key);
         }
         $charge = Twocheckout_Charge::auth($twocheckout_args);
         if ($charge['response']['responseCode'] == 'APPROVED') {
             $order->payment_complete();
             return array('result' => 'success', 'redirect' => $this->get_return_url($order));
         }
     } catch (Twocheckout_Error $e) {
         wc_add_notice($e->getMessage(), $notice_type = 'error');
         return;
     }
 }
 /**
  * Set the subscription prices to be used in calculating totals by @see WC_Subscriptions_Cart::calculate_subscription_totals()
  *
  * @since 1.4
  */
 public static function maybe_set_apporitioned_totals($total)
 {
     global $woocommerce;
     if (false === self::cart_contains_subscription_switch()) {
         return $total;
     }
     // Maybe charge an initial amount to account for upgrading from a cheaper subscription
     $apportion_recurring_price = get_option(WC_Subscriptions_Admin::$option_prefix . '_apportion_recurring_price', 'no');
     $apportion_sign_up_fee = get_option(WC_Subscriptions_Admin::$option_prefix . '_apportion_sign_up_fee', 'no');
     $apportion_length = get_option(WC_Subscriptions_Admin::$option_prefix . '_apportion_length', 'no');
     foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
         if (!isset($cart_item['subscription_switch']['subscription_key'])) {
             continue;
         }
         $old_subscription_key = $cart_item['subscription_switch']['subscription_key'];
         $item_data = $cart_item['data'];
         $product_id = empty($cart_item['variation_id']) ? $cart_item['product_id'] : $cart_item['variation_id'];
         $product = get_product($product_id);
         // Set the date on which the first payment for the new subscription should be charged
         $woocommerce->cart->cart_contents[$cart_item_key]['subscription_switch']['first_payment_timestamp'] = $cart_item['subscription_switch']['next_payment_timestamp'];
         $is_virtual_product = 'no' != $item_data->virtual ? true : false;
         // Add any extra sign up fees required to switch to the new subscription
         if ('yes' == $apportion_sign_up_fee) {
             $old_subscription = WC_Subscriptions_Manager::get_subscription($old_subscription_key);
             $sign_up_fee_due = $product->subscription_sign_up_fee;
             if (self::order_contains_subscription_switch($old_subscription['order_id'])) {
                 $old_order = new WC_Order($old_subscription['order_id']);
                 $sign_up_fee_paid = $old_order->get_total();
             } else {
                 $sign_up_fee_paid = WC_Subscriptions_Order::get_item_sign_up_fee($old_subscription['order_id'], $old_subscription['product_id']);
             }
             $woocommerce->cart->cart_contents[$cart_item_key]['data']->subscription_sign_up_fee = max($sign_up_fee_due - $sign_up_fee_paid, 0);
         } elseif ('no' == $apportion_sign_up_fee) {
             // $0 the initial sign-up fee
             $woocommerce->cart->cart_contents[$cart_item_key]['data']->subscription_sign_up_fee = 0;
         }
         // Now lets see if we should add an apportioned amount to the sign-up fee (for upgrades) or extend the next payment date (for downgrades)
         if ('yes' == $apportion_recurring_price || 'virtual' == $apportion_recurring_price && $is_virtual_product) {
             // Get the current subscription
             $old_subscription = isset($old_subscription) ? $old_subscription : WC_Subscriptions_Manager::get_subscription($old_subscription_key);
             // Get the current subscription's original order
             $old_order = isset($old_order) ? $old_order : new WC_Order($old_subscription['order_id']);
             // Get the current subscription's last payment date
             $last_payment_timestamp = WC_Subscriptions_Manager::get_last_payment_date($old_subscription_key, get_current_user_id(), 'timestamp');
             $days_since_last_payment = round((gmdate('U') - $last_payment_timestamp) / (60 * 60 * 24));
             // Get the current subscription's next payment date
             $next_payment_timestamp = $cart_item['subscription_switch']['next_payment_timestamp'];
             $days_until_next_payment = round(($next_payment_timestamp - gmdate('U')) / (60 * 60 * 24));
             // Find the number of days between the two
             $days_in_old_cycle = $days_until_next_payment + $days_since_last_payment;
             // Find the $price per day for the old subscription's recurring total
             $old_recurring_total = WC_Subscriptions_Order::get_item_recurring_amount($old_subscription['order_id'], $old_subscription['product_id']);
             $old_price_per_day = $old_recurring_total / $days_in_old_cycle;
             // Find the price per day for the new subscription's recurring total
             // If the subscription uses the same billing interval & cycle as the old subscription,
             if ($item_data->subscription_period == $old_subscription['period'] && $item_data->subscription_period_interval == $old_subscription['interval']) {
                 $days_in_new_cycle = $days_in_old_cycle;
                 // Use $days_in_old_cycle to make sure they're consistent
                 $new_price_per_day = $product->subscription_price / $days_in_old_cycle;
             } else {
                 // We need to figure out the price per day for the new subscription based on its billing schedule
                 switch ($item_data->subscription_period) {
                     case 'day':
                         $days_in_new_cycle = $item_data->subscription_period_interval;
                         break;
                     case 'week':
                         $days_in_new_cycle = $item_data->subscription_period_interval * 7;
                         break;
                     case 'month':
                         $days_in_new_cycle = $item_data->subscription_period_interval * 30.4375;
                         // Average days per month over 4 year period
                         break;
                     case 'year':
                         $days_in_new_cycle = $item_data->subscription_period_interval * 365.25;
                         // Average days per year over 4 year period
                         break;
                 }
                 $new_price_per_day = $product->subscription_price / $days_in_new_cycle;
             }
             // If the customer is upgrading, we may need to add a gap payment to the sign-up fee or to reduce the pre-paid period (or both)
             if ($old_price_per_day < $new_price_per_day) {
                 // The new subscription may be more expensive, but it's also on a shorter billing cycle, so reduce the next pre-paid term
                 if ($days_in_old_cycle > $days_in_new_cycle) {
                     // Find out how many days at the new price per day the customer would receive for the total amount already paid
                     // (e.g. if the customer paid $10 / month previously, and was switching to a $5 / week subscription, she has pre-paid 14 days at the new price)
                     $pre_paid_days = 0;
                     do {
                         $pre_paid_days++;
                         $new_total_paid = $pre_paid_days * $new_price_per_day;
                     } while ($new_total_paid < $old_recurring_total);
                     // If the total amount the customer has paid entitles her to more days at the new price than she has received, there is no gap payment, just shorten the pre-paid term the appropriate number of days
                     if ($days_since_last_payment < $pre_paid_days) {
                         $woocommerce->cart->cart_contents[$cart_item_key]['subscription_switch']['first_payment_timestamp'] = $last_payment_timestamp + $pre_paid_days * 60 * 60 * 24;
                         // If the total amount the customer has paid entitles her to the same or less days at the new price then start the new subscription from today
                     } else {
                         $woocommerce->cart->cart_contents[$cart_item_key]['subscription_switch']['first_payment_timestamp'] = 0;
                     }
                 } else {
                     $extra_to_pay = $days_until_next_payment * ($new_price_per_day - $old_price_per_day);
                     $woocommerce->cart->cart_contents[$cart_item_key]['data']->subscription_sign_up_fee += round($extra_to_pay, 2);
                 }
                 $woocommerce->cart->cart_contents[$cart_item_key]['subscription_switch']['upgraded_or_downgraded'] = 'upgraded';
                 // If the customer is downgrading, we need to extend the next payment date for n more days
             } elseif ($old_price_per_day > $new_price_per_day && $new_price_per_day > 0) {
                 $old_total_paid = $old_price_per_day * $days_until_next_payment;
                 $new_total_paid = $new_price_per_day;
                 // Find how many more days at the new lower price it takes to exceed the amount already paid
                 for ($days_to_add = 1; $new_total_paid <= $old_total_paid; $days_to_add++) {
                     $new_total_paid = $days_to_add * $new_price_per_day;
                 }
                 $days_to_add -= $days_until_next_payment;
                 $woocommerce->cart->cart_contents[$cart_item_key]['subscription_switch']['first_payment_timestamp'] = $next_payment_timestamp + $days_to_add * 60 * 60 * 24;
                 $woocommerce->cart->cart_contents[$cart_item_key]['subscription_switch']['upgraded_or_downgraded'] = 'downgraded';
             }
             // The old price per day == the new price per day, no need to change anything
         }
         // Finally, if we need to make sure the initial total doesn't include any recurring amount, we can by spoofing a free trial
         if (0 != $woocommerce->cart->cart_contents[$cart_item_key]['subscription_switch']['first_payment_timestamp']) {
             $woocommerce->cart->cart_contents[$cart_item_key]['data']->subscription_trial_length = 1;
         }
         if ('yes' == $apportion_length || 'virtual' == $apportion_length && $is_virtual_product) {
             // Maybe charge an initial amount to account for upgrading from a cheaper subscription
             $base_length = WC_Subscriptions_Product::get_length($product_id);
             $completed_payments = WC_Subscriptions_Manager::get_subscriptions_completed_payment_count($old_subscription_key);
             $length_remaining = $base_length - $completed_payments;
             // Default to the base length if more payments have already been made than this subscription requires
             if ($length_remaining < 0) {
                 $length_remaining = $base_length;
             }
             $woocommerce->cart->cart_contents[$cart_item_key]['data']->subscription_length = $length_remaining;
         }
     }
     return $total;
 }
 /**
  * Process the payment and return the result
  *
  * @access public
  * @param int $order_id
  * @return array
  */
 public function process_payment($order_id)
 {
     $this->init_mijireh();
     $mj_order = new Mijireh_Order();
     $wc_order = new WC_Order($order_id);
     // Avoid rounding issues altogether by sending the order as one lump
     if (get_option('woocommerce_prices_include_tax') == 'yes') {
         // Don't pass items - Pass 1 item for the order items overall
         $item_names = array();
         if (sizeof($wc_order->get_items()) > 0) {
             foreach ($wc_order->get_items() as $item) {
                 if ($item['qty']) {
                     $item_names[] = $item['name'] . ' x ' . $item['qty'];
                 }
             }
         }
         $mj_order->add_item(sprintf(__('Order %s', 'woocommerce'), $wc_order->get_order_number()) . " - " . implode(', ', $item_names), number_format($wc_order->get_total() - round($wc_order->get_total_shipping() + $wc_order->get_shipping_tax(), 2) + $wc_order->get_order_discount(), 2, '.', ''), 1);
         if ($wc_order->get_total_shipping() + $wc_order->get_shipping_tax() > 0) {
             $mj_order->shipping = number_format($wc_order->get_total_shipping() + $wc_order->get_shipping_tax(), 2, '.', '');
         }
         $mj_order->show_tax = false;
         // No issues when prices exclude tax
     } else {
         // 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, false, true), $item['qty'], $product->get_sku());
         }
         // Handle fees
         $items = $wc_order->get_fees();
         foreach ($items as $item) {
             $mj_order->add_item($item['name'], number_format($item['line_total'], 2, '.', ','), 1, '');
         }
         $mj_order->shipping = round($wc_order->get_total_shipping(), 2);
         $mj_order->tax = $wc_order->get_total_tax();
     }
     // set order totals
     $mj_order->total = $wc_order->get_total();
     $mj_order->discount = $wc_order->get_total_discount();
     // 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;
     // 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 = WC()->api_request_url('WC_Gateway_Mijireh');
     // 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) {
         wc_add_notice(__('Mijireh error:', 'woocommerce') . $e->getMessage() . print_r($mj_order, true), 'error');
     }
 }
Пример #30
-1
 public function getRefMoney()
 {
     $sum_ref = 0;
     $args = array('post_type' => 'shop_order', 'post_status' => 'publish', 'posts_per_page' => 10, 'tax_query' => array(array('taxonomy' => 'shop_order_status', 'field' => 'slug', 'terms' => array('completed'))));
     $arr = $this->get_refals();
     $orders = get_posts($args);
     foreach ($orders as $order) {
         #print_r ($order);
         $info = new WC_Order($order->ID);
         #print $info->user_id;
         /*My Orders */
         if ($info->user_id == $this->id) {
             $this->orders[] = $info;
         }
         if (!$this->in_ref($info->user_id, $arr)) {
             continue;
         }
         $sum = $info->get_total();
         $sum_ref += $sum;
     }
     if ($sum_ref > 0) {
         $sum_ref = $sum_ref * 0.1;
     }
     return $sum_ref;
 }