Jump to content
sligoman

Oscommerce 2.3 - PayPal Express Postage Charges

Recommended Posts

HI All

 

Only just noticed after customer rang me, that he tried to make purchase through paypal exppress from shopping cart. Postage in shopping cart was only £3.30 and after pressing the paypal express button and arriving at the PayPal payment page the postage was £8.85..

 

Now if the customer makes an account and checkouts through the OSCommerse Route and arrives at the PayPal payment page using the same payment module then the postage is OK it stays at £3.30.

 

I have checked all the settings in oscommerce Shipping/Packaging, Order Totals and the PayPal Express module setting as well. If anyone has had this problem before or someone with the insight that may know off the problem I would be appreciative.

 

Thanks in advance

 

Sligoman

Share this post


Link to post
Share on other sites

@@sligoman

 

Check your PayPal account and disable the option for PayPal to charge shipping.

 

 

 

Chris


:|: Was this post helpful ? Click the LIKE THIS button :|:

 

See my Profile to learn more about add ons, templates, support plans and custom coding (click here)

Share this post


Link to post
Share on other sites

Hi Chris

 

Yes that is disabled... well for now I have uncommented the code that displays the button and will check to see if there is another paypal express module that will work corectly..

 

Thanks

Share this post


Link to post
Share on other sites

Is there a way to get some info logged or emailed on the AJAX call that the Paypal Express Instant Update makes when the customer logs into Paypal? This is on osC 2.3.1. I've been adding debug email lines in all sorts of places - lol - the emails always come up empty :)

 

I'm getting what looks like the same issue and yet I can see it's pulling the default shipping rate (£16.55) from the database so it looks as if it's maybe sending a country code that is not understood by the shipping module? (which, in this case, is a variation on zonesworld/zones international default).

 

The shipping is set up for a rate of £4.50 for the UK, £8.50 for Europe and £16.55 for the rest of the world, (i.e. it defaults to £16.55 if it doesn't get either 'GB' or one of the two-character EU codes) and that is what the Instant Update AJAX call is coming back with: £16.50. In Paypal's "Review Your Information" section, the Postage method is also missing the country. It says, "Postage method: Zone Rates (Shipping to ..." where it should say, "Zone Rates (Shipping to UK ..."

Share this post


Link to post
Share on other sites

:) OK, I won't ask that question again - lol. It's just that I've been postponing getting into AJAX (mainly because of the smell of brimstone).

 

From what I can see, the Paypal Express Checkout and its Instant-Update feature were coded by Harald himself. ... It must work!!

 

No idea if this is relevant but the constructor specifies this version:

 

signature = 'paypal|paypal_express|1.2|2.2';

api_version = '60.0';

 

Starting out with a fresh install of osC 2.3.1, with Paypal Express Checkout enabled and with its Instant Update set to TRUE, does anyone know which shipping module we should use in order that the Instant Update request will return the correct shipping rate? In this case, we only need three rates for three locations: UK, EU, Rest of World. Is there more to it than setting up a zones-based shipping module in the same way as we would for Paypal Standard?

 

Zone 1 Countries

GB

Zone 1 Shipping Table

99:4.5

Zone 1 Handling Fee

0

 

Zone 2 Countries

AT,BE,NL,DE,FR,GL,IS,IE,IT,NO,DK,PL,ES,SE,CH,FI,PT,IL,GR

Zone 2 Shipping Table

99:8.5

Zone 2 Handling Fee

0

 

Zone 3 Countries

All Others

Zone 3 Shipping Table

99:16.5

Zone 3 Handling Fee

0

 

I tried three flat-rate shipping modules, each enabled only for one zone, which works fine with Paypal Standard but, on reverting to Paypal Express Checkout, the Instant Update didn't work at all. At least, when using the zones-based (international default) shipping module, it feels as if it's nearly working: the AJAX call is coming back with the default value of 16.50. With the flat-rate modules, no shipping was being charged at all.

 

BTW, does anyone have Paypal Express Checkout with Instant Update working? All I can find on the forum are unanswered questions on this.

Edited by cujimmy

Share this post


Link to post
Share on other sites

Is there a way to get some info logged or emailed on the AJAX call that the Paypal Express Instant Update makes when the customer logs into Paypal? This is on osC 2.3.1. I've been adding debug email lines in all sorts of places - lol - the emails always come up empty :)

 

The Instant Update is processed in:

 

ext/modules/payment/paypal/express.php

 

lines 54 - 226 (the callbackSet case in the switch statement)

 

Have you tried adding debugging code there?


:heart:, osCommerce

Share this post


Link to post
Share on other sites

One thing I loathe is obsequious grovelling and sycophancy but, Harald, you are a rock star and a legend! :-)

 

Apologies for the slow reply. I wanted to go back over everything I'd done and check it again.

 

To make sure I was getting the debug email,

I added $paypal_express->sendDebugEmail(); at line 27, right after $paypal_express = new paypal_express();

result: 1) good - after clicking on Checkout with Paypal, the empty debug email arrived (no POST or GET data)

result: 2) maybe not so good? - after logging in at Paypal, and seeing the shipping (apparently) update to £16.50, no further email arrived.

With the debug email call at line 27, I expected a second email at the time of the AJAX request?

I imagined php would have to parse that line before getting to the switch?

 

I then placed the debug call at a variety of points inside the switch, for example:

at line 55, right after case 'callbackSet':

at line 164 after the comment "// get all available shipping quotes"

at line 223 at the end of case callbackSet (just before exit;)

result in each case (even after logging in to Paypal and watching the shipping update (or default) to £16.50): no email received.

 

The AJAX response always seems to include the (RoW) shipping rate of £16.50 but, according to the debug email, no POST or GET request ever reached express.php? I know that can't be right but that's how I'm reading it - lol - unless the default £16.50 shipping value had already been passed to Paypal along with the rest of the cart data?

 

I tried calling the page directly in the browser:

URL: ... .../express.php?osC_Action=callbackSet, and with the debug email line inside the switch at line 57 right after

 if (MODULE_PAYMENT_PAYPAL_EXPRESS_INSTANT_UPDATE == 'True') {

result: the email came back with $HTTP_GET_VARS: osC_Action=callbackSet

 

Also tried an AJAX request to the page (debug call still inside the switch at line 57)

ajaxTest.open("GET", "... ... /express.php?osC_Action=callbackSet", true);

result: again, the email came back with $HTTP_GET_VARS: osC_Action=callbackSet

 

Then repeated the AJAX request but with the debug call back at line 27, right after $paypal_express = new paypal_express();

ajaxTest.open("GET", "... ... /express.php?osC_Action=callbackSet", true);

result: the email came back with $HTTP_GET_VARS: osC_Action=callbackSet

Share this post


Link to post
Share on other sites

Please note that SSL must be enabled on your live store for PayPal to request the shipping methods and prices. This may explain why you're not receiving a debug e-mail.

 

There's a check for ENABLE_SSL at ext/modules/payment/paypal/express.php line 659.

 

You can also see an example response with curl:

 

curl -d "L_NUMBER0=6&L_QTY0=1&SHIPTOZIP=90210&SHIPTOCITY=Beverly%20Hills&SHIPTOSTATE=CA&SHIPTOCOUNTRY=US" https://server/ext/modules/payment/paypal/express.php?osC_Action=callbackSet

Edited by Harald Ponce de Leon

:heart:, osCommerce

Share this post


Link to post
Share on other sites

Please note that SSL must be enabled on your live store for PayPal to request the shipping methods and prices. This may explain why you're not receiving a debug e-mail.

 

There's a check for ENABLE_SSL at ext/modules/payment/paypal/express.php line 659.

 

You can also see an example response with curl:

 

curl -d "L_NUMBER0=6&L_QTY0=1&SHIPTOZIP=90210&SHIPTOCITY=Beverly%20Hills&SHIPTOSTATE=CA&SHIPTOCOUNTRY=US" https://server/ext/modules/payment/paypal/express.php?osC_Action=callbackSet

 

I have also use word zone shipping rate. and also can not update shipping fee in paypal

 

my server is a full ssl host

follow is my debug info of ext/modules/payment/paypal/express.php

 

POST

Array

(

[METHOD] => CallbackRequest

[CALLBACKVERSION] => 57

[TOKEN] => EC-7J889120M1357080F

[LOCALECODE] => en_US

[CURRENCYCODE] => USD

[L_NAME0] => iPod Touch 10

[L_NUMBER0] => 148

[L_DESC0] =>

[L_AMT0] => 99.00

[L_QTY0] => 3

[L_ITEMWEIGHTUNIT0] =>

[L_ITEMWEIGHTVALUE0] => 0

[L_ITEMHEIGHTUNIT0] =>

[L_ITEMHEIGHTVALUE0] => 0

[L_ITEMWIDTHUNIT0] =>

[L_ITEMWIDTHVALUE0] => 0

[L_ITEMLENGTHUNIT0] =>

[L_ITEMLENGTHVALUE0] => 0

[sHIPTOSTREET] => SouthHuanghe Road 22

[sHIPTOCITY] => zhuzhou

[sHIPTOSTATE] => Hunan

[sHIPTOCOUNTRY] => CN

[sHIPTOZIP] => 412007

[sHIPTOSTREET2] =>

)

GET

Array

(

[osC_Action] => callbackSet

)

 

 

the $params array before the line 221 echo $post_string;

 

 

Array

(

[METHOD] => CallbackResponse

[OFFERINSURANCEOPTION] => false

[L_SHIPPINGOPTIONNAME0] => Per Item (Best Way)

[L_SHIPINGPOPTIONLABEL0] =>

[L_SHIPPINGOPTIONAMOUNT0] => 2.50

[L_SHIPPINGOPTIONISDEFAULT0] => true

[L_TAXAMT0] => 0.00

[L_SHIPPINGOPTIONNAME1] => World Express (Shipping to China 7-15 Days)

[L_SHIPINGPOPTIONLABEL1] =>

[L_SHIPPINGOPTIONAMOUNT1] => 40.00

[L_SHIPPINGOPTIONISDEFAULT1] => false

[L_TAXAMT1] => 0.00

[L_SHIPPINGOPTIONNAME2] => Express (Shipping to China 7-15 Days)

[L_SHIPINGPOPTIONLABEL2] =>

[L_SHIPPINGOPTIONAMOUNT2] => 8.50

[L_SHIPPINGOPTIONISDEFAULT2] => false

[L_TAXAMT2] => 0.00

[L_SHIPPINGOPTIONNAME3] => Flat Shipping (Best Way)

[L_SHIPINGPOPTIONLABEL3] =>

[L_SHIPPINGOPTIONAMOUNT3] => 5.00

[L_SHIPPINGOPTIONISDEFAULT3] => false

[L_TAXAMT3] => 0.00

)

 

look like all $params is right.

 

but in the paypal not update the shipping price list when i login paypal when i change shippping country.

Share this post


Link to post
Share on other sites

I have check and test debug infomation one day. now the shipping fee is ok.

 

1: you site must have ssl

 

2: The session setting will influence the paypal get the shipping fee.

osCommerce send products id to paypal and paypal imitate add products to cart

 

Force Cookie Use must off.

if this on the $cart->count_contents() is 0 and exit, will not return shipping fee.

 


   case 'callbackSet':
  if (MODULE_PAYMENT_PAYPAL_EXPRESS_INSTANT_UPDATE == 'True') {
    $counter = 0;
    while (true) {
	  if (isset($HTTP_POST_VARS['L_NUMBER' . $counter])) {
	    $cart->add_cart($HTTP_POST_VARS['L_NUMBER' . $counter], $HTTP_POST_VARS['L_QTY' . $counter]);
	  } else {
	    break;
	  }
	  $counter++;
    }

   //debug
$fp = fopen("express_".date("Y-m-d-h-i").".txt","a"); 
flock($fp, LOCK_EX) ;
fwrite($fp,"time: ".date("Y-m-d h:i:s")."\r\n");
flock($fp, LOCK_EX) ;
ob_start();
print_r($_POST);
print_r($cart);
$cache_output = ob_get_contents();
ob_end_clean(); 
fwrite($fp,$cache_output."\r\nCart: ".$cart->count_contents()."\r\n");
flock($fp, LOCK_UN);
fclose($fp);
   //debug
// exit if there is nothing in the shopping cart
    if ($cart->count_contents() < 1) {
	  exit;
    }
    if($HTTP_POST_VARS['SHIPTOCOUNTRY']=='C2'){
	 $HTTP_POST_VARS['SHIPTOCOUNTRY'] ='CN';
	}
    $sendto = array('firstname' => '',
				    'lastname' => '',
				    'company' => '',
				    'street_address' => '',
				    'suburb' => '',
				    'postcode' => $HTTP_POST_VARS['SHIPTOZIP'],
				    'city' => $HTTP_POST_VARS['SHIPTOCITY'],
				    'zone_id' => '',
				    'zone_name' => $HTTP_POST_VARS['SHIPTOSTATE'],
				    'country_id' => '',
				    'country_name' => $HTTP_POST_VARS['SHIPTOCOUNTRY'],
				    'country_iso_code_2' => '',
				    'country_iso_code_3' => '',
				    'address_format_id' => '');
    $country_query = tep_db_query("select * from " . TABLE_COUNTRIES . " where countries_iso_code_2 = '" . tep_db_input($sendto['country_name']) . "' limit 1");
    if (tep_db_num_rows($country_query)) {
	  $country = tep_db_fetch_array($country_query);
	  $sendto['country_id'] = $country['countries_id'];
	  $sendto['country_name'] = $country['countries_name'];
	  $sendto['country_iso_code_2'] = $country['countries_iso_code_2'];
	  $sendto['country_iso_code_3'] = $country['countries_iso_code_3'];
	  $sendto['address_format_id'] = $country['address_format_id'];
    }
    if ($sendto['country_id'] > 0) {
	  $zone_query = tep_db_query("select * from " . TABLE_ZONES . " where zone_country_id = '" . (int)$sendto['country_id'] . "' and (zone_name = '" . tep_db_input($sendto['zone_name']) . "' or zone_code = '" . tep_db_input($sendto['zone_name']) . "') limit 1");
	  if (tep_db_num_rows($zone_query)) {
	    $zone = tep_db_fetch_array($zone_query);
	    $sendto['zone_id'] = $zone['zone_id'];
	    $sendto['zone_name'] = $zone['zone_name'];
	  }
    }
    $billto = $sendto;
    $quotes_array = array();
    include(DIR_WS_CLASSES . 'order.php');
    if ($cart->get_content_type() != 'virtual') {
	  $order = new order;
	  $total_weight = $cart->show_weight();
	  $total_count = $cart->count_contents();
// load all enabled shipping modules
	  include(DIR_WS_CLASSES . 'shipping.php');
	  $shipping_modules = new shipping;
	  $free_shipping = false;
	  if ( defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') ) {
	    $pass = false;
	    switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
		  case 'national':
		    if ($order->delivery['country_id'] == STORE_COUNTRY) {
			  $pass = true;
		    }
		    break;
		  case 'international':
		    if ($order->delivery['country_id'] != STORE_COUNTRY) {
			  $pass = true;
		    }
		    break;
		  case 'both':
		    $pass = true;
		    break;
	    }
	    if ( ($pass == true) && ($order->info['total'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {
		  $free_shipping = true;
		  include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
	    }
	  }
	  if ( (tep_count_shipping_modules() > 0) || ($free_shipping == true) ) {
	    if ($free_shipping == true) {
		  $quotes_array[] = array('id' => 'free_free',
								  'name' => FREE_SHIPPING_TITLE,
								  'label' => FREE_SHIPPING_TITLE,
								  'cost' => '0',
								  'tax' => '0');
	    } else {
// get all available shipping quotes
		  $quotes = $shipping_modules->quote();
		  foreach ($quotes as $quote) {
		    if (!isset($quote['error'])) {
			  foreach ($quote['methods'] as $rate) {
			    $quotes_array[] = array('id' => $quote['id'] . '_' . $rate['id'],
									    'name' => $quote['module'],
									    'label' => $rate['title'],
									    'cost' => $rate['cost'],
									    'tax' => isset($quote['tax']) ? $quote['tax'] : '0');
			  }
		    }
		  }
	    }
	  }
    } else {
	  $quotes_array[] = array('id' => 'null',
							  'name' => 'No Shipping',
							  'label' => 'No Shipping',
							  'cost' => '0',
							  'tax' => '0');
    }
    $params = array('METHOD' => 'CallbackResponse',
				    'OFFERINSURANCEOPTION' => 'false');
    $counter = 0;
    $cheapest_rate = null;
    $cheapest_counter = $counter;
    foreach ($quotes_array as $quote) {
	  $shipping_rate = $paypal_express->format_raw($quote['cost'] + tep_calculate_tax($quote['cost'], $quote['tax']));
	  $params['L_SHIPPINGOPTIONNAME' . $counter] = $quote['name'];
	  $params['L_SHIPINGPOPTIONLABEL' . $counter] = '(' . strip_tags($quote['label']) . ')';
	  $params['L_SHIPPINGOPTIONAMOUNT' . $counter] = $paypal_express->format_raw($quote['cost']);
	  $params['L_SHIPPINGOPTIONISDEFAULT' . $counter] = 'false';
	  $params['L_TAXAMT' . $counter] = $paypal_express->format_raw($order->info['tax'] + tep_calculate_tax($quote['cost'], $quote['tax']));
	  if (is_null($cheapest_rate) || ($shipping_rate < $cheapest_rate)) {
	    $cheapest_rate = $shipping_rate;
	    $cheapest_counter = $counter;
	  }
	  $counter++;
    }
    $params['L_SHIPPINGOPTIONISDEFAULT' . $cheapest_counter] = 'true';
    $post_string = '';
    foreach ($params as $key => $value) {
	  $post_string .= $key . '=' . urlencode(utf8_encode(trim($value))) . '&';
    }
    $post_string = substr($post_string, 0, -1);
    echo $post_string;
  }
   //debug
$fp = fopen("express_".date("Y-m-d-h-i").".txt","a+"); 
fwrite($fp, $post_string."\r\n");
flock($fp, LOCK_UN);
fclose($fp);
   //debug

  exit;
  break;

 

3. if products with attribute the add cart faild.

 

time: 2012-09-19 11:42:06

Array

(

[METHOD] => CallbackRequest

[CALLBACKVERSION] => 57

[TOKEN] => EC-5Y926703UH5421842

[LOCALECODE] => en_US

[CURRENCYCODE] => USD

[L_NAME0] => iPod Classic

[L_NUMBER0] => 138{1}3

[L_DESC0] =>

[L_AMT0] => 89.00

[L_QTY0] => 1

[L_ITEMWEIGHTUNIT0] =>

[L_ITEMWEIGHTVALUE0] => 0

[L_ITEMHEIGHTUNIT0] =>

[L_ITEMHEIGHTVALUE0] => 0

[L_ITEMWIDTHUNIT0] =>

[L_ITEMWIDTHVALUE0] => 0

[L_ITEMLENGTHUNIT0] =>

[L_ITEMLENGTHVALUE0] => 0

[sHIPTOSTREET] => 5041Heintz St

[sHIPTOCITY] => Baldwin Park

[sHIPTOSTATE] => CA

[sHIPTOCOUNTRY] => US

[sHIPTOZIP] => 91706

[sHIPTOSTREET2] => Baldwin

)

shoppingCart Object

(

[contents] => Array

(

)

[total] => 0

[weight] => 0

[content_type] =>

)

 

Cart: 0

 

is a bug ?

Share this post


Link to post
Share on other sites

Now I have make sure, there is a bug in ext/modules/payment/paypal/express.php

 

 if (isset($HTTP_POST_VARS['L_NUMBER' . $counter])) { $cart->add_cart($HTTP_POST_VARS['L_NUMBER' . $counter], $HTTP_POST_VARS['L_QTY' . $counter]); } 

 

if products have attribute the way $cart->add_cart('138{1}3',1) will return add card faild and cart number is 0 that exit and can not get the right shipping fee

 

the right way is

 

while (true) {
if (isset($HTTP_POST_VARS['L_NUMBER' . $counter])) {
//$cart->add_cart($HTTP_POST_VARS['L_NUMBER' . $counter], $HTTP_POST_VARS['L_QTY' . $counter]);   
 if(is_numeric($HTTP_POST_VARS['L_NUMBER' . $counter])){
	$cart->add_cart($HTTP_POST_VARS['L_NUMBER' . $counter], $HTTP_POST_VARS['L_QTY' . $counter]);
  }
 else{
	 $product_id = '';
	 $products = explode('{', $HTTP_POST_VARS['L_NUMBER' . $counter]);
	 $product_id =  (int)$products[0];
	 $attributes = array();
	 for($i=1; $i<sizeof($products); $i++){
	   $attributes_str = explode('}', $products[$i]);
	   $attributes[$attributes_str[0]]=$attributes_str[1];
	 }
	  $cart->add_cart($product_id, $HTTP_POST_VARS['L_QTY' . $counter], $attributes);
   }
}
else {
  break;
}

 $counter++;
	}

Edited by osCommerce China

Share this post


Link to post
Share on other sites

Thank you very much! the above works for products with 1 product attribute, Can someone expand on the code above and allow for products with 2 or more product attributes?

 

for example: $cart->add_cart('783{1}15{2}17',1)

Share this post


Link to post
Share on other sites
while (true) {
	  if (isset($HTTP_POST_VARS['L_NUMBER' . $counter])) {
	   if(is_numeric($HTTP_POST_VARS['L_NUMBER' . $counter])){
		 $cart->add_cart($HTTP_POST_VARS['L_NUMBER' . $counter], $HTTP_POST_VARS['L_QTY' . $counter]);
	   }
	   else{
	    $attributes = array();
	    $products_str = explode('{',$HTTP_POST_VARS['L_NUMBER' . $counter]); //get how many attrib
	    $product_id = (int)$products_str[0];
	    for($i=1; $i<sizeof($products_str); $i++){ //0 is products_id
		 $attr_value= explode('}', $products_str[$i]);  //separate key and value
		 $attributes[$attr_value[0]] = $attr_value[1];
	    }
	    $cart->add_cart($product_id, $HTTP_POST_VARS['L_QTY' . $counter], $attributes);
	   }
	  } else {
	    break;
	  }
	  $counter++;
    }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×