PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 260917
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v260917
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 / src / 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 260917, at src/includes/classes/paypal-return-in.inc.php

215 lines 14.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // @codingStandardsIgnoreFile
3 /**
4 * s2Member's PayPal Auto-Return/PDT handler (inner processing routines).
5 *
6 * Copyright: © 2009-2011
7 * {@link http://websharks-inc.com/ WebSharks, Inc.}
8 * (coded in the USA)
9 *
10 * Released under the terms of the GNU General Public License.
11 * You should have received a copy of the GNU General Public License,
12 * along with this software. In the main directory, see: /licensing/
13 * If not, see: {@link http://www.gnu.org/licenses/}.
14 *
15 * @package s2Member\PayPal
16 * @since 3.5
17 */
18 if(!defined('WPINC')) // MUST have WordPress.
19 exit ("Do not access this file directly.");
20
21 if (!class_exists ("c_ws_plugin__s2member_paypal_return_in"))
22 {
23 /**
24 * s2Member's PayPal Auto-Return/PDT handler (inner processing routines).
25 *
26 * @package s2Member\PayPal
27 * @since 3.5
28 */
29 class c_ws_plugin__s2member_paypal_return_in
30 {
31 /**
32 * Handles PayPal Return URLs.
33 *
34 * @package s2Member\PayPal
35 * @since 3.5
36 *
37 * @attaches-to ``add_action("init");``
38 *
39 * @return null Or exits script execution after redirection.
40 */
41 public static function paypal_return ()
42 {
43 global /* For Multisite support. */ $current_site, $current_blog;
44
45 do_action("ws_plugin__s2member_before_paypal_return", get_defined_vars ());
46
47 //260831.0135 Normalize optional s2Member proxy fields once; direct PayPal returns omit them, while proxied gateway integrations provide strings.
48 if(!isset($_GET["s2member_paypal_proxy"]) || !is_string($_GET["s2member_paypal_proxy"]))
49 $_GET["s2member_paypal_proxy"] = "";
50 if(!isset($_GET["s2member_paypal_proxy_use"]) || !is_string($_GET["s2member_paypal_proxy_use"]))
51 $_GET["s2member_paypal_proxy_use"] = "";
52
53 if (!empty($_GET["s2member_paypal_return"]) && ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_business"] || !empty($_GET["s2member_paypal_proxy"])))
54 {
55 $paypal = array(); // Initialize PayPal array; we also reference this with a variable for a possible proxy handler.
56 if(!empty($_GET["s2member_paypal_proxy"]) && in_array($_GET["s2member_paypal_proxy"], array("alipay", "stripe", "authnet", "clickbank", "ccbill", "google"), TRUE))
57 ${esc_html(trim(stripslashes($_GET["s2member_paypal_proxy"])))} = &$paypal; // Internal alias by reference.
58
59 //240320 Pro success valid redir
60 $custom_success_redirection = false;
61 if (c_ws_plugin__s2member_utils_conds::pro_is_installed()
62 && isset($_GET["s2member_paypal_return_success"])
63 && (bool)wp_validate_redirect($_GET["s2member_paypal_return_success"])) {
64 $custom_success_redirection = esc_html(trim(stripslashes($_GET["s2member_paypal_return_success"])));
65 $custom_success_redirection = str_ireplace(["&#038;", "&amp;"], "&", $custom_success_redirection);
66 }
67 // //240320 Pro success valid redir
68 // $custom_success_redirection = false;
69 // if (c_ws_plugin__s2member_utils_conds::pro_is_installed()
70 // && isset($_GET["s2member_paypal_return_success"])) {
71
72 // $_success = (string)$_GET["s2member_paypal_return_success"];
73 // $_success = trim(stripslashes($_success));
74 // $_success = rawurldecode($_success); //260112
75 // $_success = str_ireplace(["&#038;", "&amp;"], "&", $_success);
76
77 // if ($_success && ($_success = wp_validate_redirect($_success, false))) {
78 // $custom_success_redirection = $_success;
79 // }
80 // }
81
82 if (is_array($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_postvars ()) && ($_paypal = $paypal) && ($_paypal_s = serialize ($_paypal)))
83 {
84 $paypal["s2member_log"][] = "Return-Data received on: " . date ("D M j, Y g:i:s a T");
85 $paypal["s2member_log"][] = "s2Member POST vars verified " . ((!empty($paypal["proxy_verified"])) ? "through a trusted proxy verification method." : "through a POST back to PayPal.");
86
87 $paypal["subscr_gateway"] = (!empty($_GET["s2member_paypal_proxy"])) ? esc_html (trim (stripslashes ($_GET["s2member_paypal_proxy"]))) : "paypal";
88
89 if (empty($_GET["s2member_paypal_proxy"]) || empty($_GET["s2member_paypal_proxy_use"]) || !preg_match ("/ty-email/", $_GET["s2member_paypal_proxy_use"]))
90 {
91 $payment_status_issues = "/^(failed|denied|expired|refunded|partially_refunded|reversed|reversal|canceled_reversal|voided)$/i";
92
93 if (!empty($paypal["custom"]) && preg_match ("/^" . preg_quote (preg_replace ("/\:([0-9]+)$/", "", $_SERVER["HTTP_HOST"]), "/") . "/i", $paypal["custom"]))
94 {
95 $paypal["s2member_log"][] = "s2Member originating domain ( `\$_SERVER[\"HTTP_HOST\"]` ) validated.";
96
97 foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
98 if (!apply_filters("ws_plugin__s2member_during_paypal_return_conditionals", false, get_defined_vars ()))
99 {
100 unset($__refs, $__v);
101
102 if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_web_accept_sp::cp (get_defined_vars ())))
103 $paypal = $_paypal_cp;
104
105 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_wa_ccaps_wo_level::cp (get_defined_vars ())))
106 $paypal = $_paypal_cp;
107
108 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_subscr_or_wa_w_level::cp (get_defined_vars ())))
109 $paypal = $_paypal_cp;
110
111 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_subscr_modify_w_level::cp (get_defined_vars ())))
112 $paypal = $_paypal_cp;
113
114 else // Else we have an unexpected scenario ( i.e., an unexpected `txn_type/status` ).
115 {
116 $paypal["s2member_log"][] = "Unexpected `txn_type/status`. The `txn_type/status` did not match a required action.";
117
118 $paypal["s2member_log"][] = "Redirecting Customer to the Home Page (after displaying an error message).";
119
120 echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
121 _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"),
122 _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
123 }
124 }
125 else unset($__refs, $__v); // Else a custom conditional has been applied by filters.
126 }
127 else // Else, use the default ``$_SERVER["HTTP_HOST"]`` error.
128 {
129 if /* Enqueue an admin notice if the site owner is using the wrong domain variation. */ ($paypal["custom"] && ($paypal["custom"] === "www.".$_SERVER["HTTP_HOST"] || "www.".$paypal["custom"] === $_SERVER["HTTP_HOST"]))
130 c_ws_plugin__s2member_admin_notices::enqueue_admin_notice("<strong>s2Member:</strong> Post-processing failed on at least one transaction. It appears that you have a PayPal Button configured with a <code>custom=\"\"</code> Shortcode Attribute that does NOT match up with your installation domain name. If your site uses the <code>www.</code> prefix, please include that. If it does not, please exclude the <code>www.</code> prefix. You should have <code>custom=\"".preg_replace ("/\:([0-9]+)$/", "", $_SERVER["HTTP_HOST"])."\"</code>", "*:*", true);
131
132 // Keep trying until we get it. TODO: may need improvement. https://f.wpsharks.com/t/5250/83
133 sleep(3);
134 wp_redirect( home_url( preg_replace( '`(&do_not_cache=[0-9]{5}){2,}`', '&do_not_cache=' . rand(10000,99999), $_SERVER["REQUEST_URI"] . '&do_not_cache=' . rand(10000,99999) ) ) );
135 exit;
136
137 $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.';
138
139 $paypal["s2member_log"][] = "Redirecting Customer to the Home Page (after displaying an error message).";
140
141 echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
142 _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"),
143 _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
144 }
145 }
146 else // In this case ... a Proxy has explicitly requested `ty-email` processing.
147 $paypal = $_paypal_cp = c_ws_plugin__s2member_paypal_return_in_proxy_ty_email::cp (get_defined_vars ());
148 }
149 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"])))))
150 $paypal = $_paypal_cp = c_ws_plugin__s2member_paypal_return_in_proxy_x_preview::cp (get_defined_vars ());
151
152 else if (empty($_GET["tx"]) && empty($_GET["s2member_paypal_proxy"]) && ($paypal["subscr_gateway"] = "paypal"))
153 $paypal = $_paypal_cp = c_ws_plugin__s2member_paypal_return_in_no_tx_data::cp (get_defined_vars ());
154
155 else // Extensive log reporting here. This is an area where many site owners find trouble. Depending on server configuration; remote HTTPS connections may fail.
156 {
157 if /* Enqueue an admin notice if the site owner is missing the PDT Identity Key. */ (!$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_identity_token"])
158 c_ws_plugin__s2member_admin_notices::enqueue_admin_notice("<strong>s2Member:</strong> You have no PayPal PDT Identity Token configured. PayPal Auto-Return handling failed. Please update your PayPal PDT Identity Key. See: <strong>s2Member → PayPal Options → PayPal PDT/Auto-Return Integration</strong>. Thank you!", "*:*", true);
159
160 $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.";
161 $paypal["s2member_log"][] = "Please make sure that you configure a PayPal PDT Identity Token for your installation of s2Member. See: `s2Member → PayPal Options → PayPal PDT/Auto-Return Integration`.";
162 $paypal["s2member_log"][] = "See also, this KB article: `http://www.s2member.com/kb/server-scanner/`. We suggest that you run the s2Member Server Scanner.";
163 $paypal["s2member_log"][] = /* Recording _POST + _GET vars for analysis and debugging. */ var_export ($_REQUEST, true);
164
165 $paypal["s2member_log"][] = "Redirecting Customer to the Home Page (after displaying an error message).";
166
167 echo c_ws_plugin__s2member_return_templates::return_template ("default",
168 _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.s2member.com/forums/topic/ideal-server-configuration-for-s2member/" target="_blank">this thread</a> for details regarding the ideal server configuration for s2Member.', "s2member-front", "s2member"),
169 _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
170 }
171 /*
172 Add RTN proxy (when available) to the ``$paypal`` array.
173 */
174 if (!empty($_GET["s2member_paypal_proxy"]))
175 $paypal["s2member_paypal_proxy"] = esc_html(trim(stripslashes((string)$_GET["s2member_paypal_proxy"])));
176 /*
177 Add IPN proxy use vars (when available) to the ``$paypal`` array.
178 */
179 if (!empty($_GET["s2member_paypal_proxy_use"]))
180 $paypal["s2member_paypal_proxy_use"] = esc_html(trim(stripslashes((string)$_GET["s2member_paypal_proxy_use"])));
181 /*
182 Also add RTN proxy self-verification (when available) to the ``$paypal`` array.
183 */
184 if (!empty($_GET["s2member_paypal_proxy_verification"]))
185 $paypal["s2member_paypal_proxy_verification"] = esc_html(trim(stripslashes((string)$_GET["s2member_paypal_proxy_verification"])));
186 /*
187 Also add RTN success redirection URL (when available) to the ``$paypal`` array.
188 */
189 if (!empty($_GET["s2member_paypal_return_success"]))
190 $paypal["s2member_paypal_return_success"] = esc_html(trim(stripslashes((string)$_GET["s2member_paypal_return_success"])));
191 /*
192 Also add RTN t and r Attributes (when available) to the ``$paypal`` array.
193 */
194 if (!empty($_GET["s2member_paypal_return_tra"]))
195 $paypal["s2member_paypal_return_tra"] = esc_html(trim(stripslashes((string)$_GET["s2member_paypal_return_tra"])));
196 /*
197 Log this IPN post-processing event now.
198 */
199 c_ws_plugin__s2member_utils_logs::log_entry('gateway-core-rtn', $paypal);
200 /*
201 Hook during core RTN post-processing might be useful for developers.
202 */
203 foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
204 do_action("ws_plugin__s2member_during_paypal_return", get_defined_vars ());
205 unset($__refs, $__v);
206
207 exit(); // Clean exit now.
208 }
209 foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
210 do_action("ws_plugin__s2member_after_paypal_return", get_defined_vars ());
211 unset($__refs, $__v);
212 }
213 }
214 }
215