/**
 * tax is included function
 *
 * @uses wpec_taxes_controller
 *
 * @return boolean true or false depending on settings>general page
 */
function wpsc_tax_isincluded()
{
    //uses new wpec_taxes functionality now
    require_once WPSC_FILE_PATH . '/wpsc-taxes/taxes_module.php';
    $wpec_taxes_controller = new wpec_taxes_controller();
    return $wpec_taxes_controller->wpec_taxes_isincluded();
}
Example #2
0
/**
 * @description: wpec_taxes_ajax_controller - controller for any ajax
 *               functions needed for wpec_taxes
 * @param: void
 * @return: null
 * */
function wpec_taxes_ajax_controller()
{
    if (!wp_verify_nonce($_POST['nonce'], 'wpsc_settings_page_nonce')) {
        die('Session expired. Try refreshing your settings page.');
    }
    //include taxes controller
    $wpec_taxes_controller = new wpec_taxes_controller();
    switch ($_REQUEST['wpec_taxes_action']) {
        case 'wpec_taxes_get_regions':
            $regions = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_regions($_REQUEST['country_code']);
            $key = $_REQUEST['current_key'];
            $type = $_REQUEST['taxes_type'];
            $default_option = array('region_code' => 'all-markets', 'name' => 'All Markets');
            $select_settings = array('id' => "{$type}-region-{$key}", 'name' => "wpsc_options[wpec_taxes_{$type}][{$key}][region_code]", 'class' => 'wpsc-taxes-region-drop-down');
            $returnable = $wpec_taxes_controller->wpec_taxes_build_select_options($regions, 'region_code', 'name', $default_option, $select_settings);
            break;
        case 'wpec_taxes_build_rates_form':
            $key = $_REQUEST['current_key'];
            $returnable = $wpec_taxes_controller->wpec_taxes_build_form($key);
            break;
        case 'wpec_taxes_build_bands_form':
            $key = $_REQUEST['current_key'];
            //get a new key if a band is already defined for this key
            while ($wpec_taxes_controller->wpec_taxes->wpec_taxes_get_band_from_index($key)) {
                $key++;
            }
            $returnable = $wpec_taxes_controller->wpec_taxes_build_form($key, false, 'bands');
            break;
    }
    // switch
    //return the results
    echo $returnable;
    //die to avoid default 0 in ajax response
    die;
}
function wpsc_is_tax_enabled()
{
    $wpec_taxes_controller = new wpec_taxes_controller();
    return $wpec_taxes_controller->wpec_taxes_isenabled();
}
Example #4
0
/**
 * submit checkout function, used through ajax and in normal page loading.
 * No parameters, returns nothing
 */
function wpsc_submit_checkout()
{
    global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways;
    $num_items = 0;
    $use_shipping = 0;
    $disregard_shipping = 0;
    $_SESSION['wpsc_checkout_misc_error_messages'] = array();
    $wpsc_checkout = new wpsc_checkout();
    $selected_gateways = get_option('custom_gateway_options');
    $submitted_gateway = $_POST['custom_gateway'];
    $options = get_option('custom_shipping_options');
    $form_validity = $wpsc_checkout->validate_forms();
    extract($form_validity);
    // extracts $is_valid and $error_messages
    if ($_POST['agree'] != 'yes') {
        $_SESSION['wpsc_checkout_misc_error_messages'][] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc');
        $is_valid = false;
    }
    $selectedCountry = $wpdb->get_results("SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode='" . $wpdb->escape($_SESSION['wpsc_delivery_country']) . "'", ARRAY_A);
    foreach ($wpsc_cart->cart_items as $cartitem) {
        if ($cartitem->meta[0]['no_shipping'] == 1) {
            continue;
        }
        $categoriesIDs = $cartitem->category_id_list;
        foreach ((array) $categoriesIDs as $catid) {
            if (is_array($catid)) {
                $countries = wpsc_get_meta($catid[0], 'target_market', 'wpsc_category');
            } else {
                $countries = wpsc_get_meta($catid, 'target_market', 'wpsc_category');
            }
            if (!empty($countries) && !in_array($selectedCountry[0]['id'], (array) $countries)) {
                $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc'), $cartitem->product_name, $selectedCountry[0]['country']);
                $_SESSION['categoryAndShippingCountryConflict'] = $errormessage;
                $is_valid = false;
            }
        }
        //count number of items, and number of items using shipping
        $num_items++;
        if ($cartitem->uses_shipping != 1) {
            $disregard_shipping++;
        } else {
            $use_shipping++;
        }
    }
    if (array_search($submitted_gateway, $selected_gateways) !== false) {
        $_SESSION['wpsc_previous_selected_gateway'] = $submitted_gateway;
    } else {
        $is_valid = false;
    }
    if (get_option('do_not_use_shipping') == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null) && $num_items != $disregard_shipping) {
        $_SESSION['wpsc_checkout_misc_error_messages'][] = __('You must select a shipping method, otherwise we cannot process your order.', 'wpsc');
        $is_valid = false;
    }
    if (get_option('do_not_use_shipping') != 1 && in_array('ups', (array) $options) && $_SESSION['wpsc_zipcode'] == '' && $num_items != $disregard_shipping) {
        $_SESSION['categoryAndShippingCountryConflict'] = __('Please enter a Zipcode and click calculate to proceed', 'wpsc');
        $is_valid = false;
    }
    if ($is_valid == true) {
        $_SESSION['categoryAndShippingCountryConflict'] = '';
        // check that the submitted gateway is in the list of selected ones
        $sessionid = mt_rand(100, 999) . time();
        $_SESSION['wpsc_sessionid'] = $sessionid;
        $subtotal = $wpsc_cart->calculate_subtotal();
        if ($wpsc_cart->has_total_shipping_discount() == false) {
            $base_shipping = $wpsc_cart->calculate_base_shipping();
        } else {
            $base_shipping = 0;
        }
        $delivery_country = $wpsc_cart->delivery_country;
        $delivery_region = $wpsc_cart->delivery_region;
        if (wpsc_uses_shipping()) {
            $shipping_method = $wpsc_cart->selected_shipping_method;
            $shipping_option = $wpsc_cart->selected_shipping_option;
        } else {
            $shipping_method = '';
            $shipping_option = '';
        }
        if (isset($_POST['how_find_us'])) {
            $find_us = $_POST['how_find_us'];
        } else {
            $find_us = '';
        }
        //keep track of tax if taxes are exclusive
        $wpec_taxes_controller = new wpec_taxes_controller();
        if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
            $tax = $wpsc_cart->calculate_total_tax();
            $tax_percentage = $wpsc_cart->tax_percentage;
        } else {
            $tax = 0.0;
            $tax_percentage = 0.0;
        }
        $total = $wpsc_cart->calculate_total_price();
        $wpdb->insert(WPSC_TABLE_PURCHASE_LOGS, array('totalprice' => $total, 'statusno' => '0', 'sessionid' => $sessionid, 'user_ID' => (int) $user_ID, 'date' => strtotime(current_time('mysql')), 'gateway' => $submitted_gateway, 'billing_country' => $wpsc_cart->selected_country, 'shipping_country' => $delivery_country, 'billing_region' => $wpsc_cart->selected_region, 'shipping_region' => $delivery_region, 'base_shipping' => $base_shipping, 'shipping_method' => $shipping_method, 'shipping_option' => $shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name, 'find_us' => $find_us, 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage));
        $purchase_log_id = $wpdb->insert_id;
        $wpsc_checkout->save_forms_to_db($purchase_log_id);
        $wpsc_cart->save_to_db($purchase_log_id);
        $wpsc_cart->submit_stock_claims($purchase_log_id);
        if (get_option('wpsc_also_bought') == 1) {
            wpsc_populate_also_bought_list();
        }
        if (!isset($our_user_id) && isset($user_ID)) {
            $our_user_id = $user_ID;
        }
        $wpsc_cart->log_id = $purchase_log_id;
        do_action('wpsc_submit_checkout', array("purchase_log_id" => $purchase_log_id, "our_user_id" => $our_user_id));
        if (get_option('permalink_structure') != '') {
            $separator = "?";
        } else {
            $separator = "&";
        }
        // submit to gateway
        $current_gateway_data =& $wpsc_gateways[$submitted_gateway];
        if ($current_gateway_data['api_version'] >= 2.0) {
            $merchant_instance = new $current_gateway_data['class_name']($purchase_log_id);
            $merchant_instance->construct_value_array();
            $merchant_instance->submit();
        } elseif ($current_gateway_data['internalname'] == $submitted_gateway && $current_gateway_data['internalname'] != 'google') {
            $gateway_used = $current_gateway_data['internalname'];
            $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('gateway' => $gateway_used), array('id' => $log_id));
            $current_gateway_data['function']($separator, $sessionid);
        } elseif ($current_gateway_data['internalname'] == 'google' && $current_gateway_data['internalname'] == $submitted_gateway) {
            $gateway_used = $current_gateway_data['internalname'];
            $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('gateway' => $gateway_used), array('id' => $log_id));
            $_SESSION['gateway'] = 'google';
            wp_redirect(get_option('shopping_cart_url'));
        }
    }
}
Example #5
0
 /**
  * save to database method
  * @access public
  *
  * @param integer purchase log id
  */
 function save_to_db($purchase_log_id)
 {
     global $wpdb, $wpsc_shipping_modules;
     $method = $this->cart->selected_shipping_method;
     $shipping = 0;
     if (!empty($method) && method_exists($wpsc_shipping_modules[$method], "get_item_shipping")) {
         $shipping = $wpsc_shipping_modules[$this->cart->selected_shipping_method]->get_item_shipping($this);
     }
     if ($this->cart->has_total_shipping_discount()) {
         $shipping = 0;
     }
     $shipping = apply_filters('wpsc_item_shipping_amount_db', $shipping, $this);
     //initialize tax variables
     $tax = 0;
     $tax_rate = 0;
     //wpec_taxes - calculate product tax and add to total price
     $wpec_taxes_controller = new wpec_taxes_controller();
     if ($wpec_taxes_controller->wpec_taxes_isincluded() && $wpec_taxes_controller->wpec_taxes_isenabled()) {
         $taxes = $wpec_taxes_controller->wpec_taxes_calculate_included_tax($this);
         $tax_rate = $taxes['rate'];
         $tax = $taxes['tax'];
     }
     $wpdb->insert(WPSC_TABLE_CART_CONTENTS, array('prodid' => $this->product_id, 'name' => $this->get_title(), 'purchaseid' => $purchase_log_id, 'price' => $this->unit_price, 'pnp' => $shipping, 'tax_charged' => $tax, 'gst' => $tax_rate, 'quantity' => $this->quantity, 'donation' => $this->is_donation, 'no_shipping' => 0, 'custom_message' => $this->custom_message, 'files' => serialize($this->custom_file), 'meta' => NULL), array('%d', '%s', '%d', '%f', '%f', '%f', '%f', '%s', '%d', '%d', '%s', '%s', '%s'));
     $cart_id = $wpdb->get_var("SELECT " . $wpdb->insert_id . " AS `id` FROM `" . WPSC_TABLE_CART_CONTENTS . "` LIMIT 1");
     wpsc_update_cartmeta($cart_id, 'sku', $this->sku);
     $downloads = get_option('max_downloads');
     if ($this->is_downloadable == true) {
         $product_files = (array) get_posts(array('post_type' => 'wpsc-product-file', 'post_parent' => $this->product_id, 'numberposts' => -1, 'post_status' => 'inherit'));
         foreach ($product_files as $file) {
             // if the file is downloadable, check that the file is real
             $unique_id = sha1(uniqid(mt_rand(), true));
             $wpdb->insert(WPSC_TABLE_DOWNLOAD_STATUS, array('product_id' => $this->product_id, 'fileid' => $file->ID, 'purchid' => $purchase_log_id, 'cartid' => $cart_id, 'uniqueid' => $unique_id, 'downloads' => $downloads, 'active' => 0, 'datetime' => date('Y-m-d H:i:s')), array('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s'));
             $download_id = $wpdb->get_var("SELECT " . $wpdb->insert_id . " AS `id` FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` LIMIT 1");
             wpsc_update_meta($download_id, '_is_legacy', 'false', 'wpsc_downloads');
         }
     }
     do_action('wpsc_save_cart_item', $cart_id, $this->product_id);
 }
Example #6
0
/**
 * Add tax rate
 * @since  3.8.9
 * @access private
 *
 * @uses wpec_taxes_controller                                                  Contains all the logic to communicate with the taxes system
 * @uses wpec_taxes_controller::wpec_taxes::wpec_taxes_get_regions()            Gets tax regions based on input country code
 * @uses wpec_taxes_controller::wpec_taxes_build_select_options()               Returns HTML formatted options from input array
 * @uses wpec_taxes_controller::wpec_taxes_build_form()                         Builds the tax rate form
 * @uses wpec_taxes_controller::wpec_taxes::wpec_taxes_get_band_from_index()    Retrieves tax band for given name
 *
 * @return array|WP_Error Response args if successful, WP_Error if otherwise
 */
function _wpsc_ajax_add_tax_rate()
{
    //include taxes controller
    $wpec_taxes_controller = new wpec_taxes_controller();
    switch ($_REQUEST['wpec_taxes_action']) {
        case 'wpec_taxes_get_regions':
            $regions = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_regions($_REQUEST['country_code']);
            $key = $_REQUEST['current_key'];
            $type = $_REQUEST['taxes_type'];
            $default_option = array('region_code' => 'all-markets', 'name' => 'All Markets');
            $select_settings = array('id' => "{$type}-region-{$key}", 'name' => "wpsc_options[wpec_taxes_{$type}][{$key}][region_code]", 'class' => 'wpsc-taxes-region-drop-down');
            $returnable = $wpec_taxes_controller->wpec_taxes_build_select_options($regions, 'region_code', 'name', $default_option, $select_settings);
            break;
    }
    // switch
    return array('content' => $returnable);
}
Example #7
0
    public function display()
    {
        $wpec_taxes_controller = new wpec_taxes_controller();
        $wpec_taxes_options = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_options();
        ?>
				<h3><?php 
        _e('Tax Settings', 'wpsc');
        ?>
</h3>
				<p>
					<label for='wpec_taxes_enabled'>
						<input <?php 
        if ($wpec_taxes_options['wpec_taxes_enabled']) {
            echo 'checked="checked"';
        }
        ?>
 type="checkbox" id='wpec_taxes_enabled' name='wpsc_options[wpec_taxes_enabled]' />
	<?php 
        _e('Turn tax on', 'wpsc');
        ?>
				</label>
			</p>
			<p>
				<label for='wpec_taxes_inprice1'>
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_inprice'] == 'exclusive') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='exclusive' id='wpec_taxes_inprice1' name='wpsc_options[wpec_taxes_inprice]' />
	<?php 
        _e('Product prices are tax exclusive - add tax to the price during checkout', 'wpsc');
        ?>
				</label>
			</p>
			<p>
				<label for='wpec_taxes_inprice2'>
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_inprice'] == 'inclusive') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='inclusive' id='wpec_taxes_inprice2' name='wpsc_options[wpec_taxes_inprice]' />
	<?php 
        _e("Product prices are tax inclusive - during checkout the total price doesn't increase but tax is shown as a line item", 'wpsc');
        ?>
				</label>
			</p>
			<h4><?php 
        _e('Product Specific Tax', 'wpsc');
        ?>
</h4>
			<p>
				<label for='wpec_taxes_product_1'>
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_product'] == 'add') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='add' id='wpec_taxes_product_1' name='wpsc_options[wpec_taxes_product]' />
	<?php 
        _e('Add per product tax to tax percentage if product has a specific tax rate', 'wpsc');
        ?>
				</label>
			</p>
			<p>
				<label for='wpec_taxes_product_2'>
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_product'] == 'replace') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='replace' id='wpec_taxes_product_2' name='wpsc_options[wpec_taxes_product]' />
	<?php 
        _e('Replace tax percentage with product specific tax rate', 'wpsc');
        ?>
				</label>
			</p>

			<h4><?php 
        _e('Tax Logic', 'wpsc');
        ?>
</h4>
			<p>
				<label for='wpec_taxes_logic_1'>
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_logic'] == 'billing_shipping') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='billing_shipping' id='wpec_taxes_logic_1' name='wpsc_options[wpec_taxes_logic]' />
						<?php 
        _e('Apply tax when Billing and Shipping Country is the same as Tax Rate', 'wpsc');
        ?>
				</label>
			<div id='billing_shipping_preference_container' style='margin-left: 20px;'>
	            <p>
					<label for='wpec_billing_preference'>
						<input <?php 
        if ($wpec_taxes_options['wpec_taxes_logic'] == 'billing_shipping' && $wpec_taxes_options['wpec_billing_shipping_preference'] == 'billing_address') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='billing_address' id='wpec_billing_preference' name='wpsc_options[wpec_billing_shipping_preference]' />
					<?php 
        _e('Apply tax to Billing Address', 'wpsc');
        ?>
						</label>
		            </p>
		            <p>
						<label for='wpec_shipping_preference'>
							<input <?php 
        if ($wpec_taxes_options['wpec_taxes_logic'] == 'billing_shipping' && $wpec_taxes_options['wpec_billing_shipping_preference'] == 'shipping_address') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='shipping_address' id='wpec_shipping_preference' name='wpsc_options[wpec_billing_shipping_preference]' />
	<?php 
        _e('Apply tax to Shipping Address', 'wpsc');
        ?>
						</label>
		            </p>
				</div>
				</p>
				<p>
					<label for='wpec_taxes_logic_2'>
						<input <?php 
        if ($wpec_taxes_options['wpec_taxes_logic'] == 'billing') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='billing' id='wpec_taxes_logic_2' name='wpsc_options[wpec_taxes_logic]' />
						<?php 
        _e('Apply tax when Billing Country is the same as Tax Rate', 'wpsc');
        ?>
				</label>
			</p>
			<p>
				<label for='wpec_taxes_logic_3'>
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_logic'] == 'shipping') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='shipping' id='wpec_taxes_logic_3' name='wpsc_options[wpec_taxes_logic]' />
						<?php 
        _e('Apply tax when Shipping Country is the same as Tax Rate', 'wpsc');
        ?>
				</label>
			</p>
			<div id='metabox-holder' class="metabox-holder">
				<div id='wpec-taxes-rates-container' class='postbox'>
					<h3 class='hndle' style='cursor: default'><?php 
        _e('Tax Rates', 'wpsc');
        ?>
</h3>
					<div id='wpec-taxes-rates' class='inside'>
						<!--Start Taxes Output-->
	<?php 
        /**
        						 * Add New Tax Rate - should add another paragraph with the
        						  another key specified for the input array
        						 * Delete - Should remove the given paragraph from the page
        						  and either ajax delete it from the DB or mark it for
        						  deletion and process it after the changes are made.
        						 * Selecting a Country - should automatically populate the
        						  regions select box. Selecting a different country should
        						  remove the region select box. If the user selects a
        						  different country with regions it shouldn't matter because
        						  the code should automatically add the region select in.
        						 *  - Allow users to define tax for entire country even if regions exist.
        						 * Shipping Tax - needs to be per region or per tax rate.
        						  Remove the setting from the main Tax Settings area.
        						 * Constraints -
        						  1. Should not allow a user to add more than one
        						  tax rate for the same area.
        						  2. If a country tax rate is specified and then a region tax
        						  rate, the region tax rate takes precedence.
        						 * */
        /**
        	                 * Removed Shipping Restriction on Included tax - 01-20-2011
        						//if tax is included warn about shipping
        						if ( $wpec_taxes_controller->wpec_taxes_isincluded() ) {
        							echo '<p>' . __( 'Note: Tax is not applied to shipping when product prices are tax inclusive.' ) . '</p>';
        						}// if
        	               **/
        //get current tax rates
        // TODO: Refactor to get rid of the need for wpec_taxes_build_form(). It's a horribly written function.
        $tax_rates = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_rates();
        $tax_rate_count = 0;
        if (!empty($tax_rates)) {
            foreach ($tax_rates as $tax_rate) {
                echo $wpec_taxes_controller->wpec_taxes_build_form($tax_rate_count, $tax_rate);
                $tax_rate_count++;
            }
            // foreach
        }
        // if
        ?>
						<!--End Taxes Output-->
						<p id="wpsc-add-tax-rates">
							<a href="#"><?php 
        _e('Add New Tax Rate', 'wpsc');
        ?>
</a>
							<img src="<?php 
        echo esc_url(admin_url('images/wpspin_light.gif'));
        ?>
" class="ajax-feedback" title="" alt="" />
						</p>
					</div>
				</div>
				<div id='wpec-taxes-bands-container' class='postbox'>
					<h3 class='hndle' style='cursor: default'><?php 
        _e('Tax Bands', 'wpsc');
        ?>
</h3>
					<div id='wpec-taxes-bands' class='inside'>

	<?php 
        echo '<p>' . __('Note: Tax Bands are special tax rules you can create and apply on a per-product basis. <br /> Please visit the product page to apply your Tax Band.', 'wpsc') . '</p>';
        //echo message regarding inclusive tax
        if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
            echo '<p>' . __('Note: Tax Bands do not take affect when product prices are tax exclusive.', 'wpsc') . '</p>';
        }
        // if
        $tax_bands = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_bands();
        $tax_band_count = 0;
        if (!empty($tax_bands)) {
            foreach ($tax_bands as $tax_band) {
                echo $wpec_taxes_controller->wpec_taxes_build_form($tax_band_count, $tax_band, 'bands');
                $tax_band_count++;
            }
            // foreach
        }
        // if
        ?>
						<p id="wpsc-add-tax-bands">
							<a href="#"><?php 
        _e('Add New Tax Band', 'wpsc');
        ?>
</a>
							<img src="<?php 
        echo esc_url(admin_url('images/wpspin_light.gif'));
        ?>
" class="ajax-feedback" title="" alt="" />
									</p>
								</div>
							</div><!--wpec-taxes-bands-container-->
						</div><!--metabox-holder-->
		<?php 
    }
Example #8
0
/**
 * Add tax rate
 * @since  3.8.9
 * @access private
 * @return array|WP_Error Response args if successful, WP_Error if otherwise
 */
function _wpsc_ajax_add_tax_rate()
{
    //include taxes controller
    $wpec_taxes_controller = new wpec_taxes_controller();
    switch ($_REQUEST['wpec_taxes_action']) {
        case 'wpec_taxes_get_regions':
            $regions = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_regions($_REQUEST['country_code']);
            $key = $_REQUEST['current_key'];
            $type = $_REQUEST['taxes_type'];
            $default_option = array('region_code' => 'all-markets', 'name' => 'All Markets');
            $select_settings = array('id' => "{$type}-region-{$key}", 'name' => "wpsc_options[wpec_taxes_{$type}][{$key}][region_code]", 'class' => 'wpsc-taxes-region-drop-down');
            $returnable = $wpec_taxes_controller->wpec_taxes_build_select_options($regions, 'region_code', 'name', $default_option, $select_settings);
            break;
        case 'wpec_taxes_build_rates_form':
            $key = $_REQUEST['current_key'];
            $returnable = $wpec_taxes_controller->wpec_taxes_build_form($key);
            break;
        case 'wpec_taxes_build_bands_form':
            $key = $_REQUEST['current_key'];
            //get a new key if a band is already defined for this key
            while ($wpec_taxes_controller->wpec_taxes->wpec_taxes_get_band_from_index($key)) {
                $key++;
            }
            $returnable = $wpec_taxes_controller->wpec_taxes_build_form($key, false, 'bands');
            break;
    }
    // switch
    return array('content' => $returnable);
}
Example #9
0
 /**
  * calculate total tax method
  *
  * @access public
  * @return float returns the price as a floating point value
  */
 function calculate_total_tax()
 {
     $wpec_taxes_controller = new wpec_taxes_controller();
     $taxes_total = $wpec_taxes_controller->wpec_taxes_calculate_total();
     $this->total_tax = $taxes_total['total'];
     if (isset($taxes_total['rate'])) {
         $this->tax_percentage = $taxes_total['rate'];
     }
     return apply_filters('wpsc_calculate_total_tax', $this->total_tax, $this);
 }
Example #10
0
/**
 * submit checkout function, used through ajax and in normal page loading.
 * No parameters, returns nothing
 */
function wpsc_submit_checkout($collected_data = true)
{
    global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways;
    if ($collected_data && isset($_POST['collected_data']) && is_array($_POST['collected_data'])) {
        _wpsc_checkout_customer_meta_update($_POST['collected_data']);
    }
    // initialize our checkout status variab;e, we start be assuming
    // checkout is falid, until we find a reason otherwise
    $is_valid = true;
    $num_items = 0;
    $use_shipping = 0;
    $disregard_shipping = 0;
    do_action('wpsc_before_submit_checkout');
    $error_messages = wpsc_get_customer_meta('checkout_misc_error_messages');
    if (!is_array($error_messages)) {
        $error_messages = array();
    }
    $wpsc_checkout = new wpsc_checkout();
    $selected_gateways = get_option('custom_gateway_options');
    $submitted_gateway = isset($_POST['custom_gateway']) ? $_POST['custom_gateway'] : '';
    if ($collected_data) {
        $form_validity = $wpsc_checkout->validate_forms();
        extract($form_validity);
        // extracts $is_valid and $error_messages
        if (wpsc_has_tnc() && (!isset($_POST['agree']) || $_POST['agree'] != 'yes')) {
            $error_messages[] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc');
            $is_valid = false;
        }
    } else {
        $is_valid = true;
        $error_messages = array();
    }
    $wpsc_country = new WPSC_Country(wpsc_get_customer_meta('shippingcountry'));
    $country_id = $wpsc_country->get_id();
    $country_name = $wpsc_country->get_name();
    foreach ($wpsc_cart->cart_items as $cartitem) {
        if (!empty($cartitem->meta[0]['no_shipping'])) {
            continue;
        }
        $categoriesIDs = $cartitem->category_id_list;
        foreach ((array) $categoriesIDs as $catid) {
            if (is_array($catid)) {
                $countries = wpsc_get_meta($catid[0], 'target_market', 'wpsc_category');
            } else {
                $countries = wpsc_get_meta($catid, 'target_market', 'wpsc_category');
            }
            if (!empty($countries) && !in_array($country_id, (array) $countries)) {
                $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc'), $cartitem->get_title(), $country_name);
                wpsc_update_customer_meta('category_shipping_conflict', $errormessage);
                $is_valid = false;
            }
        }
        //count number of items, and number of items using shipping
        $num_items++;
        if ($cartitem->uses_shipping != 1) {
            $disregard_shipping++;
        } else {
            $use_shipping++;
        }
    }
    // check to see if the current gateway is in the list of available gateways
    if (array_search($submitted_gateway, $selected_gateways) !== false) {
        wpsc_update_customer_meta('selected_gateway', $submitted_gateway);
    } else {
        $is_valid = false;
    }
    if ($collected_data) {
        // Test for required shipping information
        if (wpsc_core_shipping_enabled() && $num_items != $disregard_shipping) {
            // for shipping to work we need a method, option and a quote
            if (!$wpsc_cart->shipping_method_selected() || !$wpsc_cart->shipping_quote_selected()) {
                $error_messages[] = __('Please select one of the available shipping options, then we can process your order.', 'wpsc');
                $is_valid = false;
            }
            // if we don't have a valid zip code ( the function also checks if we need it ) we have an error
            if (!wpsc_have_valid_shipping_zipcode()) {
                wpsc_update_customer_meta('category_shipping_conflict', __('Please enter a Zipcode and click calculate to proceed', 'wpsc'));
                $is_valid = false;
            }
        }
    }
    wpsc_update_customer_meta('checkout_misc_error_messages', $error_messages);
    if ($is_valid == true) {
        wpsc_delete_customer_meta('category_shipping_conflict');
        // check that the submitted gateway is in the list of selected ones
        $sessionid = mt_rand(100, 999) . time();
        wpsc_update_customer_meta('checkout_session_id', $sessionid);
        $subtotal = $wpsc_cart->calculate_subtotal();
        if ($wpsc_cart->has_total_shipping_discount() == false) {
            $base_shipping = $wpsc_cart->calculate_base_shipping();
        } else {
            $base_shipping = 0;
        }
        $delivery_country = $wpsc_cart->delivery_country;
        $delivery_region = $wpsc_cart->delivery_region;
        if (wpsc_uses_shipping()) {
            $shipping_method = $wpsc_cart->selected_shipping_method;
            $shipping_option = $wpsc_cart->selected_shipping_option;
        } else {
            $shipping_method = '';
            $shipping_option = '';
        }
        if (isset($_POST['how_find_us'])) {
            $find_us = $_POST['how_find_us'];
        } else {
            $find_us = '';
        }
        //keep track of tax if taxes are exclusive
        $wpec_taxes_controller = new wpec_taxes_controller();
        if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
            $tax = $wpsc_cart->calculate_total_tax();
            $tax_percentage = $wpsc_cart->tax_percentage;
        } else {
            $tax = 0.0;
            $tax_percentage = 0.0;
        }
        $total = $wpsc_cart->calculate_total_price();
        $args = array('totalprice' => $total, 'statusno' => '0', 'sessionid' => $sessionid, 'user_ID' => (int) $user_ID, 'date' => time(), 'gateway' => $submitted_gateway, 'billing_country' => $wpsc_cart->selected_country, 'shipping_country' => $delivery_country, 'billing_region' => $wpsc_cart->selected_region, 'shipping_region' => $delivery_region, 'base_shipping' => $base_shipping, 'shipping_method' => $shipping_method, 'shipping_option' => $shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name, 'find_us' => $find_us, 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage);
        $purchase_log = new WPSC_Purchase_Log($args);
        $purchase_log->save();
        $purchase_log_id = $purchase_log->get('id');
        if ($collected_data) {
            $wpsc_checkout->save_forms_to_db($purchase_log_id);
        }
        $wpsc_cart->save_to_db($purchase_log_id);
        $wpsc_cart->submit_stock_claims($purchase_log_id);
        if (!isset($our_user_id) && isset($user_ID)) {
            $our_user_id = $user_ID;
        }
        $wpsc_cart->log_id = $purchase_log_id;
        do_action('wpsc_submit_checkout', array('purchase_log_id' => $purchase_log_id, 'our_user_id' => $our_user_id));
        do_action('wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log);
    }
}
function wpsc_product_taxes_forms()
{
    global $post, $wpdb, $wpsc_product_defaults;
    $product_data = get_post_custom($post->ID);
    $product_data['meta'] = $product_meta = array();
    if (!empty($product_data['_wpsc_product_metadata'])) {
        $product_data['meta'] = $product_meta = maybe_unserialize($product_data['_wpsc_product_metadata'][0]);
    }
    if (!isset($product_data['meta']['_wpsc_custom_tax'])) {
        $product_data['meta']['_wpsc_custom_tax'] = '';
    }
    $custom_tax = $product_data['meta']['_wpsc_custom_tax'];
    if (!isset($product_meta['custom_tax'])) {
        $product_meta['custom_tax'] = 0.0;
    }
    //Add New WPEC-Taxes Bands Here
    $wpec_taxes_controller = new wpec_taxes_controller();
    //display tax bands
    $band_select_settings = array('id' => 'wpec_taxes_band', 'name' => 'meta[_wpsc_product_metadata][wpec_taxes_band]', 'label' => __('Custom Tax Band', 'wpsc'));
    $wpec_taxes_band = '';
    if (isset($product_meta['wpec_taxes_band'])) {
        $band = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_band_from_index($product_meta['wpec_taxes_band']);
        $wpec_taxes_band = array('index' => $band['index'], 'name' => $band['name']);
    }
    $taxable_checkbox_settings = array('type' => 'checkbox', 'id' => 'wpec_taxes_taxable', 'name' => 'meta[_wpsc_product_metadata][wpec_taxes_taxable]', 'label' => __('This product is not taxable.', 'wpsc'));
    if (isset($product_meta['wpec_taxes_taxable']) && 'on' == $product_meta['wpec_taxes_taxable']) {
        $taxable_checkbox_settings['checked'] = 'checked';
    }
    //add taxable amount only for exclusive tax
    if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
        $taxable_amount_input_settings = array('id' => 'wpec_taxes_taxable_amount', 'name' => 'meta[_wpsc_product_metadata][wpec_taxes_taxable_amount]', 'label' => __('Taxable Amount', 'wpsc'), 'description' => __('Taxable amount in your currency, not percentage of price.', 'wpsc'));
        if (isset($product_meta['wpec_taxes_taxable_amount'])) {
            $taxable_amount_input_settings['value'] = $product_meta['wpec_taxes_taxable_amount'];
        }
    }
    // if
    ?>
			<a name="wpsc_tax"></a>
            <p><?php 
    echo $wpec_taxes_controller->wpec_taxes_display_tax_bands($band_select_settings, $wpec_taxes_band);
    ?>
</p>
				<p>
					<?php 
    if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
        ?>
						<?php 
        echo $wpec_taxes_controller->wpec_taxes_build_input($taxable_amount_input_settings);
        ?>
					<?php 
    }
    ?>
				</p>
            <p><?php 
    echo $wpec_taxes_controller->wpec_taxes_build_input($taxable_checkbox_settings);
    ?>
</p>
<?php 
}
/**
 * transaction_results function main function for creating the purchase reports, transaction results page, and email receipts
 * @access public
 *
 * @since 3.7
 * @param $sessionid (string) unique session id
 * @param echo_to_screen (boolean) whether to output the results or return them (potentially redundant)
 * @param $transaction_id (int) the transaction id
 */
function transaction_results($sessionid, $display_to_screen = true, $transaction_id = null)
{
    // Do we seriously need this many globals?
    global $wpdb, $wpsc_cart, $echo_to_screen, $purchase_log, $order_url;
    global $message_html, $cart, $errorcode, $wpsc_purchlog_statuses, $wpsc_gateways;
    $wpec_taxes_controller = new wpec_taxes_controller();
    $is_transaction = false;
    $errorcode = 0;
    $purchase_log = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= %s LIMIT 1", $sessionid), ARRAY_A);
    $order_status = $purchase_log['processed'];
    $curgateway = $purchase_log['gateway'];
    if (!is_bool($display_to_screen)) {
        $display_to_screen = true;
    }
    $echo_to_screen = $display_to_screen;
    //new variable to check whether function is being called from wpsc_purchlog_resend_email()
    $resend_email = isset($_REQUEST['email_buyer_id']) ? true : false;
    if (is_numeric($sessionid)) {
        if ($echo_to_screen) {
            echo apply_filters('wpsc_pre_transaction_results', '');
        }
        // New code to check whether transaction is processed, true if accepted false if pending or incomplete
        $is_transaction = wpsc_check_purchase_processed($purchase_log['processed']);
        $message_html = $message = stripslashes(get_option('wpsc_email_receipt'));
        if ($is_transaction) {
            $message = __('The Transaction was successful', 'wpsc') . "\r\n" . $message;
            $message_html = __('The Transaction was successful', 'wpsc') . "<br />" . $message_html;
        }
        $country = get_option('country_form_field');
        $billing_country = '';
        $shipping_country = '';
        if (!empty($purchase_log['shipping_country'])) {
            $billing_country = $purchase_log['billing_country'];
            $shipping_country = $purchase_log['shipping_country'];
        } elseif (!empty($country)) {
            $country = $wpdb->get_var($wpdb->prepare("SELECT `value` FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = %d AND `form_id` = %d LIMIT 1", $purchase_log['id'], get_option('country_form_field')));
            $billing_country = $country;
            $shipping_country = $country;
        }
        $email = wpsc_get_buyers_email($purchase_log['id']);
        $previous_download_ids = array();
        $product_list = $product_list_html = $report_product_list = '';
        $cart = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid` = %d", $purchase_log['id']), ARRAY_A);
        if ($cart != null && $errorcode == 0) {
            $total_shipping = '';
            foreach ($cart as $row) {
                $link = array();
                $wpdb->update(WPSC_TABLE_DOWNLOAD_STATUS, array('active' => '1'), array('cartid' => $row['id'], 'purchid' => $purchase_log['id']));
                do_action('wpsc_transaction_result_cart_item', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log));
                if ($is_transaction) {
                    $download_data = $wpdb->get_results($wpdb->prepare("SELECT *\n\t\t\t\t\tFROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "`\n\t\t\t\t\tWHERE `active`='1'\n\t\t\t\t\tAND `purchid` = %d\n\t\t\t\t\tAND `cartid` = %d", $purchase_log['id'], $row['id']), ARRAY_A);
                    if (count($download_data) > 0) {
                        foreach ($download_data as $single_download) {
                            $file_data = get_post($single_download['product_id']);
                            // if the uniqueid is not equal to null, its "valid", regardless of what it is
                            $argsdl = array('post_type' => 'wpsc-product-file', 'post_parent' => $single_download['product_id'], 'numberposts' => -1, 'post_status' => 'all');
                            $download_file_posts = (array) get_posts($argsdl);
                            foreach ((array) $download_file_posts as $single_file_post) {
                                if ($single_file_post->ID == $single_download['fileid']) {
                                    $current_Dl_product_file_post = $single_file_post;
                                    break;
                                }
                            }
                            $file_name = $current_Dl_product_file_post->post_title;
                            if ($single_download['uniqueid'] == null) {
                                $link[] = array("url" => site_url("?downloadid=" . $single_download['id']), "name" => $file_name);
                            } else {
                                $link[] = array("url" => site_url("?downloadid=" . $single_download['uniqueid']), "name" => $file_name);
                            }
                        }
                    } else {
                        $order_status = $purchase_log['processed'];
                    }
                    if (isset($download_data['id'])) {
                        $previous_download_ids[] = $download_data['id'];
                    }
                }
                do_action('wpsc_confirm_checkout', $purchase_log['id']);
                $total = 0;
                $shipping = $row['pnp'];
                $total_shipping += $shipping;
                $total += $row['price'] * $row['quantity'];
                $message_price = wpsc_currency_display($total, array('display_as_html' => false));
                $message_price_html = wpsc_currency_display($total);
                $shipping_price = wpsc_currency_display($shipping, array('display_as_html' => false));
                if (isset($purchase['gateway']) && 'wpsc_merchant_testmode' != $purchase['gateway']) {
                    if ($gateway['internalname'] == $purch_data[0]['gateway']) {
                        $gateway_name = $gateway['name'];
                    }
                } else {
                    $gateway_name = "Manual Payment";
                }
                $variation_list = '';
                if (!empty($link)) {
                    $additional_content = apply_filters('wpsc_transaction_result_content', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log));
                    if (!is_string($additional_content)) {
                        $additional_content = '';
                    }
                    $product_list .= " - " . $row['name'] . "  " . $message_price . " " . __('Click to download', 'wpsc') . ":";
                    $product_list_html .= " - " . $row['name'] . "  " . $message_price_html . "&nbsp;&nbsp;" . __('Click to download', 'wpsc') . ":\n\r";
                    foreach ($link as $single_link) {
                        $product_list .= "\n\r " . $single_link["name"] . ": " . $single_link["url"] . "\n\r";
                        $product_list_html .= "<a href='" . $single_link["url"] . "'>" . $single_link["name"] . "</a>\n";
                    }
                    $product_list .= $additional_content;
                    $product_list_html .= $additional_content;
                } else {
                    $product_list .= " - " . $row['quantity'] . " " . $row['name'] . "  " . $message_price . "\n\r";
                    if ($shipping > 0) {
                        $product_list .= sprintf(__(' - Shipping: %s
', 'wpsc'), $shipping_price);
                    }
                    $product_list_html .= "\n\r - " . $row['quantity'] . " " . $row['name'] . "  " . $message_price_html . "\n\r";
                    if ($shipping > 0) {
                        $product_list_html .= sprintf(__(' &nbsp; Shipping: %s
', 'wpsc'), $shipping_price);
                    }
                }
                //add tax if included
                if ($wpec_taxes_controller->wpec_taxes_isenabled() && $wpec_taxes_controller->wpec_taxes_isincluded()) {
                    $taxes_text = ' - - ' . __('Tax Included', 'wpsc') . ': ' . wpsc_currency_display($row['tax_charged'], array('display_as_html' => false)) . "\n\r";
                    $taxes_text_html = ' - - ' . __('Tax Included', 'wpsc') . ': ' . wpsc_currency_display($row['tax_charged']);
                    $product_list .= $taxes_text;
                    $product_list_html .= $taxes_text_html;
                }
                // if
                $report = get_option('wpsc_email_admin');
                $report_product_list .= " - " . $row['quantity'] . " " . $row['name'] . "  " . $message_price . "\n\r";
            }
            // closes foreach cart as row
            // Decrement the stock here
            if ($is_transaction) {
                wpsc_decrement_claimed_stock($purchase_log['id']);
            }
            if (!empty($purchase_log['discount_data'])) {
                $coupon_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE coupon_code = %s LIMIT 1", $purchase_log['discount_data']), ARRAY_A);
                if ($coupon_data['use-once'] == 1) {
                    $wpdb->update(WPSC_TABLE_COUPON_CODES, array('active' => '0', 'is-used' => '1'), array('id' => $coupon_data['id']));
                }
            }
            $total_shipping = wpsc_get_total_shipping($purchase_log['id']);
            $total = $purchase_log['totalprice'];
            $total_price_email = '';
            $total_price_html = '';
            $total_tax_html = '';
            $total_tax = '';
            $total_shipping_html = '';
            $total_shipping_email = '';
            if (wpsc_uses_shipping() || !empty($purchase_log['base_shipping'])) {
                $total_shipping_email .= sprintf(__('Total Shipping: %s
	', 'wpsc'), wpsc_currency_display($total_shipping, array('display_as_html' => false)));
            }
            $total_price_email .= sprintf(__('Total: %s
', 'wpsc'), wpsc_currency_display($total, array('display_as_html' => false)));
            if ($purchase_log['discount_value'] > 0) {
                $discount_email = __('Discount', 'wpsc') . "\n\r: ";
                $discount_email .= $purchase_log['discount_data'] . ' : ' . wpsc_currency_display($purchase_log['discount_value'], array('display_as_html' => false)) . "\n\r";
                $report .= $discount_email . "\n\r";
                $total_shipping_email .= $discount_email;
                $total_shipping_html .= __('Discount', 'wpsc') . ": " . wpsc_currency_display($purchase_log['discount_value']) . "\n\r";
            }
            //only show total tax if tax is not included
            if ($wpec_taxes_controller->wpec_taxes_isenabled() && !$wpec_taxes_controller->wpec_taxes_isincluded()) {
                $total_tax_html .= __('Total Tax', 'wpsc') . ': ' . wpsc_currency_display($purchase_log['wpec_taxes_total']) . "\n\r";
                $total_tax .= __('Total Tax', 'wpsc') . ': ' . wpsc_currency_display($purchase_log['wpec_taxes_total'], array('display_as_html' => false)) . "\n\r";
            }
            if (wpsc_uses_shipping() || !empty($purchase_log['base_shipping'])) {
                $total_shipping_html .= '<hr>' . sprintf(__('Total Shipping: %s
	', 'wpsc'), wpsc_currency_display($total_shipping));
            }
            $total_price_html .= sprintf(__('Total: %s
', 'wpsc'), wpsc_currency_display($total));
            $report_id = sprintf(__("Purchase # %s\n", 'wpsc'), $purchase_log['id']);
            if (isset($_GET['ti'])) {
                $message .= "\n\r" . __('Your Transaction ID', 'wpsc') . ": " . $_GET['ti'];
                $message_html .= "\n\r" . __('Your Transaction ID', 'wpsc') . ": " . $_GET['ti'];
                $report .= "\n\r" . __('Transaction ID', 'wpsc') . ": " . $_GET['ti'];
            }
            $message = apply_filters('wpsc_transaction_result_message', $message);
            $message = str_replace('%purchase_id%', $report_id, $message);
            $message = str_replace('%product_list%', $product_list, $message);
            $message = str_replace('%total_tax%', $total_tax, $message);
            $message = str_replace('%total_shipping%', $total_shipping_email, $message);
            $message = str_replace('%total_price%', $total_price_email, $message);
            $message = str_replace('%shop_name%', get_option('blogname'), $message);
            $message = str_replace('%find_us%', $purchase_log['find_us'], $message);
            $report = apply_filters('wpsc_transaction_result_report', $report);
            $report = str_replace('%purchase_id%', $report_id, $report);
            $report = str_replace('%product_list%', $report_product_list, $report);
            $report = str_replace('%total_tax%', $total_tax, $report);
            $report = str_replace('%total_shipping%', $total_shipping_email, $report);
            $report = str_replace('%total_price%', $total_price_email, $report);
            $report = str_replace('%shop_name%', get_option('blogname'), $report);
            $report = str_replace('%find_us%', $purchase_log['find_us'], $report);
            $message_html = apply_filters('wpsc_transaction_result_message_html', $message_html);
            $message_html = str_replace('%purchase_id%', $report_id, $message_html);
            $message_html = str_replace('%product_list%', $product_list_html, $message_html);
            $message_html = str_replace('%total_tax%', $total_tax_html, $message_html);
            $message_html = str_replace('%total_shipping%', $total_shipping_html, $message_html);
            $message_html = str_replace('%total_price%', $total_price_html, $message_html);
            $message_html = str_replace('%shop_name%', get_option('blogname'), $message_html);
            $message_html = str_replace('%find_us%', $purchase_log['find_us'], $message_html);
            if (!empty($email)) {
                add_filter('wp_mail_from', 'wpsc_replace_reply_address', 0);
                add_filter('wp_mail_from_name', 'wpsc_replace_reply_name', 0);
                $message = apply_filters('wpsc_email_message', $message, $report_id, $product_list, $total_tax, $total_shipping_email, $total_price_email);
                if (!$is_transaction) {
                    $payment_instructions = strip_tags(stripslashes(get_option('payment_instructions')));
                    if (!empty($payment_instructions)) {
                        $payment_instructions .= "\n\r";
                    }
                    $message = __('Thank you, your purchase is pending, you will be sent an email once the order clears.', 'wpsc') . "\n\r" . $payment_instructions . $message;
                    $message_html = __('Thank you, your purchase is pending, you will be sent an email once the order clears.', 'wpsc') . "\n\r" . $payment_instructions . $message_html;
                    // prevent email duplicates
                    if (!get_transient("{$sessionid}_pending_email_sent") || $resend_email) {
                        wp_mail($email, __('Order Pending: Payment Required', 'wpsc'), $message);
                        set_transient("{$sessionid}_pending_email_sent", true, 60 * 60 * 12);
                    }
                } elseif (!get_transient("{$sessionid}_receipt_email_sent") || $resend_email) {
                    wp_mail($email, __('Purchase Receipt', 'wpsc'), $message);
                    set_transient("{$sessionid}_receipt_email_sent", true, 60 * 60 * 12);
                }
            }
            remove_filter('wp_mail_from_name', 'wpsc_replace_reply_name');
            remove_filter('wp_mail_from', 'wpsc_replace_reply_address');
            $report_user = __('Customer Details', 'wpsc') . "\n\r";
            $form_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = %d", $purchase_log['id']);
            $form_data = $wpdb->get_results($form_sql, ARRAY_A);
            if ($form_data != null) {
                foreach ($form_data as $form_field) {
                    $form_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `id` = %d LIMIT 1", $form_field['form_id']), ARRAY_A);
                    switch ($form_data['type']) {
                        case "country":
                            $country_code = $form_field['value'];
                            $report_user .= $form_data['name'] . ": " . wpsc_get_country($country_code) . "\n";
                            //check if country has a state then display if it does.
                            $country_data = wpsc_country_has_state($country_code);
                            if ($country_data['has_regions'] == 1) {
                                $report_user .= __('Billing State', 'wpsc') . ": " . wpsc_get_region($purchase_log['billing_region']) . "\n";
                            }
                            break;
                        case "delivery_country":
                            $report_user .= $form_data['name'] . ": " . wpsc_get_country($form_field['value']) . "\n";
                            break;
                        default:
                            if ($form_data['name'] == 'State' && is_numeric($form_field['value'])) {
                                $report_user .= __('Delivery State', 'wpsc') . ": " . wpsc_get_state_by_id($form_field['value'], 'name') . "\n";
                            } else {
                                $report_user .= wp_kses($form_data['name'], array()) . ": " . $form_field['value'] . "\n";
                            }
                            break;
                    }
                }
            }
            $report_user .= "\n\r";
            $report = $report_id . $report_user . $report;
            //echo '======REPORT======<br />'.$report.'<br />';
            //echo '======EMAIL======<br />'.$message.'<br />';
            if (get_option('purch_log_email') != null && $purchase_log['email_sent'] != 1) {
                wp_mail(get_option('purch_log_email'), __('Purchase Report', 'wpsc'), $report);
                $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('email_sent' => '1'), array('sessionid' => $sessionid));
            }
            /// Adjust stock and empty the cart
            $wpsc_cart->submit_stock_claims($purchase_log['id']);
            $wpsc_cart->empty_cart();
        }
    }
}
/**
 * tax is included function
 *
 * @uses wpec_taxes_controller
 *
 * @return boolean true or false depending on settings>general page
 */
function wpsc_tax_isincluded()
{
    //uses new wpec_taxes functionality now
    $wpec_taxes_controller = new wpec_taxes_controller();
    return $wpec_taxes_controller->wpec_taxes_isincluded();
}
Example #14
0
 /**
  * save to database method
  * @access public
  *
  * @param integer purchase log id
  */
 function save_to_db($purchase_log_id)
 {
     global $wpdb, $wpsc_shipping_modules;
     $method = $this->cart->selected_shipping_method;
     $shipping = 0;
     if (!empty($method) && method_exists($wpsc_shipping_modules[$method], "get_item_shipping")) {
         $shipping = $wpsc_shipping_modules[$this->cart->selected_shipping_method]->get_item_shipping($this);
     }
     if ($this->cart->has_total_shipping_discount()) {
         $shipping = 0;
     }
     //initialize tax variables
     $tax = 0;
     $tax_rate = 0;
     //wpec_taxes - calculate product tax and add to total price
     $wpec_taxes_controller = new wpec_taxes_controller();
     if ($wpec_taxes_controller->wpec_taxes_isincluded() && $wpec_taxes_controller->wpec_taxes_isenabled()) {
         $taxes = $wpec_taxes_controller->wpec_taxes_calculate_included_tax($this);
         $tax_rate = $taxes['rate'];
         $tax = $taxes['tax'];
     }
     $wpdb->query($wpdb->prepare("INSERT INTO `" . WPSC_TABLE_CART_CONTENTS . "` (\n         `prodid`, `name`, `purchaseid`,  `price`, `pnp`,\n         `tax_charged`, `gst`, `quantity`, `donation`,\n         `no_shipping`, `custom_message`, `files`, `meta`\n      ) VALUES ('%d', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '0', '%s', '%s', NULL)", $this->product_id, $this->product_name, $purchase_log_id, $this->unit_price, (double) $shipping, (double) $tax, (double) $tax_rate, $this->quantity, $this->is_donation, $this->custom_message, serialize($this->custom_file)));
     $cart_id = $wpdb->get_var("SELECT LAST_INSERT_ID() AS `id` FROM `" . WPSC_TABLE_CART_CONTENTS . "` LIMIT 1");
     wpsc_update_cartmeta($cart_id, 'sku', $this->sku);
     $downloads = get_option('max_downloads');
     if ($this->is_downloadable == true) {
         $product_files = (array) get_posts(array('post_type' => 'wpsc-product-file', 'post_parent' => $this->product_id, 'numberposts' => -1, 'post_status' => 'inherit'));
         foreach ($product_files as $file) {
             // if the file is downloadable, check that the file is real
             $unique_id = sha1(uniqid(mt_rand(), true));
             $wpdb->query("INSERT INTO `" . WPSC_TABLE_DOWNLOAD_STATUS . "` (\n               `product_id` , `fileid` ,\n               `purchid` , `cartid`,\n               `uniqueid`, `downloads`,\n               `active` , `datetime`\n            ) VALUES (\n               '{$this->product_id}', '{$file->ID}',\n               '{$purchase_log_id}', '{$cart_id}',\n               '{$unique_id}', '{$downloads}',\n               '0', NOW()\n            );");
             $download_id = $wpdb->get_var("SELECT LAST_INSERT_ID() AS `id` FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` LIMIT 1");
             wpsc_update_meta($download_id, '_is_legacy', 'false', 'wpsc_downloads');
         }
     }
     do_action('wpsc_save_cart_item', $cart_id, $this->product_id);
 }
 public function save_shipping_and_billing_info()
 {
     global $wpsc_cart;
     $purchase_log = $this->get_purchase_log();
     $sessionid = mt_rand(100, 999) . time();
     wpsc_update_customer_meta('checkout_session_id', $sessionid);
     $purchase_log->set(array('user_ID' => get_current_user_id(), 'date' => time(), 'plugin_version' => WPSC_VERSION, 'statusno' => '0', 'sessionid' => $sessionid));
     $form = WPSC_Checkout_Form::get();
     $fields = $form->get_fields();
     foreach ($fields as $field) {
         if (!array_key_exists($field->id, $_POST['wpsc_checkout_details'])) {
             continue;
         }
         $value = $_POST['wpsc_checkout_details'][$field->id];
         switch ($field->unique_name) {
             case 'billingstate':
                 wpsc_update_customer_meta('billing_region', $value);
                 $purchase_log->set('billing_region', $value);
                 break;
             case 'shippingstate':
                 wpsc_update_customer_meta('shipping_region', $value);
                 $purchase_log->set('shipping_region', $value);
                 break;
             case 'billingcountry':
                 wpsc_update_customer_meta('billing_country', $value);
                 $purchase_log->set('billing_country', $value);
                 break;
             case 'shippingcountry':
                 wpsc_update_customer_meta('shipping_country', $value);
                 $purchase_log->set('shipping_region', $value);
                 break;
             case 'shippingpostcode':
                 wpsc_update_customer_meta('shipping_zip', $value);
                 break;
         }
     }
     _wpsc_update_location();
     //keep track of tax if taxes are exclusive
     $wpec_taxes_controller = new wpec_taxes_controller();
     if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
         $tax = $wpsc_cart->calculate_total_tax();
         $tax_percentage = $wpsc_cart->tax_percentage;
     } else {
         $tax = 0.0;
         $tax_percentage = 0.0;
     }
     $purchase_log->set(array('wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage));
     $purchase_log->save();
     //Check to ensure purchase log row was inserted successfully
     if (is_null($purchase_log->get('id'))) {
         $this->message_collection->add(__('A database error occured while processing your request.', 'wp-e-commerce'), 'error');
         return;
     }
     $wpsc_cart->log_id = $purchase_log->get('id');
     wpsc_update_customer_meta('current_purchase_log_id', $purchase_log->get('id'));
     WPSC_Checkout_Form_Data::save_form($purchase_log, $fields);
     $this->init_shipping_calculator();
     if (wpsc_uses_shipping() && !$this->shipping_calculator->has_quotes) {
         $this->message_collection->add(__('Sorry, but we cannot ship products to your submitted address. Please either provide another shipping address or contact the store administrator about product availability to your location.', 'wp-e-commerce'), 'error');
         return;
     }
     $this->wizard->completed_step('shipping-and-billing');
     $url = add_query_arg($_GET, wpsc_get_checkout_url($this->wizard->pending_step));
     wp_redirect($url);
     exit;
 }
Example #16
0
function dibspayment_paywin_order_params($cart)
{
    global $wpdb;
    $order_data = array();
    $purchase_log = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $cart->sessionid . " LIMIT 1", ARRAY_A);
    $currency_code = $wpdb->get_results("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1", ARRAY_A);
    // Set status on new order
    $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed` = '" . get_option('dibspw_statusp') . "' WHERE `sessionid` = '" . $cart->sessionid . "' LIMIT 1;");
    // collect data for request
    $order_data['orderid'] = $purchase_log[0]['id'];
    $order_data['merchant'] = get_option('dibspw_mid');
    $order_data['amount'] = dibspayment_paywin_round($cart->total_price);
    $order_data['currency'] = $currency_code[0]['code'];
    $order_data['language'] = get_option('dibspw_lang');
    $order_data['oitypes'] = 'QUANTITY;UNITCODE;DESCRIPTION;AMOUNT;ITEMID;VATAMOUNT';
    $order_data['oinames'] = 'Qty;UnitCode;Description;Amount;ItemId;VatAmount';
    $order_data['oinames'] = 'Qty;UnitCode;Description;Amount;ItemId;VatAmount';
    $wpec_taxes_c = new wpec_taxes_controller();
    //$tax_total = $wpec_taxes_c->wpec_taxes_calculate_total();
    //get the rate for the country and region if set
    $tax_total = $wpec_taxes_c->wpec_taxes->wpec_taxes_get_rate($wpec_taxes_c->wpec_taxes_retrieve_selected_country(), $wpec_taxes_c->wpec_taxes_retrieve_region());
    // cart items
    $i = 1;
    foreach ($cart->cart_items as $oitem) {
        $tmp_price = dibspayment_paywin_round($oitem->unit_price);
        if (!empty($tmp_price)) {
            $unit_price = $oitem->unit_price;
            $tax['tax'] = 0;
            if ($wpec_taxes_c->wpec_taxes->wpec_taxes_get_enabled() && $tax_total['rate']) {
                if ($wpec_taxes_c->wpec_taxes_isincluded()) {
                    $tax = $wpec_taxes_c->wpec_taxes_calculate_included_tax($oitem);
                    $tax['tax'] = $tax['tax'] / $oitem->quantity;
                    $unit_price = $oitem->unit_price - $tax['tax'];
                } else {
                    $tax['tax'] = $unit_price * ($tax_total['rate'] / 100);
                }
            }
            $tmp_name = !empty($oitem->product_name) ? $oitem->product_name : $oitem->sku;
            if (empty($tmp_name)) {
                $tmp_name = $oitem->product_id;
            }
            $order_data['oiRow' . $i++] = dibspayment_paywin_oirow_str($oitem->quantity, dibspayment_paywin_utf8Fix(str_replace(";", "\\;", $tmp_name)), dibspayment_paywin_round($unit_price), dibspayment_paywin_utf8Fix(str_replace(";", "\\;", $oitem->product_id)), dibspayment_paywin_round($tax['tax']));
        }
        unset($tmp_price, $tmp_name);
    }
    // Shipping calculation
    if ($cart->calculate_total_shipping()) {
        $shipping_tax = 0;
        $fRate = $cart->calculate_total_shipping();
        if ($tax_total['shipping'] && $wpec_taxes_c->wpec_taxes->wpec_taxes_get_enabled()) {
            if ($wpec_taxes_c->wpec_taxes_isincluded()) {
                $shipping_tax = $wpec_taxes_c->wpec_taxes_calculate_tax($cart->calculate_total_shipping(), $tax_total['rate'], false);
                $fRate = $fRate - $shipping_tax;
            } else {
                $shipping_tax = $wpec_taxes_c->wpec_taxes_calculate_tax($cart->calculate_total_shipping(), $tax_total['rate']);
            }
        }
        $order_data['oiRow' . $i++] = dibspayment_paywin_oirow_str(1, "Shipping", dibspayment_paywin_round($fRate), "shipping_0", dibspayment_paywin_round($shipping_tax));
    }
    // Cupone if it is avaliable
    if ($cart->coupons_amount > 0) {
        $order_data['oiRow' . $i++] = dibspayment_paywin_oirow_str(1, "Coupon", -dibspayment_paywin_round($cart->coupons_amount), "coupon_0", 0);
    }
    // Address fields here..
    $aAddr = $_POST['collected_data'];
    $order_data['shippingfirstname'] = $aAddr[get_option('dibspw_form_first_name_d')];
    $order_data['shippinglastname'] = $aAddr[get_option('dibspw_form_last_name_d')];
    $order_data['shippingpostalcode'] = $aAddr[get_option('dibspw_form_post_code_d')];
    $order_data['shippingpostalplace'] = $aAddr[get_option('dibspw_form_city_d')];
    //$order_data['shippingaddress2']   = $aAddr[get_option('dibspw_form_address_d')];
    $order_data['shippingaddress'] = $aAddr[get_option('dibspw_form_country_d')] . " " . $aAddr[get_option('dibspw_form_state_d')];
    $order_data['billingfirstname'] = $aAddr[get_option('dibspw_form_first_name_b')];
    $order_data['billinglastname'] = $aAddr[get_option('dibspw_form_last_name_b')];
    $order_data['billingpostalcode'] = $aAddr[get_option('dibspw_form_post_code_b')];
    $order_data['billingpostalplace'] = $aAddr[get_option('dibspw_form_city_b')];
    $order_data['billingaddress'] = $aAddr[get_option('dibspw_form_address_b')];
    //$order_data['billingaddress']     = $aAddr[get_option('dibspw_form_country_b')]. " " .
    //                             $aAddr[get_option('dibspw_form_state_b')];
    $order_data['billingmobile'] = $aAddr[get_option('dibspw_form_phone_b')];
    $order_data['billingemail'] = $aAddr[get_option('dibspw_form_email_b')];
    $order_data['acceptreturnurl'] = get_option('siteurl') . "/?dibspw_result=success";
    $order_data['cancelreturnurl'] = site_url() . "/?dibspw_result=cancel";
    $order_data['callbackurl'] = get_option('siteurl') . "/?dibspw_result=callback";
    $order_data['s_callbackfix'] = get_option('siteurl') . "/?dibspw_result=callback";
    $order_data['s_sysmod'] = DIBS_SYSMOD;
    if (get_option('dibspw_testmode')) {
        $order_data['test'] = 1;
    }
    if (get_option('dibspw_capturenow')) {
        $order_data['capturenow'] = 1;
    }
    if (get_option('dibspw_fee')) {
        $order_data['addfee'] = 1;
    }
    $order_data['s_pid'] = $cart->sessionid;
    if (get_option('dibspw_account')) {
        $order_data['account'] = get_option('dibspw_account');
    }
    if (get_option('dibspw_paytype')) {
        $order_data['paytype'] = get_option('dibspw_paytype');
    }
    if (get_option('dibspw_pid')) {
        $order_data['s_partnerid'] = get_option('dibspw_pid');
    }
    if ($hmac = get_option('dibspw_hmac')) {
        $order_data['MAC'] = dibspayment_paywin_calc_mac($order_data, $hmac, $bUrlDecode = FALSE);
    }
    return $order_data;
}
/**
 * submit checkout function, used through ajax and in normal page loading.
 * No parameters, returns nothing
 */
function wpmlm_submit_checkout()
{
    global $wpdb, $wpmlm_cart, $user_ID, $nzshpcrt_gateways, $wpmlm_shipping_modules, $wpmlm_gateways;
    $num_items = 0;
    $use_shipping = 0;
    $disregard_shipping = 0;
    do_action('wpmlm_before_submit_checkout');
    $_SESSION['wpmlm_checkout_misc_error_messages'] = array();
    $wpmlm_checkout = new wpmlm_checkout();
    $selected_gateways = get_option('custom_gateway_options');
    $submitted_gateway = $_POST['custom_gateway'];
    $options = get_option('custom_shipping_options');
    $form_validity = $wpmlm_checkout->validate_forms();
    //echo "<pre>";print_r($form_validity); exit;
    extract($form_validity);
    // extracts $is_valid and $error_messages
    if ($_POST['agree'] != 'yes') {
        $_SESSION['wpmlm_checkout_misc_error_messages'][] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpmlm');
        $is_valid = false;
    }
    $selectedCountry = $wpdb->get_results($wpdb->prepare("SELECT id, country FROM `" . WPMLM_TABLE_CURRENCY_LIST . "` WHERE isocode = '%s' ", $_SESSION['wpmlm_delivery_country']), ARRAY_A);
    foreach ($wpmlm_cart->cart_items as $cartitem) {
        if (!empty($cartitem->meta[0]['no_shipping'])) {
            continue;
        }
        $categoriesIDs = $cartitem->category_id_list;
        foreach ((array) $categoriesIDs as $catid) {
            if (is_array($catid)) {
                $countries = wpmlm_get_meta($catid[0], 'target_market', 'wpmlm_category');
            } else {
                $countries = wpmlm_get_meta($catid, 'target_market', 'wpmlm_category');
            }
            if (!empty($countries) && !in_array($selectedCountry[0]['id'], (array) $countries)) {
                $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpmlm'), $cartitem->product_name, $selectedCountry[0]['country']);
                $_SESSION['categoryAndShippingCountryConflict'] = $errormessage;
                $is_valid = false;
            }
        }
        //count number of items, and number of items using shipping
        $num_items++;
        if ($cartitem->uses_shipping != 1) {
            $disregard_shipping++;
        } else {
            $use_shipping++;
        }
    }
    if (array_search($submitted_gateway, $selected_gateways) !== false) {
        $_SESSION['wpmlm_previous_selected_gateway'] = $submitted_gateway;
    } else {
        $is_valid = false;
    }
    if (get_option('do_not_use_shipping') == 0 && ($wpmlm_cart->selected_shipping_method == null || $wpmlm_cart->selected_shipping_option == null) && $num_items != $disregard_shipping) {
        $_SESSION['wpmlm_checkout_misc_error_messages'][] = __('You must select a shipping method, otherwise we cannot process your order.', 'wpmlm');
        $is_valid = false;
    }
    if (get_option('do_not_use_shipping') != 1 && in_array('ups', (array) $options) && $_SESSION['wpmlm_zipcode'] == '' && $num_items != $disregard_shipping) {
        $_SESSION['categoryAndShippingCountryConflict'] = __('Please enter a Zipcode and click calculate to proceed', 'wpmlm');
        $is_valid = false;
    }
    if ($is_valid == true) {
        //echo "test2";exit;
        $_SESSION['categoryAndShippingCountryConflict'] = '';
        // check that the submitted gateway is in the list of selected ones
        $sessionid = mt_rand(100, 999) . time();
        $_SESSION['wpmlm_sessionid'] = $sessionid;
        $subtotal = $wpmlm_cart->calculate_subtotal();
        if ($wpmlm_cart->has_total_shipping_discount() == false) {
            $base_shipping = $wpmlm_cart->calculate_base_shipping();
        } else {
            $base_shipping = 0;
        }
        $delivery_country = $wpmlm_cart->delivery_country;
        $delivery_region = $wpmlm_cart->delivery_region;
        if (wpmlm_uses_shipping()) {
            $shipping_method = $wpmlm_cart->selected_shipping_method;
            $shipping_option = $wpmlm_cart->selected_shipping_option;
        } else {
            $shipping_method = '';
            $shipping_option = '';
        }
        if (isset($_POST['how_find_us'])) {
            $find_us = $_POST['how_find_us'];
        } else {
            $find_us = '';
        }
        //keep track of tax if taxes are exclusive
        $wpec_taxes_controller = new wpec_taxes_controller();
        if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
            $tax = $wpmlm_cart->calculate_total_tax();
            $tax_percentage = $wpmlm_cart->tax_percentage;
        } else {
            $tax = 0.0;
            $tax_percentage = 0.0;
        }
        $total = $wpmlm_cart->calculate_total_price();
        $total_point_value = $wpmlm_cart->calculate_total_point_value();
        $wpdb->insert(WPMLM_TABLE_PURCHASE_LOGS, array('totalprice' => $total, 'totalpointvalue' => $total_point_value, 'statusno' => '0', 'sessionid' => $sessionid, 'user_ID' => (int) $user_ID, 'date' => time(), 'gateway' => $submitted_gateway, 'billing_country' => $wpmlm_cart->selected_country, 'shipping_country' => $delivery_country, 'billing_region' => $wpmlm_cart->selected_region, 'shipping_region' => $delivery_region, 'base_shipping' => $base_shipping, 'shipping_method' => $shipping_method, 'shipping_option' => $shipping_option, 'plugin_version' => WPMLM_VERSION, 'discount_value' => $wpmlm_cart->coupons_amount, 'discount_data' => $wpmlm_cart->coupons_name, 'find_us' => $find_us, 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage));
        /********| MLM USERS |*********/
        $user_tbl = mysql_query("SELECT id, user_key, parent_key,sponsor_key,leg, payment_status, banned \n\t\t\t\t\t\t\t\tFROM " . WPMLM_TABLE_USER . " WHERE user_id ='" . $user_ID . "'");
        $row = mysql_fetch_array($user_tbl);
        $user_key = $row['user_key'];
        $parent_key = $row['parent_key'];
        $payment_status = $row['payment_status'];
        $banned = $row['banned'];
        $sponsor_key = $row['sponsor_key'];
        $leg = $row['leg'];
        /*Now the below  if condition is not in use 
        		Entry are going when user registerd
        		*/
        if ($banned == 1 && $parent_key == '') {
            do {
                $parentquery = mysql_query("SELECT `user_key` FROM " . WPMLM_TABLE_USER . " \n\t\t\t\t\t\t\t\t\t\t\tWHERE parent_key = '" . $sponsor_key . "' AND \n\t\t\t\t\t\t\t\t\t\t\tleg = '" . $leg . "' AND banned = '0'");
                $num = mysql_num_rows($parentquery);
                if ($num) {
                    $ref1 = mysql_fetch_array($parentquery);
                    $sponsor_key = $ref1['key'];
                }
            } while ($num == 1);
            $parent_key = $sponsor_key;
            /*Update the mlm user table */
            $query = "UPDATE \n\t\t\t\t\t\t\t" . WPMLM_TABLE_USER . " \n\t\t\t\t\t\tSET \n\t\t\t\t\t\t\tbanned \t\t= '0' ,\n\t\t\t\t\t\t\tparent_key \t= '" . $parent_key . "'\n\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t`user_id` = '" . $user_ID . "'";
            $rs_query = mysql_query($query);
            //entry on left leg and Right leg
            if ($leg == 0) {
                mysql_query("INSERT INTO `" . WPMLM_TABLE_LEFT_LEG . "` \n\t\t\t\t\t(`id`, `pkey`,`ukey`) \n\t\t\t\t\t\tVALUES \n\t\t\t\t\t\t('', '" . $parent_key . "','" . $user_key . "')");
            } else {
                if ($leg == 1) {
                    mysql_query("INSERT INTO `" . WPMLM_TABLE_RIGHT_LEG . "` \n\t\t\t\t\t\t\t(`id`, `pkey`,`ukey`)\n\t\t\t\t\t\t\tVALUES \n\t\t\t\t\t\t\t ('', '" . $parent_key . "','" . $user_key . "')");
                }
            }
            while ($parent_key != '0') {
                $query = mysql_query("SELECT `parent_key`, `leg` FROM " . WPMLM_TABLE_USER . " WHERE `user_key` = '" . $parent_key . "'");
                $num_rows = mysql_num_rows($query);
                if ($num_rows) {
                    $result = mysql_fetch_array($query);
                    if ($result['parent_key'] != '0') {
                        if ($result['leg'] == 1) {
                            mysql_query("INSERT INTO `" . WPMLM_TABLE_RIGHT_LEG . "` (`id`, `pkey`,`ukey`) \n\t\t\t\t\t\t\tVALUES ('','" . $result['parent_key'] . "','" . $user_key . "')");
                        } else {
                            mysql_query("INSERT INTO `" . WPMLM_TABLE_LEFT_LEG . "` (`id`, `pkey`,`ukey`) \n\t\t\t\t\t\t\tVALUES ('','" . $result['parent_key'] . "','" . $user_key . "')");
                        }
                    }
                    $parent_key = $result['parent_key'];
                } else {
                    $parent_key = '0';
                }
            }
        }
        /*end of the entry for mlm table */
        $purchase_log_id = $wpdb->insert_id;
        $wpmlm_checkout->save_forms_to_db($purchase_log_id);
        $wpmlm_cart->save_to_db($purchase_log_id);
        $wpmlm_cart->submit_stock_claims($purchase_log_id);
        if (get_option('wpmlm_also_bought') == 1) {
            wpmlm_populate_also_bought_list();
        }
        if (!isset($our_user_id) && isset($user_ID)) {
            $our_user_id = $user_ID;
        }
        $wpmlm_cart->log_id = $purchase_log_id;
        do_action('wpmlm_submit_checkout', array("purchase_log_id" => $purchase_log_id, "our_user_id" => $our_user_id));
        if (get_option('permalink_structure') != '') {
            $separator = "?";
        } else {
            $separator = "&";
        }
        // submit to gateway
        $current_gateway_data =& $wpmlm_gateways[$submitted_gateway];
        if (isset($current_gateway_data['api_version']) && $current_gateway_data['api_version'] >= 2.0) {
            $merchant_instance = new $current_gateway_data['class_name']($purchase_log_id);
            $merchant_instance->construct_value_array();
            do_action_ref_array('wpmlm_pre_submit_gateway', array(&$merchant_instance));
            $merchant_instance->submit();
        } elseif ($current_gateway_data['internalname'] == $submitted_gateway && $current_gateway_data['internalname'] != 'google') {
            $gateway_used = $current_gateway_data['internalname'];
            $wpdb->update(WPMLM_TABLE_PURCHASE_LOGS, array('gateway' => $gateway_used), array('id' => $purchase_log_id));
            $current_gateway_data['function']($separator, $sessionid);
        } elseif ($current_gateway_data['internalname'] == 'google' && $current_gateway_data['internalname'] == $submitted_gateway) {
            $gateway_used = $current_gateway_data['internalname'];
            $wpdb->update(WPMLM_TABLE_PURCHASE_LOGS, array('gateway' => $gateway_used), array('id' => $purchase_log_id));
            $_SESSION['gateway'] = 'google';
            wp_redirect(get_option('shopping_cart_url'));
            exit;
        }
    }
}
function wpsc_product_taxes_forms()
{
    global $post, $wpdb, $wpsc_product_defaults;
    $product_data = get_post_custom($post->ID);
    $product_data['meta'] = $product_meta = array();
    if (!empty($product_data['_wpsc_product_metadata'])) {
        $product_data['meta'] = $product_meta = maybe_unserialize($product_data['_wpsc_product_metadata'][0]);
    }
    if (!isset($product_data['meta']['_wpsc_custom_tax'])) {
        $product_data['meta']['_wpsc_custom_tax'] = '';
    }
    $custom_tax = $product_data['meta']['_wpsc_custom_tax'];
    if (!isset($product_meta['custom_tax'])) {
        $product_meta['custom_tax'] = 0.0;
    }
    //Add New WPEC-Taxes Bands Here
    $wpec_taxes_controller = new wpec_taxes_controller();
    //display tax bands
    $band_select_settings = array('id' => 'wpec_taxes_band', 'name' => 'meta[_wpsc_product_metadata][wpec_taxes_band]', 'label' => __('Custom Tax Band', 'wp-e-commerce'));
    $wpec_taxes_band = '';
    if (isset($product_meta['wpec_taxes_band'])) {
        $band = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_band_from_index($product_meta['wpec_taxes_band']);
        $wpec_taxes_band = array('index' => $band['index'], 'name' => $band['name']);
    }
    $taxable_checkbox_settings = array('type' => 'checkbox', 'id' => 'wpec_taxes_taxable', 'name' => 'meta[_wpsc_product_metadata][wpec_taxes_taxable]', 'label' => __('Product is exempt from taxation.', 'wp-e-commerce'));
    if (isset($product_meta['wpec_taxes_taxable']) && 'on' == $product_meta['wpec_taxes_taxable']) {
        $taxable_checkbox_settings['checked'] = 'checked';
    }
    //add taxable amount only for exclusive tax
    if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
        $taxable_amount_input_settings = array('id' => 'wpec_taxes_taxable_amount', 'name' => 'meta[_wpsc_product_metadata][wpec_taxes_taxable_amount]', 'label' => __('Taxable Amount', 'wp-e-commerce'), 'description' => __('Taxable amount in your currency, not percentage of price.', 'wp-e-commerce'));
        if (isset($product_meta['wpec_taxes_taxable_amount'])) {
            $taxable_amount_input_settings['value'] = $product_meta['wpec_taxes_taxable_amount'];
            if (!empty($product_meta['wpec_taxes_taxable_amount'])) {
                $taxable_amount_input_settings['value'] = wpsc_format_number($taxable_amount_input_settings['value']);
            }
        }
    }
    // if
    $output = '<a name="wpsc_tax"></a>';
    $output .= '<p>' . $wpec_taxes_controller->wpec_taxes_build_input($taxable_checkbox_settings) . '</p>';
    $output .= '<p>' . $wpec_taxes_controller->wpec_taxes_display_tax_bands($band_select_settings, $wpec_taxes_band) . '</p>';
    $output .= '<p>';
    $output .= !$wpec_taxes_controller->wpec_taxes_isincluded() ? $wpec_taxes_controller->wpec_taxes_build_input($taxable_amount_input_settings) : '';
    $output .= '</p>';
    if (!$wpec_taxes_controller->wpec_taxes->wpec_taxes_get_enabled()) {
        $output = '<p>' . sprintf(__('Taxes are not enabled. See <a href="%s">Settings &gt; Taxes</a>', 'wp-e-commerce'), admin_url('options-general.php?page=wpsc-settings&tab=taxes')) . '</p>';
    }
    echo $output;
    wp_nonce_field('update', 'wpsc_product_tax_nonce');
}
        }
        ?>
         <?php 
    }
    ?>

         <?php 
    wpsc_update_shipping_multiple_methods();
    ?>
      </table>
   <?php 
}
?>

   <?php 
$wpec_taxes_controller = new wpec_taxes_controller();
if ($wpec_taxes_controller->wpec_taxes_isenabled()) {
    ?>
      <table class="productcart">
         <tr class="total_price total_tax">
            <td colspan="3">
               <?php 
    echo wpsc_display_tax_label(true);
    ?>
            </td>
            <td colspan="2">
               <span id="checkout_tax" class="pricedisplay checkout-tax"><?php 
    echo wpsc_cart_tax();
    ?>
</span>
            </td>
Example #20
0
    public function display()
    {
        $wpec_taxes_controller = new wpec_taxes_controller();
        $wpec_taxes_options = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_options();
        ?>
		<h3><?php 
        esc_html_e('Tax Settings', 'wp-e-commerce');
        ?>
</h3>
		<table class='form-table'>
			<tr>
				<th><?php 
        esc_html_e("Enable Tax", 'wp-e-commerce');
        ?>
</th>
				<td>
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_enabled']) {
            echo 'checked="checked"';
        }
        ?>
 type="checkbox" id='wpec_taxes_enabled' name='wpsc_options[wpec_taxes_enabled]' />
					<label for='wpec_taxes_enabled'>
						<?php 
        esc_html_e('Turn tax on', 'wp-e-commerce');
        ?>
					</label>
				</td>
			</tr>
			<tr>
				<th><?php 
        esc_html_e("Product Prices", 'wp-e-commerce');
        ?>
</th>
				<td>
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_inprice'] == 'exclusive') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='exclusive' id='wpec_taxes_inprice1' name='wpsc_options[wpec_taxes_inprice]' />
					<label for='wpec_taxes_inprice1'>
						<?php 
        esc_html_e('Product prices are tax exclusive - add tax to the price during checkout', 'wp-e-commerce');
        ?>
					</label><br />
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_inprice'] == 'inclusive') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='inclusive' id='wpec_taxes_inprice2' name='wpsc_options[wpec_taxes_inprice]' />
					<label for='wpec_taxes_inprice2'>
						<?php 
        esc_html_e("Product prices are tax inclusive - during checkout the total price doesn't increase but tax is shown as a line item", 'wp-e-commerce');
        ?>
					</label>
				</td>
			</tr>
			<tr>
				<th><?php 
        esc_html_e('Product Specific Tax', 'wp-e-commerce');
        ?>
</th>
				<td>
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_product'] == 'add') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='add' id='wpec_taxes_product_1' name='wpsc_options[wpec_taxes_product]' />
					<label for='wpec_taxes_product_1'>
						<?php 
        esc_html_e('Add per product tax to tax percentage if product has a specific tax rate', 'wp-e-commerce');
        ?>
					</label><br />
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_product'] == 'replace') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='replace' id='wpec_taxes_product_2' name='wpsc_options[wpec_taxes_product]' />
					<label for='wpec_taxes_product_2'>
						<?php 
        esc_html_e('Replace tax percentage with product specific tax rate', 'wp-e-commerce');
        ?>
					</label>
				</td>
			</tr>
			<tr>
				<th><?php 
        _e('Tax Logic', 'wp-e-commerce');
        ?>
</th>
				<td>
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_logic'] == 'billing_shipping') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='billing_shipping' id='wpec_taxes_logic_1' name='wpsc_options[wpec_taxes_logic]' />
					<label for='wpec_taxes_logic_1'>
						<?php 
        esc_html_e('Apply tax when Billing and Shipping Region is the same as Tax Rate', 'wp-e-commerce');
        ?>
					</label>
					<div id='billing_shipping_preference_container' style='margin-left: 20px;'>
						<?php 
        $checked = $wpec_taxes_options['wpec_taxes_logic'] == 'billing_shipping' && $wpec_taxes_options['wpec_billing_shipping_preference'] == 'billing_address' ? 'checked="checked"' : '';
        ?>
						<input <?php 
        echo $checked;
        ?>
 type="radio" value='billing_address' id='wpec_billing_preference' name='wpsc_options[wpec_billing_shipping_preference]' />
						<label for='wpec_billing_preference'>
							<?php 
        esc_html_e('Apply tax to Billing Address', 'wp-e-commerce');
        ?>
						</label><br />
						<?php 
        $checked = $wpec_taxes_options['wpec_taxes_logic'] == 'billing_shipping' && $wpec_taxes_options['wpec_billing_shipping_preference'] == 'shipping_address' ? 'checked="checked"' : '';
        ?>
						<input <?php 
        echo $checked;
        ?>
type="radio" value='shipping_address' id='wpec_shipping_preference' name='wpsc_options[wpec_billing_shipping_preference]' />
						<label for='wpec_shipping_preference'>
							<?php 
        esc_html_e('Apply tax to Shipping Address', 'wp-e-commerce');
        ?>
						</label>
					</div>
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_logic'] == 'billing') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='billing' id='wpec_taxes_logic_2' name='wpsc_options[wpec_taxes_logic]' />
					<label for='wpec_taxes_logic_2'>
						<?php 
        esc_html_e('Apply tax when Billing Region is the same as Tax Rate', 'wp-e-commerce');
        ?>
					</label><br />
					<input <?php 
        if ($wpec_taxes_options['wpec_taxes_logic'] == 'shipping') {
            echo 'checked="checked"';
        }
        ?>
 type="radio" value='shipping' id='wpec_taxes_logic_3' name='wpsc_options[wpec_taxes_logic]' />
					<label for='wpec_taxes_logic_3'>
						<?php 
        esc_html_e('Apply tax when Shipping Region is the same as Tax Rate', 'wp-e-commerce');
        ?>
					</label>
				</td>
			</tr>
		</table>

		<h3><?php 
        esc_html_e('Tax Rates', 'wp-e-commerce');
        ?>
</h3>
		<div id='wpec-taxes-rates'>
			<!--Start Taxes Output-->
			<table class='widefat page fixed ui-sortable'>
				<thead>
					<th scope='col' width='60%'><?php 
        _e('Market', 'wp-e-commerce');
        ?>
</th>
					<th scope='col' width='10%'><?php 
        _e('Tax Rate', 'wp-e-commerce');
        ?>
</th>
					<th scope='col'><?php 
        _e('Tax Shipping?', 'wp-e-commerce');
        ?>
</th>
					<th scope='col' style='width: 60px'><?php 
        _e('Actions', 'wp-e-commerce');
        ?>
</th>
				</thead>
				<tbody>
					<?php 
        $tax_rates = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_rates();
        echo $wpec_taxes_controller->wpsc_build_taxes_row('rates', 'prototype', array('row_class' => 'prototype'));
        if (count($tax_rates) === 0) {
            echo $wpec_taxes_controller->wpsc_build_taxes_row('rates', 0, null);
        }
        $tax_rate_count = 0;
        if (!empty($tax_rates)) {
            foreach ($tax_rates as $tax_rate) {
                // OLD: echo $wpec_taxes_controller->wpec_taxes_build_form( $tax_rate_count, $tax_rate );
                echo $wpec_taxes_controller->wpsc_build_taxes_row('rates', $tax_rate_count, $tax_rate);
                $tax_rate_count++;
            }
        }
        ?>
				</tbody>
			</table>
			<!--End Taxes Output-->
		</div>
		<div id='wpec-taxes-bands-container'>
			<h3><?php 
        esc_html_e('Tax Bands', 'wp-e-commerce');
        ?>
</h3>
			<div id='wpec-taxes-bands'>
				<div class="updated inline">
					<p><?php 
        _e('Note: Tax Bands are special tax rules you can create and apply on a per-product basis. Please visit the product page to apply your Tax Band.', 'wp-e-commerce');
        ?>
</p>
				</div>
				<?php 
        if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
            ?>
					<div class="error inline">
						<p><?php 
            _e('Warning: Tax Bands do not take effect when product prices are tax exclusive.', 'wp-e-commerce');
            ?>
</p>
					</div>
				<?php 
        }
        ?>
				<table class='widefat page fixed ui-sortable'>
					<thead>
						<th scope='col'><?php 
        _e('Band Name', 'wp-e-commerce');
        ?>
</th>
						<th scope='col' width="50%"><?php 
        _e('Market', 'wp-e-commerce');
        ?>
</th>
						<th scope='col' width='20%'><?php 
        _e('Tax Rate', 'wp-e-commerce');
        ?>
</th>
						<th scope='col' style='width: 60px'><?php 
        _e('Actions', 'wp-e-commerce');
        ?>
</th>
					</thead>
					<tbody>
						<?php 
        $tax_bands = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_bands();
        echo $wpec_taxes_controller->wpsc_build_taxes_row('bands', 'prototype', array('row_class' => 'prototype'));
        if (count($tax_bands) === 0) {
            echo $wpec_taxes_controller->wpsc_build_taxes_row('bands', 0, null);
        }
        $tax_band_count = 0;
        if (!empty($tax_bands)) {
            foreach ($tax_bands as $tax_band) {
                // OLD: echo $wpec_taxes_controller->wpec_taxes_build_form( $tax_band_count, $tax_band, 'bands' );
                echo $wpec_taxes_controller->wpsc_build_taxes_row('bands', $tax_band_count, $tax_band);
                $tax_band_count++;
            }
        }
        ?>

					</tbody>
				</table>
			</div>
		</div><!--wpec-taxes-bands-container-->
		<?php 
    }