views:

178

answers:

3

Hey,

So I am curious on how to setup a recurring payment like I have here, but I need paypal to return to me if the payment was successful, and ONCE it is go to X.PHP page where I update the MySQL User Table stating he has setup payment. If anyone could give me some guidance that would be great.

   echo '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">';
    echo '<input type="hidden" name="cmd" value="_xclick-subscriptions" />';
    echo '<input type="hidden" name="business" value="[email protected]" />';
    echo '<input type="hidden" name="item_name" value="Subscription" />';
    echo '<input type="hidden" name="currency_code" value="CAD" />';
    echo '<input type="hidden" name="a3" value="0.01" />';
    echo '<input type="hidden" name="p3" value="1" />';
    echo '<input type="hidden" name="t3" value="M" />';
    echo '<input type="hidden" name="return" value="success.php" />';
    echo '<input type="hidden" name="cancel_return" value="fail.php" />';
    echo '<input type="hidden" name="src" value="1" />';
    echo '<input type="hidden" name="sra" value="1" />';
    echo '<input type="hidden" name="receiver_email" value="[email protected]" />';
    echo '<input type="hidden" name="mrb" value="R-3WH47588B4505740X" />';
    echo '<input type="hidden" name="pal" value="ANNSXSLJLYR2A" />';
    echo '<input type="hidden" name="no_shipping" value="1" />';
    echo '<input type="hidden" name="no_note" value="1" />';
    echo '<input name="submit" type="submit" value="Use PayPal" />';
    echo '</form>';
A: 

If I remember right paypal asks you to use CURL posts to their system and then you have the option of parsing a serialized PHP array that contains success and error codes. You will need to check their docs for your specific gateway setup, but you won't just be getting a true/false you are going to get a lot of data and are going to have to know how to read their codes to get anything useful back. I will check some old code I have and post an update in a few minutes.

EDIT WITH ADDITIONAL INFO: I looked through a gateway integration I have with paypal and it looks like the closest thing you are going to get to a TRUE/FALSE is to take the result from your call to their server and check the array for the key 'ACK' and see if it equals 'SUCCESS' or 'SUCCESSWITHWARNINGS':

if( strtoupper( $result['ACK'] ) == 'SUCCESS' || strtoupper( $result['ACK']) == 'SUCCESSWITHWARNING' )
    {
        //DO SOMETHING
    }

Once again I will say though that to make your app work correctly in all instance you will have to follow this check with quite a few others to be sure that any warning or delay codes are dealt with and that requested retry attempts are completed. It gets a little complicated but if you follow their manuals you'll get it working.. Just do a LOT of testing in the sandbox before you send it live!

angryCodeMonkey
A: 

This seems to give a good response to this issue.

http://www.web-development-blog.com/archives/easy-payments-using-paypal-ipn/

Justin
+1  A: 

I use Micah Carrick's Paypal IPN class to send payment data to paypal. This code is same with examples from Paypal, but Micah has wrap it into a class so it's easier to use.

To update your own database, do it in the ipn validation page, so the buyer don't have to click return to your site after do the payment.

About recurring payment, Paypal have a great documentation about this.

Donny Kurnia