1
votes

I am trying to send passthrough data in a paypal paynow button and have paypal return that data to my php page when user clicks “return to merchant” button after paying.

For this I am using the “return” facility in the paypal button, together with rm=2 to send all the data back as post. However, I cannot get it to work. Here is my paypal button html:

<form name="paypal2" action="https://www.paypal.com/cgi-bin/webscr"     method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="xxx">
<input type="hidden" name="invoice" value="testinvoice_fromcode2">
<input type="hidden" name="custom" value="testcustom_fromcode1">
<input type="hidden" name="on0" value="yes"><!--agreetc-->
<input type="hidden" name="os0" value="<?php echo $aid; ?>">
<input type="hidden" name="on1" value="<?php echo $id; ?>">
<input type="hidden" name="os1" value="<?php echo $agent; ?>">
<input type="hidden" name="return" value=http://www.example.com/Admin/conpanel/privat/phpvendorpaidad.php>
<input type="hidden" name="rm" value="2">
<input id="submit" type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

In the IPN notification, paypal renders: os0 as option_selection1, os1 as option_selection2, on0 as option_name1, on1 as option_name2,

I know that on0 and os0 are supposed to be used as name value pairs but way back in 2009 when I first wrote this script there were only 2 sets allowed and therefore I used all 4 to carry values and it worked then.

But essentially, I cannot understand why

<input type="hidden" name="return" value=http://www.example.com/Admin/conpanel/privat/phpvendorpaidad.php>
<input type="hidden" name="rm" value="2">

is not working.

I cannot pick up these values in the receiving script, phpvendorpaidad.php, either as

$aid=$_REQUEST['option_selection1'];

or as

$aid=$_REQUEST['os0'];

for example.

Can anyone see what I am doing wrong? Much appreciated.

I also have an IPN listener page that is working normally. Could another way be to build this in to the IPN listener page using javascript to send the form data automatically on page onload?

2

2 Answers

2
votes

Is paypal actually POSTing to your return script or using GET? In the latter case, you can see the txn_id and some other info in the query string, but you will NOT get the whole payment detail data.

If you have Auto Return set to On (meaning the user get automatically redirected back to your site, without having to click a button), then paypal with send a GET request and will include only a few items.

var_dump($_REQUEST) and var_dump($_POST) in your script to see what you are getting.

0
votes

Actually the problem lay in defective if/else logic in my return code, which was set up in 2009 to handle the GET variables that Paypal was sending to the return script in those days. This logic had to differentiate between the POSTed data received from a preceeding form on my server and the GET data received from Paypal. Paypal appears to have chenged since 2009 and no longer sends GET data to the return script but POST data via

 <input type="hidden" name="return" value=http://www.example.com/Admin/conpanel/privat/phpvendorpaidad.php>
 <input type="hidden" name="rm" value="2">

Once this was corrected the program worked.

However, I was only able to discover the problem thanks to the brilliant suggestion from JBart to var_dump($_REQUEST) (or the more easily read print_r($_REQUEST)). Without this I would still have been floundering. So cheers JBart, would love to buy you a drink if you are in the neighbourhood (NW London)!

And no, I didn't need to extract any variables from the received POSTed array (see my last comment above), just normal '$payment_status = $_POST['payment_status'];'. In this I had misinterpreted another thread on the subject in "How can I get posted data passed along when the user is first redirected through Paypal?"