PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 261001
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v261001
261001 260927 260917 260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 All 191 releases
s2member / src / includes / classes / paypal-return-in-wa-ccaps-wo-level.inc.php

paypal-return-in-wa-ccaps-wo-level.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 261001, at src/includes/classes/paypal-return-in-wa-ccaps-wo-level.inc.php

212 lines 15.5 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 routine).
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 110720
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_wa_ccaps_wo_level'))
22 {
23 /**
24 * s2Member's PayPal Auto-Return/PDT handler (inner processing routine).
25 *
26 * @package s2Member\PayPal
27 * @since 110720
28 */
29 class c_ws_plugin__s2member_paypal_return_in_wa_ccaps_wo_level
30 {
31 /**
32 * s2Member's PayPal Auto-Return/PDT handler (inner processing routine).
33 *
34 * @package s2Member\PayPal
35 * @since 110720
36 *
37 * @param array $vars Required. An array of defined variables passed by {@link s2Member\PayPal\c_ws_plugin__s2member_paypal_return_in::paypal_return()}.
38 *
39 * @return array|bool The original ``$paypal`` array passed in (extracted) from ``$vars``, or false when conditions do NOT apply.
40 */
41 public static function cp($vars = array() /* Conditional phase for ``c_ws_plugin__s2member_paypal_notify_in::paypal_notify()``. */)
42 {
43 extract($vars, EXTR_OVERWRITE | EXTR_REFS /* Extract all vars passed in from: ``c_ws_plugin__s2member_paypal_notify_in::paypal_notify()``. */);
44
45 if((!empty($paypal['txn_type']) && preg_match('/^web_accept$/i', $paypal['txn_type']))
46 && (!empty($paypal['item_number']) && preg_match($GLOBALS['WS_PLUGIN__']['s2member']['c']['membership_item_number_wo_level_regex'], $paypal['item_number']))
47 && (empty($paypal['payment_status']) || empty($payment_status_issues) || !preg_match($payment_status_issues, $paypal['payment_status']))
48 && (!empty($paypal['txn_id'])) && (!empty($paypal['payer_email']))
49 && (!empty($paypal['txn_baid']) || ($paypal['txn_baid'] = $paypal['txn_id']))
50 && (!empty($paypal['txn_cid']) || ($paypal['txn_cid'] = $paypal['txn_id']))
51 )
52 {
53 foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
54 do_action('ws_plugin__s2member_during_paypal_return_before_new_ccaps', get_defined_vars());
55 unset($__refs, $__v);
56
57 if(!get_transient($transient_rtn = 's2m_rtn_'.md5('s2member_transient_'.$_paypal_s)) && set_transient($transient_rtn, time(), 31556926 * 10))
58 {
59 $paypal['s2member_log'][] = 's2Member `txn_type` identified as ( `web_accept` ) w/ update vars for Capabilities w/o Level.';
60
61 //260814 Parse and pad optional CCaps/EOT components instead of relying on undefined list() offsets.
62 list ($paypal['level'], $paypal['ccaps'], $paypal['eotper']) = array_pad(explode(':', $paypal['item_number'], 3), 3, '');
63 //260814 Set optional gateway elements used below so sparse/null payload fields do not trigger PHP diagnostics.
64 $paypal = c_ws_plugin__s2member_utils_arrays::set_unset_elements($paypal, array('option_name1', 'option_selection1', 'option_name2', 'option_selection2', 'invoice', 'first_name', 'last_name'));
65
66 $paypal['ip'] = (preg_match('/ip address/i', $paypal['option_name2']) && $paypal['option_selection2']) ? $paypal['option_selection2'] : '';
67 $paypal['ip'] = (!$paypal['ip'] && preg_match('/^[a-z0-9]+~[0-9\.]+$/i', $paypal['invoice'])) ? preg_replace('/^[a-z0-9]+~/i', '', $paypal['invoice']) : $paypal['ip'];
68 $paypal['ip'] = (!$paypal['ip'] && c_ws_plugin__s2member_utils_ip::current()) ? c_ws_plugin__s2member_utils_ip::current() : $paypal['ip'];
69
70 $paypal['currency'] = strtoupper($paypal['mc_currency']); // Normalize input currency.
71 $paypal['currency_symbol'] = c_ws_plugin__s2member_utils_cur::symbol($paypal['currency']);
72
73 if(preg_match('/(referenc|associat|updat|upgrad)/i', $paypal['option_name1']) && $paypal['option_selection1'] /* Must have this information for Capability additions. */)
74 {
75 if(($user_id = c_ws_plugin__s2member_utils_users::get_user_id_with($paypal['txn_id'], $paypal['option_selection1'])) && is_object($user = new WP_User ($user_id)) && $user->ID)
76 {
77 if(!$user->has_cap('administrator') /* Do NOT process this routine on Administrators. */)
78 {
79 $processing = $during = TRUE; // Yes, we ARE processing this.
80
81 $fields = get_user_option('s2member_custom_fields', $user_id); // These will be needed in the routines below.
82 $user_reg_ip = get_user_option('s2member_registration_ip', $user_id); // Original IP during Registration.
83 $user_reg_ip = $paypal['ip'] = ($user_reg_ip) ? $user_reg_ip : $paypal['ip']; // Now merge conditionally.
84
85 if(is_multisite() && !is_user_member_of_blog($user_id) /* Must have a Role on this Blog. */)
86 {
87 add_existing_user_to_blog(array('user_id' => $user_id, 'role' => get_option('default_role')));
88 $user = new WP_User ($user_id);
89 }
90 if($paypal['ccaps'] && preg_match('/^-all/', str_replace('+', '', $paypal['ccaps'])))
91 foreach($user->allcaps as $cap => $cap_enabled)
92 if(preg_match('/^access_s2member_ccap_/', $cap))
93 $user->remove_cap($ccap = $cap);
94
95 if($paypal['ccaps'] && preg_replace('/^-all['."\r\n\t".'\s;,]*/', '', str_replace('+', '', $paypal['ccaps'])))
96 foreach(preg_split('/['."\r\n\t".'\s;,]+/', preg_replace('/^-all['."\r\n\t".'\s;,]*/', '', str_replace('+', '', $paypal['ccaps']))) as $ccap)
97 if(strlen($ccap = trim(strtolower(preg_replace('/[^a-z_0-9]/i', '', $ccap)))))
98 $user->add_cap('access_s2member_ccap_'.$ccap);
99
100 if(!get_user_option('s2member_registration_ip', $user_id))
101 update_user_option($user_id, 's2member_registration_ip', $paypal['ip']);
102
103 $paypal['s2member_log'][] = 's2Member Custom Capabilities updated w/ advanced update routines.';
104
105 setcookie('s2member_tracking', ($s2member_tracking = c_ws_plugin__s2member_utils_encryption::encrypt($paypal['txn_id'])), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN).setcookie('s2member_tracking', $s2member_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN).($_COOKIE['s2member_tracking'] = $s2member_tracking);
106
107 $paypal['s2member_log'][] = 'Transient Tracking Cookie set on ( `web_accept` ) w/ update vars for Capabilities w/o Level.';
108
109 if($processing && ($code = $GLOBALS['WS_PLUGIN__']['s2member']['o']['ccap_tracking_codes']))
110 {
111 if(($code = c_ws_plugin__s2member_utils_strings::fill_cvs($code, $paypal['custom'])) && ($code = preg_replace('/%%(?:subscr|txn)_id%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['txn_id']), $code)))
112 if(($code = preg_replace('/%%(?:subscr|txn)_baid%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['txn_baid']), $code)) && ($code = preg_replace('/%%(?:subscr|txn)_cid%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['txn_cid']), $code)))
113 if(($code = preg_replace('/%%currency%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['currency']), $code)) && ($code = preg_replace('/%%currency_symbol%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['currency_symbol']), $code)))
114 if(($code = preg_replace('/%%amount%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['mc_gross']), $code)) && ($code = preg_replace('/%%txn_id%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['txn_id']), $code)))
115 if(($code = preg_replace('/%%item_number%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['item_number']), $code)) && ($code = preg_replace('/%%item_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['item_name']), $code)))
116 if(($code = preg_replace('/%%first_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['first_name']), $code)) && ($code = preg_replace('/%%last_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['last_name']), $code)))
117 if(($code = preg_replace('/%%full_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(trim($paypal['first_name'].' '.$paypal['last_name'])), $code)))
118 if(($code = preg_replace('/%%payer_email%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['payer_email']), $code)))
119 {
120 if(($code = preg_replace('/%%user_first_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user->first_name), $code)) && ($code = preg_replace('/%%user_last_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user->last_name), $code)))
121 if(($code = preg_replace('/%%user_full_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(trim($user->first_name.' '.$user->last_name)), $code)))
122 if(($code = preg_replace('/%%user_email%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user->user_email), $code)))
123 if(($code = preg_replace('/%%user_login%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user->user_login), $code)))
124 if(($code = preg_replace('/%%user_ip%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user_reg_ip), $code)))
125 if(($code = preg_replace('/%%user_id%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($user_id), $code)))
126 {
127 if(is_array($fields) && !empty($fields))
128 foreach($fields as $var => $val /* Custom Registration/Profile Fields. */)
129 if(!($code = preg_replace('/%%'.preg_quote($var, '/').'%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(maybe_serialize($val)), $code)))
130 break;
131
132 if(($code = trim(preg_replace('/%%(.+?)%%/i', '', $code))) /* This gets stored into a Transient Queue. */)
133 {
134 $paypal['s2member_log'][] = 'Storing Payment Tracking Codes into a Transient Queue. These will be processed on-site.';
135 set_transient('s2m_'.md5('s2member_transient_ccap_tracking_codes_'.$paypal['txn_id']), $code, 43200);
136 }
137 }
138 }
139 }
140 foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
141 do_action('ws_plugin__s2member_during_paypal_return_during_new_ccaps', get_defined_vars());
142 unset($__refs, $__v);
143
144 if(($redirection_url_after_capabilities = apply_filters('ws_plugin__s2member_redirection_url_after_capabilities', FALSE, get_defined_vars())))
145 {
146 $paypal['s2member_log'][] = 'Redirecting Customer to a custom URL after Capabilities: '.$redirection_url_after_capabilities;
147
148 wp_redirect($redirection_url_after_capabilities);
149 }
150 else // Else, use standard/default handling in this scenario. Have the Customer log in again.
151 {
152 $paypal['s2member_log'][] = 'Redirecting Customer to the Login Page (after displaying a quick thank-you message). They need to log back in.';
153
154 echo c_ws_plugin__s2member_return_templates::return_template($paypal['subscr_gateway'],
155 '<strong>'._x('Thank you! You now have access to:', 's2member-front', 's2member').'<br /><em>'.esc_html($paypal['item_name']).'</em></strong>',
156 _x('Please Log Back In (Click Here)', 's2member-front', 's2member'), wp_login_url());
157 }
158 }
159 else // Unable to add new Capabilities. The existing User ID is associated with an Administrator. Stopping here.
160 {
161 $paypal['s2member_log'][] = 'Unable to add new Capabilities. The existing User ID is associated with an Administrator. Stopping here. Otherwise, an Administrator could lose access. Please make sure that you are NOT logged in as an Administrator while testing.';
162
163 $paypal['s2member_log'][] = 'Redirecting Customer to the Home Page (after displaying an error message).';
164
165 echo c_ws_plugin__s2member_return_templates::return_template($paypal['subscr_gateway'],
166 _x('<strong>ERROR:</strong> Unable to add new Capabilities.<br />Please contact Support for assistance.<br /><br />The existing User ID is associated with an Administrator. Stopping here. Otherwise, an Administrator could lose access. Please make sure that you are NOT logged in as an Administrator while testing.', 's2member-front', 's2member'),
167 _x('Back To Home Page', 's2member-front', 's2member'), home_url('/'));
168 }
169 }
170 else // Unable to add new Capabilities. Could not get the existing User ID from the DB.
171 {
172 $paypal['s2member_log'][] = 'Unable to add new Capabilities. Could not get the existing User ID from the DB.';
173
174 $paypal['s2member_log'][] = 'Redirecting Customer to the Home Page (after displaying an error message).';
175
176 echo c_ws_plugin__s2member_return_templates::return_template($paypal['subscr_gateway'],
177 _x('<strong>ERROR:</strong> Unable to add new Capabilities.<br />Please contact Support for assistance.<br /><br />Could not get the existing User ID from the DB.', 's2member-front', 's2member'),
178 _x('Back To Home Page', 's2member-front', 's2member'), home_url('/'));
179 }
180 }
181 else // Unable to add new Capabilities. Missing User/Member details.
182 {
183 $paypal['s2member_log'][] = 'Unable to add new Capabilities. Missing User/Member details. Please check the `on0` and `os0` variables in your Button Code.';
184
185 $paypal['s2member_log'][] = 'Redirecting Customer to the Home Page (after displaying an error message).';
186
187 echo c_ws_plugin__s2member_return_templates::return_template($paypal['subscr_gateway'],
188 _x('<strong>ERROR:</strong> Unable to add new Capabilities.<br />Please contact Support for assistance.<br /><br />Missing User/Member details.', 's2member-front', 's2member'),
189 _x('Back To Home Page', 's2member-front', 's2member'), home_url('/'));
190 }
191 }
192 else // Page Expired. Duplicate Return-Data.
193 {
194 $paypal['s2member_log'][] = 'Page Expired. Duplicate Return-Data.';
195 $paypal['s2member_log'][] = 's2Member `txn_type` identified as ( `web_accept` ) w/ update vars for Capabilities w/o Level.';
196 $paypal['s2member_log'][] = 'Page Expired. Instructing customer to check their email for further details about how to obtain access to what they purchased.';
197
198 echo c_ws_plugin__s2member_return_templates::return_template($paypal['subscr_gateway'],
199 '<strong>'._x('Thank you! Please check your email for further details regarding your purchase.', 's2member-front', 's2member').'</strong>',
200 _x('Return to Home Page', 's2member-front', 's2member'), home_url('/'));
201 }
202 foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
203 do_action('ws_plugin__s2member_during_paypal_return_after_new_ccaps', get_defined_vars());
204 unset($__refs, $__v);
205
206 return apply_filters('c_ws_plugin__s2member_paypal_return_in_wa_ccaps_wo_level', $paypal, get_defined_vars());
207 }
208 else return apply_filters('c_ws_plugin__s2member_paypal_return_in_wa_ccaps_wo_level', FALSE, get_defined_vars());
209 }
210 }
211 }
212