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

209 lines 13.8 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 if (!empty($_GET["s2member_paypal_return"]) && ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_business"] || !empty($_GET["s2member_paypal_proxy"])))
48 {
49 $paypal = array(); // Initialize PayPal array; we also reference this with a variable for a possible proxy handler.
50 if(!empty($_GET["s2member_paypal_proxy"]) && in_array($_GET["s2member_paypal_proxy"], array("alipay", "stripe", "authnet", "clickbank", "ccbill", "google"), TRUE))
51 ${esc_html(trim(stripslashes($_GET["s2member_paypal_proxy"])))} = &$paypal; // Internal alias by reference.
52
53 //240320 Pro success valid redir
54 $custom_success_redirection = false;
55 if (c_ws_plugin__s2member_utils_conds::pro_is_installed()
56 && isset($_GET["s2member_paypal_return_success"])
57 && (bool)wp_validate_redirect($_GET["s2member_paypal_return_success"])) {
58 $custom_success_redirection = esc_html(trim(stripslashes($_GET["s2member_paypal_return_success"])));
59 $custom_success_redirection = str_ireplace(["&#038;", "&amp;"], "&", $custom_success_redirection);
60 }
61 // //240320 Pro success valid redir
62 // $custom_success_redirection = false;
63 // if (c_ws_plugin__s2member_utils_conds::pro_is_installed()
64 // && isset($_GET["s2member_paypal_return_success"])) {
65
66 // $_success = (string)$_GET["s2member_paypal_return_success"];
67 // $_success = trim(stripslashes($_success));
68 // $_success = rawurldecode($_success); //260112
69 // $_success = str_ireplace(["&#038;", "&amp;"], "&", $_success);
70
71 // if ($_success && ($_success = wp_validate_redirect($_success, false))) {
72 // $custom_success_redirection = $_success;
73 // }
74 // }
75
76 if (is_array($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_postvars ()) && ($_paypal = $paypal) && ($_paypal_s = serialize ($_paypal)))
77 {
78 $paypal["s2member_log"][] = "Return-Data received on: " . date ("D M j, Y g:i:s a T");
79 $paypal["s2member_log"][] = "s2Member POST vars verified " . ((!empty($paypal["proxy_verified"])) ? "with a Proxy Key" : "through a POST back to PayPal.");
80
81 $paypal["subscr_gateway"] = (!empty($_GET["s2member_paypal_proxy"])) ? esc_html (trim (stripslashes ($_GET["s2member_paypal_proxy"]))) : "paypal";
82
83 if (empty($_GET["s2member_paypal_proxy"]) || empty($_GET["s2member_paypal_proxy_use"]) || !preg_match ("/ty-email/", $_GET["s2member_paypal_proxy_use"]))
84 {
85 $payment_status_issues = "/^(failed|denied|expired|refunded|partially_refunded|reversed|reversal|canceled_reversal|voided)$/i";
86
87 if (!empty($paypal["custom"]) && preg_match ("/^" . preg_quote (preg_replace ("/\:([0-9]+)$/", "", $_SERVER["HTTP_HOST"]), "/") . "/i", $paypal["custom"]))
88 {
89 $paypal["s2member_log"][] = "s2Member originating domain ( `\$_SERVER[\"HTTP_HOST\"]` ) validated.";
90
91 foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
92 if (!apply_filters("ws_plugin__s2member_during_paypal_return_conditionals", false, get_defined_vars ()))
93 {
94 unset($__refs, $__v);
95
96 if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_web_accept_sp::cp (get_defined_vars ())))
97 $paypal = $_paypal_cp;
98
99 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_wa_ccaps_wo_level::cp (get_defined_vars ())))
100 $paypal = $_paypal_cp;
101
102 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_subscr_or_wa_w_level::cp (get_defined_vars ())))
103 $paypal = $_paypal_cp;
104
105 else if (($_paypal_cp = c_ws_plugin__s2member_paypal_return_in_subscr_modify_w_level::cp (get_defined_vars ())))
106 $paypal = $_paypal_cp;
107
108 else // Else we have an unexpected scenario ( i.e., an unexpected `txn_type/status` ).
109 {
110 $paypal["s2member_log"][] = "Unexpected `txn_type/status`. The `txn_type/status` did not match a required action.";
111
112 $paypal["s2member_log"][] = "Redirecting Customer to the Home Page (after displaying an error message).";
113
114 echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
115 _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"),
116 _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
117 }
118 }
119 else unset($__refs, $__v); // Else a custom conditional has been applied by filters.
120 }
121 else // Else, use the default ``$_SERVER["HTTP_HOST"]`` error.
122 {
123 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"]))
124 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);
125
126 // Keep trying until we get it. TODO: may need improvement. https://f.wpsharks.com/t/5250/83
127 sleep(3);
128 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) ) ) );
129 exit;
130
131 $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.';
132
133 $paypal["s2member_log"][] = "Redirecting Customer to the Home Page (after displaying an error message).";
134
135 echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
136 _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"),
137 _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
138 }
139 }
140 else // In this case ... a Proxy has explicitly requested `ty-email` processing.
141 $paypal = $_paypal_cp = c_ws_plugin__s2member_paypal_return_in_proxy_ty_email::cp (get_defined_vars ());
142 }
143 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"])))))
144 $paypal = $_paypal_cp = c_ws_plugin__s2member_paypal_return_in_proxy_x_preview::cp (get_defined_vars ());
145
146 else if (empty($_GET["tx"]) && empty($_GET["s2member_paypal_proxy"]) && ($paypal["subscr_gateway"] = "paypal"))
147 $paypal = $_paypal_cp = c_ws_plugin__s2member_paypal_return_in_no_tx_data::cp (get_defined_vars ());
148
149 else // Extensive log reporting here. This is an area where many site owners find trouble. Depending on server configuration; remote HTTPS connections may fail.
150 {
151 if /* Enqueue an admin notice if the site owner is missing the PDT Identity Key. */ (!$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_identity_token"])
152 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);
153
154 $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.";
155 $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`.";
156 $paypal["s2member_log"][] = "See also, this KB article: `http://www.s2member.com/kb/server-scanner/`. We suggest that you run the s2Member Server Scanner.";
157 $paypal["s2member_log"][] = /* Recording _POST + _GET vars for analysis and debugging. */ var_export ($_REQUEST, true);
158
159 $paypal["s2member_log"][] = "Redirecting Customer to the Home Page (after displaying an error message).";
160
161 echo c_ws_plugin__s2member_return_templates::return_template ("default",
162 _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"),
163 _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
164 }
165 /*
166 Add RTN proxy (when available) to the ``$paypal`` array.
167 */
168 if (!empty($_GET["s2member_paypal_proxy"]))
169 $paypal["s2member_paypal_proxy"] = esc_html(trim(stripslashes((string)$_GET["s2member_paypal_proxy"])));
170 /*
171 Add IPN proxy use vars (when available) to the ``$paypal`` array.
172 */
173 if (!empty($_GET["s2member_paypal_proxy_use"]))
174 $paypal["s2member_paypal_proxy_use"] = esc_html(trim(stripslashes((string)$_GET["s2member_paypal_proxy_use"])));
175 /*
176 Also add RTN proxy self-verification (when available) to the ``$paypal`` array.
177 */
178 if (!empty($_GET["s2member_paypal_proxy_verification"]))
179 $paypal["s2member_paypal_proxy_verification"] = esc_html(trim(stripslashes((string)$_GET["s2member_paypal_proxy_verification"])));
180 /*
181 Also add RTN success redirection URL (when available) to the ``$paypal`` array.
182 */
183 if (!empty($_GET["s2member_paypal_return_success"]))
184 $paypal["s2member_paypal_return_success"] = esc_html(trim(stripslashes((string)$_GET["s2member_paypal_return_success"])));
185 /*
186 Also add RTN t and r Attributes (when available) to the ``$paypal`` array.
187 */
188 if (!empty($_GET["s2member_paypal_return_tra"]))
189 $paypal["s2member_paypal_return_tra"] = esc_html(trim(stripslashes((string)$_GET["s2member_paypal_return_tra"])));
190 /*
191 Log this IPN post-processing event now.
192 */
193 c_ws_plugin__s2member_utils_logs::log_entry('gateway-core-rtn', $paypal);
194 /*
195 Hook during core RTN post-processing might be useful for developers.
196 */
197 foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
198 do_action("ws_plugin__s2member_during_paypal_return", get_defined_vars ());
199 unset($__refs, $__v);
200
201 exit(); // Clean exit now.
202 }
203 foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
204 do_action("ws_plugin__s2member_after_paypal_return", get_defined_vars ());
205 unset($__refs, $__v);
206 }
207 }
208 }
209