Jump to content

Express Checkout not returning province


Recommended Posts

Hi Everyone, 

 

I'm testing the express checkout option in PS 1.6.  It will redirect a customer back to my website to pick shipping, but I noticed taxes weren't applied afterwards.  I checked the address paypal was returning and everything looked good except there was no province indicated  in the address.  Taxes in Canada are based on province,  so this data returned is imperative to use express checkout.  

 

Does anyone else have this issue?  Is there anything I can do about it?

Link to comment
Share on other sites

I checked the code in the expresscheckout.php file in the paypal module and I see this code... this looks like it should be grabbing the state... so why isn't it being updated in prestashop?

 

/* Create or update a PayPal address for this customer */

$address = new Address(isset($id_address) ? (int)$id_address : 0);

$address->id_customer = (int)$customer->id;

$address->id_country = (int)Country::getByIso($result['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE']);

$address->id_state = (int)State::getIdByIso($result['PAYMENTREQUEST_0_SHIPTOSTATE'], (int)$address->id_country); $address->alias = 'PayPal'; $address->lastname = Tools::substr($result['PAYMENTREQUEST_0_SHIPTONAME'], 0, strpos($result['PAYMENTREQUEST_0_SHIPTONAME'], ' '));

$address->firstname = Tools::substr($result['PAYMENTREQUEST_0_SHIPTONAME'], strpos($result['PAYMENTREQUEST_0_SHIPTONAME'], ' '), Tools::strlen($result['PAYMENTREQUEST_0_SHIPTONAME']) - Tools::strlen($address->lastname));

$address->address1 = $result['PAYMENTREQUEST_0_SHIPTOSTREET']; if ($result['PAYMENTREQUEST_0_SHIPTOSTREET2'] != '') $address->address2 = $result['PAYMENTREQUEST_0_SHIPTOSTREET2'];

$address->city = $result['PAYMENTREQUEST_0_SHIPTOCITY']; $address->postcode = $result['PAYMENTREQUEST_0_SHIPTOZIP']; $address->save();


Canada is set up properly by ISO (CA) and all provinces are included with ISO's entered.

Link to comment
Share on other sites

If anyone cares... and I'm not sure anyone does, the issue I've been having here is that

$address->id_state = (int)State::getIdByIso($result['PAYMENTREQUEST_0_SHIPTOSTATE'], (int)$address->id_country); 

 

is returning 0 and it's because PayPal is returning the full state name instead of the ISO code.  The example I've been using is a customer from PEI in Canada.  Paypal is returning "Prince Edward Island" instead of PE. 

 

I have a support ticket into PayPal asking why this is the case.  If this is something that can't be avoided I will write some code to convert the return value to ISO code before calling this function (unless someone has any other ideas). 

  • Like 1
Link to comment
Share on other sites

Hi Everyone,

 

Just FYI, PayPal is insisting that they can't recreate this issue and the ISO code is always returned in the $result['PAYMENTREQUEST_0_SHIPTOSTATE'] variable and that Prestashop must be converting it to state name rather than ISO code somewhere.  I can't find evidence of this, but someone who knows the Prestashop code better than I may be able to.

 

In the meantime, if you run into this issue, modify the expresscheckout.php file under paypalusa/controllers/front in this way:

 

add the following code to the expressCheckout function:

 

switch ($result['PAYMENTREQUEST_0_SHIPTOSTATE']) { case "Prince Edward Island": $State = 'PE'; break; case "Ontario": $State = 'ON'; break; case "Newfoundland and Labrador": $State = 'NL'; break; case "Newfoundland": $State = 'NL'; break; case "Quebec": $State = 'QC'; break; case "British Columbia": $State = 'BC'; break; case "Alberta": $State = 'AB'; break; case "Manitoba": $State = 'MB'; break; case "Saskatchewan": $State = 'SK'; break; case "Nova Scotia": $State = 'NS'; break; case "New Brunswick": $State = 'NB'; break; case "Northwest Territories": $State = 'NT'; break; case "Yukon": $State = 'YT'; break; default : $State = $result['PAYMENTREQUEST_0_SHIPTOSTATE']; }

 

Then change the following code:

 

From this:

 

$address->id_state = (int)State::getIdByIso($result['PAYMENTREQUEST_0_SHIPTOSTATE'], (int)$address->id_country);

 

To this:

 

$address->id_state = (int)State::getIdByIso($State, (int)$address->id_country);

 

Enjoy!

  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...