• [PHP] Paypal Subscription IPN
    4 replies, posted
Alright I've been trying for months now and I still can't get this correct. I have a donation system that adds a user to a MySQL database. Simple enough. What I haven't gotten was the subscription part to even remotely work. Please if anyone could help or lend me a script they use I would be very appreciative. Thanks.
Or, rather, post what it's not working so we can give it a look
this is what im using now.. [php] <?php /** * PHP-PayPal-IPN Example * * This shows a basic example of how to use the IpnListener() PHP class to * implement a PayPal Instant Payment Notification (IPN) listener script. * * For a more in depth tutorial, see my blog post: * http://www.micahcarrick.com/paypal-ipn-with-php.html * * This code is available at github: * https://github.com/Quixotix/PHP-PayPal-IPN * * @package PHP-PayPal-IPN * @author Micah Carrick * @copyright (c) 2011 - Micah Carrick * @license http://opensource.org/licenses/gpl-3.0.html */ /* Since this script is executed on the back end between the PayPal server and this script, you will want to log errors to a file or email. Do not try to use echo or print--it will not work! Here I am turning on PHP error logging to a file called "ipn_errors.log". Make sure your web server has permissions to write to that file. In a production environment it is better to have that log file outside of the web root. */ ini_set('log_errors', true); ini_set('error_log', dirname(__FILE__).'/ipn_errors.log'); // instantiate the IpnListener class include('ipnlistener.php'); $listener = new IpnListener(); /* When you are testing your IPN script you should be using a PayPal "Sandbox" account: https://developer.paypal.com When you are ready to go live change use_sandbox to false. */ $listener->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. */ $txntype = $_POST['txn_type']; $date = $_POST['subscr_date']; $paymentstatus = $_POST['payment_status']; $paymentdate = $_POST['payment_date']; $amount = $_POST['mc_gross']; $currency = $_POST['mc_currency']; $custom = $_POST['custom']; $custom = explode("|", $custom); $donationtype = $custom[0]; $steamid = $custom[1]; $hostname="xxxxxxx"; $username="xxxxxxxxxxx"; $password="xxxxxxx"; $db="xxxxxxxx"; $table="darkrp_list"; if ($currency == 'USD' && $paymentstatus == 'Completed') { $con = mysql_connect($hostname,$username, $password); mysql_select_db($db); //mysql_query("UPDATE $table SET status='$donationtype' WHERE steam='$steamid'"); if($txntype == 'subscr_signup') { mysql_query("UPDATE $table SET status='green', date='$date' WHERE id='1'"); mysql_close($con); } } } 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. */ file_put_contents('FailedAttempt.txt', 'Someone failed an IPN attempt.'); } ?> [/php] it works without the subscriptions but i have no idea on how to make the subscription part to it.
On your paypal account there should be an option under IPN for a callback. Set that to the URL of that file.
[QUOTE=SataniX;40147674]On your paypal account there should be an option under IPN for a callback. Set that to the URL of that file.[/QUOTE] it calls when i run it though sandbox.
Sorry, you need to Log In to post a reply to this thread.