Page 3 of 3

Re: how to pass opencart address to Paypal Standard?

Posted: Fri Jul 07, 2017 8:45 pm
by ADD Creative
Sorry, there was an extra ) on one of the lines. Try.

Code: Select all

				$phone = preg_replace("/[^0-9.]/", "", html_entity_decode($order_info['telephone'], ENT_QUOTES, 'UTF-8'));
				$this->data['night_phone_a'] = substr($phone, 0, 3);
				$this->data['night_phone_b'] = substr($phone, 3, 3);
				$this->data['night_phone_c'] = substr($phone, 6);
Where you had it or just after line below should be fine.

Code: Select all

			$this->data['country'] = $order_info['payment_iso_code_2'];

Re: how to pass opencart address to Paypal Standard?

Posted: Fri Jul 07, 2017 9:07 pm
by RideTheWave
There is an error on the checkout confirmation step: "Indirect modification of overloaded property ControllerExtensionPaymentPPStandard::$data has no effect" and that error is for all 3 of those lines containing night_phone_a, night_phone_b, and night_phone_c.

Re: how to pass opencart address to Paypal Standard?

Posted: Fri Jul 07, 2017 9:30 pm
by ADD Creative
Sorry, try.

Code: Select all

				$phone = preg_replace("/[^0-9.]/", "", html_entity_decode($order_info['telephone'], ENT_QUOTES, 'UTF-8'));
				$data['night_phone_a'] = substr($phone, 0, 3);
				$data['night_phone_b'] = substr($phone, 3, 3);
				$data['night_phone_c'] = substr($phone, 6);

Re: how to pass opencart address to Paypal Standard?

Posted: Sat Jul 08, 2017 7:30 am
by RideTheWave
No errors this time, but the phone number field is still not populated. Do you think it makes a difference if the customer enters the phone number as (333) 333-3333 vs 333-333-3333 vs 3333333333 ?

Re: how to pass opencart address to Paypal Standard?

Posted: Sun Jul 09, 2017 12:38 am
by ADD Creative
See PayPal's information and example here. https://www.paypal.com/cgi-bin/webscr?c ... te_outside

To check, use your web browsers 'Inspect' (right click to the left of the Confirm Order button) on "Step 6: Confirm Order". You should see somewhere <input name="night_phone_a" value="123" type="hidden"> in the form sent to PayPal. Check the night_phone_a, b, and c are correct.

Re: how to pass opencart address to Paypal Standard?

Posted: Sun Jul 09, 2017 7:23 am
by RideTheWave
For phone number, I entered 1234567890. When inspecting the page at the Confirm Order step, I do see the variables:

<input name="night_phone_a" value="123" type="hidden">
<input name="night_phone_b" value="456" type="hidden">
<input name="night_phone_c" value="7890" type="hidden">

That should be an indication that the numbers are at least being sent to PayPal, right? I'm wondering if it could be something on PayPal's end? Add Creative: Does it work for you? Are you getting the phone number field populated in the PayPal guest checkout?

Re: how to pass opencart address to Paypal Standard?

Posted: Sun Jul 09, 2017 7:36 am
by RideTheWave
Ok, I think I've figured it out. All your above code DOES work! The problem was that I was testing it with fictitious area codes like 123 or 333. If I put in a REAL area code like 213 or 646, then it works! And I think it might be country specific too because when I put in a US address but enter a Canadian area code, the phone number doesn't get pre-populated. Thank-you ADD Creative!

Re: how to pass opencart address to Paypal Standard?

Posted: Sun Jul 09, 2017 8:25 am
by ADD Creative
It will be US only. See the following link for other countries.
https://www.paypal.com/uk/cgi-bin/websc ... te_outside

You might have to do something like this for other countries.

Code: Select all

$phone = preg_replace("/[^0-9.]/", "", html_entity_decode($order_info['telephone'], ENT_QUOTES, 'UTF-8'));
if ($order_info['payment_iso_code_2'] == 'US') {
	$data['night_phone_a'] = substr($phone, 0, 3);
	$data['night_phone_b'] = substr($phone, 3, 3);
	$data['night_phone_c'] = substr($phone, 6);
} else if ($order_info['payment_iso_code_2'] == 'CA') {
	$data['night_phone_a'] = '1'
	$data['night_phone_b'] = substr($phone, 0, 16);
	$data['night_phone_c'] = '';
}

Re: how to pass opencart address to Paypal Standard?

Posted: Sun Jul 09, 2017 12:24 pm
by RideTheWave
I have to correct my above post. Without changing any of the code (ie/ without specifying country code & just keeping your original code), when I enter a Canadian phone number (say area code 416) and put a US address, it does go through "sometimes." For example, say I get to the PayPal checkout page and I see that the phone number is missing. Then I'll press the Back button until I get back to the checkout page again. Without changing anything, I'll re-submit the same info from the checkout page and then this time the phone number will appear on the PayPal checkout page. So it seems like a hit or miss.

The same thing occurs when I enter a UK address. The phone number sometimes does and sometimes doesn't get populated (again, without changing any of the code). By the way, I'm wondering how would someone from the UK enter his/her phone number? I saw that a London area code is 020 plus 8 digits so the test number I used was 02033333333 and it went through. It was populated as 20333 33333 (five digits, a space, then five digits). How many digits is a phone number from the UK?

Re: how to pass opencart address to Paypal Standard?

Posted: Mon Jul 10, 2017 1:55 am
by ADD Creative
The most common length in the UK is 11 including the leading 0. There are however exceptions. The leading 0 is removed if dialing from outside the UK and replaced with the country code 44. So 01234 567890 becomes +44 1234 567890. This is probably why PayPal removes the leading 0.

The following seemed to work for me.

Code: Select all

$phone = preg_replace("/[^0-9.]/", "", html_entity_decode($order_info['telephone'], ENT_QUOTES, 'UTF-8'));
if ($order_info['payment_iso_code_2'] == 'US') {
	$data['night_phone_a'] = substr($phone, 0, 3);
	$data['night_phone_b'] = substr($phone, 3, 3);
	$data['night_phone_c'] = substr($phone, 6);
} else {
	$data['night_phone_a'] = ''
	$data['night_phone_b'] = substr($phone, 0, 16);
	$data['night_phone_c'] = '';
}

Re: how to pass opencart address to Paypal Standard?

Posted: Mon Jul 10, 2017 10:36 am
by RideTheWave
On your 4th last line you forgot a semi-colon which gave a syntax error. Also, since Canada follows the exact same phone number structure as the US (3 digit area code, 3 digit prefix, and 4 for the rest), I changed the code a little to look like this:

Code: Select all

 $phone = preg_replace("/[^0-9.]/", "", html_entity_decode($order_info['telephone'], ENT_QUOTES, 'UTF-8'));
			if (($order_info['payment_iso_code_2'] == 'US')||($order_info['payment_iso_code_2'] == 'CA')) {
				$data['night_phone_a'] = substr($phone, 0, 3);
				$data['night_phone_b'] = substr($phone, 3, 3);
				$data['night_phone_c'] = substr($phone, 6);
            } else {
			    $data['night_phone_a'] = '';
	            $data['night_phone_b'] = substr($phone, 0, 16);
            	$data['night_phone_c'] = '';
But I have to tell you, this seems to be a hit or miss thing. Sometimes the phone number is not populated, then I'll press the Back button a few times, then press Confirm Order again (with the exact same details), and then the phone number field will be populated. So it doesn't seem to be a consistent thing. Are you finding the same? Oh well, I guess it's not going to be a huge inconvenience for a customer to enter their phone number again (at least I hope not)...

Re: how to pass opencart address to Paypal Standard?

Posted: Mon Jul 10, 2017 8:15 pm
by ADD Creative
For UK numbers it worked every time. For US numbers there seemed to be some validation going on, when I tested in the sandbox. The numbers that worked always worked and the numbers that didn't always failed, as far as I could tell.

Re: how to pass opencart address to Paypal Standard?

Posted: Tue Oct 31, 2017 12:29 pm
by tingwing
I have a naive thought ,if use paypal express checkout,would the problem disappear?

Re: how to pass opencart address to Paypal Standard?

Posted: Tue Oct 31, 2017 6:40 pm
by ADD Creative
The PayPal Express module passes both the payment and the shipping address, so should not have the problem or the shipping address not being passed to PayPal.

Re: how to pass opencart address to Paypal Standard?

Posted: Fri Nov 03, 2017 9:25 pm
by tingwing
thanks

for paypal standard,the simple solution.
go to catalog\view\theme\default\template\extension\payment\pp_standard.tpl
edit
name="no_shipping" value="1"
to
name="no_shipping" value="2"