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

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

470 lines 23.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PayPal® utilities.
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_utilities"))
21 {
22 /**
23 * PayPal® utilities.
24 *
25 * @package s2Member\PayPal
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_paypal_utilities
29 {
30 /**
31 * Get ``$_POST`` or ``$_REQUEST`` vars from PayPal®.
32 *
33 * @package s2Member\PayPal
34 * @since 3.5
35 *
36 * @return array|bool An array of verified ``$_POST`` or ``$_REQUEST`` variables, else false.
37 */
38 public static function paypal_postvars ()
39 {
40 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
41 do_action ("ws_plugin__s2member_before_paypal_postvars", get_defined_vars ());
42 unset ($__refs, $__v); /* Unset defined __refs, __v. */
43 /*
44 Custom conditionals can be applied by filters.
45 */
46 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
47 if (!($postvars = apply_filters ("ws_plugin__s2member_during_paypal_postvars_conditionals", array (), get_defined_vars ())))
48 {
49 unset ($__refs, $__v); /* Unset defined __refs, __v. */
50 /**/
51 if (!empty ($_GET["tx"]) && empty ($_GET["s2member_paypal_proxy"]))
52 {
53 $postback["tx"] = $_GET["tx"];
54 $postback["cmd"] = "_notify-synch";
55 $postback["at"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_identity_token"];
56 /**/
57 $endpoint = ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_sandbox"]) ? "www.sandbox.paypal.com" : "www.paypal.com";
58 /**/
59 if (preg_match ("/^SUCCESS/i", ($response = trim (c_ws_plugin__s2member_utils_urls::remote ("https://" . $endpoint . "/cgi-bin/webscr", $postback, array ("timeout" => 20))))))
60 {
61 foreach (preg_split ("/[\r\n]+/", preg_replace ("/^SUCCESS/i", "", $response)) as $varline)
62 {
63 list ($key, $value) = preg_split ("/\=/", $varline, 2);
64 if (strlen ($key = trim ($key)) && strlen ($value = trim ($value)))
65 $postvars[$key] = trim (stripslashes (urldecode ($value)));
66 }
67 /**/
68 return apply_filters ("ws_plugin__s2member_paypal_postvars", $postvars, get_defined_vars ());
69 }
70 else /* Nope. */
71 return false;
72 }
73 else if (!empty ($_REQUEST) && is_array ($postvars = stripslashes_deep ($_REQUEST)))
74 {
75 foreach ($postvars as $key => $value)
76 if (preg_match ("/^s2member_/", $key))
77 unset($postvars[$key]);
78 /**/
79 $postback = $postvars; /* Copy. */
80 $postback["cmd"] = "_notify-validate";
81 /**/
82 $postvars = c_ws_plugin__s2member_utils_strings::trim_deep ($postvars);
83 /**/
84 $endpoint = ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_sandbox"]) ? "www.sandbox.paypal.com" : "www.paypal.com";
85 /**/
86 if (!empty ($_GET["s2member_paypal_proxy"]) && !empty ($_GET["s2member_paypal_proxy_verification"]) && $_GET["s2member_paypal_proxy_verification"] === c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen ())
87 return apply_filters ("ws_plugin__s2member_paypal_postvars", array_merge ($postvars, array ("proxy_verified" => $_GET["s2member_paypal_proxy"])), get_defined_vars ());
88 /**/
89 else if (trim (strtolower (c_ws_plugin__s2member_utils_urls::remote ("https://" . $endpoint . "/cgi-bin/webscr", $postback, array ("timeout" => 20)))) === "verified")
90 return apply_filters ("ws_plugin__s2member_paypal_postvars", $postvars, get_defined_vars ());
91 /**/
92 else /* Nope. */
93 return false;
94 }
95 else /* Nope. */
96 return false;
97 }
98 else /* Else a custom conditional has been applied by Filters. */
99 {
100 unset ($__refs, $__v); /* Unset defined __refs, __v. */
101 /**/
102 return apply_filters ("ws_plugin__s2member_paypal_postvars", $postvars, get_defined_vars ());
103 }
104 }
105 /**
106 * Generates a PayPal® Proxy Key, for simulated IPN responses.
107 *
108 * @package s2Member\PayPal
109 * @since 3.5
110 *
111 * @return str A Proxy Key. It's an MD5 Hash, 32 chars, URL-safe.
112 */
113 public static function paypal_proxy_key_gen () /* Generate Key. */
114 {
115 global $current_site, $current_blog; /* Multisite Networking. */
116 /**/
117 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
118 do_action ("ws_plugin__s2member_before_paypal_proxy_key_gen", get_defined_vars ());
119 unset ($__refs, $__v); /* Unset defined __refs, __v. */
120 /**/
121 if (is_multisite () && !is_main_site ())
122 $key = md5 (c_ws_plugin__s2member_utils_encryption::xencrypt ($current_blog->domain . $current_blog->path));
123 /**/
124 else /* Else it's a standard Proxy Key; not on a Multisite Network, or not on the Main Site anyway. */
125 $key = md5 (c_ws_plugin__s2member_utils_encryption::xencrypt (preg_replace ("/\:[0-9]+$/", "", $_SERVER["HTTP_HOST"])));
126 /**/
127 return apply_filters ("ws_plugin__s2member_paypal_proxy_key_gen", $key, get_defined_vars ());
128 }
129 /**
130 * Calls upon the PayPal® API, and returns the response.
131 *
132 * @package s2Member\PayPal
133 * @since 3.5
134 *
135 * @param array $post_vars An array of variables to send through the PayPal® API call.
136 * @return array An array of variables returned by the PayPal® API.
137 *
138 * @todo Optimize this routine with ``empty()`` and ``isset()``.
139 * @todo Possibly integrate this API: {@link http://msdn.microsoft.com/en-us/library/ff512417.aspx}.
140 */
141 public static function paypal_api_response ($post_vars = FALSE)
142 {
143 global $current_site, $current_blog; /* For Multisite support. */
144 /**/
145 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
146 do_action ("ws_plugin__s2member_before_paypal_api_response", get_defined_vars ());
147 unset ($__refs, $__v); /* Unset defined __refs, __v. */
148 /**/
149 $url = "https://" . (($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_sandbox"]) ? "api-3t.sandbox.paypal.com" : "api-3t.paypal.com") . "/nvp";
150 /**/
151 $post_vars = apply_filters ("ws_plugin__s2member_paypal_api_post_vars", $post_vars, get_defined_vars ());
152 $post_vars = (is_array ($post_vars)) ? $post_vars : array (); /* Must be an array. */
153 /**/
154 $post_vars["VERSION"] = "71.0"; /* Configure the PayPal® API version. */
155 $post_vars["USER"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_api_username"];
156 $post_vars["PWD"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_api_password"];
157 $post_vars["SIGNATURE"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["paypal_api_signature"];
158 /**/
159 $input_time = date ("D M j, Y g:i:s a T"); /* Record input/nvp for logging. */
160 /**/
161 $nvp = trim (c_ws_plugin__s2member_utils_urls::remote ($url, $post_vars, array ("timeout" => 20)));
162 /**/
163 $output_time = date ("D M j, Y g:i:s a T"); /* Now record after output time. */
164 /**/
165 wp_parse_str ($nvp, $response); /* Parse NVP response. */
166 $response = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($response));
167 /**/
168 if (!$response["ACK"] || !preg_match ("/^(Success|SuccessWithWarning)$/i", $response["ACK"]))
169 {
170 if (strlen ($response["L_ERRORCODE0"]) || $response["L_SHORTMESSAGE0"] || $response["L_LONGMESSAGE0"])
171 /* translators: Exclude `%2$s` and `%3$s`. These are English details returned by PayPal®. Replace `%2$s` and `%3$s` with: `Unable to process, please try again`, or something to that affect. Or, if you prefer, you could Filter ``$response["__error"]`` with `ws_plugin__s2member_paypal_api_response`. */
172 $response["__error"] = sprintf (_x ('Error #%1$s. %2$s. %3$s.', "s2member-front", "s2member"), $response["L_ERRORCODE0"], rtrim ($response["L_SHORTMESSAGE0"], "."), rtrim ($response["L_LONGMESSAGE0"], "."));
173 /**/
174 else /* Else, generate an error messsage - so something is reported back to the Customer. */
175 $response["__error"] = _x ("Error. Please contact Support for assistance.", "s2member-front", "s2member");
176 }
177 /*
178 If debugging is enabled; we need to maintain a comprehensive log file.
179 Logging now supports Multisite Networking as well.
180 */
181 $logv = c_ws_plugin__s2member_utilities::ver_details ();
182 $logm = c_ws_plugin__s2member_utilities::mem_details ();
183 $log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"];
184 $log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4;
185 $log2 = (is_multisite () && !is_main_site ()) ? "paypal-api-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "paypal-api.log";
186 /**/
187 if (isset ($post_vars["ACCT"]) && strlen ($post_vars["ACCT"]) > 4)
188 $post_vars["ACCT"] = str_repeat ("*", strlen ($post_vars["ACCT"]) - 4) . substr ($post_vars["ACCT"], -4);
189 /**/
190 if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"])
191 if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"]))
192 if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ())
193 if (($log = "-------- Input vars: ( " . $input_time . " ) --------\n" . var_export ($post_vars, true) . "\n"))
194 if (($log .= "-------- Output string/vars: ( " . $output_time . " ) --------\n" . $nvp . "\n" . var_export ($response, true)))
195 file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . $log . "\n\n", FILE_APPEND);
196 /**/
197 return apply_filters ("ws_plugin__s2member_paypal_api_response", c_ws_plugin__s2member_paypal_utilities::_paypal_api_response_filters ($response), get_defined_vars ());
198 }
199 /**
200 * A sort of callback function that Filters PayPal® responses.
201 *
202 * Provides alternative explanations in some cases that require special attention.
203 *
204 * @package s2Member\PayPal
205 * @since 3.5
206 *
207 * @param array $response Expects an array of response variables returned by the PayPal® API.
208 * @return array An array of variables returned by the PayPal® API, after ``$response["__error"]`` is Filtered.
209 */
210 public static function _paypal_api_response_filters ($response = FALSE)
211 {
212 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
213 do_action ("_ws_plugin__s2member_before_paypal_api_response_filters", get_defined_vars ());
214 unset ($__refs, $__v); /* Unset defined __refs, __v. */
215 /**/
216 if (!empty ($response["__error"]) && !empty ($response["L_ERRORCODE0"]))
217 {
218 if ((int)$response["L_ERRORCODE0"] === 10422)
219 $response["__error"] = sprintf (_x ("Error #%s. Transaction declined. Please use an alternate funding source.", "s2member-front", "s2member"), $response["L_ERRORCODE0"]);
220 /**/
221 else if ((int)$response["L_ERRORCODE0"] === 10435)
222 $response["__error"] = sprintf (_x ("Error #%s. Transaction declined. Express Checkout was NOT confirmed.", "s2member-front", "s2member"), $response["L_ERRORCODE0"]);
223 /**/
224 else if ((int)$response["L_ERRORCODE0"] === 10417)
225 $response["__error"] = sprintf (_x ("Error #%s. Transaction declined. Please use an alternate funding source.", "s2member-front", "s2member"), $response["L_ERRORCODE0"]);
226 }
227 /**/
228 return $response; /* Filters already applied with: ``ws_plugin__s2member_paypal_api_response``. */
229 }
230 /**
231 * Converts a term `D|W|M|Y` into PayPal® Pro format.
232 *
233 * @package s2Member\PayPal
234 * @since 3.5
235 *
236 * @param str $term Expects one of `D|W|M|Y`.
237 * @return bool|str A full singular description of the term *( i.e. `Day|Week|Month|Year` )*, else false.
238 */
239 public static function paypal_pro_term ($term = FALSE)
240 {
241 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
242 do_action ("ws_plugin__s2member_before_paypal_pro_term", get_defined_vars ());
243 unset ($__refs, $__v); /* Unset defined __refs, __v. */
244 /**/
245 $paypal_pro_terms = array ("D" => "Day", "W" => "Week", "M" => "Month", "Y" => "Year");
246 /**/
247 $pro_term = (!empty ($paypal_pro_terms[strtoupper ($term)])) ? $paypal_pro_terms[strtoupper ($term)] : false;
248 /**/
249 return apply_filters ("ws_plugin__s2member_paypal_pro_term", $pro_term, get_defined_vars ());
250 }
251 /**
252 * Converts a term `Day|Week|Month|Year` into PayPal® Standard format.
253 *
254 * @package s2Member\PayPal
255 * @since 3.5
256 *
257 * @param str $term Expects one of `Day|Week|Month|Year`.
258 * @return bool|str A term code *( i.e. `D|W|M|Y` )*, else false.
259 */
260 public static function paypal_std_term ($term = FALSE)
261 {
262 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
263 do_action ("ws_plugin__s2member_before_paypal_std_term", get_defined_vars ());
264 unset ($__refs, $__v); /* Unset defined __refs, __v. */
265 /**/
266 $paypal_std_terms = array ("DAY" => "D", "WEEK" => "W", "MONTH" => "M", "YEAR" => "Y");
267 /**/
268 $std_term = (!empty ($paypal_std_terms[strtoupper ($term)])) ? $paypal_std_terms[strtoupper ($term)] : false;
269 /**/
270 return apply_filters ("ws_plugin__s2member_paypal_std_term", $std_term, get_defined_vars ());
271 }
272 /**
273 * Get `subscr_id` from either an array with `recurring_payment_id|subscr_id`, or use an existing string.
274 *
275 * @package s2Member\PayPal
276 * @since 3.5
277 *
278 * @param str|array $array_or_string Either an array of PayPal® post vars, or a string.
279 * @return str|bool A `subscr_id` string if non-empty, else false.
280 */
281 public static function paypal_pro_subscr_id ($array_or_string = FALSE)
282 {
283 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
284 do_action ("ws_plugin__s2member_before_paypal_pro_subscr_id", get_defined_vars ());
285 unset ($__refs, $__v); /* Unset defined __refs, __v. */
286 /**/
287 if (is_array ($array = $array_or_string) && !empty ($array["recurring_payment_id"]))
288 $subscr_id = trim ($array["recurring_payment_id"]);
289 /**/
290 else if (is_array ($array = $array_or_string) && !empty ($array["subscr_id"]))
291 $subscr_id = trim ($array["subscr_id"]);
292 /**/
293 else if (is_string ($string = $array_or_string) && !empty ($string))
294 $subscr_id = trim ($string);
295 /**/
296 return apply_filters ("ws_plugin__s2member_paypal_pro_subscr_id", ((!empty ($subscr_id)) ? $subscr_id : false), get_defined_vars ());
297 }
298 /**
299 * Get `item_number` from either an array with `PROFILEREFERENCE|rp_invoice_id|item_number1|item_number`, or use an existing string.
300 *
301 * @package s2Member\PayPal
302 * @since 3.5
303 *
304 * @param str|array $array_or_string Either an array of PayPal® post vars, or a string.
305 * If it's a string, we make sure it is a valid `level:ccaps:eotper` or `sp:ids:expiration` combination.
306 * @return str|bool An `item_number` string if non-empty, else false.
307 */
308 public static function paypal_pro_item_number ($array_or_string = FALSE)
309 {
310 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
311 do_action ("ws_plugin__s2member_before_paypal_pro_item_number", get_defined_vars ());
312 unset ($__refs, $__v); /* Unset defined __refs, __v. */
313 /**/
314 if (is_array ($array = $array_or_string) && (!empty ($array["PROFILEREFERENCE"]) || !empty ($array["rp_invoice_id"])))
315 list ($_reference, $_domain, $_item_number) = array_map ("trim", preg_split ("/~/", ((!empty ($array["PROFILEREFERENCE"])) ? $array["PROFILEREFERENCE"] : $array["rp_invoice_id"]), 3));
316 /**/
317 else if (is_array ($array = $array_or_string) && !empty ($array["item_number1"]))
318 $_item_number = trim ($array["item_number1"]);
319 /**/
320 else if (is_array ($array = $array_or_string) && !empty ($array["item_number"]))
321 $_item_number = trim ($array["item_number"]);
322 /**/
323 else if (is_string ($string = $array_or_string) && !empty ($string))
324 $_item_number = trim ($string);
325 /**/
326 if (!empty ($_item_number) && preg_match ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["membership_item_number_w_or_wo_level_regex"], $_item_number))
327 $item_number = $_item_number;
328 /**/
329 else if (!empty ($_item_number) && preg_match ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["sp_access_item_number_regex"], $_item_number))
330 $item_number = $_item_number;
331 /**/
332 return apply_filters ("ws_plugin__s2member_paypal_pro_item_number", ((!empty ($item_number)) ? $item_number : false), get_defined_vars ());
333 }
334 /**
335 * Get `item_name` from either an array with `product_name|item_name1|item_name`, or use an existing string.
336 *
337 * @package s2Member\PayPal
338 * @since 3.5
339 *
340 * @param str|array $array_or_string Either an array of PayPal® post vars, or a string.
341 * @return str|bool An `item_name` string if non-empty, else false.
342 */
343 public static function paypal_pro_item_name ($array_or_string = FALSE)
344 {
345 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
346 do_action ("ws_plugin__s2member_before_paypal_pro_item_name", get_defined_vars ());
347 unset ($__refs, $__v); /* Unset defined __refs, __v. */
348 /**/
349 if (is_array ($array = $array_or_string) && !empty ($array["product_name"]))
350 $item_name = trim ($array["product_name"]);
351 /**/
352 else if (is_array ($array = $array_or_string) && !empty ($array["item_name1"]))
353 $item_name = trim ($array["item_name1"]);
354 /**/
355 else if (is_array ($array = $array_or_string) && !empty ($array["item_name"]))
356 $item_name = trim ($array["item_name"]);
357 /**/
358 else if (is_string ($string = $array_or_string) && !empty ($string))
359 $item_name = trim ($string);
360 /**/
361 return apply_filters ("ws_plugin__s2member_paypal_pro_item_name", ((!empty ($item_name)) ? $item_name : false), get_defined_vars ());
362 }
363 /**
364 * Get `period1` from either an array with `PROFILEREFERENCE|rp_invoice_id|period1`, or use an existing string.
365 *
366 * This will also convert `1 Day`, into `1 D`, and so on.
367 * This will also convert `1 SemiMonth`, into `2 W`, and so on.
368 *
369 * @package s2Member\PayPal
370 * @since 3.5
371 *
372 * @param str|array $array_or_string Either an array of PayPal® post vars, or a string.
373 * If it's a string, we make sure it is a valid `period term` combination.
374 * @param str $default Optional. Value if unavailable. Defaults to `0 D`.
375 * @return str A `period1` string if possible, or defaults to `0 D`.
376 */
377 public static function paypal_pro_period1 ($array_or_string = FALSE, $default = "0 D")
378 {
379 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
380 do_action ("ws_plugin__s2member_before_paypal_pro_period1", get_defined_vars ());
381 unset ($__refs, $__v); /* Unset defined __refs, __v. */
382 /**/
383 if (is_array ($array = $array_or_string) && (!empty ($array["PROFILEREFERENCE"]) || !empty ($array["rp_invoice_id"])))
384 {
385 list ($_reference, $_domain, $_item_number) = array_map ("trim", preg_split ("/~/", ((!empty ($array["PROFILEREFERENCE"])) ? $array["PROFILEREFERENCE"] : $array["rp_invoice_id"]), 3));
386 list ($_start_time, $_period1, $_period3) = array_map ("trim", preg_split ("/\:/", $_reference, 3));
387 }
388 else if (is_array ($array = $array_or_string) && !empty ($array["period1"]))
389 $_period1 = trim ($array["period1"]);
390 /**/
391 else if (is_string ($string = $array_or_string) && !empty ($string))
392 $_period1 = trim ($string);
393 /**/
394 if (!empty ($_period1)) /* Were we able to get a `period1` string? */
395 {
396 list ($num, $span) = array_map ("trim", preg_split ("/ /", $_period1, 2));
397 /**/
398 if (strtoupper ($span) === "SEMIMONTH")
399 if (is_numeric ($num) && $num >= 1)
400 eval('$num = "2"; $span = "W";');
401 /**/
402 if (strlen ($span) !== 1) /* To Standard format. */
403 $span = c_ws_plugin__s2member_paypal_utilities::paypal_std_term ($span);
404 /**/
405 $span = (preg_match ("/^[DWMY]$/i", $span)) ? $span : "";
406 $num = ($span && is_numeric ($num) && $num >= 0) ? $num : "";
407 /**/
408 $period1 = ($num && $span) ? $num . " " . strtoupper ($span) : $default;
409 /**/
410 return apply_filters ("ws_plugin__s2member_paypal_pro_period1", $period1, get_defined_vars ());
411 }
412 else /* Default. */
413 return apply_filters ("ws_plugin__s2member_paypal_pro_period1", $default, get_defined_vars ());
414 }
415 /**
416 * Get `period3` from either an array with `PROFILEREFERENCE|rp_invoice_id|period3`, or use an existing string.
417 *
418 * This will also convert `1 Day`, into `1 D`, and so on.
419 * This will also convert `1 SemiMonth`, into `2 W`, and so on.
420 * The Regular Period can never be less than 1 day ( `1 D` ).
421 *
422 * @package s2Member\PayPal
423 * @since 3.5
424 *
425 * @param str|array $array_or_string Either an array of PayPal® post vars, or a string.
426 * If it's a string, we make sure it is a valid `period term` combination.
427 * @param str $default Optional. Value if unavailable. Defaults to `1 D`.
428 * @return str A `period3` string if possible, or defaults to `1 D`.
429 */
430 public static function paypal_pro_period3 ($array_or_string = FALSE, $default = "1 D")
431 {
432 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
433 do_action ("ws_plugin__s2member_before_paypal_pro_period3", get_defined_vars ());
434 unset ($__refs, $__v); /* Unset defined __refs, __v. */
435 /**/
436 if (is_array ($array = $array_or_string) && (!empty ($array["PROFILEREFERENCE"]) || !empty ($array["rp_invoice_id"])))
437 {
438 list ($_reference, $_domain, $_item_number) = array_map ("trim", preg_split ("/~/", ((!empty ($array["PROFILEREFERENCE"])) ? $array["PROFILEREFERENCE"] : $array["rp_invoice_id"]), 3));
439 list ($_start_time, $_period1, $_period3) = array_map ("trim", preg_split ("/\:/", $_reference, 3));
440 }
441 else if (is_array ($array = $array_or_string) && !empty ($array["period3"]))
442 $_period3 = trim ($array["period3"]);
443 /**/
444 else if (is_string ($string = $array_or_string) && !empty ($string))
445 $_period3 = trim ($string);
446 /**/
447 if (!empty ($_period3)) /* Were we able to get a `period3` string? */
448 {
449 list ($num, $span) = array_map ("trim", preg_split ("/ /", $_period3, 2));
450 /**/
451 if (strtoupper ($span) === "SEMIMONTH")
452 if (is_numeric ($num) && $num >= 1)
453 eval('$num = "2"; $span = "W";');
454 /**/
455 if (strlen ($span) !== 1) /* To Standard format. */
456 $span = c_ws_plugin__s2member_paypal_utilities::paypal_std_term ($span);
457 /**/
458 $span = (preg_match ("/^[DWMY]$/i", $span)) ? $span : "";
459 $num = ($span && is_numeric ($num) && $num >= 0) ? $num : "";
460 /**/
461 $period3 = ($num && $span) ? $num . " " . strtoupper ($span) : $default;
462 /**/
463 return apply_filters ("ws_plugin__s2member_paypal_pro_period3", $period3, get_defined_vars ());
464 }
465 else /* Default. */
466 return apply_filters ("ws_plugin__s2member_paypal_pro_period3", $default, get_defined_vars ());
467 }
468 }
469 }
470 ?>