Skip to content

Instantly share code, notes, and snippets.

@Basilakis
Last active September 9, 2021 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Basilakis/ee0858742efd9ddfad008ecba2c812b5 to your computer and use it in GitHub Desktop.
Save Basilakis/ee0858742efd9ddfad008ecba2c812b5 to your computer and use it in GitHub Desktop.
Multiple IPN for PayPal, Stripe etc
<?php
ini_set( 'max_execution_time', 0 ); /* Do not abort with timeouts */
ini_set( 'display_errors', 'Off' ); /* Do not display any errors to anyone */
$urls = array(); /* The broadcast session queue */
/* List of IPN listener points */
$ipns = array(
'edd' => 'https://creativeg.gr/?edd-listener=IPN',
'edd_payments' => 'https://creativeg.gr/?Paypal_For_Edd=&action=ipn_handler',
'rcp' => 'https://creativeg.gr/?listener=EIPN',
'edd_rp' => 'https://creativeg.gr/?edd-listener=eppe'
);
/* Broadcast */
if ( !sizeof($urls) ) $urls = $ipns; /* No URLs have been matched */
$urls = array_unique( $urls ); /* Unique, just in case */
/* Broadcast (excluding IPNs from the list according to filter is possible */
foreach ( $urls as $url ) broadcast( $url );
header( 'HTTP/1.1 200 OK', true, 200 );
exit(); /* Thank you, bye */
/* Perform a simple cURL-powered proxy request to broadcast */
function broadcast( $url ) {
/* Format POST data accordingly */
$data = array();
foreach ($_POST as $key => $value) $data []= urlencode($key).'='.urlencode($value);
$data = implode('&', $data);
/* Log the broadcast */
file_put_contents('_logs/'.time().'.'.reverse_lookup( $url ).'-'.rand(1,100), $data);
$ch = curl_init(); /* Initialize */
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, strlen($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch); /* Execute HTTP request */
curl_close($ch); /* Close */
}
function reverse_lookup( $url ) {
global $ipns;
foreach ( $ipns as $tag => $_url ) {
if ( $url == $_url ) return $tag;
}
return 'unknown';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment