use_sandbox = true; /* By default the IpnListener object is going going to post the data back to PayPal using cURL over a secure SSL connection. This is the recommended way to post the data back, however, some people may have connections problems using this method. To post over standard HTTP connection, use: $listener->use_ssl = false; To post using the fsockopen() function rather than cURL, use: $listener->use_curl = false; */ /* The processIpn() method will encode the POST variables sent by PayPal and then POST them back to the PayPal server. An exception will be thrown if there is a fatal error (cannot connect, your server is not configured properly, etc.). Use a try/catch block to catch these fatal errors and log to the ipn_errors.log file we setup at the top of this file. The processIpn() method will send the raw data on 'php://input' to PayPal. You can optionally pass the data to processIpn() yourself: $verified = $listener->processIpn($my_post_data); */ try { $listener->requirePostMethod(); $verified = $listener->processIpn(); } catch (Exception $e) { error_log($e->getMessage()); exit(0); } /* The processIpn() method returned true if the IPN was "VERIFIED" and false if it was "INVALID". */ if ($verified) { /* Once you have a verified IPN you need to do a few more checks on the POST fields--typically against data you stored in your database during when the end user made a purchase (such as in the "success" page on a web payments standard button). The fields PayPal recommends checking are: 1. Check the $_POST['payment_status'] is "Completed" 2. Check that $_POST['txn_id'] has not been previously processed 3. Check that $_POST['receiver_email'] is your Primary PayPal email 4. Check that $_POST['payment_amount'] and $_POST['payment_currency'] are correct Since implementations on this varies, I will leave these checks out of this example and just send an email using the getTextReport() method to get all of the details about the IPN. */ mail('YOUR EMAIL ADDRESS', 'Verified IPN', $listener->getTextReport()); } else { /* An Invalid IPN *may* be caused by a fraudulent transaction attempt. It's a good idea to have a developer or sys admin manually investigate any invalid IPN. */ mail('YOUR EMAIL ADDRESS', 'Invalid IPN', $listener->getTextReport()); } ?>