daily pastebin goal
8%
SHARE
TWEET

Paypal MultipleIPN with receiver_email and 302 Redirect mod

a guest Jun 26th, 2013 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   /*
  3.    * This is a PayPal IPN (Instant Payment Notification) broadcaster
  4.    * Since PayPal does not provide any straightforward way to add
  5.    * multiple IPN listeners we'll have to create a central IPN
  6.    * listener that will broadcast (or filter and dispatch) Instant
  7.    * Payment Notifications to different destinations (IPN listeners)
  8.    *
  9.    * Destination IPN listeners must not panic and recognize IPNs sent
  10.    * by this central broadcast as valid ones in terms of source IP
  11.    * and any other fingerprints. Any IP filtering must add this host,
  12.    * other adjustments made as necessary.
  13.    *
  14.    * IPNs are logged into files for debugging and maintenance purposes
  15.    *
  16.    * this code comes with absolutely no warranty
  17.    * http://codeseekah.com/2012/02/11/how-to-setup-multiple-ipn-receivers-in-paypal/
  18.    *
  19.    * This modification checks the receiver_email field to decide on where to broadcast
  20.    * The broadcast has been modified from curl to a 302 redirect
  21.   */
  22.  
  23.   ini_set( 'max_execution_time', 0 ); /* Do not abort with timeouts */
  24.   ini_set( 'display_errors', 'Off' ); /* Do not display any errors to anyone */
  25.   $urls = array(); /* The broadcast session queue */
  26.  
  27.   /* List of IPN listener points */
  28.   $ipns = array(
  29.       'store1' => 'http://store1.com/ipn.php',
  30.       'store2' => 'http://store2.com/paypal_ipn.php',
  31.       'store3' => 'http://store3.com/paypal/ipn.php'
  32.     );
  33.   $emais = array(
  34.       'store1' => 'store1@gmail.com',
  35.       'store2' => 'store2@yahoo.com',
  36.       'store3' => 'store3@hotmail.com'
  37.     );
  38.    
  39.   /* Fingerprints */
  40.  
  41.   if ( /* My Store IPN Fingerprint */
  42.     $_POST["receiver_email"] == $emails['store1']
  43.     header("HTTP/1.1 302 Moved Temporarily");
  44.     header("Location: $ipns['store1']");
  45.   ) urls []= $ipns['store1'];
  46.  
  47.  
  48.   if ( /* My Other Store IPN Fingerprint */
  49.     $_POST["receiver_email"] == $emails['store2']
  50.     header("HTTP/1.1 302 Moved Temporarily");
  51.     header("Location: $ipns['store2']");
  52.   ) urls []= $ipns['store2'];
  53.  
  54.  
  55.   /* My Other And Better Store IPN Fingerprint */
  56.   if (
  57.     $_POST["receiver_email"] == $emails['store3']
  58.     header("HTTP/1.1 302 Moved Temporarily");
  59.     header("Location: $ipns['store3']");
  60.   ) urls []= $ipns['store3'];
  61.  
  62.   /* ... */
  63.  
  64.  
  65.   /* Broadcast */
  66.  
  67.   if ( !sizeof($urls)
  68.     header( 'HTTP/1.1 200 OK', true, 200 );
  69.   ) $urls = $ipns; /* No URLs have been matched */
  70.   $urls = array_unique( $urls ); /* Unique, just in case */
  71.  
  72.   /* Log data (excluding IPNs from the list according to filter is possible */
  73.   foreach ( $urls as $url ) log( $url );
  74.  
  75.   header( 'HTTP/1.1 200 OK', true, 200 );
  76.   exit(); /* Thank you, bye */
  77.  
  78.   /* Log the data */
  79.   function log( $url ) {
  80.  
  81.     /* Format POST data accordingly */
  82.     $data = array();
  83.     foreach ($_POST as $key => $value) $data []= urlencode($key).'='.urlencode($value);
  84.     $data = implode('&', $data);
  85.  
  86.     /* Log the broadcast */
  87.     file_put_contents('_logs/'.time().'.'.reverse_lookup( $url ).'-'.rand(1,100), $data);
  88.   }
  89.  
  90.   function reverse_lookup( $url ) {
  91.     global $ipns;
  92.     foreach ( $ipns as $tag => $_url ) {
  93.       if ( $url == $_url ) return $tag;
  94.     }
  95.     return 'unknown';
  96.   }
  97. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top