PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 260909
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v260909
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-web-accept-sp.inc.php

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

154 lines 10.1 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_web_accept_sp'))
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_web_accept_sp
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']['sp_access_item_number_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['txn_baid']) || ($paypal['txn_baid'] = $paypal['txn_id']))
49 && (!empty($paypal['txn_cid']) || ($paypal['txn_cid'] = $paypal['txn_id']))
50 )
51 {
52 foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
53 do_action('ws_plugin__s2member_during_paypal_return_before_sp_access', get_defined_vars());
54 unset($__refs, $__v);
55
56 if(!get_transient($transient_rtn = 's2m_rtn_'.md5('s2member_transient_'.$_paypal_s)) && set_transient($transient_rtn, time(), 31556926 * 10))
57 {
58 $paypal['s2member_log'][] = 's2Member `txn_type` identified as ( `web_accept` ) for Specific Post/Page Access.';
59
60 list (, $paypal['sp_ids'], $paypal['hours']) = preg_split('/\:/', $paypal['item_number'], 3);
61
62 //260814 Set optional gateway elements used below so sparse/null payload fields do not trigger PHP diagnostics.
63 $paypal = c_ws_plugin__s2member_utils_arrays::set_unset_elements($paypal, array('option_name2', 'option_selection2', 'invoice', 'first_name', 'last_name'));
64
65 $paypal['ip'] = (preg_match('/ip address/i', $paypal['option_name2']) && $paypal['option_selection2']) ? $paypal['option_selection2'] : '';
66 $paypal['ip'] = (!$paypal['ip'] && preg_match('/^[a-z0-9]+~[0-9\.]+$/i', $paypal['invoice'])) ? preg_replace('/^[a-z0-9]+~/i', '', $paypal['invoice']) : $paypal['ip'];
67 $paypal['ip'] = (!$paypal['ip'] && c_ws_plugin__s2member_utils_ip::current()) ? c_ws_plugin__s2member_utils_ip::current() : $paypal['ip'];
68
69 $paypal['currency'] = strtoupper($paypal['mc_currency']); // Normalize input currency.
70 $paypal['currency_symbol'] = c_ws_plugin__s2member_utils_cur::symbol($paypal['currency']);
71
72 if(($sp_access_url = c_ws_plugin__s2member_sp_access::sp_access_link_gen($paypal['sp_ids'], $paypal['hours'], FALSE)))
73 {
74 $processing = $during = TRUE; // Yes, we ARE processing this.
75
76 setcookie('s2member_sp_tracking', ($s2member_sp_tracking = c_ws_plugin__s2member_utils_encryption::encrypt($paypal['txn_id'])), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN).setcookie('s2member_sp_tracking', $s2member_sp_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN).($_COOKIE['s2member_sp_tracking'] = $s2member_sp_tracking);
77
78 $paypal['s2member_log'][] = 'Transient Tracking Cookie set on ( `web_accept` ) for Specific Post/Page Access.';
79
80 if($processing && ($code = $GLOBALS['WS_PLUGIN__']['s2member']['o']['sp_tracking_codes']))
81 {
82 $paypal = c_ws_plugin__s2member_utils_strings::strip_php_tags_deep($paypal); //251003
83 if(($code = c_ws_plugin__s2member_utils_strings::fill_cvs($code, $paypal['custom'])) && ($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)))
84 if(($code = preg_replace('/%%txn_baid%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['txn_baid']), $code)) && ($code = preg_replace('/%%txn_cid%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['txn_cid']), $code)))
85 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)))
86 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)))
87 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)))
88 if(($code = preg_replace('/%%full_name%%/i', c_ws_plugin__s2member_utils_strings::esc_refs(trim($paypal['first_name'].' '.$paypal['last_name'])), $code)))
89 if(($code = preg_replace('/%%payer_email%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['payer_email']), $code)))
90 if(($code = preg_replace('/%%user_ip%%/i', c_ws_plugin__s2member_utils_strings::esc_refs($paypal['ip']), $code)))
91
92 if(($code = trim(preg_replace('/%%(.+?)%%/i', '', $code)))) // This gets stored into a Transient Queue.
93 {
94 $paypal['s2member_log'][] = 'Storing Specific Post/Page Tracking Codes into a Transient Queue. These will be processed on-site.';
95 set_transient('s2m_'.md5('s2member_transient_sp_tracking_codes_'.$paypal['txn_id']), $code, 43200);
96 }
97 }
98 foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
99 do_action('ws_plugin__s2member_during_paypal_return_during_sp_access', get_defined_vars());
100 unset($__refs, $__v);
101
102 if(apply_filters('ws_plugin__s2member_immediate_sp_access_redirection', FALSE, get_defined_vars()))
103 {
104 $paypal['s2member_log'][] = 'Redirecting Customer immediately to the Specific Post/Page.';
105
106 wp_redirect($sp_access_url); // Immediate redirection to Specific Post/Page.
107 }
108 else if($custom_success_redirection) // Using a custom success redirection URL?
109 {
110 $paypal['s2member_log'][] = 'Redirecting Customer to a custom URL on success: '.$custom_success_redirection;
111
112 wp_redirect($custom_success_redirection);
113 }
114 else // Else use the default return URL in this scenario, which is the Specific Post/Page.
115 {
116 $paypal['s2member_log'][] = 'Redirecting Customer to the Specific Post/Page (after displaying a thank-you message).';
117
118 echo c_ws_plugin__s2member_return_templates::return_template($paypal['subscr_gateway'],
119 _x('<strong>Thank You! Your transaction has been approved.</strong>', 's2member-front', 's2member'),
120 _x('Continue (Click Here)', 's2member-front', 's2member'), $sp_access_url);
121 }
122 }
123 else // Otherwise, the ID must have been invalid. Or the Post/Page was deleted.
124 {
125 $paypal['s2member_log'][] = 'Unable to generate Specific Post/Page Access Link. Does your Leading Post/Page still exist?';
126
127 $paypal['s2member_log'][] = 'Redirecting Customer to the Home Page (after displaying an error message).';
128
129 echo c_ws_plugin__s2member_return_templates::return_template($paypal['subscr_gateway'],
130 _x('<strong>ERROR:</strong> Unable to generate Access Link.<br />Please contact Support for assistance.', 's2member-front', 's2member'),
131 _x('Back To Home Page', 's2member-front', 's2member'), home_url('/'));
132 }
133 }
134 else // Page Expired. Duplicate Return-Data.
135 {
136 $paypal['s2member_log'][] = 'Page Expired. Duplicate Return-Data.';
137 $paypal['s2member_log'][] = 's2Member `txn_type` identified as ( `web_accept` ) for Specific Post/Page Access.';
138 $paypal['s2member_log'][] = 'Page Expired. Instructing customer to check their email for further details about how to obtain access to what they purchased.';
139
140 echo c_ws_plugin__s2member_return_templates::return_template($paypal['subscr_gateway'],
141 '<strong>'._x('Thank you! Please check your email for further details regarding your purchase.', 's2member-front', 's2member').'</strong>',
142 _x('Return to Home Page', 's2member-front', 's2member'), home_url('/'));
143 }
144 foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
145 do_action('ws_plugin__s2member_during_paypal_return_after_sp_access', get_defined_vars());
146 unset($__refs, $__v);
147
148 return apply_filters('c_ws_plugin__s2member_paypal_return_in_web_accept_sp', $paypal, get_defined_vars());
149 }
150 else return apply_filters('c_ws_plugin__s2member_paypal_return_in_web_accept_sp', FALSE, get_defined_vars());
151 }
152 }
153 }
154