Пример #1
0
function _wpsc_filter_merchant_v2_payment_method_form_fields($fields)
{
    $selected_value = isset($_POST['wpsc_payment_method']) ? $_POST['wpsc_payment_method'] : '';
    if (empty($selected_value)) {
        $current_purchase_log_id = wpsc_get_customer_meta('current_purchase_log_id');
        $purchase_log = new WPSC_Purchase_Log($current_purchase_log_id);
        $selected_value = $purchase_log->get('gateway');
    }
    $gateways = _wpsc_merchant_v2_get_active_gateways();
    if (empty($gateways)) {
        return $fields;
    }
    foreach (_wpsc_merchant_v2_get_active_gateways() as $gateway) {
        $gateway = (object) $gateway;
        $title = $gateway->name;
        if (!empty($gateway->image)) {
            $title .= ' <img src="' . $gateway->image . '" alt="' . $gateway->name . '" />';
        }
        $field = array('title' => $title, 'type' => 'radio', 'value' => $gateway->internalname, 'name' => 'wpsc_payment_method', 'checked' => $selected_value == $gateway->internalname);
        $fields[] = $field;
    }
    // check the first payment gateway by default
    if (empty($selected_value)) {
        $fields[0]['checked'] = true;
    }
    return $fields;
}
Пример #2
0
 private function callback_login()
 {
     if (empty($_COOKIE[TEST_COOKIE])) {
         $this->message_collection->add(__("Cookies are blocked or not supported by your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to log in to your account.", 'wp-e-commerce'), 'error');
     }
     $form_args = wpsc_get_login_form_args();
     $validation = wpsc_validate_form($form_args);
     if (is_wp_error($validation)) {
         wpsc_set_validation_errors($validation);
         return;
     }
     $user = wp_signon(array('user_login' => $_POST['username'], 'user_password' => $_POST['password'], 'rememberme' => !empty($_POST['rememberme'])));
     if (is_wp_error($user)) {
         $this->message_collection->add(__('We do not recognize the login information you entered. Please try again.', 'wp-e-commerce'), 'error');
         return;
     }
     $redirect_to = wp_get_referer();
     if (wpsc_get_customer_meta('checkout_after_login')) {
         $redirect_to = wpsc_get_checkout_url();
         wpsc_delete_customer_meta('checkout_after_login');
     }
     if (!$redirect_to || trim(str_replace(home_url(), '', $redirect_to), '/') == trim($_SERVER['REQUEST_URI'], '/')) {
         $redirect_to = wpsc_get_store_url();
     }
     wp_redirect($redirect_to);
     exit;
 }
Пример #3
0
function gateway_paystation($seperator, $sessionid)
{
    $price = number_format(nzshpcrt_overall_total_price(wpsc_get_customer_meta('billing_country')), 2, '', ',');
    $url = "https://www.paystation.co.nz/dart/darthttp.dll?paystation&pi=" . get_option('paystation_id') . "&ms=" . $sessionid . "&am=" . $price . "";
    header("Location: {$url}");
    exit;
}
Пример #4
0
 private function get_completed()
 {
     $this->completed = wpsc_get_customer_meta('checkout_wizard_completed_steps');
     if (!is_array($this->completed)) {
         $this->completed = array();
     }
 }
Пример #5
0
function gateway_dps($seperator, $sessionid)
{
    $PxAccess_Url = get_option('access_url');
    $PxAccess_Userid = get_option('access_userid');
    $PxAccess_Key = get_option('access_key');
    $Mac_Key = get_option('mac_key');
    $pxaccess = new PxAccess($PxAccess_Url, $PxAccess_Userid, $PxAccess_Key, $Mac_Key);
    $request = new PxPayRequest();
    $http_host = getenv("HTTP_HOST");
    $request_uri = getenv("SCRIPT_NAME");
    $server_url = get_option('siteurl');
    $script_url = get_option('transact_url');
    //Using this code after PHP version 4.3.4  ?page_id=$_GET['page_id']
    //echo $script_url . '<br />';
    //exit(get_option('checkout_url'));
    # the following variables are read from the form
    $Address1 = $_POST['address'];
    $Address2 = "";
    #Set up PxPayRequest Object
    $request->setAmountInput(nzshpcrt_overall_total_price(wpsc_get_customer_meta('shipping_country')));
    $request->setTxnData1(get_option('blogname'));
    # whatever you want to appear, original:   $request->setTxnData1("Widget order");
    $request->setTxnData2("n/a");
    # whatever you want to appear
    $request->setTxnData3("n/a");
    # whatever you want to appear
    $request->setTxnType("Purchase");
    if (get_option('dps_curcode') != '') {
        $request->setInputCurrency(get_option('dps_curcode'));
    } else {
        $request->setInputCurrency("USD");
    }
    $request->setMerchantReference($sessionid);
    # fill this with your order number
    $request->setEmailAddress(get_option('purch_log_email'));
    $request->setUrlFail($script_url);
    $request->setUrlSuccess($script_url);
    #Call makeResponse of PxAccess object to obtain the 3-DES encrypted payment request
    $request_string = $pxaccess->makeRequest($request);
    header("Location: {$request_string}");
    exit;
}
Пример #6
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;
 }
Пример #7
0
 function getQuote()
 {
     global $wpdb, $wpec_ash, $wpsc_cart, $wpec_ash_tools;
     // Arguments array for various functions to use
     $args = array();
     $args['dest_ccode'] = wpsc_get_customer_meta('shippingcountry');
     // Get the ups settings from the ups account info page (Shipping tab)
     $wpsc_ups_settings = get_option('wpsc_ups_settings', array());
     //Disable International Shipping. Default: Enabled, as it currently is.
     $args['intl_rate'] = isset($wpsc_ups_settings['intl_rate']) && !empty($wpsc_ups_settings['intl_rate']) ? FALSE : TRUE;
     if (!$args['intl_rate'] && $args['dest_ccode'] != get_option('base_country')) {
         return array();
     }
     // Destination zip code
     $args['dest_pcode'] = (string) wpsc_get_customer_meta('shippingpostcode');
     if (!is_object($wpec_ash_tools)) {
         $wpec_ash_tools = new ASHTools();
     }
     if (empty($args['dest_pcode']) && $wpec_ash_tools->needs_post_code($args['dest_ccode'])) {
         // We cannot get a quote without a zip code so might as well return!
         return array();
     }
     // Get the total weight from the shopping cart
     $args['weight'] = wpsc_cart_weight_total();
     if (empty($args['weight'])) {
         return array();
     }
     $args['dest_state'] = '';
     $wpsc_country = new WPSC_Country(wpsc_get_customer_meta('shippingcountry'));
     if ($wpsc_country->has_regions()) {
         $wpsc_region = $wpsc_country->get_region(wpsc_get_customer_meta('shippingregion'));
         if (is_a($wpsc_region, 'WPSC_Region')) {
             $args['dest_state'] = $wpsc_region->get_code();
         }
     }
     if (empty($args['dest_state'])) {
         $args['dest_state'] = wpsc_get_customer_meta('shippingstate');
     }
     if (!is_object($wpec_ash)) {
         $wpec_ash = new ASH();
     }
     $shipping_cache_check['state'] = $args['dest_state'];
     //The destination is needed for cached shipment check.
     $shipping_cache_check['country'] = $args['dest_ccode'];
     $shipping_cache_check['zipcode'] = $args['dest_pcode'];
     $this->shipment = $wpec_ash->get_shipment();
     $this->shipment->set_destination($this->internal_name, $shipping_cache_check);
     //Set this shipment's destination.
     $this->shipment->rates_expire = date('Y-m-d');
     $args['shipper'] = $this->internal_name;
     $args['singular_shipping'] = array_key_exists('singular_shipping', $wpsc_ups_settings) ? $wpsc_ups_settings['singular_shipping'] : '0';
     if ($args['weight'] > 150 && !(bool) $args['singular_shipping']) {
         // This is where shipping breaks out of UPS if weight is higher than 150 LBS
         $over_weight_txt = apply_filters('wpsc_shipment_over_weight', __('Your order exceeds the standard shipping weight limit. Please contact us to quote other shipping alternatives.', 'wpsc'), $args);
         $shipping_quotes[$over_weight_txt] = 0;
         // yes, a constant.
         $wpec_ash->cache_results($this->internal_name, array($shipping_quotes), $this->shipment);
         //Update shipment cache.
         return array($shipping_quotes);
     }
     $cache = $wpec_ash->check_cache($this->internal_name, $this->shipment);
     //And now, we're ready to check cache.
     // We do not want to spam UPS (and slow down our process) if we already
     // have a shipping quote!
     if (count($cache['rate_table']) >= 1) {
         return $cache['rate_table'];
     }
     // Final rate table
     $rate_table = array();
     // 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['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 = WPSC_Countries::get_currency_code(get_option('currency_type'));
     if (!empty($currency_data)) {
         $args['currency'] = $currency_data;
     } else {
         $args['currency'] = 'USD';
     }
     // Shipping billing / account address
     $region = new WPSC_Region(get_option('base_country'), get_option('base_region'));
     $args['shipr_state'] = $region->get_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'];
     $args['units'] = 'LBS';
     $args['cart_total'] = $wpsc_cart->calculate_subtotal(true);
     $args = apply_filters('wpsc_shipment_data', $args, $this->shipment);
     if (isset($args['stop'])) {
         //Do not get rates.
         return array();
     }
     // 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 = apply_filters('wpsc_rates_table', $this->_formatTable($quotes, $args['currency']), $args, $this->shipment);
     } else {
         if (isset($wpsc_ups_settings['upsenvironment'])) {
             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, $rate_table, $this->shipment);
     // return the final formatted array !
     return $rate_table;
 }
        ?>
 colspan='2'>
                     <h4><?php 
        echo wpsc_checkout_form_name();
        ?>
</h4>
                  </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');
Пример #9
0
/**
 * output shipping error messages
 *
 * @since 3.8.14.1
 *
 * @access private
 */
function _wpsc_shipping_error_messages()
{
    $shipping_error_messages = wpsc_get_customer_meta('shipping_error_messages');
    if (!empty($shipping_error_messages)) {
        ?>
	<div class="wpsc-shipping-error_messages error">
	<?php 
        foreach ($shipping_error_messages as $id => $message) {
            ?>
			<div class="wpsc-shipping-error_message error" id="<?php 
            echo esc_attr($id);
            ?>
">
			<?php 
            echo esc_html($message);
            ?>
			</div>
			<?php 
        }
        ?>
	</div>
	<?php 
    }
}
Пример #10
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;
}
    /**
     * Error Page Template
     *
     * @since 3.9
     */
    public function filter_paypal_error_page()
    {
        $errors = wpsc_get_customer_meta('paypal_express_checkout_errors');
        ob_start();
        ?>
	<p>
	<?php 
        _e('Sorry, your transaction could not be processed by PayPal. Please contact the site administrator. The following errors are returned:', 'wp-e-commerce');
        ?>
		</p>
			<ul>
			<?php 
        foreach ($errors as $error) {
            ?>
			<li><?php 
            echo esc_html($error['details']);
            ?>
 (<?php 
            echo esc_html($error['code']);
            ?>
)</li>
			<?php 
        }
        ?>
		</ul>
			<p><a href="<?php 
        echo esc_url($this->get_shopping_cart_payment_url());
        ?>
"><?php 
        'Click here to go back to the checkout page.';
        ?>
</a></p>
<?php 
        $output = apply_filters('wpsc_paypal_express_checkout_gateway_error_message', ob_get_clean(), $errors);
        return $output;
    }
Пример #12
0
 /**
  * Creates cache key for current cart and ZIP code for shipping rates.
  * @since 3.8.9
  * @return string
  */
 public function get_cache_key()
 {
     global $wpsc_cart;
     if (!is_object($wpsc_cart) || empty($wpsc_cart->cart_items)) {
         return false;
     }
     $cached_object = array();
     $products = $wpsc_cart->cart_items;
     $zip = wpsc_get_customer_meta('shipping_zip');
     $num = 0;
     foreach ($products as $product) {
         if (!$product->uses_shipping) {
             continue;
         }
         $cached_object['products'][$num]['sku'] = $product->sku;
         $cached_object['products'][$num]['qty'] = $product->quantity;
         $num++;
     }
     $cached_object['zip'] = $zip;
     return 'rates_' . hash('md5', json_encode($cached_object));
 }
Пример #13
0
 /**
  * Common routine to put the current customer meta values into an jax
  * response in a format to be consumed by the wp-e-commerce.js ajax processings
  *
  * @since 3.8.14
  * @access private
  *
  * @param array values being readied to send back to javascript in the json encoded AJAX response
  * @param string|array|null meta keys to retrieve, if not specified all meta keys are retrieved
  * @return JSON encoded array with results, results include original request parameters
  */
 function _wpsc_add_customer_meta_to_response($response, $meta_keys = null, $meta_key = 'customer_meta')
 {
     if (!empty($meta_keys)) {
         if (!is_array($meta_keys)) {
             $meta_keys = array($meta_keys);
         }
     } else {
         $meta_keys = wpsc_checkout_unique_names();
     }
     $customer_meta = array();
     foreach ($meta_keys as $a_meta_key) {
         $customer_meta[$a_meta_key] = wpsc_get_customer_meta($a_meta_key);
     }
     $response[$meta_key] = $customer_meta;
     $response = apply_filters('wpsc_ajax_response_customer_meta', $response);
     return $response;
 }
 /**
  * @description: wpec_taxes_calculate_total - takes into account all tax logic
  *                   settings and returns the calculated total tax.
  *                   Expects wpsc_cart to be set.
  *
  * @param: void
  * @return: array containing total tax and rate if applicable
  * */
 function wpec_taxes_calculate_total()
 {
     //get the cart - NOTE: billing country is selected_country and shipping country is delivery_country
     global $wpsc_cart;
     //initialize return variable
     $returnable = array('total' => 0, 'rate' => 0);
     //check if tax is enabled
     if ($this->wpec_taxes->wpec_taxes_get_enabled()) {
         //run tax logic and calculate tax
         if ($this->wpec_taxes_run_logic()) {
             //get selected country code
             $wpec_selected_country = $this->wpec_taxes_retrieve_selected_country();
             //set tax region
             $region = $this->wpec_taxes_retrieve_region();
             //get the rate for the country and region if set
             $tax_rate = $this->wpec_taxes->wpec_taxes_get_rate($wpec_selected_country, $region);
             //start the total_tax off at 0
             $total_tax = 0;
             foreach ($wpsc_cart->cart_items as $cart_item) {
                 //if the tax is inclusive calculate vat
                 if ($this->wpec_taxes_isincluded()) {
                     //run wpec_taxes_calculate_included_tax
                     $taxes = $this->wpec_taxes_calculate_included_tax($cart_item);
                     $total_tax += $taxes['tax'];
                 } else {
                     //run wpec_taxes_calculate_excluded_tax
                     $taxes = $this->wpec_taxes_calculate_excluded_tax($cart_item, $tax_rate);
                     $total_tax += $taxes['tax'];
                 }
                 // if
             }
             // foreach
             $free_shipping = false;
             $coupon_num = wpsc_get_customer_meta('coupon');
             if ($coupon_num) {
                 $coupon = new wpsc_coupons($coupon_num);
                 $free_shipping = $coupon->is_percentage == '2';
             }
             // minus coupon tax if we are using coupons, but make sure the coupon is not a free shipping coupon
             /* Iterative note: In a future implementation, we'll allow for coupons to either apply to taxes, or not */
             /* The default logic to date has been that they do, which is generally improper, and there's a logic bug here as well */
             /* @link: https://github.com/wp-e-commerce/WP-e-Commerce/issues/170 */
             if ($wpsc_cart->coupons_amount > 0 && !$free_shipping) {
                 if ($this->wpec_taxes_isincluded()) {
                     $coupon_tax = $this->wpec_taxes_calculate_tax($wpsc_cart->coupons_amount, $tax_rate['rate'], false);
                 } else {
                     $coupon_tax = $this->wpec_taxes_calculate_tax($wpsc_cart->coupons_amount, $tax_rate['rate']);
                 }
                 /* Only subtract if coupons apply to tax.  Likely in 4.0 */
                 /* $total_tax -= $coupon_tax; */
             }
             //add shipping tax if set
             if ($tax_rate['shipping'] && !$free_shipping) {
                 if ($this->wpec_taxes_isincluded()) {
                     $total_tax += $this->wpec_taxes_calculate_tax($wpsc_cart->calculate_total_shipping(), $tax_rate['rate'], false);
                 } else {
                     $total_tax += $this->wpec_taxes_calculate_tax($wpsc_cart->calculate_total_shipping(), $tax_rate['rate']);
                 }
             }
             // if
             $returnable = array('total' => $total_tax);
             if (!$this->wpec_taxes_isincluded() && isset($tax_rate['rate'])) {
                 $returnable['rate'] = $tax_rate['rate'];
             }
             // if
         }
         // if
     }
     //if
     return $returnable;
 }
Пример #15
0
/**
 * Merge cart from anonymous user with cart from logged in user
 *
 * @since 3.8.13
 * @access private
 */
function _wpsc_merge_cart()
{
    $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)) {
        return;
    }
    do_action('_wpsc_merge_cart', $id_from_wp_user);
    $id_from_customer_meta = wpsc_get_customer_meta('merge_cart_vistor_id');
    wpsc_delete_customer_meta('merge_cart_vistor_id');
    $old_cart = wpsc_get_customer_cart($id_from_customer_meta);
    $items = $old_cart->get_items();
    $new_cart = wpsc_get_customer_cart($id_from_wp_user);
    // first of all empty the old cart so that the claimed stock and related
    // hooks are released
    $old_cart->empty_cart();
    // add each item to the new cart
    foreach ($items as $item) {
        $new_cart->set_item($item->product_id, array('quantity' => $item->quantity, 'variation_values' => $item->variation_values, 'custom_message' => $item->custom_message, 'provided_price' => $item->provided_price, 'time_requested' => $item->time_requested, 'custom_file' => $item->custom_file, 'is_customisable' => $item->is_customisable, 'meta' => $item->meta, 'item_meta' => $item->get_meta()));
    }
    wpsc_update_customer_cart($new_cart);
    // The old profile is no longer needed
    _wpsc_abandon_temporary_customer_profile($id_from_customer_meta);
}
Пример #16
0
 /**
  * returns shipping quotes using this shipping module.
  *
  * @return array collection of rates applicable.
  */
 function getQuote()
 {
     global $wpdb, $wpsc_cart;
     if (wpsc_get_customer_meta('nzshpcart')) {
         $shopping_cart = wpsc_get_customer_meta('nzshpcart');
     }
     if (is_object($wpsc_cart)) {
         $price = $wpsc_cart->calculate_subtotal(true);
     }
     $layers = get_option('table_rate_layers');
     if ($layers != '') {
         // At some point we should probably remove this as the sorting should be
         // done when we save the data to the database. But need to leave it here
         // for people who have non-sorted settings in their database
         krsort($layers);
         foreach ($layers as $key => $shipping) {
             if ($price >= (double) $key) {
                 if (stristr($shipping, '%')) {
                     // Shipping should be a % of the cart total
                     $shipping = str_replace('%', '', $shipping);
                     $shipping_amount = $price * ($shipping / 100);
                 } else {
                     // Shipping is an absolute value
                     $shipping_amount = $shipping;
                 }
                 return array(__("Table Rate", 'wpsc') => $shipping_amount);
             }
         }
         $shipping = array_shift($layers);
         if (stristr($shipping, '%')) {
             $shipping = str_replace('%', '', $shipping);
             $shipping_amount = $price * ($shipping / 100);
         } else {
             $shipping_amount = $shipping;
         }
         return array(__("Table Rate", 'wpsc') => $shipping_amount);
     }
 }
 /**
  * submit method, sends the received data to the payment gateway
  * @access public
  */
 function submit()
 {
     $paymentAmount = $this->cart_data['total_price'];
     wpsc_update_customer_meta('paypal_express_converted_amount', $this->convert($paymentAmount));
     wpsc_update_customer_meta('paypal_express_original_amount', $paymentAmount);
     wpsc_update_customer_meta('paypal_express_sessionid', $this->cart_data['session_id']);
     $currencyCodeType = $this->get_paypal_currency_code();
     $paymentType = "Sale";
     if (get_option('permalink_structure') != '') {
         $separator = "?";
     } else {
         $separator = "&";
     }
     $transact_url = get_option('transact_url');
     $returnURL = $transact_url . $separator . "sessionid=" . $this->cart_data['session_id'] . "&gateway=paypal";
     $cancelURL = get_option('shopping_cart_url');
     $resArray = $this->CallShortcutExpressCheckout(wpsc_get_customer_meta('paypal_express_converted_amount'), $currencyCodeType, $paymentType, $returnURL, $cancelURL);
     $ack = strtoupper($resArray["ACK"]);
     if ($ack == "SUCCESS") {
         $this->RedirectToPayPal($resArray["TOKEN"]);
     } else {
         //Display a user friendly Error on the page using any of the following error information returned by PayPal
         $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
         $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
         $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
         $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
         echo "SetExpressCheckout API call failed. ";
         echo "<br />Detailed Error Message: " . $ErrorLongMsg;
         echo "<br />Short Error Message: " . $ErrorShortMsg;
         echo "<br />Error Code: " . $ErrorCode;
         echo "<br />Error Severity Code: " . $ErrorSeverityCode;
     }
     exit;
 }
Пример #18
0
/**
 * Get the current values for checkout meta
 *
 * @since 3.8.14
 * @access private
 *
 * @param array values being readied to send back to javascript in the json encoded AJAX response
 * @param string|array|null meta keys to retrieve, if not specified all meta keys are retrieved
 * @return JSON encoded array with results, results include original request parameters
 */
function _wpsc_get_checkout_meta($meta_keys = null)
{
    if (!empty($meta_keys)) {
        if (!is_array($meta_keys)) {
            $meta_keys = array($meta_keys);
        }
    } else {
        $meta_keys = wpsc_checkout_unique_names();
    }
    $checkout_meta = array();
    foreach ($meta_keys as $a_meta_key) {
        $checkout_meta[$a_meta_key] = wpsc_get_customer_meta($a_meta_key);
    }
    return $checkout_meta;
}
Пример #19
0
/**
 * function to provide deprecated variables to older shipping modules
 *
 * @since 3.8.14
 */
function wpsc_deprecated_vars_for_shipping($wpsc_cart)
{
    // extracted from the Instinct fedex module
    $_POST['country'] = wpsc_get_customer_meta('shippingcountry');
    $_POST['region'] = wpsc_get_customer_meta('shippingregion');
    $_POST['zipcode'] = wpsc_get_customer_meta('shippingpostcode');
}
Пример #20
0
    /**
     * General entry point for WPEC external shipping calculator
     * This function expects no arguments but requires POST data
     * and configuration from the plugin settings
     * @return array $rate_table List of rates in "Service"=>"Rate" format
     */
    function getQuote()
    {
        global $wpdb, $wpec_ash, $wpec_ash_tools, $wpsc_cart;
        $data = array();
        //************** These values are common to all entry points **************
        //*** User/Customer Entered Values ***\\
        //*** Set up the destination country ***\
        $data["dest_country"] = wpsc_get_customer_meta('shipping_country');
        $settings = get_option('wpec_usps');
        //Disable International Shipping. Default: Enabled as it currently is.
        $data['intl_rate'] = isset($settings['intl_rate']) && !empty($settings['intl_rate']) ? FALSE : TRUE;
        if (!$data['intl_rate'] && $data['dest_country'] != get_option('base_country')) {
            return array();
        }
        // If ths zip code is provided via a form post use it!
        $data["dest_zipcode"] = (string) wpsc_get_customer_meta('shippingpostcode');
        if (!is_object($wpec_ash_tools)) {
            $wpec_ash_tools = new ASHTools();
        }
        if (empty($data["dest_zipcode"]) && $wpec_ash_tools->needs_post_code($data["dest_country"])) {
            // We cannot get a quote without a zip code so might as well return!
            return array();
        }
        //*** Grab Total Weight from the shipment object for simple shipping
        $data["weight"] = wpsc_cart_weight_total();
        if (empty($data["weight"])) {
            return array();
        }
        // If the region code is provided via a form post use it!
        if (isset($_POST['region']) && !empty($_POST['region'])) {
            $data['dest_state'] = wpsc_get_region(sanitize_text_field($_POST['region']));
        } else {
            if ($dest_state = wpsc_get_customer_meta('shipping_state')) {
                // Well, we have a zip code in the session and no new one provided
                $data['dest_state'] = $dest_state;
            } else {
                $data['dest_state'] = "";
            }
        }
        $data["dest_country"] = $wpec_ash_tools->get_full_country($data["dest_country"]);
        $data["dest_country"] = $this->_update_country($data["dest_country"]);
        if (!is_object($wpec_ash)) {
            $wpec_ash = new ASH();
        }
        $shipping_cache_check['state'] = $data['dest_state'];
        $shipping_cache_check['country'] = $data['dest_country'];
        $shipping_cache_check['zipcode'] = $data["dest_zipcode"];
        $this->shipment = $wpec_ash->get_shipment();
        $this->shipment->set_destination($this->internal_name, $shipping_cache_check);
        $this->shipment->rates_expire = date('Y-m-d');
        //Date will be checked against the cached date.
        $data['shipper'] = $this->internal_name;
        $data["adv_rate"] = !empty($settings["adv_rate"]) ? $settings["adv_rate"] : FALSE;
        // Use advanced shipping for Domestic Rates ? Not available
        if ($data["weight"] > 70 && !(bool) $data["adv_rate"]) {
            //USPS has a weight limit: https://www.usps.com/send/can-you-mail-it.htm?#3.
            $over_weight_txt = apply_filters('wpsc_shipment_over_weight', __('Your order exceeds the standard shipping weight limit.
													Please contact us to quote other shipping alternatives.', 'wp-e-commerce'), $data);
            $shipping_quotes[$over_weight_txt] = 0;
            // yes, a constant.
            $wpec_ash->cache_results($this->internal_name, array($shipping_quotes), $this->shipment);
            return array($shipping_quotes);
        }
        // Check to see if the cached shipment is still accurate, if not we need new rate
        $cache = $wpec_ash->check_cache($this->internal_name, $this->shipment);
        // We do not want to spam USPS (and slow down our process) if we already
        // have a shipping quote!
        if (count($cache["rate_table"]) >= 1) {
            //$cache['rate_table'] could be array(0).
            return $cache["rate_table"];
        }
        //*** WPEC Configuration values ***\\
        $this->use_test_env = !isset($settings["test_server"]) ? false : (bool) $settings['test_server'];
        $data["fcl_type"] = !empty($settings["fcl_type"]) ? $settings["fcl_type"] : "PARCEL";
        $data["mail_type"] = !empty($settings["intl_pkg"]) ? $settings["intl_pkg"] : "Package";
        $data["base_zipcode"] = get_option("base_zipcode");
        $data["services"] = !empty($settings["services"]) ? $settings["services"] : array("STANDARD POST", "PRIORITY", "PRIORITY EXPRESS", "FIRST CLASS");
        foreach ($data["services"] as $id => $service) {
            if ($service == 'PARCEL') {
                $data["services"][$id] = 'STANDARD POST';
            }
            if ($service == 'EXPRESS') {
                $data["services"][$id] = 'PRIORITY EXPRESS';
            }
        }
        $data["user_id"] = $settings["id"];
        $data["value"] = $wpsc_cart->calculate_subtotal(true);
        //Required by $this->_build_intl_shipment.
        $data = apply_filters('wpsc_shipment_data', $data, $this->shipment);
        if (isset($data['stop'])) {
            //Do not get rates.
            return array();
        }
        //************ GET THE RATE ************\\
        $rate_table = apply_filters('wpsc_rates_table', $this->_run_quote($data), $data, $this->shipment);
        //Avoid trying getting rates again and again when the stored zip code is incorrect.
        //************ CACHE the Results ************\\
        $wpec_ash->cache_results($this->internal_name, $rate_table, $this->shipment);
        return $rate_table;
    }
Пример #21
0
 /**
  * update_location method, updates the location
  * @access public
  */
 public function update_location()
 {
     $delivery_country = wpsc_get_customer_meta('shippingcountry');
     $billing_country = wpsc_get_customer_meta('billingcountry');
     $delivery_region = wpsc_get_customer_meta('shippingregion');
     $billing_region = wpsc_get_customer_meta('billingregion');
     $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();
 }
Пример #22
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();
 }
Пример #23
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;
 }
Пример #24
0
function gateway_ideal($seperator, $sessionid)
{
    global $wpdb;
    $purchase_log_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1";
    $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A);
    $submiturl = "https://internetkassa.abnamro.nl/ncol/prod/orderstandard.asp";
    $amount = nzshpcrt_overall_total_price(wpsc_get_customer_meta('shipping_country'));
    if ($_POST['collected_data'][get_option('ideal_form_post_code')] != '') {
        $postcode = $_POST['collected_data'][get_option('ideal_form_post_code')];
    }
    if ($_POST['collected_data'][get_option('ideal_form_address')] != '') {
        $address = $_POST['collected_data'][get_option('ideal_form_address')];
    }
    if ($_POST['collected_data'][get_option('ideal_form_email')] != '') {
        $email = $_POST['collected_data'][get_option('ideal_form_email')];
    }
    if ($_POST['collected_data'][get_option('ideal_form_city')] != '') {
        $city = $_POST['collected_data'][get_option('ideal_form_city')];
    }
    if ($_POST['collected_data'][get_option('ideal_form_country')] != '') {
        $country = $_POST['collected_data'][get_option('ideal_form_country')][0];
        $country = $wpdb->get_var("SELECT country FROM {$wpdb->prefix}currency_list WHERE isocode='{$country}'");
    }
    if ($_POST['collected_data'][get_option('ideal_form_first_name')] != '') {
        $name = $_POST['collected_data'][get_option('ideal_form_first_name')] . " " . $_POST['collected_data'][get_option('ideal_form_last_name')];
    }
    ?>
<body onload="setTimeout('submit_purchase()',50)">
<script type="text/javascript">
var Amount = <?php 
    echo $amount;
    ?>
;
var PSPID = "<?php 
    echo get_option('ideal_id');
    ?>
";
var AM;
if (isNaN(Amount)) {
	alert("Amount not a number: " + Amount + " !");
	AM = "";
} else {
	AM = Math.round(parseFloat(Amount)*100);
}
</script>
<form method='post' action='<?php 
    echo $submiturl;
    ?>
' id='ideal_form' name='ideal_form'>
<script type="text/javascript">
document.write("<input type=\"hidden\" NAME=\"PSPID\" value=\"" + PSPID + "\" />");
document.write("<input type=\"hidden\" NAME=\"amount\" value=\"" + AM + "\" />");
</script>
<input type="hidden" NAME="orderID" value="<?php 
    echo $purchase_log[0]['id'];
    ?>
" />
<input type="hidden" name="currency" value="<?php 
    echo get_option('ideal_currency');
    ?>
" />
<input type="hidden" name="language" value="<?php 
    echo get_option('ideal_language');
    ?>
" />
<input type="hidden" name="accepturl" value="<?php 
    echo get_option('product_list_url');
    ?>
">
<input type="hidden" name="cancelurl" value="<?php 
    echo get_option('shopping_cart_url');
    ?>
">
<!--customer information starts-->
<input type="hidden" name="CN" value="<?php 
    echo $name;
    ?>
">
<input type="hidden" name="EMAIL" value="<?php 
    echo $email;
    ?>
">
<input type="hidden" name="ownerZIP" value="<?php 
    echo $postcode;
    ?>
">
<input type="hidden" name="owneraddress" value="<?php 
    echo $address;
    ?>
">
<input type="hidden" name="ownercty" value="<?php 
    echo $country;
    ?>
">
<input type="hidden" name="ownertown" value="<?php 
    echo $city;
    ?>
">
<input type="hidden" name="ownertelno" value="<?php 
    echo $phone;
    ?>
">
<!--customer information ends-->
<input type="hidden" name="PM" value="iDEAL" />
</form>
</body>
<?php 
    // 	$fields = "PSPID=".get_option('ideal_id')."&orderID=".$sessionid."&amount=".$amount."&PM=iDEAL&language=".get_option('ideal_language')."&currency=".get_option('ideal_currency');
    // 	exit($fields);
    // 	header("Location:". $submiturl.$fields);
    // 	exit($result);
}
/**
 * wpsc_display_form_fields()
 *
 * This function displays each of the form fields.  Each of them are filterable via 'wpsc_account_form_field_$tag' where tag is permalink-styled name or uniquename.
 * i.e. First Name under Shipping would be 'wpsc_account_form_field_shippingfirstname' - while Your Billing Details would be filtered
 * via 'wpsc_account_form_field_your-billing-details'.
 *
 * @global <type> $wpdb
 * @global <type> $user_ID
 * @global <type> $wpsc_purchlog_statuses
 * @global <type> $gateway_checkout_form_fields
 */
function wpsc_display_form_fields()
{
    // Field display and Data saving function
    global $wpdb, $user_ID, $wpsc_purchlog_statuses, $gateway_checkout_form_fields, $wpsc_checkout;
    if (empty($wpsc_checkout)) {
        $wpsc_checkout = new wpsc_checout();
    }
    $meta_data = wpsc_get_customer_meta('checkout_details');
    $meta_data = apply_filters('wpsc_user_log_get', $meta_data, $user_ID);
    $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' ORDER BY `checkout_set`, `checkout_order`;";
    $form_data = $wpdb->get_results($form_sql, ARRAY_A);
    foreach ($form_data as $form_field) {
        if (!empty($form_field['unique_name'])) {
            $ff_tag = $form_field['unique_name'];
        } else {
            $ff_tag = esc_html(strtolower(str_replace(' ', '-', $form_field['name'])));
        }
        if (!empty($meta_data[$form_field['id']]) && !is_array($meta_data[$form_field['id']])) {
            $meta_data[$form_field['id']] = esc_html($meta_data[$form_field['id']]);
        }
        if ($form_field['type'] == 'heading') {
            echo "\n    <tr>\n      <td colspan='2'>\n\r";
            echo "<strong>" . apply_filters('wpsc_account_form_field_' . $ff_tag, esc_html($form_field['name'])) . "</strong>";
            echo "\n      </td>\n    </tr>\n\r";
        } else {
            $display = '';
            if (in_array($form_field['unique_name'], array('shippingstate', 'billingstate'))) {
                if ($form_field['unique_name'] == 'shippingstate') {
                    $country_field_id = wpsc_get_country_form_id_by_type('delivery_country');
                } else {
                    $country_field_id = wpsc_get_country_form_id_by_type('country');
                }
                $country = is_array($meta_data[$country_field_id]) ? $meta_data[$country_field_id][0] : $meta_data[$country_field_id];
                if (wpsc_has_regions($country)) {
                    $display = ' style="display:none;"';
                }
            }
            echo "\n\t\t      <tr{$display}>\n    \t\t    <td align='left'>\n\r";
            echo apply_filters('wpsc_account_form_field_' . $ff_tag, $form_field['name']);
            if ($form_field['mandatory'] == 1) {
                echo " *";
            }
            echo "\n        \t\t</td>\n\r\n        \t\t<td  align='left'>\n\r";
            switch ($form_field['type']) {
                case "city":
                case "delivery_city":
                    echo "<input type='text' value='" . $meta_data[$form_field['id']] . "' name='collected_data[" . $form_field['id'] . "]' />";
                    break;
                case "address":
                case "delivery_address":
                case "textarea":
                    echo "<textarea name='collected_data[" . $form_field['id'] . "]'>" . $meta_data[$form_field['id']] . "</textarea>";
                    break;
                case "text":
                    $value = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : '';
                    echo "<input type='text' value='" . $value . "' name='collected_data[" . $form_field['id'] . "]' />";
                    break;
                case "region":
                case "delivery_region":
                    echo "<select name='collected_data[" . $form_field['id'] . "]'>" . nzshpcrt_region_list($_SESSION['collected_data'][$form_field['id']]) . "</select>";
                    break;
                case "country":
                    if (is_array($meta_data[$form_field['id']])) {
                        $country_code = $meta_data[$form_field['id']][0];
                    } else {
                        $country_code = $meta_data[$form_field['id']];
                    }
                    $html_id = 'wpsc-profile-billing-country';
                    $js = "onchange=\"wpsc_set_profile_country('{$html_id}', '" . $form_field['id'] . "');\"";
                    echo "<select id='{$html_id}' {$js} name='collected_data[" . $form_field['id'] . "][0]' >" . nzshpcrt_country_list($country_code) . "</select>";
                    if (wpsc_has_regions($country_code)) {
                        $region = isset($meta_data[$form_field['id']][1]) ? $meta_data[$form_field['id']][1] : '';
                        echo "<br /><select name='collected_data[" . $form_field['id'] . "][1]'>" . nzshpcrt_region_list($country_code, $region) . "</select>";
                    }
                    break;
                case "delivery_country":
                    if (is_array($meta_data[$form_field['id']])) {
                        $country_code = $meta_data[$form_field['id']][0];
                    } else {
                        $country_code = $meta_data[$form_field['id']];
                    }
                    $html_id = 'wpsc-profile-shipping-country';
                    $js = "onchange=\"wpsc_set_profile_country('{$html_id}', '" . $form_field['id'] . "');\"";
                    echo "<select id='{$html_id}' {$js} name='collected_data[" . $form_field['id'] . "][0]' >" . nzshpcrt_country_list($country_code) . "</select>";
                    if (wpsc_has_regions($country_code)) {
                        $region = isset($meta_data[$form_field['id']][1]) ? $meta_data[$form_field['id']][1] : '';
                        echo "<br /><select name='collected_data[" . $form_field['id'] . "][1]'>" . nzshpcrt_region_list($country_code, $region) . "</select>";
                    }
                    break;
                case "email":
                    echo "<input type='text' value='" . $meta_data[$form_field['id']] . "' name='collected_data[" . $form_field['id'] . "]' />";
                    break;
                case "select":
                    $options = $wpsc_checkout->get_checkout_options($form_field['id']);
                    $selected = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : null;
                    ?>
						<select name='collected_data[<?php 
                    echo esc_attr($form_field['id']);
                    ?>
]'>
							<option value="-1"><?php 
                    _ex('Select an Option', 'Dropdown default on user log page', 'wpsc');
                    ?>
</option>
							<?php 
                    foreach ($options as $label => $value) {
                        ?>
								<option <?php 
                        selected($value, $selected);
                        ?>
 value="<?php 
                        echo esc_attr($value);
                        ?>
"><?php 
                        echo esc_html($label);
                        ?>
</option>
							<?php 
                    }
                    ?>
						</select>
					<?php 
                    break;
                case 'checkbox':
                case 'radio':
                    $checked_values = isset($meta_data[$form_field['id']]) ? (array) $meta_data[$form_field['id']] : array();
                    $options = $wpsc_checkout->get_checkout_options($form_field['id']);
                    $field_name = "collected_data[{$form_field['id']}]";
                    if ($form_field['type'] == 'checkbox') {
                        $field_name .= '[]';
                    }
                    foreach ($options as $label => $value) {
                        ?>
							<label>
								<input <?php 
                        checked(in_array($value, $checked_values));
                        ?>
 type="<?php 
                        echo $form_field['type'];
                        ?>
" id="" name="collected_data[<?php 
                        echo esc_attr($form_field['id']);
                        ?>
][]" value="<?php 
                        echo esc_attr($value);
                        ?>
"  />
								<?php 
                        echo esc_html($label);
                        ?>
							</label><br />
						<?php 
                    }
                    break;
                default:
                    $value = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : '';
                    echo "<input type='text' value='" . $value . "' name='collected_data[" . $form_field['id'] . "]' />";
                    break;
            }
            echo wp_nonce_field('wpsc_user_profile', '_wpsc_user_profile');
            echo "\n        </td>\n      </tr>\n\r";
        }
    }
    /* Returns an empty array at this point, empty in regards to fields, does show the internalname though.  Needs to be reconsidered, even if it did work, need to check
    	 * functionality and PCI_DSS compliance
    
    	  if ( isset( $gateway_checkout_form_fields ) )
    	  {
    	  echo $gateway_checkout_form_fields;
    	  }
    	 */
}
Пример #26
0
function gateway_chronopay($separator, $sessionid)
{
    global $wpdb;
    $purchase_log_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= %s LIMIT 1", $sessionid);
    $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A);
    $cart_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='" . $purchase_log[0]['id'] . "'";
    $cart = $wpdb->get_results($cart_sql, ARRAY_A);
    // ChronoPay post variables
    $chronopay_url = get_option('chronopay_url');
    $data['product_id'] = get_option('chronopay_product_id');
    $data['product_name'] = get_option('chronopay_product_name');
    $data['product_price_currency'] = get_option('chronopay_curcode');
    $data['language'] = get_option('chronopay_language');
    $data['cb_url'] = add_query_arg('chronopay_callback', 'true', home_url('/'));
    $data['cb_type'] = 'P';
    $data['decline_url'] = home_url('/?chronopay_callback=true');
    $data['cs1'] = $sessionid;
    $data['cs2'] = 'chronopay';
    $salt = get_option('chronopay_salt');
    $data['cs3'] = md5($salt . md5($sessionid . $salt));
    // placed in here for security so that the return call can be validated as 'real'
    // User details
    if ($_POST['collected_data'][get_option('chronopay_form_first_name')] != '') {
        $data['f_name'] = $_POST['collected_data'][get_option('chronopay_form_first_name')];
    }
    if ($_POST['collected_data'][get_option('chronopay_form_last_name')] != "") {
        $data['s_name'] = $_POST['collected_data'][get_option('chronopay_form_last_name')];
    }
    if ($_POST['collected_data'][get_option('chronopay_form_address')] != '') {
        $data['street'] = str_replace("\n", ', ', $_POST['collected_data'][get_option('chronopay_form_address')]);
    }
    if ($_POST['collected_data'][get_option('chronopay_form_city')] != '') {
        $data['city'] = $_POST['collected_data'][get_option('chronopay_form_city')];
    }
    $data['country'] = (string) wpsc_get_customer_meta('billingcountry');
    // Change suggested by waxfeet@gmail.com, if email to be sent is not there, dont send an email address
    $email_data = $wpdb->get_results("SELECT `id`,`type` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1'", ARRAY_A);
    foreach ((array) $email_data as $email) {
        $data['email'] = $_POST['collected_data'][$email['id']];
    }
    if ($_POST['collected_data'][get_option('email_form_field')] != null && $data['email'] == null) {
        $data['email'] = $_POST['collected_data'][get_option('email_form_field')];
    }
    // Get Currency details abd price
    $currency_code = WPSC_Countries::get_currency_code(get_option('currency_type'));
    $local_currency_code = $currency_code[0]['code'];
    $chronopay_currency_code = get_option('chronopay_curcode');
    // ChronoPay only processes in the set currency.  This is USD or EUR dependent on what the Chornopay account is set up with.
    // This must match the ChronoPay settings set up in wordpress.  Convert to the chronopay currency and calculate total.
    $curr = new CURRENCYCONVERTER();
    $decimal_places = 2;
    $total_price = 0;
    $i = 1;
    $all_donations = true;
    $all_no_shipping = true;
    foreach ($cart as $item) {
        $product_data = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . $wpdb->posts . "` WHERE `id`= %d LIMIT 1", $item['prodid']), ARRAY_A);
        $product_data = $product_data[0];
        $variation_count = count($product_variations);
        //Does this even still work in 3.8? We're not using this table.
        $variation_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id` = %d", $item['id']);
        $variation_data = $wpdb->get_results($variation_sql, ARRAY_A);
        $variation_count = count($variation_data);
        if ($variation_count >= 1) {
            $variation_list = " (";
            $j = 0;
            foreach ($variation_data as $variation) {
                if ($j > 0) {
                    $variation_list .= ", ";
                }
                $value_id = $variation['venue_id'];
                $value_data = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`= %d LIMIT 1", $value_id), ARRAY_A);
                $variation_list .= $value_data[0]['name'];
                $j++;
            }
            $variation_list .= ")";
        } else {
            $variation_list = '';
        }
        $local_currency_productprice = $item['price'];
        $local_currency_shipping = $item['pnp'];
        $chronopay_currency_productprice = $local_currency_productprice;
        $chronopay_currency_shipping = $local_currency_shipping;
        $data['item_name_' . $i] = $product_data['name'] . $variation_list;
        $data['amount_' . $i] = number_format(sprintf("%01.2f", $chronopay_currency_productprice), $decimal_places, '.', '');
        $data['quantity_' . $i] = $item['quantity'];
        $data['item_number_' . $i] = $product_data['id'];
        if ($item['donation'] != 1) {
            $all_donations = false;
            $data['shipping_' . $i] = number_format($chronopay_currency_shipping, $decimal_places, '.', '');
            $data['shipping2_' . $i] = number_format($chronopay_currency_shipping, $decimal_places, '.', '');
        } else {
            $data['shipping_' . $i] = number_format(0, $decimal_places, '.', '');
            $data['shipping2_' . $i] = number_format(0, $decimal_places, '.', '');
        }
        if ($product_data['no_shipping'] != 1) {
            $all_no_shipping = false;
        }
        $total_price = $total_price + $data['amount_' . $i] * $data['quantity_' . $i];
        if ($all_no_shipping != false) {
            $total_price = $total_price + $data['shipping_' . $i] + $data['shipping2_' . $i];
        }
        $i++;
    }
    $base_shipping = $purchase_log[0]['base_shipping'];
    if ($base_shipping > 0 && $all_donations == false && $all_no_shipping == false) {
        $data['handling_cart'] = number_format($base_shipping, $decimal_places, '.', '');
        $total_price += number_format($base_shipping, $decimal_places, '.', '');
    }
    $data['product_price'] = $total_price;
    // Create Form to post to ChronoPay
    $output = "\n\t\t<form id=\"chronopay_form\" name=\"chronopay_form\" method=\"post\" action=\"{$chronopay_url}\">\n";
    foreach ($data as $n => $v) {
        $output .= "\t\t\t<input type=\"hidden\" name=\"{$n}\" value=\"{$v}\" />\n";
    }
    $output .= "\t\t\t<input type=\"submit\" value=\"Continue to ChronoPay\" />\n\t\t</form>\n\t";
    // Output the form.
    echo $output;
    echo "<script language=\"javascript\" type=\"text/javascript\">document.getElementById('chronopay_form').submit();</script>";
    exit;
}
Пример #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
function wpsc_transaction_theme()
{
    global $wpdb, $user_ID, $nzshpcrt_gateways, $sessionid, $cart_log_id, $errorcode;
    $errorcode = '';
    $transactid = '';
    $dont_show_transaction_results = false;
    if (isset($_GET['sessionid'])) {
        $sessionid = $_GET['sessionid'];
    }
    if (!isset($_GET['sessionid']) && isset($_GET['ms'])) {
        $sessionid = $_GET['ms'];
    }
    $selected_gateway = wpsc_get_customer_meta('selected_gateway');
    if ($selected_gateway && in_array($selected_gateway, array('paypal_certified', 'wpsc_merchant_paypal_express'))) {
        $sessionid = wpsc_get_customer_meta('paypal_express_sessionid');
    }
    if (isset($_REQUEST['eway']) && '1' == $_REQUEST['eway']) {
        $sessionid = $_GET['result'];
    } elseif (isset($_REQUEST['eway']) && '0' == $_REQUEST['eway']) {
        echo wpsc_get_customer_meta('eway_message');
    } elseif (isset($_REQUEST['payflow']) && '1' == $_REQUEST['payflow']) {
        echo wpsc_get_customer_meta('payflow_message');
        wpsc_delete_customer_meta('payflow_message');
    }
    $dont_show_transaction_results = false;
    if ($selected_gateway) {
        // Replaces the ugly if else for gateways
        switch ($selected_gateway) {
            case 'paypal_certified':
            case 'wpsc_merchant_paypal_express':
                echo wpsc_get_customer_meta('paypal_express_message');
                $reshash = wpsc_get_customer_meta('paypal_express_reshash');
                if (isset($reshash['PAYMENTINFO_0_TRANSACTIONTYPE']) && in_array($reshash['PAYMENTINFO_0_TRANSACTIONTYPE'], array('expresscheckout', 'cart'))) {
                    $dont_show_transaction_results = false;
                } else {
                    $dont_show_transaction_results = true;
                }
                break;
            case 'dps':
                $sessionid = decrypt_dps_response();
                break;
                //paystation was not updating the purchase logs for successful payment - this is ugly as need to have the databse update done in one place by all gatways on a sucsessful transaction hook not some within the gateway and some within here and some not at all??? This is getting a major overhaul but for here and now it just needs to work for the gold cart people!
            //paystation was not updating the purchase logs for successful payment - this is ugly as need to have the databse update done in one place by all gatways on a sucsessful transaction hook not some within the gateway and some within here and some not at all??? This is getting a major overhaul but for here and now it just needs to work for the gold cart people!
            case 'paystation':
                $ec = $_GET['ec'];
                $result = $_GET['em'];
                if ($result == 'Transaction successful' && $ec == 0) {
                    $processed_id = '3';
                }
                if ($result == 'Insufficient Funds' && $ec == 5) {
                    $processed_id = '6';
                }
                if ($processed_id) {
                    wpsc_update_purchase_log_status($sessionid, $processed_id, 'sessionid');
                }
                break;
            case 'wpsc_merchant_paymentexpress':
                // Payment Express sends back there own session id, which is temporarily stored in the Auth field
                // so just swapping that over here
                $query = "SELECT `sessionid` FROM  `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE  `authcode` ='" . $sessionid . "'";
                $result = $wpdb->get_var($query);
                if ($result != null) {
                    // just in case they are using an older version old gold cart (pre 2.9.5)
                    $sessionid = $result;
                    $dont_show_transaction_results = true;
                }
                break;
            case 'eway_hosted':
                $sessionid = decrypt_eway_uk_response();
                break;
                //default filter for other payment gateways to use
            //default filter for other payment gateways to use
            default:
                $sessionid = apply_filters('wpsc_previous_selected_gateway_' . $selected_gateway, $sessionid);
                break;
        }
    }
    if (!$dont_show_transaction_results) {
        if (!empty($sessionid)) {
            $cart_log_id = $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= %s LIMIT 1", $sessionid));
            echo transaction_results($sessionid, true);
        } else {
            printf(__('Sorry your transaction was not accepted.<br /><a href="%1$s">Click here to go back to checkout page</a>.', 'wp-e-commerce'), wpsc_get_checkout_url());
        }
    }
}
Пример #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
 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);
 }