Consulter le code

A PayPal IPN tool

This is a PayPal IPN tool to help make multiple IPN for 1 PayPal
account.
Original file grabbed here :
https://codeseekah.com/wp-content/uploads/2012/02/paypal_multiple_ipn.ph
p_.zip

Ivan FELICITE a écrit le 29/02/2016 00:59:05
Affichage de 1 fichier(s) changé(s)
1 1
new file mode 100644
... ...
@@ -0,0 +1,93 @@
0
+<?php
1
+	/*
2
+	 * This is a PayPal IPN (Instant Payment Notification) broadcaster
3
+	 * Since PayPal does not provide any straightforward way to add
4
+	 * multiple IPN listeners we'll have to create a central IPN
5
+	 * listener that will broadcast (or filter and dispatch) Instant
6
+	 * Payment Notifications to different destinations (IPN listeners)
7
+	 *
8
+	 * Destination IPN listeners must not panic and recognize IPNs sent
9
+	 * by this central broadcast as valid ones in terms of source IP
10
+	 * and any other fingerprints. Any IP filtering must add this host,
11
+	 * other adjustments made as necessary.
12
+	 *
13
+	 * IPNs are logged into files for debugging and maintenance purposes
14
+     *
15
+     * this code comes with absolutely no warranty
16
+	 * http://codeseekah.com
17
+	*/
18
+
19
+	ini_set( 'max_execution_time', 0 ); /* Do not abort with timeouts */
20
+	ini_set( 'display_errors', 'Off' ); /* Do not display any errors to anyone */
21
+	$urls = array(); /* The broadcast session queue */
22
+
23
+	/* List of IPN listener points */
24
+	$ipns = array(
25
+			'mystore' => 'http://mystore.com/ipn.php',
26
+			'myotherstore' => 'http://mybigstore.com/paypal_ipn.php',
27
+			'myotherandbetterstore' => 'http://slickstore.com/paypal/ipn.php'
28
+		);
29
+		
30
+	/* Fingerprints */
31
+
32
+	if ( /* My Store IPN Fingerprint */
33
+		preg_match( '#^\d+\|[a-f0-9]{32}$#', $_POST['custom'] ) /* Custom hash */
34
+		and $_POST['num_cart_items'] == 2 /* alwayst 1 item in cart */
35
+		and strpos( $_POST['item_name1'], 'MySite.com Product' ) == 0 /* First item name */
36
+	) $urls []= $ipns['mystore']; /* Choose this IPN URL if all conditions have been met */
37
+
38
+	if ( /* My Other Store IPN Fingerprint */
39
+		sizeof( explode('_', $_POST['custom']) ) == 7 /* has 7 custom pieces */
40
+	) $urls []= $ipns['myotherstore']; /* Choose this IPN URL if all conditions have been met */
41
+
42
+	/* My Other And Better Store IPN Fingerprint */
43
+	$custom = explode('|', $_POST['custom']);
44
+	if (
45
+		isset($custom[2]) and $custom[2] == 'FROM_OB_STORE' /* custom prefixes */
46
+	) $urls []= $ipns['myotherandbetterstore']; /* Choose this IPN URL if all conditions have been met */
47
+
48
+	/* ... */
49
+	
50
+	
51
+	/* Broadcast */
52
+	
53
+	if ( !sizeof($urls) ) $urls = $ipns; /* No URLs have been matched */
54
+	$urls = array_unique( $urls ); /* Unique, just in case */
55
+
56
+	/* Broadcast (excluding IPNs from the list according to filter is possible */
57
+	foreach ( $urls as $url ) broadcast( $url );
58
+
59
+	header( 'HTTP/1.1 200 OK', true, 200 );
60
+	exit(); /* Thank you, bye */
61
+
62
+	/* Perform a simple cURL-powered proxy request to broadcast */
63
+	function broadcast( $url ) {
64
+
65
+		/* Format POST data accordingly */
66
+		$data = array();
67
+		foreach ($_POST as $key => $value) $data []= urlencode($key).'='.urlencode($value);
68
+		$data = implode('&', $data);
69
+
70
+		/* Log the broadcast */
71
+		file_put_contents('_logs/'.time().'.'.reverse_lookup( $url ).'-'.rand(1,100), $data);
72
+
73
+		$ch = curl_init(); /* Initialize */
74
+
75
+		curl_setopt($ch, CURLOPT_URL, $url);
76
+		curl_setopt($ch, CURLOPT_POST, count($data));
77
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
78
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
79
+
80
+		curl_exec($ch); /* Execute HTTP request */
81
+
82
+		curl_close($ch); /* Close */
83
+	}
84
+
85
+	function reverse_lookup( $url ) {
86
+		global $ipns;
87
+		foreach ( $ipns as $tag => $_url ) {
88
+			if ( $url == $_url ) return $tag;
89
+		}
90
+		return 'unknown';
91
+	}
92
+?>