@@ -12,270 +12,270 @@ |
||
12 | 12 | class EEH_URL |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * _add_query_arg |
|
17 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
18 | - * |
|
19 | - * @access public |
|
20 | - * @param array $args |
|
21 | - * @param string $url |
|
22 | - * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
26 | - { |
|
27 | - // check that an action exists and add nonce |
|
28 | - if (! $exclude_nonce) { |
|
29 | - if (isset($args['action']) && ! empty($args['action'])) { |
|
30 | - $args = array_merge( |
|
31 | - $args, |
|
32 | - array( |
|
33 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
34 | - ) |
|
35 | - ); |
|
36 | - } else { |
|
37 | - $args = array_merge( |
|
38 | - $args, |
|
39 | - array( |
|
40 | - 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
41 | - ) |
|
42 | - ); |
|
43 | - } |
|
44 | - } |
|
15 | + /** |
|
16 | + * _add_query_arg |
|
17 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
18 | + * |
|
19 | + * @access public |
|
20 | + * @param array $args |
|
21 | + * @param string $url |
|
22 | + * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
26 | + { |
|
27 | + // check that an action exists and add nonce |
|
28 | + if (! $exclude_nonce) { |
|
29 | + if (isset($args['action']) && ! empty($args['action'])) { |
|
30 | + $args = array_merge( |
|
31 | + $args, |
|
32 | + array( |
|
33 | + $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
34 | + ) |
|
35 | + ); |
|
36 | + } else { |
|
37 | + $args = array_merge( |
|
38 | + $args, |
|
39 | + array( |
|
40 | + 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
41 | + ) |
|
42 | + ); |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | - // finally, let's always add a return address (if present) :) |
|
47 | - $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
48 | - ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
49 | - : $args; |
|
46 | + // finally, let's always add a return address (if present) :) |
|
47 | + $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
48 | + ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
49 | + : $args; |
|
50 | 50 | |
51 | - return add_query_arg($args, $url); |
|
52 | - } |
|
51 | + return add_query_arg($args, $url); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Returns whether not the remote file exists. |
|
57 | - * Checking via GET because HEAD requests are blocked on some server configurations. |
|
58 | - * |
|
59 | - * @param string $url |
|
60 | - * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
61 | - * @return boolean |
|
62 | - */ |
|
63 | - public static function remote_file_exists($url, $args = array()) |
|
64 | - { |
|
65 | - $results = wp_remote_request( |
|
66 | - $url, |
|
67 | - array_merge( |
|
68 | - array( |
|
69 | - 'method' => 'GET', |
|
70 | - 'redirection' => 1, |
|
71 | - ), |
|
72 | - $args |
|
73 | - ) |
|
74 | - ); |
|
75 | - if (! $results instanceof WP_Error && |
|
76 | - isset($results['response']) && |
|
77 | - isset($results['response']['code']) && |
|
78 | - $results['response']['code'] == '200') { |
|
79 | - return true; |
|
80 | - } else { |
|
81 | - return false; |
|
82 | - } |
|
83 | - } |
|
55 | + /** |
|
56 | + * Returns whether not the remote file exists. |
|
57 | + * Checking via GET because HEAD requests are blocked on some server configurations. |
|
58 | + * |
|
59 | + * @param string $url |
|
60 | + * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
61 | + * @return boolean |
|
62 | + */ |
|
63 | + public static function remote_file_exists($url, $args = array()) |
|
64 | + { |
|
65 | + $results = wp_remote_request( |
|
66 | + $url, |
|
67 | + array_merge( |
|
68 | + array( |
|
69 | + 'method' => 'GET', |
|
70 | + 'redirection' => 1, |
|
71 | + ), |
|
72 | + $args |
|
73 | + ) |
|
74 | + ); |
|
75 | + if (! $results instanceof WP_Error && |
|
76 | + isset($results['response']) && |
|
77 | + isset($results['response']['code']) && |
|
78 | + $results['response']['code'] == '200') { |
|
79 | + return true; |
|
80 | + } else { |
|
81 | + return false; |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | |
86 | - /** |
|
87 | - * refactor_url |
|
88 | - * primarily used for removing the query string from a URL |
|
89 | - * |
|
90 | - * @param string $url |
|
91 | - * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
92 | - * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
96 | - { |
|
97 | - // break apart incoming URL |
|
98 | - $url_bits = parse_url($url); |
|
99 | - // HTTP or HTTPS ? |
|
100 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
101 | - // domain |
|
102 | - $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
103 | - // if only the base URL is requested, then return that now |
|
104 | - if ($base_url_only) { |
|
105 | - return $scheme . $host; |
|
106 | - } |
|
107 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
108 | - $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
109 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
110 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
111 | - $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
112 | - // if the query string is not required, then return what we have so far |
|
113 | - if ($remove_query) { |
|
114 | - return $scheme . $user . $pass . $host . $port . $path; |
|
115 | - } |
|
116 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
117 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
118 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
119 | - } |
|
86 | + /** |
|
87 | + * refactor_url |
|
88 | + * primarily used for removing the query string from a URL |
|
89 | + * |
|
90 | + * @param string $url |
|
91 | + * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
92 | + * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
96 | + { |
|
97 | + // break apart incoming URL |
|
98 | + $url_bits = parse_url($url); |
|
99 | + // HTTP or HTTPS ? |
|
100 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
101 | + // domain |
|
102 | + $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
103 | + // if only the base URL is requested, then return that now |
|
104 | + if ($base_url_only) { |
|
105 | + return $scheme . $host; |
|
106 | + } |
|
107 | + $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
108 | + $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
109 | + $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
110 | + $pass = ($user || $pass) ? $pass . '@' : ''; |
|
111 | + $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
112 | + // if the query string is not required, then return what we have so far |
|
113 | + if ($remove_query) { |
|
114 | + return $scheme . $user . $pass . $host . $port . $path; |
|
115 | + } |
|
116 | + $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
117 | + $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
118 | + return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
119 | + } |
|
120 | 120 | |
121 | 121 | |
122 | - /** |
|
123 | - * get_query_string |
|
124 | - * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
125 | - * |
|
126 | - * @param string $url |
|
127 | - * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
128 | - * simply return the query string |
|
129 | - * @return string|array |
|
130 | - */ |
|
131 | - public static function get_query_string($url = '', $as_array = true) |
|
132 | - { |
|
133 | - // decode, then break apart incoming URL |
|
134 | - $url_bits = parse_url(html_entity_decode($url)); |
|
135 | - // grab query string from URL |
|
136 | - $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
137 | - // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
138 | - if (! $as_array) { |
|
139 | - return $query; |
|
140 | - } |
|
141 | - // if no query string exists then just return an empty array now |
|
142 | - if (empty($query)) { |
|
143 | - return array(); |
|
144 | - } |
|
145 | - // empty array to hold results |
|
146 | - $query_params = array(); |
|
147 | - // now break apart the query string into separate params |
|
148 | - $query = explode('&', $query); |
|
149 | - // loop thru our query params |
|
150 | - foreach ($query as $query_args) { |
|
151 | - // break apart the key value pairs |
|
152 | - $query_args = explode('=', $query_args); |
|
153 | - // and add to our results array |
|
154 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
155 | - } |
|
156 | - return $query_params; |
|
157 | - } |
|
122 | + /** |
|
123 | + * get_query_string |
|
124 | + * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
125 | + * |
|
126 | + * @param string $url |
|
127 | + * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
128 | + * simply return the query string |
|
129 | + * @return string|array |
|
130 | + */ |
|
131 | + public static function get_query_string($url = '', $as_array = true) |
|
132 | + { |
|
133 | + // decode, then break apart incoming URL |
|
134 | + $url_bits = parse_url(html_entity_decode($url)); |
|
135 | + // grab query string from URL |
|
136 | + $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
137 | + // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
138 | + if (! $as_array) { |
|
139 | + return $query; |
|
140 | + } |
|
141 | + // if no query string exists then just return an empty array now |
|
142 | + if (empty($query)) { |
|
143 | + return array(); |
|
144 | + } |
|
145 | + // empty array to hold results |
|
146 | + $query_params = array(); |
|
147 | + // now break apart the query string into separate params |
|
148 | + $query = explode('&', $query); |
|
149 | + // loop thru our query params |
|
150 | + foreach ($query as $query_args) { |
|
151 | + // break apart the key value pairs |
|
152 | + $query_args = explode('=', $query_args); |
|
153 | + // and add to our results array |
|
154 | + $query_params[ $query_args[0] ] = $query_args[1]; |
|
155 | + } |
|
156 | + return $query_params; |
|
157 | + } |
|
158 | 158 | |
159 | 159 | |
160 | - /** |
|
161 | - * prevent_prefetching |
|
162 | - * |
|
163 | - * @return void |
|
164 | - */ |
|
165 | - public static function prevent_prefetching() |
|
166 | - { |
|
167 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
168 | - // with the registration process |
|
169 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
170 | - } |
|
160 | + /** |
|
161 | + * prevent_prefetching |
|
162 | + * |
|
163 | + * @return void |
|
164 | + */ |
|
165 | + public static function prevent_prefetching() |
|
166 | + { |
|
167 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
168 | + // with the registration process |
|
169 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
170 | + } |
|
171 | 171 | |
172 | 172 | |
173 | - /** |
|
174 | - * This generates a unique site-specific string. |
|
175 | - * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
176 | - * urls. |
|
177 | - * |
|
178 | - * @param string $prefix Use this to prefix the string with something. |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public static function generate_unique_token($prefix = '') |
|
182 | - { |
|
183 | - $token = md5(uniqid() . mt_rand()); |
|
184 | - return $prefix ? $prefix . '_' . $token : $token; |
|
185 | - } |
|
173 | + /** |
|
174 | + * This generates a unique site-specific string. |
|
175 | + * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
176 | + * urls. |
|
177 | + * |
|
178 | + * @param string $prefix Use this to prefix the string with something. |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public static function generate_unique_token($prefix = '') |
|
182 | + { |
|
183 | + $token = md5(uniqid() . mt_rand()); |
|
184 | + return $prefix ? $prefix . '_' . $token : $token; |
|
185 | + } |
|
186 | 186 | |
187 | 187 | |
188 | - /** |
|
189 | - * filter_input_server_url |
|
190 | - * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
191 | - * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
192 | - * |
|
193 | - * @param string $server_variable |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
197 | - { |
|
198 | - $URL = ''; |
|
199 | - $server_variables = array( |
|
200 | - 'REQUEST_URI' => 1, |
|
201 | - 'HTTP_HOST' => 1, |
|
202 | - 'PHP_SELF' => 1, |
|
203 | - ); |
|
204 | - $server_variable = strtoupper($server_variable); |
|
205 | - // whitelist INPUT_SERVER var |
|
206 | - if (isset($server_variables[ $server_variable ])) { |
|
207 | - $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
208 | - if (empty($URL)) { |
|
209 | - // fallback sanitization if the above fails |
|
210 | - $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
211 | - } |
|
212 | - } |
|
213 | - return $URL; |
|
214 | - } |
|
188 | + /** |
|
189 | + * filter_input_server_url |
|
190 | + * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
191 | + * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
192 | + * |
|
193 | + * @param string $server_variable |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
197 | + { |
|
198 | + $URL = ''; |
|
199 | + $server_variables = array( |
|
200 | + 'REQUEST_URI' => 1, |
|
201 | + 'HTTP_HOST' => 1, |
|
202 | + 'PHP_SELF' => 1, |
|
203 | + ); |
|
204 | + $server_variable = strtoupper($server_variable); |
|
205 | + // whitelist INPUT_SERVER var |
|
206 | + if (isset($server_variables[ $server_variable ])) { |
|
207 | + $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
208 | + if (empty($URL)) { |
|
209 | + // fallback sanitization if the above fails |
|
210 | + $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
211 | + } |
|
212 | + } |
|
213 | + return $URL; |
|
214 | + } |
|
215 | 215 | |
216 | 216 | |
217 | - /** |
|
218 | - * Gets the current page's full URL. |
|
219 | - * |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public static function current_url() |
|
223 | - { |
|
224 | - $url = ''; |
|
225 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
226 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
227 | - $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
228 | - $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
229 | - } |
|
230 | - return $url; |
|
231 | - } |
|
217 | + /** |
|
218 | + * Gets the current page's full URL. |
|
219 | + * |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public static function current_url() |
|
223 | + { |
|
224 | + $url = ''; |
|
225 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
226 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
227 | + $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
228 | + $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
229 | + } |
|
230 | + return $url; |
|
231 | + } |
|
232 | 232 | |
233 | 233 | |
234 | - /** |
|
235 | - * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
236 | - * |
|
237 | - * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
238 | - * @since 4.9.46.rc.029 |
|
239 | - * @return string |
|
240 | - */ |
|
241 | - public static function current_url_without_query_paramaters(array $query_parameters) |
|
242 | - { |
|
243 | - return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
244 | - } |
|
234 | + /** |
|
235 | + * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
236 | + * |
|
237 | + * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
238 | + * @since 4.9.46.rc.029 |
|
239 | + * @return string |
|
240 | + */ |
|
241 | + public static function current_url_without_query_paramaters(array $query_parameters) |
|
242 | + { |
|
243 | + return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
244 | + } |
|
245 | 245 | |
246 | 246 | |
247 | - /** |
|
248 | - * @param string $location |
|
249 | - * @param int $status |
|
250 | - * @param string $exit_notice |
|
251 | - */ |
|
252 | - public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '') |
|
253 | - { |
|
254 | - EE_Error::get_notices(false, true); |
|
255 | - wp_safe_redirect($location, $status); |
|
256 | - exit($exit_notice); |
|
257 | - } |
|
247 | + /** |
|
248 | + * @param string $location |
|
249 | + * @param int $status |
|
250 | + * @param string $exit_notice |
|
251 | + */ |
|
252 | + public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '') |
|
253 | + { |
|
254 | + EE_Error::get_notices(false, true); |
|
255 | + wp_safe_redirect($location, $status); |
|
256 | + exit($exit_notice); |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * Slugifies text for usage in a URL. |
|
261 | - * |
|
262 | - * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters, |
|
263 | - * and WordPress chokes on them when used as CPT and custom taxonomy slugs. |
|
264 | - * |
|
265 | - * @since 4.9.66.p |
|
266 | - * @param string $text |
|
267 | - * @param string $fallback |
|
268 | - * @return string which can be used in a URL |
|
269 | - */ |
|
270 | - public static function slugify($text, $fallback) |
|
271 | - { |
|
272 | - // url decode after sanitizing title to restore unicode characters, |
|
273 | - // see https://github.com/eventespresso/event-espresso-core/issues/575 |
|
274 | - return urldecode( |
|
275 | - sanitize_title( |
|
276 | - $text, |
|
277 | - $fallback |
|
278 | - ) |
|
279 | - ); |
|
280 | - } |
|
259 | + /** |
|
260 | + * Slugifies text for usage in a URL. |
|
261 | + * |
|
262 | + * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters, |
|
263 | + * and WordPress chokes on them when used as CPT and custom taxonomy slugs. |
|
264 | + * |
|
265 | + * @since 4.9.66.p |
|
266 | + * @param string $text |
|
267 | + * @param string $fallback |
|
268 | + * @return string which can be used in a URL |
|
269 | + */ |
|
270 | + public static function slugify($text, $fallback) |
|
271 | + { |
|
272 | + // url decode after sanitizing title to restore unicode characters, |
|
273 | + // see https://github.com/eventespresso/event-espresso-core/issues/575 |
|
274 | + return urldecode( |
|
275 | + sanitize_title( |
|
276 | + $text, |
|
277 | + $fallback |
|
278 | + ) |
|
279 | + ); |
|
280 | + } |
|
281 | 281 | } |
@@ -25,12 +25,12 @@ discard block |
||
25 | 25 | public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
26 | 26 | { |
27 | 27 | // check that an action exists and add nonce |
28 | - if (! $exclude_nonce) { |
|
28 | + if ( ! $exclude_nonce) { |
|
29 | 29 | if (isset($args['action']) && ! empty($args['action'])) { |
30 | 30 | $args = array_merge( |
31 | 31 | $args, |
32 | 32 | array( |
33 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
33 | + $args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce') |
|
34 | 34 | ) |
35 | 35 | ); |
36 | 36 | } else { |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $args |
73 | 73 | ) |
74 | 74 | ); |
75 | - if (! $results instanceof WP_Error && |
|
75 | + if ( ! $results instanceof WP_Error && |
|
76 | 76 | isset($results['response']) && |
77 | 77 | isset($results['response']['code']) && |
78 | 78 | $results['response']['code'] == '200') { |
@@ -97,25 +97,25 @@ discard block |
||
97 | 97 | // break apart incoming URL |
98 | 98 | $url_bits = parse_url($url); |
99 | 99 | // HTTP or HTTPS ? |
100 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
100 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://'; |
|
101 | 101 | // domain |
102 | 102 | $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
103 | 103 | // if only the base URL is requested, then return that now |
104 | 104 | if ($base_url_only) { |
105 | - return $scheme . $host; |
|
105 | + return $scheme.$host; |
|
106 | 106 | } |
107 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
107 | + $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : ''; |
|
108 | 108 | $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
109 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
110 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
109 | + $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : ''; |
|
110 | + $pass = ($user || $pass) ? $pass.'@' : ''; |
|
111 | 111 | $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
112 | 112 | // if the query string is not required, then return what we have so far |
113 | 113 | if ($remove_query) { |
114 | - return $scheme . $user . $pass . $host . $port . $path; |
|
114 | + return $scheme.$user.$pass.$host.$port.$path; |
|
115 | 115 | } |
116 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
117 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
118 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
116 | + $query = isset($url_bits['query']) ? '?'.$url_bits['query'] : ''; |
|
117 | + $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : ''; |
|
118 | + return $scheme.$user.$pass.$host.$port.$path.$query.$fragment; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | // grab query string from URL |
136 | 136 | $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
137 | 137 | // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
138 | - if (! $as_array) { |
|
138 | + if ( ! $as_array) { |
|
139 | 139 | return $query; |
140 | 140 | } |
141 | 141 | // if no query string exists then just return an empty array now |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | // break apart the key value pairs |
152 | 152 | $query_args = explode('=', $query_args); |
153 | 153 | // and add to our results array |
154 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
154 | + $query_params[$query_args[0]] = $query_args[1]; |
|
155 | 155 | } |
156 | 156 | return $query_params; |
157 | 157 | } |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public static function generate_unique_token($prefix = '') |
182 | 182 | { |
183 | - $token = md5(uniqid() . mt_rand()); |
|
184 | - return $prefix ? $prefix . '_' . $token : $token; |
|
183 | + $token = md5(uniqid().mt_rand()); |
|
184 | + return $prefix ? $prefix.'_'.$token : $token; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | 'HTTP_HOST' => 1, |
202 | 202 | 'PHP_SELF' => 1, |
203 | 203 | ); |
204 | - $server_variable = strtoupper($server_variable); |
|
204 | + $server_variable = strtoupper($server_variable); |
|
205 | 205 | // whitelist INPUT_SERVER var |
206 | - if (isset($server_variables[ $server_variable ])) { |
|
206 | + if (isset($server_variables[$server_variable])) { |
|
207 | 207 | $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
208 | 208 | if (empty($URL)) { |
209 | 209 | // fallback sanitization if the above fails |
210 | - $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
210 | + $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | return $URL; |
@@ -29,358 +29,358 @@ |
||
29 | 29 | class EED_Batch extends EED_Module |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
34 | - * processes data only |
|
35 | - */ |
|
36 | - const batch_job = 'job'; |
|
37 | - /** |
|
38 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
39 | - * produces a file for download |
|
40 | - */ |
|
41 | - const batch_file_job = 'file'; |
|
42 | - /** |
|
43 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
44 | - * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
45 | - * at all |
|
46 | - */ |
|
47 | - const batch_not_job = 'none'; |
|
32 | + /** |
|
33 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
34 | + * processes data only |
|
35 | + */ |
|
36 | + const batch_job = 'job'; |
|
37 | + /** |
|
38 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
39 | + * produces a file for download |
|
40 | + */ |
|
41 | + const batch_file_job = 'file'; |
|
42 | + /** |
|
43 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
44 | + * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
45 | + * at all |
|
46 | + */ |
|
47 | + const batch_not_job = 'none'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * |
|
51 | - * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
52 | - */ |
|
53 | - protected $_batch_request_type = null; |
|
49 | + /** |
|
50 | + * |
|
51 | + * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
52 | + */ |
|
53 | + protected $_batch_request_type = null; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Because we want to use the response in both the localized JS and in the body |
|
57 | - * we need to make this response available between method calls |
|
58 | - * |
|
59 | - * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
60 | - */ |
|
61 | - protected $_job_step_response = null; |
|
55 | + /** |
|
56 | + * Because we want to use the response in both the localized JS and in the body |
|
57 | + * we need to make this response available between method calls |
|
58 | + * |
|
59 | + * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
60 | + */ |
|
61 | + protected $_job_step_response = null; |
|
62 | 62 | |
63 | - /** |
|
64 | - * @var LoaderInterface |
|
65 | - */ |
|
66 | - protected $loader; |
|
63 | + /** |
|
64 | + * @var LoaderInterface |
|
65 | + */ |
|
66 | + protected $loader; |
|
67 | 67 | |
68 | - /** |
|
69 | - * Gets the batch instance |
|
70 | - * |
|
71 | - * @return EED_Batch |
|
72 | - */ |
|
73 | - public static function instance() |
|
74 | - { |
|
75 | - return self::get_instance(); |
|
76 | - } |
|
68 | + /** |
|
69 | + * Gets the batch instance |
|
70 | + * |
|
71 | + * @return EED_Batch |
|
72 | + */ |
|
73 | + public static function instance() |
|
74 | + { |
|
75 | + return self::get_instance(); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
80 | - * because it's an attack vector and there are currently no implementations |
|
81 | - */ |
|
82 | - public static function set_hooks() |
|
83 | - { |
|
84 | - // because this is a possibel attack vector, let's have this disabled until |
|
85 | - // we at least have a real use for it on the frontend |
|
86 | - if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
87 | - add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
88 | - add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
89 | - } |
|
90 | - } |
|
78 | + /** |
|
79 | + * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
80 | + * because it's an attack vector and there are currently no implementations |
|
81 | + */ |
|
82 | + public static function set_hooks() |
|
83 | + { |
|
84 | + // because this is a possibel attack vector, let's have this disabled until |
|
85 | + // we at least have a real use for it on the frontend |
|
86 | + if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
87 | + add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
88 | + add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Initializes some hooks for the admin in order to run batch jobs |
|
94 | - */ |
|
95 | - public static function set_hooks_admin() |
|
96 | - { |
|
97 | - add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
98 | - add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
92 | + /** |
|
93 | + * Initializes some hooks for the admin in order to run batch jobs |
|
94 | + */ |
|
95 | + public static function set_hooks_admin() |
|
96 | + { |
|
97 | + add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
98 | + add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
99 | 99 | |
100 | - // ajax |
|
101 | - add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
102 | - add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
103 | - add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
104 | - add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
105 | - } |
|
100 | + // ajax |
|
101 | + add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
102 | + add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
103 | + add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
104 | + add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @since 4.9.80.p |
|
109 | - * @return LoaderInterface |
|
110 | - * @throws InvalidArgumentException |
|
111 | - * @throws InvalidDataTypeException |
|
112 | - * @throws InvalidInterfaceException |
|
113 | - */ |
|
114 | - protected function getLoader() |
|
115 | - { |
|
116 | - if (!$this->loader instanceof LoaderInterface) { |
|
117 | - $this->loader = LoaderFactory::getLoader(); |
|
118 | - } |
|
119 | - return $this->loader; |
|
120 | - } |
|
107 | + /** |
|
108 | + * @since 4.9.80.p |
|
109 | + * @return LoaderInterface |
|
110 | + * @throws InvalidArgumentException |
|
111 | + * @throws InvalidDataTypeException |
|
112 | + * @throws InvalidInterfaceException |
|
113 | + */ |
|
114 | + protected function getLoader() |
|
115 | + { |
|
116 | + if (!$this->loader instanceof LoaderInterface) { |
|
117 | + $this->loader = LoaderFactory::getLoader(); |
|
118 | + } |
|
119 | + return $this->loader; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Enqueues batch scripts on the frontend or admin, and creates a job |
|
124 | - */ |
|
125 | - public function enqueue_scripts() |
|
126 | - { |
|
127 | - if (isset($_REQUEST['espresso_batch']) |
|
128 | - || |
|
129 | - ( |
|
130 | - isset($_REQUEST['page']) |
|
131 | - && $_REQUEST['page'] == 'espresso_batch' |
|
132 | - ) |
|
133 | - ) { |
|
134 | - if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
135 | - wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
|
136 | - } |
|
137 | - switch ($this->batch_request_type()) { |
|
138 | - case self::batch_job: |
|
139 | - $this->enqueue_scripts_styles_batch_create(); |
|
140 | - break; |
|
141 | - case self::batch_file_job: |
|
142 | - $this->enqueue_scripts_styles_batch_file_create(); |
|
143 | - break; |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
122 | + /** |
|
123 | + * Enqueues batch scripts on the frontend or admin, and creates a job |
|
124 | + */ |
|
125 | + public function enqueue_scripts() |
|
126 | + { |
|
127 | + if (isset($_REQUEST['espresso_batch']) |
|
128 | + || |
|
129 | + ( |
|
130 | + isset($_REQUEST['page']) |
|
131 | + && $_REQUEST['page'] == 'espresso_batch' |
|
132 | + ) |
|
133 | + ) { |
|
134 | + if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
135 | + wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
|
136 | + } |
|
137 | + switch ($this->batch_request_type()) { |
|
138 | + case self::batch_job: |
|
139 | + $this->enqueue_scripts_styles_batch_create(); |
|
140 | + break; |
|
141 | + case self::batch_file_job: |
|
142 | + $this->enqueue_scripts_styles_batch_file_create(); |
|
143 | + break; |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
150 | - */ |
|
151 | - public function enqueue_scripts_styles_batch_create() |
|
152 | - { |
|
153 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
154 | - wp_enqueue_script( |
|
155 | - 'batch_runner_init', |
|
156 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
157 | - array('batch_runner'), |
|
158 | - EVENT_ESPRESSO_VERSION, |
|
159 | - true |
|
160 | - ); |
|
161 | - wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
162 | - wp_localize_script( |
|
163 | - 'batch_runner_init', |
|
164 | - 'ee_job_i18n', |
|
165 | - array( |
|
166 | - 'return_url' => $_REQUEST['return_url'], |
|
167 | - ) |
|
168 | - ); |
|
169 | - } |
|
148 | + /** |
|
149 | + * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
150 | + */ |
|
151 | + public function enqueue_scripts_styles_batch_create() |
|
152 | + { |
|
153 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
154 | + wp_enqueue_script( |
|
155 | + 'batch_runner_init', |
|
156 | + BATCH_URL . 'assets/batch_runner_init.js', |
|
157 | + array('batch_runner'), |
|
158 | + EVENT_ESPRESSO_VERSION, |
|
159 | + true |
|
160 | + ); |
|
161 | + wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
162 | + wp_localize_script( |
|
163 | + 'batch_runner_init', |
|
164 | + 'ee_job_i18n', |
|
165 | + array( |
|
166 | + 'return_url' => $_REQUEST['return_url'], |
|
167 | + ) |
|
168 | + ); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
173 | - */ |
|
174 | - public function enqueue_scripts_styles_batch_file_create() |
|
175 | - { |
|
176 | - // creates a job based on the request variable |
|
177 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
178 | - wp_enqueue_script( |
|
179 | - 'batch_file_runner_init', |
|
180 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
181 | - array('batch_runner'), |
|
182 | - EVENT_ESPRESSO_VERSION, |
|
183 | - true |
|
184 | - ); |
|
185 | - wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
186 | - wp_localize_script( |
|
187 | - 'batch_file_runner_init', |
|
188 | - 'ee_job_i18n', |
|
189 | - array( |
|
190 | - 'download_and_redirecting' => sprintf( |
|
191 | - __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
192 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
193 | - '</a>' |
|
194 | - ), |
|
195 | - 'return_url' => $_REQUEST['return_url'], |
|
196 | - ) |
|
197 | - ); |
|
198 | - } |
|
171 | + /** |
|
172 | + * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
173 | + */ |
|
174 | + public function enqueue_scripts_styles_batch_file_create() |
|
175 | + { |
|
176 | + // creates a job based on the request variable |
|
177 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
178 | + wp_enqueue_script( |
|
179 | + 'batch_file_runner_init', |
|
180 | + BATCH_URL . 'assets/batch_file_runner_init.js', |
|
181 | + array('batch_runner'), |
|
182 | + EVENT_ESPRESSO_VERSION, |
|
183 | + true |
|
184 | + ); |
|
185 | + wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
186 | + wp_localize_script( |
|
187 | + 'batch_file_runner_init', |
|
188 | + 'ee_job_i18n', |
|
189 | + array( |
|
190 | + 'download_and_redirecting' => sprintf( |
|
191 | + __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
192 | + '<a href="' . $_REQUEST['return_url'] . '">', |
|
193 | + '</a>' |
|
194 | + ), |
|
195 | + 'return_url' => $_REQUEST['return_url'], |
|
196 | + ) |
|
197 | + ); |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * Enqueues scripts and styles common to any batch job, and creates |
|
202 | - * a job from the request data, and stores the response in the |
|
203 | - * $this->_job_step_response property |
|
204 | - * |
|
205 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
206 | - */ |
|
207 | - protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
208 | - { |
|
209 | - // just copy the bits of EE admin's eei18n that we need in the JS |
|
210 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
211 | - 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
212 | - 'event_espresso' |
|
213 | - ); |
|
214 | - wp_register_script( |
|
215 | - 'progress_bar', |
|
216 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
217 | - array('jquery'), |
|
218 | - EVENT_ESPRESSO_VERSION, |
|
219 | - true |
|
220 | - ); |
|
221 | - wp_enqueue_style( |
|
222 | - 'progress_bar', |
|
223 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
224 | - array(), |
|
225 | - EVENT_ESPRESSO_VERSION |
|
226 | - ); |
|
227 | - wp_enqueue_script( |
|
228 | - 'batch_runner', |
|
229 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
230 | - array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
231 | - EVENT_ESPRESSO_VERSION, |
|
232 | - true |
|
233 | - ); |
|
234 | - $job_handler_classname = stripslashes($_GET['job_handler']); |
|
235 | - $request_data = array_diff_key( |
|
236 | - $_REQUEST, |
|
237 | - array_flip(array('action', 'page', 'ee', 'batch')) |
|
238 | - ); |
|
239 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
240 | - // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
241 | - $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
242 | - // remember the response for later. We need it to display the page body |
|
243 | - $this->_job_step_response = $job_response; |
|
244 | - return $job_response; |
|
245 | - } |
|
200 | + /** |
|
201 | + * Enqueues scripts and styles common to any batch job, and creates |
|
202 | + * a job from the request data, and stores the response in the |
|
203 | + * $this->_job_step_response property |
|
204 | + * |
|
205 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
206 | + */ |
|
207 | + protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
208 | + { |
|
209 | + // just copy the bits of EE admin's eei18n that we need in the JS |
|
210 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
211 | + 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
212 | + 'event_espresso' |
|
213 | + ); |
|
214 | + wp_register_script( |
|
215 | + 'progress_bar', |
|
216 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
217 | + array('jquery'), |
|
218 | + EVENT_ESPRESSO_VERSION, |
|
219 | + true |
|
220 | + ); |
|
221 | + wp_enqueue_style( |
|
222 | + 'progress_bar', |
|
223 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
224 | + array(), |
|
225 | + EVENT_ESPRESSO_VERSION |
|
226 | + ); |
|
227 | + wp_enqueue_script( |
|
228 | + 'batch_runner', |
|
229 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
230 | + array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
231 | + EVENT_ESPRESSO_VERSION, |
|
232 | + true |
|
233 | + ); |
|
234 | + $job_handler_classname = stripslashes($_GET['job_handler']); |
|
235 | + $request_data = array_diff_key( |
|
236 | + $_REQUEST, |
|
237 | + array_flip(array('action', 'page', 'ee', 'batch')) |
|
238 | + ); |
|
239 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
240 | + // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
241 | + $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
242 | + // remember the response for later. We need it to display the page body |
|
243 | + $this->_job_step_response = $job_response; |
|
244 | + return $job_response; |
|
245 | + } |
|
246 | 246 | |
247 | - /** |
|
248 | - * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
249 | - * |
|
250 | - * @param string $template |
|
251 | - * @return string |
|
252 | - */ |
|
253 | - public function override_template($template) |
|
254 | - { |
|
255 | - if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
256 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
257 | - } |
|
258 | - return $template; |
|
259 | - } |
|
247 | + /** |
|
248 | + * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
249 | + * |
|
250 | + * @param string $template |
|
251 | + * @return string |
|
252 | + */ |
|
253 | + public function override_template($template) |
|
254 | + { |
|
255 | + if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
256 | + return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
257 | + } |
|
258 | + return $template; |
|
259 | + } |
|
260 | 260 | |
261 | - /** |
|
262 | - * Adds an admin page which doesn't appear in the admin menu |
|
263 | - */ |
|
264 | - public function register_admin_pages() |
|
265 | - { |
|
266 | - add_submenu_page( |
|
267 | - '', // parent slug. we don't want this to actually appear in the menu |
|
268 | - __('Batch Job', 'event_espresso'), // page title |
|
269 | - 'n/a', // menu title |
|
270 | - 'read', // we want this page to actually be accessible to anyone, |
|
271 | - 'espresso_batch', // menu slug |
|
272 | - array(self::instance(), 'show_admin_page') |
|
273 | - ); |
|
274 | - } |
|
261 | + /** |
|
262 | + * Adds an admin page which doesn't appear in the admin menu |
|
263 | + */ |
|
264 | + public function register_admin_pages() |
|
265 | + { |
|
266 | + add_submenu_page( |
|
267 | + '', // parent slug. we don't want this to actually appear in the menu |
|
268 | + __('Batch Job', 'event_espresso'), // page title |
|
269 | + 'n/a', // menu title |
|
270 | + 'read', // we want this page to actually be accessible to anyone, |
|
271 | + 'espresso_batch', // menu slug |
|
272 | + array(self::instance(), 'show_admin_page') |
|
273 | + ); |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
278 | - * of creating the job and localizing some data |
|
279 | - */ |
|
280 | - public function show_admin_page() |
|
281 | - { |
|
282 | - echo EEH_Template::locate_template( |
|
283 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
284 | - array('batch_request_type' => $this->batch_request_type()) |
|
285 | - ); |
|
286 | - } |
|
276 | + /** |
|
277 | + * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
278 | + * of creating the job and localizing some data |
|
279 | + */ |
|
280 | + public function show_admin_page() |
|
281 | + { |
|
282 | + echo EEH_Template::locate_template( |
|
283 | + EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
284 | + array('batch_request_type' => $this->batch_request_type()) |
|
285 | + ); |
|
286 | + } |
|
287 | 287 | |
288 | - /** |
|
289 | - * Receives ajax calls for continuing a job |
|
290 | - */ |
|
291 | - public function batch_continue() |
|
292 | - { |
|
293 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
294 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
295 | - $response_obj = $batch_runner->continue_job($job_id); |
|
296 | - $this->_return_json($response_obj->to_array()); |
|
297 | - } |
|
288 | + /** |
|
289 | + * Receives ajax calls for continuing a job |
|
290 | + */ |
|
291 | + public function batch_continue() |
|
292 | + { |
|
293 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
294 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
295 | + $response_obj = $batch_runner->continue_job($job_id); |
|
296 | + $this->_return_json($response_obj->to_array()); |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * Receives the ajax call to cleanup a job |
|
301 | - * |
|
302 | - * @return type |
|
303 | - */ |
|
304 | - public function batch_cleanup() |
|
305 | - { |
|
306 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
307 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
308 | - $response_obj = $batch_runner->cleanup_job($job_id); |
|
309 | - $this->_return_json($response_obj->to_array()); |
|
310 | - } |
|
299 | + /** |
|
300 | + * Receives the ajax call to cleanup a job |
|
301 | + * |
|
302 | + * @return type |
|
303 | + */ |
|
304 | + public function batch_cleanup() |
|
305 | + { |
|
306 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
307 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
308 | + $response_obj = $batch_runner->cleanup_job($job_id); |
|
309 | + $this->_return_json($response_obj->to_array()); |
|
310 | + } |
|
311 | 311 | |
312 | 312 | |
313 | - /** |
|
314 | - * Returns a json response |
|
315 | - * |
|
316 | - * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
317 | - * |
|
318 | - * The returned json object is created from an array in the following format: |
|
319 | - * array( |
|
320 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
321 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
322 | - * We're also going to include the template args with every package (so js can pick out any specific template |
|
323 | - * args that might be included in here) |
|
324 | - * 'isEEajax' => true,//indicates this is a response from EE |
|
325 | - * ) |
|
326 | - */ |
|
327 | - protected function _return_json($data) |
|
328 | - { |
|
329 | - $json = array( |
|
330 | - 'notices' => EE_Error::get_notices(), |
|
331 | - 'data' => $data, |
|
332 | - 'isEEajax' => true |
|
333 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
334 | - ); |
|
313 | + /** |
|
314 | + * Returns a json response |
|
315 | + * |
|
316 | + * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
317 | + * |
|
318 | + * The returned json object is created from an array in the following format: |
|
319 | + * array( |
|
320 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
321 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
322 | + * We're also going to include the template args with every package (so js can pick out any specific template |
|
323 | + * args that might be included in here) |
|
324 | + * 'isEEajax' => true,//indicates this is a response from EE |
|
325 | + * ) |
|
326 | + */ |
|
327 | + protected function _return_json($data) |
|
328 | + { |
|
329 | + $json = array( |
|
330 | + 'notices' => EE_Error::get_notices(), |
|
331 | + 'data' => $data, |
|
332 | + 'isEEajax' => true |
|
333 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
334 | + ); |
|
335 | 335 | |
336 | 336 | |
337 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
338 | - if (null === error_get_last() || ! headers_sent()) { |
|
339 | - header('Content-Type: application/json; charset=UTF-8'); |
|
340 | - } |
|
341 | - echo wp_json_encode($json); |
|
342 | - exit(); |
|
343 | - } |
|
337 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
338 | + if (null === error_get_last() || ! headers_sent()) { |
|
339 | + header('Content-Type: application/json; charset=UTF-8'); |
|
340 | + } |
|
341 | + echo wp_json_encode($json); |
|
342 | + exit(); |
|
343 | + } |
|
344 | 344 | |
345 | - /** |
|
346 | - * Gets the job step response which was done during the enqueuing of scripts |
|
347 | - * |
|
348 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
349 | - */ |
|
350 | - public function job_step_response() |
|
351 | - { |
|
352 | - return $this->_job_step_response; |
|
353 | - } |
|
345 | + /** |
|
346 | + * Gets the job step response which was done during the enqueuing of scripts |
|
347 | + * |
|
348 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
349 | + */ |
|
350 | + public function job_step_response() |
|
351 | + { |
|
352 | + return $this->_job_step_response; |
|
353 | + } |
|
354 | 354 | |
355 | - /** |
|
356 | - * Gets the batch request type indicated in the $_REQUEST |
|
357 | - * |
|
358 | - * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
359 | - */ |
|
360 | - public function batch_request_type() |
|
361 | - { |
|
362 | - if ($this->_batch_request_type === null) { |
|
363 | - if (isset($_GET['batch'])) { |
|
364 | - if ($_GET['batch'] == self::batch_job) { |
|
365 | - $this->_batch_request_type = self::batch_job; |
|
366 | - } elseif ($_GET['batch'] == self::batch_file_job) { |
|
367 | - $this->_batch_request_type = self::batch_file_job; |
|
368 | - } |
|
369 | - } |
|
370 | - // if we didn't find that it was a batch request, indicate it wasn't |
|
371 | - if ($this->_batch_request_type === null) { |
|
372 | - $this->_batch_request_type = self::batch_not_job; |
|
373 | - } |
|
374 | - } |
|
375 | - return $this->_batch_request_type; |
|
376 | - } |
|
355 | + /** |
|
356 | + * Gets the batch request type indicated in the $_REQUEST |
|
357 | + * |
|
358 | + * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
359 | + */ |
|
360 | + public function batch_request_type() |
|
361 | + { |
|
362 | + if ($this->_batch_request_type === null) { |
|
363 | + if (isset($_GET['batch'])) { |
|
364 | + if ($_GET['batch'] == self::batch_job) { |
|
365 | + $this->_batch_request_type = self::batch_job; |
|
366 | + } elseif ($_GET['batch'] == self::batch_file_job) { |
|
367 | + $this->_batch_request_type = self::batch_file_job; |
|
368 | + } |
|
369 | + } |
|
370 | + // if we didn't find that it was a batch request, indicate it wasn't |
|
371 | + if ($this->_batch_request_type === null) { |
|
372 | + $this->_batch_request_type = self::batch_not_job; |
|
373 | + } |
|
374 | + } |
|
375 | + return $this->_batch_request_type; |
|
376 | + } |
|
377 | 377 | |
378 | - /** |
|
379 | - * Unnecessary |
|
380 | - * |
|
381 | - * @param type $WP |
|
382 | - */ |
|
383 | - public function run($WP) |
|
384 | - { |
|
385 | - } |
|
378 | + /** |
|
379 | + * Unnecessary |
|
380 | + * |
|
381 | + * @param type $WP |
|
382 | + */ |
|
383 | + public function run($WP) |
|
384 | + { |
|
385 | + } |
|
386 | 386 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | protected function getLoader() |
115 | 115 | { |
116 | - if (!$this->loader instanceof LoaderInterface) { |
|
116 | + if ( ! $this->loader instanceof LoaderInterface) { |
|
117 | 117 | $this->loader = LoaderFactory::getLoader(); |
118 | 118 | } |
119 | 119 | return $this->loader; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | && $_REQUEST['page'] == 'espresso_batch' |
132 | 132 | ) |
133 | 133 | ) { |
134 | - if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
134 | + if ( ! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) { |
|
135 | 135 | wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso')); |
136 | 136 | } |
137 | 137 | switch ($this->batch_request_type()) { |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
154 | 154 | wp_enqueue_script( |
155 | 155 | 'batch_runner_init', |
156 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
156 | + BATCH_URL.'assets/batch_runner_init.js', |
|
157 | 157 | array('batch_runner'), |
158 | 158 | EVENT_ESPRESSO_VERSION, |
159 | 159 | true |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
178 | 178 | wp_enqueue_script( |
179 | 179 | 'batch_file_runner_init', |
180 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
180 | + BATCH_URL.'assets/batch_file_runner_init.js', |
|
181 | 181 | array('batch_runner'), |
182 | 182 | EVENT_ESPRESSO_VERSION, |
183 | 183 | true |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | array( |
190 | 190 | 'download_and_redirecting' => sprintf( |
191 | 191 | __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
192 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
192 | + '<a href="'.$_REQUEST['return_url'].'">', |
|
193 | 193 | '</a>' |
194 | 194 | ), |
195 | 195 | 'return_url' => $_REQUEST['return_url'], |
@@ -207,26 +207,26 @@ discard block |
||
207 | 207 | protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
208 | 208 | { |
209 | 209 | // just copy the bits of EE admin's eei18n that we need in the JS |
210 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
210 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
211 | 211 | 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
212 | 212 | 'event_espresso' |
213 | 213 | ); |
214 | 214 | wp_register_script( |
215 | 215 | 'progress_bar', |
216 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
216 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js', |
|
217 | 217 | array('jquery'), |
218 | 218 | EVENT_ESPRESSO_VERSION, |
219 | 219 | true |
220 | 220 | ); |
221 | 221 | wp_enqueue_style( |
222 | 222 | 'progress_bar', |
223 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
223 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css', |
|
224 | 224 | array(), |
225 | 225 | EVENT_ESPRESSO_VERSION |
226 | 226 | ); |
227 | 227 | wp_enqueue_script( |
228 | 228 | 'batch_runner', |
229 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
229 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js', |
|
230 | 230 | array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
231 | 231 | EVENT_ESPRESSO_VERSION, |
232 | 232 | true |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | public function override_template($template) |
254 | 254 | { |
255 | 255 | if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
256 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
256 | + return EE_MODULES.'batch'.DS.'templates'.DS.'batch_frontend_wrapper.template.html'; |
|
257 | 257 | } |
258 | 258 | return $template; |
259 | 259 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | public function show_admin_page() |
281 | 281 | { |
282 | 282 | echo EEH_Template::locate_template( |
283 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
283 | + EE_MODULES.'batch'.DS.'templates'.DS.'batch_wrapper.template.html', |
|
284 | 284 | array('batch_request_type' => $this->batch_request_type()) |
285 | 285 | ); |
286 | 286 | } |
@@ -12,2893 +12,2893 @@ |
||
12 | 12 | class EE_SPCO_Reg_Step_Payment_Options extends EE_SPCO_Reg_Step |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @access protected |
|
17 | - * @var EE_Line_Item_Display $Line_Item_Display |
|
18 | - */ |
|
19 | - protected $line_item_display; |
|
20 | - |
|
21 | - /** |
|
22 | - * @access protected |
|
23 | - * @var boolean $handle_IPN_in_this_request |
|
24 | - */ |
|
25 | - protected $handle_IPN_in_this_request = false; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
30 | - * |
|
31 | - * @access public |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public static function set_hooks() |
|
35 | - { |
|
36 | - add_filter( |
|
37 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
38 | - array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
39 | - ); |
|
40 | - add_action( |
|
41 | - 'wp_ajax_switch_spco_billing_form', |
|
42 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
43 | - ); |
|
44 | - add_action( |
|
45 | - 'wp_ajax_nopriv_switch_spco_billing_form', |
|
46 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
47 | - ); |
|
48 | - add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
49 | - add_action( |
|
50 | - 'wp_ajax_nopriv_save_payer_details', |
|
51 | - array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
52 | - ); |
|
53 | - add_action( |
|
54 | - 'wp_ajax_get_transaction_details_for_gateways', |
|
55 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
56 | - ); |
|
57 | - add_action( |
|
58 | - 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
59 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
60 | - ); |
|
61 | - add_filter( |
|
62 | - 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
63 | - array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
64 | - 10, |
|
65 | - 1 |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * ajax switch_spco_billing_form |
|
72 | - * |
|
73 | - * @throws \EE_Error |
|
74 | - */ |
|
75 | - public static function switch_spco_billing_form() |
|
76 | - { |
|
77 | - EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * ajax save_payer_details |
|
83 | - * |
|
84 | - * @throws \EE_Error |
|
85 | - */ |
|
86 | - public static function save_payer_details() |
|
87 | - { |
|
88 | - EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * ajax get_transaction_details |
|
94 | - * |
|
95 | - * @throws \EE_Error |
|
96 | - */ |
|
97 | - public static function get_transaction_details() |
|
98 | - { |
|
99 | - EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * bypass_recaptcha_for_load_payment_method |
|
105 | - * |
|
106 | - * @access public |
|
107 | - * @return array |
|
108 | - * @throws InvalidArgumentException |
|
109 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
110 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
111 | - */ |
|
112 | - public static function bypass_recaptcha_for_load_payment_method() |
|
113 | - { |
|
114 | - return array( |
|
115 | - 'EESID' => EE_Registry::instance()->SSN->id(), |
|
116 | - 'step' => 'payment_options', |
|
117 | - 'action' => 'spco_billing_form', |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * class constructor |
|
124 | - * |
|
125 | - * @access public |
|
126 | - * @param EE_Checkout $checkout |
|
127 | - */ |
|
128 | - public function __construct(EE_Checkout $checkout) |
|
129 | - { |
|
130 | - $this->_slug = 'payment_options'; |
|
131 | - $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
133 | - $this->checkout = $checkout; |
|
134 | - $this->_reset_success_message(); |
|
135 | - $this->set_instructions( |
|
136 | - esc_html__( |
|
137 | - 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
138 | - 'event_espresso' |
|
139 | - ) |
|
140 | - ); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return null |
|
146 | - */ |
|
147 | - public function line_item_display() |
|
148 | - { |
|
149 | - return $this->line_item_display; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param null $line_item_display |
|
155 | - */ |
|
156 | - public function set_line_item_display($line_item_display) |
|
157 | - { |
|
158 | - $this->line_item_display = $line_item_display; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @return boolean |
|
164 | - */ |
|
165 | - public function handle_IPN_in_this_request() |
|
166 | - { |
|
167 | - return $this->handle_IPN_in_this_request; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param boolean $handle_IPN_in_this_request |
|
173 | - */ |
|
174 | - public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
175 | - { |
|
176 | - $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * translate_js_strings |
|
182 | - * |
|
183 | - * @return void |
|
184 | - */ |
|
185 | - public function translate_js_strings() |
|
186 | - { |
|
187 | - EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
188 | - 'Please select a method of payment in order to continue.', |
|
189 | - 'event_espresso' |
|
190 | - ); |
|
191 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
192 | - 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
193 | - 'event_espresso' |
|
194 | - ); |
|
195 | - EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
196 | - 'Forwarding to Secure Payment Provider.', |
|
197 | - 'event_espresso' |
|
198 | - ); |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * enqueue_styles_and_scripts |
|
204 | - * |
|
205 | - * @return void |
|
206 | - * @throws EE_Error |
|
207 | - * @throws InvalidArgumentException |
|
208 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
209 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
210 | - */ |
|
211 | - public function enqueue_styles_and_scripts() |
|
212 | - { |
|
213 | - $transaction = $this->checkout->transaction; |
|
214 | - // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
215 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
216 | - return; |
|
217 | - } |
|
218 | - foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
219 | - $transaction, |
|
220 | - EEM_Payment_Method::scope_cart |
|
221 | - ) as $payment_method) { |
|
222 | - $type_obj = $payment_method->type_obj(); |
|
223 | - if ($type_obj instanceof EE_PMT_Base) { |
|
224 | - $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
225 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
226 | - $billing_form->enqueue_js(); |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * initialize_reg_step |
|
235 | - * |
|
236 | - * @return bool |
|
237 | - * @throws EE_Error |
|
238 | - * @throws InvalidArgumentException |
|
239 | - * @throws ReflectionException |
|
240 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
241 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
242 | - */ |
|
243 | - public function initialize_reg_step() |
|
244 | - { |
|
245 | - // TODO: if /when we implement donations, then this will need overriding |
|
246 | - if (// don't need payment options for: |
|
247 | - // registrations made via the admin |
|
248 | - // completed transactions |
|
249 | - // overpaid transactions |
|
250 | - // $ 0.00 transactions(no payment required) |
|
251 | - ! $this->checkout->payment_required() |
|
252 | - // but do NOT remove if current action being called belongs to this reg step |
|
253 | - && ! is_callable(array($this, $this->checkout->action)) |
|
254 | - && ! $this->completed() |
|
255 | - ) { |
|
256 | - // and if so, then we no longer need the Payment Options step |
|
257 | - if ($this->is_current_step()) { |
|
258 | - $this->checkout->generate_reg_form = false; |
|
259 | - } |
|
260 | - $this->checkout->remove_reg_step($this->_slug); |
|
261 | - // DEBUG LOG |
|
262 | - // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
263 | - return false; |
|
264 | - } |
|
265 | - // load EEM_Payment_Method |
|
266 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
267 | - // get all active payment methods |
|
268 | - $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
269 | - $this->checkout->transaction, |
|
270 | - EEM_Payment_Method::scope_cart |
|
271 | - ); |
|
272 | - return true; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * @return EE_Form_Section_Proper |
|
278 | - * @throws EE_Error |
|
279 | - * @throws InvalidArgumentException |
|
280 | - * @throws ReflectionException |
|
281 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
282 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
283 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
284 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
285 | - */ |
|
286 | - public function generate_reg_form() |
|
287 | - { |
|
288 | - // reset in case someone changes their mind |
|
289 | - $this->_reset_selected_method_of_payment(); |
|
290 | - // set some defaults |
|
291 | - $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
292 | - $registrations_requiring_payment = array(); |
|
293 | - $registrations_for_free_events = array(); |
|
294 | - $registrations_requiring_pre_approval = array(); |
|
295 | - $sold_out_events = array(); |
|
296 | - $insufficient_spaces_available = array(); |
|
297 | - $no_payment_required = true; |
|
298 | - // loop thru registrations to gather info |
|
299 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
300 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
301 | - $registrations, |
|
302 | - $this->checkout->revisit |
|
303 | - ); |
|
304 | - foreach ($registrations as $REG_ID => $registration) { |
|
305 | - /** @var $registration EE_Registration */ |
|
306 | - // has this registration lost it's space ? |
|
307 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
308 | - if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
309 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
310 | - } else { |
|
311 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
312 | - } |
|
313 | - continue; |
|
314 | - } |
|
315 | - // event requires admin approval |
|
316 | - if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
317 | - // add event to list of events with pre-approval reg status |
|
318 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
319 | - do_action( |
|
320 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
321 | - $registration->event(), |
|
322 | - $this |
|
323 | - ); |
|
324 | - continue; |
|
325 | - } |
|
326 | - if ($this->checkout->revisit |
|
327 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
328 | - && ( |
|
329 | - $registration->event()->is_sold_out() |
|
330 | - || $registration->event()->is_sold_out(true) |
|
331 | - ) |
|
332 | - ) { |
|
333 | - // add event to list of events that are sold out |
|
334 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
335 | - do_action( |
|
336 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
337 | - $registration->event(), |
|
338 | - $this |
|
339 | - ); |
|
340 | - continue; |
|
341 | - } |
|
342 | - // are they allowed to pay now and is there monies owing? |
|
343 | - if ($registration->owes_monies_and_can_pay()) { |
|
344 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
345 | - do_action( |
|
346 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
347 | - $registration->event(), |
|
348 | - $this |
|
349 | - ); |
|
350 | - } elseif (! $this->checkout->revisit |
|
351 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
352 | - && $registration->ticket()->is_free() |
|
353 | - ) { |
|
354 | - $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
355 | - } |
|
356 | - } |
|
357 | - $subsections = array(); |
|
358 | - // now decide which template to load |
|
359 | - if (! empty($sold_out_events)) { |
|
360 | - $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
361 | - } |
|
362 | - if (! empty($insufficient_spaces_available)) { |
|
363 | - $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
364 | - $insufficient_spaces_available |
|
365 | - ); |
|
366 | - } |
|
367 | - if (! empty($registrations_requiring_pre_approval)) { |
|
368 | - $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
369 | - $registrations_requiring_pre_approval |
|
370 | - ); |
|
371 | - } |
|
372 | - if (! empty($registrations_for_free_events)) { |
|
373 | - $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
374 | - } |
|
375 | - if (! empty($registrations_requiring_payment)) { |
|
376 | - if ($this->checkout->amount_owing > 0) { |
|
377 | - // autoload Line_Item_Display classes |
|
378 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
379 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
380 | - apply_filters( |
|
381 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
382 | - new EE_Line_Item_Filter_Collection() |
|
383 | - ), |
|
384 | - $this->checkout->cart->get_grand_total() |
|
385 | - ); |
|
386 | - /** @var EE_Line_Item $filtered_line_item_tree */ |
|
387 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
388 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
389 | - $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
390 | - $subsections['payment_options'] = $this->_display_payment_options( |
|
391 | - $this->line_item_display->display_line_item( |
|
392 | - $filtered_line_item_tree, |
|
393 | - array('registrations' => $registrations) |
|
394 | - ) |
|
395 | - ); |
|
396 | - $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
397 | - $this->_apply_registration_payments_to_amount_owing($registrations); |
|
398 | - } |
|
399 | - $no_payment_required = false; |
|
400 | - } else { |
|
401 | - $this->_hide_reg_step_submit_button_if_revisit(); |
|
402 | - } |
|
403 | - $this->_save_selected_method_of_payment(); |
|
404 | - |
|
405 | - $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
406 | - $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
407 | - |
|
408 | - return new EE_Form_Section_Proper( |
|
409 | - array( |
|
410 | - 'name' => $this->reg_form_name(), |
|
411 | - 'html_id' => $this->reg_form_name(), |
|
412 | - 'subsections' => $subsections, |
|
413 | - 'layout_strategy' => new EE_No_Layout(), |
|
414 | - ) |
|
415 | - ); |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * add line item filters required for this reg step |
|
421 | - * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
422 | - * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
423 | - * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
424 | - * payment options reg step, can apply these filters via the following: apply_filters( |
|
425 | - * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
426 | - * filter collection by passing that instead of instantiating a new collection |
|
427 | - * |
|
428 | - * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
429 | - * @return EE_Line_Item_Filter_Collection |
|
430 | - * @throws EE_Error |
|
431 | - * @throws InvalidArgumentException |
|
432 | - * @throws ReflectionException |
|
433 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
434 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
435 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
436 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
437 | - */ |
|
438 | - public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
439 | - { |
|
440 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
441 | - return $line_item_filter_collection; |
|
442 | - } |
|
443 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
444 | - return $line_item_filter_collection; |
|
445 | - } |
|
446 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
447 | - return $line_item_filter_collection; |
|
448 | - } |
|
449 | - $line_item_filter_collection->add( |
|
450 | - new EE_Billable_Line_Item_Filter( |
|
451 | - EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
452 | - EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
453 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
454 | - ) |
|
455 | - ) |
|
456 | - ) |
|
457 | - ); |
|
458 | - $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
459 | - return $line_item_filter_collection; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * remove_ejected_registrations |
|
465 | - * if a registrant has lost their potential space at an event due to lack of payment, |
|
466 | - * then this method removes them from the list of registrations being paid for during this request |
|
467 | - * |
|
468 | - * @param \EE_Registration[] $registrations |
|
469 | - * @return EE_Registration[] |
|
470 | - * @throws EE_Error |
|
471 | - * @throws InvalidArgumentException |
|
472 | - * @throws ReflectionException |
|
473 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
474 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
475 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
476 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
477 | - */ |
|
478 | - public static function remove_ejected_registrations(array $registrations) |
|
479 | - { |
|
480 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
481 | - $registrations, |
|
482 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
483 | - ); |
|
484 | - foreach ($registrations as $REG_ID => $registration) { |
|
485 | - // has this registration lost it's space ? |
|
486 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
487 | - unset($registrations[ $REG_ID ]); |
|
488 | - continue; |
|
489 | - } |
|
490 | - } |
|
491 | - return $registrations; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * find_registrations_that_lost_their_space |
|
497 | - * If a registrant chooses an offline payment method like Invoice, |
|
498 | - * then no space is reserved for them at the event until they fully pay fo that site |
|
499 | - * (unless the event's default reg status is set to APPROVED) |
|
500 | - * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
501 | - * then this method will determine which registrations have lost the ability to complete the reg process. |
|
502 | - * |
|
503 | - * @param \EE_Registration[] $registrations |
|
504 | - * @param bool $revisit |
|
505 | - * @return array |
|
506 | - * @throws EE_Error |
|
507 | - * @throws InvalidArgumentException |
|
508 | - * @throws ReflectionException |
|
509 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
510 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
511 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
512 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
513 | - */ |
|
514 | - public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
515 | - { |
|
516 | - // registrations per event |
|
517 | - $event_reg_count = array(); |
|
518 | - // spaces left per event |
|
519 | - $event_spaces_remaining = array(); |
|
520 | - // tickets left sorted by ID |
|
521 | - $tickets_remaining = array(); |
|
522 | - // registrations that have lost their space |
|
523 | - $ejected_registrations = array(); |
|
524 | - foreach ($registrations as $REG_ID => $registration) { |
|
525 | - if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
526 | - || apply_filters( |
|
527 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
528 | - false, |
|
529 | - $registration, |
|
530 | - $revisit |
|
531 | - ) |
|
532 | - ) { |
|
533 | - continue; |
|
534 | - } |
|
535 | - $EVT_ID = $registration->event_ID(); |
|
536 | - $ticket = $registration->ticket(); |
|
537 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
538 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
539 | - } |
|
540 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
541 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
542 | - $event_reg_count[ $EVT_ID ] = 0; |
|
543 | - } |
|
544 | - $event_reg_count[ $EVT_ID ]++; |
|
545 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
546 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
547 | - } |
|
548 | - } |
|
549 | - if ($revisit |
|
550 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
551 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
552 | - ) |
|
553 | - ) { |
|
554 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
555 | - if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
556 | - /** @type EE_Registration_Processor $registration_processor */ |
|
557 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
558 | - // at this point, we should have enough details about the registrant to consider the registration |
|
559 | - // NOT incomplete |
|
560 | - $registration_processor->manually_update_registration_status( |
|
561 | - $registration, |
|
562 | - EEM_Registration::status_id_wait_list |
|
563 | - ); |
|
564 | - } |
|
565 | - } |
|
566 | - } |
|
567 | - return $ejected_registrations; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * _hide_reg_step_submit_button |
|
573 | - * removes the html for the reg step submit button |
|
574 | - * by replacing it with an empty string via filter callback |
|
575 | - * |
|
576 | - * @return void |
|
577 | - */ |
|
578 | - protected function _adjust_registration_status_if_event_old_sold() |
|
579 | - { |
|
580 | - } |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * _hide_reg_step_submit_button |
|
585 | - * removes the html for the reg step submit button |
|
586 | - * by replacing it with an empty string via filter callback |
|
587 | - * |
|
588 | - * @return void |
|
589 | - */ |
|
590 | - protected function _hide_reg_step_submit_button_if_revisit() |
|
591 | - { |
|
592 | - if ($this->checkout->revisit) { |
|
593 | - add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
594 | - } |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - /** |
|
599 | - * sold_out_events |
|
600 | - * displays notices regarding events that have sold out since hte registrant first signed up |
|
601 | - * |
|
602 | - * @param \EE_Event[] $sold_out_events_array |
|
603 | - * @return \EE_Form_Section_Proper |
|
604 | - * @throws \EE_Error |
|
605 | - */ |
|
606 | - private function _sold_out_events($sold_out_events_array = array()) |
|
607 | - { |
|
608 | - // set some defaults |
|
609 | - $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
610 | - $sold_out_events = ''; |
|
611 | - foreach ($sold_out_events_array as $sold_out_event) { |
|
612 | - $sold_out_events .= EEH_HTML::li( |
|
613 | - EEH_HTML::span( |
|
614 | - ' ' . $sold_out_event->name(), |
|
615 | - '', |
|
616 | - 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
617 | - ) |
|
618 | - ); |
|
619 | - } |
|
620 | - return new EE_Form_Section_Proper( |
|
621 | - array( |
|
622 | - 'layout_strategy' => new EE_Template_Layout( |
|
623 | - array( |
|
624 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
625 | - . $this->_slug |
|
626 | - . DS |
|
627 | - . 'sold_out_events.template.php', |
|
628 | - 'template_args' => apply_filters( |
|
629 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
630 | - array( |
|
631 | - 'sold_out_events' => $sold_out_events, |
|
632 | - 'sold_out_events_msg' => apply_filters( |
|
633 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
634 | - sprintf( |
|
635 | - esc_html__( |
|
636 | - 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', |
|
637 | - 'event_espresso' |
|
638 | - ), |
|
639 | - '<strong>', |
|
640 | - '</strong>', |
|
641 | - '<br />' |
|
642 | - ) |
|
643 | - ), |
|
644 | - ) |
|
645 | - ), |
|
646 | - ) |
|
647 | - ), |
|
648 | - ) |
|
649 | - ); |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * _insufficient_spaces_available |
|
655 | - * displays notices regarding events that do not have enough remaining spaces |
|
656 | - * to satisfy the current number of registrations looking to pay |
|
657 | - * |
|
658 | - * @param \EE_Event[] $insufficient_spaces_events_array |
|
659 | - * @return \EE_Form_Section_Proper |
|
660 | - * @throws \EE_Error |
|
661 | - */ |
|
662 | - private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
663 | - { |
|
664 | - // set some defaults |
|
665 | - $this->checkout->selected_method_of_payment = 'invoice'; |
|
666 | - $insufficient_space_events = ''; |
|
667 | - foreach ($insufficient_spaces_events_array as $event) { |
|
668 | - if ($event instanceof EE_Event) { |
|
669 | - $insufficient_space_events .= EEH_HTML::li( |
|
670 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
671 | - ); |
|
672 | - } |
|
673 | - } |
|
674 | - return new EE_Form_Section_Proper( |
|
675 | - array( |
|
676 | - 'subsections' => array( |
|
677 | - 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
678 | - 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
679 | - ), |
|
680 | - 'layout_strategy' => new EE_Template_Layout( |
|
681 | - array( |
|
682 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
683 | - . $this->_slug |
|
684 | - . DS |
|
685 | - . 'sold_out_events.template.php', |
|
686 | - 'template_args' => apply_filters( |
|
687 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
688 | - array( |
|
689 | - 'sold_out_events' => $insufficient_space_events, |
|
690 | - 'sold_out_events_msg' => apply_filters( |
|
691 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
692 | - esc_html__( |
|
693 | - 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
694 | - 'event_espresso' |
|
695 | - ) |
|
696 | - ), |
|
697 | - ) |
|
698 | - ), |
|
699 | - ) |
|
700 | - ), |
|
701 | - ) |
|
702 | - ); |
|
703 | - } |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * registrations_requiring_pre_approval |
|
708 | - * |
|
709 | - * @param array $registrations_requiring_pre_approval |
|
710 | - * @return EE_Form_Section_Proper |
|
711 | - * @throws EE_Error |
|
712 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
713 | - */ |
|
714 | - private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
715 | - { |
|
716 | - $events_requiring_pre_approval = ''; |
|
717 | - foreach ($registrations_requiring_pre_approval as $registration) { |
|
718 | - if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
719 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
720 | - EEH_HTML::span( |
|
721 | - '', |
|
722 | - '', |
|
723 | - 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
724 | - ) |
|
725 | - . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
726 | - ); |
|
727 | - } |
|
728 | - } |
|
729 | - return new EE_Form_Section_Proper( |
|
730 | - array( |
|
731 | - 'layout_strategy' => new EE_Template_Layout( |
|
732 | - array( |
|
733 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
734 | - . $this->_slug |
|
735 | - . DS |
|
736 | - . 'events_requiring_pre_approval.template.php', // layout_template |
|
737 | - 'template_args' => apply_filters( |
|
738 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
739 | - array( |
|
740 | - 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
741 | - 'events_requiring_pre_approval_msg' => apply_filters( |
|
742 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
743 | - esc_html__( |
|
744 | - 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
745 | - 'event_espresso' |
|
746 | - ) |
|
747 | - ), |
|
748 | - ) |
|
749 | - ), |
|
750 | - ) |
|
751 | - ), |
|
752 | - ) |
|
753 | - ); |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * _no_payment_required |
|
759 | - * |
|
760 | - * @param \EE_Event[] $registrations_for_free_events |
|
761 | - * @return \EE_Form_Section_Proper |
|
762 | - * @throws \EE_Error |
|
763 | - */ |
|
764 | - private function _no_payment_required($registrations_for_free_events = array()) |
|
765 | - { |
|
766 | - // set some defaults |
|
767 | - $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
768 | - // generate no_payment_required form |
|
769 | - return new EE_Form_Section_Proper( |
|
770 | - array( |
|
771 | - 'layout_strategy' => new EE_Template_Layout( |
|
772 | - array( |
|
773 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
774 | - . $this->_slug |
|
775 | - . DS |
|
776 | - . 'no_payment_required.template.php', // layout_template |
|
777 | - 'template_args' => apply_filters( |
|
778 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
779 | - array( |
|
780 | - 'revisit' => $this->checkout->revisit, |
|
781 | - 'registrations' => array(), |
|
782 | - 'ticket_count' => array(), |
|
783 | - 'registrations_for_free_events' => $registrations_for_free_events, |
|
784 | - 'no_payment_required_msg' => EEH_HTML::p( |
|
785 | - esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
786 | - ), |
|
787 | - ) |
|
788 | - ), |
|
789 | - ) |
|
790 | - ), |
|
791 | - ) |
|
792 | - ); |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * _display_payment_options |
|
798 | - * |
|
799 | - * @param string $transaction_details |
|
800 | - * @return EE_Form_Section_Proper |
|
801 | - * @throws EE_Error |
|
802 | - * @throws InvalidArgumentException |
|
803 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
804 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
805 | - */ |
|
806 | - private function _display_payment_options($transaction_details = '') |
|
807 | - { |
|
808 | - // has method_of_payment been set by no-js user? |
|
809 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
810 | - // build payment options form |
|
811 | - return apply_filters( |
|
812 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
813 | - new EE_Form_Section_Proper( |
|
814 | - array( |
|
815 | - 'subsections' => array( |
|
816 | - 'before_payment_options' => apply_filters( |
|
817 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
818 | - new EE_Form_Section_Proper( |
|
819 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
820 | - ) |
|
821 | - ), |
|
822 | - 'payment_options' => $this->_setup_payment_options(), |
|
823 | - 'after_payment_options' => apply_filters( |
|
824 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
825 | - new EE_Form_Section_Proper( |
|
826 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
827 | - ) |
|
828 | - ), |
|
829 | - ), |
|
830 | - 'layout_strategy' => new EE_Template_Layout( |
|
831 | - array( |
|
832 | - 'layout_template_file' => $this->_template, |
|
833 | - 'template_args' => apply_filters( |
|
834 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
835 | - array( |
|
836 | - 'reg_count' => $this->line_item_display->total_items(), |
|
837 | - 'transaction_details' => $transaction_details, |
|
838 | - 'available_payment_methods' => array(), |
|
839 | - ) |
|
840 | - ), |
|
841 | - ) |
|
842 | - ), |
|
843 | - ) |
|
844 | - ) |
|
845 | - ); |
|
846 | - } |
|
847 | - |
|
848 | - |
|
849 | - /** |
|
850 | - * _extra_hidden_inputs |
|
851 | - * |
|
852 | - * @param bool $no_payment_required |
|
853 | - * @return \EE_Form_Section_Proper |
|
854 | - * @throws \EE_Error |
|
855 | - */ |
|
856 | - private function _extra_hidden_inputs($no_payment_required = true) |
|
857 | - { |
|
858 | - return new EE_Form_Section_Proper( |
|
859 | - array( |
|
860 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
861 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
862 | - 'subsections' => array( |
|
863 | - 'spco_no_payment_required' => new EE_Hidden_Input( |
|
864 | - array( |
|
865 | - 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
866 | - 'html_name' => 'spco_no_payment_required', |
|
867 | - 'html_id' => 'spco-no-payment-required-payment_options', |
|
868 | - 'default' => $no_payment_required, |
|
869 | - ) |
|
870 | - ), |
|
871 | - 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
872 | - array( |
|
873 | - 'normalization_strategy' => new EE_Int_Normalization(), |
|
874 | - 'html_name' => 'spco_transaction_id', |
|
875 | - 'html_id' => 'spco-transaction-id', |
|
876 | - 'default' => $this->checkout->transaction->ID(), |
|
877 | - ) |
|
878 | - ), |
|
879 | - ), |
|
880 | - ) |
|
881 | - ); |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - /** |
|
886 | - * _apply_registration_payments_to_amount_owing |
|
887 | - * |
|
888 | - * @access protected |
|
889 | - * @param array $registrations |
|
890 | - * @throws EE_Error |
|
891 | - */ |
|
892 | - protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
893 | - { |
|
894 | - $payments = array(); |
|
895 | - foreach ($registrations as $registration) { |
|
896 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
897 | - $payments += $registration->registration_payments(); |
|
898 | - } |
|
899 | - } |
|
900 | - if (! empty($payments)) { |
|
901 | - foreach ($payments as $payment) { |
|
902 | - if ($payment instanceof EE_Registration_Payment) { |
|
903 | - $this->checkout->amount_owing -= $payment->amount(); |
|
904 | - } |
|
905 | - } |
|
906 | - } |
|
907 | - } |
|
908 | - |
|
909 | - |
|
910 | - /** |
|
911 | - * _reset_selected_method_of_payment |
|
912 | - * |
|
913 | - * @access private |
|
914 | - * @param bool $force_reset |
|
915 | - * @return void |
|
916 | - * @throws InvalidArgumentException |
|
917 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
918 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
919 | - */ |
|
920 | - private function _reset_selected_method_of_payment($force_reset = false) |
|
921 | - { |
|
922 | - $reset_payment_method = $force_reset |
|
923 | - ? true |
|
924 | - : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
925 | - if ($reset_payment_method) { |
|
926 | - $this->checkout->selected_method_of_payment = null; |
|
927 | - $this->checkout->payment_method = null; |
|
928 | - $this->checkout->billing_form = null; |
|
929 | - $this->_save_selected_method_of_payment(); |
|
930 | - } |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - /** |
|
935 | - * _save_selected_method_of_payment |
|
936 | - * stores the selected_method_of_payment in the session |
|
937 | - * so that it's available for all subsequent requests including AJAX |
|
938 | - * |
|
939 | - * @access private |
|
940 | - * @param string $selected_method_of_payment |
|
941 | - * @return void |
|
942 | - * @throws InvalidArgumentException |
|
943 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
944 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
945 | - */ |
|
946 | - private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
947 | - { |
|
948 | - $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
949 | - ? $selected_method_of_payment |
|
950 | - : $this->checkout->selected_method_of_payment; |
|
951 | - EE_Registry::instance()->SSN->set_session_data( |
|
952 | - array('selected_method_of_payment' => $selected_method_of_payment) |
|
953 | - ); |
|
954 | - } |
|
955 | - |
|
956 | - |
|
957 | - /** |
|
958 | - * _setup_payment_options |
|
959 | - * |
|
960 | - * @return EE_Form_Section_Proper |
|
961 | - * @throws EE_Error |
|
962 | - * @throws InvalidArgumentException |
|
963 | - * @throws ReflectionException |
|
964 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
965 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
966 | - */ |
|
967 | - public function _setup_payment_options() |
|
968 | - { |
|
969 | - // load payment method classes |
|
970 | - $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
971 | - if (empty($this->checkout->available_payment_methods)) { |
|
972 | - EE_Error::add_error( |
|
973 | - apply_filters( |
|
974 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
975 | - sprintf( |
|
976 | - esc_html__( |
|
977 | - 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
978 | - 'event_espresso' |
|
979 | - ), |
|
980 | - '<br>', |
|
981 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
982 | - ) |
|
983 | - ), |
|
984 | - __FILE__, |
|
985 | - __FUNCTION__, |
|
986 | - __LINE__ |
|
987 | - ); |
|
988 | - } |
|
989 | - // switch up header depending on number of available payment methods |
|
990 | - $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
991 | - ? apply_filters( |
|
992 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
993 | - esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
994 | - ) |
|
995 | - : apply_filters( |
|
996 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
997 | - esc_html__('Method of Payment', 'event_espresso') |
|
998 | - ); |
|
999 | - $available_payment_methods = array( |
|
1000 | - // display the "Payment Method" header |
|
1001 | - 'payment_method_header' => new EE_Form_Section_HTML( |
|
1002 | - apply_filters( |
|
1003 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header', |
|
1004 | - EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'), |
|
1005 | - $payment_method_header |
|
1006 | - ) |
|
1007 | - ), |
|
1008 | - ); |
|
1009 | - // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
1010 | - $available_payment_method_options = array(); |
|
1011 | - $default_payment_method_option = array(); |
|
1012 | - // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
1013 | - $payment_methods_billing_info = array( |
|
1014 | - new EE_Form_Section_HTML( |
|
1015 | - EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
1016 | - ), |
|
1017 | - ); |
|
1018 | - // loop through payment methods |
|
1019 | - foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
1020 | - if ($payment_method instanceof EE_Payment_Method) { |
|
1021 | - $payment_method_button = EEH_HTML::img( |
|
1022 | - $payment_method->button_url(), |
|
1023 | - $payment_method->name(), |
|
1024 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
1025 | - 'spco-payment-method-btn-img' |
|
1026 | - ); |
|
1027 | - // check if any payment methods are set as default |
|
1028 | - // if payment method is already selected OR nothing is selected and this payment method should be |
|
1029 | - // open_by_default |
|
1030 | - if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
1031 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1032 | - ) { |
|
1033 | - $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
1034 | - $this->_save_selected_method_of_payment(); |
|
1035 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
1036 | - } else { |
|
1037 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
1038 | - } |
|
1039 | - $payment_methods_billing_info[ $payment_method->slug( |
|
1040 | - ) . '-info' ] = $this->_payment_method_billing_info( |
|
1041 | - $payment_method |
|
1042 | - ); |
|
1043 | - } |
|
1044 | - } |
|
1045 | - // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
1046 | - // of PMs |
|
1047 | - $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
1048 | - // now generate the actual form inputs |
|
1049 | - $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
1050 | - $available_payment_method_options |
|
1051 | - ); |
|
1052 | - $available_payment_methods += $payment_methods_billing_info; |
|
1053 | - // build the available payment methods form |
|
1054 | - return new EE_Form_Section_Proper( |
|
1055 | - array( |
|
1056 | - 'html_id' => 'spco-available-methods-of-payment-dv', |
|
1057 | - 'subsections' => $available_payment_methods, |
|
1058 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1059 | - ) |
|
1060 | - ); |
|
1061 | - } |
|
1062 | - |
|
1063 | - |
|
1064 | - /** |
|
1065 | - * _get_available_payment_methods |
|
1066 | - * |
|
1067 | - * @return EE_Payment_Method[] |
|
1068 | - * @throws EE_Error |
|
1069 | - * @throws InvalidArgumentException |
|
1070 | - * @throws ReflectionException |
|
1071 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1072 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1073 | - */ |
|
1074 | - protected function _get_available_payment_methods() |
|
1075 | - { |
|
1076 | - if (! empty($this->checkout->available_payment_methods)) { |
|
1077 | - return $this->checkout->available_payment_methods; |
|
1078 | - } |
|
1079 | - $available_payment_methods = array(); |
|
1080 | - // load EEM_Payment_Method |
|
1081 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
1082 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
1083 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
1084 | - // get all active payment methods |
|
1085 | - $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
1086 | - $this->checkout->transaction, |
|
1087 | - EEM_Payment_Method::scope_cart |
|
1088 | - ); |
|
1089 | - foreach ($payment_methods as $payment_method) { |
|
1090 | - if ($payment_method instanceof EE_Payment_Method) { |
|
1091 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1092 | - } |
|
1093 | - } |
|
1094 | - return $available_payment_methods; |
|
1095 | - } |
|
1096 | - |
|
1097 | - |
|
1098 | - /** |
|
1099 | - * _available_payment_method_inputs |
|
1100 | - * |
|
1101 | - * @access private |
|
1102 | - * @param array $available_payment_method_options |
|
1103 | - * @return \EE_Form_Section_Proper |
|
1104 | - */ |
|
1105 | - private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
1106 | - { |
|
1107 | - // generate inputs |
|
1108 | - return new EE_Form_Section_Proper( |
|
1109 | - array( |
|
1110 | - 'html_id' => 'ee-available-payment-method-inputs', |
|
1111 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1112 | - 'subsections' => array( |
|
1113 | - '' => new EE_Radio_Button_Input( |
|
1114 | - $available_payment_method_options, |
|
1115 | - array( |
|
1116 | - 'html_name' => 'selected_method_of_payment', |
|
1117 | - 'html_class' => 'spco-payment-method', |
|
1118 | - 'default' => $this->checkout->selected_method_of_payment, |
|
1119 | - 'label_size' => 11, |
|
1120 | - 'enforce_label_size' => true, |
|
1121 | - ) |
|
1122 | - ), |
|
1123 | - ), |
|
1124 | - ) |
|
1125 | - ); |
|
1126 | - } |
|
1127 | - |
|
1128 | - |
|
1129 | - /** |
|
1130 | - * _payment_method_billing_info |
|
1131 | - * |
|
1132 | - * @access private |
|
1133 | - * @param EE_Payment_Method $payment_method |
|
1134 | - * @return EE_Form_Section_Proper |
|
1135 | - * @throws EE_Error |
|
1136 | - * @throws InvalidArgumentException |
|
1137 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1138 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1139 | - */ |
|
1140 | - private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
1141 | - { |
|
1142 | - $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
1143 | - ? true |
|
1144 | - : false; |
|
1145 | - // generate the billing form for payment method |
|
1146 | - $billing_form = $currently_selected |
|
1147 | - ? $this->_get_billing_form_for_payment_method($payment_method) |
|
1148 | - : new EE_Form_Section_HTML(); |
|
1149 | - $this->checkout->billing_form = $currently_selected |
|
1150 | - ? $billing_form |
|
1151 | - : $this->checkout->billing_form; |
|
1152 | - // it's all in the details |
|
1153 | - $info_html = EEH_HTML::h3( |
|
1154 | - esc_html__('Important information regarding your payment', 'event_espresso'), |
|
1155 | - '', |
|
1156 | - 'spco-payment-method-hdr' |
|
1157 | - ); |
|
1158 | - // add some info regarding the step, either from what's saved in the admin, |
|
1159 | - // or a default string depending on whether the PM has a billing form or not |
|
1160 | - if ($payment_method->description()) { |
|
1161 | - $payment_method_info = $payment_method->description(); |
|
1162 | - } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
1163 | - $payment_method_info = sprintf( |
|
1164 | - esc_html__( |
|
1165 | - 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
1166 | - 'event_espresso' |
|
1167 | - ), |
|
1168 | - $this->submit_button_text() |
|
1169 | - ); |
|
1170 | - } else { |
|
1171 | - $payment_method_info = sprintf( |
|
1172 | - esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
1173 | - $this->submit_button_text() |
|
1174 | - ); |
|
1175 | - } |
|
1176 | - $info_html .= EEH_HTML::div( |
|
1177 | - apply_filters( |
|
1178 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
1179 | - $payment_method_info |
|
1180 | - ), |
|
1181 | - '', |
|
1182 | - 'spco-payment-method-desc ee-attention' |
|
1183 | - ); |
|
1184 | - return new EE_Form_Section_Proper( |
|
1185 | - array( |
|
1186 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1187 | - 'html_class' => 'spco-payment-method-info-dv', |
|
1188 | - // only display the selected or default PM |
|
1189 | - 'html_style' => $currently_selected ? '' : 'display:none;', |
|
1190 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1191 | - 'subsections' => array( |
|
1192 | - 'info' => new EE_Form_Section_HTML($info_html), |
|
1193 | - 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
1194 | - ), |
|
1195 | - ) |
|
1196 | - ); |
|
1197 | - } |
|
1198 | - |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * get_billing_form_html_for_payment_method |
|
1202 | - * |
|
1203 | - * @access public |
|
1204 | - * @return string |
|
1205 | - * @throws EE_Error |
|
1206 | - * @throws InvalidArgumentException |
|
1207 | - * @throws ReflectionException |
|
1208 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1209 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1210 | - */ |
|
1211 | - public function get_billing_form_html_for_payment_method() |
|
1212 | - { |
|
1213 | - // how have they chosen to pay? |
|
1214 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1215 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1216 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1217 | - return false; |
|
1218 | - } |
|
1219 | - if (apply_filters( |
|
1220 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1221 | - false |
|
1222 | - )) { |
|
1223 | - EE_Error::add_success( |
|
1224 | - apply_filters( |
|
1225 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1226 | - sprintf( |
|
1227 | - esc_html__( |
|
1228 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1229 | - 'event_espresso' |
|
1230 | - ), |
|
1231 | - $this->checkout->payment_method->name() |
|
1232 | - ) |
|
1233 | - ) |
|
1234 | - ); |
|
1235 | - } |
|
1236 | - // now generate billing form for selected method of payment |
|
1237 | - $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
1238 | - // fill form with attendee info if applicable |
|
1239 | - if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1240 | - && $this->checkout->transaction_has_primary_registrant() |
|
1241 | - ) { |
|
1242 | - $payment_method_billing_form->populate_from_attendee( |
|
1243 | - $this->checkout->transaction->primary_registration()->attendee() |
|
1244 | - ); |
|
1245 | - } |
|
1246 | - // and debug content |
|
1247 | - if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
1248 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1249 | - ) { |
|
1250 | - $payment_method_billing_form = |
|
1251 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1252 | - $payment_method_billing_form |
|
1253 | - ); |
|
1254 | - } |
|
1255 | - $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
1256 | - ? $payment_method_billing_form->get_html() |
|
1257 | - : ''; |
|
1258 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
1259 | - // localize validation rules for main form |
|
1260 | - $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
1261 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1262 | - return true; |
|
1263 | - } |
|
1264 | - |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * _get_billing_form_for_payment_method |
|
1268 | - * |
|
1269 | - * @access private |
|
1270 | - * @param EE_Payment_Method $payment_method |
|
1271 | - * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
1272 | - * @throws EE_Error |
|
1273 | - * @throws InvalidArgumentException |
|
1274 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1275 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1276 | - */ |
|
1277 | - private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
1278 | - { |
|
1279 | - $billing_form = $payment_method->type_obj()->billing_form( |
|
1280 | - $this->checkout->transaction, |
|
1281 | - array('amount_owing' => $this->checkout->amount_owing) |
|
1282 | - ); |
|
1283 | - if ($billing_form instanceof EE_Billing_Info_Form) { |
|
1284 | - if (apply_filters( |
|
1285 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1286 | - false |
|
1287 | - ) |
|
1288 | - && EE_Registry::instance()->REQ->is_set('payment_method') |
|
1289 | - ) { |
|
1290 | - EE_Error::add_success( |
|
1291 | - apply_filters( |
|
1292 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1293 | - sprintf( |
|
1294 | - esc_html__( |
|
1295 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1296 | - 'event_espresso' |
|
1297 | - ), |
|
1298 | - $payment_method->name() |
|
1299 | - ) |
|
1300 | - ) |
|
1301 | - ); |
|
1302 | - } |
|
1303 | - return apply_filters( |
|
1304 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
1305 | - $billing_form, |
|
1306 | - $payment_method |
|
1307 | - ); |
|
1308 | - } |
|
1309 | - // no actual billing form, so return empty HTML form section |
|
1310 | - return new EE_Form_Section_HTML(); |
|
1311 | - } |
|
1312 | - |
|
1313 | - |
|
1314 | - /** |
|
1315 | - * _get_selected_method_of_payment |
|
1316 | - * |
|
1317 | - * @access private |
|
1318 | - * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
1319 | - * is not found in the incoming request |
|
1320 | - * @param string $request_param |
|
1321 | - * @return NULL|string |
|
1322 | - * @throws EE_Error |
|
1323 | - * @throws InvalidArgumentException |
|
1324 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1325 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1326 | - */ |
|
1327 | - private function _get_selected_method_of_payment( |
|
1328 | - $required = false, |
|
1329 | - $request_param = 'selected_method_of_payment' |
|
1330 | - ) { |
|
1331 | - // is selected_method_of_payment set in the request ? |
|
1332 | - $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
1333 | - if ($selected_method_of_payment) { |
|
1334 | - // sanitize it |
|
1335 | - $selected_method_of_payment = is_array($selected_method_of_payment) |
|
1336 | - ? array_shift($selected_method_of_payment) |
|
1337 | - : $selected_method_of_payment; |
|
1338 | - $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
1339 | - // store it in the session so that it's available for all subsequent requests including AJAX |
|
1340 | - $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
1341 | - } else { |
|
1342 | - // or is is set in the session ? |
|
1343 | - $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
1344 | - 'selected_method_of_payment' |
|
1345 | - ); |
|
1346 | - } |
|
1347 | - // do ya really really gotta have it? |
|
1348 | - if (empty($selected_method_of_payment) && $required) { |
|
1349 | - EE_Error::add_error( |
|
1350 | - sprintf( |
|
1351 | - esc_html__( |
|
1352 | - 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
1353 | - 'event_espresso' |
|
1354 | - ), |
|
1355 | - '<br/>', |
|
1356 | - '<br/>', |
|
1357 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1358 | - ), |
|
1359 | - __FILE__, |
|
1360 | - __FUNCTION__, |
|
1361 | - __LINE__ |
|
1362 | - ); |
|
1363 | - return null; |
|
1364 | - } |
|
1365 | - return $selected_method_of_payment; |
|
1366 | - } |
|
1367 | - |
|
1368 | - |
|
1369 | - |
|
1370 | - |
|
1371 | - |
|
1372 | - |
|
1373 | - /********************************************************************************************************/ |
|
1374 | - /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
1375 | - /********************************************************************************************************/ |
|
1376 | - /** |
|
1377 | - * switch_payment_method |
|
1378 | - * |
|
1379 | - * @access public |
|
1380 | - * @return string |
|
1381 | - * @throws EE_Error |
|
1382 | - * @throws InvalidArgumentException |
|
1383 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1384 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1385 | - */ |
|
1386 | - public function switch_payment_method() |
|
1387 | - { |
|
1388 | - if (! $this->_verify_payment_method_is_set()) { |
|
1389 | - return false; |
|
1390 | - } |
|
1391 | - if (apply_filters( |
|
1392 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1393 | - false |
|
1394 | - )) { |
|
1395 | - EE_Error::add_success( |
|
1396 | - apply_filters( |
|
1397 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1398 | - sprintf( |
|
1399 | - esc_html__( |
|
1400 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1401 | - 'event_espresso' |
|
1402 | - ), |
|
1403 | - $this->checkout->payment_method->name() |
|
1404 | - ) |
|
1405 | - ) |
|
1406 | - ); |
|
1407 | - } |
|
1408 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1409 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1410 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1411 | - $this->checkout->payment_method |
|
1412 | - ); |
|
1413 | - } |
|
1414 | - // fill form with attendee info if applicable |
|
1415 | - if (apply_filters( |
|
1416 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
1417 | - ( |
|
1418 | - $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1419 | - && $this->checkout->transaction_has_primary_registrant() |
|
1420 | - ), |
|
1421 | - $this->checkout->billing_form, |
|
1422 | - $this->checkout->transaction |
|
1423 | - ) |
|
1424 | - ) { |
|
1425 | - $this->checkout->billing_form->populate_from_attendee( |
|
1426 | - $this->checkout->transaction->primary_registration()->attendee() |
|
1427 | - ); |
|
1428 | - } |
|
1429 | - // and debug content |
|
1430 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1431 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1432 | - ) { |
|
1433 | - $this->checkout->billing_form = |
|
1434 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1435 | - $this->checkout->billing_form |
|
1436 | - ); |
|
1437 | - } |
|
1438 | - // get html and validation rules for form |
|
1439 | - if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
1440 | - $this->checkout->json_response->set_return_data( |
|
1441 | - array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
1442 | - ); |
|
1443 | - // localize validation rules for main form |
|
1444 | - $this->checkout->billing_form->localize_validation_rules(true); |
|
1445 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1446 | - } else { |
|
1447 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
1448 | - } |
|
1449 | - // prevents advancement to next step |
|
1450 | - $this->checkout->continue_reg = false; |
|
1451 | - return true; |
|
1452 | - } |
|
1453 | - |
|
1454 | - |
|
1455 | - /** |
|
1456 | - * _verify_payment_method_is_set |
|
1457 | - * |
|
1458 | - * @return bool |
|
1459 | - * @throws EE_Error |
|
1460 | - * @throws InvalidArgumentException |
|
1461 | - * @throws ReflectionException |
|
1462 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1463 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1464 | - */ |
|
1465 | - protected function _verify_payment_method_is_set() |
|
1466 | - { |
|
1467 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1468 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
1469 | - // how have they chosen to pay? |
|
1470 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1471 | - } else { |
|
1472 | - // choose your own adventure based on method_of_payment |
|
1473 | - switch ($this->checkout->selected_method_of_payment) { |
|
1474 | - case 'events_sold_out': |
|
1475 | - EE_Error::add_attention( |
|
1476 | - apply_filters( |
|
1477 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
1478 | - esc_html__( |
|
1479 | - 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
1480 | - 'event_espresso' |
|
1481 | - ) |
|
1482 | - ), |
|
1483 | - __FILE__, |
|
1484 | - __FUNCTION__, |
|
1485 | - __LINE__ |
|
1486 | - ); |
|
1487 | - return false; |
|
1488 | - break; |
|
1489 | - case 'payments_closed': |
|
1490 | - EE_Error::add_attention( |
|
1491 | - apply_filters( |
|
1492 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
1493 | - esc_html__( |
|
1494 | - 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
1495 | - 'event_espresso' |
|
1496 | - ) |
|
1497 | - ), |
|
1498 | - __FILE__, |
|
1499 | - __FUNCTION__, |
|
1500 | - __LINE__ |
|
1501 | - ); |
|
1502 | - return false; |
|
1503 | - break; |
|
1504 | - case 'no_payment_required': |
|
1505 | - EE_Error::add_attention( |
|
1506 | - apply_filters( |
|
1507 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
1508 | - esc_html__( |
|
1509 | - 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
1510 | - 'event_espresso' |
|
1511 | - ) |
|
1512 | - ), |
|
1513 | - __FILE__, |
|
1514 | - __FUNCTION__, |
|
1515 | - __LINE__ |
|
1516 | - ); |
|
1517 | - return false; |
|
1518 | - break; |
|
1519 | - default: |
|
1520 | - } |
|
1521 | - } |
|
1522 | - // verify payment method |
|
1523 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1524 | - // get payment method for selected method of payment |
|
1525 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1526 | - } |
|
1527 | - return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
1528 | - } |
|
1529 | - |
|
1530 | - |
|
1531 | - |
|
1532 | - /********************************************************************************************************/ |
|
1533 | - /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
1534 | - /********************************************************************************************************/ |
|
1535 | - /** |
|
1536 | - * save_payer_details_via_ajax |
|
1537 | - * |
|
1538 | - * @return void |
|
1539 | - * @throws EE_Error |
|
1540 | - * @throws InvalidArgumentException |
|
1541 | - * @throws ReflectionException |
|
1542 | - * @throws RuntimeException |
|
1543 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1544 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1545 | - */ |
|
1546 | - public function save_payer_details_via_ajax() |
|
1547 | - { |
|
1548 | - if (! $this->_verify_payment_method_is_set()) { |
|
1549 | - return; |
|
1550 | - } |
|
1551 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1552 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1553 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1554 | - $this->checkout->payment_method |
|
1555 | - ); |
|
1556 | - } |
|
1557 | - // generate primary attendee from payer info if applicable |
|
1558 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
1559 | - $attendee = $this->_create_attendee_from_request_data(); |
|
1560 | - if ($attendee instanceof EE_Attendee) { |
|
1561 | - foreach ($this->checkout->transaction->registrations() as $registration) { |
|
1562 | - if ($registration->is_primary_registrant()) { |
|
1563 | - $this->checkout->primary_attendee_obj = $attendee; |
|
1564 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
1565 | - $registration->set_attendee_id($attendee->ID()); |
|
1566 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1567 | - } |
|
1568 | - } |
|
1569 | - } |
|
1570 | - } |
|
1571 | - } |
|
1572 | - |
|
1573 | - |
|
1574 | - /** |
|
1575 | - * create_attendee_from_request_data |
|
1576 | - * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
1577 | - * |
|
1578 | - * @return EE_Attendee |
|
1579 | - * @throws EE_Error |
|
1580 | - * @throws InvalidArgumentException |
|
1581 | - * @throws ReflectionException |
|
1582 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1583 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1584 | - */ |
|
1585 | - protected function _create_attendee_from_request_data() |
|
1586 | - { |
|
1587 | - // get State ID |
|
1588 | - $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
1589 | - if (! empty($STA_ID)) { |
|
1590 | - // can we get state object from name ? |
|
1591 | - EE_Registry::instance()->load_model('State'); |
|
1592 | - $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
1593 | - $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
1594 | - } |
|
1595 | - // get Country ISO |
|
1596 | - $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
1597 | - if (! empty($CNT_ISO)) { |
|
1598 | - // can we get country object from name ? |
|
1599 | - EE_Registry::instance()->load_model('Country'); |
|
1600 | - $country = EEM_Country::instance()->get_col( |
|
1601 | - array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
1602 | - 'CNT_ISO' |
|
1603 | - ); |
|
1604 | - $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
1605 | - } |
|
1606 | - // grab attendee data |
|
1607 | - $attendee_data = array( |
|
1608 | - 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
1609 | - 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
1610 | - 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
1611 | - 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
1612 | - 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
1613 | - 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
1614 | - 'STA_ID' => $STA_ID, |
|
1615 | - 'CNT_ISO' => $CNT_ISO, |
|
1616 | - 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
1617 | - 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
1618 | - ); |
|
1619 | - // validate the email address since it is the most important piece of info |
|
1620 | - if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
1621 | - EE_Error::add_error( |
|
1622 | - esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
1623 | - __FILE__, |
|
1624 | - __FUNCTION__, |
|
1625 | - __LINE__ |
|
1626 | - ); |
|
1627 | - } |
|
1628 | - // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
1629 | - // AND email address |
|
1630 | - if (! empty($attendee_data['ATT_fname']) |
|
1631 | - && ! empty($attendee_data['ATT_lname']) |
|
1632 | - && ! empty($attendee_data['ATT_email']) |
|
1633 | - ) { |
|
1634 | - $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
1635 | - array( |
|
1636 | - 'ATT_fname' => $attendee_data['ATT_fname'], |
|
1637 | - 'ATT_lname' => $attendee_data['ATT_lname'], |
|
1638 | - 'ATT_email' => $attendee_data['ATT_email'], |
|
1639 | - ) |
|
1640 | - ); |
|
1641 | - if ($existing_attendee instanceof EE_Attendee) { |
|
1642 | - return $existing_attendee; |
|
1643 | - } |
|
1644 | - } |
|
1645 | - // no existing attendee? kk let's create a new one |
|
1646 | - // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
1647 | - // don't exist |
|
1648 | - $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
1649 | - ? $attendee_data['ATT_fname'] |
|
1650 | - : $attendee_data['ATT_email']; |
|
1651 | - $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
1652 | - ? $attendee_data['ATT_lname'] |
|
1653 | - : $attendee_data['ATT_email']; |
|
1654 | - return EE_Attendee::new_instance($attendee_data); |
|
1655 | - } |
|
1656 | - |
|
1657 | - |
|
1658 | - |
|
1659 | - /********************************************************************************************************/ |
|
1660 | - /**************************************** PROCESS REG STEP *****************************************/ |
|
1661 | - /********************************************************************************************************/ |
|
1662 | - /** |
|
1663 | - * process_reg_step |
|
1664 | - * |
|
1665 | - * @return bool |
|
1666 | - * @throws EE_Error |
|
1667 | - * @throws InvalidArgumentException |
|
1668 | - * @throws ReflectionException |
|
1669 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1670 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1671 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1672 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1673 | - */ |
|
1674 | - public function process_reg_step() |
|
1675 | - { |
|
1676 | - // how have they chosen to pay? |
|
1677 | - $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
1678 | - ? 'no_payment_required' |
|
1679 | - : $this->_get_selected_method_of_payment(true); |
|
1680 | - // choose your own adventure based on method_of_payment |
|
1681 | - switch ($this->checkout->selected_method_of_payment) { |
|
1682 | - case 'events_sold_out': |
|
1683 | - $this->checkout->redirect = true; |
|
1684 | - $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
1685 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1686 | - // mark this reg step as completed |
|
1687 | - $this->set_completed(); |
|
1688 | - return false; |
|
1689 | - break; |
|
1690 | - |
|
1691 | - case 'payments_closed': |
|
1692 | - if (apply_filters( |
|
1693 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
1694 | - false |
|
1695 | - )) { |
|
1696 | - EE_Error::add_success( |
|
1697 | - esc_html__('no payment required at this time.', 'event_espresso'), |
|
1698 | - __FILE__, |
|
1699 | - __FUNCTION__, |
|
1700 | - __LINE__ |
|
1701 | - ); |
|
1702 | - } |
|
1703 | - // mark this reg step as completed |
|
1704 | - $this->set_completed(); |
|
1705 | - return true; |
|
1706 | - break; |
|
1707 | - |
|
1708 | - case 'no_payment_required': |
|
1709 | - if (apply_filters( |
|
1710 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
1711 | - false |
|
1712 | - )) { |
|
1713 | - EE_Error::add_success( |
|
1714 | - esc_html__('no payment required.', 'event_espresso'), |
|
1715 | - __FILE__, |
|
1716 | - __FUNCTION__, |
|
1717 | - __LINE__ |
|
1718 | - ); |
|
1719 | - } |
|
1720 | - // mark this reg step as completed |
|
1721 | - $this->set_completed(); |
|
1722 | - return true; |
|
1723 | - break; |
|
1724 | - |
|
1725 | - default: |
|
1726 | - $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
1727 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
1728 | - ); |
|
1729 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
1730 | - $registrations, |
|
1731 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
1732 | - ); |
|
1733 | - // calculate difference between the two arrays |
|
1734 | - $registrations = array_diff($registrations, $ejected_registrations); |
|
1735 | - if (empty($registrations)) { |
|
1736 | - $this->_redirect_because_event_sold_out(); |
|
1737 | - return false; |
|
1738 | - } |
|
1739 | - $payment_successful = $this->_process_payment(); |
|
1740 | - if ($payment_successful) { |
|
1741 | - $this->checkout->continue_reg = true; |
|
1742 | - $this->_maybe_set_completed($this->checkout->payment_method); |
|
1743 | - } else { |
|
1744 | - $this->checkout->continue_reg = false; |
|
1745 | - } |
|
1746 | - return $payment_successful; |
|
1747 | - } |
|
1748 | - } |
|
1749 | - |
|
1750 | - |
|
1751 | - /** |
|
1752 | - * _redirect_because_event_sold_out |
|
1753 | - * |
|
1754 | - * @access protected |
|
1755 | - * @return void |
|
1756 | - */ |
|
1757 | - protected function _redirect_because_event_sold_out() |
|
1758 | - { |
|
1759 | - $this->checkout->continue_reg = false; |
|
1760 | - // set redirect URL |
|
1761 | - $this->checkout->redirect_url = add_query_arg( |
|
1762 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1763 | - $this->checkout->current_step->reg_step_url() |
|
1764 | - ); |
|
1765 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1766 | - } |
|
1767 | - |
|
1768 | - |
|
1769 | - /** |
|
1770 | - * _maybe_set_completed |
|
1771 | - * |
|
1772 | - * @access protected |
|
1773 | - * @param \EE_Payment_Method $payment_method |
|
1774 | - * @return void |
|
1775 | - * @throws \EE_Error |
|
1776 | - */ |
|
1777 | - protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
1778 | - { |
|
1779 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
1780 | - case EE_PMT_Base::offsite: |
|
1781 | - break; |
|
1782 | - case EE_PMT_Base::onsite: |
|
1783 | - case EE_PMT_Base::offline: |
|
1784 | - // mark this reg step as completed |
|
1785 | - $this->set_completed(); |
|
1786 | - break; |
|
1787 | - } |
|
1788 | - } |
|
1789 | - |
|
1790 | - |
|
1791 | - /** |
|
1792 | - * update_reg_step |
|
1793 | - * this is the final step after a user revisits the site to retry a payment |
|
1794 | - * |
|
1795 | - * @return bool |
|
1796 | - * @throws EE_Error |
|
1797 | - * @throws InvalidArgumentException |
|
1798 | - * @throws ReflectionException |
|
1799 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1800 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1801 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1802 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1803 | - */ |
|
1804 | - public function update_reg_step() |
|
1805 | - { |
|
1806 | - $success = true; |
|
1807 | - // if payment required |
|
1808 | - if ($this->checkout->transaction->total() > 0) { |
|
1809 | - do_action( |
|
1810 | - 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
1811 | - $this->checkout->transaction |
|
1812 | - ); |
|
1813 | - // attempt payment via payment method |
|
1814 | - $success = $this->process_reg_step(); |
|
1815 | - } |
|
1816 | - if ($success && ! $this->checkout->redirect) { |
|
1817 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
1818 | - $this->checkout->transaction->ID() |
|
1819 | - ); |
|
1820 | - // set return URL |
|
1821 | - $this->checkout->redirect_url = add_query_arg( |
|
1822 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1823 | - $this->checkout->thank_you_page_url |
|
1824 | - ); |
|
1825 | - } |
|
1826 | - return $success; |
|
1827 | - } |
|
1828 | - |
|
1829 | - |
|
1830 | - /** |
|
1831 | - * _process_payment |
|
1832 | - * |
|
1833 | - * @access private |
|
1834 | - * @return bool |
|
1835 | - * @throws EE_Error |
|
1836 | - * @throws InvalidArgumentException |
|
1837 | - * @throws ReflectionException |
|
1838 | - * @throws RuntimeException |
|
1839 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1840 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1841 | - */ |
|
1842 | - private function _process_payment() |
|
1843 | - { |
|
1844 | - // basically confirm that the event hasn't sold out since they hit the page |
|
1845 | - if (! $this->_last_second_ticket_verifications()) { |
|
1846 | - return false; |
|
1847 | - } |
|
1848 | - // ya gotta make a choice man |
|
1849 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
1850 | - $this->checkout->json_response->set_plz_select_method_of_payment( |
|
1851 | - esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
1852 | - ); |
|
1853 | - return false; |
|
1854 | - } |
|
1855 | - // get EE_Payment_Method object |
|
1856 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1857 | - return false; |
|
1858 | - } |
|
1859 | - // setup billing form |
|
1860 | - if ($this->checkout->payment_method->is_on_site()) { |
|
1861 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1862 | - $this->checkout->payment_method |
|
1863 | - ); |
|
1864 | - // bad billing form ? |
|
1865 | - if (! $this->_billing_form_is_valid()) { |
|
1866 | - return false; |
|
1867 | - } |
|
1868 | - } |
|
1869 | - // ensure primary registrant has been fully processed |
|
1870 | - if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1871 | - return false; |
|
1872 | - } |
|
1873 | - // if session is close to expiring (under 10 minutes by default) |
|
1874 | - if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
1875 | - // add some time to session expiration so that payment can be completed |
|
1876 | - EE_Registry::instance()->SSN->extend_expiration(); |
|
1877 | - } |
|
1878 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
1879 | - // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
1880 | - // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
1881 | - // for events with a default reg status of Approved |
|
1882 | - // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
1883 | - // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
1884 | - // ); |
|
1885 | - // attempt payment |
|
1886 | - $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
1887 | - // process results |
|
1888 | - $payment = $this->_validate_payment($payment); |
|
1889 | - $payment = $this->_post_payment_processing($payment); |
|
1890 | - // verify payment |
|
1891 | - if ($payment instanceof EE_Payment) { |
|
1892 | - // store that for later |
|
1893 | - $this->checkout->payment = $payment; |
|
1894 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
1895 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1896 | - $payment_status = $payment->status(); |
|
1897 | - if ($payment_status === EEM_Payment::status_id_approved |
|
1898 | - || $payment_status === EEM_Payment::status_id_pending |
|
1899 | - ) { |
|
1900 | - return true; |
|
1901 | - } else { |
|
1902 | - return false; |
|
1903 | - } |
|
1904 | - } elseif ($payment === true) { |
|
1905 | - // please note that offline payment methods will NOT make a payment, |
|
1906 | - // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
1907 | - $this->checkout->payment = $payment; |
|
1908 | - return true; |
|
1909 | - } |
|
1910 | - // where's my money? |
|
1911 | - return false; |
|
1912 | - } |
|
1913 | - |
|
1914 | - |
|
1915 | - /** |
|
1916 | - * _last_second_ticket_verifications |
|
1917 | - * |
|
1918 | - * @access public |
|
1919 | - * @return bool |
|
1920 | - * @throws EE_Error |
|
1921 | - */ |
|
1922 | - protected function _last_second_ticket_verifications() |
|
1923 | - { |
|
1924 | - // don't bother re-validating if not a return visit |
|
1925 | - if (! $this->checkout->revisit) { |
|
1926 | - return true; |
|
1927 | - } |
|
1928 | - $registrations = $this->checkout->transaction->registrations(); |
|
1929 | - if (empty($registrations)) { |
|
1930 | - return false; |
|
1931 | - } |
|
1932 | - foreach ($registrations as $registration) { |
|
1933 | - if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
1934 | - $event = $registration->event_obj(); |
|
1935 | - if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
1936 | - EE_Error::add_error( |
|
1937 | - apply_filters( |
|
1938 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
1939 | - sprintf( |
|
1940 | - esc_html__( |
|
1941 | - 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
1942 | - 'event_espresso' |
|
1943 | - ), |
|
1944 | - $event->name() |
|
1945 | - ) |
|
1946 | - ), |
|
1947 | - __FILE__, |
|
1948 | - __FUNCTION__, |
|
1949 | - __LINE__ |
|
1950 | - ); |
|
1951 | - return false; |
|
1952 | - } |
|
1953 | - } |
|
1954 | - } |
|
1955 | - return true; |
|
1956 | - } |
|
1957 | - |
|
1958 | - |
|
1959 | - /** |
|
1960 | - * redirect_form |
|
1961 | - * |
|
1962 | - * @access public |
|
1963 | - * @return bool |
|
1964 | - * @throws EE_Error |
|
1965 | - * @throws InvalidArgumentException |
|
1966 | - * @throws ReflectionException |
|
1967 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1968 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1969 | - */ |
|
1970 | - public function redirect_form() |
|
1971 | - { |
|
1972 | - $payment_method_billing_info = $this->_payment_method_billing_info( |
|
1973 | - $this->_get_payment_method_for_selected_method_of_payment() |
|
1974 | - ); |
|
1975 | - $html = $payment_method_billing_info->get_html(); |
|
1976 | - $html .= $this->checkout->redirect_form; |
|
1977 | - EE_Registry::instance()->REQ->add_output($html); |
|
1978 | - return true; |
|
1979 | - } |
|
1980 | - |
|
1981 | - |
|
1982 | - /** |
|
1983 | - * _billing_form_is_valid |
|
1984 | - * |
|
1985 | - * @access private |
|
1986 | - * @return bool |
|
1987 | - * @throws \EE_Error |
|
1988 | - */ |
|
1989 | - private function _billing_form_is_valid() |
|
1990 | - { |
|
1991 | - if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1992 | - return true; |
|
1993 | - } |
|
1994 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
1995 | - if ($this->checkout->billing_form->was_submitted()) { |
|
1996 | - $this->checkout->billing_form->receive_form_submission(); |
|
1997 | - if ($this->checkout->billing_form->is_valid()) { |
|
1998 | - return true; |
|
1999 | - } |
|
2000 | - $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
2001 | - $error_strings = array(); |
|
2002 | - foreach ($validation_errors as $validation_error) { |
|
2003 | - if ($validation_error instanceof EE_Validation_Error) { |
|
2004 | - $form_section = $validation_error->get_form_section(); |
|
2005 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
2006 | - $label = $form_section->html_label_text(); |
|
2007 | - } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
2008 | - $label = $form_section->name(); |
|
2009 | - } else { |
|
2010 | - $label = esc_html__('Validation Error', 'event_espresso'); |
|
2011 | - } |
|
2012 | - $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
2013 | - } |
|
2014 | - } |
|
2015 | - EE_Error::add_error( |
|
2016 | - sprintf( |
|
2017 | - esc_html__( |
|
2018 | - 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
2019 | - 'event_espresso' |
|
2020 | - ), |
|
2021 | - '<br/>', |
|
2022 | - implode('<br/>', $error_strings) |
|
2023 | - ), |
|
2024 | - __FILE__, |
|
2025 | - __FUNCTION__, |
|
2026 | - __LINE__ |
|
2027 | - ); |
|
2028 | - } else { |
|
2029 | - EE_Error::add_error( |
|
2030 | - esc_html__( |
|
2031 | - 'The billing form was not submitted or something prevented it\'s submission.', |
|
2032 | - 'event_espresso' |
|
2033 | - ), |
|
2034 | - __FILE__, |
|
2035 | - __FUNCTION__, |
|
2036 | - __LINE__ |
|
2037 | - ); |
|
2038 | - } |
|
2039 | - } else { |
|
2040 | - EE_Error::add_error( |
|
2041 | - esc_html__( |
|
2042 | - 'The submitted billing form is invalid possibly due to a technical reason.', |
|
2043 | - 'event_espresso' |
|
2044 | - ), |
|
2045 | - __FILE__, |
|
2046 | - __FUNCTION__, |
|
2047 | - __LINE__ |
|
2048 | - ); |
|
2049 | - } |
|
2050 | - return false; |
|
2051 | - } |
|
2052 | - |
|
2053 | - |
|
2054 | - /** |
|
2055 | - * _setup_primary_registrant_prior_to_payment |
|
2056 | - * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
2057 | - * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
2058 | - * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
2059 | - * yet) |
|
2060 | - * |
|
2061 | - * @access private |
|
2062 | - * @return bool |
|
2063 | - * @throws EE_Error |
|
2064 | - * @throws InvalidArgumentException |
|
2065 | - * @throws ReflectionException |
|
2066 | - * @throws RuntimeException |
|
2067 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2068 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2069 | - */ |
|
2070 | - private function _setup_primary_registrant_prior_to_payment() |
|
2071 | - { |
|
2072 | - // check if transaction has a primary registrant and that it has a related Attendee object |
|
2073 | - // if not, then we need to at least gather some primary registrant data before attempting payment |
|
2074 | - if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
2075 | - && ! $this->checkout->transaction_has_primary_registrant() |
|
2076 | - && ! $this->_capture_primary_registration_data_from_billing_form() |
|
2077 | - ) { |
|
2078 | - return false; |
|
2079 | - } |
|
2080 | - // because saving an object clears it's cache, we need to do the chevy shuffle |
|
2081 | - // grab the primary_registration object |
|
2082 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2083 | - // at this point we'll consider a TXN to not have been failed |
|
2084 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
2085 | - // save the TXN ( which clears cached copy of primary_registration) |
|
2086 | - $this->checkout->transaction->save(); |
|
2087 | - // grab TXN ID and save it to the primary_registration |
|
2088 | - $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
2089 | - // save what we have so far |
|
2090 | - $primary_registration->save(); |
|
2091 | - return true; |
|
2092 | - } |
|
2093 | - |
|
2094 | - |
|
2095 | - /** |
|
2096 | - * _capture_primary_registration_data_from_billing_form |
|
2097 | - * |
|
2098 | - * @access private |
|
2099 | - * @return bool |
|
2100 | - * @throws EE_Error |
|
2101 | - * @throws InvalidArgumentException |
|
2102 | - * @throws ReflectionException |
|
2103 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2104 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2105 | - */ |
|
2106 | - private function _capture_primary_registration_data_from_billing_form() |
|
2107 | - { |
|
2108 | - // convert billing form data into an attendee |
|
2109 | - $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
2110 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2111 | - EE_Error::add_error( |
|
2112 | - sprintf( |
|
2113 | - esc_html__( |
|
2114 | - 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2115 | - 'event_espresso' |
|
2116 | - ), |
|
2117 | - '<br/>', |
|
2118 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2119 | - ), |
|
2120 | - __FILE__, |
|
2121 | - __FUNCTION__, |
|
2122 | - __LINE__ |
|
2123 | - ); |
|
2124 | - return false; |
|
2125 | - } |
|
2126 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2127 | - if (! $primary_registration instanceof EE_Registration) { |
|
2128 | - EE_Error::add_error( |
|
2129 | - sprintf( |
|
2130 | - esc_html__( |
|
2131 | - 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2132 | - 'event_espresso' |
|
2133 | - ), |
|
2134 | - '<br/>', |
|
2135 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2136 | - ), |
|
2137 | - __FILE__, |
|
2138 | - __FUNCTION__, |
|
2139 | - __LINE__ |
|
2140 | - ); |
|
2141 | - return false; |
|
2142 | - } |
|
2143 | - if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
2144 | - instanceof |
|
2145 | - EE_Attendee |
|
2146 | - ) { |
|
2147 | - EE_Error::add_error( |
|
2148 | - sprintf( |
|
2149 | - esc_html__( |
|
2150 | - 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2151 | - 'event_espresso' |
|
2152 | - ), |
|
2153 | - '<br/>', |
|
2154 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2155 | - ), |
|
2156 | - __FILE__, |
|
2157 | - __FUNCTION__, |
|
2158 | - __LINE__ |
|
2159 | - ); |
|
2160 | - return false; |
|
2161 | - } |
|
2162 | - /** @type EE_Registration_Processor $registration_processor */ |
|
2163 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
2164 | - // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
2165 | - $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
2166 | - return true; |
|
2167 | - } |
|
2168 | - |
|
2169 | - |
|
2170 | - /** |
|
2171 | - * _get_payment_method_for_selected_method_of_payment |
|
2172 | - * retrieves a valid payment method |
|
2173 | - * |
|
2174 | - * @access public |
|
2175 | - * @return EE_Payment_Method |
|
2176 | - * @throws EE_Error |
|
2177 | - * @throws InvalidArgumentException |
|
2178 | - * @throws ReflectionException |
|
2179 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2180 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2181 | - */ |
|
2182 | - private function _get_payment_method_for_selected_method_of_payment() |
|
2183 | - { |
|
2184 | - if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
2185 | - $this->_redirect_because_event_sold_out(); |
|
2186 | - return null; |
|
2187 | - } |
|
2188 | - // get EE_Payment_Method object |
|
2189 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
2190 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2191 | - } else { |
|
2192 | - // load EEM_Payment_Method |
|
2193 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
2194 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
2195 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
2196 | - $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
2197 | - } |
|
2198 | - // verify $payment_method |
|
2199 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
2200 | - // not a payment |
|
2201 | - EE_Error::add_error( |
|
2202 | - sprintf( |
|
2203 | - esc_html__( |
|
2204 | - 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2205 | - 'event_espresso' |
|
2206 | - ), |
|
2207 | - '<br/>', |
|
2208 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2209 | - ), |
|
2210 | - __FILE__, |
|
2211 | - __FUNCTION__, |
|
2212 | - __LINE__ |
|
2213 | - ); |
|
2214 | - return null; |
|
2215 | - } |
|
2216 | - // and verify it has a valid Payment_Method Type object |
|
2217 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2218 | - // not a payment |
|
2219 | - EE_Error::add_error( |
|
2220 | - sprintf( |
|
2221 | - esc_html__( |
|
2222 | - 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2223 | - 'event_espresso' |
|
2224 | - ), |
|
2225 | - '<br/>', |
|
2226 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2227 | - ), |
|
2228 | - __FILE__, |
|
2229 | - __FUNCTION__, |
|
2230 | - __LINE__ |
|
2231 | - ); |
|
2232 | - return null; |
|
2233 | - } |
|
2234 | - return $payment_method; |
|
2235 | - } |
|
2236 | - |
|
2237 | - |
|
2238 | - /** |
|
2239 | - * _attempt_payment |
|
2240 | - * |
|
2241 | - * @access private |
|
2242 | - * @type EE_Payment_Method $payment_method |
|
2243 | - * @return mixed EE_Payment | boolean |
|
2244 | - * @throws EE_Error |
|
2245 | - * @throws InvalidArgumentException |
|
2246 | - * @throws ReflectionException |
|
2247 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2248 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2249 | - */ |
|
2250 | - private function _attempt_payment(EE_Payment_Method $payment_method) |
|
2251 | - { |
|
2252 | - $payment = null; |
|
2253 | - $this->checkout->transaction->save(); |
|
2254 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2255 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
2256 | - return false; |
|
2257 | - } |
|
2258 | - try { |
|
2259 | - $payment_processor->set_revisit($this->checkout->revisit); |
|
2260 | - // generate payment object |
|
2261 | - $payment = $payment_processor->process_payment( |
|
2262 | - $payment_method, |
|
2263 | - $this->checkout->transaction, |
|
2264 | - $this->checkout->amount_owing, |
|
2265 | - $this->checkout->billing_form, |
|
2266 | - $this->_get_return_url($payment_method), |
|
2267 | - 'CART', |
|
2268 | - $this->checkout->admin_request, |
|
2269 | - true, |
|
2270 | - $this->reg_step_url() |
|
2271 | - ); |
|
2272 | - } catch (Exception $e) { |
|
2273 | - $this->_handle_payment_processor_exception($e); |
|
2274 | - } |
|
2275 | - return $payment; |
|
2276 | - } |
|
2277 | - |
|
2278 | - |
|
2279 | - /** |
|
2280 | - * _handle_payment_processor_exception |
|
2281 | - * |
|
2282 | - * @access protected |
|
2283 | - * @param \Exception $e |
|
2284 | - * @return void |
|
2285 | - * @throws EE_Error |
|
2286 | - * @throws InvalidArgumentException |
|
2287 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2288 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2289 | - */ |
|
2290 | - protected function _handle_payment_processor_exception(Exception $e) |
|
2291 | - { |
|
2292 | - EE_Error::add_error( |
|
2293 | - sprintf( |
|
2294 | - esc_html__( |
|
2295 | - 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
2296 | - 'event_espresso' |
|
2297 | - ), |
|
2298 | - '<br/>', |
|
2299 | - EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
2300 | - $e->getMessage(), |
|
2301 | - $e->getFile(), |
|
2302 | - $e->getLine() |
|
2303 | - ), |
|
2304 | - __FILE__, |
|
2305 | - __FUNCTION__, |
|
2306 | - __LINE__ |
|
2307 | - ); |
|
2308 | - } |
|
2309 | - |
|
2310 | - |
|
2311 | - /** |
|
2312 | - * _get_return_url |
|
2313 | - * |
|
2314 | - * @access protected |
|
2315 | - * @param \EE_Payment_Method $payment_method |
|
2316 | - * @return string |
|
2317 | - * @throws \EE_Error |
|
2318 | - */ |
|
2319 | - protected function _get_return_url(EE_Payment_Method $payment_method) |
|
2320 | - { |
|
2321 | - $return_url = ''; |
|
2322 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
2323 | - case EE_PMT_Base::offsite: |
|
2324 | - $return_url = add_query_arg( |
|
2325 | - array( |
|
2326 | - 'action' => 'process_gateway_response', |
|
2327 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2328 | - 'spco_txn' => $this->checkout->transaction->ID(), |
|
2329 | - ), |
|
2330 | - $this->reg_step_url() |
|
2331 | - ); |
|
2332 | - break; |
|
2333 | - case EE_PMT_Base::onsite: |
|
2334 | - case EE_PMT_Base::offline: |
|
2335 | - $return_url = $this->checkout->next_step->reg_step_url(); |
|
2336 | - break; |
|
2337 | - } |
|
2338 | - return $return_url; |
|
2339 | - } |
|
2340 | - |
|
2341 | - |
|
2342 | - /** |
|
2343 | - * _validate_payment |
|
2344 | - * |
|
2345 | - * @access private |
|
2346 | - * @param EE_Payment $payment |
|
2347 | - * @return EE_Payment|FALSE |
|
2348 | - * @throws EE_Error |
|
2349 | - * @throws InvalidArgumentException |
|
2350 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2351 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2352 | - */ |
|
2353 | - private function _validate_payment($payment = null) |
|
2354 | - { |
|
2355 | - if ($this->checkout->payment_method->is_off_line()) { |
|
2356 | - return true; |
|
2357 | - } |
|
2358 | - // verify payment object |
|
2359 | - if (! $payment instanceof EE_Payment) { |
|
2360 | - // not a payment |
|
2361 | - EE_Error::add_error( |
|
2362 | - sprintf( |
|
2363 | - esc_html__( |
|
2364 | - 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
2365 | - 'event_espresso' |
|
2366 | - ), |
|
2367 | - '<br/>', |
|
2368 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2369 | - ), |
|
2370 | - __FILE__, |
|
2371 | - __FUNCTION__, |
|
2372 | - __LINE__ |
|
2373 | - ); |
|
2374 | - return false; |
|
2375 | - } |
|
2376 | - return $payment; |
|
2377 | - } |
|
2378 | - |
|
2379 | - |
|
2380 | - /** |
|
2381 | - * _post_payment_processing |
|
2382 | - * |
|
2383 | - * @access private |
|
2384 | - * @param EE_Payment|bool $payment |
|
2385 | - * @return bool |
|
2386 | - * @throws EE_Error |
|
2387 | - * @throws InvalidArgumentException |
|
2388 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2389 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2390 | - */ |
|
2391 | - private function _post_payment_processing($payment = null) |
|
2392 | - { |
|
2393 | - // Off-Line payment? |
|
2394 | - if ($payment === true) { |
|
2395 | - // $this->_setup_redirect_for_next_step(); |
|
2396 | - return true; |
|
2397 | - // On-Site payment? |
|
2398 | - } elseif ($this->checkout->payment_method->is_on_site()) { |
|
2399 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2400 | - // $this->_setup_redirect_for_next_step(); |
|
2401 | - $this->checkout->continue_reg = false; |
|
2402 | - } |
|
2403 | - // Off-Site payment? |
|
2404 | - } elseif ($this->checkout->payment_method->is_off_site()) { |
|
2405 | - // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
2406 | - if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
2407 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
2408 | - $this->checkout->redirect = true; |
|
2409 | - $this->checkout->redirect_form = $payment->redirect_form(); |
|
2410 | - $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
2411 | - // set JSON response |
|
2412 | - $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
2413 | - // and lastly, let's bump the payment status to pending |
|
2414 | - $payment->set_status(EEM_Payment::status_id_pending); |
|
2415 | - $payment->save(); |
|
2416 | - } else { |
|
2417 | - // not a payment |
|
2418 | - $this->checkout->continue_reg = false; |
|
2419 | - EE_Error::add_error( |
|
2420 | - sprintf( |
|
2421 | - esc_html__( |
|
2422 | - 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
2423 | - 'event_espresso' |
|
2424 | - ), |
|
2425 | - '<br/>', |
|
2426 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2427 | - ), |
|
2428 | - __FILE__, |
|
2429 | - __FUNCTION__, |
|
2430 | - __LINE__ |
|
2431 | - ); |
|
2432 | - } |
|
2433 | - } else { |
|
2434 | - // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
2435 | - $this->checkout->continue_reg = false; |
|
2436 | - return false; |
|
2437 | - } |
|
2438 | - return $payment; |
|
2439 | - } |
|
2440 | - |
|
2441 | - |
|
2442 | - /** |
|
2443 | - * _process_payment_status |
|
2444 | - * |
|
2445 | - * @access private |
|
2446 | - * @type EE_Payment $payment |
|
2447 | - * @param string $payment_occurs |
|
2448 | - * @return bool |
|
2449 | - * @throws EE_Error |
|
2450 | - * @throws InvalidArgumentException |
|
2451 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2452 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2453 | - */ |
|
2454 | - private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
2455 | - { |
|
2456 | - // off-line payment? carry on |
|
2457 | - if ($payment_occurs === EE_PMT_Base::offline) { |
|
2458 | - return true; |
|
2459 | - } |
|
2460 | - // verify payment validity |
|
2461 | - if ($payment instanceof EE_Payment) { |
|
2462 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
2463 | - $msg = $payment->gateway_response(); |
|
2464 | - // check results |
|
2465 | - switch ($payment->status()) { |
|
2466 | - // good payment |
|
2467 | - case EEM_Payment::status_id_approved: |
|
2468 | - EE_Error::add_success( |
|
2469 | - esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
2470 | - __FILE__, |
|
2471 | - __FUNCTION__, |
|
2472 | - __LINE__ |
|
2473 | - ); |
|
2474 | - return true; |
|
2475 | - break; |
|
2476 | - // slow payment |
|
2477 | - case EEM_Payment::status_id_pending: |
|
2478 | - if (empty($msg)) { |
|
2479 | - $msg = esc_html__( |
|
2480 | - 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
2481 | - 'event_espresso' |
|
2482 | - ); |
|
2483 | - } |
|
2484 | - EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2485 | - return true; |
|
2486 | - break; |
|
2487 | - // don't wanna payment |
|
2488 | - case EEM_Payment::status_id_cancelled: |
|
2489 | - if (empty($msg)) { |
|
2490 | - $msg = _n( |
|
2491 | - 'Payment cancelled. Please try again.', |
|
2492 | - 'Payment cancelled. Please try again or select another method of payment.', |
|
2493 | - count($this->checkout->available_payment_methods), |
|
2494 | - 'event_espresso' |
|
2495 | - ); |
|
2496 | - } |
|
2497 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2498 | - return false; |
|
2499 | - break; |
|
2500 | - // not enough payment |
|
2501 | - case EEM_Payment::status_id_declined: |
|
2502 | - if (empty($msg)) { |
|
2503 | - $msg = _n( |
|
2504 | - 'We\'re sorry but your payment was declined. Please try again.', |
|
2505 | - 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
2506 | - count($this->checkout->available_payment_methods), |
|
2507 | - 'event_espresso' |
|
2508 | - ); |
|
2509 | - } |
|
2510 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2511 | - return false; |
|
2512 | - break; |
|
2513 | - // bad payment |
|
2514 | - case EEM_Payment::status_id_failed: |
|
2515 | - if (! empty($msg)) { |
|
2516 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2517 | - return false; |
|
2518 | - } |
|
2519 | - // default to error below |
|
2520 | - break; |
|
2521 | - } |
|
2522 | - } |
|
2523 | - // off-site payment gateway responses are too unreliable, so let's just assume that |
|
2524 | - // the payment processing is just running slower than the registrant's request |
|
2525 | - if ($payment_occurs === EE_PMT_Base::offsite) { |
|
2526 | - return true; |
|
2527 | - } |
|
2528 | - EE_Error::add_error( |
|
2529 | - sprintf( |
|
2530 | - esc_html__( |
|
2531 | - 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2532 | - 'event_espresso' |
|
2533 | - ), |
|
2534 | - '<br/>', |
|
2535 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2536 | - ), |
|
2537 | - __FILE__, |
|
2538 | - __FUNCTION__, |
|
2539 | - __LINE__ |
|
2540 | - ); |
|
2541 | - return false; |
|
2542 | - } |
|
2543 | - |
|
2544 | - |
|
2545 | - |
|
2546 | - |
|
2547 | - |
|
2548 | - |
|
2549 | - /********************************************************************************************************/ |
|
2550 | - /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
2551 | - /********************************************************************************************************/ |
|
2552 | - /** |
|
2553 | - * process_gateway_response |
|
2554 | - * this is the return point for Off-Site Payment Methods |
|
2555 | - * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
2556 | - * otherwise, it will load up the last payment made for the TXN. |
|
2557 | - * If the payment retrieved looks good, it will then either: |
|
2558 | - * complete the current step and allow advancement to the next reg step |
|
2559 | - * or present the payment options again |
|
2560 | - * |
|
2561 | - * @access private |
|
2562 | - * @return EE_Payment|FALSE |
|
2563 | - * @throws EE_Error |
|
2564 | - * @throws InvalidArgumentException |
|
2565 | - * @throws ReflectionException |
|
2566 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2567 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2568 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2569 | - */ |
|
2570 | - public function process_gateway_response() |
|
2571 | - { |
|
2572 | - $payment = null; |
|
2573 | - // how have they chosen to pay? |
|
2574 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
2575 | - // get EE_Payment_Method object |
|
2576 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2577 | - $this->checkout->continue_reg = false; |
|
2578 | - return false; |
|
2579 | - } |
|
2580 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
2581 | - return false; |
|
2582 | - } |
|
2583 | - $this->_validate_offsite_return(); |
|
2584 | - // DEBUG LOG |
|
2585 | - // $this->checkout->log( |
|
2586 | - // __CLASS__, |
|
2587 | - // __FUNCTION__, |
|
2588 | - // __LINE__, |
|
2589 | - // array( |
|
2590 | - // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2591 | - // 'payment_method' => $this->checkout->payment_method, |
|
2592 | - // ), |
|
2593 | - // true |
|
2594 | - // ); |
|
2595 | - // verify TXN |
|
2596 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
2597 | - $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
2598 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
2599 | - $this->checkout->continue_reg = false; |
|
2600 | - return false; |
|
2601 | - } |
|
2602 | - $payment = $this->_process_off_site_payment($gateway); |
|
2603 | - $payment = $this->_process_cancelled_payments($payment); |
|
2604 | - $payment = $this->_validate_payment($payment); |
|
2605 | - // if payment was not declined by the payment gateway or cancelled by the registrant |
|
2606 | - if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
2607 | - // $this->_setup_redirect_for_next_step(); |
|
2608 | - // store that for later |
|
2609 | - $this->checkout->payment = $payment; |
|
2610 | - // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
2611 | - // because we will complete this step during the IPN processing then |
|
2612 | - if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
2613 | - $this->set_completed(); |
|
2614 | - } |
|
2615 | - return true; |
|
2616 | - } |
|
2617 | - } |
|
2618 | - // DEBUG LOG |
|
2619 | - // $this->checkout->log( |
|
2620 | - // __CLASS__, |
|
2621 | - // __FUNCTION__, |
|
2622 | - // __LINE__, |
|
2623 | - // array('payment' => $payment) |
|
2624 | - // ); |
|
2625 | - $this->checkout->continue_reg = false; |
|
2626 | - return false; |
|
2627 | - } |
|
2628 | - |
|
2629 | - |
|
2630 | - /** |
|
2631 | - * _validate_return |
|
2632 | - * |
|
2633 | - * @access private |
|
2634 | - * @return void |
|
2635 | - * @throws EE_Error |
|
2636 | - * @throws InvalidArgumentException |
|
2637 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2638 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2639 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2640 | - */ |
|
2641 | - private function _validate_offsite_return() |
|
2642 | - { |
|
2643 | - $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
2644 | - if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
2645 | - // Houston... we might have a problem |
|
2646 | - $invalid_TXN = false; |
|
2647 | - // first gather some info |
|
2648 | - $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2649 | - $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
2650 | - ? $valid_TXN->primary_registration() |
|
2651 | - : null; |
|
2652 | - // let's start by retrieving the cart for this TXN |
|
2653 | - $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
2654 | - if ($cart instanceof EE_Cart) { |
|
2655 | - // verify that the current cart has tickets |
|
2656 | - $tickets = $cart->get_tickets(); |
|
2657 | - if (empty($tickets)) { |
|
2658 | - $invalid_TXN = true; |
|
2659 | - } |
|
2660 | - } else { |
|
2661 | - $invalid_TXN = true; |
|
2662 | - } |
|
2663 | - $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
2664 | - ? $primary_registrant->session_ID() |
|
2665 | - : null; |
|
2666 | - // validate current Session ID and compare against valid TXN session ID |
|
2667 | - if ($invalid_TXN // if this is already true, then skip other checks |
|
2668 | - || EE_Session::instance()->id() === null |
|
2669 | - || ( |
|
2670 | - // WARNING !!! |
|
2671 | - // this could be PayPal sending back duplicate requests (ya they do that) |
|
2672 | - // or it **could** mean someone is simply registering AGAIN after having just done so |
|
2673 | - // so now we need to determine if this current TXN looks valid or not |
|
2674 | - // and whether this reg step has even been started ? |
|
2675 | - EE_Session::instance()->id() === $valid_TXN_SID |
|
2676 | - // really? you're half way through this reg step, but you never started it ? |
|
2677 | - && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
2678 | - ) |
|
2679 | - ) { |
|
2680 | - $invalid_TXN = true; |
|
2681 | - } |
|
2682 | - if ($invalid_TXN) { |
|
2683 | - // is the valid TXN completed ? |
|
2684 | - if ($valid_TXN instanceof EE_Transaction) { |
|
2685 | - // has this step even been started ? |
|
2686 | - $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
2687 | - if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
2688 | - // so it **looks** like this is a double request from PayPal |
|
2689 | - // so let's try to pick up where we left off |
|
2690 | - $this->checkout->transaction = $valid_TXN; |
|
2691 | - $this->checkout->refresh_all_entities(true); |
|
2692 | - return; |
|
2693 | - } |
|
2694 | - } |
|
2695 | - // you appear to be lost? |
|
2696 | - $this->_redirect_wayward_request($primary_registrant); |
|
2697 | - } |
|
2698 | - } |
|
2699 | - } |
|
2700 | - |
|
2701 | - |
|
2702 | - /** |
|
2703 | - * _redirect_wayward_request |
|
2704 | - * |
|
2705 | - * @access private |
|
2706 | - * @param \EE_Registration|null $primary_registrant |
|
2707 | - * @return bool |
|
2708 | - * @throws EE_Error |
|
2709 | - * @throws InvalidArgumentException |
|
2710 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2711 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2712 | - */ |
|
2713 | - private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
2714 | - { |
|
2715 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2716 | - // try redirecting based on the current TXN |
|
2717 | - $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
2718 | - ? $this->checkout->transaction->primary_registration() |
|
2719 | - : null; |
|
2720 | - } |
|
2721 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2722 | - EE_Error::add_error( |
|
2723 | - sprintf( |
|
2724 | - esc_html__( |
|
2725 | - 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
2726 | - 'event_espresso' |
|
2727 | - ), |
|
2728 | - '<br/>', |
|
2729 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2730 | - ), |
|
2731 | - __FILE__, |
|
2732 | - __FUNCTION__, |
|
2733 | - __LINE__ |
|
2734 | - ); |
|
2735 | - return false; |
|
2736 | - } |
|
2737 | - // make sure transaction is not locked |
|
2738 | - $this->checkout->transaction->unlock(); |
|
2739 | - wp_safe_redirect( |
|
2740 | - add_query_arg( |
|
2741 | - array( |
|
2742 | - 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
2743 | - ), |
|
2744 | - $this->checkout->thank_you_page_url |
|
2745 | - ) |
|
2746 | - ); |
|
2747 | - exit(); |
|
2748 | - } |
|
2749 | - |
|
2750 | - |
|
2751 | - /** |
|
2752 | - * _process_off_site_payment |
|
2753 | - * |
|
2754 | - * @access private |
|
2755 | - * @param \EE_Offsite_Gateway $gateway |
|
2756 | - * @return EE_Payment |
|
2757 | - * @throws EE_Error |
|
2758 | - * @throws InvalidArgumentException |
|
2759 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2760 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2761 | - */ |
|
2762 | - private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
2763 | - { |
|
2764 | - try { |
|
2765 | - $request_data = \EE_Registry::instance()->REQ->params(); |
|
2766 | - // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
2767 | - $this->set_handle_IPN_in_this_request( |
|
2768 | - $gateway->handle_IPN_in_this_request($request_data, false) |
|
2769 | - ); |
|
2770 | - if ($this->handle_IPN_in_this_request()) { |
|
2771 | - // get payment details and process results |
|
2772 | - /** @type EE_Payment_Processor $payment_processor */ |
|
2773 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2774 | - $payment = $payment_processor->process_ipn( |
|
2775 | - $request_data, |
|
2776 | - $this->checkout->transaction, |
|
2777 | - $this->checkout->payment_method, |
|
2778 | - true, |
|
2779 | - false |
|
2780 | - ); |
|
2781 | - // $payment_source = 'process_ipn'; |
|
2782 | - } else { |
|
2783 | - $payment = $this->checkout->transaction->last_payment(); |
|
2784 | - // $payment_source = 'last_payment'; |
|
2785 | - } |
|
2786 | - } catch (Exception $e) { |
|
2787 | - // let's just eat the exception and try to move on using any previously set payment info |
|
2788 | - $payment = $this->checkout->transaction->last_payment(); |
|
2789 | - // $payment_source = 'last_payment after Exception'; |
|
2790 | - // but if we STILL don't have a payment object |
|
2791 | - if (! $payment instanceof EE_Payment) { |
|
2792 | - // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
2793 | - $this->_handle_payment_processor_exception($e); |
|
2794 | - } |
|
2795 | - } |
|
2796 | - // DEBUG LOG |
|
2797 | - // $this->checkout->log( |
|
2798 | - // __CLASS__, |
|
2799 | - // __FUNCTION__, |
|
2800 | - // __LINE__, |
|
2801 | - // array( |
|
2802 | - // 'process_ipn_payment' => $payment, |
|
2803 | - // 'payment_source' => $payment_source, |
|
2804 | - // ) |
|
2805 | - // ); |
|
2806 | - return $payment; |
|
2807 | - } |
|
2808 | - |
|
2809 | - |
|
2810 | - /** |
|
2811 | - * _process_cancelled_payments |
|
2812 | - * just makes sure that the payment status gets updated correctly |
|
2813 | - * so tha tan error isn't generated during payment validation |
|
2814 | - * |
|
2815 | - * @access private |
|
2816 | - * @param EE_Payment $payment |
|
2817 | - * @return EE_Payment | FALSE |
|
2818 | - * @throws \EE_Error |
|
2819 | - */ |
|
2820 | - private function _process_cancelled_payments($payment = null) |
|
2821 | - { |
|
2822 | - if ($payment instanceof EE_Payment |
|
2823 | - && isset($_REQUEST['ee_cancel_payment']) |
|
2824 | - && $payment->status() === EEM_Payment::status_id_failed |
|
2825 | - ) { |
|
2826 | - $payment->set_status(EEM_Payment::status_id_cancelled); |
|
2827 | - } |
|
2828 | - return $payment; |
|
2829 | - } |
|
2830 | - |
|
2831 | - |
|
2832 | - /** |
|
2833 | - * get_transaction_details_for_gateways |
|
2834 | - * |
|
2835 | - * @access public |
|
2836 | - * @return int |
|
2837 | - * @throws EE_Error |
|
2838 | - * @throws InvalidArgumentException |
|
2839 | - * @throws ReflectionException |
|
2840 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2841 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2842 | - */ |
|
2843 | - public function get_transaction_details_for_gateways() |
|
2844 | - { |
|
2845 | - $txn_details = array(); |
|
2846 | - // ya gotta make a choice man |
|
2847 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
2848 | - $txn_details = array( |
|
2849 | - 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
2850 | - ); |
|
2851 | - } |
|
2852 | - // get EE_Payment_Method object |
|
2853 | - if (empty($txn_details) |
|
2854 | - && |
|
2855 | - ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
2856 | - ) { |
|
2857 | - $txn_details = array( |
|
2858 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2859 | - 'error' => esc_html__( |
|
2860 | - 'A valid Payment Method could not be determined.', |
|
2861 | - 'event_espresso' |
|
2862 | - ), |
|
2863 | - ); |
|
2864 | - } |
|
2865 | - if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
2866 | - $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
2867 | - $txn_details = array( |
|
2868 | - 'TXN_ID' => $this->checkout->transaction->ID(), |
|
2869 | - 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
2870 | - 'TXN_total' => $this->checkout->transaction->total(), |
|
2871 | - 'TXN_paid' => $this->checkout->transaction->paid(), |
|
2872 | - 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
2873 | - 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
2874 | - 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
2875 | - 'payment_amount' => $this->checkout->amount_owing, |
|
2876 | - 'return_url' => $return_url, |
|
2877 | - 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
2878 | - 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
2879 | - array( |
|
2880 | - 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
2881 | - 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
2882 | - ) |
|
2883 | - ), |
|
2884 | - ); |
|
2885 | - } |
|
2886 | - echo wp_json_encode($txn_details); |
|
2887 | - exit(); |
|
2888 | - } |
|
2889 | - |
|
2890 | - |
|
2891 | - /** |
|
2892 | - * __sleep |
|
2893 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
2894 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
2895 | - * reg form, because if needed, it will be regenerated anyways |
|
2896 | - * |
|
2897 | - * @return array |
|
2898 | - */ |
|
2899 | - public function __sleep() |
|
2900 | - { |
|
2901 | - // remove the reg form and the checkout |
|
2902 | - return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
2903 | - } |
|
15 | + /** |
|
16 | + * @access protected |
|
17 | + * @var EE_Line_Item_Display $Line_Item_Display |
|
18 | + */ |
|
19 | + protected $line_item_display; |
|
20 | + |
|
21 | + /** |
|
22 | + * @access protected |
|
23 | + * @var boolean $handle_IPN_in_this_request |
|
24 | + */ |
|
25 | + protected $handle_IPN_in_this_request = false; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
30 | + * |
|
31 | + * @access public |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public static function set_hooks() |
|
35 | + { |
|
36 | + add_filter( |
|
37 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
38 | + array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
39 | + ); |
|
40 | + add_action( |
|
41 | + 'wp_ajax_switch_spco_billing_form', |
|
42 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
43 | + ); |
|
44 | + add_action( |
|
45 | + 'wp_ajax_nopriv_switch_spco_billing_form', |
|
46 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
47 | + ); |
|
48 | + add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
49 | + add_action( |
|
50 | + 'wp_ajax_nopriv_save_payer_details', |
|
51 | + array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
52 | + ); |
|
53 | + add_action( |
|
54 | + 'wp_ajax_get_transaction_details_for_gateways', |
|
55 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
56 | + ); |
|
57 | + add_action( |
|
58 | + 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
59 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
60 | + ); |
|
61 | + add_filter( |
|
62 | + 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
63 | + array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
64 | + 10, |
|
65 | + 1 |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * ajax switch_spco_billing_form |
|
72 | + * |
|
73 | + * @throws \EE_Error |
|
74 | + */ |
|
75 | + public static function switch_spco_billing_form() |
|
76 | + { |
|
77 | + EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * ajax save_payer_details |
|
83 | + * |
|
84 | + * @throws \EE_Error |
|
85 | + */ |
|
86 | + public static function save_payer_details() |
|
87 | + { |
|
88 | + EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * ajax get_transaction_details |
|
94 | + * |
|
95 | + * @throws \EE_Error |
|
96 | + */ |
|
97 | + public static function get_transaction_details() |
|
98 | + { |
|
99 | + EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * bypass_recaptcha_for_load_payment_method |
|
105 | + * |
|
106 | + * @access public |
|
107 | + * @return array |
|
108 | + * @throws InvalidArgumentException |
|
109 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
110 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
111 | + */ |
|
112 | + public static function bypass_recaptcha_for_load_payment_method() |
|
113 | + { |
|
114 | + return array( |
|
115 | + 'EESID' => EE_Registry::instance()->SSN->id(), |
|
116 | + 'step' => 'payment_options', |
|
117 | + 'action' => 'spco_billing_form', |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * class constructor |
|
124 | + * |
|
125 | + * @access public |
|
126 | + * @param EE_Checkout $checkout |
|
127 | + */ |
|
128 | + public function __construct(EE_Checkout $checkout) |
|
129 | + { |
|
130 | + $this->_slug = 'payment_options'; |
|
131 | + $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
132 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
133 | + $this->checkout = $checkout; |
|
134 | + $this->_reset_success_message(); |
|
135 | + $this->set_instructions( |
|
136 | + esc_html__( |
|
137 | + 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
138 | + 'event_espresso' |
|
139 | + ) |
|
140 | + ); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return null |
|
146 | + */ |
|
147 | + public function line_item_display() |
|
148 | + { |
|
149 | + return $this->line_item_display; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param null $line_item_display |
|
155 | + */ |
|
156 | + public function set_line_item_display($line_item_display) |
|
157 | + { |
|
158 | + $this->line_item_display = $line_item_display; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @return boolean |
|
164 | + */ |
|
165 | + public function handle_IPN_in_this_request() |
|
166 | + { |
|
167 | + return $this->handle_IPN_in_this_request; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param boolean $handle_IPN_in_this_request |
|
173 | + */ |
|
174 | + public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
175 | + { |
|
176 | + $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * translate_js_strings |
|
182 | + * |
|
183 | + * @return void |
|
184 | + */ |
|
185 | + public function translate_js_strings() |
|
186 | + { |
|
187 | + EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
188 | + 'Please select a method of payment in order to continue.', |
|
189 | + 'event_espresso' |
|
190 | + ); |
|
191 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
192 | + 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
193 | + 'event_espresso' |
|
194 | + ); |
|
195 | + EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
196 | + 'Forwarding to Secure Payment Provider.', |
|
197 | + 'event_espresso' |
|
198 | + ); |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * enqueue_styles_and_scripts |
|
204 | + * |
|
205 | + * @return void |
|
206 | + * @throws EE_Error |
|
207 | + * @throws InvalidArgumentException |
|
208 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
209 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
210 | + */ |
|
211 | + public function enqueue_styles_and_scripts() |
|
212 | + { |
|
213 | + $transaction = $this->checkout->transaction; |
|
214 | + // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
215 | + if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
216 | + return; |
|
217 | + } |
|
218 | + foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
219 | + $transaction, |
|
220 | + EEM_Payment_Method::scope_cart |
|
221 | + ) as $payment_method) { |
|
222 | + $type_obj = $payment_method->type_obj(); |
|
223 | + if ($type_obj instanceof EE_PMT_Base) { |
|
224 | + $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
225 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
226 | + $billing_form->enqueue_js(); |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * initialize_reg_step |
|
235 | + * |
|
236 | + * @return bool |
|
237 | + * @throws EE_Error |
|
238 | + * @throws InvalidArgumentException |
|
239 | + * @throws ReflectionException |
|
240 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
241 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
242 | + */ |
|
243 | + public function initialize_reg_step() |
|
244 | + { |
|
245 | + // TODO: if /when we implement donations, then this will need overriding |
|
246 | + if (// don't need payment options for: |
|
247 | + // registrations made via the admin |
|
248 | + // completed transactions |
|
249 | + // overpaid transactions |
|
250 | + // $ 0.00 transactions(no payment required) |
|
251 | + ! $this->checkout->payment_required() |
|
252 | + // but do NOT remove if current action being called belongs to this reg step |
|
253 | + && ! is_callable(array($this, $this->checkout->action)) |
|
254 | + && ! $this->completed() |
|
255 | + ) { |
|
256 | + // and if so, then we no longer need the Payment Options step |
|
257 | + if ($this->is_current_step()) { |
|
258 | + $this->checkout->generate_reg_form = false; |
|
259 | + } |
|
260 | + $this->checkout->remove_reg_step($this->_slug); |
|
261 | + // DEBUG LOG |
|
262 | + // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
263 | + return false; |
|
264 | + } |
|
265 | + // load EEM_Payment_Method |
|
266 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
267 | + // get all active payment methods |
|
268 | + $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
269 | + $this->checkout->transaction, |
|
270 | + EEM_Payment_Method::scope_cart |
|
271 | + ); |
|
272 | + return true; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * @return EE_Form_Section_Proper |
|
278 | + * @throws EE_Error |
|
279 | + * @throws InvalidArgumentException |
|
280 | + * @throws ReflectionException |
|
281 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
282 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
283 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
284 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
285 | + */ |
|
286 | + public function generate_reg_form() |
|
287 | + { |
|
288 | + // reset in case someone changes their mind |
|
289 | + $this->_reset_selected_method_of_payment(); |
|
290 | + // set some defaults |
|
291 | + $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
292 | + $registrations_requiring_payment = array(); |
|
293 | + $registrations_for_free_events = array(); |
|
294 | + $registrations_requiring_pre_approval = array(); |
|
295 | + $sold_out_events = array(); |
|
296 | + $insufficient_spaces_available = array(); |
|
297 | + $no_payment_required = true; |
|
298 | + // loop thru registrations to gather info |
|
299 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
300 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
301 | + $registrations, |
|
302 | + $this->checkout->revisit |
|
303 | + ); |
|
304 | + foreach ($registrations as $REG_ID => $registration) { |
|
305 | + /** @var $registration EE_Registration */ |
|
306 | + // has this registration lost it's space ? |
|
307 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
308 | + if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
309 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
310 | + } else { |
|
311 | + $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
312 | + } |
|
313 | + continue; |
|
314 | + } |
|
315 | + // event requires admin approval |
|
316 | + if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
317 | + // add event to list of events with pre-approval reg status |
|
318 | + $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
319 | + do_action( |
|
320 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
321 | + $registration->event(), |
|
322 | + $this |
|
323 | + ); |
|
324 | + continue; |
|
325 | + } |
|
326 | + if ($this->checkout->revisit |
|
327 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
328 | + && ( |
|
329 | + $registration->event()->is_sold_out() |
|
330 | + || $registration->event()->is_sold_out(true) |
|
331 | + ) |
|
332 | + ) { |
|
333 | + // add event to list of events that are sold out |
|
334 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
335 | + do_action( |
|
336 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
337 | + $registration->event(), |
|
338 | + $this |
|
339 | + ); |
|
340 | + continue; |
|
341 | + } |
|
342 | + // are they allowed to pay now and is there monies owing? |
|
343 | + if ($registration->owes_monies_and_can_pay()) { |
|
344 | + $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
345 | + do_action( |
|
346 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
347 | + $registration->event(), |
|
348 | + $this |
|
349 | + ); |
|
350 | + } elseif (! $this->checkout->revisit |
|
351 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
352 | + && $registration->ticket()->is_free() |
|
353 | + ) { |
|
354 | + $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
355 | + } |
|
356 | + } |
|
357 | + $subsections = array(); |
|
358 | + // now decide which template to load |
|
359 | + if (! empty($sold_out_events)) { |
|
360 | + $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
361 | + } |
|
362 | + if (! empty($insufficient_spaces_available)) { |
|
363 | + $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
364 | + $insufficient_spaces_available |
|
365 | + ); |
|
366 | + } |
|
367 | + if (! empty($registrations_requiring_pre_approval)) { |
|
368 | + $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
369 | + $registrations_requiring_pre_approval |
|
370 | + ); |
|
371 | + } |
|
372 | + if (! empty($registrations_for_free_events)) { |
|
373 | + $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
374 | + } |
|
375 | + if (! empty($registrations_requiring_payment)) { |
|
376 | + if ($this->checkout->amount_owing > 0) { |
|
377 | + // autoload Line_Item_Display classes |
|
378 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
379 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
380 | + apply_filters( |
|
381 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
382 | + new EE_Line_Item_Filter_Collection() |
|
383 | + ), |
|
384 | + $this->checkout->cart->get_grand_total() |
|
385 | + ); |
|
386 | + /** @var EE_Line_Item $filtered_line_item_tree */ |
|
387 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
388 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
389 | + $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
390 | + $subsections['payment_options'] = $this->_display_payment_options( |
|
391 | + $this->line_item_display->display_line_item( |
|
392 | + $filtered_line_item_tree, |
|
393 | + array('registrations' => $registrations) |
|
394 | + ) |
|
395 | + ); |
|
396 | + $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
397 | + $this->_apply_registration_payments_to_amount_owing($registrations); |
|
398 | + } |
|
399 | + $no_payment_required = false; |
|
400 | + } else { |
|
401 | + $this->_hide_reg_step_submit_button_if_revisit(); |
|
402 | + } |
|
403 | + $this->_save_selected_method_of_payment(); |
|
404 | + |
|
405 | + $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
406 | + $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
407 | + |
|
408 | + return new EE_Form_Section_Proper( |
|
409 | + array( |
|
410 | + 'name' => $this->reg_form_name(), |
|
411 | + 'html_id' => $this->reg_form_name(), |
|
412 | + 'subsections' => $subsections, |
|
413 | + 'layout_strategy' => new EE_No_Layout(), |
|
414 | + ) |
|
415 | + ); |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * add line item filters required for this reg step |
|
421 | + * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
422 | + * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
423 | + * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
424 | + * payment options reg step, can apply these filters via the following: apply_filters( |
|
425 | + * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
426 | + * filter collection by passing that instead of instantiating a new collection |
|
427 | + * |
|
428 | + * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
429 | + * @return EE_Line_Item_Filter_Collection |
|
430 | + * @throws EE_Error |
|
431 | + * @throws InvalidArgumentException |
|
432 | + * @throws ReflectionException |
|
433 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
434 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
435 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
436 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
437 | + */ |
|
438 | + public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
439 | + { |
|
440 | + if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
441 | + return $line_item_filter_collection; |
|
442 | + } |
|
443 | + if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
444 | + return $line_item_filter_collection; |
|
445 | + } |
|
446 | + if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
447 | + return $line_item_filter_collection; |
|
448 | + } |
|
449 | + $line_item_filter_collection->add( |
|
450 | + new EE_Billable_Line_Item_Filter( |
|
451 | + EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
452 | + EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
453 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
454 | + ) |
|
455 | + ) |
|
456 | + ) |
|
457 | + ); |
|
458 | + $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
459 | + return $line_item_filter_collection; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * remove_ejected_registrations |
|
465 | + * if a registrant has lost their potential space at an event due to lack of payment, |
|
466 | + * then this method removes them from the list of registrations being paid for during this request |
|
467 | + * |
|
468 | + * @param \EE_Registration[] $registrations |
|
469 | + * @return EE_Registration[] |
|
470 | + * @throws EE_Error |
|
471 | + * @throws InvalidArgumentException |
|
472 | + * @throws ReflectionException |
|
473 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
474 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
475 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
476 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
477 | + */ |
|
478 | + public static function remove_ejected_registrations(array $registrations) |
|
479 | + { |
|
480 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
481 | + $registrations, |
|
482 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
483 | + ); |
|
484 | + foreach ($registrations as $REG_ID => $registration) { |
|
485 | + // has this registration lost it's space ? |
|
486 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
487 | + unset($registrations[ $REG_ID ]); |
|
488 | + continue; |
|
489 | + } |
|
490 | + } |
|
491 | + return $registrations; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * find_registrations_that_lost_their_space |
|
497 | + * If a registrant chooses an offline payment method like Invoice, |
|
498 | + * then no space is reserved for them at the event until they fully pay fo that site |
|
499 | + * (unless the event's default reg status is set to APPROVED) |
|
500 | + * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
501 | + * then this method will determine which registrations have lost the ability to complete the reg process. |
|
502 | + * |
|
503 | + * @param \EE_Registration[] $registrations |
|
504 | + * @param bool $revisit |
|
505 | + * @return array |
|
506 | + * @throws EE_Error |
|
507 | + * @throws InvalidArgumentException |
|
508 | + * @throws ReflectionException |
|
509 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
510 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
511 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
512 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
513 | + */ |
|
514 | + public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
515 | + { |
|
516 | + // registrations per event |
|
517 | + $event_reg_count = array(); |
|
518 | + // spaces left per event |
|
519 | + $event_spaces_remaining = array(); |
|
520 | + // tickets left sorted by ID |
|
521 | + $tickets_remaining = array(); |
|
522 | + // registrations that have lost their space |
|
523 | + $ejected_registrations = array(); |
|
524 | + foreach ($registrations as $REG_ID => $registration) { |
|
525 | + if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
526 | + || apply_filters( |
|
527 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
528 | + false, |
|
529 | + $registration, |
|
530 | + $revisit |
|
531 | + ) |
|
532 | + ) { |
|
533 | + continue; |
|
534 | + } |
|
535 | + $EVT_ID = $registration->event_ID(); |
|
536 | + $ticket = $registration->ticket(); |
|
537 | + if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
538 | + $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
539 | + } |
|
540 | + if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
541 | + if (! isset($event_reg_count[ $EVT_ID ])) { |
|
542 | + $event_reg_count[ $EVT_ID ] = 0; |
|
543 | + } |
|
544 | + $event_reg_count[ $EVT_ID ]++; |
|
545 | + if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
546 | + $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
547 | + } |
|
548 | + } |
|
549 | + if ($revisit |
|
550 | + && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
551 | + || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
552 | + ) |
|
553 | + ) { |
|
554 | + $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
555 | + if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
556 | + /** @type EE_Registration_Processor $registration_processor */ |
|
557 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
558 | + // at this point, we should have enough details about the registrant to consider the registration |
|
559 | + // NOT incomplete |
|
560 | + $registration_processor->manually_update_registration_status( |
|
561 | + $registration, |
|
562 | + EEM_Registration::status_id_wait_list |
|
563 | + ); |
|
564 | + } |
|
565 | + } |
|
566 | + } |
|
567 | + return $ejected_registrations; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * _hide_reg_step_submit_button |
|
573 | + * removes the html for the reg step submit button |
|
574 | + * by replacing it with an empty string via filter callback |
|
575 | + * |
|
576 | + * @return void |
|
577 | + */ |
|
578 | + protected function _adjust_registration_status_if_event_old_sold() |
|
579 | + { |
|
580 | + } |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * _hide_reg_step_submit_button |
|
585 | + * removes the html for the reg step submit button |
|
586 | + * by replacing it with an empty string via filter callback |
|
587 | + * |
|
588 | + * @return void |
|
589 | + */ |
|
590 | + protected function _hide_reg_step_submit_button_if_revisit() |
|
591 | + { |
|
592 | + if ($this->checkout->revisit) { |
|
593 | + add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
594 | + } |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + /** |
|
599 | + * sold_out_events |
|
600 | + * displays notices regarding events that have sold out since hte registrant first signed up |
|
601 | + * |
|
602 | + * @param \EE_Event[] $sold_out_events_array |
|
603 | + * @return \EE_Form_Section_Proper |
|
604 | + * @throws \EE_Error |
|
605 | + */ |
|
606 | + private function _sold_out_events($sold_out_events_array = array()) |
|
607 | + { |
|
608 | + // set some defaults |
|
609 | + $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
610 | + $sold_out_events = ''; |
|
611 | + foreach ($sold_out_events_array as $sold_out_event) { |
|
612 | + $sold_out_events .= EEH_HTML::li( |
|
613 | + EEH_HTML::span( |
|
614 | + ' ' . $sold_out_event->name(), |
|
615 | + '', |
|
616 | + 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
617 | + ) |
|
618 | + ); |
|
619 | + } |
|
620 | + return new EE_Form_Section_Proper( |
|
621 | + array( |
|
622 | + 'layout_strategy' => new EE_Template_Layout( |
|
623 | + array( |
|
624 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
625 | + . $this->_slug |
|
626 | + . DS |
|
627 | + . 'sold_out_events.template.php', |
|
628 | + 'template_args' => apply_filters( |
|
629 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
630 | + array( |
|
631 | + 'sold_out_events' => $sold_out_events, |
|
632 | + 'sold_out_events_msg' => apply_filters( |
|
633 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
634 | + sprintf( |
|
635 | + esc_html__( |
|
636 | + 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', |
|
637 | + 'event_espresso' |
|
638 | + ), |
|
639 | + '<strong>', |
|
640 | + '</strong>', |
|
641 | + '<br />' |
|
642 | + ) |
|
643 | + ), |
|
644 | + ) |
|
645 | + ), |
|
646 | + ) |
|
647 | + ), |
|
648 | + ) |
|
649 | + ); |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * _insufficient_spaces_available |
|
655 | + * displays notices regarding events that do not have enough remaining spaces |
|
656 | + * to satisfy the current number of registrations looking to pay |
|
657 | + * |
|
658 | + * @param \EE_Event[] $insufficient_spaces_events_array |
|
659 | + * @return \EE_Form_Section_Proper |
|
660 | + * @throws \EE_Error |
|
661 | + */ |
|
662 | + private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
663 | + { |
|
664 | + // set some defaults |
|
665 | + $this->checkout->selected_method_of_payment = 'invoice'; |
|
666 | + $insufficient_space_events = ''; |
|
667 | + foreach ($insufficient_spaces_events_array as $event) { |
|
668 | + if ($event instanceof EE_Event) { |
|
669 | + $insufficient_space_events .= EEH_HTML::li( |
|
670 | + EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
671 | + ); |
|
672 | + } |
|
673 | + } |
|
674 | + return new EE_Form_Section_Proper( |
|
675 | + array( |
|
676 | + 'subsections' => array( |
|
677 | + 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
678 | + 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
679 | + ), |
|
680 | + 'layout_strategy' => new EE_Template_Layout( |
|
681 | + array( |
|
682 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
683 | + . $this->_slug |
|
684 | + . DS |
|
685 | + . 'sold_out_events.template.php', |
|
686 | + 'template_args' => apply_filters( |
|
687 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
688 | + array( |
|
689 | + 'sold_out_events' => $insufficient_space_events, |
|
690 | + 'sold_out_events_msg' => apply_filters( |
|
691 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
692 | + esc_html__( |
|
693 | + 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
694 | + 'event_espresso' |
|
695 | + ) |
|
696 | + ), |
|
697 | + ) |
|
698 | + ), |
|
699 | + ) |
|
700 | + ), |
|
701 | + ) |
|
702 | + ); |
|
703 | + } |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * registrations_requiring_pre_approval |
|
708 | + * |
|
709 | + * @param array $registrations_requiring_pre_approval |
|
710 | + * @return EE_Form_Section_Proper |
|
711 | + * @throws EE_Error |
|
712 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
713 | + */ |
|
714 | + private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
715 | + { |
|
716 | + $events_requiring_pre_approval = ''; |
|
717 | + foreach ($registrations_requiring_pre_approval as $registration) { |
|
718 | + if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
719 | + $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
720 | + EEH_HTML::span( |
|
721 | + '', |
|
722 | + '', |
|
723 | + 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
724 | + ) |
|
725 | + . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
726 | + ); |
|
727 | + } |
|
728 | + } |
|
729 | + return new EE_Form_Section_Proper( |
|
730 | + array( |
|
731 | + 'layout_strategy' => new EE_Template_Layout( |
|
732 | + array( |
|
733 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
734 | + . $this->_slug |
|
735 | + . DS |
|
736 | + . 'events_requiring_pre_approval.template.php', // layout_template |
|
737 | + 'template_args' => apply_filters( |
|
738 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
739 | + array( |
|
740 | + 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
741 | + 'events_requiring_pre_approval_msg' => apply_filters( |
|
742 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
743 | + esc_html__( |
|
744 | + 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
745 | + 'event_espresso' |
|
746 | + ) |
|
747 | + ), |
|
748 | + ) |
|
749 | + ), |
|
750 | + ) |
|
751 | + ), |
|
752 | + ) |
|
753 | + ); |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * _no_payment_required |
|
759 | + * |
|
760 | + * @param \EE_Event[] $registrations_for_free_events |
|
761 | + * @return \EE_Form_Section_Proper |
|
762 | + * @throws \EE_Error |
|
763 | + */ |
|
764 | + private function _no_payment_required($registrations_for_free_events = array()) |
|
765 | + { |
|
766 | + // set some defaults |
|
767 | + $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
768 | + // generate no_payment_required form |
|
769 | + return new EE_Form_Section_Proper( |
|
770 | + array( |
|
771 | + 'layout_strategy' => new EE_Template_Layout( |
|
772 | + array( |
|
773 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
774 | + . $this->_slug |
|
775 | + . DS |
|
776 | + . 'no_payment_required.template.php', // layout_template |
|
777 | + 'template_args' => apply_filters( |
|
778 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
779 | + array( |
|
780 | + 'revisit' => $this->checkout->revisit, |
|
781 | + 'registrations' => array(), |
|
782 | + 'ticket_count' => array(), |
|
783 | + 'registrations_for_free_events' => $registrations_for_free_events, |
|
784 | + 'no_payment_required_msg' => EEH_HTML::p( |
|
785 | + esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
786 | + ), |
|
787 | + ) |
|
788 | + ), |
|
789 | + ) |
|
790 | + ), |
|
791 | + ) |
|
792 | + ); |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * _display_payment_options |
|
798 | + * |
|
799 | + * @param string $transaction_details |
|
800 | + * @return EE_Form_Section_Proper |
|
801 | + * @throws EE_Error |
|
802 | + * @throws InvalidArgumentException |
|
803 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
804 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
805 | + */ |
|
806 | + private function _display_payment_options($transaction_details = '') |
|
807 | + { |
|
808 | + // has method_of_payment been set by no-js user? |
|
809 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
810 | + // build payment options form |
|
811 | + return apply_filters( |
|
812 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
813 | + new EE_Form_Section_Proper( |
|
814 | + array( |
|
815 | + 'subsections' => array( |
|
816 | + 'before_payment_options' => apply_filters( |
|
817 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
818 | + new EE_Form_Section_Proper( |
|
819 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
820 | + ) |
|
821 | + ), |
|
822 | + 'payment_options' => $this->_setup_payment_options(), |
|
823 | + 'after_payment_options' => apply_filters( |
|
824 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
825 | + new EE_Form_Section_Proper( |
|
826 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
827 | + ) |
|
828 | + ), |
|
829 | + ), |
|
830 | + 'layout_strategy' => new EE_Template_Layout( |
|
831 | + array( |
|
832 | + 'layout_template_file' => $this->_template, |
|
833 | + 'template_args' => apply_filters( |
|
834 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
835 | + array( |
|
836 | + 'reg_count' => $this->line_item_display->total_items(), |
|
837 | + 'transaction_details' => $transaction_details, |
|
838 | + 'available_payment_methods' => array(), |
|
839 | + ) |
|
840 | + ), |
|
841 | + ) |
|
842 | + ), |
|
843 | + ) |
|
844 | + ) |
|
845 | + ); |
|
846 | + } |
|
847 | + |
|
848 | + |
|
849 | + /** |
|
850 | + * _extra_hidden_inputs |
|
851 | + * |
|
852 | + * @param bool $no_payment_required |
|
853 | + * @return \EE_Form_Section_Proper |
|
854 | + * @throws \EE_Error |
|
855 | + */ |
|
856 | + private function _extra_hidden_inputs($no_payment_required = true) |
|
857 | + { |
|
858 | + return new EE_Form_Section_Proper( |
|
859 | + array( |
|
860 | + 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
861 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
862 | + 'subsections' => array( |
|
863 | + 'spco_no_payment_required' => new EE_Hidden_Input( |
|
864 | + array( |
|
865 | + 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
866 | + 'html_name' => 'spco_no_payment_required', |
|
867 | + 'html_id' => 'spco-no-payment-required-payment_options', |
|
868 | + 'default' => $no_payment_required, |
|
869 | + ) |
|
870 | + ), |
|
871 | + 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
872 | + array( |
|
873 | + 'normalization_strategy' => new EE_Int_Normalization(), |
|
874 | + 'html_name' => 'spco_transaction_id', |
|
875 | + 'html_id' => 'spco-transaction-id', |
|
876 | + 'default' => $this->checkout->transaction->ID(), |
|
877 | + ) |
|
878 | + ), |
|
879 | + ), |
|
880 | + ) |
|
881 | + ); |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + /** |
|
886 | + * _apply_registration_payments_to_amount_owing |
|
887 | + * |
|
888 | + * @access protected |
|
889 | + * @param array $registrations |
|
890 | + * @throws EE_Error |
|
891 | + */ |
|
892 | + protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
893 | + { |
|
894 | + $payments = array(); |
|
895 | + foreach ($registrations as $registration) { |
|
896 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
897 | + $payments += $registration->registration_payments(); |
|
898 | + } |
|
899 | + } |
|
900 | + if (! empty($payments)) { |
|
901 | + foreach ($payments as $payment) { |
|
902 | + if ($payment instanceof EE_Registration_Payment) { |
|
903 | + $this->checkout->amount_owing -= $payment->amount(); |
|
904 | + } |
|
905 | + } |
|
906 | + } |
|
907 | + } |
|
908 | + |
|
909 | + |
|
910 | + /** |
|
911 | + * _reset_selected_method_of_payment |
|
912 | + * |
|
913 | + * @access private |
|
914 | + * @param bool $force_reset |
|
915 | + * @return void |
|
916 | + * @throws InvalidArgumentException |
|
917 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
918 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
919 | + */ |
|
920 | + private function _reset_selected_method_of_payment($force_reset = false) |
|
921 | + { |
|
922 | + $reset_payment_method = $force_reset |
|
923 | + ? true |
|
924 | + : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
925 | + if ($reset_payment_method) { |
|
926 | + $this->checkout->selected_method_of_payment = null; |
|
927 | + $this->checkout->payment_method = null; |
|
928 | + $this->checkout->billing_form = null; |
|
929 | + $this->_save_selected_method_of_payment(); |
|
930 | + } |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + /** |
|
935 | + * _save_selected_method_of_payment |
|
936 | + * stores the selected_method_of_payment in the session |
|
937 | + * so that it's available for all subsequent requests including AJAX |
|
938 | + * |
|
939 | + * @access private |
|
940 | + * @param string $selected_method_of_payment |
|
941 | + * @return void |
|
942 | + * @throws InvalidArgumentException |
|
943 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
944 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
945 | + */ |
|
946 | + private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
947 | + { |
|
948 | + $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
949 | + ? $selected_method_of_payment |
|
950 | + : $this->checkout->selected_method_of_payment; |
|
951 | + EE_Registry::instance()->SSN->set_session_data( |
|
952 | + array('selected_method_of_payment' => $selected_method_of_payment) |
|
953 | + ); |
|
954 | + } |
|
955 | + |
|
956 | + |
|
957 | + /** |
|
958 | + * _setup_payment_options |
|
959 | + * |
|
960 | + * @return EE_Form_Section_Proper |
|
961 | + * @throws EE_Error |
|
962 | + * @throws InvalidArgumentException |
|
963 | + * @throws ReflectionException |
|
964 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
965 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
966 | + */ |
|
967 | + public function _setup_payment_options() |
|
968 | + { |
|
969 | + // load payment method classes |
|
970 | + $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
971 | + if (empty($this->checkout->available_payment_methods)) { |
|
972 | + EE_Error::add_error( |
|
973 | + apply_filters( |
|
974 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
975 | + sprintf( |
|
976 | + esc_html__( |
|
977 | + 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
978 | + 'event_espresso' |
|
979 | + ), |
|
980 | + '<br>', |
|
981 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
982 | + ) |
|
983 | + ), |
|
984 | + __FILE__, |
|
985 | + __FUNCTION__, |
|
986 | + __LINE__ |
|
987 | + ); |
|
988 | + } |
|
989 | + // switch up header depending on number of available payment methods |
|
990 | + $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
991 | + ? apply_filters( |
|
992 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
993 | + esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
994 | + ) |
|
995 | + : apply_filters( |
|
996 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
997 | + esc_html__('Method of Payment', 'event_espresso') |
|
998 | + ); |
|
999 | + $available_payment_methods = array( |
|
1000 | + // display the "Payment Method" header |
|
1001 | + 'payment_method_header' => new EE_Form_Section_HTML( |
|
1002 | + apply_filters( |
|
1003 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header', |
|
1004 | + EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'), |
|
1005 | + $payment_method_header |
|
1006 | + ) |
|
1007 | + ), |
|
1008 | + ); |
|
1009 | + // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
1010 | + $available_payment_method_options = array(); |
|
1011 | + $default_payment_method_option = array(); |
|
1012 | + // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
1013 | + $payment_methods_billing_info = array( |
|
1014 | + new EE_Form_Section_HTML( |
|
1015 | + EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
1016 | + ), |
|
1017 | + ); |
|
1018 | + // loop through payment methods |
|
1019 | + foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
1020 | + if ($payment_method instanceof EE_Payment_Method) { |
|
1021 | + $payment_method_button = EEH_HTML::img( |
|
1022 | + $payment_method->button_url(), |
|
1023 | + $payment_method->name(), |
|
1024 | + 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
1025 | + 'spco-payment-method-btn-img' |
|
1026 | + ); |
|
1027 | + // check if any payment methods are set as default |
|
1028 | + // if payment method is already selected OR nothing is selected and this payment method should be |
|
1029 | + // open_by_default |
|
1030 | + if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
1031 | + || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1032 | + ) { |
|
1033 | + $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
1034 | + $this->_save_selected_method_of_payment(); |
|
1035 | + $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
1036 | + } else { |
|
1037 | + $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
1038 | + } |
|
1039 | + $payment_methods_billing_info[ $payment_method->slug( |
|
1040 | + ) . '-info' ] = $this->_payment_method_billing_info( |
|
1041 | + $payment_method |
|
1042 | + ); |
|
1043 | + } |
|
1044 | + } |
|
1045 | + // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
1046 | + // of PMs |
|
1047 | + $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
1048 | + // now generate the actual form inputs |
|
1049 | + $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
1050 | + $available_payment_method_options |
|
1051 | + ); |
|
1052 | + $available_payment_methods += $payment_methods_billing_info; |
|
1053 | + // build the available payment methods form |
|
1054 | + return new EE_Form_Section_Proper( |
|
1055 | + array( |
|
1056 | + 'html_id' => 'spco-available-methods-of-payment-dv', |
|
1057 | + 'subsections' => $available_payment_methods, |
|
1058 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1059 | + ) |
|
1060 | + ); |
|
1061 | + } |
|
1062 | + |
|
1063 | + |
|
1064 | + /** |
|
1065 | + * _get_available_payment_methods |
|
1066 | + * |
|
1067 | + * @return EE_Payment_Method[] |
|
1068 | + * @throws EE_Error |
|
1069 | + * @throws InvalidArgumentException |
|
1070 | + * @throws ReflectionException |
|
1071 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1072 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1073 | + */ |
|
1074 | + protected function _get_available_payment_methods() |
|
1075 | + { |
|
1076 | + if (! empty($this->checkout->available_payment_methods)) { |
|
1077 | + return $this->checkout->available_payment_methods; |
|
1078 | + } |
|
1079 | + $available_payment_methods = array(); |
|
1080 | + // load EEM_Payment_Method |
|
1081 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
1082 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
1083 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
1084 | + // get all active payment methods |
|
1085 | + $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
1086 | + $this->checkout->transaction, |
|
1087 | + EEM_Payment_Method::scope_cart |
|
1088 | + ); |
|
1089 | + foreach ($payment_methods as $payment_method) { |
|
1090 | + if ($payment_method instanceof EE_Payment_Method) { |
|
1091 | + $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1092 | + } |
|
1093 | + } |
|
1094 | + return $available_payment_methods; |
|
1095 | + } |
|
1096 | + |
|
1097 | + |
|
1098 | + /** |
|
1099 | + * _available_payment_method_inputs |
|
1100 | + * |
|
1101 | + * @access private |
|
1102 | + * @param array $available_payment_method_options |
|
1103 | + * @return \EE_Form_Section_Proper |
|
1104 | + */ |
|
1105 | + private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
1106 | + { |
|
1107 | + // generate inputs |
|
1108 | + return new EE_Form_Section_Proper( |
|
1109 | + array( |
|
1110 | + 'html_id' => 'ee-available-payment-method-inputs', |
|
1111 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1112 | + 'subsections' => array( |
|
1113 | + '' => new EE_Radio_Button_Input( |
|
1114 | + $available_payment_method_options, |
|
1115 | + array( |
|
1116 | + 'html_name' => 'selected_method_of_payment', |
|
1117 | + 'html_class' => 'spco-payment-method', |
|
1118 | + 'default' => $this->checkout->selected_method_of_payment, |
|
1119 | + 'label_size' => 11, |
|
1120 | + 'enforce_label_size' => true, |
|
1121 | + ) |
|
1122 | + ), |
|
1123 | + ), |
|
1124 | + ) |
|
1125 | + ); |
|
1126 | + } |
|
1127 | + |
|
1128 | + |
|
1129 | + /** |
|
1130 | + * _payment_method_billing_info |
|
1131 | + * |
|
1132 | + * @access private |
|
1133 | + * @param EE_Payment_Method $payment_method |
|
1134 | + * @return EE_Form_Section_Proper |
|
1135 | + * @throws EE_Error |
|
1136 | + * @throws InvalidArgumentException |
|
1137 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1138 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1139 | + */ |
|
1140 | + private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
1141 | + { |
|
1142 | + $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
1143 | + ? true |
|
1144 | + : false; |
|
1145 | + // generate the billing form for payment method |
|
1146 | + $billing_form = $currently_selected |
|
1147 | + ? $this->_get_billing_form_for_payment_method($payment_method) |
|
1148 | + : new EE_Form_Section_HTML(); |
|
1149 | + $this->checkout->billing_form = $currently_selected |
|
1150 | + ? $billing_form |
|
1151 | + : $this->checkout->billing_form; |
|
1152 | + // it's all in the details |
|
1153 | + $info_html = EEH_HTML::h3( |
|
1154 | + esc_html__('Important information regarding your payment', 'event_espresso'), |
|
1155 | + '', |
|
1156 | + 'spco-payment-method-hdr' |
|
1157 | + ); |
|
1158 | + // add some info regarding the step, either from what's saved in the admin, |
|
1159 | + // or a default string depending on whether the PM has a billing form or not |
|
1160 | + if ($payment_method->description()) { |
|
1161 | + $payment_method_info = $payment_method->description(); |
|
1162 | + } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
1163 | + $payment_method_info = sprintf( |
|
1164 | + esc_html__( |
|
1165 | + 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
1166 | + 'event_espresso' |
|
1167 | + ), |
|
1168 | + $this->submit_button_text() |
|
1169 | + ); |
|
1170 | + } else { |
|
1171 | + $payment_method_info = sprintf( |
|
1172 | + esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
1173 | + $this->submit_button_text() |
|
1174 | + ); |
|
1175 | + } |
|
1176 | + $info_html .= EEH_HTML::div( |
|
1177 | + apply_filters( |
|
1178 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
1179 | + $payment_method_info |
|
1180 | + ), |
|
1181 | + '', |
|
1182 | + 'spco-payment-method-desc ee-attention' |
|
1183 | + ); |
|
1184 | + return new EE_Form_Section_Proper( |
|
1185 | + array( |
|
1186 | + 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1187 | + 'html_class' => 'spco-payment-method-info-dv', |
|
1188 | + // only display the selected or default PM |
|
1189 | + 'html_style' => $currently_selected ? '' : 'display:none;', |
|
1190 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1191 | + 'subsections' => array( |
|
1192 | + 'info' => new EE_Form_Section_HTML($info_html), |
|
1193 | + 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
1194 | + ), |
|
1195 | + ) |
|
1196 | + ); |
|
1197 | + } |
|
1198 | + |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * get_billing_form_html_for_payment_method |
|
1202 | + * |
|
1203 | + * @access public |
|
1204 | + * @return string |
|
1205 | + * @throws EE_Error |
|
1206 | + * @throws InvalidArgumentException |
|
1207 | + * @throws ReflectionException |
|
1208 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1209 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1210 | + */ |
|
1211 | + public function get_billing_form_html_for_payment_method() |
|
1212 | + { |
|
1213 | + // how have they chosen to pay? |
|
1214 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1215 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1216 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1217 | + return false; |
|
1218 | + } |
|
1219 | + if (apply_filters( |
|
1220 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1221 | + false |
|
1222 | + )) { |
|
1223 | + EE_Error::add_success( |
|
1224 | + apply_filters( |
|
1225 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1226 | + sprintf( |
|
1227 | + esc_html__( |
|
1228 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1229 | + 'event_espresso' |
|
1230 | + ), |
|
1231 | + $this->checkout->payment_method->name() |
|
1232 | + ) |
|
1233 | + ) |
|
1234 | + ); |
|
1235 | + } |
|
1236 | + // now generate billing form for selected method of payment |
|
1237 | + $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
1238 | + // fill form with attendee info if applicable |
|
1239 | + if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1240 | + && $this->checkout->transaction_has_primary_registrant() |
|
1241 | + ) { |
|
1242 | + $payment_method_billing_form->populate_from_attendee( |
|
1243 | + $this->checkout->transaction->primary_registration()->attendee() |
|
1244 | + ); |
|
1245 | + } |
|
1246 | + // and debug content |
|
1247 | + if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
1248 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1249 | + ) { |
|
1250 | + $payment_method_billing_form = |
|
1251 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1252 | + $payment_method_billing_form |
|
1253 | + ); |
|
1254 | + } |
|
1255 | + $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
1256 | + ? $payment_method_billing_form->get_html() |
|
1257 | + : ''; |
|
1258 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
1259 | + // localize validation rules for main form |
|
1260 | + $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
1261 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1262 | + return true; |
|
1263 | + } |
|
1264 | + |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * _get_billing_form_for_payment_method |
|
1268 | + * |
|
1269 | + * @access private |
|
1270 | + * @param EE_Payment_Method $payment_method |
|
1271 | + * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
1272 | + * @throws EE_Error |
|
1273 | + * @throws InvalidArgumentException |
|
1274 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1275 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1276 | + */ |
|
1277 | + private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
1278 | + { |
|
1279 | + $billing_form = $payment_method->type_obj()->billing_form( |
|
1280 | + $this->checkout->transaction, |
|
1281 | + array('amount_owing' => $this->checkout->amount_owing) |
|
1282 | + ); |
|
1283 | + if ($billing_form instanceof EE_Billing_Info_Form) { |
|
1284 | + if (apply_filters( |
|
1285 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1286 | + false |
|
1287 | + ) |
|
1288 | + && EE_Registry::instance()->REQ->is_set('payment_method') |
|
1289 | + ) { |
|
1290 | + EE_Error::add_success( |
|
1291 | + apply_filters( |
|
1292 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1293 | + sprintf( |
|
1294 | + esc_html__( |
|
1295 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1296 | + 'event_espresso' |
|
1297 | + ), |
|
1298 | + $payment_method->name() |
|
1299 | + ) |
|
1300 | + ) |
|
1301 | + ); |
|
1302 | + } |
|
1303 | + return apply_filters( |
|
1304 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
1305 | + $billing_form, |
|
1306 | + $payment_method |
|
1307 | + ); |
|
1308 | + } |
|
1309 | + // no actual billing form, so return empty HTML form section |
|
1310 | + return new EE_Form_Section_HTML(); |
|
1311 | + } |
|
1312 | + |
|
1313 | + |
|
1314 | + /** |
|
1315 | + * _get_selected_method_of_payment |
|
1316 | + * |
|
1317 | + * @access private |
|
1318 | + * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
1319 | + * is not found in the incoming request |
|
1320 | + * @param string $request_param |
|
1321 | + * @return NULL|string |
|
1322 | + * @throws EE_Error |
|
1323 | + * @throws InvalidArgumentException |
|
1324 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1325 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1326 | + */ |
|
1327 | + private function _get_selected_method_of_payment( |
|
1328 | + $required = false, |
|
1329 | + $request_param = 'selected_method_of_payment' |
|
1330 | + ) { |
|
1331 | + // is selected_method_of_payment set in the request ? |
|
1332 | + $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
1333 | + if ($selected_method_of_payment) { |
|
1334 | + // sanitize it |
|
1335 | + $selected_method_of_payment = is_array($selected_method_of_payment) |
|
1336 | + ? array_shift($selected_method_of_payment) |
|
1337 | + : $selected_method_of_payment; |
|
1338 | + $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
1339 | + // store it in the session so that it's available for all subsequent requests including AJAX |
|
1340 | + $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
1341 | + } else { |
|
1342 | + // or is is set in the session ? |
|
1343 | + $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
1344 | + 'selected_method_of_payment' |
|
1345 | + ); |
|
1346 | + } |
|
1347 | + // do ya really really gotta have it? |
|
1348 | + if (empty($selected_method_of_payment) && $required) { |
|
1349 | + EE_Error::add_error( |
|
1350 | + sprintf( |
|
1351 | + esc_html__( |
|
1352 | + 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
1353 | + 'event_espresso' |
|
1354 | + ), |
|
1355 | + '<br/>', |
|
1356 | + '<br/>', |
|
1357 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1358 | + ), |
|
1359 | + __FILE__, |
|
1360 | + __FUNCTION__, |
|
1361 | + __LINE__ |
|
1362 | + ); |
|
1363 | + return null; |
|
1364 | + } |
|
1365 | + return $selected_method_of_payment; |
|
1366 | + } |
|
1367 | + |
|
1368 | + |
|
1369 | + |
|
1370 | + |
|
1371 | + |
|
1372 | + |
|
1373 | + /********************************************************************************************************/ |
|
1374 | + /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
1375 | + /********************************************************************************************************/ |
|
1376 | + /** |
|
1377 | + * switch_payment_method |
|
1378 | + * |
|
1379 | + * @access public |
|
1380 | + * @return string |
|
1381 | + * @throws EE_Error |
|
1382 | + * @throws InvalidArgumentException |
|
1383 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1384 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1385 | + */ |
|
1386 | + public function switch_payment_method() |
|
1387 | + { |
|
1388 | + if (! $this->_verify_payment_method_is_set()) { |
|
1389 | + return false; |
|
1390 | + } |
|
1391 | + if (apply_filters( |
|
1392 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1393 | + false |
|
1394 | + )) { |
|
1395 | + EE_Error::add_success( |
|
1396 | + apply_filters( |
|
1397 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1398 | + sprintf( |
|
1399 | + esc_html__( |
|
1400 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1401 | + 'event_espresso' |
|
1402 | + ), |
|
1403 | + $this->checkout->payment_method->name() |
|
1404 | + ) |
|
1405 | + ) |
|
1406 | + ); |
|
1407 | + } |
|
1408 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1409 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1410 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1411 | + $this->checkout->payment_method |
|
1412 | + ); |
|
1413 | + } |
|
1414 | + // fill form with attendee info if applicable |
|
1415 | + if (apply_filters( |
|
1416 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
1417 | + ( |
|
1418 | + $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1419 | + && $this->checkout->transaction_has_primary_registrant() |
|
1420 | + ), |
|
1421 | + $this->checkout->billing_form, |
|
1422 | + $this->checkout->transaction |
|
1423 | + ) |
|
1424 | + ) { |
|
1425 | + $this->checkout->billing_form->populate_from_attendee( |
|
1426 | + $this->checkout->transaction->primary_registration()->attendee() |
|
1427 | + ); |
|
1428 | + } |
|
1429 | + // and debug content |
|
1430 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1431 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1432 | + ) { |
|
1433 | + $this->checkout->billing_form = |
|
1434 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1435 | + $this->checkout->billing_form |
|
1436 | + ); |
|
1437 | + } |
|
1438 | + // get html and validation rules for form |
|
1439 | + if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
1440 | + $this->checkout->json_response->set_return_data( |
|
1441 | + array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
1442 | + ); |
|
1443 | + // localize validation rules for main form |
|
1444 | + $this->checkout->billing_form->localize_validation_rules(true); |
|
1445 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1446 | + } else { |
|
1447 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
1448 | + } |
|
1449 | + // prevents advancement to next step |
|
1450 | + $this->checkout->continue_reg = false; |
|
1451 | + return true; |
|
1452 | + } |
|
1453 | + |
|
1454 | + |
|
1455 | + /** |
|
1456 | + * _verify_payment_method_is_set |
|
1457 | + * |
|
1458 | + * @return bool |
|
1459 | + * @throws EE_Error |
|
1460 | + * @throws InvalidArgumentException |
|
1461 | + * @throws ReflectionException |
|
1462 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1463 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1464 | + */ |
|
1465 | + protected function _verify_payment_method_is_set() |
|
1466 | + { |
|
1467 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1468 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
1469 | + // how have they chosen to pay? |
|
1470 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1471 | + } else { |
|
1472 | + // choose your own adventure based on method_of_payment |
|
1473 | + switch ($this->checkout->selected_method_of_payment) { |
|
1474 | + case 'events_sold_out': |
|
1475 | + EE_Error::add_attention( |
|
1476 | + apply_filters( |
|
1477 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
1478 | + esc_html__( |
|
1479 | + 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
1480 | + 'event_espresso' |
|
1481 | + ) |
|
1482 | + ), |
|
1483 | + __FILE__, |
|
1484 | + __FUNCTION__, |
|
1485 | + __LINE__ |
|
1486 | + ); |
|
1487 | + return false; |
|
1488 | + break; |
|
1489 | + case 'payments_closed': |
|
1490 | + EE_Error::add_attention( |
|
1491 | + apply_filters( |
|
1492 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
1493 | + esc_html__( |
|
1494 | + 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
1495 | + 'event_espresso' |
|
1496 | + ) |
|
1497 | + ), |
|
1498 | + __FILE__, |
|
1499 | + __FUNCTION__, |
|
1500 | + __LINE__ |
|
1501 | + ); |
|
1502 | + return false; |
|
1503 | + break; |
|
1504 | + case 'no_payment_required': |
|
1505 | + EE_Error::add_attention( |
|
1506 | + apply_filters( |
|
1507 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
1508 | + esc_html__( |
|
1509 | + 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
1510 | + 'event_espresso' |
|
1511 | + ) |
|
1512 | + ), |
|
1513 | + __FILE__, |
|
1514 | + __FUNCTION__, |
|
1515 | + __LINE__ |
|
1516 | + ); |
|
1517 | + return false; |
|
1518 | + break; |
|
1519 | + default: |
|
1520 | + } |
|
1521 | + } |
|
1522 | + // verify payment method |
|
1523 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1524 | + // get payment method for selected method of payment |
|
1525 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1526 | + } |
|
1527 | + return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
1528 | + } |
|
1529 | + |
|
1530 | + |
|
1531 | + |
|
1532 | + /********************************************************************************************************/ |
|
1533 | + /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
1534 | + /********************************************************************************************************/ |
|
1535 | + /** |
|
1536 | + * save_payer_details_via_ajax |
|
1537 | + * |
|
1538 | + * @return void |
|
1539 | + * @throws EE_Error |
|
1540 | + * @throws InvalidArgumentException |
|
1541 | + * @throws ReflectionException |
|
1542 | + * @throws RuntimeException |
|
1543 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1544 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1545 | + */ |
|
1546 | + public function save_payer_details_via_ajax() |
|
1547 | + { |
|
1548 | + if (! $this->_verify_payment_method_is_set()) { |
|
1549 | + return; |
|
1550 | + } |
|
1551 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1552 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1553 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1554 | + $this->checkout->payment_method |
|
1555 | + ); |
|
1556 | + } |
|
1557 | + // generate primary attendee from payer info if applicable |
|
1558 | + if (! $this->checkout->transaction_has_primary_registrant()) { |
|
1559 | + $attendee = $this->_create_attendee_from_request_data(); |
|
1560 | + if ($attendee instanceof EE_Attendee) { |
|
1561 | + foreach ($this->checkout->transaction->registrations() as $registration) { |
|
1562 | + if ($registration->is_primary_registrant()) { |
|
1563 | + $this->checkout->primary_attendee_obj = $attendee; |
|
1564 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1565 | + $registration->set_attendee_id($attendee->ID()); |
|
1566 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1567 | + } |
|
1568 | + } |
|
1569 | + } |
|
1570 | + } |
|
1571 | + } |
|
1572 | + |
|
1573 | + |
|
1574 | + /** |
|
1575 | + * create_attendee_from_request_data |
|
1576 | + * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
1577 | + * |
|
1578 | + * @return EE_Attendee |
|
1579 | + * @throws EE_Error |
|
1580 | + * @throws InvalidArgumentException |
|
1581 | + * @throws ReflectionException |
|
1582 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1583 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1584 | + */ |
|
1585 | + protected function _create_attendee_from_request_data() |
|
1586 | + { |
|
1587 | + // get State ID |
|
1588 | + $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
1589 | + if (! empty($STA_ID)) { |
|
1590 | + // can we get state object from name ? |
|
1591 | + EE_Registry::instance()->load_model('State'); |
|
1592 | + $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
1593 | + $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
1594 | + } |
|
1595 | + // get Country ISO |
|
1596 | + $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
1597 | + if (! empty($CNT_ISO)) { |
|
1598 | + // can we get country object from name ? |
|
1599 | + EE_Registry::instance()->load_model('Country'); |
|
1600 | + $country = EEM_Country::instance()->get_col( |
|
1601 | + array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
1602 | + 'CNT_ISO' |
|
1603 | + ); |
|
1604 | + $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
1605 | + } |
|
1606 | + // grab attendee data |
|
1607 | + $attendee_data = array( |
|
1608 | + 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
1609 | + 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
1610 | + 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
1611 | + 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
1612 | + 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
1613 | + 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
1614 | + 'STA_ID' => $STA_ID, |
|
1615 | + 'CNT_ISO' => $CNT_ISO, |
|
1616 | + 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
1617 | + 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
1618 | + ); |
|
1619 | + // validate the email address since it is the most important piece of info |
|
1620 | + if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
1621 | + EE_Error::add_error( |
|
1622 | + esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
1623 | + __FILE__, |
|
1624 | + __FUNCTION__, |
|
1625 | + __LINE__ |
|
1626 | + ); |
|
1627 | + } |
|
1628 | + // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
1629 | + // AND email address |
|
1630 | + if (! empty($attendee_data['ATT_fname']) |
|
1631 | + && ! empty($attendee_data['ATT_lname']) |
|
1632 | + && ! empty($attendee_data['ATT_email']) |
|
1633 | + ) { |
|
1634 | + $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
1635 | + array( |
|
1636 | + 'ATT_fname' => $attendee_data['ATT_fname'], |
|
1637 | + 'ATT_lname' => $attendee_data['ATT_lname'], |
|
1638 | + 'ATT_email' => $attendee_data['ATT_email'], |
|
1639 | + ) |
|
1640 | + ); |
|
1641 | + if ($existing_attendee instanceof EE_Attendee) { |
|
1642 | + return $existing_attendee; |
|
1643 | + } |
|
1644 | + } |
|
1645 | + // no existing attendee? kk let's create a new one |
|
1646 | + // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
1647 | + // don't exist |
|
1648 | + $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
1649 | + ? $attendee_data['ATT_fname'] |
|
1650 | + : $attendee_data['ATT_email']; |
|
1651 | + $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
1652 | + ? $attendee_data['ATT_lname'] |
|
1653 | + : $attendee_data['ATT_email']; |
|
1654 | + return EE_Attendee::new_instance($attendee_data); |
|
1655 | + } |
|
1656 | + |
|
1657 | + |
|
1658 | + |
|
1659 | + /********************************************************************************************************/ |
|
1660 | + /**************************************** PROCESS REG STEP *****************************************/ |
|
1661 | + /********************************************************************************************************/ |
|
1662 | + /** |
|
1663 | + * process_reg_step |
|
1664 | + * |
|
1665 | + * @return bool |
|
1666 | + * @throws EE_Error |
|
1667 | + * @throws InvalidArgumentException |
|
1668 | + * @throws ReflectionException |
|
1669 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1670 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1671 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1672 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1673 | + */ |
|
1674 | + public function process_reg_step() |
|
1675 | + { |
|
1676 | + // how have they chosen to pay? |
|
1677 | + $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
1678 | + ? 'no_payment_required' |
|
1679 | + : $this->_get_selected_method_of_payment(true); |
|
1680 | + // choose your own adventure based on method_of_payment |
|
1681 | + switch ($this->checkout->selected_method_of_payment) { |
|
1682 | + case 'events_sold_out': |
|
1683 | + $this->checkout->redirect = true; |
|
1684 | + $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
1685 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1686 | + // mark this reg step as completed |
|
1687 | + $this->set_completed(); |
|
1688 | + return false; |
|
1689 | + break; |
|
1690 | + |
|
1691 | + case 'payments_closed': |
|
1692 | + if (apply_filters( |
|
1693 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
1694 | + false |
|
1695 | + )) { |
|
1696 | + EE_Error::add_success( |
|
1697 | + esc_html__('no payment required at this time.', 'event_espresso'), |
|
1698 | + __FILE__, |
|
1699 | + __FUNCTION__, |
|
1700 | + __LINE__ |
|
1701 | + ); |
|
1702 | + } |
|
1703 | + // mark this reg step as completed |
|
1704 | + $this->set_completed(); |
|
1705 | + return true; |
|
1706 | + break; |
|
1707 | + |
|
1708 | + case 'no_payment_required': |
|
1709 | + if (apply_filters( |
|
1710 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
1711 | + false |
|
1712 | + )) { |
|
1713 | + EE_Error::add_success( |
|
1714 | + esc_html__('no payment required.', 'event_espresso'), |
|
1715 | + __FILE__, |
|
1716 | + __FUNCTION__, |
|
1717 | + __LINE__ |
|
1718 | + ); |
|
1719 | + } |
|
1720 | + // mark this reg step as completed |
|
1721 | + $this->set_completed(); |
|
1722 | + return true; |
|
1723 | + break; |
|
1724 | + |
|
1725 | + default: |
|
1726 | + $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
1727 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
1728 | + ); |
|
1729 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
1730 | + $registrations, |
|
1731 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
1732 | + ); |
|
1733 | + // calculate difference between the two arrays |
|
1734 | + $registrations = array_diff($registrations, $ejected_registrations); |
|
1735 | + if (empty($registrations)) { |
|
1736 | + $this->_redirect_because_event_sold_out(); |
|
1737 | + return false; |
|
1738 | + } |
|
1739 | + $payment_successful = $this->_process_payment(); |
|
1740 | + if ($payment_successful) { |
|
1741 | + $this->checkout->continue_reg = true; |
|
1742 | + $this->_maybe_set_completed($this->checkout->payment_method); |
|
1743 | + } else { |
|
1744 | + $this->checkout->continue_reg = false; |
|
1745 | + } |
|
1746 | + return $payment_successful; |
|
1747 | + } |
|
1748 | + } |
|
1749 | + |
|
1750 | + |
|
1751 | + /** |
|
1752 | + * _redirect_because_event_sold_out |
|
1753 | + * |
|
1754 | + * @access protected |
|
1755 | + * @return void |
|
1756 | + */ |
|
1757 | + protected function _redirect_because_event_sold_out() |
|
1758 | + { |
|
1759 | + $this->checkout->continue_reg = false; |
|
1760 | + // set redirect URL |
|
1761 | + $this->checkout->redirect_url = add_query_arg( |
|
1762 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1763 | + $this->checkout->current_step->reg_step_url() |
|
1764 | + ); |
|
1765 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1766 | + } |
|
1767 | + |
|
1768 | + |
|
1769 | + /** |
|
1770 | + * _maybe_set_completed |
|
1771 | + * |
|
1772 | + * @access protected |
|
1773 | + * @param \EE_Payment_Method $payment_method |
|
1774 | + * @return void |
|
1775 | + * @throws \EE_Error |
|
1776 | + */ |
|
1777 | + protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
1778 | + { |
|
1779 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
1780 | + case EE_PMT_Base::offsite: |
|
1781 | + break; |
|
1782 | + case EE_PMT_Base::onsite: |
|
1783 | + case EE_PMT_Base::offline: |
|
1784 | + // mark this reg step as completed |
|
1785 | + $this->set_completed(); |
|
1786 | + break; |
|
1787 | + } |
|
1788 | + } |
|
1789 | + |
|
1790 | + |
|
1791 | + /** |
|
1792 | + * update_reg_step |
|
1793 | + * this is the final step after a user revisits the site to retry a payment |
|
1794 | + * |
|
1795 | + * @return bool |
|
1796 | + * @throws EE_Error |
|
1797 | + * @throws InvalidArgumentException |
|
1798 | + * @throws ReflectionException |
|
1799 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1800 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1801 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1802 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1803 | + */ |
|
1804 | + public function update_reg_step() |
|
1805 | + { |
|
1806 | + $success = true; |
|
1807 | + // if payment required |
|
1808 | + if ($this->checkout->transaction->total() > 0) { |
|
1809 | + do_action( |
|
1810 | + 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
1811 | + $this->checkout->transaction |
|
1812 | + ); |
|
1813 | + // attempt payment via payment method |
|
1814 | + $success = $this->process_reg_step(); |
|
1815 | + } |
|
1816 | + if ($success && ! $this->checkout->redirect) { |
|
1817 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
1818 | + $this->checkout->transaction->ID() |
|
1819 | + ); |
|
1820 | + // set return URL |
|
1821 | + $this->checkout->redirect_url = add_query_arg( |
|
1822 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1823 | + $this->checkout->thank_you_page_url |
|
1824 | + ); |
|
1825 | + } |
|
1826 | + return $success; |
|
1827 | + } |
|
1828 | + |
|
1829 | + |
|
1830 | + /** |
|
1831 | + * _process_payment |
|
1832 | + * |
|
1833 | + * @access private |
|
1834 | + * @return bool |
|
1835 | + * @throws EE_Error |
|
1836 | + * @throws InvalidArgumentException |
|
1837 | + * @throws ReflectionException |
|
1838 | + * @throws RuntimeException |
|
1839 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1840 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1841 | + */ |
|
1842 | + private function _process_payment() |
|
1843 | + { |
|
1844 | + // basically confirm that the event hasn't sold out since they hit the page |
|
1845 | + if (! $this->_last_second_ticket_verifications()) { |
|
1846 | + return false; |
|
1847 | + } |
|
1848 | + // ya gotta make a choice man |
|
1849 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
1850 | + $this->checkout->json_response->set_plz_select_method_of_payment( |
|
1851 | + esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
1852 | + ); |
|
1853 | + return false; |
|
1854 | + } |
|
1855 | + // get EE_Payment_Method object |
|
1856 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1857 | + return false; |
|
1858 | + } |
|
1859 | + // setup billing form |
|
1860 | + if ($this->checkout->payment_method->is_on_site()) { |
|
1861 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1862 | + $this->checkout->payment_method |
|
1863 | + ); |
|
1864 | + // bad billing form ? |
|
1865 | + if (! $this->_billing_form_is_valid()) { |
|
1866 | + return false; |
|
1867 | + } |
|
1868 | + } |
|
1869 | + // ensure primary registrant has been fully processed |
|
1870 | + if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1871 | + return false; |
|
1872 | + } |
|
1873 | + // if session is close to expiring (under 10 minutes by default) |
|
1874 | + if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
1875 | + // add some time to session expiration so that payment can be completed |
|
1876 | + EE_Registry::instance()->SSN->extend_expiration(); |
|
1877 | + } |
|
1878 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
1879 | + // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
1880 | + // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
1881 | + // for events with a default reg status of Approved |
|
1882 | + // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
1883 | + // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
1884 | + // ); |
|
1885 | + // attempt payment |
|
1886 | + $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
1887 | + // process results |
|
1888 | + $payment = $this->_validate_payment($payment); |
|
1889 | + $payment = $this->_post_payment_processing($payment); |
|
1890 | + // verify payment |
|
1891 | + if ($payment instanceof EE_Payment) { |
|
1892 | + // store that for later |
|
1893 | + $this->checkout->payment = $payment; |
|
1894 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
1895 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1896 | + $payment_status = $payment->status(); |
|
1897 | + if ($payment_status === EEM_Payment::status_id_approved |
|
1898 | + || $payment_status === EEM_Payment::status_id_pending |
|
1899 | + ) { |
|
1900 | + return true; |
|
1901 | + } else { |
|
1902 | + return false; |
|
1903 | + } |
|
1904 | + } elseif ($payment === true) { |
|
1905 | + // please note that offline payment methods will NOT make a payment, |
|
1906 | + // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
1907 | + $this->checkout->payment = $payment; |
|
1908 | + return true; |
|
1909 | + } |
|
1910 | + // where's my money? |
|
1911 | + return false; |
|
1912 | + } |
|
1913 | + |
|
1914 | + |
|
1915 | + /** |
|
1916 | + * _last_second_ticket_verifications |
|
1917 | + * |
|
1918 | + * @access public |
|
1919 | + * @return bool |
|
1920 | + * @throws EE_Error |
|
1921 | + */ |
|
1922 | + protected function _last_second_ticket_verifications() |
|
1923 | + { |
|
1924 | + // don't bother re-validating if not a return visit |
|
1925 | + if (! $this->checkout->revisit) { |
|
1926 | + return true; |
|
1927 | + } |
|
1928 | + $registrations = $this->checkout->transaction->registrations(); |
|
1929 | + if (empty($registrations)) { |
|
1930 | + return false; |
|
1931 | + } |
|
1932 | + foreach ($registrations as $registration) { |
|
1933 | + if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
1934 | + $event = $registration->event_obj(); |
|
1935 | + if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
1936 | + EE_Error::add_error( |
|
1937 | + apply_filters( |
|
1938 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
1939 | + sprintf( |
|
1940 | + esc_html__( |
|
1941 | + 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
1942 | + 'event_espresso' |
|
1943 | + ), |
|
1944 | + $event->name() |
|
1945 | + ) |
|
1946 | + ), |
|
1947 | + __FILE__, |
|
1948 | + __FUNCTION__, |
|
1949 | + __LINE__ |
|
1950 | + ); |
|
1951 | + return false; |
|
1952 | + } |
|
1953 | + } |
|
1954 | + } |
|
1955 | + return true; |
|
1956 | + } |
|
1957 | + |
|
1958 | + |
|
1959 | + /** |
|
1960 | + * redirect_form |
|
1961 | + * |
|
1962 | + * @access public |
|
1963 | + * @return bool |
|
1964 | + * @throws EE_Error |
|
1965 | + * @throws InvalidArgumentException |
|
1966 | + * @throws ReflectionException |
|
1967 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1968 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1969 | + */ |
|
1970 | + public function redirect_form() |
|
1971 | + { |
|
1972 | + $payment_method_billing_info = $this->_payment_method_billing_info( |
|
1973 | + $this->_get_payment_method_for_selected_method_of_payment() |
|
1974 | + ); |
|
1975 | + $html = $payment_method_billing_info->get_html(); |
|
1976 | + $html .= $this->checkout->redirect_form; |
|
1977 | + EE_Registry::instance()->REQ->add_output($html); |
|
1978 | + return true; |
|
1979 | + } |
|
1980 | + |
|
1981 | + |
|
1982 | + /** |
|
1983 | + * _billing_form_is_valid |
|
1984 | + * |
|
1985 | + * @access private |
|
1986 | + * @return bool |
|
1987 | + * @throws \EE_Error |
|
1988 | + */ |
|
1989 | + private function _billing_form_is_valid() |
|
1990 | + { |
|
1991 | + if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1992 | + return true; |
|
1993 | + } |
|
1994 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
1995 | + if ($this->checkout->billing_form->was_submitted()) { |
|
1996 | + $this->checkout->billing_form->receive_form_submission(); |
|
1997 | + if ($this->checkout->billing_form->is_valid()) { |
|
1998 | + return true; |
|
1999 | + } |
|
2000 | + $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
2001 | + $error_strings = array(); |
|
2002 | + foreach ($validation_errors as $validation_error) { |
|
2003 | + if ($validation_error instanceof EE_Validation_Error) { |
|
2004 | + $form_section = $validation_error->get_form_section(); |
|
2005 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
2006 | + $label = $form_section->html_label_text(); |
|
2007 | + } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
2008 | + $label = $form_section->name(); |
|
2009 | + } else { |
|
2010 | + $label = esc_html__('Validation Error', 'event_espresso'); |
|
2011 | + } |
|
2012 | + $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
2013 | + } |
|
2014 | + } |
|
2015 | + EE_Error::add_error( |
|
2016 | + sprintf( |
|
2017 | + esc_html__( |
|
2018 | + 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
2019 | + 'event_espresso' |
|
2020 | + ), |
|
2021 | + '<br/>', |
|
2022 | + implode('<br/>', $error_strings) |
|
2023 | + ), |
|
2024 | + __FILE__, |
|
2025 | + __FUNCTION__, |
|
2026 | + __LINE__ |
|
2027 | + ); |
|
2028 | + } else { |
|
2029 | + EE_Error::add_error( |
|
2030 | + esc_html__( |
|
2031 | + 'The billing form was not submitted or something prevented it\'s submission.', |
|
2032 | + 'event_espresso' |
|
2033 | + ), |
|
2034 | + __FILE__, |
|
2035 | + __FUNCTION__, |
|
2036 | + __LINE__ |
|
2037 | + ); |
|
2038 | + } |
|
2039 | + } else { |
|
2040 | + EE_Error::add_error( |
|
2041 | + esc_html__( |
|
2042 | + 'The submitted billing form is invalid possibly due to a technical reason.', |
|
2043 | + 'event_espresso' |
|
2044 | + ), |
|
2045 | + __FILE__, |
|
2046 | + __FUNCTION__, |
|
2047 | + __LINE__ |
|
2048 | + ); |
|
2049 | + } |
|
2050 | + return false; |
|
2051 | + } |
|
2052 | + |
|
2053 | + |
|
2054 | + /** |
|
2055 | + * _setup_primary_registrant_prior_to_payment |
|
2056 | + * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
2057 | + * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
2058 | + * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
2059 | + * yet) |
|
2060 | + * |
|
2061 | + * @access private |
|
2062 | + * @return bool |
|
2063 | + * @throws EE_Error |
|
2064 | + * @throws InvalidArgumentException |
|
2065 | + * @throws ReflectionException |
|
2066 | + * @throws RuntimeException |
|
2067 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2068 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2069 | + */ |
|
2070 | + private function _setup_primary_registrant_prior_to_payment() |
|
2071 | + { |
|
2072 | + // check if transaction has a primary registrant and that it has a related Attendee object |
|
2073 | + // if not, then we need to at least gather some primary registrant data before attempting payment |
|
2074 | + if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
2075 | + && ! $this->checkout->transaction_has_primary_registrant() |
|
2076 | + && ! $this->_capture_primary_registration_data_from_billing_form() |
|
2077 | + ) { |
|
2078 | + return false; |
|
2079 | + } |
|
2080 | + // because saving an object clears it's cache, we need to do the chevy shuffle |
|
2081 | + // grab the primary_registration object |
|
2082 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2083 | + // at this point we'll consider a TXN to not have been failed |
|
2084 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
2085 | + // save the TXN ( which clears cached copy of primary_registration) |
|
2086 | + $this->checkout->transaction->save(); |
|
2087 | + // grab TXN ID and save it to the primary_registration |
|
2088 | + $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
2089 | + // save what we have so far |
|
2090 | + $primary_registration->save(); |
|
2091 | + return true; |
|
2092 | + } |
|
2093 | + |
|
2094 | + |
|
2095 | + /** |
|
2096 | + * _capture_primary_registration_data_from_billing_form |
|
2097 | + * |
|
2098 | + * @access private |
|
2099 | + * @return bool |
|
2100 | + * @throws EE_Error |
|
2101 | + * @throws InvalidArgumentException |
|
2102 | + * @throws ReflectionException |
|
2103 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2104 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2105 | + */ |
|
2106 | + private function _capture_primary_registration_data_from_billing_form() |
|
2107 | + { |
|
2108 | + // convert billing form data into an attendee |
|
2109 | + $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
2110 | + if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2111 | + EE_Error::add_error( |
|
2112 | + sprintf( |
|
2113 | + esc_html__( |
|
2114 | + 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2115 | + 'event_espresso' |
|
2116 | + ), |
|
2117 | + '<br/>', |
|
2118 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2119 | + ), |
|
2120 | + __FILE__, |
|
2121 | + __FUNCTION__, |
|
2122 | + __LINE__ |
|
2123 | + ); |
|
2124 | + return false; |
|
2125 | + } |
|
2126 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2127 | + if (! $primary_registration instanceof EE_Registration) { |
|
2128 | + EE_Error::add_error( |
|
2129 | + sprintf( |
|
2130 | + esc_html__( |
|
2131 | + 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2132 | + 'event_espresso' |
|
2133 | + ), |
|
2134 | + '<br/>', |
|
2135 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2136 | + ), |
|
2137 | + __FILE__, |
|
2138 | + __FUNCTION__, |
|
2139 | + __LINE__ |
|
2140 | + ); |
|
2141 | + return false; |
|
2142 | + } |
|
2143 | + if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
2144 | + instanceof |
|
2145 | + EE_Attendee |
|
2146 | + ) { |
|
2147 | + EE_Error::add_error( |
|
2148 | + sprintf( |
|
2149 | + esc_html__( |
|
2150 | + 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2151 | + 'event_espresso' |
|
2152 | + ), |
|
2153 | + '<br/>', |
|
2154 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2155 | + ), |
|
2156 | + __FILE__, |
|
2157 | + __FUNCTION__, |
|
2158 | + __LINE__ |
|
2159 | + ); |
|
2160 | + return false; |
|
2161 | + } |
|
2162 | + /** @type EE_Registration_Processor $registration_processor */ |
|
2163 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
2164 | + // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
2165 | + $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
2166 | + return true; |
|
2167 | + } |
|
2168 | + |
|
2169 | + |
|
2170 | + /** |
|
2171 | + * _get_payment_method_for_selected_method_of_payment |
|
2172 | + * retrieves a valid payment method |
|
2173 | + * |
|
2174 | + * @access public |
|
2175 | + * @return EE_Payment_Method |
|
2176 | + * @throws EE_Error |
|
2177 | + * @throws InvalidArgumentException |
|
2178 | + * @throws ReflectionException |
|
2179 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2180 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2181 | + */ |
|
2182 | + private function _get_payment_method_for_selected_method_of_payment() |
|
2183 | + { |
|
2184 | + if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
2185 | + $this->_redirect_because_event_sold_out(); |
|
2186 | + return null; |
|
2187 | + } |
|
2188 | + // get EE_Payment_Method object |
|
2189 | + if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
2190 | + $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2191 | + } else { |
|
2192 | + // load EEM_Payment_Method |
|
2193 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
2194 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
2195 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
2196 | + $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
2197 | + } |
|
2198 | + // verify $payment_method |
|
2199 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
2200 | + // not a payment |
|
2201 | + EE_Error::add_error( |
|
2202 | + sprintf( |
|
2203 | + esc_html__( |
|
2204 | + 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2205 | + 'event_espresso' |
|
2206 | + ), |
|
2207 | + '<br/>', |
|
2208 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2209 | + ), |
|
2210 | + __FILE__, |
|
2211 | + __FUNCTION__, |
|
2212 | + __LINE__ |
|
2213 | + ); |
|
2214 | + return null; |
|
2215 | + } |
|
2216 | + // and verify it has a valid Payment_Method Type object |
|
2217 | + if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2218 | + // not a payment |
|
2219 | + EE_Error::add_error( |
|
2220 | + sprintf( |
|
2221 | + esc_html__( |
|
2222 | + 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2223 | + 'event_espresso' |
|
2224 | + ), |
|
2225 | + '<br/>', |
|
2226 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2227 | + ), |
|
2228 | + __FILE__, |
|
2229 | + __FUNCTION__, |
|
2230 | + __LINE__ |
|
2231 | + ); |
|
2232 | + return null; |
|
2233 | + } |
|
2234 | + return $payment_method; |
|
2235 | + } |
|
2236 | + |
|
2237 | + |
|
2238 | + /** |
|
2239 | + * _attempt_payment |
|
2240 | + * |
|
2241 | + * @access private |
|
2242 | + * @type EE_Payment_Method $payment_method |
|
2243 | + * @return mixed EE_Payment | boolean |
|
2244 | + * @throws EE_Error |
|
2245 | + * @throws InvalidArgumentException |
|
2246 | + * @throws ReflectionException |
|
2247 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2248 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2249 | + */ |
|
2250 | + private function _attempt_payment(EE_Payment_Method $payment_method) |
|
2251 | + { |
|
2252 | + $payment = null; |
|
2253 | + $this->checkout->transaction->save(); |
|
2254 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2255 | + if (! $payment_processor instanceof EE_Payment_Processor) { |
|
2256 | + return false; |
|
2257 | + } |
|
2258 | + try { |
|
2259 | + $payment_processor->set_revisit($this->checkout->revisit); |
|
2260 | + // generate payment object |
|
2261 | + $payment = $payment_processor->process_payment( |
|
2262 | + $payment_method, |
|
2263 | + $this->checkout->transaction, |
|
2264 | + $this->checkout->amount_owing, |
|
2265 | + $this->checkout->billing_form, |
|
2266 | + $this->_get_return_url($payment_method), |
|
2267 | + 'CART', |
|
2268 | + $this->checkout->admin_request, |
|
2269 | + true, |
|
2270 | + $this->reg_step_url() |
|
2271 | + ); |
|
2272 | + } catch (Exception $e) { |
|
2273 | + $this->_handle_payment_processor_exception($e); |
|
2274 | + } |
|
2275 | + return $payment; |
|
2276 | + } |
|
2277 | + |
|
2278 | + |
|
2279 | + /** |
|
2280 | + * _handle_payment_processor_exception |
|
2281 | + * |
|
2282 | + * @access protected |
|
2283 | + * @param \Exception $e |
|
2284 | + * @return void |
|
2285 | + * @throws EE_Error |
|
2286 | + * @throws InvalidArgumentException |
|
2287 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2288 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2289 | + */ |
|
2290 | + protected function _handle_payment_processor_exception(Exception $e) |
|
2291 | + { |
|
2292 | + EE_Error::add_error( |
|
2293 | + sprintf( |
|
2294 | + esc_html__( |
|
2295 | + 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
2296 | + 'event_espresso' |
|
2297 | + ), |
|
2298 | + '<br/>', |
|
2299 | + EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
2300 | + $e->getMessage(), |
|
2301 | + $e->getFile(), |
|
2302 | + $e->getLine() |
|
2303 | + ), |
|
2304 | + __FILE__, |
|
2305 | + __FUNCTION__, |
|
2306 | + __LINE__ |
|
2307 | + ); |
|
2308 | + } |
|
2309 | + |
|
2310 | + |
|
2311 | + /** |
|
2312 | + * _get_return_url |
|
2313 | + * |
|
2314 | + * @access protected |
|
2315 | + * @param \EE_Payment_Method $payment_method |
|
2316 | + * @return string |
|
2317 | + * @throws \EE_Error |
|
2318 | + */ |
|
2319 | + protected function _get_return_url(EE_Payment_Method $payment_method) |
|
2320 | + { |
|
2321 | + $return_url = ''; |
|
2322 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
2323 | + case EE_PMT_Base::offsite: |
|
2324 | + $return_url = add_query_arg( |
|
2325 | + array( |
|
2326 | + 'action' => 'process_gateway_response', |
|
2327 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2328 | + 'spco_txn' => $this->checkout->transaction->ID(), |
|
2329 | + ), |
|
2330 | + $this->reg_step_url() |
|
2331 | + ); |
|
2332 | + break; |
|
2333 | + case EE_PMT_Base::onsite: |
|
2334 | + case EE_PMT_Base::offline: |
|
2335 | + $return_url = $this->checkout->next_step->reg_step_url(); |
|
2336 | + break; |
|
2337 | + } |
|
2338 | + return $return_url; |
|
2339 | + } |
|
2340 | + |
|
2341 | + |
|
2342 | + /** |
|
2343 | + * _validate_payment |
|
2344 | + * |
|
2345 | + * @access private |
|
2346 | + * @param EE_Payment $payment |
|
2347 | + * @return EE_Payment|FALSE |
|
2348 | + * @throws EE_Error |
|
2349 | + * @throws InvalidArgumentException |
|
2350 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2351 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2352 | + */ |
|
2353 | + private function _validate_payment($payment = null) |
|
2354 | + { |
|
2355 | + if ($this->checkout->payment_method->is_off_line()) { |
|
2356 | + return true; |
|
2357 | + } |
|
2358 | + // verify payment object |
|
2359 | + if (! $payment instanceof EE_Payment) { |
|
2360 | + // not a payment |
|
2361 | + EE_Error::add_error( |
|
2362 | + sprintf( |
|
2363 | + esc_html__( |
|
2364 | + 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
2365 | + 'event_espresso' |
|
2366 | + ), |
|
2367 | + '<br/>', |
|
2368 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2369 | + ), |
|
2370 | + __FILE__, |
|
2371 | + __FUNCTION__, |
|
2372 | + __LINE__ |
|
2373 | + ); |
|
2374 | + return false; |
|
2375 | + } |
|
2376 | + return $payment; |
|
2377 | + } |
|
2378 | + |
|
2379 | + |
|
2380 | + /** |
|
2381 | + * _post_payment_processing |
|
2382 | + * |
|
2383 | + * @access private |
|
2384 | + * @param EE_Payment|bool $payment |
|
2385 | + * @return bool |
|
2386 | + * @throws EE_Error |
|
2387 | + * @throws InvalidArgumentException |
|
2388 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2389 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2390 | + */ |
|
2391 | + private function _post_payment_processing($payment = null) |
|
2392 | + { |
|
2393 | + // Off-Line payment? |
|
2394 | + if ($payment === true) { |
|
2395 | + // $this->_setup_redirect_for_next_step(); |
|
2396 | + return true; |
|
2397 | + // On-Site payment? |
|
2398 | + } elseif ($this->checkout->payment_method->is_on_site()) { |
|
2399 | + if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2400 | + // $this->_setup_redirect_for_next_step(); |
|
2401 | + $this->checkout->continue_reg = false; |
|
2402 | + } |
|
2403 | + // Off-Site payment? |
|
2404 | + } elseif ($this->checkout->payment_method->is_off_site()) { |
|
2405 | + // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
2406 | + if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
2407 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
2408 | + $this->checkout->redirect = true; |
|
2409 | + $this->checkout->redirect_form = $payment->redirect_form(); |
|
2410 | + $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
2411 | + // set JSON response |
|
2412 | + $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
2413 | + // and lastly, let's bump the payment status to pending |
|
2414 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
2415 | + $payment->save(); |
|
2416 | + } else { |
|
2417 | + // not a payment |
|
2418 | + $this->checkout->continue_reg = false; |
|
2419 | + EE_Error::add_error( |
|
2420 | + sprintf( |
|
2421 | + esc_html__( |
|
2422 | + 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
2423 | + 'event_espresso' |
|
2424 | + ), |
|
2425 | + '<br/>', |
|
2426 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2427 | + ), |
|
2428 | + __FILE__, |
|
2429 | + __FUNCTION__, |
|
2430 | + __LINE__ |
|
2431 | + ); |
|
2432 | + } |
|
2433 | + } else { |
|
2434 | + // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
2435 | + $this->checkout->continue_reg = false; |
|
2436 | + return false; |
|
2437 | + } |
|
2438 | + return $payment; |
|
2439 | + } |
|
2440 | + |
|
2441 | + |
|
2442 | + /** |
|
2443 | + * _process_payment_status |
|
2444 | + * |
|
2445 | + * @access private |
|
2446 | + * @type EE_Payment $payment |
|
2447 | + * @param string $payment_occurs |
|
2448 | + * @return bool |
|
2449 | + * @throws EE_Error |
|
2450 | + * @throws InvalidArgumentException |
|
2451 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2452 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2453 | + */ |
|
2454 | + private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
2455 | + { |
|
2456 | + // off-line payment? carry on |
|
2457 | + if ($payment_occurs === EE_PMT_Base::offline) { |
|
2458 | + return true; |
|
2459 | + } |
|
2460 | + // verify payment validity |
|
2461 | + if ($payment instanceof EE_Payment) { |
|
2462 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
2463 | + $msg = $payment->gateway_response(); |
|
2464 | + // check results |
|
2465 | + switch ($payment->status()) { |
|
2466 | + // good payment |
|
2467 | + case EEM_Payment::status_id_approved: |
|
2468 | + EE_Error::add_success( |
|
2469 | + esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
2470 | + __FILE__, |
|
2471 | + __FUNCTION__, |
|
2472 | + __LINE__ |
|
2473 | + ); |
|
2474 | + return true; |
|
2475 | + break; |
|
2476 | + // slow payment |
|
2477 | + case EEM_Payment::status_id_pending: |
|
2478 | + if (empty($msg)) { |
|
2479 | + $msg = esc_html__( |
|
2480 | + 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
2481 | + 'event_espresso' |
|
2482 | + ); |
|
2483 | + } |
|
2484 | + EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2485 | + return true; |
|
2486 | + break; |
|
2487 | + // don't wanna payment |
|
2488 | + case EEM_Payment::status_id_cancelled: |
|
2489 | + if (empty($msg)) { |
|
2490 | + $msg = _n( |
|
2491 | + 'Payment cancelled. Please try again.', |
|
2492 | + 'Payment cancelled. Please try again or select another method of payment.', |
|
2493 | + count($this->checkout->available_payment_methods), |
|
2494 | + 'event_espresso' |
|
2495 | + ); |
|
2496 | + } |
|
2497 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2498 | + return false; |
|
2499 | + break; |
|
2500 | + // not enough payment |
|
2501 | + case EEM_Payment::status_id_declined: |
|
2502 | + if (empty($msg)) { |
|
2503 | + $msg = _n( |
|
2504 | + 'We\'re sorry but your payment was declined. Please try again.', |
|
2505 | + 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
2506 | + count($this->checkout->available_payment_methods), |
|
2507 | + 'event_espresso' |
|
2508 | + ); |
|
2509 | + } |
|
2510 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2511 | + return false; |
|
2512 | + break; |
|
2513 | + // bad payment |
|
2514 | + case EEM_Payment::status_id_failed: |
|
2515 | + if (! empty($msg)) { |
|
2516 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2517 | + return false; |
|
2518 | + } |
|
2519 | + // default to error below |
|
2520 | + break; |
|
2521 | + } |
|
2522 | + } |
|
2523 | + // off-site payment gateway responses are too unreliable, so let's just assume that |
|
2524 | + // the payment processing is just running slower than the registrant's request |
|
2525 | + if ($payment_occurs === EE_PMT_Base::offsite) { |
|
2526 | + return true; |
|
2527 | + } |
|
2528 | + EE_Error::add_error( |
|
2529 | + sprintf( |
|
2530 | + esc_html__( |
|
2531 | + 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2532 | + 'event_espresso' |
|
2533 | + ), |
|
2534 | + '<br/>', |
|
2535 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2536 | + ), |
|
2537 | + __FILE__, |
|
2538 | + __FUNCTION__, |
|
2539 | + __LINE__ |
|
2540 | + ); |
|
2541 | + return false; |
|
2542 | + } |
|
2543 | + |
|
2544 | + |
|
2545 | + |
|
2546 | + |
|
2547 | + |
|
2548 | + |
|
2549 | + /********************************************************************************************************/ |
|
2550 | + /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
2551 | + /********************************************************************************************************/ |
|
2552 | + /** |
|
2553 | + * process_gateway_response |
|
2554 | + * this is the return point for Off-Site Payment Methods |
|
2555 | + * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
2556 | + * otherwise, it will load up the last payment made for the TXN. |
|
2557 | + * If the payment retrieved looks good, it will then either: |
|
2558 | + * complete the current step and allow advancement to the next reg step |
|
2559 | + * or present the payment options again |
|
2560 | + * |
|
2561 | + * @access private |
|
2562 | + * @return EE_Payment|FALSE |
|
2563 | + * @throws EE_Error |
|
2564 | + * @throws InvalidArgumentException |
|
2565 | + * @throws ReflectionException |
|
2566 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2567 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2568 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2569 | + */ |
|
2570 | + public function process_gateway_response() |
|
2571 | + { |
|
2572 | + $payment = null; |
|
2573 | + // how have they chosen to pay? |
|
2574 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
2575 | + // get EE_Payment_Method object |
|
2576 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2577 | + $this->checkout->continue_reg = false; |
|
2578 | + return false; |
|
2579 | + } |
|
2580 | + if (! $this->checkout->payment_method->is_off_site()) { |
|
2581 | + return false; |
|
2582 | + } |
|
2583 | + $this->_validate_offsite_return(); |
|
2584 | + // DEBUG LOG |
|
2585 | + // $this->checkout->log( |
|
2586 | + // __CLASS__, |
|
2587 | + // __FUNCTION__, |
|
2588 | + // __LINE__, |
|
2589 | + // array( |
|
2590 | + // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2591 | + // 'payment_method' => $this->checkout->payment_method, |
|
2592 | + // ), |
|
2593 | + // true |
|
2594 | + // ); |
|
2595 | + // verify TXN |
|
2596 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
2597 | + $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
2598 | + if (! $gateway instanceof EE_Offsite_Gateway) { |
|
2599 | + $this->checkout->continue_reg = false; |
|
2600 | + return false; |
|
2601 | + } |
|
2602 | + $payment = $this->_process_off_site_payment($gateway); |
|
2603 | + $payment = $this->_process_cancelled_payments($payment); |
|
2604 | + $payment = $this->_validate_payment($payment); |
|
2605 | + // if payment was not declined by the payment gateway or cancelled by the registrant |
|
2606 | + if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
2607 | + // $this->_setup_redirect_for_next_step(); |
|
2608 | + // store that for later |
|
2609 | + $this->checkout->payment = $payment; |
|
2610 | + // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
2611 | + // because we will complete this step during the IPN processing then |
|
2612 | + if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
2613 | + $this->set_completed(); |
|
2614 | + } |
|
2615 | + return true; |
|
2616 | + } |
|
2617 | + } |
|
2618 | + // DEBUG LOG |
|
2619 | + // $this->checkout->log( |
|
2620 | + // __CLASS__, |
|
2621 | + // __FUNCTION__, |
|
2622 | + // __LINE__, |
|
2623 | + // array('payment' => $payment) |
|
2624 | + // ); |
|
2625 | + $this->checkout->continue_reg = false; |
|
2626 | + return false; |
|
2627 | + } |
|
2628 | + |
|
2629 | + |
|
2630 | + /** |
|
2631 | + * _validate_return |
|
2632 | + * |
|
2633 | + * @access private |
|
2634 | + * @return void |
|
2635 | + * @throws EE_Error |
|
2636 | + * @throws InvalidArgumentException |
|
2637 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2638 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2639 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2640 | + */ |
|
2641 | + private function _validate_offsite_return() |
|
2642 | + { |
|
2643 | + $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
2644 | + if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
2645 | + // Houston... we might have a problem |
|
2646 | + $invalid_TXN = false; |
|
2647 | + // first gather some info |
|
2648 | + $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2649 | + $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
2650 | + ? $valid_TXN->primary_registration() |
|
2651 | + : null; |
|
2652 | + // let's start by retrieving the cart for this TXN |
|
2653 | + $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
2654 | + if ($cart instanceof EE_Cart) { |
|
2655 | + // verify that the current cart has tickets |
|
2656 | + $tickets = $cart->get_tickets(); |
|
2657 | + if (empty($tickets)) { |
|
2658 | + $invalid_TXN = true; |
|
2659 | + } |
|
2660 | + } else { |
|
2661 | + $invalid_TXN = true; |
|
2662 | + } |
|
2663 | + $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
2664 | + ? $primary_registrant->session_ID() |
|
2665 | + : null; |
|
2666 | + // validate current Session ID and compare against valid TXN session ID |
|
2667 | + if ($invalid_TXN // if this is already true, then skip other checks |
|
2668 | + || EE_Session::instance()->id() === null |
|
2669 | + || ( |
|
2670 | + // WARNING !!! |
|
2671 | + // this could be PayPal sending back duplicate requests (ya they do that) |
|
2672 | + // or it **could** mean someone is simply registering AGAIN after having just done so |
|
2673 | + // so now we need to determine if this current TXN looks valid or not |
|
2674 | + // and whether this reg step has even been started ? |
|
2675 | + EE_Session::instance()->id() === $valid_TXN_SID |
|
2676 | + // really? you're half way through this reg step, but you never started it ? |
|
2677 | + && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
2678 | + ) |
|
2679 | + ) { |
|
2680 | + $invalid_TXN = true; |
|
2681 | + } |
|
2682 | + if ($invalid_TXN) { |
|
2683 | + // is the valid TXN completed ? |
|
2684 | + if ($valid_TXN instanceof EE_Transaction) { |
|
2685 | + // has this step even been started ? |
|
2686 | + $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
2687 | + if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
2688 | + // so it **looks** like this is a double request from PayPal |
|
2689 | + // so let's try to pick up where we left off |
|
2690 | + $this->checkout->transaction = $valid_TXN; |
|
2691 | + $this->checkout->refresh_all_entities(true); |
|
2692 | + return; |
|
2693 | + } |
|
2694 | + } |
|
2695 | + // you appear to be lost? |
|
2696 | + $this->_redirect_wayward_request($primary_registrant); |
|
2697 | + } |
|
2698 | + } |
|
2699 | + } |
|
2700 | + |
|
2701 | + |
|
2702 | + /** |
|
2703 | + * _redirect_wayward_request |
|
2704 | + * |
|
2705 | + * @access private |
|
2706 | + * @param \EE_Registration|null $primary_registrant |
|
2707 | + * @return bool |
|
2708 | + * @throws EE_Error |
|
2709 | + * @throws InvalidArgumentException |
|
2710 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2711 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2712 | + */ |
|
2713 | + private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
2714 | + { |
|
2715 | + if (! $primary_registrant instanceof EE_Registration) { |
|
2716 | + // try redirecting based on the current TXN |
|
2717 | + $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
2718 | + ? $this->checkout->transaction->primary_registration() |
|
2719 | + : null; |
|
2720 | + } |
|
2721 | + if (! $primary_registrant instanceof EE_Registration) { |
|
2722 | + EE_Error::add_error( |
|
2723 | + sprintf( |
|
2724 | + esc_html__( |
|
2725 | + 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
2726 | + 'event_espresso' |
|
2727 | + ), |
|
2728 | + '<br/>', |
|
2729 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2730 | + ), |
|
2731 | + __FILE__, |
|
2732 | + __FUNCTION__, |
|
2733 | + __LINE__ |
|
2734 | + ); |
|
2735 | + return false; |
|
2736 | + } |
|
2737 | + // make sure transaction is not locked |
|
2738 | + $this->checkout->transaction->unlock(); |
|
2739 | + wp_safe_redirect( |
|
2740 | + add_query_arg( |
|
2741 | + array( |
|
2742 | + 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
2743 | + ), |
|
2744 | + $this->checkout->thank_you_page_url |
|
2745 | + ) |
|
2746 | + ); |
|
2747 | + exit(); |
|
2748 | + } |
|
2749 | + |
|
2750 | + |
|
2751 | + /** |
|
2752 | + * _process_off_site_payment |
|
2753 | + * |
|
2754 | + * @access private |
|
2755 | + * @param \EE_Offsite_Gateway $gateway |
|
2756 | + * @return EE_Payment |
|
2757 | + * @throws EE_Error |
|
2758 | + * @throws InvalidArgumentException |
|
2759 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2760 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2761 | + */ |
|
2762 | + private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
2763 | + { |
|
2764 | + try { |
|
2765 | + $request_data = \EE_Registry::instance()->REQ->params(); |
|
2766 | + // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
2767 | + $this->set_handle_IPN_in_this_request( |
|
2768 | + $gateway->handle_IPN_in_this_request($request_data, false) |
|
2769 | + ); |
|
2770 | + if ($this->handle_IPN_in_this_request()) { |
|
2771 | + // get payment details and process results |
|
2772 | + /** @type EE_Payment_Processor $payment_processor */ |
|
2773 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2774 | + $payment = $payment_processor->process_ipn( |
|
2775 | + $request_data, |
|
2776 | + $this->checkout->transaction, |
|
2777 | + $this->checkout->payment_method, |
|
2778 | + true, |
|
2779 | + false |
|
2780 | + ); |
|
2781 | + // $payment_source = 'process_ipn'; |
|
2782 | + } else { |
|
2783 | + $payment = $this->checkout->transaction->last_payment(); |
|
2784 | + // $payment_source = 'last_payment'; |
|
2785 | + } |
|
2786 | + } catch (Exception $e) { |
|
2787 | + // let's just eat the exception and try to move on using any previously set payment info |
|
2788 | + $payment = $this->checkout->transaction->last_payment(); |
|
2789 | + // $payment_source = 'last_payment after Exception'; |
|
2790 | + // but if we STILL don't have a payment object |
|
2791 | + if (! $payment instanceof EE_Payment) { |
|
2792 | + // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
2793 | + $this->_handle_payment_processor_exception($e); |
|
2794 | + } |
|
2795 | + } |
|
2796 | + // DEBUG LOG |
|
2797 | + // $this->checkout->log( |
|
2798 | + // __CLASS__, |
|
2799 | + // __FUNCTION__, |
|
2800 | + // __LINE__, |
|
2801 | + // array( |
|
2802 | + // 'process_ipn_payment' => $payment, |
|
2803 | + // 'payment_source' => $payment_source, |
|
2804 | + // ) |
|
2805 | + // ); |
|
2806 | + return $payment; |
|
2807 | + } |
|
2808 | + |
|
2809 | + |
|
2810 | + /** |
|
2811 | + * _process_cancelled_payments |
|
2812 | + * just makes sure that the payment status gets updated correctly |
|
2813 | + * so tha tan error isn't generated during payment validation |
|
2814 | + * |
|
2815 | + * @access private |
|
2816 | + * @param EE_Payment $payment |
|
2817 | + * @return EE_Payment | FALSE |
|
2818 | + * @throws \EE_Error |
|
2819 | + */ |
|
2820 | + private function _process_cancelled_payments($payment = null) |
|
2821 | + { |
|
2822 | + if ($payment instanceof EE_Payment |
|
2823 | + && isset($_REQUEST['ee_cancel_payment']) |
|
2824 | + && $payment->status() === EEM_Payment::status_id_failed |
|
2825 | + ) { |
|
2826 | + $payment->set_status(EEM_Payment::status_id_cancelled); |
|
2827 | + } |
|
2828 | + return $payment; |
|
2829 | + } |
|
2830 | + |
|
2831 | + |
|
2832 | + /** |
|
2833 | + * get_transaction_details_for_gateways |
|
2834 | + * |
|
2835 | + * @access public |
|
2836 | + * @return int |
|
2837 | + * @throws EE_Error |
|
2838 | + * @throws InvalidArgumentException |
|
2839 | + * @throws ReflectionException |
|
2840 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2841 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2842 | + */ |
|
2843 | + public function get_transaction_details_for_gateways() |
|
2844 | + { |
|
2845 | + $txn_details = array(); |
|
2846 | + // ya gotta make a choice man |
|
2847 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
2848 | + $txn_details = array( |
|
2849 | + 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
2850 | + ); |
|
2851 | + } |
|
2852 | + // get EE_Payment_Method object |
|
2853 | + if (empty($txn_details) |
|
2854 | + && |
|
2855 | + ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
2856 | + ) { |
|
2857 | + $txn_details = array( |
|
2858 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2859 | + 'error' => esc_html__( |
|
2860 | + 'A valid Payment Method could not be determined.', |
|
2861 | + 'event_espresso' |
|
2862 | + ), |
|
2863 | + ); |
|
2864 | + } |
|
2865 | + if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
2866 | + $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
2867 | + $txn_details = array( |
|
2868 | + 'TXN_ID' => $this->checkout->transaction->ID(), |
|
2869 | + 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
2870 | + 'TXN_total' => $this->checkout->transaction->total(), |
|
2871 | + 'TXN_paid' => $this->checkout->transaction->paid(), |
|
2872 | + 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
2873 | + 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
2874 | + 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
2875 | + 'payment_amount' => $this->checkout->amount_owing, |
|
2876 | + 'return_url' => $return_url, |
|
2877 | + 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
2878 | + 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
2879 | + array( |
|
2880 | + 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
2881 | + 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
2882 | + ) |
|
2883 | + ), |
|
2884 | + ); |
|
2885 | + } |
|
2886 | + echo wp_json_encode($txn_details); |
|
2887 | + exit(); |
|
2888 | + } |
|
2889 | + |
|
2890 | + |
|
2891 | + /** |
|
2892 | + * __sleep |
|
2893 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
2894 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
2895 | + * reg form, because if needed, it will be regenerated anyways |
|
2896 | + * |
|
2897 | + * @return array |
|
2898 | + */ |
|
2899 | + public function __sleep() |
|
2900 | + { |
|
2901 | + // remove the reg form and the checkout |
|
2902 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
2903 | + } |
|
2904 | 2904 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.83.rc.006'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.83.rc.006'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |