MillerMedia
MillerMedia

Reputation: 3671

PayPal POST variables not working (PHP)

I am attempting to set up a PayPal 'subscription' payment button on a site I'm working on. It's a form that gets sent to PayPal and then sends the user back to a return URL when the transaction is successfully completed. I'm currently using the PayPal Sandbox to test this. The problem is that the POST variables are not being sent to the thank you page (which is a PHP page FYI).

The reason I need this is that I'm updating a database and if a user successfully completes a transaction, it needs to take a look at the variables being returned, determine that the user paid and then update the user's information in the MySQL database automatically.

I've been in touch with a PayPal rep for the past two weeks and they can't seem to help. I've also researched all over the web and Stack Overflow and none of the current answers seem to address my issue. Here's what I've tried:

Here is the code being used on the two pages. Feel free to go to these pages as well to test out the issue yourself and see that is doesn't work:

Page

http://www.miller-media.com/sites/paypal_test/test_form.php

Code

<html>
<head>
</head>
<body>
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" id="paypal_form" method="post" target="_top">
        <input type="hidden" name="cmd" value="_xclick-subscriptions">
        <input type="hidden" name="item_name" value="Test Monthly Subscription">
        <input type="hidden" name="business" value="[email protected]">
        <input type="hidden" name="a3" value="7.00">
        <input type="hidden" name="p3" value="1">
        <input type="hidden" name="t3" value="M">
        <input type="hidden" name="src" value="1">
        <input type="hidden" name="sra" value="1">
        <input type="hidden" name="no_note" value="1">
        <input type="hidden" name="custom" value="20130731 it worked">
        <input type="hidden" name="cancel_return" value="http://www.miller-media.com">
        <input type="hidden" name="return" value="http://www.miller-media.com/sites/paypal_test/mmiller.php">
        <input type="hidden" name="rm" value="2">
        <input type="submit">
    </form>
</body>
</html>

And the return URL

Page

http://www.miller-media.com/sites/paypal_test/mmiller.php

Code

<html>
<head>
</head>
<body>
    TEST FOR MILLER MEDIA

    THIS IS FOR POST 
    <?php
        echo ("Custom = " . $_POST['custom']);
        echo ("Transaction = " . $_POST['txn_id']);
        echo ("First name = " . $_POST['first_name']);
        echo ("Last name = ". $_POST['last_name']);
    ?>


</body>
</html>

This code above is what was provided by the PayPal rep to me (mine was slightly different when I first set it up). If you go through the process (with a PayPal sandbox account), no variables will show up on the thank you page (mmiller.php).

Here is a message that the PayPal rep provided to me and it showed that he get variables working correctly. It looks like he was testing locally, so I'm not sure if that had something to do with it:

Here is the screenshot http://i.imgur.com/zno0UkK.jpg . But I just noticed I was using a Buy Now button but your button is a subscription.

The txn_id is not returned for subscription (that is by design) . Please see below for variables that are returned. https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables#id091EB0901HT

This is what I get with subscription signup http://i.imgur.com/BOrw1Hn.jpg . A txn_id is not returned.

Here is also the complete POST data :

POSTDATA=txn_type=subscr_signup&subscr_id=I-0RSGVWA904CF&last_name=Connor&residence_country=GB&mc_currency=USD&item_name=StormAware+Monthly+Subscription&business=mbizz%40paypal.com&amount3=7.00&recurring=1&address_street=1+Main+Terrace&payer_status=verified&payer_email=UKrealPro%40paypal.com&address_status=confirmed&first_name=John&receiver_email=mbizz%40paypal.com&address_country_code=GB&payer_id=UXPBYWUW8ZDHA&address_city=Wolverhampton&reattempt=1&payer_business_name=John+Connor%27s+Test+Store&address_state=West+Midlands&subscr_date=16%3A37%3A38+Aug+05%2C+2013+PDT&address_zip=W12+4LQ&custom=20130731+it+worked&charset=windows-1252&period3=1+M&address_country=United+Kingdom&mc_amount3=7.00&address_name=John+Connor%27s+Test+Store&auth=AOgsYFMneBuxymkc0UoZ6OI6D-BXCQmWRz5xyilJR1-7uCvNI1kB Om1eHPbogzB7YnoOUIAZZiFOrx0ZcUgN-gQ&form_charset=UTF-8

Any help would be greatly appreciated as this has frustrated me for the past several weeks. Thank you in advance!

Upvotes: 0

Views: 2417

Answers (1)

Drew Angell
Drew Angell

Reputation: 26036

If you want POST data included with your return page you'll need to setup PDT (payment data transfer.)

This is not recommended for updating databases or anything that you need to make sure happens, though, because even with Auto-Return enabled there is no guarantee the user will actually make it back to your site and you will undoubtedly end up with transactions that don't get updated correct.

That is why IPN is recommended instead. IPN will be triggered regardless of whether or not the user makes it back to your site.

Keep your thank you page simple and do all of your post-payment processing within IPN.

Upvotes: 1

Related Questions