PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 111017
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v111017
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-return-in.inc.php

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

188 lines 12.8 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® Auto-Return/PDT 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_return_in"))
21 {
22 /**
23 * s2Member's PayPal® Auto-Return/PDT handler ( inner processing routines ).
24 *
25 * @package s2Member\PayPal
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_paypal_return_in
29 {
30 /**
31 * Handles PayPal® Return URLs.
32 *
33 * @package s2Member\PayPal
34 * @since 3.5
35 *
36 * @attaches-to: ``add_action("init");``
37 *
38 * @return null Or exits script execution after redirection.
39 */
40 public static function paypal_return ()
41 {
42 global $current_site, $current_blog; /* For Multisite support. */
43 /**/
44 do_action ("ws_plugin__s2member_before_paypal_return", get_defined_vars ());
45 /**/
46 if (!empty ($_GET["s2member_paypal_return"]) && ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_business"] || !empty ($_GET["s2member_paypal_proxy"])))
47 {
48 $custom_success_redirection = (!empty ($_GET["s2member_paypal_return_success"])) ? esc_html (trim (stripslashes ($_GET["s2member_paypal_return_success"]))) : false;
49 $custom_success_redirection = ($custom_success_redirection) ? str_ireplace (array ("&#038;", "&amp;"), "&", $custom_success_redirection) : $custom_success_redirection;
50 /**/
51 if (is_array ($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_postvars ()) && ($_paypal = $paypal) && ($_paypal_s = serialize ($_paypal)))
52 {
53 $paypal["s2member_log"][] = "Return-Data received on: " . date ("D M j, Y g:i:s a T");
54 $paypal["s2member_log"][] = "s2Member POST vars verified " . ((!empty ($paypal["proxy_verified"])) ? "with a Proxy Key" : "through a POST back to PayPal®.");
55 /**/
56 $paypal["subscr_gateway"] = (!empty ($_GET["s2member_paypal_proxy"])) ? esc_html (trim (stripslashes ($_GET["s2member_paypal_proxy"]))) : "paypal";
57 /**/
58 if (empty ($_GET["s2member_paypal_proxy"]) || empty ($_GET["s2member_paypal_proxy_use"]) || !preg_match ("/ty-email/", $_GET["s2member_paypal_proxy_use"]))
59 {
60 $payment_status_issues = "/^(failed|denied|expired|refunded|partially_refunded|reversed|reversal|canceled_reversal|voided)$/i";
61 /**/
62 if (!empty ($paypal["custom"]) && preg_match ("/^" . preg_quote (preg_replace ("/\:([0-9]+)$/", "", $_SERVER["HTTP_HOST"]), "/") . "/i", $paypal["custom"]))
63 {
64 $paypal["s2member_log"][] = "s2Member originating domain ( `\$_SERVER[\"HTTP_HOST\"]` ) validated.";
65 /**/
66 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
67 if (!apply_filters ("ws_plugin__s2member_during_paypal_return_conditionals", false, get_defined_vars ()))
68 {
69 unset ($__refs, $__v); /* Unset defined __refs, __v. */
70 /**/
71 if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_web_accept_sp::cp (get_defined_vars ())))
72 $paypal = $_paypal_cp;
73 /**/
74 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_wa_ccaps_wo_level::cp (get_defined_vars ())))
75 $paypal = $_paypal_cp;
76 /**/
77 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_subscr_or_wa_w_level::cp (get_defined_vars ())))
78 $paypal = $_paypal_cp;
79 /**/
80 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_subscr_modify_w_level::cp (get_defined_vars ())))
81 $paypal = $_paypal_cp;
82 /**/
83 else /* Else we have an unexpected scenario ( i.e. an unexpected `txn_type/status` ). */
84 {
85 $paypal["s2member_log"][] = "Unexpected `txn_type/status`. The `txn_type/status` did not match a required action.";
86 /**/
87 $paypal["s2member_log"][] = "Redirecting Customer to the Home Page, due to an error that occurred.";
88 /**/
89 echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],/**/
90 _x ('<strong>ERROR:</strong> Unexpected <code>txn_type/status</code>.<br />The <code>txn_type/status</code> did not meet requirements.<br />Please contact Support for assistance.', "s2member-front", "s2member"),/**/
91 _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
92 }
93 }
94 else /* Else a custom conditional has been applied by filters. */
95 unset ($__refs, $__v); /* Unset defined __refs, __v. */
96 }
97 else /* Else, use the default ``$_SERVER["HTTP_HOST"]`` error. */
98 {
99 $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.";
100 /**/
101 $paypal["s2member_log"][] = "Redirecting Customer to the Home Page, due to an error that occurred.";
102 /**/
103 echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],/**/
104 _x ('<strong>ERROR:</strong> Unable to verify <code>$_SERVER["HTTP_HOST"]</code>.<br />Please contact Support for assistance.<br /><br />If you are the site owner, please check the <code>custom</code> value in your Button Code. It MUST start with your domain name.', "s2member-front", "s2member"),/**/
105 _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
106 }
107 }
108 else /* In this case ... a Proxy has explicitly requested `ty-email` processing. */
109 {
110 $paypal = $_paypal_cp = c_ws_plugin__s2member_paypal_return_in_proxy_ty_email::cp (get_defined_vars ());
111 }
112 }
113 else if (!empty ($_GET["s2member_paypal_proxy"]) && !empty ($_GET["s2member_paypal_proxy_use"]) && preg_match ("/x-preview/", $_GET["s2member_paypal_proxy_use"]) && ($paypal["subscr_gateway"] = esc_html (trim (stripslashes ($_GET["s2member_paypal_proxy"])))))
114 {
115 $paypal = $_paypal_cp = c_ws_plugin__s2member_paypal_return_in_proxy_x_preview::cp (get_defined_vars ());
116 }
117 else if (empty ($_GET["tx"]) && empty ($_GET["s2member_paypal_proxy"]) && ($paypal["subscr_gateway"] = "paypal"))
118 {
119 $paypal = $_paypal_cp = c_ws_plugin__s2member_paypal_return_in_no_tx_data::cp (get_defined_vars ());
120 }
121 else /* Extensive log reporting here. This is an area where many site owners find trouble. Depending on server configuration; remote HTTPS connections may fail. */
122 {
123 $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.";
124 $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.";
125 $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.";
126 $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.";
127 $paypal["s2member_log"][] = var_export ($_REQUEST, true); /* Recording _POST + _GET vars for analysis and debugging. */
128 /**/
129 $paypal["s2member_log"][] = "Redirecting Customer to the Home Page, due to an error that occurred.";
130 /**/
131 echo c_ws_plugin__s2member_return_templates::return_template ("default",/**/
132 _x ('<strong>ERROR:</strong> Unable to verify <code>$_POST</code> vars.<br />Please contact Support for assistance.<br /><br />This is most likely related to an invalid configuration of s2Member, or a problem with server compatibility. If you are the site owner, and you\'re absolutely SURE that your configuration is valid, you may want to run some tests on your server, just to be sure <code>$_POST</code> variables are populated, and that your server is able to connect/communicate with your Payment Gateway over an HTTPS connection.<br /><br />s2Member uses the <code>WP_Http</code> class for remote connections; which will try to use <code>cURL</code> first, and then fall back on the <code>FOPEN</code> method when <code>cURL</code> is not available. On a Windows® server, you may have to disable your <code>cURL</code> extension; and instead, set <code>allow_url_fopen = yes</code> in your php.ini file. The <code>cURL</code> extension (usually) does NOT support SSL connections on a Windows® server.<br /><br />Please see <a href="http://www.primothemes.com/forums/viewtopic.php?f=36&t=2636" target="_blank">this thread</a> for details regarding the ideal server configuration for s2Member.', "s2member-front", "s2member"),/**/
133 _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
134 }
135 /*
136 Add RTN proxy ( when available ) to the ``$paypal`` array.
137 */
138 if (!empty ($_GET["s2member_paypal_proxy"]))
139 $paypal["s2member_paypal_proxy"] = $_GET["s2member_paypal_proxy"];
140 /*
141 Add IPN proxy use vars ( when available ) to the ``$paypal`` array.
142 */
143 if (!empty ($_GET["s2member_paypal_proxy_use"]))
144 $paypal["s2member_paypal_proxy_use"] = $_GET["s2member_paypal_proxy_use"];
145 /*
146 Also add RTN proxy self-verification ( when available ) to the ``$paypal`` array.
147 */
148 if (!empty ($_GET["s2member_paypal_proxy_verification"]))
149 $paypal["s2member_paypal_proxy_verification"] = $_GET["s2member_paypal_proxy_verification"];
150 /*
151 Also add RTN success redirection URL ( when available ) to the ``$paypal`` array.
152 */
153 if (!empty ($_GET["s2member_paypal_return_success"]))
154 $paypal["s2member_paypal_return_success"] = $_GET["s2member_paypal_return_success"];
155 /*
156 Also add RTN t and r Attributes ( when available ) to the ``$paypal`` array.
157 */
158 if (!empty ($_GET["s2member_paypal_return_tra"]))
159 $paypal["s2member_paypal_return_tra"] = $_GET["s2member_paypal_return_tra"];
160 /*
161 If debugging/logging is enabled; we need to append $paypal to the log file.
162 Logging now supports Multisite Networking as well.
163 */
164 $logv = c_ws_plugin__s2member_utilities::ver_details ();
165 $logm = c_ws_plugin__s2member_utilities::mem_details ();
166 $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"];
167 $log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4;
168 $log2 = (is_multisite () && !is_main_site ()) ? "paypal-rtn-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "paypal-rtn.log";
169 /**/
170 if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
171 if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
172 if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ())
173 file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export ($paypal, true) . "\n\n", FILE_APPEND);
174 /**/
175 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
176 do_action ("ws_plugin__s2member_during_paypal_return", get_defined_vars ());
177 unset ($__refs, $__v); /* Unset defined __refs, __v. */
178 /**/
179 exit (); /* Clean exit. */
180 }
181 /**/
182 eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
183 do_action ("ws_plugin__s2member_after_paypal_return", get_defined_vars ());
184 unset ($__refs, $__v); /* Unset defined __refs, __v. */
185 }
186 }
187 }
188 ?>