PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110731
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110731
260917 260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 All 189 releases
s2member / includes / classes / paypal-notify-in.inc.php

paypal-notify-in.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110731, at includes/classes/paypal-notify-in.inc.php

196 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * s2Member's PayPal® IPN handler ( inner processing routines ).
4 *
5 * Copyright: © 2009-2011
6 * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
7 * ( coded in the USA )
8 *
9 * Released under the terms of the GNU General Public License.
10 * You should have received a copy of the GNU General Public License,
11 * along with this software. In the main directory, see: /licensing/
12 * If not, see: {@link http://www.gnu.org/licenses/}.
13 *
14 * @package s2Member\PayPal
15 * @since 3.5
16 */
17 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
18 exit ("Do not access this file directly.");
19 /**/
20 if (!class_exists ("c_ws_plugin__s2member_paypal_notify_in"))
21 {
22 /**
23 * s2Member's PayPal® IPN handler ( inner processing routines ).
24 *
25 * @package s2Member\PayPal
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_paypal_notify_in
29 {
30 /**
31 * Handles PayPal® IPN processing.
32 *
33 * These same routines also handle s2Member Pro/PayPal® Pro operations;
34 * giving you the ability *( as needed )* to Hook into these routines using
35 * WordPress® Hooks/Filters; as seen in the source code below.
36 *
37 * Please do NOT modify the source code directly.
38 * Instead, use WordPress® Hooks/Filters.
39 *
40 * For example, if you'd like to add your own custom conditionals, use:
41 * ``add_filter ("ws_plugin__s2member_during_paypal_notify_conditionals", "your_function");``
42 *
43 * @package s2Member\PayPal
44 * @since 3.5
45 *
46 * @attaches-to: ``add_action("init");``
47 *
48 * @return null Or exits script execution after handling IPN procesing.
49 */
50 public static function paypal_notify ()
51 {
52 global $current_site, $current_blog; /* For Multisite support. */
53 /**/
54 do_action ("ws_plugin__s2member_before_paypal_notify", get_defined_vars ());
55 /**/
56 if (!empty ($_GET["s2member_paypal_notify"]) && ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_business"] || !empty ($_GET["s2member_paypal_proxy"])))
57 {
58 @ignore_user_abort (true); /* Important. Continue processing even if/when the connection is broken by the sending party. */
59 /**/
60 include_once ABSPATH . "wp-admin/includes/admin.php"; /* Get administrative functions. Needed for `wp_delete_user()`. */
61 /**/
62 c_ws_plugin__s2member_email_configs::email_config_release (); /* Release Filters on wp_mail() / From: headers. */
63 /**/
64 if (is_array ($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_postvars ()) && ($_paypal = $paypal) && ($_paypal_s = serialize ($_paypal)))
65 {
66 $paypal["s2member_log"][] = "IPN received on: " . date ("D M j, Y g:i:s a T");
67 $paypal["s2member_log"][] = "s2Member POST vars verified " . ((!empty ($paypal["proxy_verified"])) ? "with a Proxy Key" : "through a POST back to PayPal®.");
68 /**/
69 $payment_status_issues = "/^(failed|denied|expired|refunded|partially_refunded|reversed|reversal|canceled_reversal|voided)$/i";
70 /**/
71 $paypal["subscr_gateway"] = (!empty ($_GET["s2member_paypal_proxy"])) ? esc_html (trim (stripslashes ($_GET["s2member_paypal_proxy"]))) : "paypal";
72 /**/
73 if (empty ($paypal["custom"]) && !empty ($paypal["recurring_payment_id"])) /* Lookup on Recurring Profiles? */
74 $paypal["custom"] = c_ws_plugin__s2member_utils_users::get_user_custom_with ($paypal["recurring_payment_id"]);
75 /**/
76 if (!empty ($paypal["custom"]) && preg_match ("/^" . preg_quote (preg_replace ("/\:([0-9]+)$/", "", $_SERVER["HTTP_HOST"]), "/") . "/i", $paypal["custom"]))
77 {
78 $paypal["s2member_log"][] = "s2Member originating domain ( `\$_SERVER[\"HTTP_HOST\"]` ) validated.";
79 /**/
80 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
81 if (!apply_filters ("ws_plugin__s2member_during_paypal_notify_conditionals", false, get_defined_vars ()))
82 {
83 unset ($__refs, $__v); /* Unset defined __refs, __v. */
84 /**/
85 if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_virtual_terminal::cp (get_defined_vars ())))
86 $paypal = $_paypal_cp;
87 /**/
88 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_express_checkout::cp (get_defined_vars ())))
89 $paypal = $_paypal_cp;
90 /**/
91 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_cart::cp (get_defined_vars ())))
92 $paypal = $_paypal_cp;
93 /**/
94 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_send_money::cp (get_defined_vars ())))
95 $paypal = $_paypal_cp;
96 /**/
97 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_web_accept_sp::cp (get_defined_vars ())))
98 $paypal = $_paypal_cp;
99 /**/
100 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_or_wa_w_level::cp (get_defined_vars ())))
101 $paypal = $_paypal_cp;
102 /**/
103 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_rec_profile_creation_w_level::cp (get_defined_vars ())))
104 $paypal = $_paypal_cp;
105 /**/
106 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_modify_w_level::cp (get_defined_vars ())))
107 $paypal = $_paypal_cp;
108 /**/
109 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_or_rp_payment_w_level::cp (get_defined_vars ())))
110 $paypal = $_paypal_cp;
111 /**/
112 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_or_rp_payment_failed_w_level::cp (get_defined_vars ())))
113 $paypal = $_paypal_cp;
114 /**/
115 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_or_rp_cancellation_w_level::cp (get_defined_vars ())))
116 $paypal = $_paypal_cp;
117 /**/
118 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_subscr_or_rp_eots_w_level::cp (get_defined_vars ())))
119 $paypal = $_paypal_cp;
120 /**/
121 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_notify_in_sp_refund_reversal::cp (get_defined_vars ())))
122 $paypal = $_paypal_cp;
123 /**/
124 else /* Ignoring this IPN request. The txn_type/status does NOT require any action. */
125 $paypal["s2member_log"][] = "Ignoring this IPN request. The `txn_type/status` does NOT require any action on the part of s2Member.";
126 }
127 else /* Else a custom conditional has been applied by Filters. */
128 unset ($__refs, $__v); /* Unset defined __refs, __v. */
129 }
130 /**/
131 else if (!empty ($paypal["txn_type"]) && preg_match ("/^recurring_payment_profile_cancel$/i", $paypal["txn_type"]))
132 {
133 $paypal["s2member_log"][] = "Transaction type ( `recurring_payment_profile_cancel` ), but there is no match to an existing account; so verification of `\$_SERVER[\"HTTP_HOST\"]` was not possible.";
134 $paypal["s2member_log"][] = "It's likely this account was just upgraded/downgraded by s2Member Pro; so the Subscr. ID has probably been updated on-site; nothing to worry about here.";
135 }
136 /**/
137 else if (!empty ($paypal["txn_type"]) && preg_match ("/^recurring_/i", $paypal["txn_type"])) /* Otherwise, is this a ^recurring_ txn_type? */
138 $paypal["s2member_log"][] = "Transaction type ( `^recurring_?` ), but there is no match to an existing account; so verification of `\$_SERVER[\"HTTP_HOST\"]` was not possible.";
139 /**/
140 else /* Else, use the default ``$_SERVER["HTTP_HOST"]`` error. */
141 $paypal["s2member_log"][] = "Unable to verify `\$_SERVER[\"HTTP_HOST\"]`. Please check the `custom` value in your Button Code. It MUST start with your domain name.";
142 }
143 /**/
144 else /* Extensive log reporting here. This is an area where many site owners find trouble. Depending on server configuration; remote HTTPS connections may fail. */
145 {
146 $paypal["s2member_log"][] = "Unable to verify \$_POST vars. This is most likely related to an invalid configuration of s2Member, or a problem with server compatibility.";
147 $paypal["s2member_log"][] = "If you're absolutely SURE that your configuration is valid, you may want to run some tests on your server, just to be sure \$_POST variables are populated, and that your server is able to connect/communicate with your Payment Gateway over an HTTPS connection.";
148 $paypal["s2member_log"][] = "s2Member uses the `WP_Http` class for remote connections; which will try to use `cURL` first, and then fall back on the `FOPEN` method when `cURL` is not available. On a Windows® server, you may have to disable your `cURL` extension; and instead, set `allow_url_fopen = yes` in your php.ini file. The `cURL` extension (usually) does NOT support SSL connections on a Windows® server.";
149 $paypal["s2member_log"][] = "Please see this thread: `http://www.primothemes.com/forums/viewtopic.php?f=36&t=2636` for details regarding the ideal server configuration for s2Member.";
150 $paypal["s2member_log"][] = var_export ($_REQUEST, true); /* Recording _POST + _GET vars for analysis and debugging. */
151 }
152 /*
153 Add IPN proxy ( when available ) to the ``$paypal`` array.
154 */
155 if (!empty ($_GET["s2member_paypal_proxy"]))
156 $paypal["s2member_paypal_proxy"] = $_GET["s2member_paypal_proxy"];
157 /*
158 Add IPN proxy use vars ( when available ) to the ``$paypal`` array.
159 */
160 if (!empty ($_GET["s2member_paypal_proxy_use"]))
161 $paypal["s2member_paypal_proxy_use"] = $_GET["s2member_paypal_proxy_use"];
162 /*
163 Also add IPN proxy self-verification ( when available ) to the ``$paypal`` array.
164 */
165 if (!empty ($_GET["s2member_paypal_proxy_verification"]))
166 $paypal["s2member_paypal_proxy_verification"] = $_GET["s2member_paypal_proxy_verification"];
167 /*
168 If debugging/logging is enabled; we need to append ``$paypal`` to the log file.
169 Logging now supports Multisite Networking as well.
170 */
171 $logv = c_ws_plugin__s2member_utilities::ver_details ();
172 $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"];
173 $log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4;
174 $log2 = (is_multisite () && !is_main_site ()) ? "paypal-ipn-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "paypal-ipn.log";
175 /**/
176 if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
177 if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
178 if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ())
179 file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $log4 . "\n" . var_export ($paypal, true) . "\n\n", FILE_APPEND);
180 /**/
181 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
182 do_action ("ws_plugin__s2member_during_paypal_notify", get_defined_vars ());
183 unset ($__refs, $__v); /* Unset defined __refs, __v. */
184 /**/
185 header ("HTTP/1.0 200 OK"); /* Send a 200 OK status header. */
186 header ("Content-Type: text/plain; charset=utf-8"); /* With text/plain ( supporting a possible return URL ). */
187 exit (((!empty ($paypal["s2member_paypal_proxy_return_url"])) ? $paypal["s2member_paypal_proxy_return_url"] : ""));
188 }
189 /**/
190 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
191 do_action ("ws_plugin__s2member_after_paypal_notify", get_defined_vars ());
192 unset ($__refs, $__v); /* Unset defined __refs, __v. */
193 }
194 }
195 }
196 ?>