homepage Welcome to WebmasterWorld Guest from 54.226.235.222
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Google Checkout International Shipping
problems only allowed to USA
aff_dan




msg:3370861
 9:59 am on Jun 18, 2007 (gmt 0)

dear Sir/Madam,

We are experiencing problems with this XML & php code that only allows us to ship to only USA>

We want to ship inetrnational, and we dont figure out where to add this code:

================
<shipping-methods>
<merchant-calculated-shipping name="SuperShip International">
<price currency="USD">14.00</price>
<address-filters>
<allowed-areas>
<world-area/>
</allowed-areas>
<excluded-areas>
<postal-area>
<country-code>KP</country-code>
</postal-area>
</excluded-areas>
</address-filters>
</merchant-calculated-shipping>
</shipping-methods>

========

to:

=======

<?php
//
// $Id: google_checkout.php 2537 2006-11-14 13:20:12Z imac $
//

//db_query("DELETE FROM $db_tables[ad_descriptions]");

if (!defined('IN_CSCART')) {die('Access denied');}

if (defined('PAYMENT_NOTIFICATION')) {

sess_register("order_id");
sess_unregister("order_id");
if (!empty($order_id)) {
fn_order_placement_routines($order_id);
fn_redirect("$http_location/$index_script?$target_name=orders&$mode_name= details&order_id=$order_id", true);
} else {
fn_set_notification('E',fn_get_lang_var('error'),fn_get_lang_var ('order_was_not_placed'));
fn_redirect("$http_location/$index_script?$target_name=orders");
}

} elseif(!empty($_payment_id) &&!empty($cart['products'])) {
$cart_g = $cart;
$_result = fn_calculate_cart_content($cart_g, $auth, true, true);
$_shipping_rates = $_result['shipping_rates'];

$return_url = "$current_location/$index_script?$target_name=payment_notification&amp; $mode_name=notify&amp;payment=google_checkout&amp;csid= ".$GLOBALS[$CSCART_SESSION_NAME];
$calculation_url = "$current_location/payments/cc_processors/google_calculations.php? csid=".$GLOBALS[$CSCART_SESSION_NAME];

$_currency = $processor_data["params"]["currency"];
$base_url = "https://" . (($processor_data["params"]["test"] == 'N')? "checkout.google.com" : "sandbox.google.com") . "/cws/v2/Merchant/" . $processor_data["params"]["merchant_id"];
$checkout_url = $base_url . "/checkout";
$request_url = $base_url . "/request";

// Form XML array with cart items
$_items = '';
$taxes = '';
foreach ($cart_g['products'] as $k => $v) {
$_product = db_get_row("SELECT product, short_description FROM $db_tables[product_descriptions] WHERE product_id='$v[product_id]' AND lang_code='$cart_language'");
$_items .= " <item>
<item-name>".strip_tags($_product['product'])."</item-name>
<item-description>".substr(strip_tags($_product['short_description']), 0, 299)."</item-description>
<unit-price currency='".$_currency."'>".fn_format_price(($v['subtotal']+ $v['discount'])/$v['amount'])."</unit-price>
<quantity>".$v['amount']."</quantity>
</item>";
}
// Prepare taxes
if (is_array(@$cart_g['taxes'])) {
$tax = "";
foreach ($cart_g['taxes'] as $k => $v) {
if ($v['price_includes_tax'] == 'N') {
// Definů whether shipping is taxable
$tax_shipping = 'false';
foreach ($v['applies'] as $kkk => $vvv) {
if (substr($kkk, 0, 2) == 'S_') {
$tax_shipping = 'true';
}
}
$tax .= "
<default-tax-rule>
<shipping-taxed>$tax_shipping</shipping-taxed>
<rate>".($v['rate_value']/100)."</rate>
<tax-area>
<us-country-area country-area='ALL'/>
</tax-area>
</default-tax-rule>";
}
}
if (!empty($tax)) {
$taxes = "
<tax-tables>
<default-tax-table>
<tax-rules>"
. $tax . "
</tax-rules>
</default-tax-table>";
}
}

// ******************************** Prepare shippings *************************
$shippings = "<shipping-methods>";
foreach ($_shipping_rates as $key => $_shipping) {
$shippings .= "
<merchant-calculated-shipping name='".$_shipping['name'] . " (".$_shipping['delivery_time']. ")'>
<price currency='".$_currency."'>".$_shipping['rate']."</price>
</merchant-calculated-shipping>";
}
$shippings .= "</shipping-methods>";
// ******************************** /Prepare shippings *************************

// Form a discount part of a form
if (!empty($cart_g['discount'])) {
$_items .= "
<item>
<item-name>".fn_get_lang_var('discount')."</item-name>
<item-description>".fn_get_lang_var('discount')."</item-description>
<unit-price currency='".$_currency."'>".-$cart_g['discount']."</unit-price>
<quantity>1</quantity>
</item>";
}
// Form a surcharge part of the payment
if (!empty($_payment_id)) {
$_data = db_get_row("SELECT a_surcharge, p_surcharge FROM $db_tables[payments] WHERE payment_id='$_payment_id'");
$cart_g['payment_surcharge'] = 0;
if (floatval($_data['a_surcharge'])) {
$cart_g['payment_surcharge'] += $_data['a_surcharge'];
}
if (floatval($_data['p_surcharge'])) {
$cart_g['payment_surcharge'] += fn_format_price($cart_g['total'] * $_data['p_surcharge'] / 100);
}
if (!empty($cart_g['payment_surcharge'])) {
$_items .= "
<item>
<item-name>".fn_get_lang_var('surcharge')."</item-name>
<item-description>".fn_get_lang_var('surcharge_for_the_payment')." </item-description>
<unit-price currency='".$_currency."'>".$cart_g['payment_surcharge']."</unit-price>
<quantity>1</quantity>
<tax-table-selector>no_tax</tax-table-selector>
</item>";
if ($taxes) {
$taxes .= '
<alternate-tax-tables>
<alternate-tax-table standalone="true" name="no_tax">
<alternate-tax-rules>
<alternate-tax-rule>
<rate>0</rate>
<tax-area>
<us-country-area country-area="ALL"/>
</tax-area>
</alternate-tax-rule>
</alternate-tax-rules>
</alternate-tax-table>
</alternate-tax-tables>';
}
}
}
if (!empty($taxes)) {
$taxes .= '</tax-tables>';
}

// The cart in XML format
$xml_cart = "<?xml version='1.0' encoding='UTF-8'?>
<checkout-shopping-cart xmlns='http://checkout.google.com/schema/2'>
<shopping-cart>
<merchant-private-data>
<additional_data>
<session_id>".$GLOBALS[$CSCART_SESSION_NAME]."</session_id>
</additional_data>
</merchant-private-data>
<items>
" . $_items . "
</items>
</shopping-cart>
<checkout-flow-support>
<merchant-checkout-flow-support>
<merchant-calculations>
<merchant-calculations-url>". $calculation_url ."</merchant-calculations-url>
<accept-merchant-coupons>false</accept-merchant-coupons>
</merchant-calculations>
<continue-shopping-url>" .$return_url. "</continue-shopping-url>
".$shippings
.$taxes. "
</merchant-checkout-flow-support>
</checkout-flow-support>
</checkout-shopping-cart>";

$signature = fn_CalcHmacSha1($xml_cart, $processor_data["params"]["merchant_key"]);
$b64_cart = base64_encode($xml_cart);
$b64_signature = base64_encode($signature);

$msg = fn_get_lang_var('text_cc_processor_connection');
$msg = str_replace('[processor]', 'Google Checkout server', $msg);

$checkout_button = '
<html>
<body>
<form method="post" action="'.$checkout_url.'" name="BB_BuyButtonForm">
<input type="hidden" name="cart" value="'.$b64_cart.'" />
<input type="hidden" name="signature" value="'.$b64_signature.'" />
<input alt="" src="https://checkout.google.com/buttons/checkout.gif?merchant_id= 853766255459917&w=160&h=43&style=trans&variant=text&loc=en_US" type="image"/>
</form>
</body>
</html>';
$smarty->assign('checkout_add_button', $checkout_button);

}

#
# The CalcHmacSha1 function computes the HMAC-SHA1 signature that you need
# to send a Checkout API request. The signature is used to verify the
# integrity of the data in your API request.
#
# @param $data message data
# @return $hmac value of the calculated HMAC-SHA1
function fn_CalcHmacSha1($data, $key) {

$blocksize = 64;
$hashfunc = 'sha1';

if (strlen($key) > $blocksize) {
$key = pack('H*', $hashfunc($key));
}

$key = str_pad($key, $blocksize, chr(0x00));
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
$hmac = pack(
'H*', $hashfunc(
($key^$opad).pack(
'H*', $hashfunc(
($key^$ipad).$data
)
)
)
);
return $hmac;
}
?>

Please help us.

Regards,
Dan

[edited by: dreamcatcher at 10:12 am (utc) on June 18, 2007]
[edit reason] Removed specifics, fixed side scroll. [/edit]

 

phparion




msg:3370975
 12:31 pm on Jun 18, 2007 (gmt 0)

Google Checkout Manual [groups.google.com]

aff_dan




msg:3371836
 6:39 am on Jun 19, 2007 (gmt 0)

Could you please tell me what to modify in that code in order to accept shipping international clients? In that code I am forced only to USA

Regards,
Dan

phparion




msg:3371885
 8:02 am on Jun 19, 2007 (gmt 0)

Hi Dan,

thanks for your sticky!

Due to my fulltime job I cannot fix your complete code to make it work, most I can do here is to give you quick guidance and you can read the manual to find your way which is very easy.

I had already given you a very good link for international shipping changes for Google Checkout API howevere to be mor precise read this one

[code.google.com...]

study the shipping link and you will probably understand how to add FILTERS or MULTIPLE options for shipping.

I guess you are based in USA therefore google checkout is pushing you to serve as a US merchant as it is google checkout default value for US merchants. You can change the XML as written on the page I mentioned earlier for more options.

I hope it helps

aff_dan




msg:3375831
 3:05 pm on Jun 22, 2007 (gmt 0)

phparion, could you please help?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved