示例#1
0
function wpsc_save_customer_details($customer_details)
{
    $customer_details = apply_filters('wpsc_update_customer_checkout_details', $customer_details);
    // legacy filter
    if (is_user_logged_in()) {
        $customer_details = apply_filters('wpsc_checkout_user_profile_update', $customer_details, get_current_user_id());
    }
    wpsc_update_customer_meta('checkout_details', $customer_details);
}
function gateway_google($fromcheckout = false)
{
    global $wpdb, $wpsc_cart, $wpsc_checkout, $current_user, $purchlogs;
    if (!isset($wpsc_checkout)) {
        $wpsc_checkout = new wpsc_checkout();
    }
    $sessionid = (string) wpsc_get_customer_meta('google_checkout_session_id');
    if (empty($sessionid)) {
        $sessionid = mt_rand(100, 999) . time();
        wpsc_update_customer_meta('google_checkout_session_id', $sessionid);
    }
    $delivery_region = wpsc_get_customer_meta('shipping_region');
    $billing_region = wpsc_get_customer_meta('billing_region');
    if (!$billing_region && !$billing_region) {
        $base_region = get_option('base_region');
        wpsc_update_customer_meta('shipping_region', $base_region);
        wpsc_update_customer_meta('billing_region', $base_region);
    }
    $wpsc_cart->get_shipping_option();
    $wpsc_cart->get_shipping_quotes();
    $wpsc_cart->get_shipping_method();
    $wpsc_cart->google_shipping_quotes();
    $subtotal = $wpsc_cart->calculate_subtotal();
    $base_shipping = $wpsc_cart->calculate_total_shipping();
    $tax = $wpsc_cart->calculate_total_tax();
    $total = $wpsc_cart->calculate_total_price();
    if ($total > 0) {
        $update = $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('totalprice' => $total, 'statusno' => 0, 'user_ID' => $user_ID, 'date' => time(), 'gateway' => 'google', 'billing_country' => $wpsc_cart->delivery_country, 'shipping_country' => $wpsc_cart->selected_country, 'base_shipping' => $base_shipping, 'shipping_method' => $wpsc_cart->selected_shipping_method, 'shipping_option' => $wpsc_cart->selected_shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name), array('sessionid' => $sessionid), array('%f', '%d', '%d', '%s', '%s', '%s', '%s', '%f', '%s', '%s', '%s', '%f', '%s'), '%s');
        $sql = $wpdb->prepare("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE sessionid = %s", $sessionid);
        $purchase_log_id = $wpdb->get_var($sql);
        if (!empty($purchase_log_id)) {
            $sql = $wpdb->prepare("DELETE FROM  `" . WPSC_TABLE_CART_CONTENTS . "` WHERE purchaseid = %d", $purchase_log_id);
            $wpdb->query($sql);
        }
        if (!$update) {
            $wpdb->insert(WPSC_TABLE_PURCHASE_LOGS, array('totalprice' => $total, 'statusno' => 0, 'sessionind' => $sessionid, 'user_ID' => $user_ID, 'date' => time(), 'gateway' => 'google', 'billing_country' => $wpsc_cart->delivery_country, 'shipping_country' => $wpsc_cart->selected_country, 'base_shipping' => $base_shipping, 'shipping_method' => $wpsc_cart->selected_shipping_method, 'shipping_option' => $wpsc_cart->selected_shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name), array('%f', '%d', '%s', '%d', '%s', '%s', '%s', '%f', '%s', '%s', '%s', '%s', '%f', '%s'), '%s');
            $purchase_log_id = $wpdb->insert_id;
        }
        $wpsc_cart->save_to_db($purchase_log_id);
        if (get_option('permalink_structure') != '') {
            $separator = "?";
        } else {
            $separator = "&";
        }
        Usecase($separator, $sessionid, $fromcheckout);
    }
}
示例#3
0
function _wpsc_copy_billing_details()
{
    $form = WPSC_Checkout_Form::get();
    $fields = $form->get_fields();
    $fields_to_copy = array('firstname', 'lastname', 'address', 'city', 'state', 'country', 'postcode');
    $field_ids = array('shipping' => array(), 'billing' => array());
    foreach ($fields as $field) {
        if (!empty($field->unique_name) && preg_match('/^(billing|shipping)(.+)/', $field->unique_name, $matches) && in_array($matches[2], $fields_to_copy)) {
            $field_ids[$matches[1]][$matches[2]] = $field->id;
        }
    }
    $post_data =& $_POST['wpsc_checkout_details'];
    foreach ($field_ids['shipping'] as $name => $id) {
        $billing_field_id = $field_ids['billing'][$name];
        $post_data[$id] = $post_data[$billing_field_id];
    }
    wpsc_update_customer_meta('wpsc_copy_billing_details', '1');
}
示例#4
0
 function wpec_auth_delete($type, $id)
 {
     $myGateway = new wpec_auth_net();
     if ($type != 'shippingadress') {
         $result = $myGateway->deletePay($id);
         if ($result === false) {
             wpsc_update_customer_meta('auth_net_message', $result);
         } else {
             wpsc_update_customer_meta('auth_net_message', __('Saved Payment Details Have Been Deleted.', 'wpsc_gold_cart'));
         }
     } else {
         $result = $myGateway->deleteShip($id);
         if ($result === false) {
             wpsc_update_customer_meta('auth_net_message', $result);
         } else {
             wpsc_update_customer_meta('auth_net_message', __('Saved Shipping Details Have Been Deleted.', 'wpsc_gold_cart'));
         }
     }
 }
/**
 * Setup current user object and customer ID as well as cart.
 *
 * @uses  do_action() Calls 'wpsc_setup_customer' after customer data is ready
 * @access private
 * @since  3.8.13
 * @return int visitor id
 *
 */
function _wpsc_action_setup_customer()
{
    /////////////////////////////////////////////////////////////////////////
    // Setting up the customer happens after WPEC is initialized AND after
    // WordPress has loaded.  The reason for this is that the conditional
    // query tags are checked to see if the request is a 404 or a feed or
    // some other request that should not create a visitor profile.  The
    // conditional query tags are not available until after the
    // posts_selection hook is processed.  The 'wp' action is fired after
    // the 'posts_selection' hook.
    /////////////////////////////////////////////////////////////////////////
    if (!did_action('init')) {
        _wpsc_doing_it_wrong(__FUNCTION__, __('Customer cannot be reliably setup until at least the "init" hook as been fired during AJAX processing.', 'wpsc'), '3.8.14');
    }
    // if the customer cookie is invalid, unset it
    $visitor_id_from_cookie = _wpsc_validate_customer_cookie();
    if ($visitor_id_from_cookie && is_user_logged_in()) {
        $id_from_wp_user = get_user_meta(get_current_user_id(), _wpsc_get_visitor_meta_key('visitor_id'), true);
        if (empty($id_from_wp_user)) {
            _wpsc_update_wp_user_visitor_id(get_current_user_id(), $visitor_id_from_cookie);
        } elseif ($visitor_id_from_cookie != $id_from_wp_user) {
            // save the old visitor id so the merge cart function can do its work
            wpsc_update_customer_meta('merge_cart_vistor_id', $visitor_id_from_cookie);
            // make the current customer cookie match the cookie that is in the WordPress user meta
            _wpsc_create_customer_id_cookie($id_from_wp_user);
            // merging cart requires the taxonomies to have been initialized
            if (did_action('wpsc_register_taxonomies_after')) {
                _wpsc_merge_cart();
            } else {
                add_action('wpsc_register_taxonomies_after', '_wpsc_merge_cart', 1);
            }
        }
    }
    // initialize customer ID if it's not already there
    $visitor_id = wpsc_get_current_customer_id();
    // if there wasn't a visitor id in the cookies we set it now
    if ($visitor_id && empty($visitor_id_from_cookie) && is_user_logged_in()) {
        _wpsc_create_customer_id_cookie($visitor_id);
    }
    // setup the cart and restore its items
    wpsc_core_setup_cart();
    do_action('wpsc_setup_customer', $visitor_id);
}
示例#6
0
 /**
  * update_location method, updates the location
  * @access public
  */
 function update_location()
 {
     $delivery_country = wpsc_get_customer_meta('shipping_country');
     $billing_country = wpsc_get_customer_meta('billing_country');
     $delivery_region = wpsc_get_customer_meta('shipping_region');
     $billing_region = wpsc_get_customer_meta('billing_region');
     if (!$billing_country && !$delivery_country) {
         $billing_country = $delivery_country = get_option('base_country');
     } elseif (!$billing_country) {
         $billing_country = $delivery_country;
     } elseif (!$delivery_country) {
         $delivery_country = $billing_country;
     }
     if (!$billing_region && !$delivery_region) {
         $billing_region = $delivery_region = get_option('base_region');
     }
     wpsc_update_customer_meta('shipping_country', $delivery_country);
     wpsc_update_customer_meta('billing_country', $billing_country);
     wpsc_update_customer_meta('delivery_region', $delivery_region);
     wpsc_update_customer_meta('billing_region', $billing_region);
     $this->delivery_country = $delivery_country;
     $this->selected_country = $billing_country;
     $this->delivery_region = $delivery_region;
     $this->selected_region = $billing_region;
     //adding refresh item
     $this->wpsc_refresh_cart_items();
 }
/**
 * Update customer information using information supplied by shopper on WPeC pages
 *
 * @since 3.8.14
 *
 * @global  $_REQUEST['meta_data']  array of key value pairs that the user has changed, key is meta item name, value is new value
 *
 * @return JSON encoded response array with results
 *
 * 			$RESPONSE['request']		: 	array containing the original AJAX $_REQUEST that was sent to
 * 											the server, use to match up asynchronous AJAX transactions, or
 * 											to see original rquiest paramters
 *
 * 			$RESPONSE['customer_meta']	: 	array of key value pairs containing updated meta values. The
 * 											specific value changed is not included. If there isn't any updated
 * 											customer meta, other than the original meta changed, this array element
 * 											may not be present, or may be present and empty
 *
 * 			$response['checkout_info']  :	array of updated checkout information, array key is the HTML element ID
 * 											where the information is presented on the checkout form. If there isn't
 * 											any updated	checkout information this array element	may not be present,
 * 											or may be present and empty
 *
 *
 */
function wpsc_customer_updated_data_ajax()
{
    $success = true;
    // we will echo back the request in the (likely async) response so that the client knows
    // which transaction the response matches
    $response = array('request' => $_REQUEST);
    // update can be a single key/value pair or an array of key value pairs
    if (!empty($_REQUEST['meta_data'])) {
        $customer_meta = isset($_REQUEST['meta_data']) ? $_REQUEST['meta_data'] : array();
    } elseif (!empty($_REQUEST['meta_key']) && isset($_REQUEST['meta_value'])) {
        $customer_meta = array($_REQUEST['meta_key'] => $_REQUEST['meta_value']);
    } else {
        _wpsc_doing_it_wrong(__FUNCTION__, __('missing meta key or meta array', 'wpsc'), '3.8.14');
        $customer_meta = array();
    }
    // We will want to know which interface elements have changed as a result of this meta update,
    // capture the current state of the elements
    $checkout_info_before_updates = _wpsc_get_checkout_info();
    // We will want to know which, if any, checkout meta changes as a result of hooks and filters
    // that may fire as we update each meta item
    $all_checkout_meta_before_updates = _wpsc_get_checkout_meta();
    if (!empty($customer_meta)) {
        foreach ($customer_meta as $meta_key => $meta_value) {
            // this will echo back any fields to the requester. It's a
            // means for the requester to maintain some state during
            // asynchronous requests
            if (!empty($meta_key)) {
                $updated = wpsc_update_customer_meta($meta_key, $meta_value);
                $success = $success & $updated;
            }
        }
        // loop through a second time so that all of the meta has been set, tht way if there are
        // dependencies in response calculation
        foreach ($customer_meta as $meta_key => $meta_value) {
            $response = apply_filters('wpsc_customer_meta_response_' . $meta_key, $response, $meta_key, $meta_value);
        }
        if ($success) {
            $response['type'] = 'success';
            $response['error'] = '';
        } else {
            $response['type'] = 'error';
            $response['error'] = __('meta values may not have been updated', 'wpsc');
        }
    } else {
        $response['type'] = 'error';
        $response['error'] = __('invalid parameters, meta array or meta key value pair required', 'wpsc');
    }
    // Let's see what the current state of the customer meta set is after we applied the requested updates
    $all_checkout_meta_after_updates = _wpsc_get_checkout_meta();
    foreach ($all_checkout_meta_after_updates as $current_meta_key => $current_meta_value) {
        // if the meta key and value are the same as what was sent in the request we don't need to
        // send them back because the client already knows about this.
        //
        // But we have to check just in case a data rule or a plugin that used our hooks made some adjustments
        if (isset($all_checkout_meta_before_updates[$current_meta_key]) && $all_checkout_meta_before_updates[$current_meta_key] == $current_meta_value) {
            // new value s the same as the old value, why send it?
            unset($all_checkout_meta_after_updates[$current_meta_key]);
            unset($all_checkout_meta_before_updates[$current_meta_key]);
            continue;
        }
        // if the meta value we are considering sending back is one of the values the client gave, we don't send it
        // because the client already knows the meta value and it is probably already visible in the user interface
        if (isset($customer_meta[$current_meta_key]) && $customer_meta[$current_meta_key] == $current_meta_value) {
            // new value s the same as the old value, why send it?
            unset($all_checkout_meta_after_updates[$current_meta_key]);
            continue;
        }
    }
    // Any checkout meta that has changed as a result of the requeeted updates remains
    // in our array, add it to the response
    $response['customer_meta'] = $all_checkout_meta_after_updates;
    // Get the changed checkout information and if something has changed add it to the repsonse
    $new_checkout_info = _wpsc_remove_unchanged_checkout_info($checkout_info_before_updates, _wpsc_get_checkout_info());
    if (!empty($new_checkout_info)) {
        $response['checkout_info'] = $new_checkout_info;
    } else {
        if (isset($response['checkout_info'])) {
            unset($response['checkout_info']);
        }
    }
    // do the shipping quotes need to be recalcualted?
    $response['needs_shipping_recalc'] = wpsc_cart_need_to_recompute_shipping_quotes();
    wp_send_json_success($response);
}
 private function save_customer_settings()
 {
     $form = WPSC_Checkout_Form::get();
     $fields = $form->get_fields();
     $customer_details = wpsc_get_customer_meta('checkout_details');
     if (!is_array($customer_details)) {
         $customer_details = array();
     }
     foreach ($fields as $field) {
         if (!array_key_exists($field->id, $_POST['wpsc_checkout_details'])) {
             continue;
         }
         $value = $_POST['wpsc_checkout_details'][$field->id];
         $customer_details[$field->id] = $value;
         switch ($field->unique_name) {
             case 'billingstate':
                 wpsc_update_customer_meta('billing_region', $value);
                 break;
             case 'shippingstate':
                 wpsc_update_customer_meta('shipping_region', $value);
                 break;
             case 'billingcountry':
                 wpsc_update_customer_meta('billing_country', $value);
                 break;
             case 'shippingcountry':
                 wpsc_update_customer_meta('shipping_country', $value);
                 break;
             case 'shippingpostcode':
                 wpsc_update_customer_meta('shipping_zip', $value);
                 break;
         }
     }
     _wpsc_update_location();
     wpsc_save_customer_details($customer_details);
 }
function validate_form_data()
{
    global $wpdb, $user_ID, $wpsc_purchlog_statuses;
    $any_bad_inputs = false;
    $changes_saved = false;
    $bad_input_message = '';
    $_SESSION['collected_data'] = null;
    if (!empty($_POST['collected_data'])) {
        if (!wp_verify_nonce($_POST['_wpsc_user_profile'], 'wpsc_user_profile')) {
            die(__('It would appear either you are trying to hack into this account, or your session has expired.  Hoping for the latter.', 'wpsc'));
        }
        foreach ((array) $_POST['collected_data'] as $value_id => $value) {
            $form_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `id` = %d LIMIT 1", $value_id);
            $form_data = $wpdb->get_row($form_sql, ARRAY_A);
            $bad_input = false;
            if ($form_data['mandatory'] == 1) {
                switch ($form_data['type']) {
                    case "email":
                        if (!preg_match("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-.]+\\.[a-zA-Z]{2,5}\$/", $value)) {
                            $any_bad_inputs = true;
                            $bad_input = true;
                        }
                        break;
                    case "delivery_country":
                        if ($value != null) {
                            wpsc_update_customer_meta('shipping_country', $value);
                        }
                        break;
                    default:
                        if (empty($value)) {
                            $bad_input = true;
                        }
                        break;
                }
                if ($bad_input === true) {
                    switch ($form_data['name']) {
                        case __('First Name', 'wpsc'):
                            $bad_input_message .= __('Please enter a valid name', 'wpsc') . "";
                            break;
                        case __('Last Name', 'wpsc'):
                            $bad_input_message .= __('Please enter a valid surname', 'wpsc') . "";
                            break;
                        case __('Email', 'wpsc'):
                            $bad_input_message .= __('Please enter a valid email address', 'wpsc') . "";
                            break;
                        case __('Address 1', 'wpsc'):
                        case __('Address 2', 'wpsc'):
                            $bad_input_message .= __('Please enter a valid address', 'wpsc') . "";
                            break;
                        case __('City', 'wpsc'):
                            $bad_input_message .= __('Please enter your town or city.', 'wpsc') . "";
                            break;
                        case __('Phone', 'wpsc'):
                            $bad_input_message .= __('Please enter a valid phone number', 'wpsc') . "";
                            break;
                        case __('Country', 'wpsc'):
                            $bad_input_message .= __('Please select your country from the list.', 'wpsc') . "";
                            break;
                        default:
                            $bad_input_message .= sprintf(__('Please enter a valid <span class="wpsc_error_msg_field_name">%s</span>.', 'wpsc'), esc_html($form_data['name']));
                            break;
                    }
                    $bad_input_message .= "<br />";
                } else {
                    $meta_data[$value_id] = $value;
                }
            } else {
                $meta_data[$value_id] = $value;
            }
        }
        $meta_data = apply_filters('wpsc_user_log_update', $meta_data, $user_ID);
        wpsc_update_customer_meta('checkout_details', $meta_data);
    }
    if ($changes_saved) {
        $message = __('Thanks, your changes have been saved.', 'wpsc');
    } else {
        $message = $bad_input_message;
    }
    return apply_filters('wpsc_profile_message', $message);
}
示例#10
0
 function getQuote()
 {
     global $wpdb, $wpsc_cart;
     if ($this->base_country != 'AU' || strlen($this->base_zipcode) != 4 || !count($wpsc_cart->cart_items)) {
         return;
     }
     $dest = wpsc_get_customer_meta('shipping_country');
     $destzipcode = (string) wpsc_get_customer_meta('shipping_zip');
     if (isset($_POST['zipcode'])) {
         $destzipcode = sanitize_text_field($_POST['zipcode']);
         wpsc_update_customer_meta('shipping_zip', $destzipcode);
     }
     if ($dest == 'AU' && strlen($destzipcode) != 4) {
         // Invalid Australian Post Code entered, so just return an empty set of quotes instead of wasting time contactin the Aus Post API
         return array();
     }
     /*
     3 possible scenarios:
     
     1.
     Cart consists of only item(s) that have "disregard shipping" ticked.
     
     In this case, WPEC doesn't mention shipping at all during checkout, and this shipping module probably won't be executed at all.
     
     Just in case it does get queried, we should still query the Australia Post API for valid shipping estimates,
     and then override the quoted price(s) to $0.00 so the customer is able to get free shipping.
     
     
     2.
     Cart consists of only item(s) where "disregard shipping" isn't ticked (ie. all item(s) attract shipping charges).
     
     In this case, we should query the Australia Post API as per normal.
     
     
     3.
     Cart consists of one or more "disregard shipping" product(s), and one or more other products that attract shipping charges.
     
     In this case, we should query the Aus Post API, only taking into account the product(s) that attract shipping charges.
     Products with "disregard shipping" ticked shouldn't have their weight or dimensions included in the quote.
     */
     // Obtain the total combined weight for all items(s) in the cart (excluding items that have the "Disregard Shipping for this product" option ticked)
     // Weight is in grams
     $weight = wpsc_convert_weight($wpsc_cart->calculate_total_weight(true), 'pound', 'gram');
     // Calculate the total cart dimensions by adding the volume of each product then calculating the cubed root
     $volume = 0;
     // Total number of item(s) in the cart
     $numItems = count($wpsc_cart->cart_items);
     if ($numItems == 0) {
         // The customer's cart is empty. This probably shouldn't occur, but just in case!
         return array();
     }
     // Total number of item(s) that don't attract shipping charges.
     $numItemsWithDisregardShippingTicked = 0;
     foreach ($wpsc_cart->cart_items as $cart_item) {
         if (!$cart_item->uses_shipping) {
             // The "Disregard Shipping for this product" option is ticked for this item.
             // Don't include it in the shipping quote.
             $numItemsWithDisregardShippingTicked++;
             continue;
         }
         // If we are here then this item attracts shipping charges.
         $meta = get_product_meta($cart_item->product_id, 'product_metadata', true);
         $unit = $meta['dimension_unit'];
         $meta = $meta['dimensions'];
         if ($meta && is_array($meta)) {
             $productVolume = 1;
             foreach (array('width', 'height', 'length') as $dimension) {
                 // default dimension to 100mm
                 if (empty($meta[$dimension])) {
                     $meta[$dimension] = 100;
                     $unit = 'mm';
                 }
                 switch ($unit) {
                     // we need the units in mm
                     case 'cm':
                         // convert from cm to mm
                         $meta[$dimension] *= 10;
                         break;
                     case 'meter':
                         // convert from m to mm
                         $meta[$dimension] *= 1000;
                         break;
                     case 'in':
                         // convert from in to mm
                         $meta[$dimension] *= 25.4;
                         break;
                 }
                 $productVolume *= $meta[$dimension];
             }
             $volume += floatval($productVolume) * $cart_item->quantity;
         }
     }
     // If there's only one item in the cart, its dimensions will be used
     // But if there are multiple items, cubic root of total volume will be used instead
     if ($wpsc_cart->get_total_shipping_quantity() == 1) {
         $height = $meta['height'];
         $width = $meta['width'];
         $length = $meta['length'];
     } else {
         // Calculate the cubic root of the total volume, rounding up
         $cuberoot = ceil(pow($volume, 1 / 3));
         if ($cuberoot > 0) {
             $height = $width = $length = $cuberoot;
         }
     }
     // As per http://auspost.com.au/personal/parcel-dimensions.html: if the parcel is box-shaped, both its length and width must be at least 15cm.
     if ($length < 150) {
         $length = 150;
     }
     if ($width < 150) {
         $width = 150;
     }
     // By default we should use Australia Post's quoted rate(s)
     $shippingPriceNeedsToBeZero = false;
     if ($numItemsWithDisregardShippingTicked == $numItems) {
         // The cart consists of entirely "disregard shipping" products, so the shipping quote(s) should be $0.00
         // Set the weight to 1 gram so that we can obtain valid Australia Post quotes (which we will then ignore the quoted price of)
         $weight = 1;
         $shippingPriceNeedsToBeZero = true;
     }
     // API Documentation: http://drc.edeliver.com.au/
     $url = "http://drc.edeliver.com.au/ratecalc.asp";
     $params = array('Pickup_Postcode' => $this->base_zipcode, 'Destination_Postcode' => $destzipcode, 'Quantity' => 1, 'Weight' => $weight, 'Height' => $height, 'Width' => $width, 'Length' => $length, 'Country' => $dest);
     // URL encode the parameters to prevent issues where postcodes contain spaces (eg London postcodes)
     $params = array_map('urlencode', $params);
     $url = add_query_arg($params, $url);
     $log = '';
     $methods = array();
     foreach ($this->services as $code => $service) {
         if (!$this->settings['services'][$code]) {
             continue;
         }
         $fullURL = esc_url_raw(add_query_arg('Service_Type', $code, $url));
         // This cache key should be unique for a cart with these contents and destination
         // Needs to be less than 45 characters (as per http://core.trac.wordpress.org/ticket/15058)
         $cacheKey = 'wpec_apq_' . md5($fullURL);
         // See if this Australia Post quote is cached
         $cachedResult = get_transient($cacheKey);
         if (false === $cachedResult) {
             // Quote isn't cached -> query the Australia Post API and then cache the result for 10 minutes
             $response = wp_safe_remote_get($fullURL);
             // Silently ignore any API server errors
             if (is_wp_error($response) || $response['response']['code'] != '200' || empty($response['body'])) {
                 continue;
             }
             if ($this->debug) {
                 $log .= "  {$fullURL}\n    " . $response['body'] . "\n";
             }
             $lines = explode("\n", $response['body']);
             foreach ($lines as $line) {
                 if (empty($line)) {
                     continue;
                 }
                 list($key, $value) = explode('=', $line);
                 $key = trim($key);
                 $value = trim($value);
                 switch ($key) {
                     case 'charge':
                         if ($shippingPriceNeedsToBeZero) {
                             // All shipping prices quoted should be zero
                             $methods[$code]['charge'] = 0.0;
                             $log .= "  NB: the price for the above quote has been overridden to \$0.00\n\n";
                         } else {
                             // Use the Australia Post quoted price
                             $methods[$code]['charge'] = floatval($value);
                         }
                         break;
                     case 'days':
                         $methods[$code]['days'] = floatval($value);
                         break;
                     case 'err_msg':
                         $methods[$code]['err_msg'] = trim($value);
                         break;
                 }
             }
             $methods[$code]['name'] = $this->services[$code];
             // Cache this quote for 10 minutes
             set_transient($cacheKey, $methods[$code], 600);
         } else {
             // This quote is cached so use that result instead
             $methods[$code] = $cachedResult;
         }
     }
     if ($this->debug && strlen($log)) {
         error_log('WP eCommerce Australia Post shipping quotes for ' . home_url() . ":\n----------\n{$log}----------");
     }
     // Allow another WordPress plugin to override the quoted method(s)/amount(s)
     $methods = apply_filters('wpsc_australia_post_methods', $methods, $this->base_zipcode, $destzipcode, $dest, $weight);
     $quotedMethods = array();
     foreach ($methods as $code => $data) {
         // Only include methods with an OK response
         if ($data['err_msg'] != 'OK') {
             continue;
         }
         if ($data['days']) {
             // If the estimated number of days is specified, so include it in the quote
             $text = sprintf(_n('%1$s (estimated delivery time: %2$d business day)', '%1$s (estimated delivery time: %2$d business days)', $data['days'], 'wpsc'), $data['name'], $data['days']);
         } else {
             // No time estimate
             $text = $data['name'];
         }
         $quotedMethods[$text] = $data['charge'];
     }
     return $quotedMethods;
 }
示例#11
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;
}
 /**
  * Process the SetExpressCheckout API Call
  *
  * @return void
  *
  * @since 3.9
  */
 public function process()
 {
     $total = $this->convert($this->purchase_log->get('totalprice'));
     $options = array('return_url' => $this->get_return_url(), 'message_id' => $this->purchase_log->get('id'), 'invoice' => $this->purchase_log->get('sessionid'), 'address_override' => 1);
     $options += $this->checkout_data->get_gateway_data();
     $options += $this->purchase_log->get_gateway_data(parent::get_currency_code(), $this->get_currency_code());
     if ($this->setting->get('ipn', false)) {
         $options['notify_url'] = $this->get_notify_url();
     }
     // SetExpressCheckout
     $response = $this->gateway->setup_purchase($options);
     if ($response->is_successful()) {
         $params = $response->get_params();
         if ($params['ACK'] == 'SuccessWithWarning') {
             $this->log_error($response);
             wpsc_update_customer_meta('paypal_express_checkout_errors', $response->get_errors());
         }
         // Successful redirect
         $url = $this->get_redirect_url(array('token' => $response->get('token')));
     } else {
         // SetExpressCheckout Failure
         $this->log_error($response);
         wpsc_update_customer_meta('paypal_express_checkout_errors', $response->get_errors());
         $url = add_query_arg(array('payment_gateway' => 'paypal-express-checkout', 'payment_gateway_callback' => 'display_paypal_error'), $this->get_return_url());
     }
     wp_redirect($url);
     exit;
 }
示例#13
0
/**
 * Overwrite customer meta with an array of meta_key => meta_value.
 *
 * Implement your own system by hooking into 'wpsc_update_all_customer_meta'.
 *
 * @access public
 * @since  3.8.9
 * @param  array      $profile Customer meta array
 * @param  int|string $id      Customer ID. Optional. Defaults to current customer.
 * @return boolean             True if meta values are updated successfully. False
 *                             if otherwise.
 */
function wpsc_update_all_customer_meta($profile, $id = false)
{
    if (!$id) {
        $id = wpsc_get_current_customer_id();
    }
    $result = apply_filters('wpsc_update_all_customer_meta', null, $profile, $id);
    if ($result) {
        return $result;
    }
    wpsc_delete_all_customer_meta($id);
    $result = true;
    foreach ($profile as $key => $value) {
        $result = $result && wpsc_update_customer_meta($key, $value, $id);
    }
    return $result;
}
示例#14
0
 private function save_shipping_and_billing_info()
 {
     global $wpsc_cart;
     // see if an existing purchase log has been set for this user
     // otherwise create one
     $purchase_log_id = (int) wpsc_get_customer_meta('current_purchase_log_id');
     if ($purchase_log_id) {
         $purchase_log = new WPSC_Purchase_Log($purchase_log_id);
     } else {
         $purchase_log = new WPSC_Purchase_Log();
     }
     $sessionid = mt_rand(100, 999) . time();
     wpsc_update_customer_meta('checkout_session_id', $sessionid);
     $purchase_log->set(array('user_ID' => wpsc_get_current_customer_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();
     if (wpsc_is_tax_included()) {
         $tax = $wpsc_cart->calculate_total_tax();
         $tax_percentage = $wpsc_cart->tax_percentage;
     } else {
         $tax = 0;
         $tax_percentage = 0;
     }
     $purchase_log->set(array('wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage));
     $purchase_log->save();
     $wpsc_cart->log_id = $purchase_log->get('id');
     wpsc_update_customer_meta('current_purchase_log_id', $purchase_log->get('id'));
     $this->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.', 'wpsc'), 'error');
         return;
     }
     $this->wizard->completed_step('shipping-and-billing');
     wp_redirect(wpsc_get_checkout_url($this->wizard->pending_step));
     exit;
 }
示例#15
0
 /**
  * set_error_message, please don't extend this without very good reason
  * saves error message, data it is stored in may need to change, hence the need to not extend this.
  */
 function set_error_message($error_message)
 {
     global $wpdb;
     $messages = wpsc_get_customer_meta('checkout_misc_error_messages');
     if (!is_array($messages)) {
         $messages = array();
     }
     $messages[] = $error_message;
     wpsc_update_customer_meta('checkout_misc_error_messages', $messages);
 }
示例#16
0
 /**
  * validate_forms method, validates the input from the checkout page
  * @access public
  */
 function validate_forms()
 {
     global $wpsc_cart, $wpdb, $current_user, $user_ID, $wpsc_gateway_error_messages, $wpsc_checkout_error_messages, $wpsc_customer_checkout_details, $wpsc_registration_error_messages;
     $any_bad_inputs = false;
     $bad_input_message = '';
     $wpsc_gateway_error_messages = array();
     $wpsc_checkout_error_messages = array();
     $wpsc_registration_error_messages = array();
     // Credit Card Number Validation for PayPal Pro and maybe others soon
     if (isset($_POST['card_number'])) {
         //should do some php CC validation here~
     } else {
         $wpsc_gateway_error_messages['card_number'] = '';
     }
     if (isset($_POST['card_number1']) && isset($_POST['card_number2']) && isset($_POST['card_number3']) && isset($_POST['card_number4'])) {
         if ($_POST['card_number1'] != '' && $_POST['card_number2'] != '' && $_POST['card_number3'] != '' && $_POST['card_number4'] != '' && is_numeric($_POST['card_number1']) && is_numeric($_POST['card_number2']) && is_numeric($_POST['card_number3']) && is_numeric($_POST['card_number4'])) {
             $wpsc_gateway_error_messages['card_number'] = '';
         } else {
             $any_bad_inputs = true;
             $bad_input = true;
             $wpsc_gateway_error_messages['card_number'] = __('Please enter a valid credit card number.', 'wp-e-commerce');
             $wpsc_customer_checkout_details['card_number'] = '';
         }
     }
     if (isset($_POST['expiry'])) {
         if (!empty($_POST['expiry']['month']) && !empty($_POST['expiry']['month']) && is_numeric($_POST['expiry']['month']) && is_numeric($_POST['expiry']['year'])) {
             $wpsc_gateway_error_messages['expdate'] = '';
         } else {
             $any_bad_inputs = true;
             $bad_input = true;
             $wpsc_gateway_error_messages['expdate'] = __('Please enter a valid expiry date.', 'wp-e-commerce');
             $wpsc_customer_checkout_details['expdate'] = '';
         }
     }
     if (isset($_POST['card_code'])) {
         if (empty($_POST['card_code']) || !is_numeric($_POST['card_code'])) {
             $any_bad_inputs = true;
             $bad_input = true;
             $wpsc_gateway_error_messages['card_code'] = __('Please enter a valid CVV.', 'wp-e-commerce');
             $wpsc_customer_checkout_details['card_code'] = '';
         } else {
             $wpsc_gateway_error_messages['card_code'] = '';
         }
     }
     if (isset($_POST['cctype'])) {
         if ($_POST['cctype'] == '') {
             $any_bad_inputs = true;
             $bad_input = true;
             $wpsc_gateway_error_messages['cctype'] = __('Please enter a valid CVV.', 'wp-e-commerce');
             $wpsc_customer_checkout_details['cctype'] = '';
         } else {
             $wpsc_gateway_error_messages['cctype'] = '';
         }
     }
     if (isset($_POST['log']) || isset($_POST['pwd']) || isset($_POST['user_email'])) {
         $results = wpsc_add_new_user($_POST['log'], $_POST['pwd'], $_POST['user_email']);
         if (is_callable(array($results, 'get_error_code')) && $results->get_error_code()) {
             foreach ($results->get_error_codes() as $code) {
                 foreach ($results->get_error_messages($code) as $error) {
                     $wpsc_registration_error_messages[] = $error;
                 }
                 $any_bad_inputs = true;
             }
         }
         if (property_exists($results, 'ID') && $results->ID > 0) {
             $our_user_id = $results->ID;
         } else {
             $any_bad_inputs = true;
             $our_user_id = '';
         }
     }
     if (isset($our_user_id) && $our_user_id < 1) {
         $our_user_id = $user_ID;
     }
     // check we have a user id
     if (isset($our_user_id) && $our_user_id > 0) {
         $user_ID = $our_user_id;
     }
     //Basic Form field validation for billing and shipping details
     foreach ($this->checkout_items as $form_data) {
         $value = wpsc_get_customer_meta($form_data->unique_name);
         $wpsc_customer_checkout_details[$form_data->id] = $value;
         $bad_input = false;
         if ($form_data->mandatory == 1 || $form_data->type == 'coupon') {
             if ($form_data->unique_name == 'billingstate' && empty($value)) {
                 $value = wpsc_get_customer_meta('billingregion');
                 if (empty($value)) {
                     $any_bad_inputs = true;
                     $bad_input = true;
                     $country = new WPSC_Country(wpsc_get_customer_meta('billingcountry'));
                     $name = $country->get('region_label');
                 }
             } else {
                 if ($form_data->unique_name == 'shippingstate' && empty($value)) {
                     $value = wpsc_get_customer_meta('shippingregion');
                     if (empty($value)) {
                         $any_bad_inputs = true;
                         $bad_input = true;
                         $country = new WPSC_Country(wpsc_get_customer_meta('shippingcountry'));
                         $name = $country->get('region_label');
                     }
                 } else {
                     $name = $form_data->name;
                     switch ($form_data->type) {
                         case 'email':
                             if (!is_email($value)) {
                                 $any_bad_inputs = true;
                                 $bad_input = true;
                             }
                             break;
                         case 'delivery_country':
                         case 'country':
                             if (empty($value)) {
                                 $any_bad_inputs = true;
                                 $bad_input = true;
                             }
                             break;
                         case 'heading':
                             break;
                         case 'select':
                             if ($value == '-1') {
                                 $any_bad_inputs = true;
                                 $bad_input = true;
                             }
                             break;
                         default:
                             if (empty($value)) {
                                 $any_bad_inputs = true;
                                 $bad_input = true;
                             }
                             break;
                     }
                 }
             }
             if ($bad_input === true) {
                 $wpsc_checkout_error_messages[$form_data->id] = sprintf(__('Please enter a valid <span class="wpsc_error_msg_field_name">%s</span>.', 'wp-e-commerce'), strtolower(esc_attr($name)));
                 $wpsc_customer_checkout_details[$form_data->id] = '';
             }
         }
     }
     wpsc_update_customer_meta('checkout_error_messages', $wpsc_checkout_error_messages);
     wpsc_update_customer_meta('gateway_error_messages', $wpsc_gateway_error_messages);
     wpsc_update_customer_meta('registration_error_messages', $wpsc_registration_error_messages);
     $filtered_checkout_details = apply_filters('wpsc_update_customer_checkout_details', $wpsc_customer_checkout_details);
     // legacy filter
     if (is_user_logged_in()) {
         $filtered_checkout_details = apply_filters('wpsc_checkout_user_profile_update', $wpsc_customer_checkout_details, get_current_user_id());
     }
     // Check if the shoppers location has changed
     _wpsc_has_visitor_location_changed();
     $states = array('is_valid' => !$any_bad_inputs, 'error_messages' => $bad_input_message);
     $states = apply_filters('wpsc_checkout_form_validation', $states);
     return $states;
 }
示例#17
0
/**
 * This switched between the 3 view types on category and products pages and includes the necessary template part
 * @access public
 *
 * @since 3.8
 * @param $display_type
 * @return NULL
 */
function wpsc_include_products_page_template($display_type = 'default')
{
    if (isset($_GET['view_type'])) {
        switch ($_GET['view_type']) {
            case 'grid':
                $display_type = 'grid';
                wpsc_update_customer_meta('display_type', $display_type);
                break;
            case 'list':
                $display_type = 'list';
                wpsc_update_customer_meta('display_type', $display_type);
                break;
            case 'default':
                $display_type = 'default';
                wpsc_update_customer_meta('display_type', $display_type);
                break;
            default:
                break;
        }
    }
    // switch the display type, based on the display type variable...
    switch ($display_type) {
        case "grid":
            include wpsc_get_template_file_path('wpsc-grid_view.php');
            break;
            // only break if we have the function;
        // only break if we have the function;
        case "list":
            include wpsc_get_template_file_path('wpsc-list_view.php');
            break;
            // only break if we have the file;
        // only break if we have the file;
        default:
            include wpsc_get_template_file_path('wpsc-products_page.php');
            break;
    }
}
 private function submit_payment_method()
 {
     global $wpsc_cart;
     if (!$this->verify_nonce('wpsc-checkout-form-payment-method')) {
         return;
     }
     if (empty($_POST['wpsc_payment_method']) && !wpsc_is_free_cart()) {
         $this->message_collection->add(__('Please select a payment method', 'wp-e-commerce'), 'validation');
     }
     $valid = apply_filters('_wpsc_merchant_v2_validate_payment_method', true, $this);
     if (!$valid) {
         return;
     }
     $purchase_log_id = wpsc_get_customer_meta('current_purchase_log_id');
     $purchase_log = new WPSC_Purchase_Log($purchase_log_id);
     $submitted_gateway = $_POST['wpsc_payment_method'];
     $purchase_log->set(array('gateway' => $submitted_gateway, 'base_shipping' => $wpsc_cart->calculate_base_shipping(), 'totalprice' => $wpsc_cart->calculate_total_price()));
     if ($this->maybe_add_guest_account() && isset($_POST['wpsc_create_account'])) {
         $email = wpsc_get_customer_meta('billingemail');
         $user_id = wpsc_register_customer($email, $email, false);
         $purchase_log->set('user_ID', $user_id);
         wpsc_update_customer_meta('checkout_details', wpsc_get_customer_meta('checkout_details'), $user_id);
         update_user_meta($user_id, '_wpsc_visitor_id', wpsc_get_current_customer_id());
     }
     $purchase_log->save();
     $wpsc_cart->empty_db($purchase_log_id);
     $wpsc_cart->save_to_db($purchase_log_id);
     $wpsc_cart->submit_stock_claims($purchase_log_id);
     $wpsc_cart->log_id = $purchase_log_id;
     $this->wizard->completed_step('payment');
     do_action('wpsc_submit_checkout', array('purchase_log_id' => $purchase_log_id, 'our_user_id' => isset($user_id) ? $user_id : get_current_user_id()));
     do_action('wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log);
 }
 function CallShortcutExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL)
 {
     global $wpdb;
     $nvpstr = '';
     $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paymentType;
     $nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
     $nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
     $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_CURRENCYCODE=" . $currencyCodeType;
     $data = array();
     if (!isset($this->cart_data['shipping_address']['first_name']) && !isset($this->cart_data['shipping_address']['last_name'])) {
         $this->cart_data['shipping_address']['first_name'] = $this->cart_data['billing_address']['first_name'];
         $this->cart_data['shipping_address']['last_name'] = $this->cart_data['billing_address']['last_name'];
     }
     if ($this->cart_data['shipping_address']['country'] == 'UK') {
         $this->cart_data['shipping_address']['country'] = 'GB';
     }
     $data += array('PAYMENTREQUEST_0_SHIPTONAME' => $this->cart_data['shipping_address']['first_name'] . ' ' . $this->cart_data['shipping_address']['last_name'], 'PAYMENTREQUEST_0_SHIPTOSTREET' => $this->cart_data['shipping_address']['address'], 'PAYMENTREQUEST_0_SHIPTOCITY' => $this->cart_data['shipping_address']['city'], 'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => $this->cart_data['shipping_address']['country'], 'PAYMENTREQUEST_0_SHIPTOZIP' => $this->cart_data['shipping_address']['post_code']);
     if (!empty($this->cart_data['shipping_address']['state'])) {
         $data += array('PAYMENTREQUEST_0_SHIPTOSTATE' => $this->cart_data['shipping_address']['state']);
     }
     $i = 0;
     $item_total = 0;
     $tax_total = 0;
     $shipping_total = 0;
     $is_free_shipping = false;
     if ($this->cart_data['has_discounts'] && (double) $this->cart_data['cart_discount_value'] > 0) {
         $coupon = new wpsc_coupons($this->cart_data['cart_discount_coupon']);
         $is_free_shipping = $coupon->is_free_shipping();
     }
     foreach ($this->cart_items as $cart_item) {
         $data["L_PAYMENTREQUEST_0_NAME{$i}"] = urlencode(apply_filters('the_title', $cart_item['name']));
         $data["L_PAYMENTREQUEST_0_AMT{$i}"] = $this->convert($cart_item['price']);
         $data["L_PAYMENTREQUEST_0_NUMBER{$i}"] = $i;
         $data["L_PAYMENTREQUEST_0_QTY{$i}"] = $cart_item['quantity'];
         $item_total += $this->convert($cart_item['price']) * $cart_item['quantity'];
         $shipping_total += $cart_item['shipping'];
         $i++;
     }
     //if we have a discount then include a negative amount with that discount
     // in php 0.00 = true so we will change that here
     if ($this->cart_data['cart_discount_value'] == 0.0) {
         $this->cart_data['cart_discount_value'] = 0;
     }
     $discount_value = $this->convert($this->cart_data['cart_discount_value']);
     if ($this->cart_data['cart_discount_value'] && !$is_free_shipping) {
         // if item total < discount amount, leave at least 0.01 unit in item total, then subtract
         // 0.01 from shipping as well
         if (!$is_free_shipping && $discount_value >= $item_total) {
             $discount_value = $item_total - 0.01;
             $shipping_total -= 0.01;
         }
         $item_total -= $discount_value;
         $data["L_PAYMENTREQUEST_0_NAME{$i}"] = "Discount / Coupon";
         $data["L_PAYMENTREQUEST_0_AMT{$i}"] = -$discount_value;
         $data["L_PAYMENTREQUEST_0_NUMBER{$i}"] = $i;
         $data["L_PAYMENTREQUEST_0_QTY{$i}"] = 1;
     }
     $data["PAYMENTREQUEST_0_ITEMAMT"] = $this->format_price($item_total);
     if ($discount_value && $is_free_shipping) {
         $data["PAYMENTREQUEST_0_SHIPPINGAMT"] = 0;
     } else {
         $data["PAYMENTREQUEST_0_SHIPPINGAMT"] = $this->convert($this->cart_data['base_shipping'] + $shipping_total);
     }
     $total = $data["PAYMENTREQUEST_0_ITEMAMT"] + $data["PAYMENTREQUEST_0_SHIPPINGAMT"];
     if (!wpsc_tax_isincluded()) {
         $data["PAYMENTREQUEST_0_TAXAMT"] = $this->convert($this->cart_data['cart_tax']);
         $total += $data["PAYMENTREQUEST_0_TAXAMT"];
     }
     // adjust total amount in case we had to round up after converting currency
     // or discount calculation
     if ($total != $paymentAmount) {
         $paymentAmount = $total;
     }
     $data["PAYMENTREQUEST_0_AMT"] = $paymentAmount;
     if (count($data) >= 4) {
         $temp_data = array();
         foreach ($data as $key => $value) {
             $temp_data[] = $key . "=" . $value;
         }
         $nvpstr = $nvpstr . "&" . implode("&", $temp_data);
     }
     wpsc_update_customer_meta('paypal_express_currency_code_type', $currencyCodeType);
     wpsc_update_customer_meta('paypal_express_payment_type', $paymentType);
     $resArray = paypal_hash_call("SetExpressCheckout", $nvpstr);
     $ack = strtoupper($resArray["ACK"]);
     if ($ack == "SUCCESS") {
         $token = urldecode($resArray["TOKEN"]);
         wpsc_update_customer_meta('paypal_express_token', $token);
     }
     return $resArray;
 }
示例#20
0
function wpsc_shipping_same_as_billing()
{
    wpsc_update_customer_meta('shipping_same_as_billing', $_POST['wpsc_shipping_same_as_billing']);
}
/**
 * deprecating user log filter for getting all customer meta as an array.
 *
 *@deprecated 3.8.14
 *
 * @return none
 */
function wpsc_deprecated_filter_user_log_get()
{
    if (has_filter('wpsc_user_log_get')) {
        $meta_data = wpsc_get_customer_meta('checkout_details');
        $meta_data = apply_filters('wpsc_user_log_get', $meta_data, wpsc_get_current_customer_id());
        wpsc_update_customer_meta('checkout_details', $meta_data);
        _wpsc_doing_it_wrong('wpsc_user_log_get', __('The filter being used has been deprecated. Use wpsc_get_visitor_meta or wpsc_get_visitor_meta_$meta_name instead.', 'wp-e-commerce'), '3.8.14');
    }
}
 /**
  * Process the SetExpressCheckout API Call
  *
  * @param array $args
  * @return void
  *
  * @since 3.9
  */
 public function process($args = array())
 {
     $total = $this->convert($this->purchase_log->get('totalprice'));
     $options = array('return_url' => $this->get_return_url(), 'message_id' => $this->purchase_log->get('id'), 'invoice' => $this->purchase_log->get('sessionid'), 'address_override' => 1);
     $options += $this->checkout_data->get_gateway_data();
     $options += $this->purchase_log->get_gateway_data(parent::get_currency_code(), $this->get_currency_code());
     if ($this->setting->get('ipn', false)) {
         $options['notify_url'] = $this->get_notify_url();
     }
     $response = $this->gateway->setup_purchase($options);
     if ($response->is_successful()) {
         $url = ($this->setting->get('sandbox_mode') ? self::SANDBOX_URL : self::LIVE_URL) . $response->get('token');
     } else {
         // SetExpressCheckout Failure
         $this->log_error($response);
         wpsc_update_customer_meta('paypal_digital_goods_errors', $response->get_errors());
         $url = add_query_arg(array('payment_gateway' => 'paypal-digital-goods', 'payment_gateway_callback' => 'display_paypal_error_redirect', 'return_url' => base64_encode($this->get_return_url())), $this->get_return_url());
     }
     if (!isset($args['return_only']) || $args['return_only'] !== true) {
         echo $url;
         exit;
     }
     return $url;
 }
/**
 * Record an error message related to shipping
 *
 * @access private
 *
 * @since 3.8.14.1
 *
 * @param string $message
 */
function _wpsc_shipping_add_error_message($message)
{
    $shipping_error_messages = wpsc_get_customer_meta('shipping_error_messages');
    if (empty($shipping_error_messages) && !is_array($shipping_error_messages)) {
        $shipping_error_messages = array();
    }
    $id = md5($message);
    $shipping_error_messages[$id] = $message;
    wpsc_update_customer_meta('shipping_error_messages', $shipping_error_messages);
}
示例#24
0
 function getQuote()
 {
     global $wpdb, $wpec_ash;
     if (!is_object($wpec_ash)) {
         $wpec_ash = new ASH();
     }
     // Arguments array for various functions to use
     $args = array();
     // Final rate table
     $rate_table = array();
     // Get the ups settings from the ups account info page (Shipping tab)
     $wpsc_ups_settings = get_option("wpsc_ups_settings", array());
     // Get the wordpress shopping cart options
     $wpsc_options = get_option("wpsc_options");
     // API Auth settings //
     $args['username'] = array_key_exists('upsaccount', $wpsc_ups_settings) ? $wpsc_ups_settings['upsusername'] : "";
     $args['password'] = array_key_exists('upspassword', $wpsc_ups_settings) ? $wpsc_ups_settings['upspassword'] : "";
     $args['api_id'] = array_key_exists('upsid', $wpsc_ups_settings) ? $wpsc_ups_settings['upsid'] : "";
     $args['account_number'] = array_key_exists('upsaccount', $wpsc_ups_settings) ? $wpsc_ups_settings['upsaccount'] : "";
     $args['negotiated_rates'] = array_key_exists('ups_negotiated_rates', $wpsc_ups_settings) ? $wpsc_ups_settings['ups_negotiated_rates'] : "";
     $args['residential'] = $wpsc_ups_settings['49_residential'];
     $args["singular_shipping"] = array_key_exists("singular_shipping", $wpsc_ups_settings) ? $wpsc_ups_settings["singular_shipping"] : "0";
     $args['insured_shipment'] = array_key_exists("insured_shipment", $wpsc_ups_settings) ? $wpsc_ups_settings["insured_shipment"] : "0";
     // What kind of pickup service do you use ?
     $args['DropoffType'] = $wpsc_ups_settings['DropoffType'];
     $args['packaging'] = $wpsc_ups_settings['48_container'];
     // Preferred Currency to display
     $currency_data = $wpdb->get_row($wpdb->prepare("SELECT `code`\n                                         FROM `" . WPSC_TABLE_CURRENCY_LIST . "`\n                                         WHERE `isocode`= %s\n                                         LIMIT 1", get_option('currency_type')), ARRAY_A);
     if ($currency_data) {
         $args['currency'] = $currency_data['code'];
     } else {
         $args['currency'] = "USD";
     }
     // Shipping billing / account address
     $origin_region_data = $wpdb->get_results($wpdb->prepare("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`\n                                WHERE `" . WPSC_TABLE_REGION_TAX . "`.`id` = %d ", get_option('base_region')), ARRAY_A);
     $args['shipr_state'] = is_array($origin_region_data) ? $origin_region_data[0]['code'] : "";
     $args['shipr_city'] = get_option('base_city');
     $args['shipr_ccode'] = get_option('base_country');
     $args['shipr_pcode'] = get_option('base_zipcode');
     // Physical Shipping address being shipped from
     $args['shipf_state'] = $args['shipr_state'];
     $args['shipf_city'] = $args['shipr_city'];
     $args['shipf_ccode'] = $args['shipr_ccode'];
     $args['shipf_pcode'] = $args['shipr_pcode'];
     // Get the total weight from the shopping cart
     $args['units'] = "LBS";
     $args['weight'] = wpsc_cart_weight_total();
     // Destination zip code
     $args['dest_ccode'] = wpsc_get_customer_meta('shipping_country');
     if ($args['dest_ccode'] == "UK") {
         // So, UPS is a little off the times
         $args['dest_ccode'] = "GB";
     }
     // If ths zip code is provided via a form post use it!
     $args['dest_pcode'] = (string) wpsc_get_customer_meta('shipping_zip');
     if (isset($_POST['zipcode']) && ($_POST['zipcode'] != __("Your Zipcode", 'wpsc') && $_POST['zipcode'] != "YOURZIPCODE")) {
         $args['dest_pcode'] = esc_attr($_POST['zipcode']);
     }
     if (in_array($args['dest_pcode'], array(__('Your Zipcode', 'wpsc'), 'YOURZIPCODE'))) {
         $args['dest_pcode'] = '';
     }
     wpsc_update_customer_meta('shipping_zip', $args['dest_pcode']);
     if (empty($args['dest_pcode'])) {
         // We cannot get a quote without a zip code so might as well return!
         return array();
     }
     // If the region code is provided via a form post use it!
     if (isset($_POST['region']) && !empty($_POST['region'])) {
         $query = $wpdb->prepare("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`\n                                WHERE `" . WPSC_TABLE_REGION_TAX . "`.`id` = %d", $_POST['region']);
         $dest_region_data = $wpdb->get_results($query, ARRAY_A);
         $args['dest_state'] = is_array($dest_region_data) ? $dest_region_data[0]['code'] : "";
         wpsc_update_customer_meta('ups_state', $args['dest_state']);
     } else {
         if ($dest_state = wpsc_get_customer_meta('ups_state')) {
             // Well, we have a zip code in the session and no new one provided
             $args['dest_state'] = $dest_state;
         } else {
             $args['dest_state'] = "";
         }
     }
     $shipping_cache_check['state'] = $args['dest_state'];
     $shipping_cache_check['zipcode'] = $args['dest_pcode'];
     $shipping_cache_check['weight'] = $args['weight'];
     $session_cache_check = wpsc_get_customer_meta('ups_shipping_cache_check');
     if (!is_array($session_cache_check)) {
         $session_cache_check = array();
     }
     $session_cache = wpsc_get_customer_meta('ups_shipping_cache');
     if (!is_array($session_cache)) {
         $session_cache = array();
     }
     if (!(bool) $args["singular_shipping"]) {
         // This is where shipping breaks out of UPS if weight is higher than 150 LBS
         if ($weight > 150) {
             wpsc_delete_customer_meta('quote_shipping_method');
             $shipping_quotes[TXT_WPSC_OVER_UPS_WEIGHT] = 0;
             $session_cache_check['weight'] = $args['weight'];
             $session_cache[$this->internal_name] = $shipping_quotes;
             wpsc_update_customer_meta('quote_shipping_method', $this->internal_name);
             wpsc_update_customer_meta('ups_shipping_cache_check', $session_cache_check);
             wpsc_update_customer_meta('ups_shipping_cache', $session_cache);
             return array($shipping_quotes);
         }
     }
     // We do not want to spam UPS (and slow down our process) if we already
     // have a shipping quote!
     if ($session_cache_check === $shipping_cache_check && !empty($session_cache[$this->internal_name])) {
         $rate_table = $session_cache[$this->internal_name];
         return $rate_table;
     } else {
         global $wpsc_cart;
         $args["cart_total"] = $wpsc_cart->calculate_subtotal(true);
         // Build the XML request
         $request = $this->_buildRateRequest($args);
         // Now that we have the message to send ... Send it!
         $raw_quote = $this->_makeRateRequest($request);
         // Now we have the UPS response .. unfortunately its not ready
         // to be viewed by normal humans ...
         $quotes = $this->_parseQuote($raw_quote);
         // If we actually have rates back from UPS we can use em!
         if ($quotes != false) {
             $rate_table = $this->_formatTable($quotes, $args['currency']);
         } else {
             if ($wpsc_ups_settings['upsenvironment'] == '1') {
                 echo "<strong>:: GetQuote ::DEBUG OUTPUT::</strong><br />";
                 echo "Arguments sent to UPS";
                 print_r($args);
                 echo "<hr />";
                 print $request;
                 echo "<hr />";
                 echo "Response from UPS";
                 echo $raw_quote;
                 echo "</strong>:: GetQuote ::End DEBUG OUTPUT::";
             }
         }
     }
     $wpec_ash->cache_results($this->internal_name, $args["dest_ccode"], $args["dest_state"], $args["dest_pcode"], $rate_table, $this->shipment);
     // return the final formatted array !
     return $rate_table;
 }
                  </td>
               </tr>
               <?php 
        if (wpsc_is_shipping_details()) {
            ?>
               <tr class='same_as_shipping_row'>
                  <td colspan ='2'>
                  <?php 
            $checked = '';
            $shipping_same_as_billing = wpsc_get_customer_meta('shippingSameBilling');
            if (isset($_POST['shippingSameBilling']) && $_POST['shippingSameBilling']) {
                $shipping_same_as_billing = true;
            } elseif (isset($_POST['submit']) && !isset($_POST['shippingSameBilling'])) {
                $shipping_same_as_billing = false;
            }
            wpsc_update_customer_meta('shippingSameBilling', $shipping_same_as_billing);
            if ($shipping_same_as_billing) {
                $checked = 'checked="checked"';
            }
            ?>
					<label for='shippingSameBilling'><input type='checkbox' value='true'  data-wpsc-meta-key="shippingSameBilling" class= "wpsc-visitor-meta"  name='shippingSameBilling' id='shippingSameBilling' <?php 
            echo $checked;
            ?>
 /><?php 
            _e('Same as billing address:', 'wp-e-commerce');
            ?>
</label>
					<br/><span id="shippingsameasbillingmessage"><?php 
            _e('Your order will be shipped to the billing address', 'wp-e-commerce');
            ?>
</span>
 public function set_customer_details()
 {
     $_POST['wpsc_checkout_details'] = array();
     $_GET['amazon_reference_id'] = sanitize_text_field($_POST['amazon_reference_id']);
     try {
         if (!$this->reference_id) {
             throw new Exception(__('An Amazon payment method was not chosen.', 'wpsc'));
         }
         if (is_null($this->purchase_log)) {
             $log = _wpsc_get_current_controller()->get_purchase_log();
             wpsc_update_customer_meta('current_purchase_log_id', $log->get('id'));
             $this->set_purchase_log($log);
         }
         global $wpsc_cart;
         // Update order reference with amounts
         $response = $this->api_request(array('Action' => 'SetOrderReferenceDetails', 'AmazonOrderReferenceId' => $this->reference_id, 'OrderReferenceAttributes.OrderTotal.Amount' => $wpsc_cart->calculate_total_price(), 'OrderReferenceAttributes.OrderTotal.CurrencyCode' => strtoupper($this->get_currency_code()), 'OrderReferenceAttributes.SellerNote' => sprintf(__('Order %s from %s.', 'wpsc'), $this->purchase_log->get('id'), urlencode(remove_accents(wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)))), 'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => $this->purchase_log->get('id'), 'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => remove_accents(wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)), 'OrderReferenceAttributes.PlatformId' => 'A2Z8DY3R4G08IM'));
         if (is_wp_error($response)) {
             throw new Exception($response->get_error_message());
         }
         if (isset($response['Error']['Message'])) {
             throw new Exception($response['Error']['Message']);
         }
         $response = $this->api_request(array('Action' => 'GetOrderReferenceDetails', 'AmazonOrderReferenceId' => $this->reference_id));
         if (is_wp_error($response)) {
             throw new Exception($response->get_error_message());
         }
         if (!isset($response['GetOrderReferenceDetailsResult']['OrderReferenceDetails']['Destination']['PhysicalDestination'])) {
             return;
         }
         $address = $response['GetOrderReferenceDetailsResult']['OrderReferenceDetails']['Destination']['PhysicalDestination'];
         remove_action('wpsc_checkout_get_fields', '__return_empty_array');
         add_filter('wpsc_validate_form', '__return_true');
         $form = WPSC_Checkout_Form::get();
         $fields = $form->get_fields();
         foreach ($fields as $field) {
             switch ($field->unique_name) {
                 case 'shippingstate':
                     $_POST['wpsc_checkout_details'][$field->id] = WPSC_Countries::get_region_id($address['CountryCode'], $address['StateOrRegion']);
                     break;
                 case 'shippingcountry':
                     $_POST['wpsc_checkout_details'][$field->id] = $address['CountryCode'];
                     break;
                 case 'shippingpostcode':
                     $_POST['wpsc_checkout_details'][$field->id] = $address['PostalCode'];
                     break;
                 case 'shippingcity':
                     $_POST['wpsc_checkout_details'][$field->id] = $address['City'];
                     break;
             }
         }
     } catch (Exception $e) {
         WPSC_Message_Collection::get_instance()->add($e->getMessage(), 'error', 'main', 'flash');
         return;
     }
 }
示例#27
0
 /**
  * returns shipping quotes using this shipping module.
  *
  * @param boolean $for_display (optional) (unused)
  * @return array collection of rates applicable.
  */
 function getQuote($for_display = false)
 {
     global $wpdb, $wpsc_cart;
     $quote_shipping_method = wpsc_get_customer_meta('quote_shipping_method');
     $quote_shipping_option = wpsc_get_customer_meta('quote_shipping_option');
     $country = '';
     if (isset($_POST['country'])) {
         $country = sanitize_text_field($_POST['country']);
         wpsc_update_customer_meta('shipping_country', $country);
     } else {
         $country = (string) wpsc_get_customer_meta('shipping_country');
     }
     if (is_object($wpsc_cart)) {
         $cart_total = $wpsc_cart->calculate_subtotal(true);
     }
     if (get_option('base_country') != $country) {
         $results = WPSC_Countries::get_continent($country);
         $flatrates = get_option('flat_rates');
         if ($flatrates != '') {
             if ($quote_shipping_method == $this->internal_name && $quote_shipping_option != __("Flat Rate", 'wp-e-commerce')) {
                 wpsc_delete_customer_meta('quote_shipping_option');
             }
             if (isset($flatrates[$results])) {
                 if (stristr($flatrates[$results], '%')) {
                     $shipping_percent = str_replace('%', '', $flatrates[$results]);
                     $shipping_amount = $cart_total * ($shipping_percent / 100);
                     $flatrates[$results] = (double) $shipping_amount;
                 }
                 return array(__("Flat Rate", 'wp-e-commerce') => (double) $flatrates[$results]);
             }
         }
     } else {
         $flatrates = get_option('flat_rates');
         $shipping_quotes = array();
         switch ($country) {
             case 'NZ':
                 if (isset($flatrates['northisland']) && strlen($flatrates['northisland']) > 0) {
                     $shipping_quotes[__('North Island', 'wp-e-commerce')] = esc_attr($flatrates['northisland']);
                 }
                 if (isset($flatrates['southisland']) && strlen($flatrates['southisland']) > 0) {
                     $shipping_quotes[__('South Island', 'wp-e-commerce')] = esc_attr($flatrates['southisland']);
                 }
                 break;
             case 'US':
                 if (isset($flatrates['continental']) && strlen($flatrates['continental']) > 0) {
                     $shipping_quotes[__('Continental 48 States', 'wp-e-commerce')] = esc_attr($flatrates['continental']);
                 }
                 if (isset($flatrates['all']) && strlen($flatrates['all']) > 0) {
                     $shipping_quotes[__('All 50 States', 'wp-e-commerce')] = esc_attr($flatrates['all']);
                 }
                 break;
             default:
                 if (isset($flatrates['local']) && strlen($flatrates['local']) > 0) {
                     $shipping_quotes[__('Local Shipping', 'wp-e-commerce')] = esc_attr($flatrates['local']);
                 }
                 break;
         }
         // Deal with % shipping rates
         foreach (array_keys($shipping_quotes) as $quote_name) {
             if (stristr($shipping_quotes[$quote_name], '%')) {
                 $shipping_percent = str_replace('%', '', $shipping_quotes[$quote_name]);
                 $shipping_amount = $cart_total * ($shipping_percent / 100);
                 $shipping_quotes[$quote_name] = (double) $shipping_amount;
             } else {
                 $shipping_quotes[$quote_name] = (double) $shipping_quotes[$quote_name];
             }
         }
         if ($quote_shipping_method == $this->internal_name) {
             $shipping_options = array_keys($shipping_quotes);
             if (array_search($quote_shipping_option, $shipping_options) === false) {
                 wpsc_delete_customer_meta('quote_shipping_option');
             }
         }
         return $shipping_quotes;
     }
 }
示例#28
0
 /**
  * validate_forms method, validates the input from the checkout page
  * @access public
  */
 function validate_forms()
 {
     global $wpsc_cart, $wpdb, $current_user, $user_ID, $wpsc_gateway_error_messages, $wpsc_checkout_error_messages, $wpsc_customer_checkout_details, $wpsc_registration_error_messages;
     $any_bad_inputs = false;
     $bad_input_message = '';
     $wpsc_gateway_error_messages = array();
     $wpsc_checkout_error_messages = array();
     $wpsc_registration_error_messages = array();
     // Credit Card Number Validation for PayPal Pro and maybe others soon
     if (isset($_POST['card_number'])) {
         //should do some php CC validation here~
     } else {
         $wpsc_gateway_error_messages['card_number'] = '';
     }
     if (isset($_POST['card_number1']) && isset($_POST['card_number2']) && isset($_POST['card_number3']) && isset($_POST['card_number4'])) {
         if ($_POST['card_number1'] != '' && $_POST['card_number2'] != '' && $_POST['card_number3'] != '' && $_POST['card_number4'] != '' && is_numeric($_POST['card_number1']) && is_numeric($_POST['card_number2']) && is_numeric($_POST['card_number3']) && is_numeric($_POST['card_number4'])) {
             $wpsc_gateway_error_messages['card_number'] = '';
         } else {
             $any_bad_inputs = true;
             $bad_input = true;
             $wpsc_gateway_error_messages['card_number'] = __('Please enter a valid card number.', 'wpsc');
             $wpsc_customer_checkout_details['card_number'] = '';
         }
     }
     if (isset($_POST['expiry'])) {
         if (!empty($_POST['expiry']['month']) && !empty($_POST['expiry']['month']) && is_numeric($_POST['expiry']['month']) && is_numeric($_POST['expiry']['year'])) {
             $wpsc_gateway_error_messages['expdate'] = '';
         } else {
             $any_bad_inputs = true;
             $bad_input = true;
             $wpsc_gateway_error_messages['expdate'] = __('Please enter a valid expiry date.', 'wpsc');
             $wpsc_customer_checkout_details['expdate'] = '';
         }
     }
     if (isset($_POST['card_code'])) {
         if (empty($_POST['card_code']) || !is_numeric($_POST['card_code'])) {
             $any_bad_inputs = true;
             $bad_input = true;
             $wpsc_gateway_error_messages['card_code'] = __('Please enter a valid CVV.', 'wpsc');
             $wpsc_customer_checkout_details['card_code'] = '';
         } else {
             $wpsc_gateway_error_messages['card_code'] = '';
         }
     }
     if (isset($_POST['cctype'])) {
         if ($_POST['cctype'] == '') {
             $any_bad_inputs = true;
             $bad_input = true;
             $wpsc_gateway_error_messages['cctype'] = __('Please enter a valid CVV.', 'wpsc');
             $wpsc_customer_checkout_details['cctype'] = '';
         } else {
             $wpsc_gateway_error_messages['cctype'] = '';
         }
     }
     if (isset($_POST['log']) || isset($_POST['pwd']) || isset($_POST['user_email'])) {
         $results = wpsc_add_new_user($_POST['log'], $_POST['pwd'], $_POST['user_email']);
         if (is_callable(array($results, "get_error_code")) && $results->get_error_code()) {
             foreach ($results->get_error_codes() as $code) {
                 foreach ($results->get_error_messages($code) as $error) {
                     $wpsc_registration_error_messages[] = $error;
                 }
                 $any_bad_inputs = true;
             }
         }
         if ($results->ID > 0) {
             $our_user_id = $results->ID;
         } else {
             $any_bad_inputs = true;
             $our_user_id = '';
         }
     }
     if (isset($our_user_id) && $our_user_id < 1) {
         $our_user_id = $user_ID;
     }
     // check we have a user id
     if (isset($our_user_id) && $our_user_id > 0) {
         $user_ID = $our_user_id;
     }
     $location_changed = false;
     //Basic Form field validation for billing and shipping details
     foreach ($this->checkout_items as $form_data) {
         $value = '';
         if (isset($_POST['collected_data'][$form_data->id])) {
             $value = stripslashes_deep($_POST['collected_data'][$form_data->id]);
         }
         $wpsc_customer_checkout_details[$form_data->id] = $value;
         $bad_input = false;
         if ($form_data->mandatory == 1 || $form_data->type == "coupon") {
             // dirty hack
             if ($form_data->unique_name == 'billingstate' && empty($value)) {
                 $billing_country_id = $wpdb->get_var("SELECT `" . WPSC_TABLE_CHECKOUT_FORMS . "`.`id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `unique_name` = 'billingcountry' AND active = '1' ");
                 $value = $_POST['collected_data'][$billing_country_id][1];
             }
             switch ($form_data->type) {
                 case "email":
                     if (!preg_match("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-.]+\\.[a-zA-Z]{2,5}\$/", $value)) {
                         $any_bad_inputs = true;
                         $bad_input = true;
                     }
                     break;
                 case "delivery_country":
                 case "country":
                 case "heading":
                     break;
                 case "select":
                     if ($value == '-1') {
                         $any_bad_inputs = true;
                         $bad_input = true;
                     }
                     break;
                 default:
                     if ($value == null) {
                         $any_bad_inputs = true;
                         $bad_input = true;
                     }
                     break;
             }
             if ($bad_input === true) {
                 $wpsc_checkout_error_messages[$form_data->id] = sprintf(__('Please enter a valid <span class="wpsc_error_msg_field_name">%s</span>.', 'wpsc'), esc_attr($form_data->name));
                 $wpsc_customer_checkout_details[$form_data->id] = '';
             }
         }
         if (!$bad_input) {
             if ($form_data->unique_name == 'shippingstate') {
                 $shipping_country_field_id = wpsc_get_country_form_id_by_type('delivery_country');
                 $shipping_country = $_POST['collected_data'][$shipping_country_field_id];
                 if (!is_array($shipping_country) || !isset($shipping_country[1])) {
                     wpsc_update_customer_meta('billing_region', $value);
                     $location_changed = true;
                 }
             } elseif ($form_data->unique_name == 'billingstate') {
                 $billing_country_field_id = wpsc_get_country_form_id_by_type('country');
                 $billing_country = $_POST['collected_data'][$billing_country_field_id];
                 if (!is_array($billing_country) || !isset($billing_country[1])) {
                     wpsc_update_customer_meta('billing_region', $value);
                     $location_changed = true;
                 }
             }
         }
     }
     wpsc_update_customer_meta('checkout_error_messages', $wpsc_checkout_error_messages);
     wpsc_update_customer_meta('gateway_error_messages', $wpsc_gateway_error_messages);
     wpsc_update_customer_meta('registration_error_messages', $wpsc_registration_error_messages);
     $filtered_checkout_details = apply_filters('wpsc_update_customer_checkout_details', $wpsc_customer_checkout_details);
     // legacy filter
     if (is_user_logged_in()) {
         $filtered_checkout_details = apply_filters('wpsc_checkout_user_profile_update', $wpsc_customer_checkout_details, get_current_user_id());
     }
     wpsc_update_customer_meta('checkout_details', $filtered_checkout_details);
     if ($location_changed) {
         $wpsc_cart->update_location();
     }
     $states = array('is_valid' => !$any_bad_inputs, 'error_messages' => $bad_input_message);
     $states = apply_filters('wpsc_checkout_form_validation', $states);
     return $states;
 }
示例#29
0
function gateway_linkpoint($seperator, $sessionid)
{
    global $wpdb;
    $transact_url = get_option('transact_url');
    $purchase_log_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= '" . $sessionid . "' LIMIT 1";
    $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A);
    $purchase_log = $purchase_log[0];
    //Get provided user info
    //Here starts most of the changes implemented into linkpoint for passing userinfo
    $usersql = "SELECT\n\t\t`" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.value,\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "`.`name`,\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "`.`unique_name` FROM\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "` LEFT JOIN\n\t\t`" . WPSC_TABLE_SUBMITED_FORM_DATA . "` ON\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "`.id =\n\t\t`" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`form_id` WHERE\n\t\t`" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`log_id`=" . $purchase_log['id'] . " ORDER BY `" . WPSC_TABLE_CHECKOUT_FORMS . "`.`checkout_order`";
    $userinfo = $wpdb->get_results($usersql, ARRAY_A);
    foreach ((array) $userinfo as $key => $value) {
        if ($value['unique_name'] == 'billingfirstname' && $value['value'] != '') {
            $myorder1['FIRSTNAME'] = $value['value'];
        }
        if ($value['unique_name'] == 'billinglastname' && $value['value'] != '') {
            $myorder1['LASTNAME'] = $value['value'];
        }
        if ($value['unique_name'] == 'billingemail' && $value['value'] != '') {
            $myorder1['EMAIL'] = $value['value'];
        }
        if ($value['unique_name'] == 'billingphone' && $value['value'] != '') {
            $myorder1['PHONENUM'] = $value['value'];
        }
        if ($value['unique_name'] == 'billingaddress' && $value['value'] != '') {
            $myorder1['STREET'] = $value['value'];
        }
        if ($value['unique_name'] == 'billingcity' && $value['value'] != '') {
            $myorder1['CITY'] = $value['value'];
        }
        if ($value['unique_name'] == 'billingstate' && $value['value'] != '') {
            $sql = "SELECT `code` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id` ='" . $value['value'] . "' LIMIT 1";
            $myorder1['STATE'] = $wpdb->get_var($sql);
        } else {
            //	$data['STATE']='CA';
        }
        if ($value['unique_name'] == 'billingcountry' && $value['value'] != '') {
            $value['value'] = maybe_unserialize($value['value']);
            if ($value['value'][0] == 'UK') {
                $myorder1['COUNTRYCODE'] = 'GB';
            } else {
                $myorder1['COUNTRYCODE'] = $value['value'][0];
            }
            if (is_numeric($value['value'][1])) {
                $sql = "SELECT `code` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id` ='" . $value['value'][1] . "' LIMIT 1";
                $myorder1['STATE'] = $wpdb->get_var($sql);
            }
        }
        if ($value['unique_name'] == 'billingpostcode' && $value['value'] != '') {
            $myorder1['ZIP'] = $value['value'];
        }
        if ($value['unique_name'] == 'shippingfirstname' && $value['value'] != '') {
            $myorder1['SHIPTONAME1'] = $value['value'];
        } else {
            //	$myorder1['SHIPTONAME1']	= '';
        }
        if ($value['unique_name'] == 'shippinglastname' && $value['value'] != '') {
            $myorder1['SHIPTONAME2'] = $value['value'];
        } else {
            //	$myorder1['SHIPTONAME2']	= '';
        }
        if ($value['unique_name'] == 'shippingaddress' && $value['value'] != '') {
            $myorder1['SHIPTOSTREET'] = $value['value'];
        }
        if ($value['unique_name'] == 'shippingcity' && $value['value'] != '') {
            $myorder1['SHIPTOCITY'] = $value['value'];
        }
        //$data['SHIPTOCITY'] = 'CA';
        if ($value['unique_name'] == 'shippingstate' && $value['value'] != '') {
            //	$data['SHIPTOSTATE'] = $value['value'];
            $sql = "SELECT `code` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id` ='" . $value['value'] . "' LIMIT 1";
            $myorder1['SHIPTOSTATE'] = $wpdb->get_var($sql);
        } else {
        }
        if ($value['unique_name'] == 'shippingcountry' && $value['value'] != '') {
            $value['value'] = maybe_unserialize($value['value']);
            if (is_array($value['value'])) {
                if ($value['value'][0] == 'UK') {
                    $myorder1['SHIPTOCOUNTRY'] = 'GB';
                } else {
                    $myorder1['SHIPTOCOUNTRY'] = $value['value'][0];
                }
                if (is_numeric($value['value'][1])) {
                    $sql = "SELECT `code` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id` ='" . $value['value'][1] . "' LIMIT 1";
                    $myorder1['SHIPTOSTATE'] = $wpdb->get_var($sql);
                }
            } else {
                $myorder1['SHIPTOCOUNTRY'] = $value['value'];
            }
        }
        if ($value['unique_name'] == 'shippingpostcode' && $value['value'] != '') {
            $myorder1['SHIPTOZIP'] = $value['value'];
        }
    }
    //Here ends most of the changes implemented into linkpoint
    $store = get_option('linkpoint_store_number');
    $linkpoint = new lphp();
    $myorder["host"] = "secure.linkpt.net";
    $myorder["port"] = "1129";
    $myorder["keyfile"] = WPSC_GOLD_FILE_PATH . "/merchants/linkpointpem/" . $store . ".pem";
    $myorder["configfile"] = $store;
    //	# CREDIT CARD INFO
    //if (get_option('linkpoint_test')=='0') {
    $myorder["ordertype"] = "SALE";
    $myorder["cardnumber"] = $_POST['card_number'];
    /* see note below ( submit_linkpoint() )on using the linkpoint test account this way
    	} else {
    		$myorder["result"] = "GOOD";
    		$myorder["cardnumber"] = "4111-1111-1111-1111";
    		$myorder["cardexpmonth"] = "01";
    		$myorder["cardexpyear"] = "11";
    		$myorder["cvmvalue"] = "111";
    	}
    */
    $myorder["cardexpmonth"] = $_POST['ExpiryMonth'];
    $myorder["cardexpyear"] = $_POST['ExpiryYear'];
    $myorder["cvmvalue"] = $_POST['cvmvalue'];
    //	# BILLING INFO
    $myorder["name"] = $myorder1['FIRSTNAME'] . ' ' . $myorder1['LASTNAME'];
    //	$myorder["billingcompany"]  = $_POST["company"];
    $myorder["address"] = $myorder1['STREET'];
    //	$myorder["address2"] = ' ';//$_POST["address2"];
    $myorder["city"] = $myorder1['CITY'];
    $myorder["state"] = $myorder1['STATE'];
    $myorder["country"] = $myorder1['COUNTRYCODE'];
    $myorder["phone"] = $myorder1['PHONENUM'];
    $myorder["email"] = $myorder1['EMAIL'];
    //	$myorder["addrnum"]  = $_POST["addrnum"];
    $myorder["zip"] = $myorder1['ZIP'];
    //	# SHIPPING INFO
    $myorder["sname"] = $myorder1['SHIPTONAME1'] . ' ' . $myorder1['SHIPTONAME2'];
    $myorder["saddress1"] = $myorder1['SHIPTOSTREET'];
    $myorder["saddress2"] = ' ';
    //$_POST["saddress2"];
    $myorder["scity"] = $myorder1['SHIPTOCITY'];
    $myorder["sstate"] = $myorder1['SHIPTOSTATE'];
    $myorder["szip"] = $myorder1['SHIPTOZIP'];
    $myorder["scountry"] = $myorder1['SHIPTOCOUNTRY'];
    //	# ORDER INFO
    $myorder["chargetotal"] = $purchase_log['totalprice'];
    //	exit('<pre>'.print_r($myorder,true).'</pre>');
    $responce = $linkpoint->curl_process($myorder);
    //	exit('<pre>'.print_r($responce,true).'</pre>');
    if ($responce["r_approved"] != "APPROVED") {
        $message .= "<h3>" . __('Please Check the Payment Results', 'wpsc_gold_cart') . "</h3>";
        $message .= __('Your transaction was not successful.', 'wpsc_gold_cart') . "<br /><br />";
        $errors = wpsc_get_customer_meta('checkout_misc_error_messages');
        if (!is_array($errors)) {
            $errors[] = $message;
        }
        wpsc_update_customer_meta('checkout_misc_error_messages', $errors);
    } else {
        $purchase_log = new WPSC_Purchase_Log($sessionid, 'sessionid');
        $purchase_log->set('processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT);
        $purchase_log->save();
        header("Location: " . $transact_url . $seperator . "sessionid=" . $sessionid);
        exit;
        //transaction_results($sessionid, true);
    }
}
示例#30
0
 /**
  * Update more than one customer meta
  * @param meta_data - array of key value pairs to set
  * @return JSON encoded array with results, results include original request parameters
  * @since 3.8.14
  */
 function wpsc_update_customer_meta_ajax()
 {
     $success = true;
     // we will echo back the request in the (likely async) response so that the client knows
     // which transaction the response matches
     $response = array('request' => $_REQUEST);
     // update can be a single key/value pair or an array of key value pairs
     if (!empty($_REQUEST['meta_data'])) {
         $customer_meta = isset($_REQUEST['meta_data']) ? $_REQUEST['meta_data'] : array();
     } elseif (!empty($_REQUEST['meta_key']) && isset($_REQUEST['meta_value'])) {
         $customer_meta = array($_REQUEST['meta_key'] => $_REQUEST['meta_value']);
     } else {
         _wpsc_doing_it_wrong(__FUNCTION__, __('missing meta key or meta array', 'wpsc'), '3.8.14');
         $customer_meta = array();
     }
     if (!empty($customer_meta)) {
         foreach ($customer_meta as $meta_key => $meta_value) {
             // this will echo back any fields to the requester. It's a
             // means for the requester to maintain some state during
             // asynchronous requests
             if (!empty($meta_key)) {
                 $updated = wpsc_update_customer_meta($meta_key, $meta_value);
                 $success = $success & $updated;
             }
         }
         // loop through a second time so that all of the meta has been set, tht way if there are
         // dependencies in response calculation
         foreach ($customer_meta as $meta_key => $meta_value) {
             $response = apply_filters('wpsc_customer_meta_response_' . $meta_key, $response, $meta_key, $meta_value);
         }
         if ($success) {
             $response['type'] = __('success', 'wpsc');
             $response['error'] = '';
         } else {
             $response['type'] = __('error', 'wpsc');
             $response['error'] = __('meta values may not have been updated', 'wpsc');
         }
     } else {
         $response['type'] = __('error', 'wpsc');
         $response['error'] = __('invalid parameters, meta array or meta key value pair required', 'wpsc');
     }
     wp_send_json_success($response);
 }