Jump to content

PayPal and the missing dni...


beepow

Recommended Posts

Hello,
when an user pays with PayPal (official module) there's no dni in notification mail: is there a way to "force" Prestashop (version 1.6.1.14, ) to keep and send it? 
For registered users, ok, it is normally stored (unless they delete it from their addresses) but with Guests it is completely lost...
Is it possible to retrieve it somehow?
PS: Our installation runs on a really old php version (5.5.38)

Thanks
 

Link to comment
Share on other sites

Hello Artixweb, thanks for your interest!
For Guests there'e no trace at all, neither  in order details.

Dni is a mandatory field in registration process but for some of the registered users, the address line with dni simply disappears at a point, like the address had been updated from PayPal. Actually, I've seen that the module sometimes(*) adds an address "PAYPAL_ADDRESS" as invoice address and then updates also delivery address with it.

I almost think that, by choosing to use the same address for the invoice and for the delivery (in paypal process), paypal updates the delivery address with the one associated with the buyer's account (or his cards)

After entering the payment details (whether these are paypal or credit card accounts), in the final summary you can already see the address without dni. And from that point, all you can do is confirm the purchase or close the browser. There are no other buttons or other possibilities.

The module does not exit the site, it opens a lightbox from where you can login with paypal...


(*) I guess it happens depending on how the paypent is done: with a paypal account or with a card, using paypal gateway...
 

Edited by beepow (see edit history)
Link to comment
Share on other sites

Morning!

I have found the setCustomerAddress function in: /modules/paypal/express_checkout/payment.php

I believe this is the culprit since the function description states:

<?php
/**
 * Set customer address (when not logged in)
 * Used to create user address with PayPal account information
 */
function setCustomerAddress($ppec, $customer, $id = null)
{
    //...
}

The function uses information from $ppec->result to create the address, the $ppec->result value contains data from Paypal's checkout API.

If the address ID is null, the name of the address is set to "Paypal_Address" and the DNI field is empty by default since a new address is being created, then the address is filled in using the data from Paypal's API which does not contain a DNI since it's an uncommon field that might not be available in Paypal. In the checkAndModifyAddress function, at the end, you will see $paypal_address->save(), this is where the address is updated if it has an ID or a new one is created if the ID is missing.

I don't know in what situation the address ID is null since I believe that this is the main issue, probably related to the Paypal popup you mentioned. Sadly, I don't have a paypal sandbox environment to test this out, maybe someone more experienced with the paypal module can help out. Sorry I couldn't be of more help!

  • Like 1
Link to comment
Share on other sites

Looking better into order details there's still the possibility to recall the registration address.
Paypal adds its own but you can select and edit original address.

I guess the registration address is always stored in the same position and maybe it can be recalled with positon 0 in some array??
 

Link to comment
Share on other sites

in /admin/themes/default/template/controllers/orders/helpers/view/view.tpl
dni from registration address can be retrived this way:
{$customer_addresses[0]['dni']}

but don't kow how to assign it in mailalerts.php ('{dninumber}' =>$customer_addresses[0]['dni'] does not work and of course '{dninumber}' gives a void string if added in mail template...)

Link to comment
Share on other sites

Not sure what you mean by "recalling" the registration address. If there is a registration address, then Paypal may attempt to update it with its own data.

Searching for the setCustomerAddress function in the payment.php file, we can see that it is used 4 times, 3 times in the checkAndModifyAddress function and once outside of any other function, I assume during the execution of the payment.php file. (payment modules are not my strong suit so please bear with me) 

In the checkAndModifyAddress function we have some scenarios, a few commented by the paypal module developers:

1. No customer addresses

<?php
if (count($customer_addresses) == 0) {
    $paypal_address = setCustomerAddress($ppec, $customer);
}

If the are no customers addresses, then the setCustomerAddress function is called without passing any address ID as the third argument (address id is null), this means a new address with the name "Paypal_Address" is created. If there are no addresses, then I don't know how we can recover the DNI field in this case however I believe this might be a rare occurrence, a "worst-case scenario" kind of thing.

2. Customer has at least one address, then we loop over the $customer_addresses array. The first comment states:

If a PayPal address already exists we use it to override new address from paypal

This part checks if there is already an address with the name "Paypal_Address", if so, the module will update it with the data from Paypal, however, when updating an address, unless properties are explicitly set to an empty string ( example: $address->dni = '' ), any additional address details that Paypal doesn't modify should remain. I have stated in my previous message that Paypal doesn't have a DNI value from its API so it doesn't touch the address' DNI property/field.

3. For the third usage, the second comment states:

We check if an address exists with the same country / city / street

So if there is a customer address that looks similar to the one the customer has on Paypal, it will update it, but the DNI field would still not be affected/removed.

4. The final usage in the checkAndModifyAddress function of setCustomerAddress is at the end, right before the address is created/updated via $paypal_address->save(). Here is the scenario where: the customer has addresses (at least one) and the we tried to look for an adddress named 'Paypal_Address' or that is similar to the address on Paypal but we haven't found a match. In this case, a new address is created based in the Paypal data, same as the first scenario.

This might be the cause of the problem you are facing, some customers may not use the same address they have on paypal and thus a new address with no DNI is created.

In this case, yes, you could use the first address in the array of addresses, something like this might work:

<?php
// Potential fix in checkAndModifyAddress() function
// Replace:
if ($paypal_address == false) {
    $paypal_address = setCustomerAddress($ppec, $customer);
}

// With:
if ($paypal_address == false) {
    $addressId = null;
    if (count($customer_addresses) !== 0) {
        $addressId = $customer_addresses[0]['id_address'];
    }
    $paypal_address = setCustomerAddress($ppec, $customer, $addressId);
}


// If you want to use the first address that HAS a DNI value, you can try this instead:
if ($paypal_address == false) {
    $addressId = null;
    if (count($customer_addresses) !== 0) {
        foreach($customer_addresses as $customerAddr) {
            if ($customerAddr['dni']) {
                $addressId = $customerAddr['id_address'];
                break;
            }
        }
        // If no DNI found, still use the first address.
        if ($addressId === null) {
            $addressId = $customer_addresses[0]['id_address'];
        }
    }
    $paypal_address = setCustomerAddress($ppec, $customer, $addressId);
}

Please use with caution! Preferably in a testing/dev environment.

5. The final usage is in the main execution of the payment.php file, here we have a few comments as well:

<?php
//...

if ((!$address || !$address->id) && $customer->id) {
    //If address does not exists, we create it
    $address = setCustomerAddress($ppec, $customer);
    $address->add();
} else if ($ppec->type != 'payment_cart') {
    //We used Express Checkout Shortcut => we override address
    $address = checkAndModifyAddress($ppec, $customer);
}

Here is where things get a bit vague for me and I'm not exactly sure what is the scenario where the setCustomerAddress function is called, except for when the customer has no address, according to the comments. This is also the only bit of code where the checkAndModifyAddress function is called, when $ppec->type is anything but "payment_cart", maybe you can shed some light on this one.

Edited by artixweb (see edit history)
  • Like 1
Link to comment
Share on other sites

1 minute ago, artixweb said:

Not sure what you mean by "recalling" the registration address. If there is a registration address, then Paypal may attempt to update it with its own data.

 

Sorry, my bad! 
I meant "retrieve".
In other words, I would like to get the dni value from registered address(es) 

I'm going to study your reply now (thanks!!!!)
 

Link to comment
Share on other sites

46 minutes ago, beepow said:

in /admin/themes/default/template/controllers/orders/helpers/view/view.tpl
dni from registration address can be retrived this way:
{$customer_addresses[0]['dni']}

but don't kow how to assign it in mailalerts.php ('{dninumber}' =>$customer_addresses[0]['dni'] does not work and of course '{dninumber}' gives a void string if added in mail template...)

I assume you're trying to find alternatives to get the customer DNIs in your emails. If it doesn't get saved in the database in the first place, then this is not going to work. I should have suggested that you first check the database to see if the DNIs are saved and that they simply don't show up in the order details page.

35 minutes ago, beepow said:

I'm going to study your reply now (thanks!!!!)

You're welcome! I hope it helps!

 

Edited by artixweb (see edit history)
  • Like 1
Link to comment
Share on other sites

With {$customer_addresses[0]['dni']} it won't work in mailalerts.php, even if the value is stored in the database.
(I guess it is because $customer_addresses is not reachable from mailalerts.php and needs to be retrieved in another way...)

 

Link to comment
Share on other sites

  • 1 year later...
On 9/26/2022 at 10:16 AM, beepow said:

Hello,
when an user pays with PayPal (official module) there's no dni in notification mail: is there a way to "force" Prestashop (version 1.6.1.14, ) to keep and send it? 
For registered users, ok, it is normally stored (unless they delete it from their addresses) but with Guests it is completely lost...
Is it possible to retrieve it somehow?
PS: Our installation runs on a really old php version (5.5.38)

Thanks
 

Did you find the reason why paypall module is changing cart address? I my opinion cart address should be untouched. As you mentioned modified address causes missing data. Module tries to synchronize paypall address with cart address?

Link to comment
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
×
×
  • Create New...