/**
 * wpsc buy now button code products function
 * Sorry about the ugly code, this is just to get the functionality back, buy now will soon be overhauled, and this function will then be completely different
 * @return string - html displaying one or more products
 */
function wpsc_buy_now_button($product_id, $replaced_shortcode = false)
{
    $product = get_post($product_id);
    $supported_gateways = array('wpsc_merchant_paypal_standard', 'paypal_multiple');
    $selected_gateways = get_option('custom_gateway_options');
    if (in_array('wpsc_merchant_paypal_standard', (array) $selected_gateways)) {
        if ($product_id > 0) {
            $post_meta = get_post_meta($product_id, '_wpsc_product_metadata', true);
            $shipping = $post_meta['shipping']['local'];
            $price = get_post_meta($product_id, '_wpsc_price', true);
            $special_price = get_post_meta($product_id, '_wpsc_special_price', true);
            if ($special_price) {
                $price = $special_price;
            }
            if (wpsc_uses_shipping()) {
                $handling = get_option('base_local_shipping');
            } else {
                $handling = $shipping;
            }
            $output .= "<form onsubmit='log_paypal_buynow(this)' target='paypal' action='" . get_option('paypal_multiple_url') . "' method='post' />\n\t\t\t\t<input type='hidden' name='business' value='" . get_option('paypal_multiple_business') . "' />\n\t\t\t\t<input type='hidden' name='cmd' value='_xclick' />\n\t\t\t\t<input type='hidden' name='item_name' value='" . $product->post_title . "' />\n\t\t\t\t<input type='hidden' id='item_number' name='item_number' value='" . $product_id . "' />\n\t\t\t\t<input type='hidden' id='amount' name='amount' value='" . $price . "' />\n\t\t\t\t<input type='hidden' id='unit' name='unit' value='" . $price . "' />\n\t\t\t\t<input type='hidden' id='shipping' name='ship11' value='" . $shipping . "' />\n\t\t\t\t<input type='hidden' name='handling' value='" . $handling . "' />\n\t\t\t\t<input type='hidden' name='currency_code' value='" . get_option('paypal_curcode') . "' />";
            if (get_option('multi_add') == 1) {
                $output .= "<label for='quantity'>" . __('Quantity', 'wpsc') . "</label>";
                $output .= "<input type='text' size='4' id='quantity' name='quantity' value='' /><br />";
            } else {
                $output .= "<input type='hidden' name='undefined_quantity' value='0' />";
            }
            $output .= "<input type='image' name='submit' border='0' src='https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif' alt='PayPal - The safer, easier way to pay online' />\n\t\t\t\t<img alt='' border='0' width='1' height='1' src='https://www.paypal.com/en_US/i/scr/pixel.gif' />\n\t\t\t</form>\n\r";
        }
    }
    if ($replaced_shortcode == true) {
        return $output;
    } else {
        echo $output;
    }
}
 /**
  * Insert the ExpessCheckout Shortcut Button
  *
  * @return void
  */
 public function add_ecs_button($cart_table, $context)
 {
     if (wpsc_uses_shipping() || !wpsc_is_gateway_active('paypal-digital-goods')) {
         return;
     }
     if ('bottom' == $context) {
         return;
     }
     if (_wpsc_get_current_controller_name() === 'cart') {
         $url = $this->get_shortcut_url();
         echo '<a class="express-checkout-button" id="pp-ecs-dg" href="' . esc_url($url) . '"><img src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-large.png" alt="' . __('Check out with PayPal', 'wp-e-commerce') . '" /></a>';
     }
 }
/**
* wpsc buy now button code products function
* Sorry about the ugly code, this is just to get the functionality back, buy now will soon be overhauled, and this function will then be completely different
* @return string - html displaying one or more products
*/
function wpsc_buy_now_button($product_id, $replaced_shortcode = false)
{
    global $wpdb, $wpsc_query, $wpsc_cart;
    $temp_wpsc_query = new WPSC_query(array('product_id' => $product_id));
    list($wpsc_query, $temp_wpsc_query) = array($temp_wpsc_query, $wpsc_query);
    // swap the wpsc_query objects
    //  exit('<pre>'.print_r($temp_wpsc_query, true).'</pre>');
    $selected_gateways = get_option('custom_gateway_options');
    if (in_array('google', (array) $selected_gateways)) {
        $output .= google_buynow($product['id']);
    } else {
        if (in_array('paypal_multiple', (array) $selected_gateways)) {
            if ($product_id > 0) {
                //$output .= "<pre>".print_r($wpsc_query,true)."</pre>";
                while (wpsc_have_products()) {
                    wpsc_the_product();
                    $price = calculate_product_price($wpsc_query->product['id'], $wpsc_query->first_variations);
                    $shipping = $wpsc_query->product['pnp'];
                    if (wpsc_uses_shipping()) {
                        $handling = get_option('base_local_shipping');
                    } else {
                        $handling = $shipping;
                    }
                    $output .= "<form onsubmit='log_paypal_buynow(this)' target='paypal' action='" . get_option('paypal_multiple_url') . "' method='post' />\r\n\t\t\t\t\t<input type='hidden' name='business' value='" . get_option('paypal_multiple_business') . "' />\r\n\t\t\t\t\t<input type='hidden' name='cmd' value='_xclick' />\r\n\t\t\t\t\t<input type='hidden' name='item_name' value='" . wpsc_the_product_title() . "' />\r\n\t\t\t\t\t<input type='hidden' id='item_number' name='item_number' value='" . wpsc_the_product_id() . "' />\r\n\t\t\t\t\t<input type='hidden' id='amount' name='amount' value='" . ($price + $pnp) . "' />\r\n\t\t\t\t\t<input type='hidden' id='unit' name='unit' value='" . $price . "' />\r\n\t\t\t\t\t<input type='hidden' id='shipping' name='ship11' value='" . $shipping . "' />\r\n\t\t\t\t\t<input type='hidden' name='handling' value='" . $handling . "' />\r\n\t\t\t\t\t<input type='hidden' name='currency_code' value='" . get_option('paypal_curcode') . "' />";
                    if (get_option('multi_add') == 1) {
                        $output .= "<label for='quantity'>" . __('Quantity', 'wpsc') . "</label>";
                        $output .= "<input type='text' size='4' id='quantity' name='quantity' value='' /><br />";
                    } else {
                        $output .= "<input type='hidden' name='undefined_quantity' value='0' />";
                    }
                    $output .= "<input type='image' name='submit' border='0' src='https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif' alt='PayPal - The safer, easier way to pay online' />\r\n\t\t\t\t\t<img alt='' border='0' width='1' height='1' src='https://www.paypal.com/en_US/i/scr/pixel.gif' />\r\n\t\t\t\t</form>\n\r";
                }
            }
        }
    }
    list($temp_wpsc_query, $wpsc_query) = array($wpsc_query, $temp_wpsc_query);
    // swap the wpsc_query objects back
    if ($replaced_shortcode == true) {
        return $output;
    } else {
        echo $output;
    }
}
function Usecase($seperator, $sessionid, $fromcheckout)
{
    global $wpdb, $wpsc_cart;
    $purchase_log_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1";
    $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A);
    $cart_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='" . $purchase_log[0]['id'] . "'";
    $wp_cart = $wpdb->get_results($cart_sql, ARRAY_A);
    $merchant_id = get_option('google_id');
    $merchant_key = get_option('google_key');
    $server_type = get_option('google_server_type');
    $currency = get_option('google_cur');
    $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
    $transact_url = get_option('transact_url');
    $returnURL = $transact_url . $seperator . "sessionid=" . $sessionid . "&gateway=google";
    $cart->SetContinueShoppingUrl($returnURL);
    $cart->SetEditCartUrl(get_option('shopping_cart_url'));
    $no = 1;
    //exit("<pre>".print_r($wpsc_cart,true)."</pre>");
    //new item code
    $no = 0;
    //	$cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
    //	foreach($wpsc_cart->cart_items as $item){
    //google prohibited items not implemented
    $curr = new CURRENCYCONVERTER();
    $currency_code = $wpdb->get_results("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1", ARRAY_A);
    $local_currency_code = $currency_code[0]['code'];
    //	    exit('<pre>'.print_r($_REQUEST,true).'</pre>');
    $google_curr = get_option('google_cur');
    while (wpsc_have_cart_items()) {
        wpsc_the_cart_item();
        if ($google_curr != $local_currency_code) {
            $google_currency_productprice = $curr->convert(wpsc_cart_item_price(false) / wpsc_cart_item_quantity(), $google_curr, $local_currency_code);
            $google_currency_shipping = $curr->convert($wpsc_cart->selected_shipping_amount, $google_curr, $local_currency_code);
        } else {
            $google_currency_productprice = wpsc_cart_item_price(false) / wpsc_cart_item_quantity() + wpsc_cart_item_shipping(false);
            $google_currency_shipping = $wpsc_cart->selected_shipping_amount;
        }
        //	exit('<pre>'.print_r(wpsc_cart_item_name(),true).'</pre>');
        $cartitem["{$no}"] = new GoogleItem(wpsc_cart_item_name(), '', wpsc_cart_item_quantity(), $google_currency_productprice);
        $cart->AddItem($cartitem["{$no}"]);
        $no++;
    }
    //If there are coupons applied add coupon as a product with negative price
    if ($wpsc_cart->coupons_amount > 0) {
        if ($google_curr != $local_currency_code) {
            $google_currency_productprice = $curr->convert($wpsc_cart->coupons_amount, $google_curr, $local_currency_code);
        } else {
            $google_currency_productprice = $wpsc_cart->coupons_amount;
        }
        $cartitem[$no] = new GoogleItem('Discount', 'Discount Price', 1, '-' . $google_currency_productprice);
        // Unit price
        $cart->AddItem($cartitem[$no]);
    }
    //	}
    // Add shipping options
    if (wpsc_uses_shipping() && $google_currency_shipping > 0) {
        $Gfilter = new GoogleShippingFilters();
        $google_checkout_shipping = get_option("google_shipping_country");
        $googleshippingcountries = count($google_checkout_shipping);
        //exit('<pre>'.print_r($googleshipping, true).'</pre>');
        if ($googleshippingcountries == 242) {
            $Gfilter->SetAllowedWorldArea(true);
        } else {
            if (is_array($google_checkout_shipping)) {
                $google_shipping_country_ids = implode(",", $google_checkout_shipping);
            }
            $google_shipping_country = $wpdb->get_col("SELECT `isocode` FROM " . WPSC_TABLE_CURRENCY_LIST . " WHERE id IN (" . $google_shipping_country_ids . ")");
            foreach ($google_shipping_country as $isocode) {
                //exit($isocode);
                $Gfilter->AddAllowedPostalArea($isocode);
                if ($isocode == 'US') {
                    $Gfilter->SetAllowedCountryArea('ALL');
                }
            }
        }
        $Gfilter->SetAllowUsPoBox(false);
        $ship_1 = new GoogleFlatRateShipping('Flat Rate Shipping', $google_currency_shipping);
        $ship_1->AddShippingRestrictions($Gfilter);
        $cart->AddShipping($ship_1);
    }
    //wpsc_google_shipping_quotes();
    // Add tax rules
    //if ($_SESSION['wpsc_selected_country']=='US'){
    //set default tax
    //exit('<pre>'.print_r($_SESSION,true).'</pre>');
    $sql = "SELECT `name`, `tax` FROM " . WPSC_TABLE_REGION_TAX . " WHERE id='" . $_SESSION['wpsc_selected_region'] . "'";
    //exit('<pre>'.print_r($sql, true).'</pre>');
    $state_name = $wpdb->get_row($sql, ARRAY_A);
    //exit('<pre>'.print_r($state_name, true).'</pre>');
    $defaultTax = $state_name['tax'] / 100;
    $tax_rule = new GoogleDefaultTaxRule($defaultTax);
    $sql = "SELECT `code` FROM " . WPSC_TABLE_REGION_TAX . " WHERE `country_id`='136' AND `tax` = " . $state_name['tax'];
    $states = $wpdb->get_col($sql);
    //exit('<pre>'.print_r($states, true).'</pre>');
    $tax_rule->SetStateAreas((array) $states);
    $cart->AddDefaultTaxRules($tax_rule);
    //get alternative tax rates
    $sql = "SELECT DISTINCT `tax` FROM " . WPSC_TABLE_REGION_TAX . " WHERE `tax` != 0 AND `tax` !=" . $state_name['tax'] . "  AND `country_id`='136' ORDER BY `tax`";
    $othertax = $wpdb->get_col($sql);
    $i = 1;
    //exit('<pre>'.print_r($othertax, true).'</pre>');
    foreach ($othertax as $altTax) {
        $sql = "SELECT `code` FROM " . WPSC_TABLE_REGION_TAX . " WHERE `country_id`='136' AND `tax`=" . $altTax;
        $alt = $wpdb->get_col($sql);
        $altTax = $altTax / 100;
        $alt_google_tax = new GoogleDefaultTaxRule($altTax);
        $alt_google_tax->SetStateAreas($alt);
        //$g = new GoogleAlternateTaxTable('Alt Tax'.$i);
        //$g->AddAlternateTaxRules($alt_google_tax);
        $cart->AddDefaultTaxRules($alt_google_tax);
        //			exit(print_r($alt,true));
        $i++;
    }
    //}
    if (get_option('google_button_size') == '0') {
        $google_button_size = 'BIG';
    } elseif (get_option('google_button_size') == '1') {
        $google_button_size = 'MEDIUM';
    } elseif (get_option('google_button_size') == '2') {
        $google_button_size = 'SMALL';
    }
    // Display Google Checkout button
    //echo '<pre>'.print_r($cart, true).'</pre>';
    //unset($_SESSION['wpsc_sessionid']);
    //if($fromCheckout){
    echo $cart->CheckoutButtonCode($google_button_size);
    //}
}
Example #5
0
 /**
  * form_field method, returns the form html
  * @access public
  */
 function form_field()
 {
     global $wpdb, $user_ID;
     if ($user_ID > 0) {
         if (!isset($_SESSION['wpsc_checkout_saved_values'])) {
             $_SESSION['wpsc_checkout_saved_values'] = get_user_meta($user_ID, 'wpshpcrt_usr_profile', 1);
         }
         $delivery_country_id = wpsc_get_country_form_id_by_type('delivery_country');
         $billing_country_id = wpsc_get_country_form_id_by_type('country');
     }
     $saved_form_data = @htmlentities(stripslashes((string) $_SESSION['wpsc_checkout_saved_values'][$this->checkout_item->id]), ENT_QUOTES, 'UTF-8');
     $an_array = '';
     if (function_exists('wpsc_get_ticket_checkout_set')) {
         if ($this->checkout_item->checkout_set == wpsc_get_ticket_checkout_set()) {
             $an_array = '[]';
         }
     }
     switch ($this->checkout_item->type) {
         case "address":
         case "delivery_address":
         case "textarea":
             $output = "<textarea title='" . $this->checkout_item->unique_name . "' class='text' id='" . $this->form_element_id() . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' rows='3' cols='40' >" . $saved_form_data . "</textarea>";
             break;
         case "checkbox":
             $options = $this->get_checkout_options($this->checkout_item->id);
             if ($options != '') {
                 $i = mt_rand();
                 foreach ($options as $label => $value) {
                     $output .= "<input type='hidden' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . "' value='-1' name='collected_data[{$this->checkout_item->id}][" . $i . "]'/><input type='checkbox' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . "' value='" . esc_attr($value) . "' name='collected_data[{$this->checkout_item->id}][" . $i . "]'/> ";
                     $output .= "<label for='" . $this->form_element_id() . "'>" . $label . "</label>";
                 }
             }
             break;
         case "country":
             $output = wpsc_country_region_list($this->checkout_item->id, false, $_SESSION['wpsc_selected_country'], $_SESSION['wpsc_selected_region'], $this->form_element_id());
             break;
         case "delivery_country":
             if (wpsc_uses_shipping()) {
                 $country_name = $wpdb->get_var("SELECT `country` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`='" . $_SESSION['wpsc_delivery_country'] . "' LIMIT 1");
                 $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_country' name='collected_data[{$this->checkout_item->id}]' value='" . esc_attr($_SESSION['wpsc_delivery_country']) . "' size='4' /><span class='shipping_country_name'>" . $country_name . "</span> ";
             } else {
                 $checkoutfields = true;
                 $output = wpsc_country_region_list($this->checkout_item->id, false, $_SESSION['wpsc_delivery_country'], $_SESSION['wpsc_delivery_region'], $this->form_element_id(), $checkoutfields);
             }
             break;
         case "select":
             $options = $this->get_checkout_options($this->checkout_item->id);
             if ($options != '') {
                 $output = "<select name='collected_data[{$this->checkout_item->id}]" . $an_array . "'>";
                 $output .= "<option value='-1'>Select an Option</option>";
                 foreach ((array) $options as $label => $value) {
                     $value = esc_attr(str_replace(' ', '', $value));
                     $output .= "<option value='" . esc_attr($value) . "'>" . esc_html($label) . "</option>\n\r";
                 }
                 $output .= "</select>";
             }
             break;
         case "radio":
             $options = $this->get_checkout_options($this->checkout_item->id);
             if ($options != '') {
                 $i = mt_rand();
                 foreach ((array) $options as $label => $value) {
                     $output .= "<input type='radio' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . "'value='" . esc_attr($value) . "' name='collected_data[{$this->checkout_item->id}][" . $i . "]'/> ";
                     $output .= "<label for='" . $this->form_element_id() . "'>" . $label . "</label>";
                 }
             }
             break;
         case "text":
         case "city":
         case "delivery_city":
         case "email":
         case "coupon":
         default:
             if ($this->checkout_item->unique_name == 'shippingstate') {
                 if (wpsc_uses_shipping() && wpsc_has_regions($_SESSION['wpsc_delivery_country'])) {
                     $region_name = $wpdb->get_var("SELECT `name` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id`='" . $_SESSION['wpsc_delivery_region'] . "' LIMIT 1");
                     $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_region' name='collected_data[{$this->checkout_item->id}]' value='" . $_SESSION['wpsc_delivery_region'] . "' size='4' /><span class='shipping_region_name'>" . $region_name . "</span> ";
                 } else {
                     $disabled = '';
                     if (wpsc_disregard_shipping_state_fields()) {
                         $disabled = 'disabled = "disabled"';
                     }
                     $output = "<input class='shipping_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />";
                 }
             } elseif ($this->checkout_item->unique_name == 'billingstate') {
                 if (wpsc_uses_shipping() && wpsc_has_regions($_SESSION['wpsc_selected_country'])) {
                     $output = '';
                 } else {
                     $disabled = '';
                     if (wpsc_disregard_billing_state_fields()) {
                         $disabled = 'disabled = "disabled"';
                     }
                     $output = "<input class='billing_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />";
                 }
             } else {
                 $output = "<input title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' class='text' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' />";
             }
             break;
     }
     return $output;
 }
Example #6
0
/**
 * wpsc buy now button code products function
 * Sorry about the ugly code, this is just to get the functionality back, buy now will soon be overhauled, and this function will then be completely different
 * @return string - html displaying one or more products
 */
function wpsc_buy_now_button($product_id, $replaced_shortcode = false)
{
    $product_id = absint($product_id);
    $product = get_post($product_id);
    $supported_gateways = array('wpsc_merchant_paypal_standard', 'paypal_multiple');
    $selected_gateways = get_option('custom_gateway_options');
    if ($replaced_shortcode) {
        ob_start();
    }
    if (in_array('wpsc_merchant_paypal_standard', (array) $selected_gateways)) {
        if ($product_id > 0) {
            $post_meta = get_post_meta($product_id, '_wpsc_product_metadata', true);
            $shipping = isset($post_meta['shipping']) ? $post_meta['shipping']['local'] : '';
            $price = get_post_meta($product_id, '_wpsc_price', true);
            $special_price = get_post_meta($product_id, '_wpsc_special_price', true);
            if ($special_price) {
                $price = $special_price;
            }
            if (wpsc_uses_shipping()) {
                $handling = get_option('base_local_shipping');
            } else {
                $handling = $shipping;
            }
            $has_variants = wpsc_product_has_variations($product_id);
            $src = apply_filters('wpsc_buy_now_button_src', _x('https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wpsc'));
            $classes = apply_filters('wpsc_buy_now_button_class', "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}");
            $classes_array = array_map('sanitize_html_class', explode(' ', $classes));
            $classes = implode(' ', $classes_array);
            $button_html = sprintf('<input%1$s class="wpsc-buy-now-button wpsc-buy-now-button-%2$s" type="image" name="submit" border="0" src="%3$s" alt="%4$s" />', disabled($has_variants, true, false), esc_attr($product_id), esc_url($src), esc_attr__('PayPal - The safer, easier way to pay online', 'wpsc'));
            $button_html = apply_filters('wpsc_buy_now_button_html', $button_html, $product_id);
            ?>
			<form class="<?php 
            echo $classes;
            ?>
" id="buy-now-product_<?php 
            echo $product_id;
            ?>
" target="paypal" action="<?php 
            echo esc_url(home_url());
            ?>
" method="post">
				<input type="hidden" name="wpsc_buy_now_callback" value="1" />
				<input type="hidden" name="product_id" value="<?php 
            echo esc_attr($product_id);
            ?>
" />
<?php 
            if ($has_variants) {
                // grab the variation form fields here
                $wpsc_variations = new wpsc_variations($product_id);
                while (wpsc_have_variation_groups()) {
                    wpsc_the_variation_group();
                    printf('<input type="hidden" class="variation-value" name="variation[%1$d]" id="%2$s" value="0"/>', wpsc_vargrp_id(), wpsc_vargrp_form_id());
                }
            }
            /* END wpsc_product_has_variations */
            ?>
				<?php 
            if (get_option('multi_add')) {
                ?>
					<label for="quantity"><?php 
                esc_html_e('Quantity', 'wpsc');
                ?>
</label>
					<input type="text" size="4" id="quantity" name="quantity" value="" /><br />
				<?php 
            } else {
                ?>
					<input type="hidden" name="quantity" value="1" />
				<?php 
            }
            ?>
				<?php 
            echo $button_html;
            ?>
				<img alt='' border='0' width='1' height='1' src='<?php 
            echo esc_url(_x('https://www.paypal.com/en_US/i/scr/pixel.gif', 'PayPal Pixel', 'wpsc'));
            ?>
' />
			</form>
			<?php 
        }
    }
    if ($replaced_shortcode) {
        return ob_get_clean();
    }
}
Example #7
0
 /**
  * calculate_total_shipping method, gets the shipping option from the selected method and associated quotes
  * @access public
  * @return float returns the shipping as a floating point value
  */
 function calculate_total_shipping()
 {
     if (!(get_option('shipping_discount') == 1 && get_option('shipping_discount_value') <= $this->calculate_subtotal()) && wpsc_uses_shipping()) {
         $total = $this->calculate_base_shipping();
         $total += $this->calculate_per_item_shipping();
     } else {
         $total = 0;
     }
     return $total;
 }
					<?php 
    $args = array('remember' => false, 'redirect' => get_option('shopping_cart_url'));
    wp_login_form($args);
    ?>
					<div class="wpsc_signup_text"><?php 
    _e('If you have bought from us before, please sign in here to purchase.', 'wp-e-commerce');
    ?>
</div>
				</fieldset>
			</div>
	<?php 
}
?>
   <table class='wpsc_checkout_table wpsc_checkout_table_totals'>
      <?php 
if (wpsc_uses_shipping()) {
    ?>
	      <tr class="total_price total_shipping">
	         <td class='wpsc_totals'>
	            <?php 
    _e('Total Shipping:', 'wp-e-commerce');
    ?>
	         </td>
	         <td class='wpsc_totals'>
	            <span id="checkout_shipping" class="pricedisplay checkout-shipping"><?php 
    echo wpsc_cart_shipping();
    ?>
</span>
	         </td>
	      </tr>
      <?php 
Example #9
0
/**
 * disregard state fields - checks to see whether selected country has regions or not,
 * depending on the scenario will return wither a true or false
 * @access public
 *
 * @since 3.8
 * @return (boolean) true or false
 */
function wpsc_disregard_shipping_state_fields()
{
    global $wpsc_checkout;
    if (!wpsc_uses_shipping()) {
        $delivery_country = wpsc_get_customer_meta('shipping_country');
        if ('shippingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions($delivery_country)) {
            return true;
        } else {
            return false;
        }
    } elseif ('billingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions(wpsc_get_customer_meta('billingcountry'))) {
        return true;
    }
    return false;
}
 private function init_shipping_calculator()
 {
     if (!wpsc_uses_shipping()) {
         return;
     }
     $current_log_id = $this->get_purchase_log();
     require_once WPSC_TE_V2_CLASSES_PATH . '/shipping-calculator.php';
     $this->shipping_calculator = new WPSC_Shipping_Calculator($current_log_id);
 }
/**
 * wpsc buy now button code products function
 * Sorry about the ugly code, this is just to get the functionality back, buy now will soon be overhauled, and this function will then be completely different
 * @return string - html displaying one or more products
 */
function wpsc_buy_now_button($product_id, $replaced_shortcode = false)
{
    $product = get_post($product_id);
    $supported_gateways = array('wpsc_merchant_paypal_standard', 'paypal_multiple');
    $selected_gateways = get_option('custom_gateway_options');
    if ($replaced_shortcode) {
        ob_start();
    }
    if (in_array('wpsc_merchant_paypal_standard', (array) $selected_gateways)) {
        if ($product_id > 0) {
            $post_meta = get_post_meta($product_id, '_wpsc_product_metadata', true);
            $shipping = isset($post_meta['shipping']) ? $post_meta['shipping']['local'] : '';
            $price = get_post_meta($product_id, '_wpsc_price', true);
            $special_price = get_post_meta($product_id, '_wpsc_special_price', true);
            if ($special_price) {
                $price = $special_price;
            }
            if (wpsc_uses_shipping()) {
                $handling = get_option('base_local_shipping');
            } else {
                $handling = $shipping;
            }
            $src = _x('https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wpsc');
            $src = apply_filters('wpsc_buy_now_button_src', $src);
            $classes = "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}";
            $button_html = '<input class="wpsc-buy-now-button wpsc-buy-now-button-' . esc_attr($product_id) . '" type="image" name="submit" border="0" src=' . esc_url($src) . ' alt="' . esc_attr('PayPal - The safer, easier way to pay online', 'wpsc') . '" />';
            $button_html = apply_filters('wpsc_buy_now_button_html', $button_html, $product_id);
            ?>
			<form class="<?php 
            echo esc_attr($classes);
            ?>
" target="paypal" action="<?php 
            echo esc_url(home_url());
            ?>
" method="post">
				<input type="hidden" name="wpsc_buy_now_callback" value="1" />
				<input type="hidden" name="product_id" value="<?php 
            echo esc_attr($product_id);
            ?>
" />
				<?php 
            if (get_option('multi_add')) {
                ?>
					<label for="quantity"><?php 
                esc_html_e('Quantity', 'wpsc');
                ?>
</label>
					<input type="text" size="4" id="quantity" name="quantity" value="" /><br />
				<?php 
            } else {
                ?>
					<input type="hidden" name="quantity" value="1" />
				<?php 
            }
            ?>
				<?php 
            echo $button_html;
            ?>
				<img alt='' border='0' width='1' height='1' src='<?php 
            echo esc_url(_x('https://www.paypal.com/en_US/i/scr/pixel.gif', 'PayPal Pixel', 'wpsc'));
            ?>
' />
			</form>
			<?php 
        }
    }
    if ($replaced_shortcode) {
        return ob_get_clean();
    }
}
/**
 * transaction_results function main function for creating the purchase reports, transaction results page, and email receipts
 * @access public
 *
 * @since 3.7
 * @param $sessionid (string) unique session id
 * @param echo_to_screen (boolean) whether to output the results or return them (potentially redundant)
 * @param $transaction_id (int) the transaction id
 */
function transaction_results($sessionid, $display_to_screen = true, $transaction_id = null)
{
    // Do we seriously need this many globals?
    global $wpdb, $wpsc_cart, $echo_to_screen, $purchase_log, $order_url;
    global $message_html, $cart, $errorcode, $wpsc_purchlog_statuses, $wpsc_gateways;
    $wpec_taxes_controller = new wpec_taxes_controller();
    $is_transaction = false;
    $errorcode = 0;
    $purchase_log = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= %s LIMIT 1", $sessionid), ARRAY_A);
    $order_status = $purchase_log['processed'];
    $curgateway = $purchase_log['gateway'];
    if (!is_bool($display_to_screen)) {
        $display_to_screen = true;
    }
    $echo_to_screen = $display_to_screen;
    //new variable to check whether function is being called from wpsc_purchlog_resend_email()
    $resend_email = isset($_REQUEST['email_buyer_id']) ? true : false;
    if (is_numeric($sessionid)) {
        if ($echo_to_screen) {
            echo apply_filters('wpsc_pre_transaction_results', '');
        }
        // New code to check whether transaction is processed, true if accepted false if pending or incomplete
        $is_transaction = wpsc_check_purchase_processed($purchase_log['processed']);
        $message_html = $message = stripslashes(get_option('wpsc_email_receipt'));
        if ($is_transaction) {
            $message = __('The Transaction was successful', 'wpsc') . "\r\n" . $message;
            $message_html = __('The Transaction was successful', 'wpsc') . "<br />" . $message_html;
        }
        $country = get_option('country_form_field');
        $billing_country = '';
        $shipping_country = '';
        if (!empty($purchase_log['shipping_country'])) {
            $billing_country = $purchase_log['billing_country'];
            $shipping_country = $purchase_log['shipping_country'];
        } elseif (!empty($country)) {
            $country = $wpdb->get_var($wpdb->prepare("SELECT `value` FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = %d AND `form_id` = %d LIMIT 1", $purchase_log['id'], get_option('country_form_field')));
            $billing_country = $country;
            $shipping_country = $country;
        }
        $email = wpsc_get_buyers_email($purchase_log['id']);
        $previous_download_ids = array();
        $product_list = $product_list_html = $report_product_list = '';
        $cart = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid` = %d", $purchase_log['id']), ARRAY_A);
        if ($cart != null && $errorcode == 0) {
            $total_shipping = '';
            foreach ($cart as $row) {
                $link = array();
                $wpdb->update(WPSC_TABLE_DOWNLOAD_STATUS, array('active' => '1'), array('cartid' => $row['id'], 'purchid' => $purchase_log['id']));
                do_action('wpsc_transaction_result_cart_item', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log));
                if ($is_transaction) {
                    $download_data = $wpdb->get_results($wpdb->prepare("SELECT *\n\t\t\t\t\tFROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "`\n\t\t\t\t\tWHERE `active`='1'\n\t\t\t\t\tAND `purchid` = %d\n\t\t\t\t\tAND `cartid` = %d", $purchase_log['id'], $row['id']), ARRAY_A);
                    if (count($download_data) > 0) {
                        foreach ($download_data as $single_download) {
                            $file_data = get_post($single_download['product_id']);
                            // if the uniqueid is not equal to null, its "valid", regardless of what it is
                            $argsdl = array('post_type' => 'wpsc-product-file', 'post_parent' => $single_download['product_id'], 'numberposts' => -1, 'post_status' => 'all');
                            $download_file_posts = (array) get_posts($argsdl);
                            foreach ((array) $download_file_posts as $single_file_post) {
                                if ($single_file_post->ID == $single_download['fileid']) {
                                    $current_Dl_product_file_post = $single_file_post;
                                    break;
                                }
                            }
                            $file_name = $current_Dl_product_file_post->post_title;
                            if ($single_download['uniqueid'] == null) {
                                $link[] = array("url" => site_url("?downloadid=" . $single_download['id']), "name" => $file_name);
                            } else {
                                $link[] = array("url" => site_url("?downloadid=" . $single_download['uniqueid']), "name" => $file_name);
                            }
                        }
                    } else {
                        $order_status = $purchase_log['processed'];
                    }
                    if (isset($download_data['id'])) {
                        $previous_download_ids[] = $download_data['id'];
                    }
                }
                do_action('wpsc_confirm_checkout', $purchase_log['id']);
                $total = 0;
                $shipping = $row['pnp'];
                $total_shipping += $shipping;
                $total += $row['price'] * $row['quantity'];
                $message_price = wpsc_currency_display($total, array('display_as_html' => false));
                $message_price_html = wpsc_currency_display($total);
                $shipping_price = wpsc_currency_display($shipping, array('display_as_html' => false));
                if (isset($purchase['gateway']) && 'wpsc_merchant_testmode' != $purchase['gateway']) {
                    if ($gateway['internalname'] == $purch_data[0]['gateway']) {
                        $gateway_name = $gateway['name'];
                    }
                } else {
                    $gateway_name = "Manual Payment";
                }
                $variation_list = '';
                if (!empty($link)) {
                    $additional_content = apply_filters('wpsc_transaction_result_content', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log));
                    if (!is_string($additional_content)) {
                        $additional_content = '';
                    }
                    $product_list .= " - " . $row['name'] . "  " . $message_price . " " . __('Click to download', 'wpsc') . ":";
                    $product_list_html .= " - " . $row['name'] . "  " . $message_price_html . "&nbsp;&nbsp;" . __('Click to download', 'wpsc') . ":\n\r";
                    foreach ($link as $single_link) {
                        $product_list .= "\n\r " . $single_link["name"] . ": " . $single_link["url"] . "\n\r";
                        $product_list_html .= "<a href='" . $single_link["url"] . "'>" . $single_link["name"] . "</a>\n";
                    }
                    $product_list .= $additional_content;
                    $product_list_html .= $additional_content;
                } else {
                    $product_list .= " - " . $row['quantity'] . " " . $row['name'] . "  " . $message_price . "\n\r";
                    if ($shipping > 0) {
                        $product_list .= sprintf(__(' - Shipping: %s
', 'wpsc'), $shipping_price);
                    }
                    $product_list_html .= "\n\r - " . $row['quantity'] . " " . $row['name'] . "  " . $message_price_html . "\n\r";
                    if ($shipping > 0) {
                        $product_list_html .= sprintf(__(' &nbsp; Shipping: %s
', 'wpsc'), $shipping_price);
                    }
                }
                //add tax if included
                if ($wpec_taxes_controller->wpec_taxes_isenabled() && $wpec_taxes_controller->wpec_taxes_isincluded()) {
                    $taxes_text = ' - - ' . __('Tax Included', 'wpsc') . ': ' . wpsc_currency_display($row['tax_charged'], array('display_as_html' => false)) . "\n\r";
                    $taxes_text_html = ' - - ' . __('Tax Included', 'wpsc') . ': ' . wpsc_currency_display($row['tax_charged']);
                    $product_list .= $taxes_text;
                    $product_list_html .= $taxes_text_html;
                }
                // if
                $report = get_option('wpsc_email_admin');
                $report_product_list .= " - " . $row['quantity'] . " " . $row['name'] . "  " . $message_price . "\n\r";
            }
            // closes foreach cart as row
            // Decrement the stock here
            if ($is_transaction) {
                wpsc_decrement_claimed_stock($purchase_log['id']);
            }
            if (!empty($purchase_log['discount_data'])) {
                $coupon_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE coupon_code = %s LIMIT 1", $purchase_log['discount_data']), ARRAY_A);
                if ($coupon_data['use-once'] == 1) {
                    $wpdb->update(WPSC_TABLE_COUPON_CODES, array('active' => '0', 'is-used' => '1'), array('id' => $coupon_data['id']));
                }
            }
            $total_shipping = wpsc_get_total_shipping($purchase_log['id']);
            $total = $purchase_log['totalprice'];
            $total_price_email = '';
            $total_price_html = '';
            $total_tax_html = '';
            $total_tax = '';
            $total_shipping_html = '';
            $total_shipping_email = '';
            if (wpsc_uses_shipping() || !empty($purchase_log['base_shipping'])) {
                $total_shipping_email .= sprintf(__('Total Shipping: %s
	', 'wpsc'), wpsc_currency_display($total_shipping, array('display_as_html' => false)));
            }
            $total_price_email .= sprintf(__('Total: %s
', 'wpsc'), wpsc_currency_display($total, array('display_as_html' => false)));
            if ($purchase_log['discount_value'] > 0) {
                $discount_email = __('Discount', 'wpsc') . "\n\r: ";
                $discount_email .= $purchase_log['discount_data'] . ' : ' . wpsc_currency_display($purchase_log['discount_value'], array('display_as_html' => false)) . "\n\r";
                $report .= $discount_email . "\n\r";
                $total_shipping_email .= $discount_email;
                $total_shipping_html .= __('Discount', 'wpsc') . ": " . wpsc_currency_display($purchase_log['discount_value']) . "\n\r";
            }
            //only show total tax if tax is not included
            if ($wpec_taxes_controller->wpec_taxes_isenabled() && !$wpec_taxes_controller->wpec_taxes_isincluded()) {
                $total_tax_html .= __('Total Tax', 'wpsc') . ': ' . wpsc_currency_display($purchase_log['wpec_taxes_total']) . "\n\r";
                $total_tax .= __('Total Tax', 'wpsc') . ': ' . wpsc_currency_display($purchase_log['wpec_taxes_total'], array('display_as_html' => false)) . "\n\r";
            }
            if (wpsc_uses_shipping() || !empty($purchase_log['base_shipping'])) {
                $total_shipping_html .= '<hr>' . sprintf(__('Total Shipping: %s
	', 'wpsc'), wpsc_currency_display($total_shipping));
            }
            $total_price_html .= sprintf(__('Total: %s
', 'wpsc'), wpsc_currency_display($total));
            $report_id = sprintf(__("Purchase # %s\n", 'wpsc'), $purchase_log['id']);
            if (isset($_GET['ti'])) {
                $message .= "\n\r" . __('Your Transaction ID', 'wpsc') . ": " . $_GET['ti'];
                $message_html .= "\n\r" . __('Your Transaction ID', 'wpsc') . ": " . $_GET['ti'];
                $report .= "\n\r" . __('Transaction ID', 'wpsc') . ": " . $_GET['ti'];
            }
            $message = apply_filters('wpsc_transaction_result_message', $message);
            $message = str_replace('%purchase_id%', $report_id, $message);
            $message = str_replace('%product_list%', $product_list, $message);
            $message = str_replace('%total_tax%', $total_tax, $message);
            $message = str_replace('%total_shipping%', $total_shipping_email, $message);
            $message = str_replace('%total_price%', $total_price_email, $message);
            $message = str_replace('%shop_name%', get_option('blogname'), $message);
            $message = str_replace('%find_us%', $purchase_log['find_us'], $message);
            $report = apply_filters('wpsc_transaction_result_report', $report);
            $report = str_replace('%purchase_id%', $report_id, $report);
            $report = str_replace('%product_list%', $report_product_list, $report);
            $report = str_replace('%total_tax%', $total_tax, $report);
            $report = str_replace('%total_shipping%', $total_shipping_email, $report);
            $report = str_replace('%total_price%', $total_price_email, $report);
            $report = str_replace('%shop_name%', get_option('blogname'), $report);
            $report = str_replace('%find_us%', $purchase_log['find_us'], $report);
            $message_html = apply_filters('wpsc_transaction_result_message_html', $message_html);
            $message_html = str_replace('%purchase_id%', $report_id, $message_html);
            $message_html = str_replace('%product_list%', $product_list_html, $message_html);
            $message_html = str_replace('%total_tax%', $total_tax_html, $message_html);
            $message_html = str_replace('%total_shipping%', $total_shipping_html, $message_html);
            $message_html = str_replace('%total_price%', $total_price_html, $message_html);
            $message_html = str_replace('%shop_name%', get_option('blogname'), $message_html);
            $message_html = str_replace('%find_us%', $purchase_log['find_us'], $message_html);
            if (!empty($email)) {
                add_filter('wp_mail_from', 'wpsc_replace_reply_address', 0);
                add_filter('wp_mail_from_name', 'wpsc_replace_reply_name', 0);
                $message = apply_filters('wpsc_email_message', $message, $report_id, $product_list, $total_tax, $total_shipping_email, $total_price_email);
                if (!$is_transaction) {
                    $payment_instructions = strip_tags(stripslashes(get_option('payment_instructions')));
                    if (!empty($payment_instructions)) {
                        $payment_instructions .= "\n\r";
                    }
                    $message = __('Thank you, your purchase is pending, you will be sent an email once the order clears.', 'wpsc') . "\n\r" . $payment_instructions . $message;
                    $message_html = __('Thank you, your purchase is pending, you will be sent an email once the order clears.', 'wpsc') . "\n\r" . $payment_instructions . $message_html;
                    // prevent email duplicates
                    if (!get_transient("{$sessionid}_pending_email_sent") || $resend_email) {
                        wp_mail($email, __('Order Pending: Payment Required', 'wpsc'), $message);
                        set_transient("{$sessionid}_pending_email_sent", true, 60 * 60 * 12);
                    }
                } elseif (!get_transient("{$sessionid}_receipt_email_sent") || $resend_email) {
                    wp_mail($email, __('Purchase Receipt', 'wpsc'), $message);
                    set_transient("{$sessionid}_receipt_email_sent", true, 60 * 60 * 12);
                }
            }
            remove_filter('wp_mail_from_name', 'wpsc_replace_reply_name');
            remove_filter('wp_mail_from', 'wpsc_replace_reply_address');
            $report_user = __('Customer Details', 'wpsc') . "\n\r";
            $form_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = %d", $purchase_log['id']);
            $form_data = $wpdb->get_results($form_sql, ARRAY_A);
            if ($form_data != null) {
                foreach ($form_data as $form_field) {
                    $form_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `id` = %d LIMIT 1", $form_field['form_id']), ARRAY_A);
                    switch ($form_data['type']) {
                        case "country":
                            $country_code = $form_field['value'];
                            $report_user .= $form_data['name'] . ": " . wpsc_get_country($country_code) . "\n";
                            //check if country has a state then display if it does.
                            $country_data = wpsc_country_has_state($country_code);
                            if ($country_data['has_regions'] == 1) {
                                $report_user .= __('Billing State', 'wpsc') . ": " . wpsc_get_region($purchase_log['billing_region']) . "\n";
                            }
                            break;
                        case "delivery_country":
                            $report_user .= $form_data['name'] . ": " . wpsc_get_country($form_field['value']) . "\n";
                            break;
                        default:
                            if ($form_data['name'] == 'State' && is_numeric($form_field['value'])) {
                                $report_user .= __('Delivery State', 'wpsc') . ": " . wpsc_get_state_by_id($form_field['value'], 'name') . "\n";
                            } else {
                                $report_user .= wp_kses($form_data['name'], array()) . ": " . $form_field['value'] . "\n";
                            }
                            break;
                    }
                }
            }
            $report_user .= "\n\r";
            $report = $report_id . $report_user . $report;
            //echo '======REPORT======<br />'.$report.'<br />';
            //echo '======EMAIL======<br />'.$message.'<br />';
            if (get_option('purch_log_email') != null && $purchase_log['email_sent'] != 1) {
                wp_mail(get_option('purch_log_email'), __('Purchase Report', 'wpsc'), $report);
                $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('email_sent' => '1'), array('sessionid' => $sessionid));
            }
            /// Adjust stock and empty the cart
            $wpsc_cart->submit_stock_claims($purchase_log['id']);
            $wpsc_cart->empty_cart();
        }
    }
}
Example #13
0
function gateway_authorize($seperator, $sessionid)
{
    global $wpdb, $wpsc_cart;
    $purchase_log_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1";
    $purchase_log = $wpdb->get_row($purchase_log_sql, ARRAY_A);
    $cart_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='" . $purchase_log['id'] . "'";
    $cart = $wpdb->get_results($cart_sql, ARRAY_A);
    $prodid = $cart[0]['prodid'];
    $product_sql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`='" . $prodid . "'";
    $product_data = $wpdb->get_results($product_sql, ARRAY_A);
    $status = get_product_meta($prodid, 'is_membership', true);
    $free_trial = get_product_meta($prodid, 'free_trial', true);
    if ($status[0] == 1 && function_exists('wpsc_members_init')) {
        $membership_length = get_product_meta($prodid, 'membership_length', true);
        $membership_length = $membership_length[0];
        $length = $membership_length['length'];
        $unit = $membership_length['unit'];
        if ($unit == 'd') {
            $unit = 'days';
        } elseif ($unit == 'm') {
            $unit = 'months';
        }
        $amount = nzshpcrt_overall_total_price($_SESSION['selected_country']);
        $loginname = get_option('authorize_login');
        $transactionkey = get_option("authorize_password");
        $firstName = $_POST['collected_data'][get_option('authorize_form_first_name')];
        $lastName = $_POST['collected_data'][get_option('authorize_form_last_name')];
        $cardNumber = $_POST['card_number'];
        $expirationDate = "20" . $_POST['expiry']['year'] . "-" . $_POST['expiry']['month'];
        $cardCode = $_POST['card_code'];
        $startDate = date('Y-m-d');
        $totalOccurrences = 99;
        $trialOccurrences = 1;
        $amount = $product_data[0]['price'];
        $trialAmount = 0;
        $xml = "<?xml version='1.0' encoding='utf-8' ?>" . "<ARBCreateSubscriptionRequest xmlns='AnetApi/xml/v1/schema/AnetApiSchema.xsd'>" . "<merchantAuthentication>" . "<name>" . $loginname . "</name>" . "<transactionKey>" . $transactionkey . "</transactionKey>" . "</merchantAuthentication>" . "<refId>Instinct</refId>" . "<subscription>" . "<name>Samplesubscription</name>" . "<paymentSchedule>" . "<interval>" . "<length>" . $length . "</length>" . "<unit>" . $unit . "</unit>" . "</interval>" . "<startDate>" . $startDate . "</startDate>" . "<totalOccurrences>" . $totalOccurrences . "</totalOccurrences>" . "<trialOccurrences>" . $trialOccurrences . "</trialOccurrences>" . "</paymentSchedule>" . "<amount>" . $amount . "</amount>" . "<trialAmount>" . $trialAmount . "</trialAmount>" . "<payment>" . "<creditCard>" . "<cardNumber>" . $cardNumber . "</cardNumber>" . "<expirationDate>" . $expirationDate . "</expirationDate>" . "<cardCode>" . $cardCode . "</cardCode>" . "</creditCard>" . "</payment>" . "<billTo>" . "<firstName>" . $firstName . "</firstName>" . "<lastName>" . $lastName . "</lastName>" . "</billTo>" . "</subscription>" . "</ARBCreateSubscriptionRequest>";
        //  	exit("<pre>".print_r($xml,1)."</pre>");
        //Send the XML via curl
        $response = send_request_via_curl($host, $path, $xml);
        //If curl is unavilable you can try using fsockopen
        /*
        $response = send_request_via_fsockopen($host,$path,$content);
        */
        //If the connection and send worked $response holds the return from Authorize.Net
        if ($response) {
            list($refId, $resultCode, $code, $text, $subscriptionId) = parse_return($response);
            if ($code == 'I00001') {
                $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed` = '2' WHERE `sessionid` = " . $sessionid . " LIMIT 1");
                $results = $wpdb->get_results("select * from `" . WPSC_TABLE_LOGGED_SUBSCRIPTIONS . "` where cart_id=" . $cart[0]['id'] . "", ARRAY_A);
                $sub_id = $results[0]['id'];
                wpsc_member_activate_subscriptions($sub_id);
                header("Location: " . get_option('transact_url') . $seperator . "sessionid=" . $sessionid);
            } else {
                echo " refId: {$refId}<br>";
                echo " resultCode: {$resultCode} <br>";
                echo " code: {$code}<br>";
                echo " text: {$text}<br>";
                echo " subscriptionId: {$subscriptionId} <br><br>";
            }
        } else {
            echo "send failed <br>";
        }
        //Dump the response to the screen for debugging
        //echo "<xmp>$response</xmp>";  //Display response SOAP
        exit('');
    }
    if ($purchase_log['shipping_country'] != null) {
        $shipping_country = $purchase_log['shipping_country'];
    }
    if ($purchase_log['shipping_region'] != null) {
        $shipping_region = $purchase_log['shipping_region'];
    } else {
        $shipping_region = 0;
    }
    if ($purchase_log['billing_country'] != null) {
        $billing_country = $purchase_log['billing_country'];
    }
    if ($purchase_log['billing_region'] != null) {
        $billing_region = $purchase_log['billing_region'];
        $billing_region = $wpdb->get_var("SELECT code FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE id='" . $billing_region . "'");
    } else {
        $billing_region = 0;
    }
    $authorize_data = array();
    $authorize_data['x_Version'] = "3.1";
    $authorize_data['x_Login'] = urlencode(get_option('authorize_login'));
    $authorize_data['x_Password'] = urlencode(get_option("authorize_password"));
    $authorize_data['x_Delim_Data'] = urlencode("TRUE");
    $authorize_data['x_Delim_Char'] = urlencode(",");
    $authorize_data['x_Encap_Char'] = urlencode("");
    $authorize_data['x_Type'] = urlencode("AUTH_CAPTURE");
    $authorize_data['x_ADC_Relay_Response'] = urlencode("FALSE");
    if (get_option('authorize_testmode') == 1) {
        $authorize_data['x_Test_Request'] = urlencode("TRUE");
    }
    $authorize_data['x_Method'] = urlencode("CC");
    $authorize_data['x_Amount'] = number_format(nzshpcrt_overall_total_price($_SESSION['delivery_country'], false, false), 2);
    $authorize_data['x_First_Name'] = urlencode($_POST['collected_data'][get_option('authorize_form_first_name')]);
    $authorize_data['x_Last_Name'] = urlencode($_POST['collected_data'][get_option('authorize_form_last_name')]);
    $authorize_data['x_Card_Num'] = urlencode($_POST['card_number']);
    $authorize_data['x_Exp_Date'] = urlencode($_POST['expiry']['month'] . $_POST['expiry']['year']);
    $authorize_data['x_Card_Code'] = urlencode($_POST['card_code']);
    $authorize_data['x_Address'] = urlencode($_POST['collected_data'][get_option('authorize_form_address')]);
    $authorize_data['x_City'] = urlencode($_POST['collected_data'][get_option('authorize_form_city')]);
    $authorize_data['x_Zip'] = urlencode($_POST['collected_data'][get_option('authorize_form_post_code')]);
    $authorize_data['x_State'] = urlencode($billing_region);
    $authorize_data['x_Country'] = urlencode($billing_country);
    $authorize_data['x_Phone'] = urlencode($_POST['collected_data'][get_option('authorize_form_phone')]);
    $authorize_data['x_Email'] = urlencode($_POST['collected_data'][get_option('authorize_form_email')]);
    $authorize_data['x_Email_Customer'] = urlencode("TRUE");
    $authorize_data['x_Merchant_Email'] = urlencode(get_option('purch_log_email'));
    // MY ADDITIONS HERE
    $authorize_data['x_Description'] = urlencode(get_option('authorize_form_description'));
    $authorize_data['x_invoice_num'] = $cart[0]['purchaseid'];
    $authorize_data['x_cust_id'] = $cart[0]['purchaseid'];
    $setstate = $_POST['collected_data'][get_option('authorize_form_country')][1];
    $setstate = $wpdb->get_var("SELECT code FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE id='" . $setstate . "'");
    //  $authorize_data['x_State'] = urlencode($setstate);
    $setcountry = $_POST['collected_data'][get_option('authorize_form_country')][0];
    //  $authorize_data['x_Country'] = urlencode($setcountry);
    $authorize_data['x_ship_to_First_Name'] = urlencode($_POST['collected_data'][get_option('authorize_form_ship_first_name')]);
    $authorize_data['x_ship_to_Last_Name'] = urlencode($_POST['collected_data'][get_option('authorize_form_ship_last_name')]);
    $authorize_data['x_ship_to_Address'] = urlencode($_POST['collected_data'][get_option('authorize_form_ship_address')]);
    $authorize_data['x_ship_to_City'] = urlencode($_POST['collected_data'][get_option('authorize_form_ship_city')]);
    $authorize_data['x_ship_to_Zip'] = urlencode($_POST['collected_data'][get_option('authorize_form_ship_post_code')]);
    $setstate = $_POST['collected_data'][get_option('authorize_form_ship_state')];
    $shipping_region = $wpdb->get_var("SELECT code FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE id='" . $shipping_region . "'");
    $authorize_data['x_ship_to_State'] = urlencode($shipping_region);
    //  $setcountry=$_POST['collected_data'][get_option('authorize_form_ship_country')];
    $authorize_data['x_ship_to_Country'] = urlencode($shipping_country);
    $authorize_data['x_tax'] = urlencode($wpsc_cart->total_tax);
    if (wpsc_uses_shipping()) {
        $authorize_data['x_freight'] = urlencode($wpsc_cart->selected_shipping_method . '<|>' . $wpsc_cart->selected_shipping_option . '<|>' . $wpsc_cart->base_shipping);
    }
    // Extra shopping cart data for credit card receipt
    if (isset($cart[0])) {
        foreach ($cart as $k => $v) {
            $authorize_data['item_' . $k . '_name'] = $v['name'];
            $authorize_data['item_' . $k . '_qty'] = $v['quantity'];
            $authorize_data['item_' . $k . '_price'] = $v['price'];
        }
    }
    if ($x_Password != '') {
        $authorize_data['x_Password'] = $x_Password;
    }
    #
    # Build fields string to post, nicer than the old code
    #
    $num = 0;
    foreach ($authorize_data as $key => $value) {
        if ($num > 0) {
            $fields .= "&";
        }
        $fields .= $key . "=" . $value;
        $num++;
    }
    #
    # Start CURL session
    #
    $user_agent = "WP eCommerce plugin for Wordpress";
    $referrer = get_option('transact_url');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://secure.authorize.net/gateway/transact.dll");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    curl_setopt($ch, CURLOPT_REFERER, $referrer);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $buffer = curl_exec($ch);
    curl_close($ch);
    // This section of the code is the change from Version 1.
    // This allows this script to process all information provided by Authorize.net...
    // and not just whether if the transaction was successful or not
    // Provided in the true spirit of giving by Chuck Carpenter (Chuck@MLSphotos.com)
    // Be sure to email him and tell him how much you appreciate his efforts for PHP coders everywhere
    $return = preg_split("/[,]+/", "{$buffer}");
    // Splits out the buffer return into an array so . . .
    $details = $return[0];
    // This can grab the Transaction ID at position 1 in the array
    $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `transactid` = '" . $wpdb->escape($return[18]) . "' WHERE `sessionid` = " . $sessionid . " LIMIT 1");
    // echo "Location: ".$transact_url.$seperator."sessionid=".$sessionid;
    // exit("<pre>".print_r($return,true)."</pre>");
    // Change the number to grab additional information.  Consult the AIM guidelines to see what information is provided in each position.
    // For instance, to get the Transaction ID from the returned information (in position 7)..
    // Simply add the following:
    // $x_trans_id = $return[6];
    // You may then use the switch statement (or other process) to process the information provided
    // Example below is to see if the transaction was charged successfully
    if (get_option('permalink_structure') != '') {
        $seperator = "?";
    } else {
        $seperator = "&";
    }
    switch ($details) {
        case 1:
            // Credit Card Successfully Charged
            $processing_stage = $wpdb->get_var("SELECT `processed` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` = " . $sessionid . " LIMIT 1");
            if ($processing_stage < 2) {
                $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed` = '2' WHERE `sessionid` = " . $sessionid . " LIMIT 1");
            }
            header("Location: " . get_option('transact_url') . $seperator . "sessionid=" . $sessionid);
            exit;
            break;
        default:
            // Credit Card Not Successfully Charged
            $_SESSION['wpsc_checkout_misc_error_messages'][] = "Credit Card Processing Error: " . $return[3];
            //. " ". print_r($return,true)
            header("Location: " . get_option('shopping_cart_url') . $seperator . "total=" . nzshpcrt_overall_total_price($_POST['collected_data'][get_option('country_form_field')]));
            exit;
            break;
    }
}
 /**
  * form_field method, returns the form html
  * @access public
  */
 function form_field()
 {
     global $wpdb, $user_ID;
     //		exit('<pre>'.print_r($_SESSION['wpsc_checkout_saved_values'], true).'</pre>');
     if (count($_SESSION['wpsc_checkout_saved_values']) <= 0 && $user_ID > 0) {
         //$_SESSION['wpsc_checkout_saved_values'] = get_usermeta($user_ID, 'wpshpcrt_usr_profile');
     }
     if (is_array($_SESSION['wpsc_checkout_saved_values'][$this->checkout_item->id])) {
         if (function_exists('wpsc_get_ticket_checkout_set')) {
             if ($this->checkout_item->checkout_set == wpsc_get_ticket_checkout_set()) {
                 if (!isset($_SESSION['wpsc_tickets_saved_values_count'])) {
                     $_SESSION['wpsc_tickets_saved_values_count'] = 0;
                     $count = $_SESSION['wpsc_tickets_saved_values_count'];
                 } else {
                     $count = $_SESSION['wpsc_tickets_saved_values_count'] - 1;
                 }
                 $saved_form_data = htmlentities(stripslashes($_SESSION['wpsc_checkout_saved_values'][$this->checkout_item->id][$count]), ENT_QUOTES, 'UTF-8');
             }
         }
     } else {
         $saved_form_data = htmlentities(stripslashes($_SESSION['wpsc_checkout_saved_values'][$this->checkout_item->id]), ENT_QUOTES, 'UTF-8');
     }
     //make sure tickets are arrays for multiple ticket holders
     $an_array = '';
     if (function_exists('wpsc_get_ticket_checkout_set')) {
         if ($this->checkout_item->checkout_set == wpsc_get_ticket_checkout_set()) {
             $an_array = '[]';
         }
     }
     switch ($this->checkout_item->type) {
         case "address":
         case "delivery_address":
         case "textarea":
             $output = "<textarea title='" . $this->checkout_item->unique_name . "' class='text' id='" . $this->form_element_id() . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' rows='3' cols='40' >" . $saved_form_data . "</textarea>";
             break;
         case "checkbox":
             $options = $this->get_checkout_options($this->checkout_item->id);
             if ($options != '') {
                 $i = mt_rand();
                 $j = 0;
                 foreach ($options as $label => $value) {
                     $output .= "<input type='hidden' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . $j . "' value='-1' name='collected_data[{$this->checkout_item->id}][" . $i . "][" . $j . "]'/><input type='checkbox' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . "' value='" . $value . "' name='collected_data[{$this->checkout_item->id}][" . $i . "][" . $j . "]'/> ";
                     $output .= "<label for='" . $this->form_element_id() . $j . "'>" . $label . "</label><br />";
                     $j++;
                 }
             }
             break;
         case "country":
             $output = wpsc_country_region_list($this->checkout_item->id, false, $_SESSION['wpsc_selected_country'], $_SESSION['wpsc_selected_region'], $this->form_element_id());
             break;
         case "delivery_country":
             if (wpsc_uses_shipping()) {
                 $country_name = $wpdb->get_var("SELECT `country` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`='" . $_SESSION['wpsc_delivery_country'] . "' LIMIT 1");
                 $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_country' name='collected_data[{$this->checkout_item->id}]' value='" . $_SESSION['wpsc_delivery_country'] . "' /><span class='shipping_country_name'>" . $country_name . "</span> ";
             } else {
                 $checkoutfields = true;
                 //$output = wpsc_shipping_country_list($checkoutfields);
                 $output = wpsc_country_region_list($this->checkout_item->id, false, $_SESSION['wpsc_selected_country'], $_SESSION['wpsc_selected_region'], $this->form_element_id(), $checkoutfields);
             }
             break;
         case "select":
             $options = $this->get_checkout_options($this->checkout_item->id);
             if ($options != '') {
                 $output = "<select name='collected_data[{$this->checkout_item->id}]" . $an_array . "'>";
                 $output .= "<option value='-1'>Select an Option</option>";
                 foreach ((array) $options as $label => $value) {
                     $value = str_replace(' ', '', $value);
                     if ($saved_form_data == $value) {
                         $selected = 'selected="selected"';
                     } else {
                         $selected = '';
                     }
                     $output .= "<option " . $selected . " value='" . $value . "'>" . $label . "</option>\n\r";
                 }
                 $output .= "</select>";
             }
             break;
         case "radio":
             $options = $this->get_checkout_options($this->checkout_item->id);
             if ($options != '') {
                 $i = mt_rand();
                 foreach ((array) $options as $label => $value) {
                     $output .= "<input type='radio' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . "'value='" . $value . "' name='collected_data[{$this->checkout_item->id}][" . $i . "]'/> ";
                     $output .= "<label for='" . $this->form_element_id() . "'>" . $label . "</label>";
                 }
             }
             break;
         case "text":
         case "city":
         case "delivery_city":
         case "email":
         case "coupon":
         default:
             $country_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode` IN('" . $_SESSION['wpsc_delivery_country'] . "') LIMIT 1", ARRAY_A);
             if ($this->checkout_item->unique_name == 'shippingstate') {
                 if (wpsc_uses_shipping() && $country_data['has_regions'] == 1) {
                     $region_name = $wpdb->get_var("SELECT `name` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id`='" . $_SESSION['wpsc_delivery_region'] . "' LIMIT 1");
                     $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_region' name='collected_data[{$this->checkout_item->id}]' value='" . $_SESSION['wpsc_delivery_region'] . "' size='4' /><span class='shipping_region_name'>" . $region_name . "</span> ";
                 } else {
                     $output = "<input class='shipping_region' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' class='text' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' />";
                 }
             } else {
                 $output = "<input title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' class='text' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' />";
             }
             break;
     }
     return $output;
 }
Example #15
0
 /**
  * form_field method, returns the form html
  * @access public
  */
 function form_field()
 {
     global $wpdb, $user_ID;
     if (count($_SESSION['wpsc_checkout_saved_values']) <= 0 && $user_ID > 0) {
         $_SESSION['wpsc_checkout_saved_values'] = get_usermeta($user_ID, 'wpshpcrt_usr_profile');
     }
     $saved_form_data = htmlentities(stripslashes($_SESSION['wpsc_checkout_saved_values'][$this->checkout_item->id]), ENT_QUOTES);
     switch ($this->checkout_item->type) {
         case "address":
         case "delivery_address":
         case "textarea":
             $output = "<textarea title='" . $this->checkout_item->unique_name . "' class='text' id='" . $this->form_element_id() . "' name='collected_data[{$this->checkout_item->id}]' rows='3' cols='40' >" . $saved_form_data . "</textarea>";
             break;
         case "country":
             $output = wpsc_country_region_list($this->checkout_item->id, false, $_SESSION['wpsc_selected_country'], $_SESSION['wpsc_selected_region'], $this->form_element_id());
             break;
         case "delivery_country":
             if (wpsc_uses_shipping()) {
                 $country_name = $wpdb->get_var("SELECT `country` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`='" . $_SESSION['wpsc_delivery_country'] . "' LIMIT 1");
                 $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_country' name='collected_data[{$this->checkout_item->id}]' value='" . $_SESSION['wpsc_delivery_country'] . "' size='4' /><span class='shipping_country_name'>" . $country_name . "</span> ";
             } else {
                 $checkoutfields = true;
                 //$output = wpsc_shipping_country_list($checkoutfields);
                 $output = wpsc_country_region_list($this->checkout_item->id, false, $_SESSION['wpsc_selected_country'], $_SESSION['wpsc_selected_region'], $this->form_element_id(), $checkoutfields);
             }
             break;
         case "text":
         case "city":
         case "delivery_city":
         case "email":
         case "coupon":
         default:
             $output = "<input title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' class='text' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]' />";
             break;
     }
     return $output;
 }
Example #16
0
/**
 * submit checkout function, used through ajax and in normal page loading.
 * No parameters, returns nothing
 */
function wpsc_submit_checkout()
{
    global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways;
    $num_items = 0;
    $use_shipping = 0;
    $disregard_shipping = 0;
    $_SESSION['wpsc_checkout_misc_error_messages'] = array();
    $wpsc_checkout = new wpsc_checkout();
    $selected_gateways = get_option('custom_gateway_options');
    $submitted_gateway = $_POST['custom_gateway'];
    $options = get_option('custom_shipping_options');
    $form_validity = $wpsc_checkout->validate_forms();
    extract($form_validity);
    // extracts $is_valid and $error_messages
    if ($_POST['agree'] != 'yes') {
        $_SESSION['wpsc_checkout_misc_error_messages'][] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc');
        $is_valid = false;
    }
    $selectedCountry = $wpdb->get_results("SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode='" . $wpdb->escape($_SESSION['wpsc_delivery_country']) . "'", ARRAY_A);
    foreach ($wpsc_cart->cart_items as $cartitem) {
        if ($cartitem->meta[0]['no_shipping'] == 1) {
            continue;
        }
        $categoriesIDs = $cartitem->category_id_list;
        foreach ((array) $categoriesIDs as $catid) {
            if (is_array($catid)) {
                $countries = wpsc_get_meta($catid[0], 'target_market', 'wpsc_category');
            } else {
                $countries = wpsc_get_meta($catid, 'target_market', 'wpsc_category');
            }
            if (!empty($countries) && !in_array($selectedCountry[0]['id'], (array) $countries)) {
                $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc'), $cartitem->product_name, $selectedCountry[0]['country']);
                $_SESSION['categoryAndShippingCountryConflict'] = $errormessage;
                $is_valid = false;
            }
        }
        //count number of items, and number of items using shipping
        $num_items++;
        if ($cartitem->uses_shipping != 1) {
            $disregard_shipping++;
        } else {
            $use_shipping++;
        }
    }
    if (array_search($submitted_gateway, $selected_gateways) !== false) {
        $_SESSION['wpsc_previous_selected_gateway'] = $submitted_gateway;
    } else {
        $is_valid = false;
    }
    if (get_option('do_not_use_shipping') == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null) && $num_items != $disregard_shipping) {
        $_SESSION['wpsc_checkout_misc_error_messages'][] = __('You must select a shipping method, otherwise we cannot process your order.', 'wpsc');
        $is_valid = false;
    }
    if (get_option('do_not_use_shipping') != 1 && in_array('ups', (array) $options) && $_SESSION['wpsc_zipcode'] == '' && $num_items != $disregard_shipping) {
        $_SESSION['categoryAndShippingCountryConflict'] = __('Please enter a Zipcode and click calculate to proceed', 'wpsc');
        $is_valid = false;
    }
    if ($is_valid == true) {
        $_SESSION['categoryAndShippingCountryConflict'] = '';
        // check that the submitted gateway is in the list of selected ones
        $sessionid = mt_rand(100, 999) . time();
        $_SESSION['wpsc_sessionid'] = $sessionid;
        $subtotal = $wpsc_cart->calculate_subtotal();
        if ($wpsc_cart->has_total_shipping_discount() == false) {
            $base_shipping = $wpsc_cart->calculate_base_shipping();
        } else {
            $base_shipping = 0;
        }
        $delivery_country = $wpsc_cart->delivery_country;
        $delivery_region = $wpsc_cart->delivery_region;
        if (wpsc_uses_shipping()) {
            $shipping_method = $wpsc_cart->selected_shipping_method;
            $shipping_option = $wpsc_cart->selected_shipping_option;
        } else {
            $shipping_method = '';
            $shipping_option = '';
        }
        if (isset($_POST['how_find_us'])) {
            $find_us = $_POST['how_find_us'];
        } else {
            $find_us = '';
        }
        //keep track of tax if taxes are exclusive
        $wpec_taxes_controller = new wpec_taxes_controller();
        if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
            $tax = $wpsc_cart->calculate_total_tax();
            $tax_percentage = $wpsc_cart->tax_percentage;
        } else {
            $tax = 0.0;
            $tax_percentage = 0.0;
        }
        $total = $wpsc_cart->calculate_total_price();
        $wpdb->insert(WPSC_TABLE_PURCHASE_LOGS, array('totalprice' => $total, 'statusno' => '0', 'sessionid' => $sessionid, 'user_ID' => (int) $user_ID, 'date' => strtotime(current_time('mysql')), 'gateway' => $submitted_gateway, 'billing_country' => $wpsc_cart->selected_country, 'shipping_country' => $delivery_country, 'billing_region' => $wpsc_cart->selected_region, 'shipping_region' => $delivery_region, 'base_shipping' => $base_shipping, 'shipping_method' => $shipping_method, 'shipping_option' => $shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name, 'find_us' => $find_us, 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage));
        $purchase_log_id = $wpdb->insert_id;
        $wpsc_checkout->save_forms_to_db($purchase_log_id);
        $wpsc_cart->save_to_db($purchase_log_id);
        $wpsc_cart->submit_stock_claims($purchase_log_id);
        if (get_option('wpsc_also_bought') == 1) {
            wpsc_populate_also_bought_list();
        }
        if (!isset($our_user_id) && isset($user_ID)) {
            $our_user_id = $user_ID;
        }
        $wpsc_cart->log_id = $purchase_log_id;
        do_action('wpsc_submit_checkout', array("purchase_log_id" => $purchase_log_id, "our_user_id" => $our_user_id));
        if (get_option('permalink_structure') != '') {
            $separator = "?";
        } else {
            $separator = "&";
        }
        // submit to gateway
        $current_gateway_data =& $wpsc_gateways[$submitted_gateway];
        if ($current_gateway_data['api_version'] >= 2.0) {
            $merchant_instance = new $current_gateway_data['class_name']($purchase_log_id);
            $merchant_instance->construct_value_array();
            $merchant_instance->submit();
        } elseif ($current_gateway_data['internalname'] == $submitted_gateway && $current_gateway_data['internalname'] != 'google') {
            $gateway_used = $current_gateway_data['internalname'];
            $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('gateway' => $gateway_used), array('id' => $log_id));
            $current_gateway_data['function']($separator, $sessionid);
        } elseif ($current_gateway_data['internalname'] == 'google' && $current_gateway_data['internalname'] == $submitted_gateway) {
            $gateway_used = $current_gateway_data['internalname'];
            $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('gateway' => $gateway_used), array('id' => $log_id));
            $_SESSION['gateway'] = 'google';
            wp_redirect(get_option('shopping_cart_url'));
        }
    }
}
Example #17
0
/**
 * submit checkout function, used through ajax and in normal page loading.
 * No parameters, returns nothing
 */
function wpsc_submit_checkout($collected_data = true)
{
    global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways;
    if ($collected_data && isset($_POST['collected_data']) && is_array($_POST['collected_data'])) {
        _wpsc_checkout_customer_meta_update($_POST['collected_data']);
    }
    // initialize our checkout status variab;e, we start be assuming
    // checkout is falid, until we find a reason otherwise
    $is_valid = true;
    $num_items = 0;
    $use_shipping = 0;
    $disregard_shipping = 0;
    do_action('wpsc_before_submit_checkout');
    $error_messages = wpsc_get_customer_meta('checkout_misc_error_messages');
    if (!is_array($error_messages)) {
        $error_messages = array();
    }
    $wpsc_checkout = new wpsc_checkout();
    $selected_gateways = get_option('custom_gateway_options');
    $submitted_gateway = isset($_POST['custom_gateway']) ? $_POST['custom_gateway'] : '';
    if ($collected_data) {
        $form_validity = $wpsc_checkout->validate_forms();
        extract($form_validity);
        // extracts $is_valid and $error_messages
        if (wpsc_has_tnc() && (!isset($_POST['agree']) || $_POST['agree'] != 'yes')) {
            $error_messages[] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc');
            $is_valid = false;
        }
    } else {
        $is_valid = true;
        $error_messages = array();
    }
    $wpsc_country = new WPSC_Country(wpsc_get_customer_meta('shippingcountry'));
    $country_id = $wpsc_country->get_id();
    $country_name = $wpsc_country->get_name();
    foreach ($wpsc_cart->cart_items as $cartitem) {
        if (!empty($cartitem->meta[0]['no_shipping'])) {
            continue;
        }
        $categoriesIDs = $cartitem->category_id_list;
        foreach ((array) $categoriesIDs as $catid) {
            if (is_array($catid)) {
                $countries = wpsc_get_meta($catid[0], 'target_market', 'wpsc_category');
            } else {
                $countries = wpsc_get_meta($catid, 'target_market', 'wpsc_category');
            }
            if (!empty($countries) && !in_array($country_id, (array) $countries)) {
                $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc'), $cartitem->get_title(), $country_name);
                wpsc_update_customer_meta('category_shipping_conflict', $errormessage);
                $is_valid = false;
            }
        }
        //count number of items, and number of items using shipping
        $num_items++;
        if ($cartitem->uses_shipping != 1) {
            $disregard_shipping++;
        } else {
            $use_shipping++;
        }
    }
    // check to see if the current gateway is in the list of available gateways
    if (array_search($submitted_gateway, $selected_gateways) !== false) {
        wpsc_update_customer_meta('selected_gateway', $submitted_gateway);
    } else {
        $is_valid = false;
    }
    if ($collected_data) {
        // Test for required shipping information
        if (wpsc_core_shipping_enabled() && $num_items != $disregard_shipping) {
            // for shipping to work we need a method, option and a quote
            if (!$wpsc_cart->shipping_method_selected() || !$wpsc_cart->shipping_quote_selected()) {
                $error_messages[] = __('Please select one of the available shipping options, then we can process your order.', 'wpsc');
                $is_valid = false;
            }
            // if we don't have a valid zip code ( the function also checks if we need it ) we have an error
            if (!wpsc_have_valid_shipping_zipcode()) {
                wpsc_update_customer_meta('category_shipping_conflict', __('Please enter a Zipcode and click calculate to proceed', 'wpsc'));
                $is_valid = false;
            }
        }
    }
    wpsc_update_customer_meta('checkout_misc_error_messages', $error_messages);
    if ($is_valid == true) {
        wpsc_delete_customer_meta('category_shipping_conflict');
        // check that the submitted gateway is in the list of selected ones
        $sessionid = mt_rand(100, 999) . time();
        wpsc_update_customer_meta('checkout_session_id', $sessionid);
        $subtotal = $wpsc_cart->calculate_subtotal();
        if ($wpsc_cart->has_total_shipping_discount() == false) {
            $base_shipping = $wpsc_cart->calculate_base_shipping();
        } else {
            $base_shipping = 0;
        }
        $delivery_country = $wpsc_cart->delivery_country;
        $delivery_region = $wpsc_cart->delivery_region;
        if (wpsc_uses_shipping()) {
            $shipping_method = $wpsc_cart->selected_shipping_method;
            $shipping_option = $wpsc_cart->selected_shipping_option;
        } else {
            $shipping_method = '';
            $shipping_option = '';
        }
        if (isset($_POST['how_find_us'])) {
            $find_us = $_POST['how_find_us'];
        } else {
            $find_us = '';
        }
        //keep track of tax if taxes are exclusive
        $wpec_taxes_controller = new wpec_taxes_controller();
        if (!$wpec_taxes_controller->wpec_taxes_isincluded()) {
            $tax = $wpsc_cart->calculate_total_tax();
            $tax_percentage = $wpsc_cart->tax_percentage;
        } else {
            $tax = 0.0;
            $tax_percentage = 0.0;
        }
        $total = $wpsc_cart->calculate_total_price();
        $args = array('totalprice' => $total, 'statusno' => '0', 'sessionid' => $sessionid, 'user_ID' => (int) $user_ID, 'date' => time(), 'gateway' => $submitted_gateway, 'billing_country' => $wpsc_cart->selected_country, 'shipping_country' => $delivery_country, 'billing_region' => $wpsc_cart->selected_region, 'shipping_region' => $delivery_region, 'base_shipping' => $base_shipping, 'shipping_method' => $shipping_method, 'shipping_option' => $shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name, 'find_us' => $find_us, 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage);
        $purchase_log = new WPSC_Purchase_Log($args);
        $purchase_log->save();
        $purchase_log_id = $purchase_log->get('id');
        if ($collected_data) {
            $wpsc_checkout->save_forms_to_db($purchase_log_id);
        }
        $wpsc_cart->save_to_db($purchase_log_id);
        $wpsc_cart->submit_stock_claims($purchase_log_id);
        if (!isset($our_user_id) && isset($user_ID)) {
            $our_user_id = $user_ID;
        }
        $wpsc_cart->log_id = $purchase_log_id;
        do_action('wpsc_submit_checkout', array('purchase_log_id' => $purchase_log_id, 'our_user_id' => $our_user_id));
        do_action('wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log);
    }
}
 /**
  * Review Transaction Callback
  *
  * @return void
  */
 public function callback_review_transaction()
 {
     // Pull Customer Details from PayPal
     $this->pull_paypal_details();
     // If no Shipping is required, confirm the Transaction
     if (!wpsc_uses_shipping()) {
         $this->callback_confirm_transaction();
     }
     // Display Customer Details
     add_filter('wpsc_review_order_buyers_details', array(&$this, 'review_order_buyer_details'));
     add_filter('wpsc_review_order_shipping_details', array(&$this, 'review_order_shipping_details'));
 }
    /**
     * Output the address widget HTML
     */
    public function address_widget()
    {
        ?>
		<div class="col2-set">
			<div class="col-1">
				<?php 
        if (wpsc_uses_shipping()) {
            ?>
<h3><?php 
            _e('Shipping Address', 'wpsc');
            ?>
</h3><?php 
        } else {
            ?>
<h3><?php 
            _e('Your Address', 'wpsc');
            ?>
</h3><?php 
        }
        ?>
				<div id="amazon_addressbook_widget"></div>
				<?php 
        $this->insert_reference_id();
        ?>
				<style type="text/css">
					.wpsc-checkout-review p,
					.wpsc-field-wpsc_payment_method {
						display: none
					}
				</style>
			</div>
		</div>
		<?php 
    }
Example #20
0
 /**
  * calculate_total_shipping method, gets the shipping option from the selected method and associated quotes
  *
  * @access public
  * @return float returns the shipping as a floating point value
  */
 function calculate_total_shipping()
 {
     $shipping_discount_value = get_option('shipping_discount_value');
     $is_free_shipping_enabled = get_option('shipping_discount');
     $subtotal = $this->calculate_subtotal();
     $has_free_shipping = $is_free_shipping_enabled && $shipping_discount_value > 0 && $shipping_discount_value <= $subtotal;
     if (!wpsc_uses_shipping() || $has_free_shipping) {
         $total = 0;
     } else {
         $total = $this->calculate_base_shipping();
         $total += $this->calculate_per_item_shipping();
     }
     return apply_filters('wpsc_convert_total_shipping', $total, $this);
 }
Example #21
0
    /**
     * form_field method, returns the form html
     * @access public
     */
    function form_field()
    {
        global $wpdb, $user_ID, $wpsc_customer_checkout_details;
        if ($user_ID > 0) {
            $delivery_country_id = wpsc_get_country_form_id_by_type('delivery_country');
            $billing_country_id = wpsc_get_country_form_id_by_type('country');
        }
        $saved_form_data = empty($wpsc_customer_checkout_details[$this->checkout_item->id]) ? null : $wpsc_customer_checkout_details[$this->checkout_item->id];
        $an_array = '';
        if (function_exists('wpsc_get_ticket_checkout_set')) {
            if ($this->checkout_item->checkout_set == wpsc_get_ticket_checkout_set()) {
                $an_array = '[]';
            }
        }
        $output = '';
        $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');
        switch ($this->checkout_item->type) {
            case "address":
            case "delivery_address":
            case "textarea":
                $output .= "<textarea title='" . $this->checkout_item->unique_name . "' class='text' id='" . $this->form_element_id() . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' rows='3' cols='40' >" . esc_html((string) $saved_form_data) . "</textarea>";
                break;
            case "checkbox":
                $options = $this->get_checkout_options($this->checkout_item->id);
                if ($options != '') {
                    $i = mt_rand();
                    foreach ($options as $label => $value) {
                        ?>
							<label>
								<input <?php 
                        checked(in_array($value, (array) $saved_form_data));
                        ?>
 type="checkbox" name="collected_data[<?php 
                        echo esc_attr($this->checkout_item->id);
                        ?>
]<?php 
                        echo $an_array;
                        ?>
[]" value="<?php 
                        echo esc_attr($value);
                        ?>
"  />
								<?php 
                        echo esc_html($label);
                        ?>
							</label>
						<?php 
                    }
                }
                break;
            case "country":
                $output = wpsc_country_region_list($this->checkout_item->id, false, $billing_country, $billing_region, $this->form_element_id());
                break;
            case "delivery_country":
                if (wpsc_uses_shipping()) {
                    $country_name = $wpdb->get_var($wpdb->prepare("SELECT `country` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`= %s LIMIT 1", $delivery_country));
                    $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_country' name='collected_data[{$this->checkout_item->id}]' value='" . esc_attr($delivery_country) . "' size='4' /><span class='shipping_country_name'>" . $country_name . "</span> ";
                } else {
                    $checkoutfields = true;
                    $output = wpsc_country_region_list($this->checkout_item->id, false, $delivery_country, $delivery_region, $this->form_element_id(), $checkoutfields);
                }
                break;
            case "select":
                $options = $this->get_checkout_options($this->checkout_item->id);
                if ($options != '') {
                    $output = "<select name='collected_data[{$this->checkout_item->id}]" . $an_array . "'>";
                    $output .= "<option value='-1'>" . _x('Select an Option', 'Dropdown default when called within checkout class', 'wpsc') . "</option>";
                    foreach ((array) $options as $label => $value) {
                        $value = esc_attr(str_replace(' ', '', $value));
                        $output .= "<option " . selected($value, $saved_form_data, false) . " value='" . esc_attr($value) . "'>" . esc_html($label) . "</option>\n\r";
                    }
                    $output .= "</select>";
                }
                break;
            case "radio":
                $options = $this->get_checkout_options($this->checkout_item->id);
                if ($options != '') {
                    foreach ((array) $options as $label => $value) {
                        ?>
							<label>
								<input type="radio" <?php 
                        checked($value, $saved_form_data);
                        ?>
 name="collected_data[<?php 
                        echo esc_attr($this->checkout_item->id);
                        ?>
]<?php 
                        echo $an_array;
                        ?>
" value="<?php 
                        echo esc_attr($value);
                        ?>
"  />
								<?php 
                        echo esc_html($label);
                        ?>
							</label>
						<?php 
                    }
                }
                break;
            case "text":
            case "city":
            case "delivery_city":
            case "email":
            case "coupon":
            default:
                if ($this->checkout_item->unique_name == 'shippingstate') {
                    if (wpsc_uses_shipping() && wpsc_has_regions($delivery_country)) {
                        $region_name = $wpdb->get_var($wpdb->prepare("SELECT `name` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id`= %d LIMIT 1", $delivery_region));
                        $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_region' name='collected_data[{$this->checkout_item->id}]' value='" . esc_attr($delivery_region) . "' size='4' /><span class='shipping_region_name'>" . esc_html($region_name) . "</span> ";
                    } else {
                        $disabled = '';
                        if (wpsc_disregard_shipping_state_fields()) {
                            $disabled = 'disabled = "disabled"';
                        }
                        $output = "<input class='shipping_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . esc_attr($saved_form_data) . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />";
                    }
                } elseif ($this->checkout_item->unique_name == 'billingstate') {
                    $disabled = '';
                    if (wpsc_disregard_billing_state_fields()) {
                        $disabled = 'disabled = "disabled"';
                    }
                    $output = "<input class='billing_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . esc_attr($saved_form_data) . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />";
                } else {
                    $output = "<input title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' class='text' value='" . esc_attr($saved_form_data) . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' />";
                }
                break;
        }
        return $output;
    }
Example #22
0
                echo "class='wpsc_shipping_forms'";
            }
            ?>
 colspan='2'>
				<h4>
					<?php 
            echo wpsc_checkout_form_name();
            ?>
				</h4>
			</td>
				</tr>
		  <?php 
        } else {
            ?>
		  <?php 
            if (!wpsc_uses_shipping() && $wpsc_checkout->checkout_item->unique_name == 'shippingstate') {
                ?>
		  <?php 
            } else {
                ?>
		  		<tr <?php 
                echo wpsc_the_checkout_item_error_class();
                ?>
>
			<td>
				<label for='<?php 
                echo wpsc_checkout_form_element_id();
                ?>
'>
				<?php 
                echo wpsc_checkout_form_name();
function Usecase($separator, $sessionid, $fromcheckout)
{
    global $wpdb, $wpsc_cart;
    $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 = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid` = %d", $purchase_log[0]['id']);
    $wp_cart = $wpdb->get_results($cart_sql, ARRAY_A);
    $merchant_id = get_option('google_id');
    $merchant_key = get_option('google_key');
    $server_type = get_option('google_server_type');
    $currency = get_option('google_cur');
    $transact_url = get_option('transact_url');
    $returnURL = $transact_url . $separator . "sessionid=" . $sessionid . "&gateway=google";
    $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
    $cart->SetContinueShoppingUrl($returnURL);
    $cart->SetEditCartUrl(get_option('shopping_cart_url'));
    //google prohibited items not implemented
    $currency_converter = new CURRENCYCONVERTER();
    $currency_code = $wpdb->get_results("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1", ARRAY_A);
    $local_currency_code = $currency_code[0]['code'];
    $google_curr = get_option('google_cur');
    $currentcy_rate = 1;
    if ($google_curr != $local_currency_code) {
        $currentcy_rate = $currency_converter->convert(1, $local_currency_code, $google_curr);
    }
    while (wpsc_have_cart_items()) {
        wpsc_the_cart_item();
        $google_currency_productprice = $currentcy_rate * (wpsc_cart_item_price(false) / wpsc_cart_item_quantity());
        $cart_item = new GoogleItem(wpsc_cart_item_name(), '', wpsc_cart_item_quantity(), $google_currency_productprice);
        $cart->AddItem($cart_item);
    }
    //If there are coupons applied add coupon as a product with negative price
    if ($wpsc_cart->coupons_amount > 0) {
        $google_currency_productprice = $currentcy_rate * $wpsc_cart->coupons_amount;
        $coupon = new GoogleItem('Discount', 'Discount Price', 1, '-' . $google_currency_productprice);
        $cart->AddItem($coupon);
    }
    $shipping_country = $purchase_log[0]['shipping_country'];
    $shipping_region = $purchase_log[0]['shipping_region'];
    if ($shipping_country == "UK") {
        $shipping_country = "GB";
    }
    // Add shipping options
    if (wpsc_uses_shipping()) {
        $shipping_name = ucfirst($wpsc_cart->selected_shipping_method) . " - " . $wpsc_cart->selected_shipping_option;
        if ($shipping_name == "") {
            $shipping_name = "Calculated";
        }
        $shipping = new GoogleFlatRateShipping($shipping_name, $wpsc_cart->calculate_total_shipping() * $currentcy_rate);
        if (!empty($shipping_country)) {
            $shipping_filter = new GoogleShippingFilters();
            if (!empty($shipping_region) && is_numeric($shipping_region)) {
                $shipping_filter->AddAllowedPostalArea($shipping_country, wpsc_get_state_by_id($shipping_region, "code"));
                $shipping_filter->AddAllowedStateArea(wpsc_get_state_by_id($shipping_region, "code"));
            } else {
                $shipping_filter->AddAllowedPostalArea($shipping_country);
            }
            $shipping->AddShippingRestrictions($shipping_filter);
        }
        $cart->AddShipping($shipping);
    }
    // Add tax rules
    if (!empty($shipping_country)) {
        $tax_rule = new GoogleDefaultTaxRule(wpsc_cart_tax(false) / $wpsc_cart->calculate_subtotal());
        $tax_rule->AddPostalArea($shipping_country);
        $cart->AddDefaultTaxRules($tax_rule);
    }
    // Display Google Checkout button
    if (get_option('google_button_size') == '0') {
        $google_button_size = 'BIG';
    } elseif (get_option('google_button_size') == '1') {
        $google_button_size = 'MEDIUM';
    } elseif (get_option('google_button_size') == '2') {
        $google_button_size = 'SMALL';
    }
    echo $cart->CheckoutButtonCode($google_button_size);
}