Ejemplo n.º 1
0
/**
 * WP eCommerce checkout class
 *
 * These are the class for the WP eCommerce checkout
 * The checkout class handles dispaying the checkout form fields
 *
 * @package wp-e-commerce
 * @subpackage wpsc-checkout-classes 
*/
function wpsc_google_checkout_submit()
{
    global $wpdb, $wpsc_cart, $current_user;
    $wpsc_checkout = new wpsc_checkout();
    $purchase_log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN('" . $_SESSION['wpsc_sessionid'] . "') LIMIT 1");
    //$purchase_log_id = 1;
    get_currentuserinfo();
    //	exit('<pre>'.print_r($current_user, true).'</pre>');
    if ($current_user->display_name != '') {
        foreach ($wpsc_checkout->checkout_items as $checkoutfield) {
            //	exit(print_r($checkoutfield,true));
            if ($checkoutfield->unique_name == 'billingfirstname') {
                $checkoutfield->value = $current_user->display_name;
            }
        }
    }
    if ($current_user->user_email != '') {
        foreach ($wpsc_checkout->checkout_items as $checkoutfield) {
            //	exit(print_r($checkoutfield,true));
            if ($checkoutfield->unique_name == 'billingemail') {
                $checkoutfield->value = $current_user->user_email;
            }
        }
    }
    $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);
}
Ejemplo n.º 2
0
/**
 * wpsc google checkout submit used for google checkout (unsure whether necessary in 3.8)
 * @access public
 *
 * @since 3.7
 */
function wpsc_google_checkout_submit()
{
    global $wpdb, $wpsc_cart, $current_user;
    $wpsc_checkout = new wpsc_checkout();
    $purchase_log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN(%s) LIMIT 1", wpsc_get_customer_meta('checkout_session_id'));
    get_currentuserinfo();
    if ($current_user->display_name != '') {
        foreach ($wpsc_checkout->checkout_items as $checkoutfield) {
            if ($checkoutfield->unique_name == 'billingfirstname') {
                $checkoutfield->value = $current_user->display_name;
            }
        }
    }
    if ($current_user->user_email != '') {
        foreach ($wpsc_checkout->checkout_items as $checkoutfield) {
            if ($checkoutfield->unique_name == 'billingemail') {
                $checkoutfield->value = $current_user->user_email;
            }
        }
    }
    $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);
}
Ejemplo n.º 3
0
/**
 * get the global checkout object, will create it
 *
 * @return wpsc_checkout       the global checkout object
 */
function wpsc_core_get_checkout()
{
    global $wpsc_checkout;
    if (empty($wpsc_checkout) || !is_a($wpsc_checkout, 'wpsc_checkout')) {
        $wpsc_checkout = new wpsc_checkout();
    }
    $wpsc_checkout->rewind_checkout_items();
    return $wpsc_checkout;
}
/**
 *	Create an array of item name and active status
 * @access public
 *
 * @since 3.8.14
 * @return (boolean)
 */
function _wpsc_create_checkout_item_required_map()
{
    global $wpsc_checkout;
    if (empty($wpsc_checkout)) {
        $wpsc_checkout = new wpsc_checkout();
    }
    $checkout_item_map = array();
    while (wpsc_have_checkout_items()) {
        $checkout_item = wpsc_the_checkout_item();
        if (!empty($checkout_item->unique_name)) {
            $checkout_item_map[$wpsc_checkout->form_item_unique_name()] = $wpsc_checkout->form_name_is_required();
        }
    }
    $wpsc_checkout->rewind_checkout_items();
    return $checkout_item_map;
}
Ejemplo n.º 5
0
/**
 * get the output used to show a shipping state and region select drop down
 *
 * @since 3.8.14
 *
 * @param wpsc_checkout|null  $wpsc_checkout checkout object
 * @return string
 */
function wpsc_checkout_shipping_state_and_region($wpsc_checkout = null)
{
    // just in case the checkout form was not presented, like when we are doing the shipping calculator
    if (empty($wpsc_checkout)) {
        $wpsc_checkout = new wpsc_checkout();
        $doing_checkout_form = false;
    } else {
        $doing_checkout_form = true;
    }
    // if we aren't showing the shipping state on the cor we have no work to do
    if (!$wpsc_checkout->get_checkout_item('shippingstate')) {
        return '';
    }
    // save the current checkout item in case we adjust it in the routine, we'll put it back before return
    $saved_checkout_item = $wpsc_checkout->checkout_item;
    // check a new checkout form with all fields
    $checkout_form = new WPSC_Checkout_Form(null, false);
    // is the shipping country visible on the form, let's find out
    $shipping_country_form_element = $checkout_form->get_field_by_unique_name('shippingcountry');
    $showing_shipping_country = (bool) $shipping_country_form_element->active;
    // make sure the shipping state is the current checkout element
    $wpsc_checkout->checkout_item = $wpsc_checkout->get_checkout_item('shippingstate');
    // setup the edit field, aka 'shippingstate'
    $shipping_country = wpsc_get_customer_meta('shippingcountry');
    $shipping_region = wpsc_get_customer_meta('shippingregion');
    $shipping_state = wpsc_get_customer_meta('shippingstate');
    // if we are showing the billing country on the form then we use the value that can be
    // changed by the user, otherwise we will use the base country as configured in store admin
    if ($showing_shipping_country) {
        $wpsc_country = new WPSC_Country($shipping_country);
    } else {
        $wpsc_country = new WPSC_Country(wpsc_get_base_country());
    }
    $region_list = $wpsc_country->get_regions();
    $placeholder = $wpsc_country->get('region_label');
    if (empty($placeholder)) {
        $placeholder = $wpsc_checkout->checkout_item->name;
    }
    $placeholder = apply_filters('wpsc_checkout_field_placeholder', apply_filters('wpsc_checkout_field_name', $placeholder), $wpsc_checkout->checkout_item);
    $form_element_id = $wpsc_checkout->form_element_id();
    if ($doing_checkout_form) {
        $id_attribute = ' id="' . $form_element_id . '" ';
    } else {
        $id_attribute = '';
    }
    // if there are regions for the current country we are going to
    // create the billing state edit, but hide it
    $style = ' ';
    if (!empty($region_list)) {
        $style = 'style="display: none;"';
    }
    $output = '<input class="shipping_region text  wpsc-visitor-meta" ' . ' data-wpsc-meta-key="' . $wpsc_checkout->checkout_item->unique_name . '" ' . ' title="' . $wpsc_checkout->checkout_item->unique_name . '" ' . ' type="text" ' . $id_attribute . ' placeholder="' . esc_attr($placeholder) . '" ' . ' value="' . esc_attr($shipping_state) . '" ' . ' name="collected_data[' . $wpsc_checkout->checkout_item->id . ']" ' . $style . ' />' . "\n\r";
    // setup the drop down field, aka 'shippingregion'
    // move the checkout item pointer to the billing country, so we can generate form element ids, highly lame
    $wpsc_checkout->checkout_item = $checkout_form->get_field_by_unique_name('shippingcountry');
    // if there aren't any regions for the current country we are going to
    // create the empty region select, but hide it
    $style = ' ';
    if (empty($region_list)) {
        $style = 'style="display: none;"';
    }
    $title = 'shippingregion';
    $region_form_id = $wpsc_checkout->form_element_id() . '_region';
    $output .= '<select id="' . $region_form_id . '" ' . ' class="current_region wpsc-visitor-meta wpsc-region-dropdown" ' . ' data-wpsc-meta-key="shippingregion" ' . ' title="' . $title . '" ' . 'name="collected_data[' . $wpsc_checkout->checkout_item->id . '][1]" ' . $style . ">\n\r";
    $wpsc_current_region = $wpsc_country->get_region($shipping_region);
    if (!empty($region_list)) {
        if (count($region_list) > 1) {
            $label = $wpsc_country->get('region_label');
            $please_select_message = sprintf(__('Please select a %s', 'wp-e-commerce'), $label);
            $output .= "<option value='0'>" . $please_select_message . "</option>\n\r";
        }
        foreach ($region_list as $wpsc_region) {
            if ((bool) $wpsc_current_region && $wpsc_current_region->get_id() == $wpsc_region->get_id()) {
                $selected = "selected='selected'";
            } else {
                $selected = '';
            }
            $output .= "<option value='" . $wpsc_region->get_id() . "' {$selected}>" . esc_html($wpsc_region->get_name()) . "</option>\n\r";
        }
    }
    $output .= "</select>\n\r";
    // restore the checkout item in case we messed with it
    $wpsc_checkout->checkout_item = $saved_checkout_item;
    return $output;
}
Ejemplo n.º 6
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;
    //echo "break redirect";
    //
    do_action('wpsc_before_submit_checkout');
    $_SESSION['wpsc_checkout_misc_error_messages'] = array();
    $wpsc_checkout = new wpsc_checkout();
    //exit('coupons:'.$wpsc_cart->coupons_name);
    $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 (get_option('do_not_use_shipping') == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null) && $wpsc_cart->uses_shipping) {
        $_SESSION['wpsc_checkout_misc_error_messages'][] = __('You must select a shipping method, otherwise we cannot process your order.', 'wpsc');
        $is_valid = false;
    }
    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) {
        //	exit('<pre>'.print_r($cartitem, true).'</pre>');
        $categoriesIDs = $wpdb->get_col("SELECT category_id FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` WHERE product_id=" . $cartitem->product_id);
        foreach ((array) $categoriesIDs as $catid) {
            if (is_array($catid)) {
                $sql = "SELECT `countryid` FROM `" . WPSC_TABLE_CATEGORY_TM . "` WHERE `visible`=0 AND `categoryid`=" . $catid[0];
            } else {
                $sql = "SELECT `countryid` FROM `" . WPSC_TABLE_CATEGORY_TM . "` WHERE `visible`=0 AND `categoryid`=" . $catid;
            }
            $countries = $wpdb->get_col($sql);
            if (in_array($selectedCountry[0]['id'], (array) $countries)) {
                $errormessage = sprintf(__('Oops the product : %s cannot be shipped to %s. To continue with your transaction please remove this product from the list above.', '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++;
        }
    }
    // exit('valid >'.$is_valid);
    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') != 1 && in_array('ups', (array) $options) && $_SESSION['wpsc_zipcode'] == '') {
        //exit('Not being called');
        if ($num_items != $disregard_shipping) {
            //<-- new line of code
            $_SESSION['categoryAndShippingCountryConflict'] = __('Please enter a Zipcode and click calculate to proceed');
            $is_valid = false;
        }
    }
    if ($is_valid == true || $_GET['gateway'] == 'noca') {
        $_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;
        }
        if (isset($_POST['how_find_us'])) {
            $find_us = $_POST['how_find_us'];
        } else {
            $find_us = '';
        }
        $tax = $wpsc_cart->calculate_total_tax();
        $total = $wpsc_cart->calculate_total_price();
        // Make sure delivery and selected region are onlly saved if the country does have regions
        // Im unsure how this would effect countries that HAVE regions, i.e if you select Canada as country,, will your 			// region be alabama if no region was selected?
        $wpsc_cart->update_location();
        if (!wpsc_has_regions($wpsc_cart->selected_country)) {
            $wpsc_cart->selected_region = '';
        }
        if (!wpsc_has_regions($wpsc_cart->delivery_country)) {
            $wpsc_cart->delivery_region = '';
        }
        $sql = "INSERT INTO `" . WPSC_TABLE_PURCHASE_LOGS . "` (`totalprice`,`statusno`, `sessionid`, `user_ID`, `date`, `gateway`, `billing_country`,`shipping_country`, `billing_region`, `shipping_region`, `base_shipping`,`shipping_method`, `shipping_option`, `plugin_version`, `discount_value`, `discount_data`,`find_us`) VALUES ('{$total}' ,'0', '{$sessionid}', '" . (int) $user_ID . "', UNIX_TIMESTAMP(), '{$submitted_gateway}', '{$wpsc_cart->selected_country}', '{$wpsc_cart->delivery_country}','{$wpsc_cart->selected_region}', '{$wpsc_cart->delivery_region}', '{$base_shipping}', '{$wpsc_cart->selected_shipping_method}', '{$wpsc_cart->selected_shipping_option}', '" . WPSC_VERSION . "', '{$wpsc_cart->coupons_amount}','{$wpsc_cart->coupons_name}', '{$find_us}')";
        //exit($sql);
        $wpdb->query($sql);
        $purchase_log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN('{$sessionid}') LIMIT 1");
        //exit('PurchLog id'.$purchase_log_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();
        }
        wp_get_current_user();
        $our_user_id = $user_ID;
        do_action('wpsc_submit_checkout', array("purchase_log_id" => $purchase_log_id, "our_user_id" => $our_user_id));
        if (get_option('permalink_structure') != '') {
            $seperator = "?";
        } else {
            $seperator = "&";
        }
        if ($total <= 0) {
            $transaction_url_with_sessionid = add_query_arg('sessionid', $session_id, get_option('transact_url'));
            wp_redirect($transaction_url_with_sessionid);
        }
        /// 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();
            //print_r($merchant_instance);
        } else {
            if ($current_gateway_data['internalname'] == $submitted_gateway && $current_gateway_data['internalname'] != 'google') {
                $gateway_used = $current_gateway_data['internalname'];
                $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `gateway` = '" . $gateway_used . "' WHERE `id` = '" . $log_id . "' LIMIT 1 ;");
                $current_gateway_data['function']($seperator, $sessionid);
                //break;
            } else {
                if ($_POST['custom_gateway'] == 'google') {
                    $gateway_used = $current_gateway_data['internalname'];
                    $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `gateway` = '" . $gateway_used . "' WHERE `id` = '" . $log_id . "' LIMIT 1 ;");
                    $_SESSION['gateway'] = 'google';
                    header('Location: ' . get_option('shopping_cart_url'));
                    exit;
                    //break;
                }
            }
        }
        if (isset($_GET['gateway']) && $_GET['gateway'] == 'noca') {
            //exit('HERE2');
            echo transaction_results($sessionid, true);
        } else {
            //exit('HERE');
        }
    } else {
    }
}
Ejemplo n.º 7
0
function wpsc_shipping_country_list($shippingdetails = false)
{
    global $wpsc_shipping_modules;
    $wpsc_checkout = new wpsc_checkout();
    $wpsc_checkout->checkout_item = $shipping_country_checkout_item = $wpsc_checkout->get_checkout_item('shippingcountry');
    $output = '';
    if ($shipping_country_checkout_item && $shipping_country_checkout_item->active) {
        if (!$shippingdetails) {
            $output = "<input type='hidden' name='wpsc_ajax_action' value='update_location' />";
        }
        $acceptable_countries = wpsc_get_acceptable_countries();
        // if there is only one country to choose from we are going to set that as the shipping country,
        // later in the UI generation the same thing will happen to make the single country the current
        // selection
        $countries = WPSC_Countries::get_countries(false);
        if (count($countries) == 1) {
            reset($countries);
            $id_of_only_country_available = key($countries);
            $wpsc_country = new WPSC_Country($id_of_only_country_available);
            wpsc_update_customer_meta('shippingcountry', $wpsc_country->get_isocode());
        }
        $selected_country = wpsc_get_customer_meta('shippingcountry');
        $additional_attributes = 'data-wpsc-meta-key="shippingcountry" ';
        $output .= wpsc_get_country_dropdown(array('id' => 'current_country', 'name' => 'country', 'class' => 'current_country wpsc-visitor-meta', 'acceptable_ids' => $acceptable_countries, 'selected' => $selected_country, 'additional_attributes' => $additional_attributes, 'placeholder' => __('Please select a country', 'wp-e-commerce')));
    }
    $output .= wpsc_checkout_shipping_state_and_region();
    $zipvalue = (string) wpsc_get_customer_meta('shippingpostcode');
    $zip_code_text = __('Your Zipcode', 'wp-e-commerce');
    if ($zipvalue != '' && $zipvalue != $zip_code_text) {
        $color = '#000';
        wpsc_update_customer_meta('shipping_zip', $zipvalue);
    } else {
        $zipvalue = $zip_code_text;
        $color = '#999';
    }
    $uses_zipcode = false;
    $custom_shipping = get_option('custom_shipping_options');
    foreach ((array) $custom_shipping as $shipping) {
        if (isset($wpsc_shipping_modules[$shipping]->needs_zipcode) && $wpsc_shipping_modules[$shipping]->needs_zipcode == true) {
            $uses_zipcode = true;
        }
    }
    if ($uses_zipcode) {
        $output .= " <input data-wpsc-meta-key='shippingpostcode' class='wpsc-visitor-meta' type='text' style='color:" . $color . ";' onclick='if (this.value==\"" . esc_js($zip_code_text) . "\") {this.value=\"\";this.style.color=\"#000\";}' onblur='if (this.value==\"\") {this.style.color=\"#999\"; this.value=\"" . esc_js($zip_code_text) . "\"; }' value='" . esc_attr($zipvalue) . "' size='10' name='zipcode' id='zipcode'>";
    }
    return $output;
}
Ejemplo n.º 8
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'));
        }
    }
}
Ejemplo n.º 9
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;
    $_SESSION['wpsc_checkout_misc_error_messages'] = array();
    $wpsc_checkout = new wpsc_checkout();
    //exit('coupons:'.$wpsc_cart->coupons_name);
    $selected_gateways = get_option('custom_gateway_options');
    $submitted_gateway = $_POST['custom_gateway'];
    $options = get_option('custom_shipping_options');
    $form_validity = $wpsc_checkout->validate_forms();
    //exit('<pre>'.print_r($_POST, true).'</pre>');
    //	exit('2<pre>'.print_r($_SESSION['wpsc_zipcode'], true).'</pre>');
    extract($form_validity);
    // extracts $is_valid and $error_messages
    //	exit('<pre>'.print_r($results, true).'</pre>');
    if (get_option('do_not_use_shipping') == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null)) {
        $_SESSION['wpsc_checkout_misc_error_messages'][] = TXT_WPSC_PLEASEASELECTSHIPPINGMETHOD;
        $is_valid = false;
    }
    if ($_POST['agree'] != 'yes') {
        $_SESSION['wpsc_checkout_misc_error_messages'][] = TXT_WPSC_PLEASEAGREETERMSANDCONDITIONS;
        $is_valid = false;
    }
    //exit('<pre>'.print_r($_POST, true).'</pre>');
    $selectedCountry = $wpdb->get_results("SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode='" . $wpdb->escape($_SESSION['wpsc_delivery_country']) . "'", ARRAY_A);
    //  exit('valid >'.$is_valid.'\r\n'.$_SESSION['wpsc_delivery_country']);
    foreach ($wpsc_cart->cart_items as $cartitem) {
        //	exit('<pre>'.print_r($cartitem, true).'</pre>');
        $categoriesIDs = $wpdb->get_col("SELECT category_id FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` WHERE product_id=" . $cartitem->product_id);
        foreach ((array) $categoriesIDs as $catid) {
            if (is_array($catid)) {
                $sql = "SELECT `countryid` FROM `" . WPSC_TABLE_CATEGORY_TM . "` WHERE `visible`=0 AND `categoryid`=" . $catid[0];
            } else {
                $sql = "SELECT `countryid` FROM `" . WPSC_TABLE_CATEGORY_TM . "` WHERE `visible`=0 AND `categoryid`=" . $catid;
            }
            $countries = $wpdb->get_col($sql);
            if (in_array($selectedCountry[0]['id'], (array) $countries)) {
                $errormessage = sprintf(TXT_WPSC_CATEGORY_TARGETMARKET, $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++;
        }
    }
    // exit('valid >'.$is_valid);
    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') != 1 && in_array('ups', (array) $options) && $_SESSION['wpsc_zipcode'] == '') {
        //exit('Not being called');
        if ($num_items != $disregard_shipping) {
            //<-- new line of code
            $_SESSION['categoryAndShippingCountryConflict'] = __('Please enter a Zipcode and click calculate to proceed');
            $is_valid = false;
        }
    }
    if ($is_valid == true || $_GET['gateway'] == 'noca') {
        $_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;
        }
        if (isset($_POST['how_find_us'])) {
            $find_us = $_POST['how_find_us'];
        } else {
            $find_us = '';
        }
        $tax = $wpsc_cart->calculate_total_tax();
        $total = $wpsc_cart->calculate_total_price();
        $sql = "INSERT INTO `" . WPSC_TABLE_PURCHASE_LOGS . "` (`totalprice`,`statusno`, `sessionid`, `user_ID`, `date`, `gateway`, `billing_country`,`shipping_country`, `billing_region`, `shipping_region`, `base_shipping`,`shipping_method`, `shipping_option`, `plugin_version`, `discount_value`, `discount_data`,`find_us`) VALUES ('{$total}' ,'0', '{$sessionid}', '" . (int) $user_ID . "', UNIX_TIMESTAMP(), '{$submitted_gateway}', '{$wpsc_cart->delivery_country}', '{$wpsc_cart->selected_country}','{$wpsc_cart->selected_region}', '{$wpsc_cart->delivery_region}', '{$base_shipping}', '{$wpsc_cart->selected_shipping_method}', '{$wpsc_cart->selected_shipping_option}', '" . WPSC_VERSION . "', '{$wpsc_cart->coupons_amount}','{$wpsc_cart->coupons_name}', '{$find_us}')";
        //exit($sql);
        $wpdb->query($sql);
        $purchase_log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN('{$sessionid}') LIMIT 1");
        //exit('PurchLog id'.$purchase_log_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();
        }
        do_action('wpsc_submit_checkout', array("purchase_log_id" => $purchase_log_id, "our_user_id" => $our_user_id));
        if (get_option('permalink_structure') != '') {
            $seperator = "?";
        } else {
            $seperator = "&";
        }
        // submit to gateway
        foreach ($nzshpcrt_gateways as $gateway) {
            if ($gateway['internalname'] == $submitted_gateway && $gateway['internalname'] != 'google') {
                $gateway_used = $gateway['internalname'];
                $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `gateway` = '" . $gateway_used . "' WHERE `id` = '" . $log_id . "' LIMIT 1 ;");
                $gateway['function']($seperator, $sessionid);
                break;
            } elseif ($gateway['internalname'] == 'google' && $gateway['internalname'] == $submitted_gateway) {
                $gateway_used = $gateway['internalname'];
                $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `gateway` = '" . $gateway_used . "' WHERE `id` = '" . $log_id . "' LIMIT 1 ;");
                $_SESSION['gateway'] = 'google';
                header('Location: ' . get_option('shopping_cart_url'));
                break;
            }
        }
        if (isset($_GET['gateway']) && $_GET['gateway'] == 'noca') {
            //exit('HERE2');
            echo transaction_results($sessionid, true);
        } else {
            //exit('HERE');
        }
    } else {
    }
}
Ejemplo n.º 10
0
/**
 * wpsc_display_form_fields()
 *
 * This function displays each of the form fields.  Each of them are filterable via 'wpsc_account_form_field_$tag' where tag is permalink-styled name or uniquename.
 * i.e. First Name under Shipping would be 'wpsc_account_form_field_shippingfirstname' - while Your Billing Details would be filtered
 * via 'wpsc_account_form_field_your-billing-details'.
 *
 * @global <type> $wpdb
 * @global <type> $user_ID
 * @global <type> $wpsc_purchlog_statuses
 * @global <type> $gateway_checkout_form_fields
 */
function wpsc_display_form_fields()
{
    // Field display and Data saving function
    global $wpdb, $user_ID, $wpsc_purchlog_statuses, $gateway_checkout_form_fields, $wpsc_checkout;
    if (empty($wpsc_checkout)) {
        $wpsc_checkout = new wpsc_checkout();
    }
    $meta_data = wpsc_get_customer_meta('checkout_details');
    $meta_data = apply_filters('wpsc_user_log_get', $meta_data, $user_ID);
    $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' ORDER BY `checkout_set`, `checkout_order`;";
    $form_data = $wpdb->get_results($form_sql, ARRAY_A);
    foreach ($form_data as $form_field) {
        if (!empty($form_field['unique_name'])) {
            $ff_tag = $form_field['unique_name'];
        } else {
            $ff_tag = esc_html(strtolower(str_replace(' ', '-', $form_field['name'])));
        }
        if (!empty($meta_data[$form_field['id']]) && !is_array($meta_data[$form_field['id']])) {
            $meta_data[$form_field['id']] = esc_html($meta_data[$form_field['id']]);
        }
        if ($form_field['type'] == 'heading') {
            echo "\n    <tr>\n      <td colspan='2'>\n\r";
            echo "<strong>" . apply_filters('wpsc_account_form_field_' . $ff_tag, esc_html($form_field['name'])) . "</strong>";
            echo "\n      </td>\n    </tr>\n\r";
        } else {
            $display = '';
            if (in_array($form_field['unique_name'], array('shippingstate', 'billingstate'))) {
                if ($form_field['unique_name'] == 'shippingstate') {
                    $country_field_id = wpsc_get_country_form_id_by_type('delivery_country');
                } else {
                    $country_field_id = wpsc_get_country_form_id_by_type('country');
                }
                $country = is_array($meta_data[$country_field_id]) ? $meta_data[$country_field_id][0] : $meta_data[$country_field_id];
                if (wpsc_has_regions($country)) {
                    $display = ' style="display:none;"';
                }
            }
            echo "\n\t\t      <tr{$display}>\n    \t\t    <td align='left'>\n\r";
            echo apply_filters('wpsc_account_form_field_' . $ff_tag, $form_field['name']);
            if ($form_field['mandatory'] == 1) {
                echo " *";
            }
            echo "\n        \t\t</td>\n\r\n        \t\t<td  align='left'>\n\r";
            switch ($form_field['type']) {
                case "city":
                case "delivery_city":
                    echo "<input type='text' value='" . $meta_data[$form_field['id']] . "' name='collected_data[" . $form_field['id'] . "]' />";
                    break;
                case "address":
                case "delivery_address":
                case "textarea":
                    echo "<textarea name='collected_data[" . $form_field['id'] . "]'>" . $meta_data[$form_field['id']] . "</textarea>";
                    break;
                case "text":
                    $value = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : '';
                    echo "<input type='text' value='" . $value . "' name='collected_data[" . $form_field['id'] . "]' />";
                    break;
                case "region":
                case "delivery_region":
                    echo "<select name='collected_data[" . $form_field['id'] . "]'>" . nzshpcrt_region_list($_SESSION['collected_data'][$form_field['id']]) . "</select>";
                    break;
                case "country":
                    if (is_array($meta_data[$form_field['id']])) {
                        $country_code = $meta_data[$form_field['id']][0];
                    } else {
                        $country_code = $meta_data[$form_field['id']];
                    }
                    $html_id = 'wpsc-profile-billing-country';
                    $js = "onchange=\"wpsc_set_profile_country('{$html_id}', '" . $form_field['id'] . "');\"";
                    echo "<select id='{$html_id}' {$js} name='collected_data[" . $form_field['id'] . "][0]' >" . nzshpcrt_country_list($country_code) . "</select>";
                    if (wpsc_has_regions($country_code)) {
                        $region = isset($meta_data[$form_field['id']][1]) ? $meta_data[$form_field['id']][1] : '';
                        echo "<br /><select name='collected_data[" . $form_field['id'] . "][1]'>" . nzshpcrt_region_list($country_code, $region) . "</select>";
                    }
                    break;
                case "delivery_country":
                    if (is_array($meta_data[$form_field['id']])) {
                        $country_code = $meta_data[$form_field['id']][0];
                    } else {
                        $country_code = $meta_data[$form_field['id']];
                    }
                    $html_id = 'wpsc-profile-shipping-country';
                    $js = "onchange=\"wpsc_set_profile_country('{$html_id}', '" . $form_field['id'] . "');\"";
                    echo "<select id='{$html_id}' {$js} name='collected_data[" . $form_field['id'] . "][0]' >" . nzshpcrt_country_list($country_code) . "</select>";
                    if (wpsc_has_regions($country_code)) {
                        $region = isset($meta_data[$form_field['id']][1]) ? $meta_data[$form_field['id']][1] : '';
                        echo "<br /><select name='collected_data[" . $form_field['id'] . "][1]'>" . nzshpcrt_region_list($country_code, $region) . "</select>";
                    }
                    break;
                case "email":
                    echo "<input type='text' value='" . $meta_data[$form_field['id']] . "' name='collected_data[" . $form_field['id'] . "]' />";
                    break;
                case "select":
                    $options = $wpsc_checkout->get_checkout_options($form_field['id']);
                    $selected = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : null;
                    ?>
						<select name='collected_data[<?php 
                    echo esc_attr($form_field['id']);
                    ?>
]'>
							<option value="-1"><?php 
                    _ex('Select an Option', 'Dropdown default on user log page', 'wp-e-commerce');
                    ?>
</option>
							<?php 
                    foreach ($options as $label => $value) {
                        ?>
								<option <?php 
                        selected($value, $selected);
                        ?>
 value="<?php 
                        echo esc_attr($value);
                        ?>
"><?php 
                        echo esc_html($label);
                        ?>
</option>
							<?php 
                    }
                    ?>
						</select>
					<?php 
                    break;
                case 'checkbox':
                case 'radio':
                    $checked_values = isset($meta_data[$form_field['id']]) ? (array) $meta_data[$form_field['id']] : array();
                    $options = $wpsc_checkout->get_checkout_options($form_field['id']);
                    $field_name = "collected_data[{$form_field['id']}]";
                    if ($form_field['type'] == 'checkbox') {
                        $field_name .= '[]';
                    }
                    foreach ($options as $label => $value) {
                        ?>
							<label>
								<input <?php 
                        checked(in_array($value, $checked_values));
                        ?>
 type="<?php 
                        echo $form_field['type'];
                        ?>
" id="" name="collected_data[<?php 
                        echo esc_attr($form_field['id']);
                        ?>
][]" value="<?php 
                        echo esc_attr($value);
                        ?>
"  />
								<?php 
                        echo esc_html($label);
                        ?>
							</label><br />
						<?php 
                    }
                    break;
                default:
                    $value = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : '';
                    echo "<input type='text' value='" . $value . "' name='collected_data[" . $form_field['id'] . "]' />";
                    break;
            }
            echo wp_nonce_field('wpsc_user_profile', '_wpsc_user_profile');
            echo "\n        </td>\n      </tr>\n\r";
        }
    }
    /* Returns an empty array at this point, empty in regards to fields, does show the internalname though.  Needs to be reconsidered, even if it did work, need to check
    	 * functionality and PCI_DSS compliance
    
    	  if ( isset( $gateway_checkout_form_fields ) )
    	  {
    	  echo $gateway_checkout_form_fields;
    	  }
    	 */
}
Ejemplo n.º 11
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);
    }
}