Re: PP Express shipping question
OK. I have done loads more testing in live mode (my poor credit card :blink:) as Sandbox environment kept coming up with errors and timing out. This is what I have found:
If I check out with a shipping address that is different from my PayPal account address, the address from my PayPal account is written to the database with the order details as the shipping address. This part I knew already. The interesting part is that once the transaction is complete there is a new entry in my address list with the PayPal account details.
This means that ZenCart is allowing the PayPal address sent back to override what the user sets as the shipping address during checkout. This does not seem right. The other interesting thing I noticed is that if you already have 5 entries in your address book, using PayPal Express as the payment method allows you to go over the 5 address limit :huh: I ended up with about 8 entries in my address book when in Zen Admin I have it set to only allow 5 max.
Now I will start looking at how to get ZenCart to ignore the address that PayPal sends back and write the address that the user has specified to the database as the shipping address.
Re: PP Express shipping question
Quote:
Originally Posted by
duwane
Now I will start looking at how to get ZenCart to ignore the address that PayPal sends back and write the address that the user has specified to the database as the shipping address.
So ... you mean ... when someone (esp not-yet-logged-in) starts Express Checkout, goes to PayPal, and *selects (or enters a new) shipping address*, you want Zen Cart to ignore that and just use whatever address is their primary ZC address ?
I haven't had a chance to test out all of what you're explaining to see where there's a discrepancy.
However, it should be using the Zen Cart address *only* if the customer specifically *changes* their address on the payment page *after* returning from PayPal.
Re: PP Express shipping question
Quote:
Originally Posted by
DrByte
So ... you mean ... when someone (esp not-yet-logged-in) starts Express Checkout, goes to PayPal, and *selects (or enters a new) shipping address*, you want Zen Cart to ignore that and just use whatever address is their primary ZC address ?
I haven't had a chance to test out all of what you're explaining to see where there's a discrepancy.
However, it should be using the Zen Cart address *only* if the customer specifically *changes* their address on the payment page *after* returning from PayPal.
Thanks for replying DrByte. I agree with you that you can't ignore the address if the user does not have a ZenCart account.
However the problem I am seeing is when the user does have a ZenCart account and goes through the 3 step checkout process. On step one they change the shipping address to something other than their default, select the shipping method and continue. On step 2 they select PayPal Express as the payment option. They go through step 3 and when they come back from PayPal they go straight to checkout success so there is no other chance for them to change the shipping address again and the address entered into the DB against the order is the address PayPal sends back (PayPal account address unless they change it again on the PayPal payment page).
The angle I was working on as a solution was if the user already has a shipping address specified i.e. if(isset($_SESSION['sendto'] then don't let the PayPal address sent back override it. That way if it is a user that does not have an account i.e. !$_SESSION['sendto'] it will still accept the PayPal details as the shipping address for the order.
Will this work or is this what is already supposed to be happening? I am just trying to find a way around this that won't break everything :smile: and avoiding extra instructions for the customer.
Re: PP Express shipping question
I received an order today with a different shipping address from billing and the order appeared correctly in Zen-Cart. The customer must have noticed that the ship to address had to be changed in PayPal too.
With my testing, the problem appears when a customer fills out the billing/payment info in PayPal, PayPal automatically fills in the shipping address with the billing address instead of receiving the correct ship to address from zen-cart. I think PayPal prefers to have the billing/ship to address the same. I know this reduces potential fraud, but many of my customers send my items as gifts and this difficulty could cause customer service problems. It also creates double entry work for the customer and it could easily be missed if they aren't paying attention.
I wish I could dive into the code to work this out, but unfortunately my coding skills are pretty messy.
Re: PP Express shipping question
Quote:
Originally Posted by
tinypack
I received an order today with a different shipping address from billing and the order appeared correctly in Zen-Cart. The customer must have noticed that the ship to address had to be changed in PayPal too.
The problem is that when a customer fills out the billing/payment info in PayPal, PayPal automatically fills in the shipping address with the billing address instead of receiving the correct ship to address from zen-cart. I think PayPal prefers to have the billing/ship to address the same. I know this reduces potential fraud, but many of my customers send my items as gifts and this difficulty could cause customer service problems. It also creates double entry work for the customer and it could easily be missed if they aren't paying attention.
I wish I could dive into the code to work this out, but unfortunately my coding skills are pretty messy.
There is a bit more to it though as the shipping calculation is also incorrect and is very noticeable when the customer is in another country :blink: The taxes are also calculated incorrectly (when the customer is from another country and shipping the order to the store's home country).
All this aside though it makes it really hard to know where the customer actually wants the order shipped to :smile:
Re: PP Express shipping question
I have made some progress and thought I would share it so you can add your opinions or advice.
If I change the code at round line 1917 of my includes/modules/payment/paypalwpp.php file from:
Code:
$_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
// This is the address matching section
// try to match it first
// note: this is by no means 100%
$address_book_id = $this->findMatchingAddressBookEntry($_SESSION['customer_id'], $order->delivery);
// no match, so add the record
if (!$address_book_id) {
$address_book_id = $this->addAddressBookEntry($_SESSION['customer_id'], $order->delivery, false);
}
// set the address for use
$_SESSION['sendto'] = $address_book_id;
to this:
Code:
if(!isset($_SESSION['sendto']) || $_SESSION['sendto'] == ''){
$_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
// This is the address matching section
// try to match it first
// note: this is by no means 100%
$address_book_id = $this->findMatchingAddressBookEntry($_SESSION['customer_id'], $order->delivery);
// no match, so add the record
if (!$address_book_id) {
$address_book_id = $this->addAddressBookEntry($_SESSION['customer_id'], $order->delivery, false);
}
// set the address for use
$_SESSION['sendto'] = $address_book_id;
}
then the address is added to the order correctly in the scenario we are having trouble with. I just added the first IF statement. The only problem that doing this creates (that I have found so far) is that if the customer changes their address on the PayPal screen it does not get added to the order.
What this means is that as long as the customer chooses the same shipping address during checkout as they do on the PayPal screens (if they change it) then we have a workaround :cool:
If someone could take a look and see what other implications this may have I would appreciate it. Also if there is a way to change my IF statement to allow the code to execute when the address is changed on the PayPal screens then this would work perfectly.
Any ideas?
Re: PP Express shipping question
I think I finally may have found a viable solution but I need some help getting the data into the PayPal tables properly. This solution is independent of the one I posted earlier and seems much cleaner and less risky.
In my travels around the PayPal developer’s handbooks I found a new API function which I had not seen before. This function is "NOSHIPPING". When I came across it I new it was the answer:lookaroun. Basically this API call removes the customer’s option to change their shipping address on the PayPal screen. The code I wrote only runs if their selected shipping address is not the same as their default one and their account is not a temporary one.
Find this code:
Code:
/**
* Ask PayPal for the token with which to initiate communications
*/
$response = $doPayPal->SetExpressCheckout(number_format($order_amount, 2), $return_url, $cancel_url, $options);
(line 1668 or so of my includes/modules/payment/paypalwpp.php)
Just ABOVE it add:
Code:
if(isset($_SESSION['sendto']) && isset($_SESSION['customer_default_address_id'])
&& $_SESSION['sendto'] != $_SESSION['customer_default_address_id'] && isset($_SESSION['customer_id'])){
//This user has selected a shipping address other than their default address book entry
$sql = "SELECT customers_paypal_ec
FROM " . TABLE_CUSTOMERS . "
WHERE customers_id = '".$_SESSION['customer_id']."' ";
$check_customer = $db->Execute($sql);
if (!$check_customer->EOF) {
if ($check_customer->fields['customers_paypal_ec'] != '1') {
//this is not a temporary account so hide the shipping detail on the PayPal screen
$options['NOSHIPPING'] = 1;
}
}
}
This seems to work really well as far as I can see except that in our scenario (customer choosing different shipping address) it does not enter all address details correctly into the PayPal table as there is no address response from PayPal. The shipping address is entered into the Zen orders tables correctly and shows the correct shipping address.
DrByte I would appreciate if you could take a look at the code above and let me know if it is a viable workaround/patch as there seems to be many threads dealing with the same issue as we are here. Most of the other threads don't have any real answers and some contain custom hacks that don't look too sound to me.
Re: PP Express shipping question
The NOSHIPPING option already does get set if the cart-contents are all virtual (ie: downloads, and not requiring shipping).
So, yes, it's possible to blindly disable all shipping address options from the PayPal interface; however there are some caveats to that ...
Consider the case where you have a new customer ... they don't have an account on your site, but they do have a PP account. If they select an address from their PP address book, then that'll automatically be set up in their Zen Cart account, meaning they won't have to create all their address details. If you disable the PP address book, then Zen Cart will not get those details ... and indeed may end up with unpredictable results due to blank data.
For existing customers, it wouldn't be as much of an issue ... but ... due to the nature of "Express", you don't know if the customer has an account or not until after they've logged into PayPal and provided an email address for lookup. And at that point they're already in PayPal, so you can't disable their address book options in PP. :lookaroun
Re: PP Express shipping question
Quote:
Originally Posted by
DrByte
Consider the case where you have a new customer ... they don't have an account on your site, but they do have a PP account. If they select an address from their PP address book, then that'll automatically be set up in their Zen Cart account, meaning they won't have to create all their address details. If you disable the PP address book, then Zen Cart will not get those details ... and indeed may end up with unpredictable results due to blank data.
Quote:
Originally Posted by
DrByte
you don't know if the customer has an account or not until after they've logged into PayPal and provided an email address for lookup. And at that point they're already in PayPal, so you can't disable their address book options in PP.
Thanks DrByte. I thought of that while writing this code and was under the impression that the code I wrote would not fire if the customer did not have an account (no $_SESSION['customer_id']) in their session and they also wouldn't have a $_SESSION['sendto'] or $_SESSION['customer_default_address_id']. Also I am doing a check to see if the account was created by the EC checkout process ($check_customer->fields['customers_paypal_ec'] != '1').
Any further thoughts? I am now trying to figure out where in the code the PayPal return data is written to the PayPal table but it got a bit late last night and mind fuzz set in :smile:
Re: PP Express shipping question
Mind fuzz ... yes, I know what you mean.
Admittedly, I didn't check your code closely enough to see your check for customer id being set in the session. Will have to review again when *my* mind is clear.
Quote:
I am now trying to figure out where in the code the PayPal return data is written to the PayPal table
*which* data are you referring to? There are a few places where data gets written. Best to search for TABLE_PAYPAL if it's the paypal table you're specifically looking for.