function UseCase3()
{
    //Create a new shopping cart object
    $merchant_id = "";
    // Your Merchant ID
    $merchant_key = "";
    // Your Merchant Key
    $server_type = "sandbox";
    $currency = "USD";
    $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
    // Add items to the cart
    $item = new GoogleItem("MegaSound 2GB MP3 Player", "Portable MP3 player - stores 500 songs", 1, 175.49);
    $item->SetMerchantPrivateItemData("<color>blue</color><weight>3.2</weight>");
    $cart->AddItem($item);
    // Add merchant calculations options
    $cart->SetMerchantCalculations("http://200.69.205.154/~brovagnati/tools/unitTest/demo/responsehandlerdemo.php", "false", "true", "true");
    // accept-merchant-gift-certificates
    // Add merchant-calculated-shipping option
    $ship = new GoogleMerchantCalculatedShipping("2nd Day Air", 10.0);
    // Default, fallback price
    $restriction = new GoogleShippingFilters();
    $restriction->AddAllowedPostalArea("GB");
    $restriction->AddAllowedPostalArea("US");
    $restriction->SetAllowUsPoBox(false);
    $ship->AddShippingRestrictions($restriction);
    $address_filter = new GoogleShippingFilters();
    $address_filter->AddAllowedPostalArea("GB");
    $address_filter->AddAllowedPostalArea("US");
    $address_filter->SetAllowUsPoBox(false);
    $ship->AddAddressFilters($address_filter);
    $cart->AddShipping($ship);
    // Set default tax options
    $tax_rule = new GoogleDefaultTaxRule(0.15);
    $tax_rule->SetWorldArea(true);
    $cart->AddDefaultTaxRules($tax_rule);
    $cart->AddRoundingPolicy("UP", "TOTAL");
    // Display XML data
    // echo "<pre>";
    // echo htmlentities($cart->GetXML());
    // echo "</pre>";
    // Display a disabled, small button
    echo $cart->CheckoutButtonCode("SMALL", false);
}
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 #3
0
 // merchant calculated shipping
 $shipping_name = $googlepayment->mc_shipping_methods_names[$module_info[$key]['code']] . ': ' . $name;
 //			merchant calculated - use defaults
 if (!in_array($module_info[$key]['code'], $googlepayment->shipping_support)) {
     $default_value = compare($module_info[$key]['code'] . $method . $type, $key_values);
     $shipping_price = $currencies->get_value(DEFAULT_CURRENCY) * $default_value;
 } else {
     $default_value = 1;
     $module = new $module_name();
     $quote = $module->quote($method);
     $price = $quote['methods'][0]['cost'];
     $shipping_price = $currencies->get_value(DEFAULT_CURRENCY) * ($price >= 0 ? $price : 0);
 }
 $Gfilter = new GoogleShippingFilters();
 if (MODULE_PAYMENT_GOOGLECHECKOUT_USPOBOX == 'False') {
     $Gfilter->SetAllowUsPoBox('false');
 }
 if (!empty($allowed_restriction_country)) {
     foreach ($allowed_restriction_state as $state_key => $state) {
         if ($allowed_restriction_country[$state_key][1] == 'US') {
             if ($state == 'All Areas') {
                 $Gfilter->SetAllowedCountryArea('ALL');
             } else {
                 $Gfilter->AddAllowedStateArea($state);
             }
         } else {
             // TODO here should go the non us area (not implemented in GC)
             // now just the country
             $Gfilter->AddAllowedPostalArea($allowed_restriction_country[$state_key][1]);
         }
     }