Guest User

Untitled

a guest
Mar 10th, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.83 KB | None | 0 0
  1. <?php
  2. /**
  3.  *  PHP-PayPal-IPN Example
  4.  *
  5.  *  This shows a basic example of how to use the IpnListener() PHP class to
  6.  *  implement a PayPal Instant Payment Notification (IPN) listener script.
  7.  *
  8.  *  For a more in depth tutorial, see my blog post:
  9.  *  http://www.micahcarrick.com/paypal-ipn-with-php.html
  10.  *
  11.  *  This code is available at github:
  12.  *  https://github.com/Quixotix/PHP-PayPal-IPN
  13.  *
  14.  *  @package    PHP-PayPal-IPN
  15.  *  @author     Micah Carrick
  16.  *  @copyright  (c) 2011 - Micah Carrick
  17.  *  @license    http://opensource.org/licenses/gpl-3.0.html
  18.  */
  19.  
  20.  
  21. ini_set('log_errors', true);
  22. ini_set('error_log', 'ipn_errors.log');
  23.  
  24.  
  25. // instantiate the IpnListener class
  26. include('ipnlistener.php');
  27. include('include/config.php');
  28. $listener = new IpnListener();
  29.  
  30. $listener->use_sandbox = false;
  31.  
  32. /*
  33. By default the IpnListener object is going  going to post the data back to PayPal
  34. using cURL over a secure SSL connection. This is the recommended way to post
  35. the data back, however, some people may have connections problems using this
  36. method.
  37.  
  38. To post over standard HTTP connection, use:
  39. $listener->use_ssl = false;
  40.  
  41. To post using the fsockopen() function rather than cURL, use:
  42. $listener->use_curl = false;
  43. */
  44.  
  45. /*
  46. The processIpn() method will encode the POST variables sent by PayPal and then
  47. POST them back to the PayPal server. An exception will be thrown if there is
  48. a fatal error (cannot connect, your server is not configured properly, etc.).
  49. Use a try/catch block to catch these fatal errors and log to the ipn_errors.log
  50. file we setup at the top of this file.
  51.  
  52. The processIpn() method will send the raw data on 'php://input' to PayPal. You
  53. can optionally pass the data to processIpn() yourself:
  54. $verified = $listener->processIpn($my_post_data);
  55. */
  56. try {
  57.     $listener->requirePostMethod();
  58.     $verified = $listener->processIpn();
  59. } catch (Exception $e) {
  60.     error_log($e->getMessage());
  61.     exit(0);
  62. }
  63.  
  64.  
  65. if ($verified) {
  66. $errmsg = '';
  67.     if ($_POST['payment_status'] != 'Completed') {
  68.         exit(0);
  69.     }
  70.     if ($_POST['receiver_email'] != $paypal) {
  71.         $errmsg .= "'receiver_email' does not match: ";
  72.         $errmsg .= $_POST['receiver_email']."\n";
  73.     }
  74.     if ($_POST['mc_currency'] != $currency_code) {
  75.         $errmsg .= "'mc_currency' does not match: ";
  76.         $errmsg .= $_POST['mc_currency']."\n";
  77.     }
  78.     if (empty($errmsg)) {
  79.     $useremail = $_POST['item_number'];
  80.     error_log($useremail);
  81.     $gross = $_POST['mc_gross'];
  82.     error_log($gross);
  83.     $newtoken = $_POST['custom'];
  84.     $firstname = $_POST['first_name'];
  85.     $lastname = $_POST['last_name'];
  86.     $payeremail = $_POST['payer_email'];
  87.     $current_date = date('l jS \of F Y h:i:s A');
  88.     $package1 = "10";
  89.     $package2 = "25";
  90.     $package3 = "50";
  91.     $package4 = "100";
  92.     $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
  93.     mysql_select_db($mysql_database, $bd) or die("Could not select database");
  94.     $crtable = sprintf("CREATE TABLE IF NOT EXISTS `transactions` (
  95.       `id` int NOT NULL AUTO_INCREMENT,
  96.       `registered_email` varchar(64) NOT NULL,
  97.       `tokens_purchased` varchar(16) NOT NULL,
  98.       `total_paid` varchar(16) NOT NULL,
  99.       `first_name` varchar(40) NOT NULL,
  100.       `last_name` varchar(40) NOT NULL,
  101.       `paypal_email` varchar(64) NOT NULL,
  102.       `date` varchar(64) NOT NULL,
  103.       PRIMARY KEY (id))");
  104.     mysql_query($crtable);
  105.     }
  106.  
  107.     if ($_POST['custom'] == $package1) {
  108.        if ($_POST['mc_gross'] == $ore1) {
  109.             $updatetbl = sprintf("UPDATE dep SET tokens = tokens + $package1 WHERE email = '$useremail'");
  110.             $record_transaction = sprintf("INSERT INTO transactions (registered_email, tokens_purchased, total_paid, first_name, last_name, paypal_email, date)
  111.             VALUES ('$useremail','$newtoken','$gross','$firstname','$lastname','$payeremail','$current_date')");
  112.             mysql_query($updatetbl);
  113.             mysql_query($record_transaction);
  114.        }
  115.     }
  116.     if ($_POST['custom'] == $package2) {
  117.        if ($_POST['mc_gross'] == $ore2) {
  118.             $updatetbl = sprintf("UPDATE dep SET tokens = tokens + $package2 WHERE email = '$useremail'");
  119.             $record_transaction = sprintf("INSERT INTO transactions (registered_email, tokens_purchased, total_paid, first_name, last_name, paypal_email, date)
  120.             VALUES ('$useremail','$newtoken','$gross','$firstname','$lastname','$payeremail','$current_date')");
  121.             mysql_query($updatetbl);
  122.             mysql_query($record_transaction);
  123.        }
  124.     }
  125.     if ($_POST['custom'] == $package3) {
  126.        if ($_POST['mc_gross'] == $ore3) {
  127.             $updatetbl = sprintf("UPDATE dep SET tokens = tokens + $package3 WHERE email = '$useremail'");
  128.             $record_transaction = sprintf("INSERT INTO transactions (registered_email, tokens_purchased, total_paid, first_name, last_name, paypal_email, date)
  129.             VALUES ('$useremail','$newtoken','$gross','$firstname','$lastname','$payeremail','$current_date')");
  130.             mysql_query($updatetbl);
  131.             mysql_query($record_transaction);
  132.        }
  133.     }
  134.     if ($_POST['custom'] == $package4) {
  135.        if ($_POST['mc_gross'] == $ore4) {
  136.             $updatetbl = sprintf("UPDATE dep SET tokens = tokens + $package4 WHERE email = '$useremail'");
  137.             $record_transaction = sprintf("INSERT INTO transactions (registered_email, tokens_purchased, total_paid, first_name, last_name, paypal_email, date)
  138.             VALUES ('$useremail','$newtoken','$gross','$firstname','$lastname','$payeremail','$current_date')");
  139.             mysql_query($updatetbl);
  140.             mysql_query($record_transaction);
  141.        }
  142.     }
  143.  
  144. } else {
  145.     mail($admin_email, 'Donator Express - Invalid Payment Detected - Payment Log', $listener->getTextReport());
  146. }
  147.  
  148. ?>
Advertisement
Add Comment
Please, Sign In to add comment