@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | */ |
20 | 20 | function is_espresso_event($event = null) |
21 | 21 | { |
22 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
23 | - // extract EE_Event object from passed param regardless of what it is (within reason of course) |
|
24 | - $event = EEH_Event_View::get_event($event); |
|
25 | - // do we have a valid event ? |
|
26 | - return $event instanceof EE_Event; |
|
27 | - } |
|
28 | - return false; |
|
22 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
23 | + // extract EE_Event object from passed param regardless of what it is (within reason of course) |
|
24 | + $event = EEH_Event_View::get_event($event); |
|
25 | + // do we have a valid event ? |
|
26 | + return $event instanceof EE_Event; |
|
27 | + } |
|
28 | + return false; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | */ |
37 | 37 | function is_espresso_event_single() |
38 | 38 | { |
39 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
40 | - global $wp_query; |
|
41 | - // return conditionals set by CPTs |
|
42 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : false; |
|
43 | - } |
|
44 | - return false; |
|
39 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
40 | + global $wp_query; |
|
41 | + // return conditionals set by CPTs |
|
42 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : false; |
|
43 | + } |
|
44 | + return false; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | */ |
53 | 53 | function is_espresso_event_archive() |
54 | 54 | { |
55 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
56 | - global $wp_query; |
|
57 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : false; |
|
58 | - } |
|
59 | - return false; |
|
55 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
56 | + global $wp_query; |
|
57 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : false; |
|
58 | + } |
|
59 | + return false; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | */ |
68 | 68 | function is_espresso_event_taxonomy() |
69 | 69 | { |
70 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
71 | - global $wp_query; |
|
72 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : false; |
|
73 | - } |
|
74 | - return false; |
|
70 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
71 | + global $wp_query; |
|
72 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : false; |
|
73 | + } |
|
74 | + return false; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | */ |
86 | 86 | function is_espresso_venue($venue = null) |
87 | 87 | { |
88 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
89 | - // extract EE_Venue object from passed param regardless of what it is (within reason of course) |
|
90 | - $venue = EEH_Venue_View::get_venue($venue, false); |
|
91 | - // do we have a valid event ? |
|
92 | - return $venue instanceof EE_Venue; |
|
93 | - } |
|
94 | - return false; |
|
88 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
89 | + // extract EE_Venue object from passed param regardless of what it is (within reason of course) |
|
90 | + $venue = EEH_Venue_View::get_venue($venue, false); |
|
91 | + // do we have a valid event ? |
|
92 | + return $venue instanceof EE_Venue; |
|
93 | + } |
|
94 | + return false; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function is_espresso_venue_single() |
104 | 104 | { |
105 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
106 | - global $wp_query; |
|
107 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : false; |
|
108 | - } |
|
109 | - return false; |
|
105 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
106 | + global $wp_query; |
|
107 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : false; |
|
108 | + } |
|
109 | + return false; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | */ |
118 | 118 | function is_espresso_venue_archive() |
119 | 119 | { |
120 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
121 | - global $wp_query; |
|
122 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : false; |
|
123 | - } |
|
124 | - return false; |
|
120 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
121 | + global $wp_query; |
|
122 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : false; |
|
123 | + } |
|
124 | + return false; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | */ |
133 | 133 | function is_espresso_venue_taxonomy() |
134 | 134 | { |
135 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
136 | - global $wp_query; |
|
137 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : false; |
|
138 | - } |
|
139 | - return false; |
|
135 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
136 | + global $wp_query; |
|
137 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : false; |
|
138 | + } |
|
139 | + return false; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -148,62 +148,62 @@ discard block |
||
148 | 148 | */ |
149 | 149 | function can_use_espresso_conditionals($conditional_tag) |
150 | 150 | { |
151 | - if (! did_action('AHEE__EE_System__initialize')) { |
|
152 | - EE_Error::doing_it_wrong( |
|
153 | - __FUNCTION__, |
|
154 | - sprintf( |
|
155 | - esc_html__( |
|
156 | - 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', |
|
157 | - 'event_espresso' |
|
158 | - ), |
|
159 | - $conditional_tag |
|
160 | - ), |
|
161 | - '4.4.0' |
|
162 | - ); |
|
163 | - return false; |
|
164 | - } |
|
165 | - return true; |
|
151 | + if (! did_action('AHEE__EE_System__initialize')) { |
|
152 | + EE_Error::doing_it_wrong( |
|
153 | + __FUNCTION__, |
|
154 | + sprintf( |
|
155 | + esc_html__( |
|
156 | + 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', |
|
157 | + 'event_espresso' |
|
158 | + ), |
|
159 | + $conditional_tag |
|
160 | + ), |
|
161 | + '4.4.0' |
|
162 | + ); |
|
163 | + return false; |
|
164 | + } |
|
165 | + return true; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | |
169 | 169 | /*************************** Event Queries ***************************/ |
170 | 170 | |
171 | 171 | if (! function_exists('espresso_get_events')) { |
172 | - /** |
|
173 | - * espresso_get_events |
|
174 | - * |
|
175 | - * @param array $params |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - function espresso_get_events($params = []) |
|
179 | - { |
|
180 | - //set default params |
|
181 | - $default_espresso_events_params = [ |
|
182 | - 'limit' => 10, |
|
183 | - 'show_expired' => false, |
|
184 | - 'month' => null, |
|
185 | - 'category_slug' => null, |
|
186 | - 'order_by' => 'start_date', |
|
187 | - 'sort' => 'ASC', |
|
188 | - ]; |
|
189 | - // allow the defaults to be filtered |
|
190 | - $default_espresso_events_params = apply_filters( |
|
191 | - 'espresso_get_events__default_espresso_events_params', |
|
192 | - $default_espresso_events_params |
|
193 | - ); |
|
194 | - // grab params and merge with defaults, then extract |
|
195 | - $params = array_merge($default_espresso_events_params, $params); |
|
196 | - // run the query |
|
197 | - $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery($params); |
|
198 | - // assign results to a variable so we can return it |
|
199 | - $events = $events_query->have_posts() ? $events_query->posts : []; |
|
200 | - // but first reset the query and postdata |
|
201 | - wp_reset_query(); |
|
202 | - wp_reset_postdata(); |
|
203 | - EED_Events_Archive::remove_all_events_archive_filters(); |
|
204 | - unset($events_query); |
|
205 | - return $events; |
|
206 | - } |
|
172 | + /** |
|
173 | + * espresso_get_events |
|
174 | + * |
|
175 | + * @param array $params |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + function espresso_get_events($params = []) |
|
179 | + { |
|
180 | + //set default params |
|
181 | + $default_espresso_events_params = [ |
|
182 | + 'limit' => 10, |
|
183 | + 'show_expired' => false, |
|
184 | + 'month' => null, |
|
185 | + 'category_slug' => null, |
|
186 | + 'order_by' => 'start_date', |
|
187 | + 'sort' => 'ASC', |
|
188 | + ]; |
|
189 | + // allow the defaults to be filtered |
|
190 | + $default_espresso_events_params = apply_filters( |
|
191 | + 'espresso_get_events__default_espresso_events_params', |
|
192 | + $default_espresso_events_params |
|
193 | + ); |
|
194 | + // grab params and merge with defaults, then extract |
|
195 | + $params = array_merge($default_espresso_events_params, $params); |
|
196 | + // run the query |
|
197 | + $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery($params); |
|
198 | + // assign results to a variable so we can return it |
|
199 | + $events = $events_query->have_posts() ? $events_query->posts : []; |
|
200 | + // but first reset the query and postdata |
|
201 | + wp_reset_query(); |
|
202 | + wp_reset_postdata(); |
|
203 | + EED_Events_Archive::remove_all_events_archive_filters(); |
|
204 | + unset($events_query); |
|
205 | + return $events; |
|
206 | + } |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | |
@@ -218,357 +218,357 @@ discard block |
||
218 | 218 | */ |
219 | 219 | function espresso_load_ticket_selector() |
220 | 220 | { |
221 | - EE_Registry::instance()->load_file(EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module'); |
|
221 | + EE_Registry::instance()->load_file(EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module'); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | if (! function_exists('espresso_ticket_selector')) { |
225 | - /** |
|
226 | - * espresso_ticket_selector |
|
227 | - * |
|
228 | - * @param null $event |
|
229 | - * @throws EE_Error |
|
230 | - * @throws ReflectionException |
|
231 | - */ |
|
232 | - function espresso_ticket_selector($event = null) |
|
233 | - { |
|
234 | - if (! apply_filters('FHEE_disable_espresso_ticket_selector', false)) { |
|
235 | - espresso_load_ticket_selector(); |
|
236 | - EED_Ticket_Selector::set_definitions(); |
|
237 | - echo EED_Ticket_Selector::display_ticket_selector($event); // already escaped |
|
238 | - } |
|
239 | - } |
|
225 | + /** |
|
226 | + * espresso_ticket_selector |
|
227 | + * |
|
228 | + * @param null $event |
|
229 | + * @throws EE_Error |
|
230 | + * @throws ReflectionException |
|
231 | + */ |
|
232 | + function espresso_ticket_selector($event = null) |
|
233 | + { |
|
234 | + if (! apply_filters('FHEE_disable_espresso_ticket_selector', false)) { |
|
235 | + espresso_load_ticket_selector(); |
|
236 | + EED_Ticket_Selector::set_definitions(); |
|
237 | + echo EED_Ticket_Selector::display_ticket_selector($event); // already escaped |
|
238 | + } |
|
239 | + } |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | |
243 | 243 | if (! function_exists('espresso_view_details_btn')) { |
244 | - /** |
|
245 | - * espresso_view_details_btn |
|
246 | - * |
|
247 | - * @param null $event |
|
248 | - * @throws EE_Error |
|
249 | - * @throws ReflectionException |
|
250 | - */ |
|
251 | - function espresso_view_details_btn($event = null) |
|
252 | - { |
|
253 | - if (! apply_filters('FHEE_disable_espresso_view_details_btn', false)) { |
|
254 | - espresso_load_ticket_selector(); |
|
255 | - echo EED_Ticket_Selector::display_ticket_selector($event, true); // already escaped |
|
256 | - } |
|
257 | - } |
|
244 | + /** |
|
245 | + * espresso_view_details_btn |
|
246 | + * |
|
247 | + * @param null $event |
|
248 | + * @throws EE_Error |
|
249 | + * @throws ReflectionException |
|
250 | + */ |
|
251 | + function espresso_view_details_btn($event = null) |
|
252 | + { |
|
253 | + if (! apply_filters('FHEE_disable_espresso_view_details_btn', false)) { |
|
254 | + espresso_load_ticket_selector(); |
|
255 | + echo EED_Ticket_Selector::display_ticket_selector($event, true); // already escaped |
|
256 | + } |
|
257 | + } |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | |
261 | 261 | /*************************** EEH_Event_View ***************************/ |
262 | 262 | |
263 | 263 | if (! function_exists('espresso_load_event_list_assets')) { |
264 | - /** |
|
265 | - * espresso_load_event_list_assets |
|
266 | - * ensures that event list styles and scripts are loaded |
|
267 | - * |
|
268 | - * @return void |
|
269 | - */ |
|
270 | - function espresso_load_event_list_assets() |
|
271 | - { |
|
272 | - $event_list = EED_Events_Archive::instance(); |
|
273 | - add_action('AHEE__EE_System__initialize_last', [$event_list, 'load_event_list_assets'], 10); |
|
274 | - add_filter('FHEE_enable_default_espresso_css', '__return_true'); |
|
275 | - } |
|
264 | + /** |
|
265 | + * espresso_load_event_list_assets |
|
266 | + * ensures that event list styles and scripts are loaded |
|
267 | + * |
|
268 | + * @return void |
|
269 | + */ |
|
270 | + function espresso_load_event_list_assets() |
|
271 | + { |
|
272 | + $event_list = EED_Events_Archive::instance(); |
|
273 | + add_action('AHEE__EE_System__initialize_last', [$event_list, 'load_event_list_assets'], 10); |
|
274 | + add_filter('FHEE_enable_default_espresso_css', '__return_true'); |
|
275 | + } |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | |
279 | 279 | if (! function_exists('espresso_event_reg_button')) { |
280 | - /** |
|
281 | - * espresso_event_reg_button |
|
282 | - * returns the "Register Now" button if event is active, |
|
283 | - * an inactive button like status banner if the event is not active |
|
284 | - * or a "Read More" button if so desired |
|
285 | - * |
|
286 | - * @param null $btn_text_if_active |
|
287 | - * @param bool $btn_text_if_inactive |
|
288 | - * @param bool $EVT_ID |
|
289 | - * @return void |
|
290 | - * @throws EE_Error |
|
291 | - * @throws ReflectionException |
|
292 | - */ |
|
293 | - function espresso_event_reg_button($btn_text_if_active = null, $btn_text_if_inactive = false, $EVT_ID = false) |
|
294 | - { |
|
295 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
296 | - if (! $event instanceof EE_Event) { |
|
297 | - return; |
|
298 | - } |
|
299 | - $event_status = $event->get_active_status(); |
|
300 | - switch ($event_status) { |
|
301 | - case EE_Datetime::sold_out : |
|
302 | - $btn_text = __('Sold Out', 'event_espresso'); |
|
303 | - $class = 'ee-pink'; |
|
304 | - break; |
|
305 | - case EE_Datetime::expired : |
|
306 | - $btn_text = __('Event is Over', 'event_espresso'); |
|
307 | - $class = 'ee-grey'; |
|
308 | - break; |
|
309 | - case EE_Datetime::inactive : |
|
310 | - $btn_text = __('Event Not Active', 'event_espresso'); |
|
311 | - $class = 'ee-grey'; |
|
312 | - break; |
|
313 | - case EE_Datetime::cancelled : |
|
314 | - $btn_text = __('Event was Cancelled', 'event_espresso'); |
|
315 | - $class = 'ee-red'; |
|
316 | - break; |
|
317 | - case EE_Datetime::upcoming : |
|
318 | - case EE_Datetime::active : |
|
319 | - default : |
|
320 | - $btn_text = ! empty($btn_text_if_active) |
|
321 | - ? $btn_text_if_active |
|
322 | - : __('Register Now', 'event_espresso'); |
|
323 | - $class = 'ee-green'; |
|
324 | - } |
|
325 | - if ($event_status < 1 && ! empty($btn_text_if_inactive)) { |
|
326 | - $btn_text = $btn_text_if_inactive; |
|
327 | - $class = 'ee-grey'; |
|
328 | - } |
|
329 | - ?> |
|
280 | + /** |
|
281 | + * espresso_event_reg_button |
|
282 | + * returns the "Register Now" button if event is active, |
|
283 | + * an inactive button like status banner if the event is not active |
|
284 | + * or a "Read More" button if so desired |
|
285 | + * |
|
286 | + * @param null $btn_text_if_active |
|
287 | + * @param bool $btn_text_if_inactive |
|
288 | + * @param bool $EVT_ID |
|
289 | + * @return void |
|
290 | + * @throws EE_Error |
|
291 | + * @throws ReflectionException |
|
292 | + */ |
|
293 | + function espresso_event_reg_button($btn_text_if_active = null, $btn_text_if_inactive = false, $EVT_ID = false) |
|
294 | + { |
|
295 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
296 | + if (! $event instanceof EE_Event) { |
|
297 | + return; |
|
298 | + } |
|
299 | + $event_status = $event->get_active_status(); |
|
300 | + switch ($event_status) { |
|
301 | + case EE_Datetime::sold_out : |
|
302 | + $btn_text = __('Sold Out', 'event_espresso'); |
|
303 | + $class = 'ee-pink'; |
|
304 | + break; |
|
305 | + case EE_Datetime::expired : |
|
306 | + $btn_text = __('Event is Over', 'event_espresso'); |
|
307 | + $class = 'ee-grey'; |
|
308 | + break; |
|
309 | + case EE_Datetime::inactive : |
|
310 | + $btn_text = __('Event Not Active', 'event_espresso'); |
|
311 | + $class = 'ee-grey'; |
|
312 | + break; |
|
313 | + case EE_Datetime::cancelled : |
|
314 | + $btn_text = __('Event was Cancelled', 'event_espresso'); |
|
315 | + $class = 'ee-red'; |
|
316 | + break; |
|
317 | + case EE_Datetime::upcoming : |
|
318 | + case EE_Datetime::active : |
|
319 | + default : |
|
320 | + $btn_text = ! empty($btn_text_if_active) |
|
321 | + ? $btn_text_if_active |
|
322 | + : __('Register Now', 'event_espresso'); |
|
323 | + $class = 'ee-green'; |
|
324 | + } |
|
325 | + if ($event_status < 1 && ! empty($btn_text_if_inactive)) { |
|
326 | + $btn_text = $btn_text_if_inactive; |
|
327 | + $class = 'ee-grey'; |
|
328 | + } |
|
329 | + ?> |
|
330 | 330 | <a class="ee-button ee-register-button <?php echo esc_attr($class); ?>" |
331 | 331 | href="<?php espresso_event_link_url($EVT_ID); ?>" |
332 | 332 | <?php echo EED_Events_Archive::link_target(); // already escaped |
333 | - ?> |
|
333 | + ?> |
|
334 | 334 | > |
335 | 335 | <?php echo esc_html($btn_text); ?> |
336 | 336 | </a> |
337 | 337 | <?php |
338 | - } |
|
338 | + } |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | |
342 | 342 | if (! function_exists('espresso_display_ticket_selector')) { |
343 | - /** |
|
344 | - * espresso_display_ticket_selector |
|
345 | - * whether or not to display the Ticket Selector for an event |
|
346 | - * |
|
347 | - * @param bool $EVT_ID |
|
348 | - * @return boolean |
|
349 | - * @throws EE_Error |
|
350 | - * @throws ReflectionException |
|
351 | - */ |
|
352 | - function espresso_display_ticket_selector($EVT_ID = false) |
|
353 | - { |
|
354 | - return EEH_Event_View::display_ticket_selector($EVT_ID); |
|
355 | - } |
|
343 | + /** |
|
344 | + * espresso_display_ticket_selector |
|
345 | + * whether or not to display the Ticket Selector for an event |
|
346 | + * |
|
347 | + * @param bool $EVT_ID |
|
348 | + * @return boolean |
|
349 | + * @throws EE_Error |
|
350 | + * @throws ReflectionException |
|
351 | + */ |
|
352 | + function espresso_display_ticket_selector($EVT_ID = false) |
|
353 | + { |
|
354 | + return EEH_Event_View::display_ticket_selector($EVT_ID); |
|
355 | + } |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | |
359 | 359 | if (! function_exists('espresso_event_status_banner')) { |
360 | - /** |
|
361 | - * espresso_event_status |
|
362 | - * returns a banner showing the event status if it is sold out, expired, or inactive |
|
363 | - * |
|
364 | - * @param bool $EVT_ID |
|
365 | - * @return string |
|
366 | - * @throws EE_Error |
|
367 | - * @throws ReflectionException |
|
368 | - */ |
|
369 | - function espresso_event_status_banner($EVT_ID = false) |
|
370 | - { |
|
371 | - return EEH_Event_View::event_status($EVT_ID); |
|
372 | - } |
|
360 | + /** |
|
361 | + * espresso_event_status |
|
362 | + * returns a banner showing the event status if it is sold out, expired, or inactive |
|
363 | + * |
|
364 | + * @param bool $EVT_ID |
|
365 | + * @return string |
|
366 | + * @throws EE_Error |
|
367 | + * @throws ReflectionException |
|
368 | + */ |
|
369 | + function espresso_event_status_banner($EVT_ID = false) |
|
370 | + { |
|
371 | + return EEH_Event_View::event_status($EVT_ID); |
|
372 | + } |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
376 | 376 | if (! function_exists('espresso_event_status')) { |
377 | - /** |
|
378 | - * espresso_event_status |
|
379 | - * returns the event status if it is sold out, expired, or inactive |
|
380 | - * |
|
381 | - * @param int $EVT_ID |
|
382 | - * @param bool $echo |
|
383 | - * @return string |
|
384 | - * @throws EE_Error |
|
385 | - * @throws ReflectionException |
|
386 | - */ |
|
387 | - function espresso_event_status($EVT_ID = 0, $echo = true) |
|
388 | - { |
|
389 | - return EEH_Event_View::event_active_status($EVT_ID, $echo); |
|
390 | - } |
|
377 | + /** |
|
378 | + * espresso_event_status |
|
379 | + * returns the event status if it is sold out, expired, or inactive |
|
380 | + * |
|
381 | + * @param int $EVT_ID |
|
382 | + * @param bool $echo |
|
383 | + * @return string |
|
384 | + * @throws EE_Error |
|
385 | + * @throws ReflectionException |
|
386 | + */ |
|
387 | + function espresso_event_status($EVT_ID = 0, $echo = true) |
|
388 | + { |
|
389 | + return EEH_Event_View::event_active_status($EVT_ID, $echo); |
|
390 | + } |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | |
394 | 394 | if (! function_exists('espresso_event_categories')) { |
395 | - /** |
|
396 | - * espresso_event_categories |
|
397 | - * returns the terms associated with an event |
|
398 | - * |
|
399 | - * @param int $EVT_ID |
|
400 | - * @param bool $hide_uncategorized |
|
401 | - * @param bool $echo |
|
402 | - * @return string |
|
403 | - * @throws EE_Error |
|
404 | - * @throws ReflectionException |
|
405 | - */ |
|
406 | - function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = true, $echo = true) |
|
407 | - { |
|
408 | - if ($echo) { |
|
409 | - echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); // already escaped |
|
410 | - return ''; |
|
411 | - } |
|
412 | - return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
413 | - } |
|
395 | + /** |
|
396 | + * espresso_event_categories |
|
397 | + * returns the terms associated with an event |
|
398 | + * |
|
399 | + * @param int $EVT_ID |
|
400 | + * @param bool $hide_uncategorized |
|
401 | + * @param bool $echo |
|
402 | + * @return string |
|
403 | + * @throws EE_Error |
|
404 | + * @throws ReflectionException |
|
405 | + */ |
|
406 | + function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = true, $echo = true) |
|
407 | + { |
|
408 | + if ($echo) { |
|
409 | + echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); // already escaped |
|
410 | + return ''; |
|
411 | + } |
|
412 | + return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
413 | + } |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | |
417 | 417 | if (! function_exists('espresso_event_tickets_available')) { |
418 | - /** |
|
419 | - * espresso_event_tickets_available |
|
420 | - * returns the ticket types available for purchase for an event |
|
421 | - * |
|
422 | - * @param int $EVT_ID |
|
423 | - * @param bool $echo |
|
424 | - * @param bool $format |
|
425 | - * @return string |
|
426 | - * @throws EE_Error |
|
427 | - * @throws ReflectionException |
|
428 | - */ |
|
429 | - function espresso_event_tickets_available($EVT_ID = 0, $echo = true, $format = true) |
|
430 | - { |
|
431 | - $tickets = EEH_Event_View::event_tickets_available($EVT_ID); |
|
432 | - if (is_array($tickets) && ! empty($tickets)) { |
|
433 | - // if formatting then $html will be a string, else it will be an array of ticket objects |
|
434 | - $html = |
|
435 | - $format ? '<ul id="ee-event-tickets-ul-' . esc_attr($EVT_ID) . '" class="ee-event-tickets-ul">' : []; |
|
436 | - foreach ($tickets as $ticket) { |
|
437 | - if ($ticket instanceof EE_Ticket) { |
|
438 | - if ($format) { |
|
439 | - $html .= '<li id="ee-event-tickets-li-' |
|
440 | - . esc_attr($ticket->ID()) |
|
441 | - . '" class="ee-event-tickets-li">'; |
|
442 | - $html .= esc_html($ticket->name()) . ' '; |
|
443 | - $html .= EEH_Template::format_currency( |
|
444 | - $ticket->get_ticket_total_with_taxes() |
|
445 | - ); // already escaped |
|
446 | - $html .= '</li>'; |
|
447 | - } else { |
|
448 | - $html[] = $ticket; |
|
449 | - } |
|
450 | - } |
|
451 | - } |
|
452 | - if ($format) { |
|
453 | - $html .= '</ul>'; |
|
454 | - } |
|
455 | - if ($echo && $format) { |
|
456 | - echo wp_kses($html, AllowedTags::getAllowedTags()); |
|
457 | - return ''; |
|
458 | - } |
|
459 | - return $html; |
|
460 | - } |
|
461 | - return ''; |
|
462 | - } |
|
418 | + /** |
|
419 | + * espresso_event_tickets_available |
|
420 | + * returns the ticket types available for purchase for an event |
|
421 | + * |
|
422 | + * @param int $EVT_ID |
|
423 | + * @param bool $echo |
|
424 | + * @param bool $format |
|
425 | + * @return string |
|
426 | + * @throws EE_Error |
|
427 | + * @throws ReflectionException |
|
428 | + */ |
|
429 | + function espresso_event_tickets_available($EVT_ID = 0, $echo = true, $format = true) |
|
430 | + { |
|
431 | + $tickets = EEH_Event_View::event_tickets_available($EVT_ID); |
|
432 | + if (is_array($tickets) && ! empty($tickets)) { |
|
433 | + // if formatting then $html will be a string, else it will be an array of ticket objects |
|
434 | + $html = |
|
435 | + $format ? '<ul id="ee-event-tickets-ul-' . esc_attr($EVT_ID) . '" class="ee-event-tickets-ul">' : []; |
|
436 | + foreach ($tickets as $ticket) { |
|
437 | + if ($ticket instanceof EE_Ticket) { |
|
438 | + if ($format) { |
|
439 | + $html .= '<li id="ee-event-tickets-li-' |
|
440 | + . esc_attr($ticket->ID()) |
|
441 | + . '" class="ee-event-tickets-li">'; |
|
442 | + $html .= esc_html($ticket->name()) . ' '; |
|
443 | + $html .= EEH_Template::format_currency( |
|
444 | + $ticket->get_ticket_total_with_taxes() |
|
445 | + ); // already escaped |
|
446 | + $html .= '</li>'; |
|
447 | + } else { |
|
448 | + $html[] = $ticket; |
|
449 | + } |
|
450 | + } |
|
451 | + } |
|
452 | + if ($format) { |
|
453 | + $html .= '</ul>'; |
|
454 | + } |
|
455 | + if ($echo && $format) { |
|
456 | + echo wp_kses($html, AllowedTags::getAllowedTags()); |
|
457 | + return ''; |
|
458 | + } |
|
459 | + return $html; |
|
460 | + } |
|
461 | + return ''; |
|
462 | + } |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | if (! function_exists('espresso_event_date_obj')) { |
466 | - /** |
|
467 | - * espresso_event_date_obj |
|
468 | - * returns the primary date object for an event |
|
469 | - * |
|
470 | - * @param bool $EVT_ID |
|
471 | - * @return EE_Datetime|null |
|
472 | - * @throws EE_Error |
|
473 | - * @throws ReflectionException |
|
474 | - */ |
|
475 | - function espresso_event_date_obj($EVT_ID = false) |
|
476 | - { |
|
477 | - return EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
478 | - } |
|
466 | + /** |
|
467 | + * espresso_event_date_obj |
|
468 | + * returns the primary date object for an event |
|
469 | + * |
|
470 | + * @param bool $EVT_ID |
|
471 | + * @return EE_Datetime|null |
|
472 | + * @throws EE_Error |
|
473 | + * @throws ReflectionException |
|
474 | + */ |
|
475 | + function espresso_event_date_obj($EVT_ID = false) |
|
476 | + { |
|
477 | + return EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
478 | + } |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | |
482 | 482 | if (! function_exists('espresso_event_date')) { |
483 | - /** |
|
484 | - * espresso_event_date |
|
485 | - * returns the primary date for an event |
|
486 | - * |
|
487 | - * @param string $date_format |
|
488 | - * @param string $time_format |
|
489 | - * @param bool $EVT_ID |
|
490 | - * @param bool $echo |
|
491 | - * @return string |
|
492 | - * @throws EE_Error |
|
493 | - * @throws ReflectionException |
|
494 | - */ |
|
495 | - function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = false, $echo = true) |
|
496 | - { |
|
497 | - $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
498 | - $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
499 | - $date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format); |
|
500 | - $time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format); |
|
501 | - if ($echo) { |
|
502 | - echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); // already escaped |
|
503 | - return ''; |
|
504 | - } |
|
505 | - return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
506 | - |
|
507 | - } |
|
483 | + /** |
|
484 | + * espresso_event_date |
|
485 | + * returns the primary date for an event |
|
486 | + * |
|
487 | + * @param string $date_format |
|
488 | + * @param string $time_format |
|
489 | + * @param bool $EVT_ID |
|
490 | + * @param bool $echo |
|
491 | + * @return string |
|
492 | + * @throws EE_Error |
|
493 | + * @throws ReflectionException |
|
494 | + */ |
|
495 | + function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = false, $echo = true) |
|
496 | + { |
|
497 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
498 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
499 | + $date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format); |
|
500 | + $time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format); |
|
501 | + if ($echo) { |
|
502 | + echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); // already escaped |
|
503 | + return ''; |
|
504 | + } |
|
505 | + return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
506 | + |
|
507 | + } |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | |
511 | 511 | if (! function_exists('espresso_list_of_event_dates')) { |
512 | - /** |
|
513 | - * espresso_list_of_event_dates |
|
514 | - * returns a unordered list of dates for an event |
|
515 | - * |
|
516 | - * @param int $EVT_ID |
|
517 | - * @param string $date_format |
|
518 | - * @param string $time_format |
|
519 | - * @param bool $echo |
|
520 | - * @param null $show_expired |
|
521 | - * @param bool $format |
|
522 | - * @param bool $add_breaks |
|
523 | - * @param null $limit |
|
524 | - * @return string |
|
525 | - * @throws EE_Error |
|
526 | - * @throws ReflectionException |
|
527 | - */ |
|
528 | - function espresso_list_of_event_dates( |
|
529 | - $EVT_ID = 0, |
|
530 | - $date_format = '', |
|
531 | - $time_format = '', |
|
532 | - $echo = true, |
|
533 | - $show_expired = null, |
|
534 | - $format = true, |
|
535 | - $add_breaks = true, |
|
536 | - $limit = null |
|
537 | - ) { |
|
538 | - $allowedtags = AllowedTags::getAllowedTags(); |
|
539 | - $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
540 | - $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
541 | - $date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format); |
|
542 | - $time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format); |
|
543 | - $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, false, $limit); |
|
544 | - if (! $format) { |
|
545 | - return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes); |
|
546 | - } |
|
547 | - $newline = $add_breaks ? '<br />' : ''; |
|
548 | - if (is_array($datetimes) && ! empty($datetimes)) { |
|
549 | - global $post; |
|
550 | - $html = |
|
551 | - '<ul id="ee-event-datetimes-ul-' . esc_attr($post->ID) . '" class="ee-event-datetimes-ul ee-clearfix">'; |
|
552 | - foreach ($datetimes as $datetime) { |
|
553 | - if ($datetime instanceof EE_Datetime) { |
|
554 | - |
|
555 | - $datetime_name = $datetime->name(); |
|
556 | - $datetime_html = ! empty($datetime_name) |
|
557 | - ? ' |
|
512 | + /** |
|
513 | + * espresso_list_of_event_dates |
|
514 | + * returns a unordered list of dates for an event |
|
515 | + * |
|
516 | + * @param int $EVT_ID |
|
517 | + * @param string $date_format |
|
518 | + * @param string $time_format |
|
519 | + * @param bool $echo |
|
520 | + * @param null $show_expired |
|
521 | + * @param bool $format |
|
522 | + * @param bool $add_breaks |
|
523 | + * @param null $limit |
|
524 | + * @return string |
|
525 | + * @throws EE_Error |
|
526 | + * @throws ReflectionException |
|
527 | + */ |
|
528 | + function espresso_list_of_event_dates( |
|
529 | + $EVT_ID = 0, |
|
530 | + $date_format = '', |
|
531 | + $time_format = '', |
|
532 | + $echo = true, |
|
533 | + $show_expired = null, |
|
534 | + $format = true, |
|
535 | + $add_breaks = true, |
|
536 | + $limit = null |
|
537 | + ) { |
|
538 | + $allowedtags = AllowedTags::getAllowedTags(); |
|
539 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
540 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
541 | + $date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format); |
|
542 | + $time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format); |
|
543 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, false, $limit); |
|
544 | + if (! $format) { |
|
545 | + return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes); |
|
546 | + } |
|
547 | + $newline = $add_breaks ? '<br />' : ''; |
|
548 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
549 | + global $post; |
|
550 | + $html = |
|
551 | + '<ul id="ee-event-datetimes-ul-' . esc_attr($post->ID) . '" class="ee-event-datetimes-ul ee-clearfix">'; |
|
552 | + foreach ($datetimes as $datetime) { |
|
553 | + if ($datetime instanceof EE_Datetime) { |
|
554 | + |
|
555 | + $datetime_name = $datetime->name(); |
|
556 | + $datetime_html = ! empty($datetime_name) |
|
557 | + ? ' |
|
558 | 558 | <strong class="ee-event-datetimes-li-date-name"> |
559 | 559 | ' . esc_html($datetime_name) . ' |
560 | 560 | </strong>' . $newline |
561 | - : ''; |
|
561 | + : ''; |
|
562 | 562 | |
563 | - $datetime_description = $datetime->description(); |
|
564 | - $datetime_html .= ! empty($datetime_description) |
|
565 | - ? ' |
|
563 | + $datetime_description = $datetime->description(); |
|
564 | + $datetime_html .= ! empty($datetime_description) |
|
565 | + ? ' |
|
566 | 566 | <span class="ee-event-datetimes-li-date-desc"> |
567 | 567 | ' . wp_kses($datetime_description, $allowedtags) . ' |
568 | 568 | </span>' . $newline |
569 | - : ''; |
|
569 | + : ''; |
|
570 | 570 | |
571 | - $datetime_html .= ' |
|
571 | + $datetime_html .= ' |
|
572 | 572 | <span class="dashicons dashicons-calendar"></span> |
573 | 573 | <span class="ee-event-datetimes-li-daterange">' . $datetime->date_range($date_format) . '</span> |
574 | 574 | <br/> |
@@ -576,482 +576,482 @@ discard block |
||
576 | 576 | <span class="ee-event-datetimes-li-timerange">' . $datetime->time_range($time_format) . '</span> |
577 | 577 | '; |
578 | 578 | |
579 | - $datetime_html = apply_filters( |
|
580 | - 'FHEE__espresso_list_of_event_dates__datetime_html', |
|
581 | - $datetime_html, |
|
582 | - $datetime |
|
583 | - ); |
|
579 | + $datetime_html = apply_filters( |
|
580 | + 'FHEE__espresso_list_of_event_dates__datetime_html', |
|
581 | + $datetime_html, |
|
582 | + $datetime |
|
583 | + ); |
|
584 | 584 | |
585 | - $DTD_ID = esc_attr($datetime->ID()); |
|
586 | - $active_status = esc_attr(' ee-event-datetimes-li-' . $datetime->get_active_status()); |
|
585 | + $DTD_ID = esc_attr($datetime->ID()); |
|
586 | + $active_status = esc_attr(' ee-event-datetimes-li-' . $datetime->get_active_status()); |
|
587 | 587 | |
588 | - $html .= ' |
|
588 | + $html .= ' |
|
589 | 589 | <li id="ee-event-datetimes-li-' . $DTD_ID . '" class="ee-event-datetimes-li' . $active_status . '"> |
590 | 590 | ' . $datetime_html . ' |
591 | 591 | </li>'; |
592 | - } |
|
593 | - } |
|
594 | - $html .= '</ul>'; |
|
595 | - } else { |
|
596 | - $html = |
|
597 | - ' |
|
592 | + } |
|
593 | + } |
|
594 | + $html .= '</ul>'; |
|
595 | + } else { |
|
596 | + $html = |
|
597 | + ' |
|
598 | 598 | <p> |
599 | 599 | <span class="dashicons dashicons-marker pink-text"></span> |
600 | 600 | ' . esc_html__( |
601 | - 'There are no upcoming dates for this event.', |
|
602 | - 'event_espresso' |
|
603 | - ) . ' |
|
601 | + 'There are no upcoming dates for this event.', |
|
602 | + 'event_espresso' |
|
603 | + ) . ' |
|
604 | 604 | </p> |
605 | 605 | <br/>'; |
606 | - } |
|
607 | - if ($echo) { |
|
608 | - echo wp_kses($html, AllowedTags::getWithFormTags()); |
|
609 | - return ''; |
|
610 | - } |
|
611 | - return $html; |
|
612 | - } |
|
606 | + } |
|
607 | + if ($echo) { |
|
608 | + echo wp_kses($html, AllowedTags::getWithFormTags()); |
|
609 | + return ''; |
|
610 | + } |
|
611 | + return $html; |
|
612 | + } |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | |
616 | 616 | if (! function_exists('espresso_event_end_date')) { |
617 | - /** |
|
618 | - * espresso_event_end_date |
|
619 | - * returns the last date for an event |
|
620 | - * |
|
621 | - * @param string $date_format |
|
622 | - * @param string $time_format |
|
623 | - * @param bool $EVT_ID |
|
624 | - * @param bool $echo |
|
625 | - * @return string |
|
626 | - * @throws EE_Error |
|
627 | - * @throws ReflectionException |
|
628 | - */ |
|
629 | - function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = false, $echo = true) |
|
630 | - { |
|
631 | - $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
632 | - $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
633 | - $date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format); |
|
634 | - $time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format); |
|
635 | - if ($echo) { |
|
636 | - echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); // already escaped |
|
637 | - return ''; |
|
638 | - } |
|
639 | - return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
640 | - } |
|
617 | + /** |
|
618 | + * espresso_event_end_date |
|
619 | + * returns the last date for an event |
|
620 | + * |
|
621 | + * @param string $date_format |
|
622 | + * @param string $time_format |
|
623 | + * @param bool $EVT_ID |
|
624 | + * @param bool $echo |
|
625 | + * @return string |
|
626 | + * @throws EE_Error |
|
627 | + * @throws ReflectionException |
|
628 | + */ |
|
629 | + function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = false, $echo = true) |
|
630 | + { |
|
631 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
632 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
633 | + $date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format); |
|
634 | + $time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format); |
|
635 | + if ($echo) { |
|
636 | + echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); // already escaped |
|
637 | + return ''; |
|
638 | + } |
|
639 | + return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
640 | + } |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | if (! function_exists('espresso_event_date_range')) { |
644 | - /** |
|
645 | - * espresso_event_date_range |
|
646 | - * returns the first and last chronologically ordered dates for an event (if different) |
|
647 | - * |
|
648 | - * @param string $date_format |
|
649 | - * @param string $time_format |
|
650 | - * @param string $single_date_format |
|
651 | - * @param string $single_time_format |
|
652 | - * @param bool $EVT_ID |
|
653 | - * @param bool $echo |
|
654 | - * @return string |
|
655 | - * @throws EE_Error |
|
656 | - * @throws ReflectionException |
|
657 | - */ |
|
658 | - function espresso_event_date_range( |
|
659 | - $date_format = '', |
|
660 | - $time_format = '', |
|
661 | - $single_date_format = '', |
|
662 | - $single_time_format = '', |
|
663 | - $EVT_ID = false, |
|
664 | - $echo = true |
|
665 | - ) { |
|
666 | - // set and filter date and time formats when a range is returned |
|
667 | - $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
668 | - $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format); |
|
669 | - // get the start and end date with NO time portion |
|
670 | - $the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID); |
|
671 | - $the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID); |
|
672 | - // now we can determine if date range spans more than one day |
|
673 | - if ($the_event_date != $the_event_end_date) { |
|
674 | - $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
675 | - $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format); |
|
676 | - $html = sprintf( |
|
677 | - /* translators: 1: first event date, 2: last event date */ |
|
678 | - esc_html__('%1$s - %2$s', 'event_espresso'), |
|
679 | - EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID), |
|
680 | - EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID) |
|
681 | - ); |
|
682 | - } else { |
|
683 | - // set and filter date and time formats when only a single datetime is returned |
|
684 | - $single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format'); |
|
685 | - $single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format'); |
|
686 | - $single_date_format = |
|
687 | - apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format); |
|
688 | - $single_time_format = |
|
689 | - apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format); |
|
690 | - $html = |
|
691 | - EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID); |
|
692 | - } |
|
693 | - if ($echo) { |
|
694 | - echo wp_kses($html, AllowedTags::getAllowedTags()); |
|
695 | - return ''; |
|
696 | - } |
|
697 | - return $html; |
|
698 | - } |
|
644 | + /** |
|
645 | + * espresso_event_date_range |
|
646 | + * returns the first and last chronologically ordered dates for an event (if different) |
|
647 | + * |
|
648 | + * @param string $date_format |
|
649 | + * @param string $time_format |
|
650 | + * @param string $single_date_format |
|
651 | + * @param string $single_time_format |
|
652 | + * @param bool $EVT_ID |
|
653 | + * @param bool $echo |
|
654 | + * @return string |
|
655 | + * @throws EE_Error |
|
656 | + * @throws ReflectionException |
|
657 | + */ |
|
658 | + function espresso_event_date_range( |
|
659 | + $date_format = '', |
|
660 | + $time_format = '', |
|
661 | + $single_date_format = '', |
|
662 | + $single_time_format = '', |
|
663 | + $EVT_ID = false, |
|
664 | + $echo = true |
|
665 | + ) { |
|
666 | + // set and filter date and time formats when a range is returned |
|
667 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
668 | + $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format); |
|
669 | + // get the start and end date with NO time portion |
|
670 | + $the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID); |
|
671 | + $the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID); |
|
672 | + // now we can determine if date range spans more than one day |
|
673 | + if ($the_event_date != $the_event_end_date) { |
|
674 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
675 | + $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format); |
|
676 | + $html = sprintf( |
|
677 | + /* translators: 1: first event date, 2: last event date */ |
|
678 | + esc_html__('%1$s - %2$s', 'event_espresso'), |
|
679 | + EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID), |
|
680 | + EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID) |
|
681 | + ); |
|
682 | + } else { |
|
683 | + // set and filter date and time formats when only a single datetime is returned |
|
684 | + $single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format'); |
|
685 | + $single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format'); |
|
686 | + $single_date_format = |
|
687 | + apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format); |
|
688 | + $single_time_format = |
|
689 | + apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format); |
|
690 | + $html = |
|
691 | + EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID); |
|
692 | + } |
|
693 | + if ($echo) { |
|
694 | + echo wp_kses($html, AllowedTags::getAllowedTags()); |
|
695 | + return ''; |
|
696 | + } |
|
697 | + return $html; |
|
698 | + } |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | if (! function_exists('espresso_next_upcoming_datetime_obj')) { |
702 | - /** |
|
703 | - * espresso_next_upcoming_datetime_obj |
|
704 | - * returns the next upcoming datetime object for an event |
|
705 | - * |
|
706 | - * @param int $EVT_ID |
|
707 | - * @return EE_Datetime|null |
|
708 | - * @throws EE_Error |
|
709 | - */ |
|
710 | - function espresso_next_upcoming_datetime_obj($EVT_ID = 0) |
|
711 | - { |
|
712 | - return EEH_Event_View::get_next_upcoming_date_obj($EVT_ID); |
|
713 | - } |
|
702 | + /** |
|
703 | + * espresso_next_upcoming_datetime_obj |
|
704 | + * returns the next upcoming datetime object for an event |
|
705 | + * |
|
706 | + * @param int $EVT_ID |
|
707 | + * @return EE_Datetime|null |
|
708 | + * @throws EE_Error |
|
709 | + */ |
|
710 | + function espresso_next_upcoming_datetime_obj($EVT_ID = 0) |
|
711 | + { |
|
712 | + return EEH_Event_View::get_next_upcoming_date_obj($EVT_ID); |
|
713 | + } |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | if (! function_exists('espresso_next_upcoming_datetime')) { |
717 | - /** |
|
718 | - * espresso_next_upcoming_datetime |
|
719 | - * returns the start date and time for the next upcoming event. |
|
720 | - * |
|
721 | - * @param string $date_format |
|
722 | - * @param string $time_format |
|
723 | - * @param int $EVT_ID |
|
724 | - * @param bool $echo |
|
725 | - * @return string |
|
726 | - * @throws EE_Error |
|
727 | - * @throws ReflectionException |
|
728 | - */ |
|
729 | - function espresso_next_upcoming_datetime($date_format = '', $time_format = '', $EVT_ID = 0, $echo = true) |
|
730 | - { |
|
731 | - |
|
732 | - $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
733 | - $date_format = apply_filters('FHEE__espresso_next_upcoming_datetime__date_format', $date_format); |
|
734 | - |
|
735 | - $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
736 | - $time_format = apply_filters('FHEE__espresso_next_upcoming_datetime__time_format', $time_format); |
|
737 | - |
|
738 | - $datetime_format = trim($date_format . ' ' . $time_format); |
|
739 | - |
|
740 | - $datetime = espresso_next_upcoming_datetime_obj($EVT_ID); |
|
741 | - |
|
742 | - if (! $datetime instanceof EE_Datetime) { |
|
743 | - return ''; |
|
744 | - } |
|
745 | - if ($echo) { |
|
746 | - echo esc_html($datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format)); |
|
747 | - return ''; |
|
748 | - } |
|
749 | - return $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format); |
|
750 | - } |
|
717 | + /** |
|
718 | + * espresso_next_upcoming_datetime |
|
719 | + * returns the start date and time for the next upcoming event. |
|
720 | + * |
|
721 | + * @param string $date_format |
|
722 | + * @param string $time_format |
|
723 | + * @param int $EVT_ID |
|
724 | + * @param bool $echo |
|
725 | + * @return string |
|
726 | + * @throws EE_Error |
|
727 | + * @throws ReflectionException |
|
728 | + */ |
|
729 | + function espresso_next_upcoming_datetime($date_format = '', $time_format = '', $EVT_ID = 0, $echo = true) |
|
730 | + { |
|
731 | + |
|
732 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
733 | + $date_format = apply_filters('FHEE__espresso_next_upcoming_datetime__date_format', $date_format); |
|
734 | + |
|
735 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
736 | + $time_format = apply_filters('FHEE__espresso_next_upcoming_datetime__time_format', $time_format); |
|
737 | + |
|
738 | + $datetime_format = trim($date_format . ' ' . $time_format); |
|
739 | + |
|
740 | + $datetime = espresso_next_upcoming_datetime_obj($EVT_ID); |
|
741 | + |
|
742 | + if (! $datetime instanceof EE_Datetime) { |
|
743 | + return ''; |
|
744 | + } |
|
745 | + if ($echo) { |
|
746 | + echo esc_html($datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format)); |
|
747 | + return ''; |
|
748 | + } |
|
749 | + return $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format); |
|
750 | + } |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | if (! function_exists('espresso_event_date_as_calendar_page')) { |
754 | - /** |
|
755 | - * espresso_event_date_as_calendar_page |
|
756 | - * returns the primary date for an event, stylized to appear as the page of a calendar |
|
757 | - * |
|
758 | - * @param bool $EVT_ID |
|
759 | - * @return void |
|
760 | - * @throws EE_Error |
|
761 | - * @throws ReflectionException |
|
762 | - */ |
|
763 | - function espresso_event_date_as_calendar_page($EVT_ID = false) |
|
764 | - { |
|
765 | - EEH_Event_View::event_date_as_calendar_page($EVT_ID); |
|
766 | - } |
|
754 | + /** |
|
755 | + * espresso_event_date_as_calendar_page |
|
756 | + * returns the primary date for an event, stylized to appear as the page of a calendar |
|
757 | + * |
|
758 | + * @param bool $EVT_ID |
|
759 | + * @return void |
|
760 | + * @throws EE_Error |
|
761 | + * @throws ReflectionException |
|
762 | + */ |
|
763 | + function espresso_event_date_as_calendar_page($EVT_ID = false) |
|
764 | + { |
|
765 | + EEH_Event_View::event_date_as_calendar_page($EVT_ID); |
|
766 | + } |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | |
770 | 770 | if (! function_exists('espresso_event_link_url')) { |
771 | - /** |
|
772 | - * espresso_event_link_url |
|
773 | - * |
|
774 | - * @param int $EVT_ID |
|
775 | - * @param bool $echo |
|
776 | - * @return string |
|
777 | - * @throws EE_Error |
|
778 | - * @throws ReflectionException |
|
779 | - */ |
|
780 | - function espresso_event_link_url($EVT_ID = 0, $echo = true) |
|
781 | - { |
|
782 | - if ($echo) { |
|
783 | - echo EEH_Event_View::event_link_url($EVT_ID); // already escaped |
|
784 | - return ''; |
|
785 | - } |
|
786 | - return EEH_Event_View::event_link_url($EVT_ID); |
|
787 | - } |
|
771 | + /** |
|
772 | + * espresso_event_link_url |
|
773 | + * |
|
774 | + * @param int $EVT_ID |
|
775 | + * @param bool $echo |
|
776 | + * @return string |
|
777 | + * @throws EE_Error |
|
778 | + * @throws ReflectionException |
|
779 | + */ |
|
780 | + function espresso_event_link_url($EVT_ID = 0, $echo = true) |
|
781 | + { |
|
782 | + if ($echo) { |
|
783 | + echo EEH_Event_View::event_link_url($EVT_ID); // already escaped |
|
784 | + return ''; |
|
785 | + } |
|
786 | + return EEH_Event_View::event_link_url($EVT_ID); |
|
787 | + } |
|
788 | 788 | } |
789 | 789 | |
790 | 790 | |
791 | 791 | if (! function_exists('espresso_event_has_content_or_excerpt')) { |
792 | - /** |
|
793 | - * espresso_event_has_content_or_excerpt |
|
794 | - * |
|
795 | - * @access public |
|
796 | - * @param bool $EVT_ID |
|
797 | - * @return boolean |
|
798 | - * @throws EE_Error |
|
799 | - * @throws ReflectionException |
|
800 | - */ |
|
801 | - function espresso_event_has_content_or_excerpt($EVT_ID = false) |
|
802 | - { |
|
803 | - return EEH_Event_View::event_has_content_or_excerpt($EVT_ID); |
|
804 | - } |
|
792 | + /** |
|
793 | + * espresso_event_has_content_or_excerpt |
|
794 | + * |
|
795 | + * @access public |
|
796 | + * @param bool $EVT_ID |
|
797 | + * @return boolean |
|
798 | + * @throws EE_Error |
|
799 | + * @throws ReflectionException |
|
800 | + */ |
|
801 | + function espresso_event_has_content_or_excerpt($EVT_ID = false) |
|
802 | + { |
|
803 | + return EEH_Event_View::event_has_content_or_excerpt($EVT_ID); |
|
804 | + } |
|
805 | 805 | } |
806 | 806 | |
807 | 807 | |
808 | 808 | if (! function_exists('espresso_event_content_or_excerpt')) { |
809 | - /** |
|
810 | - * espresso_event_content_or_excerpt |
|
811 | - * |
|
812 | - * @param int $num_words |
|
813 | - * @param null $more |
|
814 | - * @param bool $echo |
|
815 | - * @return string |
|
816 | - */ |
|
817 | - function espresso_event_content_or_excerpt($num_words = 55, $more = null, $echo = true) |
|
818 | - { |
|
819 | - if ($echo) { |
|
820 | - echo EEH_Event_View::event_content_or_excerpt($num_words, $more); // already escaped |
|
821 | - return ''; |
|
822 | - } |
|
823 | - return EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
824 | - } |
|
809 | + /** |
|
810 | + * espresso_event_content_or_excerpt |
|
811 | + * |
|
812 | + * @param int $num_words |
|
813 | + * @param null $more |
|
814 | + * @param bool $echo |
|
815 | + * @return string |
|
816 | + */ |
|
817 | + function espresso_event_content_or_excerpt($num_words = 55, $more = null, $echo = true) |
|
818 | + { |
|
819 | + if ($echo) { |
|
820 | + echo EEH_Event_View::event_content_or_excerpt($num_words, $more); // already escaped |
|
821 | + return ''; |
|
822 | + } |
|
823 | + return EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
824 | + } |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | |
828 | 828 | if (! function_exists('espresso_event_phone')) { |
829 | - /** |
|
830 | - * espresso_event_phone |
|
831 | - * |
|
832 | - * @param int $EVT_ID |
|
833 | - * @param bool $echo |
|
834 | - * @return string |
|
835 | - * @throws EE_Error |
|
836 | - * @throws ReflectionException |
|
837 | - */ |
|
838 | - function espresso_event_phone($EVT_ID = 0, $echo = true) |
|
839 | - { |
|
840 | - if ($echo) { |
|
841 | - echo EEH_Event_View::event_phone($EVT_ID); // already escaped |
|
842 | - return ''; |
|
843 | - } |
|
844 | - return EEH_Event_View::event_phone($EVT_ID); |
|
845 | - } |
|
829 | + /** |
|
830 | + * espresso_event_phone |
|
831 | + * |
|
832 | + * @param int $EVT_ID |
|
833 | + * @param bool $echo |
|
834 | + * @return string |
|
835 | + * @throws EE_Error |
|
836 | + * @throws ReflectionException |
|
837 | + */ |
|
838 | + function espresso_event_phone($EVT_ID = 0, $echo = true) |
|
839 | + { |
|
840 | + if ($echo) { |
|
841 | + echo EEH_Event_View::event_phone($EVT_ID); // already escaped |
|
842 | + return ''; |
|
843 | + } |
|
844 | + return EEH_Event_View::event_phone($EVT_ID); |
|
845 | + } |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | |
849 | 849 | if (! function_exists('espresso_edit_event_link')) { |
850 | - /** |
|
851 | - * espresso_edit_event_link |
|
852 | - * returns a link to edit an event |
|
853 | - * |
|
854 | - * @param int $EVT_ID |
|
855 | - * @param bool $echo |
|
856 | - * @return string |
|
857 | - * @throws EE_Error |
|
858 | - * @throws ReflectionException |
|
859 | - */ |
|
860 | - function espresso_edit_event_link($EVT_ID = 0, $echo = true) |
|
861 | - { |
|
862 | - if ($echo) { |
|
863 | - echo EEH_Event_View::edit_event_link($EVT_ID); // already escaped |
|
864 | - return ''; |
|
865 | - } |
|
866 | - return EEH_Event_View::edit_event_link($EVT_ID); |
|
867 | - } |
|
850 | + /** |
|
851 | + * espresso_edit_event_link |
|
852 | + * returns a link to edit an event |
|
853 | + * |
|
854 | + * @param int $EVT_ID |
|
855 | + * @param bool $echo |
|
856 | + * @return string |
|
857 | + * @throws EE_Error |
|
858 | + * @throws ReflectionException |
|
859 | + */ |
|
860 | + function espresso_edit_event_link($EVT_ID = 0, $echo = true) |
|
861 | + { |
|
862 | + if ($echo) { |
|
863 | + echo EEH_Event_View::edit_event_link($EVT_ID); // already escaped |
|
864 | + return ''; |
|
865 | + } |
|
866 | + return EEH_Event_View::edit_event_link($EVT_ID); |
|
867 | + } |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | |
871 | 871 | if (! function_exists('espresso_organization_name')) { |
872 | - /** |
|
873 | - * espresso_organization_name |
|
874 | - * |
|
875 | - * @param bool $echo |
|
876 | - * @return string |
|
877 | - * @throws EE_Error |
|
878 | - */ |
|
879 | - function espresso_organization_name($echo = true) |
|
880 | - { |
|
881 | - if ($echo) { |
|
882 | - echo EE_Registry::instance()->CFG->organization->get_pretty('name'); // already escaped |
|
883 | - return ''; |
|
884 | - } |
|
885 | - return EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
886 | - } |
|
872 | + /** |
|
873 | + * espresso_organization_name |
|
874 | + * |
|
875 | + * @param bool $echo |
|
876 | + * @return string |
|
877 | + * @throws EE_Error |
|
878 | + */ |
|
879 | + function espresso_organization_name($echo = true) |
|
880 | + { |
|
881 | + if ($echo) { |
|
882 | + echo EE_Registry::instance()->CFG->organization->get_pretty('name'); // already escaped |
|
883 | + return ''; |
|
884 | + } |
|
885 | + return EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
886 | + } |
|
887 | 887 | } |
888 | 888 | |
889 | 889 | if (! function_exists('espresso_organization_address')) { |
890 | - /** |
|
891 | - * espresso_organization_address |
|
892 | - * |
|
893 | - * @param string $type |
|
894 | - * @return string |
|
895 | - */ |
|
896 | - function espresso_organization_address($type = 'inline') |
|
897 | - { |
|
898 | - if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) { |
|
899 | - $address = new EventEspresso\core\domain\entities\GenericAddress( |
|
900 | - EE_Registry::instance()->CFG->organization->address_1, |
|
901 | - EE_Registry::instance()->CFG->organization->address_2, |
|
902 | - EE_Registry::instance()->CFG->organization->city, |
|
903 | - EE_Registry::instance()->CFG->organization->STA_ID, |
|
904 | - EE_Registry::instance()->CFG->organization->zip, |
|
905 | - EE_Registry::instance()->CFG->organization->CNT_ISO |
|
906 | - ); |
|
907 | - return EEH_Address::format($address, $type); |
|
908 | - } |
|
909 | - return ''; |
|
910 | - } |
|
890 | + /** |
|
891 | + * espresso_organization_address |
|
892 | + * |
|
893 | + * @param string $type |
|
894 | + * @return string |
|
895 | + */ |
|
896 | + function espresso_organization_address($type = 'inline') |
|
897 | + { |
|
898 | + if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) { |
|
899 | + $address = new EventEspresso\core\domain\entities\GenericAddress( |
|
900 | + EE_Registry::instance()->CFG->organization->address_1, |
|
901 | + EE_Registry::instance()->CFG->organization->address_2, |
|
902 | + EE_Registry::instance()->CFG->organization->city, |
|
903 | + EE_Registry::instance()->CFG->organization->STA_ID, |
|
904 | + EE_Registry::instance()->CFG->organization->zip, |
|
905 | + EE_Registry::instance()->CFG->organization->CNT_ISO |
|
906 | + ); |
|
907 | + return EEH_Address::format($address, $type); |
|
908 | + } |
|
909 | + return ''; |
|
910 | + } |
|
911 | 911 | } |
912 | 912 | |
913 | 913 | if (! function_exists('espresso_organization_email')) { |
914 | - /** |
|
915 | - * espresso_organization_email |
|
916 | - * |
|
917 | - * @param bool $echo |
|
918 | - * @return string |
|
919 | - * @throws EE_Error |
|
920 | - */ |
|
921 | - function espresso_organization_email($echo = true) |
|
922 | - { |
|
923 | - if ($echo) { |
|
924 | - echo EE_Registry::instance()->CFG->organization->get_pretty('email'); // already escaped |
|
925 | - return ''; |
|
926 | - } |
|
927 | - return EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
928 | - } |
|
914 | + /** |
|
915 | + * espresso_organization_email |
|
916 | + * |
|
917 | + * @param bool $echo |
|
918 | + * @return string |
|
919 | + * @throws EE_Error |
|
920 | + */ |
|
921 | + function espresso_organization_email($echo = true) |
|
922 | + { |
|
923 | + if ($echo) { |
|
924 | + echo EE_Registry::instance()->CFG->organization->get_pretty('email'); // already escaped |
|
925 | + return ''; |
|
926 | + } |
|
927 | + return EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
928 | + } |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | if (! function_exists('espresso_organization_logo_url')) { |
932 | - /** |
|
933 | - * espresso_organization_logo_url |
|
934 | - * |
|
935 | - * @param bool $echo |
|
936 | - * @return string |
|
937 | - * @throws EE_Error |
|
938 | - */ |
|
939 | - function espresso_organization_logo_url($echo = true) |
|
940 | - { |
|
941 | - if ($echo) { |
|
942 | - echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); // already escaped |
|
943 | - return ''; |
|
944 | - } |
|
945 | - return EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
946 | - } |
|
932 | + /** |
|
933 | + * espresso_organization_logo_url |
|
934 | + * |
|
935 | + * @param bool $echo |
|
936 | + * @return string |
|
937 | + * @throws EE_Error |
|
938 | + */ |
|
939 | + function espresso_organization_logo_url($echo = true) |
|
940 | + { |
|
941 | + if ($echo) { |
|
942 | + echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); // already escaped |
|
943 | + return ''; |
|
944 | + } |
|
945 | + return EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
946 | + } |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | if (! function_exists('espresso_organization_facebook')) { |
950 | - /** |
|
951 | - * espresso_organization_facebook |
|
952 | - * |
|
953 | - * @param bool $echo |
|
954 | - * @return string |
|
955 | - * @throws EE_Error |
|
956 | - */ |
|
957 | - function espresso_organization_facebook($echo = true) |
|
958 | - { |
|
959 | - if ($echo) { |
|
960 | - echo EE_Registry::instance()->CFG->organization->get_pretty('facebook'); // already escaped |
|
961 | - return ''; |
|
962 | - } |
|
963 | - return EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
964 | - } |
|
950 | + /** |
|
951 | + * espresso_organization_facebook |
|
952 | + * |
|
953 | + * @param bool $echo |
|
954 | + * @return string |
|
955 | + * @throws EE_Error |
|
956 | + */ |
|
957 | + function espresso_organization_facebook($echo = true) |
|
958 | + { |
|
959 | + if ($echo) { |
|
960 | + echo EE_Registry::instance()->CFG->organization->get_pretty('facebook'); // already escaped |
|
961 | + return ''; |
|
962 | + } |
|
963 | + return EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
964 | + } |
|
965 | 965 | } |
966 | 966 | |
967 | 967 | if (! function_exists('espresso_organization_twitter')) { |
968 | - /** |
|
969 | - * espresso_organization_twitter |
|
970 | - * |
|
971 | - * @param bool $echo |
|
972 | - * @return string |
|
973 | - * @throws EE_Error |
|
974 | - */ |
|
975 | - function espresso_organization_twitter($echo = true) |
|
976 | - { |
|
977 | - if ($echo) { |
|
978 | - echo EE_Registry::instance()->CFG->organization->get_pretty('twitter'); // already escaped |
|
979 | - return ''; |
|
980 | - } |
|
981 | - return EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
982 | - } |
|
968 | + /** |
|
969 | + * espresso_organization_twitter |
|
970 | + * |
|
971 | + * @param bool $echo |
|
972 | + * @return string |
|
973 | + * @throws EE_Error |
|
974 | + */ |
|
975 | + function espresso_organization_twitter($echo = true) |
|
976 | + { |
|
977 | + if ($echo) { |
|
978 | + echo EE_Registry::instance()->CFG->organization->get_pretty('twitter'); // already escaped |
|
979 | + return ''; |
|
980 | + } |
|
981 | + return EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
982 | + } |
|
983 | 983 | } |
984 | 984 | |
985 | 985 | if (! function_exists('espresso_organization_linkedin')) { |
986 | - /** |
|
987 | - * espresso_organization_linkedin |
|
988 | - * |
|
989 | - * @param bool $echo |
|
990 | - * @return string |
|
991 | - * @throws EE_Error |
|
992 | - */ |
|
993 | - function espresso_organization_linkedin($echo = true) |
|
994 | - { |
|
995 | - if ($echo) { |
|
996 | - echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); // already escaped |
|
997 | - return ''; |
|
998 | - } |
|
999 | - return EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
1000 | - } |
|
986 | + /** |
|
987 | + * espresso_organization_linkedin |
|
988 | + * |
|
989 | + * @param bool $echo |
|
990 | + * @return string |
|
991 | + * @throws EE_Error |
|
992 | + */ |
|
993 | + function espresso_organization_linkedin($echo = true) |
|
994 | + { |
|
995 | + if ($echo) { |
|
996 | + echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); // already escaped |
|
997 | + return ''; |
|
998 | + } |
|
999 | + return EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
1000 | + } |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | if (! function_exists('espresso_organization_pinterest')) { |
1004 | - /** |
|
1005 | - * espresso_organization_pinterest |
|
1006 | - * |
|
1007 | - * @param bool $echo |
|
1008 | - * @return string |
|
1009 | - * @throws EE_Error |
|
1010 | - */ |
|
1011 | - function espresso_organization_pinterest($echo = true) |
|
1012 | - { |
|
1013 | - if ($echo) { |
|
1014 | - echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); // already escaped |
|
1015 | - return ''; |
|
1016 | - } |
|
1017 | - return EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
1018 | - } |
|
1004 | + /** |
|
1005 | + * espresso_organization_pinterest |
|
1006 | + * |
|
1007 | + * @param bool $echo |
|
1008 | + * @return string |
|
1009 | + * @throws EE_Error |
|
1010 | + */ |
|
1011 | + function espresso_organization_pinterest($echo = true) |
|
1012 | + { |
|
1013 | + if ($echo) { |
|
1014 | + echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); // already escaped |
|
1015 | + return ''; |
|
1016 | + } |
|
1017 | + return EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
1018 | + } |
|
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | if (! function_exists('espresso_organization_google')) { |
1022 | - /** |
|
1023 | - * espresso_organization_google |
|
1024 | - * |
|
1025 | - * @param bool $echo |
|
1026 | - * @return string |
|
1027 | - * @throws EE_Error |
|
1028 | - */ |
|
1029 | - function espresso_organization_google($echo = true) |
|
1030 | - { |
|
1031 | - if ($echo) { |
|
1032 | - echo EE_Registry::instance()->CFG->organization->get_pretty('google'); // already escaped |
|
1033 | - return ''; |
|
1034 | - } |
|
1035 | - return EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
1036 | - } |
|
1022 | + /** |
|
1023 | + * espresso_organization_google |
|
1024 | + * |
|
1025 | + * @param bool $echo |
|
1026 | + * @return string |
|
1027 | + * @throws EE_Error |
|
1028 | + */ |
|
1029 | + function espresso_organization_google($echo = true) |
|
1030 | + { |
|
1031 | + if ($echo) { |
|
1032 | + echo EE_Registry::instance()->CFG->organization->get_pretty('google'); // already escaped |
|
1033 | + return ''; |
|
1034 | + } |
|
1035 | + return EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
1036 | + } |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | if (! function_exists('espresso_organization_instagram')) { |
1040 | - /** |
|
1041 | - * espresso_organization_instagram |
|
1042 | - * |
|
1043 | - * @param bool $echo |
|
1044 | - * @return string |
|
1045 | - * @throws EE_Error |
|
1046 | - */ |
|
1047 | - function espresso_organization_instagram($echo = true) |
|
1048 | - { |
|
1049 | - if ($echo) { |
|
1050 | - echo EE_Registry::instance()->CFG->organization->get_pretty('instagram'); // already escaped |
|
1051 | - return ''; |
|
1052 | - } |
|
1053 | - return EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
1054 | - } |
|
1040 | + /** |
|
1041 | + * espresso_organization_instagram |
|
1042 | + * |
|
1043 | + * @param bool $echo |
|
1044 | + * @return string |
|
1045 | + * @throws EE_Error |
|
1046 | + */ |
|
1047 | + function espresso_organization_instagram($echo = true) |
|
1048 | + { |
|
1049 | + if ($echo) { |
|
1050 | + echo EE_Registry::instance()->CFG->organization->get_pretty('instagram'); // already escaped |
|
1051 | + return ''; |
|
1052 | + } |
|
1053 | + return EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
1054 | + } |
|
1055 | 1055 | } |
1056 | 1056 | |
1057 | 1057 | |
@@ -1059,345 +1059,345 @@ discard block |
||
1059 | 1059 | |
1060 | 1060 | |
1061 | 1061 | if (! function_exists('espresso_event_venues')) { |
1062 | - /** |
|
1063 | - * espresso_event_venues |
|
1064 | - * |
|
1065 | - * @return array all venues related to an event |
|
1066 | - * @throws EE_Error |
|
1067 | - * @throws ReflectionException |
|
1068 | - */ |
|
1069 | - function espresso_event_venues() |
|
1070 | - { |
|
1071 | - return EEH_Venue_View::get_event_venues(); |
|
1072 | - } |
|
1062 | + /** |
|
1063 | + * espresso_event_venues |
|
1064 | + * |
|
1065 | + * @return array all venues related to an event |
|
1066 | + * @throws EE_Error |
|
1067 | + * @throws ReflectionException |
|
1068 | + */ |
|
1069 | + function espresso_event_venues() |
|
1070 | + { |
|
1071 | + return EEH_Venue_View::get_event_venues(); |
|
1072 | + } |
|
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | |
1076 | 1076 | if (! function_exists('espresso_venue_id')) { |
1077 | - /** |
|
1078 | - * espresso_venue_name |
|
1079 | - * |
|
1080 | - * @access public |
|
1081 | - * @param int $EVT_ID |
|
1082 | - * @return string |
|
1083 | - * @throws EE_Error |
|
1084 | - * @throws ReflectionException |
|
1085 | - */ |
|
1086 | - function espresso_venue_id($EVT_ID = 0) |
|
1087 | - { |
|
1088 | - $venue = EEH_Venue_View::get_venue($EVT_ID); |
|
1089 | - return $venue instanceof EE_Venue ? $venue->ID() : 0; |
|
1090 | - } |
|
1077 | + /** |
|
1078 | + * espresso_venue_name |
|
1079 | + * |
|
1080 | + * @access public |
|
1081 | + * @param int $EVT_ID |
|
1082 | + * @return string |
|
1083 | + * @throws EE_Error |
|
1084 | + * @throws ReflectionException |
|
1085 | + */ |
|
1086 | + function espresso_venue_id($EVT_ID = 0) |
|
1087 | + { |
|
1088 | + $venue = EEH_Venue_View::get_venue($EVT_ID); |
|
1089 | + return $venue instanceof EE_Venue ? $venue->ID() : 0; |
|
1090 | + } |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | |
1094 | 1094 | if (! function_exists('espresso_is_venue_private')) { |
1095 | - /** |
|
1096 | - * Return whether a venue is private or not. |
|
1097 | - * |
|
1098 | - * @param int $VNU_ID optional, the venue id to check. |
|
1099 | - * |
|
1100 | - * @return bool | null |
|
1101 | - * @throws EE_Error |
|
1102 | - * @throws ReflectionException |
|
1103 | - * @see EEH_Venue_View::get_venue() for more info on expected return results. |
|
1104 | - */ |
|
1105 | - function espresso_is_venue_private($VNU_ID = 0) |
|
1106 | - { |
|
1107 | - return EEH_Venue_View::is_venue_private($VNU_ID); |
|
1108 | - } |
|
1095 | + /** |
|
1096 | + * Return whether a venue is private or not. |
|
1097 | + * |
|
1098 | + * @param int $VNU_ID optional, the venue id to check. |
|
1099 | + * |
|
1100 | + * @return bool | null |
|
1101 | + * @throws EE_Error |
|
1102 | + * @throws ReflectionException |
|
1103 | + * @see EEH_Venue_View::get_venue() for more info on expected return results. |
|
1104 | + */ |
|
1105 | + function espresso_is_venue_private($VNU_ID = 0) |
|
1106 | + { |
|
1107 | + return EEH_Venue_View::is_venue_private($VNU_ID); |
|
1108 | + } |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | |
1112 | 1112 | if (! function_exists('espresso_venue_is_password_protected')) { |
1113 | - /** |
|
1114 | - * returns true or false if a venue is password protected or not |
|
1115 | - * |
|
1116 | - * @param int $VNU_ID optional, the venue id to check. |
|
1117 | - * @return bool |
|
1118 | - * @throws EE_Error |
|
1119 | - * @throws ReflectionException |
|
1120 | - */ |
|
1121 | - function espresso_venue_is_password_protected($VNU_ID = 0) |
|
1122 | - { |
|
1123 | - EE_Registry::instance()->load_helper('Venue_View'); |
|
1124 | - return EEH_Venue_View::is_venue_password_protected($VNU_ID); |
|
1125 | - } |
|
1113 | + /** |
|
1114 | + * returns true or false if a venue is password protected or not |
|
1115 | + * |
|
1116 | + * @param int $VNU_ID optional, the venue id to check. |
|
1117 | + * @return bool |
|
1118 | + * @throws EE_Error |
|
1119 | + * @throws ReflectionException |
|
1120 | + */ |
|
1121 | + function espresso_venue_is_password_protected($VNU_ID = 0) |
|
1122 | + { |
|
1123 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
1124 | + return EEH_Venue_View::is_venue_password_protected($VNU_ID); |
|
1125 | + } |
|
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | |
1129 | 1129 | if (! function_exists('espresso_password_protected_venue_form')) { |
1130 | - /** |
|
1131 | - * Returns a password form if venue is password protected. |
|
1132 | - * |
|
1133 | - * @param int $VNU_ID optional, the venue id to check. |
|
1134 | - * @return string |
|
1135 | - * @throws EE_Error |
|
1136 | - * @throws ReflectionException |
|
1137 | - */ |
|
1138 | - function espresso_password_protected_venue_form($VNU_ID = 0) |
|
1139 | - { |
|
1140 | - EE_Registry::instance()->load_helper('Venue_View'); |
|
1141 | - return EEH_Venue_View::password_protected_venue_form($VNU_ID); |
|
1142 | - } |
|
1130 | + /** |
|
1131 | + * Returns a password form if venue is password protected. |
|
1132 | + * |
|
1133 | + * @param int $VNU_ID optional, the venue id to check. |
|
1134 | + * @return string |
|
1135 | + * @throws EE_Error |
|
1136 | + * @throws ReflectionException |
|
1137 | + */ |
|
1138 | + function espresso_password_protected_venue_form($VNU_ID = 0) |
|
1139 | + { |
|
1140 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
1141 | + return EEH_Venue_View::password_protected_venue_form($VNU_ID); |
|
1142 | + } |
|
1143 | 1143 | } |
1144 | 1144 | |
1145 | 1145 | |
1146 | 1146 | if (! function_exists('espresso_venue_name')) { |
1147 | - /** |
|
1148 | - * espresso_venue_name |
|
1149 | - * |
|
1150 | - * @access public |
|
1151 | - * @param int $VNU_ID |
|
1152 | - * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website |
|
1153 | - * @param bool $echo |
|
1154 | - * @return string |
|
1155 | - * @throws EE_Error |
|
1156 | - * @throws ReflectionException |
|
1157 | - */ |
|
1158 | - function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = true) |
|
1159 | - { |
|
1160 | - if ($echo) { |
|
1161 | - echo EEH_Venue_View::venue_name($link_to, $VNU_ID); // already escaped |
|
1162 | - return ''; |
|
1163 | - } |
|
1164 | - return EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
1165 | - } |
|
1147 | + /** |
|
1148 | + * espresso_venue_name |
|
1149 | + * |
|
1150 | + * @access public |
|
1151 | + * @param int $VNU_ID |
|
1152 | + * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website |
|
1153 | + * @param bool $echo |
|
1154 | + * @return string |
|
1155 | + * @throws EE_Error |
|
1156 | + * @throws ReflectionException |
|
1157 | + */ |
|
1158 | + function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = true) |
|
1159 | + { |
|
1160 | + if ($echo) { |
|
1161 | + echo EEH_Venue_View::venue_name($link_to, $VNU_ID); // already escaped |
|
1162 | + return ''; |
|
1163 | + } |
|
1164 | + return EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
1165 | + } |
|
1166 | 1166 | } |
1167 | 1167 | |
1168 | 1168 | |
1169 | 1169 | if (! function_exists('espresso_venue_link')) { |
1170 | - /** |
|
1171 | - * espresso_venue_link |
|
1172 | - * |
|
1173 | - * @access public |
|
1174 | - * @param int $VNU_ID |
|
1175 | - * @param string $text |
|
1176 | - * @return string |
|
1177 | - * @throws EE_Error |
|
1178 | - * @throws ReflectionException |
|
1179 | - */ |
|
1180 | - function espresso_venue_link($VNU_ID = 0, $text = '') |
|
1181 | - { |
|
1182 | - return EEH_Venue_View::venue_details_link($VNU_ID, $text); |
|
1183 | - } |
|
1170 | + /** |
|
1171 | + * espresso_venue_link |
|
1172 | + * |
|
1173 | + * @access public |
|
1174 | + * @param int $VNU_ID |
|
1175 | + * @param string $text |
|
1176 | + * @return string |
|
1177 | + * @throws EE_Error |
|
1178 | + * @throws ReflectionException |
|
1179 | + */ |
|
1180 | + function espresso_venue_link($VNU_ID = 0, $text = '') |
|
1181 | + { |
|
1182 | + return EEH_Venue_View::venue_details_link($VNU_ID, $text); |
|
1183 | + } |
|
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | |
1187 | 1187 | if (! function_exists('espresso_venue_description')) { |
1188 | - /** |
|
1189 | - * espresso_venue_description |
|
1190 | - * |
|
1191 | - * @access public |
|
1192 | - * @param bool $VNU_ID |
|
1193 | - * @param bool $echo |
|
1194 | - * @return string |
|
1195 | - * @throws EE_Error |
|
1196 | - * @throws ReflectionException |
|
1197 | - */ |
|
1198 | - function espresso_venue_description($VNU_ID = false, $echo = true) |
|
1199 | - { |
|
1200 | - if ($echo) { |
|
1201 | - echo EEH_Venue_View::venue_description($VNU_ID); // already escaped |
|
1202 | - return ''; |
|
1203 | - } |
|
1204 | - return EEH_Venue_View::venue_description($VNU_ID); |
|
1205 | - } |
|
1188 | + /** |
|
1189 | + * espresso_venue_description |
|
1190 | + * |
|
1191 | + * @access public |
|
1192 | + * @param bool $VNU_ID |
|
1193 | + * @param bool $echo |
|
1194 | + * @return string |
|
1195 | + * @throws EE_Error |
|
1196 | + * @throws ReflectionException |
|
1197 | + */ |
|
1198 | + function espresso_venue_description($VNU_ID = false, $echo = true) |
|
1199 | + { |
|
1200 | + if ($echo) { |
|
1201 | + echo EEH_Venue_View::venue_description($VNU_ID); // already escaped |
|
1202 | + return ''; |
|
1203 | + } |
|
1204 | + return EEH_Venue_View::venue_description($VNU_ID); |
|
1205 | + } |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | 1208 | |
1209 | 1209 | if (! function_exists('espresso_venue_excerpt')) { |
1210 | - /** |
|
1211 | - * espresso_venue_excerpt |
|
1212 | - * |
|
1213 | - * @access public |
|
1214 | - * @param int $VNU_ID |
|
1215 | - * @param bool $echo |
|
1216 | - * @return string |
|
1217 | - * @throws EE_Error |
|
1218 | - * @throws ReflectionException |
|
1219 | - */ |
|
1220 | - function espresso_venue_excerpt($VNU_ID = 0, $echo = true) |
|
1221 | - { |
|
1222 | - if ($echo) { |
|
1223 | - echo EEH_Venue_View::venue_excerpt($VNU_ID); // already escaped |
|
1224 | - return ''; |
|
1225 | - } |
|
1226 | - return EEH_Venue_View::venue_excerpt($VNU_ID); |
|
1227 | - } |
|
1210 | + /** |
|
1211 | + * espresso_venue_excerpt |
|
1212 | + * |
|
1213 | + * @access public |
|
1214 | + * @param int $VNU_ID |
|
1215 | + * @param bool $echo |
|
1216 | + * @return string |
|
1217 | + * @throws EE_Error |
|
1218 | + * @throws ReflectionException |
|
1219 | + */ |
|
1220 | + function espresso_venue_excerpt($VNU_ID = 0, $echo = true) |
|
1221 | + { |
|
1222 | + if ($echo) { |
|
1223 | + echo EEH_Venue_View::venue_excerpt($VNU_ID); // already escaped |
|
1224 | + return ''; |
|
1225 | + } |
|
1226 | + return EEH_Venue_View::venue_excerpt($VNU_ID); |
|
1227 | + } |
|
1228 | 1228 | } |
1229 | 1229 | |
1230 | 1230 | |
1231 | 1231 | if (! function_exists('espresso_venue_categories')) { |
1232 | - /** |
|
1233 | - * espresso_venue_categories |
|
1234 | - * returns the terms associated with a venue |
|
1235 | - * |
|
1236 | - * @param int $VNU_ID |
|
1237 | - * @param bool $hide_uncategorized |
|
1238 | - * @param bool $echo |
|
1239 | - * @return string |
|
1240 | - * @throws EE_Error |
|
1241 | - * @throws ReflectionException |
|
1242 | - */ |
|
1243 | - function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = true, $echo = true) |
|
1244 | - { |
|
1245 | - if ($echo) { |
|
1246 | - echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); // already escaped |
|
1247 | - return ''; |
|
1248 | - } |
|
1249 | - return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
1250 | - } |
|
1232 | + /** |
|
1233 | + * espresso_venue_categories |
|
1234 | + * returns the terms associated with a venue |
|
1235 | + * |
|
1236 | + * @param int $VNU_ID |
|
1237 | + * @param bool $hide_uncategorized |
|
1238 | + * @param bool $echo |
|
1239 | + * @return string |
|
1240 | + * @throws EE_Error |
|
1241 | + * @throws ReflectionException |
|
1242 | + */ |
|
1243 | + function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = true, $echo = true) |
|
1244 | + { |
|
1245 | + if ($echo) { |
|
1246 | + echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); // already escaped |
|
1247 | + return ''; |
|
1248 | + } |
|
1249 | + return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
1250 | + } |
|
1251 | 1251 | } |
1252 | 1252 | |
1253 | 1253 | |
1254 | 1254 | if (! function_exists('espresso_venue_address')) { |
1255 | - /** |
|
1256 | - * espresso_venue_address |
|
1257 | - * returns a formatted block of html for displaying a venue's address |
|
1258 | - * |
|
1259 | - * @param string $type 'inline' or 'multiline' |
|
1260 | - * @param int $VNU_ID |
|
1261 | - * @param bool $echo |
|
1262 | - * @return string |
|
1263 | - * @throws EE_Error |
|
1264 | - * @throws ReflectionException |
|
1265 | - */ |
|
1266 | - function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = true) |
|
1267 | - { |
|
1268 | - if ($echo) { |
|
1269 | - echo EEH_Venue_View::venue_address($type, $VNU_ID); // already escaped |
|
1270 | - return ''; |
|
1271 | - } |
|
1272 | - return EEH_Venue_View::venue_address($type, $VNU_ID); |
|
1273 | - } |
|
1255 | + /** |
|
1256 | + * espresso_venue_address |
|
1257 | + * returns a formatted block of html for displaying a venue's address |
|
1258 | + * |
|
1259 | + * @param string $type 'inline' or 'multiline' |
|
1260 | + * @param int $VNU_ID |
|
1261 | + * @param bool $echo |
|
1262 | + * @return string |
|
1263 | + * @throws EE_Error |
|
1264 | + * @throws ReflectionException |
|
1265 | + */ |
|
1266 | + function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = true) |
|
1267 | + { |
|
1268 | + if ($echo) { |
|
1269 | + echo EEH_Venue_View::venue_address($type, $VNU_ID); // already escaped |
|
1270 | + return ''; |
|
1271 | + } |
|
1272 | + return EEH_Venue_View::venue_address($type, $VNU_ID); |
|
1273 | + } |
|
1274 | 1274 | } |
1275 | 1275 | |
1276 | 1276 | |
1277 | 1277 | if (! function_exists('espresso_venue_raw_address')) { |
1278 | - /** |
|
1279 | - * espresso_venue_address |
|
1280 | - * returns an UN-formatted string containing a venue's address |
|
1281 | - * |
|
1282 | - * @param string $type 'inline' or 'multiline' |
|
1283 | - * @param int $VNU_ID |
|
1284 | - * @param bool $echo |
|
1285 | - * @return string |
|
1286 | - * @throws EE_Error |
|
1287 | - * @throws ReflectionException |
|
1288 | - */ |
|
1289 | - function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = true) |
|
1290 | - { |
|
1291 | - if ($echo) { |
|
1292 | - echo EEH_Venue_View::venue_address($type, $VNU_ID, false, false); // already escaped |
|
1293 | - return ''; |
|
1294 | - } |
|
1295 | - return EEH_Venue_View::venue_address($type, $VNU_ID, false, false); |
|
1296 | - } |
|
1278 | + /** |
|
1279 | + * espresso_venue_address |
|
1280 | + * returns an UN-formatted string containing a venue's address |
|
1281 | + * |
|
1282 | + * @param string $type 'inline' or 'multiline' |
|
1283 | + * @param int $VNU_ID |
|
1284 | + * @param bool $echo |
|
1285 | + * @return string |
|
1286 | + * @throws EE_Error |
|
1287 | + * @throws ReflectionException |
|
1288 | + */ |
|
1289 | + function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = true) |
|
1290 | + { |
|
1291 | + if ($echo) { |
|
1292 | + echo EEH_Venue_View::venue_address($type, $VNU_ID, false, false); // already escaped |
|
1293 | + return ''; |
|
1294 | + } |
|
1295 | + return EEH_Venue_View::venue_address($type, $VNU_ID, false, false); |
|
1296 | + } |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | |
1300 | 1300 | if (! function_exists('espresso_venue_has_address')) { |
1301 | - /** |
|
1302 | - * espresso_venue_has_address |
|
1303 | - * returns TRUE or FALSE if a Venue has address information |
|
1304 | - * |
|
1305 | - * @param int $VNU_ID |
|
1306 | - * @return bool |
|
1307 | - * @throws EE_Error |
|
1308 | - * @throws ReflectionException |
|
1309 | - */ |
|
1310 | - function espresso_venue_has_address($VNU_ID = 0) |
|
1311 | - { |
|
1312 | - return EEH_Venue_View::venue_has_address($VNU_ID); |
|
1313 | - } |
|
1301 | + /** |
|
1302 | + * espresso_venue_has_address |
|
1303 | + * returns TRUE or FALSE if a Venue has address information |
|
1304 | + * |
|
1305 | + * @param int $VNU_ID |
|
1306 | + * @return bool |
|
1307 | + * @throws EE_Error |
|
1308 | + * @throws ReflectionException |
|
1309 | + */ |
|
1310 | + function espresso_venue_has_address($VNU_ID = 0) |
|
1311 | + { |
|
1312 | + return EEH_Venue_View::venue_has_address($VNU_ID); |
|
1313 | + } |
|
1314 | 1314 | } |
1315 | 1315 | |
1316 | 1316 | |
1317 | 1317 | if (! function_exists('espresso_venue_gmap')) { |
1318 | - /** |
|
1319 | - * espresso_venue_gmap |
|
1320 | - * returns a google map for the venue address |
|
1321 | - * |
|
1322 | - * @param int $VNU_ID |
|
1323 | - * @param bool $map_ID |
|
1324 | - * @param array $gmap |
|
1325 | - * @param bool $echo |
|
1326 | - * @return string |
|
1327 | - * @throws EE_Error |
|
1328 | - * @throws ReflectionException |
|
1329 | - */ |
|
1330 | - function espresso_venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = [], $echo = true) |
|
1331 | - { |
|
1332 | - if ($echo) { |
|
1333 | - echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); // already escaped |
|
1334 | - return ''; |
|
1335 | - } |
|
1336 | - return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
1337 | - } |
|
1318 | + /** |
|
1319 | + * espresso_venue_gmap |
|
1320 | + * returns a google map for the venue address |
|
1321 | + * |
|
1322 | + * @param int $VNU_ID |
|
1323 | + * @param bool $map_ID |
|
1324 | + * @param array $gmap |
|
1325 | + * @param bool $echo |
|
1326 | + * @return string |
|
1327 | + * @throws EE_Error |
|
1328 | + * @throws ReflectionException |
|
1329 | + */ |
|
1330 | + function espresso_venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = [], $echo = true) |
|
1331 | + { |
|
1332 | + if ($echo) { |
|
1333 | + echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); // already escaped |
|
1334 | + return ''; |
|
1335 | + } |
|
1336 | + return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
1337 | + } |
|
1338 | 1338 | } |
1339 | 1339 | |
1340 | 1340 | |
1341 | 1341 | if (! function_exists('espresso_venue_phone')) { |
1342 | - /** |
|
1343 | - * espresso_venue_phone |
|
1344 | - * |
|
1345 | - * @param int $VNU_ID |
|
1346 | - * @param bool $echo |
|
1347 | - * @return string |
|
1348 | - * @throws EE_Error |
|
1349 | - * @throws ReflectionException |
|
1350 | - */ |
|
1351 | - function espresso_venue_phone($VNU_ID = 0, $echo = true) |
|
1352 | - { |
|
1353 | - if ($echo) { |
|
1354 | - echo EEH_Venue_View::venue_phone($VNU_ID); // already escaped |
|
1355 | - return ''; |
|
1356 | - } |
|
1357 | - return EEH_Venue_View::venue_phone($VNU_ID); |
|
1358 | - } |
|
1342 | + /** |
|
1343 | + * espresso_venue_phone |
|
1344 | + * |
|
1345 | + * @param int $VNU_ID |
|
1346 | + * @param bool $echo |
|
1347 | + * @return string |
|
1348 | + * @throws EE_Error |
|
1349 | + * @throws ReflectionException |
|
1350 | + */ |
|
1351 | + function espresso_venue_phone($VNU_ID = 0, $echo = true) |
|
1352 | + { |
|
1353 | + if ($echo) { |
|
1354 | + echo EEH_Venue_View::venue_phone($VNU_ID); // already escaped |
|
1355 | + return ''; |
|
1356 | + } |
|
1357 | + return EEH_Venue_View::venue_phone($VNU_ID); |
|
1358 | + } |
|
1359 | 1359 | } |
1360 | 1360 | |
1361 | 1361 | |
1362 | 1362 | if (! function_exists('espresso_venue_website')) { |
1363 | - /** |
|
1364 | - * espresso_venue_website |
|
1365 | - * |
|
1366 | - * @param int $VNU_ID |
|
1367 | - * @param bool $echo |
|
1368 | - * @return string |
|
1369 | - * @throws EE_Error |
|
1370 | - * @throws ReflectionException |
|
1371 | - */ |
|
1372 | - function espresso_venue_website($VNU_ID = 0, $echo = true) |
|
1373 | - { |
|
1374 | - if ($echo) { |
|
1375 | - echo EEH_Venue_View::venue_website_link($VNU_ID); // already escaped |
|
1376 | - return ''; |
|
1377 | - } |
|
1378 | - return EEH_Venue_View::venue_website_link($VNU_ID); |
|
1379 | - } |
|
1363 | + /** |
|
1364 | + * espresso_venue_website |
|
1365 | + * |
|
1366 | + * @param int $VNU_ID |
|
1367 | + * @param bool $echo |
|
1368 | + * @return string |
|
1369 | + * @throws EE_Error |
|
1370 | + * @throws ReflectionException |
|
1371 | + */ |
|
1372 | + function espresso_venue_website($VNU_ID = 0, $echo = true) |
|
1373 | + { |
|
1374 | + if ($echo) { |
|
1375 | + echo EEH_Venue_View::venue_website_link($VNU_ID); // already escaped |
|
1376 | + return ''; |
|
1377 | + } |
|
1378 | + return EEH_Venue_View::venue_website_link($VNU_ID); |
|
1379 | + } |
|
1380 | 1380 | } |
1381 | 1381 | |
1382 | 1382 | |
1383 | 1383 | if (! function_exists('espresso_edit_venue_link')) { |
1384 | - /** |
|
1385 | - * espresso_edit_venue_link |
|
1386 | - * |
|
1387 | - * @param int $VNU_ID |
|
1388 | - * @param bool $echo |
|
1389 | - * @return string |
|
1390 | - * @throws EE_Error |
|
1391 | - * @throws ReflectionException |
|
1392 | - */ |
|
1393 | - function espresso_edit_venue_link($VNU_ID = 0, $echo = true) |
|
1394 | - { |
|
1395 | - if ($echo) { |
|
1396 | - echo EEH_Venue_View::edit_venue_link($VNU_ID); // already escaped |
|
1397 | - return ''; |
|
1398 | - } |
|
1399 | - return EEH_Venue_View::edit_venue_link($VNU_ID); |
|
1400 | - } |
|
1384 | + /** |
|
1385 | + * espresso_edit_venue_link |
|
1386 | + * |
|
1387 | + * @param int $VNU_ID |
|
1388 | + * @param bool $echo |
|
1389 | + * @return string |
|
1390 | + * @throws EE_Error |
|
1391 | + * @throws ReflectionException |
|
1392 | + */ |
|
1393 | + function espresso_edit_venue_link($VNU_ID = 0, $echo = true) |
|
1394 | + { |
|
1395 | + if ($echo) { |
|
1396 | + echo EEH_Venue_View::edit_venue_link($VNU_ID); // already escaped |
|
1397 | + return ''; |
|
1398 | + } |
|
1399 | + return EEH_Venue_View::edit_venue_link($VNU_ID); |
|
1400 | + } |
|
1401 | 1401 | } |
1402 | 1402 | |
1403 | 1403 |
@@ -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.6.2'); |
|
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.6.2'); |
|
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.10.33.rc.015'); |
|
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.10.33.rc.015'); |
|
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 | } |
141 | 141 | \ No newline at end of file |
@@ -20,2834 +20,2834 @@ |
||
20 | 20 | class EE_SPCO_Reg_Step_Payment_Options extends EE_SPCO_Reg_Step |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var EE_Line_Item_Display $Line_Item_Display |
|
25 | - */ |
|
26 | - protected $line_item_display; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var boolean $handle_IPN_in_this_request |
|
30 | - */ |
|
31 | - protected $handle_IPN_in_this_request = false; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
36 | - * |
|
37 | - * @access public |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public static function set_hooks() |
|
41 | - { |
|
42 | - add_filter( |
|
43 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
44 | - ['EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters'] |
|
45 | - ); |
|
46 | - add_action( |
|
47 | - 'wp_ajax_switch_spco_billing_form', |
|
48 | - ['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form'] |
|
49 | - ); |
|
50 | - add_action( |
|
51 | - 'wp_ajax_nopriv_switch_spco_billing_form', |
|
52 | - ['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form'] |
|
53 | - ); |
|
54 | - add_action('wp_ajax_save_payer_details', ['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details']); |
|
55 | - add_action( |
|
56 | - 'wp_ajax_nopriv_save_payer_details', |
|
57 | - ['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details'] |
|
58 | - ); |
|
59 | - add_action( |
|
60 | - 'wp_ajax_get_transaction_details_for_gateways', |
|
61 | - ['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details'] |
|
62 | - ); |
|
63 | - add_action( |
|
64 | - 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
65 | - ['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details'] |
|
66 | - ); |
|
67 | - add_filter( |
|
68 | - 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
69 | - ['EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'], |
|
70 | - 10, |
|
71 | - 1 |
|
72 | - ); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * ajax switch_spco_billing_form |
|
78 | - * |
|
79 | - */ |
|
80 | - public static function switch_spco_billing_form() |
|
81 | - { |
|
82 | - EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * ajax save_payer_details |
|
88 | - * |
|
89 | - */ |
|
90 | - public static function save_payer_details() |
|
91 | - { |
|
92 | - EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * ajax get_transaction_details |
|
98 | - * |
|
99 | - */ |
|
100 | - public static function get_transaction_details() |
|
101 | - { |
|
102 | - EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * bypass_recaptcha_for_load_payment_method |
|
108 | - * |
|
109 | - * @access public |
|
110 | - * @return array |
|
111 | - * @throws InvalidArgumentException |
|
112 | - * @throws InvalidDataTypeException |
|
113 | - * @throws InvalidInterfaceException |
|
114 | - */ |
|
115 | - public static function bypass_recaptcha_for_load_payment_method() |
|
116 | - { |
|
117 | - return [ |
|
118 | - 'EESID' => EE_Registry::instance()->SSN->id(), |
|
119 | - 'step' => 'payment_options', |
|
120 | - 'action' => 'spco_billing_form', |
|
121 | - ]; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * class constructor |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param EE_Checkout $checkout |
|
130 | - */ |
|
131 | - public function __construct(EE_Checkout $checkout) |
|
132 | - { |
|
133 | - $this->request = EED_Single_Page_Checkout::getRequest(); |
|
134 | - $this->_slug = 'payment_options'; |
|
135 | - $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
136 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php'; |
|
137 | - $this->checkout = $checkout; |
|
138 | - $this->_reset_success_message(); |
|
139 | - $this->set_instructions( |
|
140 | - esc_html__( |
|
141 | - 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
142 | - 'event_espresso' |
|
143 | - ) |
|
144 | - ); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @return null |
|
150 | - */ |
|
151 | - public function line_item_display() |
|
152 | - { |
|
153 | - return $this->line_item_display; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @param null $line_item_display |
|
159 | - */ |
|
160 | - public function set_line_item_display($line_item_display) |
|
161 | - { |
|
162 | - $this->line_item_display = $line_item_display; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @return boolean |
|
168 | - */ |
|
169 | - public function handle_IPN_in_this_request() |
|
170 | - { |
|
171 | - return $this->handle_IPN_in_this_request; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @param boolean $handle_IPN_in_this_request |
|
177 | - */ |
|
178 | - public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
179 | - { |
|
180 | - $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * translate_js_strings |
|
186 | - * |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - public function translate_js_strings() |
|
190 | - { |
|
191 | - EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
192 | - 'Please select a method of payment in order to continue.', |
|
193 | - 'event_espresso' |
|
194 | - ); |
|
195 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
196 | - 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
197 | - 'event_espresso' |
|
198 | - ); |
|
199 | - EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
200 | - 'Forwarding to Secure Payment Provider.', |
|
201 | - 'event_espresso' |
|
202 | - ); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * enqueue_styles_and_scripts |
|
208 | - * |
|
209 | - * @return void |
|
210 | - * @throws EE_Error |
|
211 | - * @throws InvalidArgumentException |
|
212 | - * @throws InvalidDataTypeException |
|
213 | - * @throws InvalidInterfaceException |
|
214 | - * @throws ReflectionException |
|
215 | - */ |
|
216 | - public function enqueue_styles_and_scripts() |
|
217 | - { |
|
218 | - $transaction = $this->checkout->transaction; |
|
219 | - // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
220 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
221 | - return; |
|
222 | - } |
|
223 | - foreach ( |
|
224 | - EEM_Payment_Method::instance()->get_all_for_transaction( |
|
225 | - $transaction, |
|
226 | - EEM_Payment_Method::scope_cart |
|
227 | - ) as $payment_method |
|
228 | - ) { |
|
229 | - $type_obj = $payment_method->type_obj(); |
|
230 | - if ($type_obj instanceof EE_PMT_Base) { |
|
231 | - $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
232 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
233 | - $billing_form->enqueue_js(); |
|
234 | - } |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * initialize_reg_step |
|
242 | - * |
|
243 | - * @return bool |
|
244 | - * @throws EE_Error |
|
245 | - * @throws InvalidArgumentException |
|
246 | - * @throws ReflectionException |
|
247 | - * @throws InvalidDataTypeException |
|
248 | - * @throws InvalidInterfaceException |
|
249 | - */ |
|
250 | - public function initialize_reg_step() |
|
251 | - { |
|
252 | - // TODO: if /when we implement donations, then this will need overriding |
|
253 | - if ( |
|
254 | - // don't need payment options for: |
|
255 | - // registrations made via the admin |
|
256 | - // completed transactions |
|
257 | - // overpaid transactions |
|
258 | - // $ 0.00 transactions(no payment required) |
|
259 | - ! $this->checkout->payment_required() |
|
260 | - // but do NOT remove if current action being called belongs to this reg step |
|
261 | - && ! is_callable([$this, $this->checkout->action]) |
|
262 | - && ! $this->completed() |
|
263 | - ) { |
|
264 | - // and if so, then we no longer need the Payment Options step |
|
265 | - if ($this->is_current_step()) { |
|
266 | - $this->checkout->generate_reg_form = false; |
|
267 | - } |
|
268 | - $this->checkout->remove_reg_step($this->_slug); |
|
269 | - // DEBUG LOG |
|
270 | - // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
271 | - return false; |
|
272 | - } |
|
273 | - // load EEM_Payment_Method |
|
274 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
275 | - // get all active payment methods |
|
276 | - $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
277 | - $this->checkout->transaction, |
|
278 | - EEM_Payment_Method::scope_cart |
|
279 | - ); |
|
280 | - return true; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @return EE_Form_Section_Proper |
|
286 | - * @throws EE_Error |
|
287 | - * @throws InvalidArgumentException |
|
288 | - * @throws ReflectionException |
|
289 | - * @throws EntityNotFoundException |
|
290 | - * @throws InvalidDataTypeException |
|
291 | - * @throws InvalidInterfaceException |
|
292 | - * @throws InvalidStatusException |
|
293 | - */ |
|
294 | - public function generate_reg_form() |
|
295 | - { |
|
296 | - // reset in case someone changes their mind |
|
297 | - $this->_reset_selected_method_of_payment(); |
|
298 | - // set some defaults |
|
299 | - $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
300 | - $registrations_requiring_payment = []; |
|
301 | - $registrations_for_free_events = []; |
|
302 | - $registrations_requiring_pre_approval = []; |
|
303 | - $sold_out_events = []; |
|
304 | - $insufficient_spaces_available = []; |
|
305 | - $no_payment_required = true; |
|
306 | - // loop thru registrations to gather info |
|
307 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
308 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
309 | - $registrations, |
|
310 | - $this->checkout->revisit |
|
311 | - ); |
|
312 | - foreach ($registrations as $REG_ID => $registration) { |
|
313 | - /** @var $registration EE_Registration */ |
|
314 | - // has this registration lost it's space ? |
|
315 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
316 | - if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
317 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
318 | - } else { |
|
319 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
320 | - } |
|
321 | - continue; |
|
322 | - } |
|
323 | - // event requires admin approval |
|
324 | - if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
325 | - // add event to list of events with pre-approval reg status |
|
326 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
327 | - do_action( |
|
328 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
329 | - $registration->event(), |
|
330 | - $this |
|
331 | - ); |
|
332 | - continue; |
|
333 | - } |
|
334 | - if ( |
|
335 | - $this->checkout->revisit |
|
336 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
337 | - && ( |
|
338 | - $registration->event()->is_sold_out() |
|
339 | - || $registration->event()->is_sold_out(true) |
|
340 | - ) |
|
341 | - ) { |
|
342 | - // add event to list of events that are sold out |
|
343 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
344 | - do_action( |
|
345 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
346 | - $registration->event(), |
|
347 | - $this |
|
348 | - ); |
|
349 | - continue; |
|
350 | - } |
|
351 | - // are they allowed to pay now and is there monies owing? |
|
352 | - if ($registration->owes_monies_and_can_pay()) { |
|
353 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
354 | - do_action( |
|
355 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
356 | - $registration->event(), |
|
357 | - $this |
|
358 | - ); |
|
359 | - } elseif ( |
|
360 | - ! $this->checkout->revisit |
|
361 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
362 | - && $registration->ticket()->is_free() |
|
363 | - ) { |
|
364 | - $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
365 | - } |
|
366 | - } |
|
367 | - $subsections = []; |
|
368 | - // now decide which template to load |
|
369 | - if (! empty($sold_out_events)) { |
|
370 | - $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
371 | - } |
|
372 | - if (! empty($insufficient_spaces_available)) { |
|
373 | - $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
374 | - $insufficient_spaces_available |
|
375 | - ); |
|
376 | - } |
|
377 | - if (! empty($registrations_requiring_pre_approval)) { |
|
378 | - $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
379 | - $registrations_requiring_pre_approval |
|
380 | - ); |
|
381 | - } |
|
382 | - if (! empty($registrations_for_free_events)) { |
|
383 | - $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
384 | - } |
|
385 | - if (! empty($registrations_requiring_payment)) { |
|
386 | - if ($this->checkout->amount_owing > 0) { |
|
387 | - // autoload Line_Item_Display classes |
|
388 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
389 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
390 | - apply_filters( |
|
391 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
392 | - new EE_Line_Item_Filter_Collection() |
|
393 | - ), |
|
394 | - $this->checkout->cart->get_grand_total() |
|
395 | - ); |
|
396 | - /** @var EE_Line_Item $filtered_line_item_tree */ |
|
397 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
398 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
399 | - $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
400 | - $subsections['payment_options'] = $this->_display_payment_options( |
|
401 | - $this->line_item_display->display_line_item( |
|
402 | - $filtered_line_item_tree, |
|
403 | - ['registrations' => $registrations] |
|
404 | - ) |
|
405 | - ); |
|
406 | - $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
407 | - $this->_apply_registration_payments_to_amount_owing($registrations); |
|
408 | - } |
|
409 | - $no_payment_required = false; |
|
410 | - } else { |
|
411 | - $this->_hide_reg_step_submit_button_if_revisit(); |
|
412 | - } |
|
413 | - $this->_save_selected_method_of_payment(); |
|
414 | - |
|
415 | - $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
416 | - $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
417 | - |
|
418 | - return new EE_Form_Section_Proper( |
|
419 | - [ |
|
420 | - 'name' => $this->reg_form_name(), |
|
421 | - 'html_id' => $this->reg_form_name(), |
|
422 | - 'subsections' => $subsections, |
|
423 | - 'layout_strategy' => new EE_No_Layout(), |
|
424 | - ] |
|
425 | - ); |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * add line item filters required for this reg step |
|
431 | - * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
432 | - * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
433 | - * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
434 | - * payment options reg step, can apply these filters via the following: apply_filters( |
|
435 | - * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
436 | - * filter collection by passing that instead of instantiating a new collection |
|
437 | - * |
|
438 | - * @param EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
439 | - * @return EE_Line_Item_Filter_Collection |
|
440 | - * @throws EE_Error |
|
441 | - * @throws InvalidArgumentException |
|
442 | - * @throws ReflectionException |
|
443 | - * @throws EntityNotFoundException |
|
444 | - * @throws InvalidDataTypeException |
|
445 | - * @throws InvalidInterfaceException |
|
446 | - * @throws InvalidStatusException |
|
447 | - */ |
|
448 | - public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
449 | - { |
|
450 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
451 | - return $line_item_filter_collection; |
|
452 | - } |
|
453 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
454 | - return $line_item_filter_collection; |
|
455 | - } |
|
456 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
457 | - return $line_item_filter_collection; |
|
458 | - } |
|
459 | - $line_item_filter_collection->add( |
|
460 | - new EE_Billable_Line_Item_Filter( |
|
461 | - EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
462 | - EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
463 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
464 | - ) |
|
465 | - ) |
|
466 | - ) |
|
467 | - ); |
|
468 | - $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
469 | - return $line_item_filter_collection; |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * remove_ejected_registrations |
|
475 | - * if a registrant has lost their potential space at an event due to lack of payment, |
|
476 | - * then this method removes them from the list of registrations being paid for during this request |
|
477 | - * |
|
478 | - * @param EE_Registration[] $registrations |
|
479 | - * @return EE_Registration[] |
|
480 | - * @throws EE_Error |
|
481 | - * @throws InvalidArgumentException |
|
482 | - * @throws ReflectionException |
|
483 | - * @throws EntityNotFoundException |
|
484 | - * @throws InvalidDataTypeException |
|
485 | - * @throws InvalidInterfaceException |
|
486 | - * @throws InvalidStatusException |
|
487 | - */ |
|
488 | - public static function remove_ejected_registrations(array $registrations) |
|
489 | - { |
|
490 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
491 | - $registrations, |
|
492 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
493 | - ); |
|
494 | - foreach ($registrations as $REG_ID => $registration) { |
|
495 | - // has this registration lost it's space ? |
|
496 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
497 | - unset($registrations[ $REG_ID ]); |
|
498 | - } |
|
499 | - } |
|
500 | - return $registrations; |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * find_registrations_that_lost_their_space |
|
506 | - * If a registrant chooses an offline payment method like Invoice, |
|
507 | - * then no space is reserved for them at the event until they fully pay fo that site |
|
508 | - * (unless the event's default reg status is set to APPROVED) |
|
509 | - * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
510 | - * then this method will determine which registrations have lost the ability to complete the reg process. |
|
511 | - * |
|
512 | - * @param EE_Registration[] $registrations |
|
513 | - * @param bool $revisit |
|
514 | - * @return array |
|
515 | - * @throws EE_Error |
|
516 | - * @throws InvalidArgumentException |
|
517 | - * @throws ReflectionException |
|
518 | - * @throws EntityNotFoundException |
|
519 | - * @throws InvalidDataTypeException |
|
520 | - * @throws InvalidInterfaceException |
|
521 | - * @throws InvalidStatusException |
|
522 | - */ |
|
523 | - public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
524 | - { |
|
525 | - // registrations per event |
|
526 | - $event_reg_count = []; |
|
527 | - // spaces left per event |
|
528 | - $event_spaces_remaining = []; |
|
529 | - // tickets left sorted by ID |
|
530 | - $tickets_remaining = []; |
|
531 | - // registrations that have lost their space |
|
532 | - $ejected_registrations = []; |
|
533 | - foreach ($registrations as $REG_ID => $registration) { |
|
534 | - if ( |
|
535 | - $registration->status_ID() === EEM_Registration::status_id_approved |
|
536 | - || apply_filters( |
|
537 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
538 | - false, |
|
539 | - $registration, |
|
540 | - $revisit |
|
541 | - ) |
|
542 | - ) { |
|
543 | - continue; |
|
544 | - } |
|
545 | - $EVT_ID = $registration->event_ID(); |
|
546 | - $ticket = $registration->ticket(); |
|
547 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
548 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
549 | - } |
|
550 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
551 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
552 | - $event_reg_count[ $EVT_ID ] = 0; |
|
553 | - } |
|
554 | - $event_reg_count[ $EVT_ID ]++; |
|
555 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
556 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
557 | - } |
|
558 | - } |
|
559 | - if ( |
|
560 | - $revisit |
|
561 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
562 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
563 | - ) |
|
564 | - ) { |
|
565 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
566 | - if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
567 | - /** @type EE_Registration_Processor $registration_processor */ |
|
568 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
569 | - // at this point, we should have enough details about the registrant to consider the registration |
|
570 | - // NOT incomplete |
|
571 | - $registration_processor->manually_update_registration_status( |
|
572 | - $registration, |
|
573 | - EEM_Registration::status_id_wait_list |
|
574 | - ); |
|
575 | - } |
|
576 | - } |
|
577 | - } |
|
578 | - return $ejected_registrations; |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * _hide_reg_step_submit_button |
|
584 | - * removes the html for the reg step submit button |
|
585 | - * by replacing it with an empty string via filter callback |
|
586 | - * |
|
587 | - * @return void |
|
588 | - */ |
|
589 | - protected function _adjust_registration_status_if_event_old_sold() |
|
590 | - { |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * _hide_reg_step_submit_button |
|
596 | - * removes the html for the reg step submit button |
|
597 | - * by replacing it with an empty string via filter callback |
|
598 | - * |
|
599 | - * @return void |
|
600 | - */ |
|
601 | - protected function _hide_reg_step_submit_button_if_revisit() |
|
602 | - { |
|
603 | - if ($this->checkout->revisit) { |
|
604 | - add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
605 | - } |
|
606 | - } |
|
607 | - |
|
608 | - |
|
609 | - /** |
|
610 | - * sold_out_events |
|
611 | - * displays notices regarding events that have sold out since hte registrant first signed up |
|
612 | - * |
|
613 | - * @param EE_Event[] $sold_out_events_array |
|
614 | - * @return EE_Form_Section_Proper |
|
615 | - * @throws EE_Error |
|
616 | - */ |
|
617 | - private function _sold_out_events($sold_out_events_array = []) |
|
618 | - { |
|
619 | - // set some defaults |
|
620 | - $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
621 | - $sold_out_events = ''; |
|
622 | - foreach ($sold_out_events_array as $sold_out_event) { |
|
623 | - $sold_out_events .= EEH_HTML::li( |
|
624 | - EEH_HTML::span( |
|
625 | - ' ' . $sold_out_event->name(), |
|
626 | - '', |
|
627 | - 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
628 | - ) |
|
629 | - ); |
|
630 | - } |
|
631 | - return new EE_Form_Section_Proper( |
|
632 | - [ |
|
633 | - 'layout_strategy' => new EE_Template_Layout( |
|
634 | - [ |
|
635 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
636 | - . $this->_slug |
|
637 | - . '/sold_out_events.template.php', |
|
638 | - 'template_args' => apply_filters( |
|
639 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
640 | - [ |
|
641 | - 'sold_out_events' => $sold_out_events, |
|
642 | - 'sold_out_events_msg' => apply_filters( |
|
643 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
644 | - sprintf( |
|
645 | - esc_html__( |
|
646 | - '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', |
|
647 | - 'event_espresso' |
|
648 | - ), |
|
649 | - '<strong>', |
|
650 | - '</strong>', |
|
651 | - '<br />' |
|
652 | - ) |
|
653 | - ), |
|
654 | - ] |
|
655 | - ), |
|
656 | - ] |
|
657 | - ), |
|
658 | - ] |
|
659 | - ); |
|
660 | - } |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * _insufficient_spaces_available |
|
665 | - * displays notices regarding events that do not have enough remaining spaces |
|
666 | - * to satisfy the current number of registrations looking to pay |
|
667 | - * |
|
668 | - * @param EE_Event[] $insufficient_spaces_events_array |
|
669 | - * @return EE_Form_Section_Proper |
|
670 | - * @throws EE_Error |
|
671 | - * @throws ReflectionException |
|
672 | - */ |
|
673 | - private function _insufficient_spaces_available($insufficient_spaces_events_array = []) |
|
674 | - { |
|
675 | - // set some defaults |
|
676 | - $this->checkout->selected_method_of_payment = 'invoice'; |
|
677 | - $insufficient_space_events = ''; |
|
678 | - foreach ($insufficient_spaces_events_array as $event) { |
|
679 | - if ($event instanceof EE_Event) { |
|
680 | - $insufficient_space_events .= EEH_HTML::li( |
|
681 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
682 | - ); |
|
683 | - } |
|
684 | - } |
|
685 | - return new EE_Form_Section_Proper( |
|
686 | - [ |
|
687 | - 'subsections' => [ |
|
688 | - 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
689 | - 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
690 | - ], |
|
691 | - 'layout_strategy' => new EE_Template_Layout( |
|
692 | - [ |
|
693 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
694 | - . $this->_slug |
|
695 | - . '/sold_out_events.template.php', |
|
696 | - 'template_args' => apply_filters( |
|
697 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
698 | - [ |
|
699 | - 'sold_out_events' => $insufficient_space_events, |
|
700 | - 'sold_out_events_msg' => apply_filters( |
|
701 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
702 | - esc_html__( |
|
703 | - '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.', |
|
704 | - 'event_espresso' |
|
705 | - ) |
|
706 | - ), |
|
707 | - ] |
|
708 | - ), |
|
709 | - ] |
|
710 | - ), |
|
711 | - ] |
|
712 | - ); |
|
713 | - } |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * registrations_requiring_pre_approval |
|
718 | - * |
|
719 | - * @param array $registrations_requiring_pre_approval |
|
720 | - * @return EE_Form_Section_Proper |
|
721 | - * @throws EE_Error |
|
722 | - * @throws EntityNotFoundException |
|
723 | - * @throws ReflectionException |
|
724 | - */ |
|
725 | - private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = []) |
|
726 | - { |
|
727 | - $events_requiring_pre_approval = []; |
|
728 | - foreach ($registrations_requiring_pre_approval as $registration) { |
|
729 | - if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
730 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
731 | - EEH_HTML::span( |
|
732 | - '', |
|
733 | - '', |
|
734 | - 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
735 | - ) |
|
736 | - . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
737 | - ); |
|
738 | - } |
|
739 | - } |
|
740 | - return new EE_Form_Section_Proper( |
|
741 | - [ |
|
742 | - 'layout_strategy' => new EE_Template_Layout( |
|
743 | - [ |
|
744 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
745 | - . $this->_slug |
|
746 | - . '/events_requiring_pre_approval.template.php', // layout_template |
|
747 | - 'template_args' => apply_filters( |
|
748 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
749 | - [ |
|
750 | - 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
751 | - 'events_requiring_pre_approval_msg' => apply_filters( |
|
752 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
753 | - esc_html__( |
|
754 | - '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.', |
|
755 | - 'event_espresso' |
|
756 | - ) |
|
757 | - ), |
|
758 | - ] |
|
759 | - ), |
|
760 | - ] |
|
761 | - ), |
|
762 | - ] |
|
763 | - ); |
|
764 | - } |
|
765 | - |
|
766 | - |
|
767 | - /** |
|
768 | - * _no_payment_required |
|
769 | - * |
|
770 | - * @param EE_Event[] $registrations_for_free_events |
|
771 | - * @return EE_Form_Section_Proper |
|
772 | - * @throws EE_Error |
|
773 | - */ |
|
774 | - private function _no_payment_required($registrations_for_free_events = []) |
|
775 | - { |
|
776 | - // set some defaults |
|
777 | - $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
778 | - // generate no_payment_required form |
|
779 | - return new EE_Form_Section_Proper( |
|
780 | - [ |
|
781 | - 'layout_strategy' => new EE_Template_Layout( |
|
782 | - [ |
|
783 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
784 | - . $this->_slug |
|
785 | - . '/no_payment_required.template.php', // layout_template |
|
786 | - 'template_args' => apply_filters( |
|
787 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
788 | - [ |
|
789 | - 'revisit' => $this->checkout->revisit, |
|
790 | - 'registrations' => [], |
|
791 | - 'ticket_count' => [], |
|
792 | - 'registrations_for_free_events' => $registrations_for_free_events, |
|
793 | - 'no_payment_required_msg' => EEH_HTML::p( |
|
794 | - esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
795 | - ), |
|
796 | - ] |
|
797 | - ), |
|
798 | - ] |
|
799 | - ), |
|
800 | - ] |
|
801 | - ); |
|
802 | - } |
|
803 | - |
|
804 | - |
|
805 | - /** |
|
806 | - * _display_payment_options |
|
807 | - * |
|
808 | - * @param string $transaction_details |
|
809 | - * @return EE_Form_Section_Proper |
|
810 | - * @throws EE_Error |
|
811 | - * @throws InvalidArgumentException |
|
812 | - * @throws InvalidDataTypeException |
|
813 | - * @throws InvalidInterfaceException |
|
814 | - */ |
|
815 | - private function _display_payment_options($transaction_details = '') |
|
816 | - { |
|
817 | - // has method_of_payment been set by no-js user? |
|
818 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
819 | - // build payment options form |
|
820 | - return apply_filters( |
|
821 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
822 | - new EE_Form_Section_Proper( |
|
823 | - [ |
|
824 | - 'subsections' => [ |
|
825 | - 'before_payment_options' => apply_filters( |
|
826 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
827 | - new EE_Form_Section_Proper( |
|
828 | - ['layout_strategy' => new EE_Div_Per_Section_Layout()] |
|
829 | - ) |
|
830 | - ), |
|
831 | - 'payment_options' => $this->_setup_payment_options(), |
|
832 | - 'after_payment_options' => apply_filters( |
|
833 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
834 | - new EE_Form_Section_Proper( |
|
835 | - ['layout_strategy' => new EE_Div_Per_Section_Layout()] |
|
836 | - ) |
|
837 | - ), |
|
838 | - ], |
|
839 | - 'layout_strategy' => new EE_Template_Layout( |
|
840 | - [ |
|
841 | - 'layout_template_file' => $this->_template, |
|
842 | - 'template_args' => apply_filters( |
|
843 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
844 | - [ |
|
845 | - 'reg_count' => $this->line_item_display->total_items(), |
|
846 | - 'transaction_details' => $transaction_details, |
|
847 | - 'available_payment_methods' => [], |
|
848 | - ] |
|
849 | - ), |
|
850 | - ] |
|
851 | - ), |
|
852 | - ] |
|
853 | - ) |
|
854 | - ); |
|
855 | - } |
|
856 | - |
|
857 | - |
|
858 | - /** |
|
859 | - * _extra_hidden_inputs |
|
860 | - * |
|
861 | - * @param bool $no_payment_required |
|
862 | - * @return EE_Form_Section_Proper |
|
863 | - * @throws EE_Error |
|
864 | - * @throws ReflectionException |
|
865 | - */ |
|
866 | - private function _extra_hidden_inputs($no_payment_required = true) |
|
867 | - { |
|
868 | - return new EE_Form_Section_Proper( |
|
869 | - [ |
|
870 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
871 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
872 | - 'subsections' => [ |
|
873 | - 'spco_no_payment_required' => new EE_Hidden_Input( |
|
874 | - [ |
|
875 | - 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
876 | - 'html_name' => 'spco_no_payment_required', |
|
877 | - 'html_id' => 'spco-no-payment-required-payment_options', |
|
878 | - 'default' => $no_payment_required, |
|
879 | - ] |
|
880 | - ), |
|
881 | - 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
882 | - [ |
|
883 | - 'normalization_strategy' => new EE_Int_Normalization(), |
|
884 | - 'html_name' => 'spco_transaction_id', |
|
885 | - 'html_id' => 'spco-transaction-id', |
|
886 | - 'default' => $this->checkout->transaction->ID(), |
|
887 | - ] |
|
888 | - ), |
|
889 | - ], |
|
890 | - ] |
|
891 | - ); |
|
892 | - } |
|
893 | - |
|
894 | - |
|
895 | - /** |
|
896 | - * _apply_registration_payments_to_amount_owing |
|
897 | - * |
|
898 | - * @param array $registrations |
|
899 | - * @throws EE_Error |
|
900 | - */ |
|
901 | - protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
902 | - { |
|
903 | - $payments = []; |
|
904 | - foreach ($registrations as $registration) { |
|
905 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
906 | - $payments += $registration->registration_payments(); |
|
907 | - } |
|
908 | - } |
|
909 | - if (! empty($payments)) { |
|
910 | - foreach ($payments as $payment) { |
|
911 | - if ($payment instanceof EE_Registration_Payment) { |
|
912 | - $this->checkout->amount_owing -= $payment->amount(); |
|
913 | - } |
|
914 | - } |
|
915 | - } |
|
916 | - } |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * _reset_selected_method_of_payment |
|
921 | - * |
|
922 | - * @access private |
|
923 | - * @param bool $force_reset |
|
924 | - * @return void |
|
925 | - * @throws InvalidArgumentException |
|
926 | - * @throws InvalidDataTypeException |
|
927 | - * @throws InvalidInterfaceException |
|
928 | - */ |
|
929 | - private function _reset_selected_method_of_payment($force_reset = false) |
|
930 | - { |
|
931 | - /** @var RequestInterface $request */ |
|
932 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
933 | - $reset_payment_method = $request->getRequestParam('reset_payment_method', $force_reset, 'bool'); |
|
934 | - if ($reset_payment_method) { |
|
935 | - $this->checkout->selected_method_of_payment = null; |
|
936 | - $this->checkout->payment_method = null; |
|
937 | - $this->checkout->billing_form = null; |
|
938 | - $this->_save_selected_method_of_payment(); |
|
939 | - } |
|
940 | - } |
|
941 | - |
|
942 | - |
|
943 | - /** |
|
944 | - * _save_selected_method_of_payment |
|
945 | - * stores the selected_method_of_payment in the session |
|
946 | - * so that it's available for all subsequent requests including AJAX |
|
947 | - * |
|
948 | - * @access private |
|
949 | - * @param string $selected_method_of_payment |
|
950 | - * @return void |
|
951 | - * @throws InvalidArgumentException |
|
952 | - * @throws InvalidDataTypeException |
|
953 | - * @throws InvalidInterfaceException |
|
954 | - */ |
|
955 | - private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
956 | - { |
|
957 | - $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
958 | - ? $selected_method_of_payment |
|
959 | - : $this->checkout->selected_method_of_payment; |
|
960 | - EE_Registry::instance()->SSN->set_session_data( |
|
961 | - ['selected_method_of_payment' => $selected_method_of_payment] |
|
962 | - ); |
|
963 | - } |
|
964 | - |
|
965 | - |
|
966 | - /** |
|
967 | - * _setup_payment_options |
|
968 | - * |
|
969 | - * @return EE_Form_Section_Proper |
|
970 | - * @throws EE_Error |
|
971 | - * @throws InvalidArgumentException |
|
972 | - * @throws InvalidDataTypeException |
|
973 | - * @throws InvalidInterfaceException |
|
974 | - */ |
|
975 | - public function _setup_payment_options() |
|
976 | - { |
|
977 | - // load payment method classes |
|
978 | - $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
979 | - if (empty($this->checkout->available_payment_methods)) { |
|
980 | - EE_Error::add_error( |
|
981 | - apply_filters( |
|
982 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
983 | - sprintf( |
|
984 | - esc_html__( |
|
985 | - '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.', |
|
986 | - 'event_espresso' |
|
987 | - ), |
|
988 | - '<br>', |
|
989 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
990 | - ) |
|
991 | - ), |
|
992 | - __FILE__, |
|
993 | - __FUNCTION__, |
|
994 | - __LINE__ |
|
995 | - ); |
|
996 | - } |
|
997 | - // switch up header depending on number of available payment methods |
|
998 | - $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
999 | - ? apply_filters( |
|
1000 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
1001 | - esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
1002 | - ) |
|
1003 | - : apply_filters( |
|
1004 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
1005 | - esc_html__('Method of Payment', 'event_espresso') |
|
1006 | - ); |
|
1007 | - $available_payment_methods = [ |
|
1008 | - // display the "Payment Method" header |
|
1009 | - 'payment_method_header' => new EE_Form_Section_HTML( |
|
1010 | - apply_filters( |
|
1011 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header', |
|
1012 | - EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'), |
|
1013 | - $payment_method_header |
|
1014 | - ) |
|
1015 | - ), |
|
1016 | - ]; |
|
1017 | - // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
1018 | - $available_payment_method_options = []; |
|
1019 | - $default_payment_method_option = []; |
|
1020 | - // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
1021 | - $payment_methods_billing_info = [ |
|
1022 | - new EE_Form_Section_HTML( |
|
1023 | - EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
1024 | - ), |
|
1025 | - ]; |
|
1026 | - // loop through payment methods |
|
1027 | - foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
1028 | - if ($payment_method instanceof EE_Payment_Method) { |
|
1029 | - $payment_method_button = EEH_HTML::img( |
|
1030 | - $payment_method->button_url(), |
|
1031 | - $payment_method->name(), |
|
1032 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
1033 | - 'spco-payment-method-btn-img' |
|
1034 | - ); |
|
1035 | - // check if any payment methods are set as default |
|
1036 | - // if payment method is already selected OR nothing is selected and this payment method should be |
|
1037 | - // open_by_default |
|
1038 | - if ( |
|
1039 | - ($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
1040 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1041 | - ) { |
|
1042 | - $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
1043 | - $this->_save_selected_method_of_payment(); |
|
1044 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
1045 | - } else { |
|
1046 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
1047 | - } |
|
1048 | - $payment_methods_billing_info[ $payment_method->slug() . '-info' ] = |
|
1049 | - $this->_payment_method_billing_info( |
|
1050 | - $payment_method |
|
1051 | - ); |
|
1052 | - } |
|
1053 | - } |
|
1054 | - // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
1055 | - // of PMs |
|
1056 | - $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
1057 | - // now generate the actual form inputs |
|
1058 | - $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
1059 | - $available_payment_method_options |
|
1060 | - ); |
|
1061 | - $available_payment_methods += $payment_methods_billing_info; |
|
1062 | - // build the available payment methods form |
|
1063 | - return new EE_Form_Section_Proper( |
|
1064 | - [ |
|
1065 | - 'html_id' => 'spco-available-methods-of-payment-dv', |
|
1066 | - 'subsections' => $available_payment_methods, |
|
1067 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1068 | - ] |
|
1069 | - ); |
|
1070 | - } |
|
1071 | - |
|
1072 | - |
|
1073 | - /** |
|
1074 | - * _get_available_payment_methods |
|
1075 | - * |
|
1076 | - * @return EE_Payment_Method[] |
|
1077 | - * @throws EE_Error |
|
1078 | - * @throws InvalidArgumentException |
|
1079 | - * @throws InvalidDataTypeException |
|
1080 | - * @throws InvalidInterfaceException |
|
1081 | - */ |
|
1082 | - protected function _get_available_payment_methods() |
|
1083 | - { |
|
1084 | - if (! empty($this->checkout->available_payment_methods)) { |
|
1085 | - return $this->checkout->available_payment_methods; |
|
1086 | - } |
|
1087 | - $available_payment_methods = []; |
|
1088 | - $EEM_Payment_Method = EEM_Payment_Method::instance(); |
|
1089 | - // get all active payment methods |
|
1090 | - $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
1091 | - $this->checkout->transaction, |
|
1092 | - EEM_Payment_Method::scope_cart |
|
1093 | - ); |
|
1094 | - foreach ($payment_methods as $payment_method) { |
|
1095 | - if ($payment_method instanceof EE_Payment_Method) { |
|
1096 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1097 | - } |
|
1098 | - } |
|
1099 | - return $available_payment_methods; |
|
1100 | - } |
|
1101 | - |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * _available_payment_method_inputs |
|
1105 | - * |
|
1106 | - * @access private |
|
1107 | - * @param array $available_payment_method_options |
|
1108 | - * @return EE_Form_Section_Proper |
|
1109 | - * @throws EE_Error |
|
1110 | - * @throws EE_Error |
|
1111 | - */ |
|
1112 | - private function _available_payment_method_inputs($available_payment_method_options = []) |
|
1113 | - { |
|
1114 | - // generate inputs |
|
1115 | - return new EE_Form_Section_Proper( |
|
1116 | - [ |
|
1117 | - 'html_id' => 'ee-available-payment-method-inputs', |
|
1118 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1119 | - 'subsections' => [ |
|
1120 | - '' => new EE_Radio_Button_Input( |
|
1121 | - $available_payment_method_options, |
|
1122 | - [ |
|
1123 | - 'html_name' => 'selected_method_of_payment', |
|
1124 | - 'html_class' => 'spco-payment-method', |
|
1125 | - 'default' => $this->checkout->selected_method_of_payment, |
|
1126 | - 'label_size' => 11, |
|
1127 | - 'enforce_label_size' => true, |
|
1128 | - ] |
|
1129 | - ), |
|
1130 | - ], |
|
1131 | - ] |
|
1132 | - ); |
|
1133 | - } |
|
1134 | - |
|
1135 | - |
|
1136 | - /** |
|
1137 | - * _payment_method_billing_info |
|
1138 | - * |
|
1139 | - * @access private |
|
1140 | - * @param EE_Payment_Method $payment_method |
|
1141 | - * @return EE_Form_Section_Proper |
|
1142 | - * @throws EE_Error |
|
1143 | - * @throws InvalidArgumentException |
|
1144 | - * @throws InvalidDataTypeException |
|
1145 | - * @throws InvalidInterfaceException |
|
1146 | - */ |
|
1147 | - private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
1148 | - { |
|
1149 | - $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug(); |
|
1150 | - // generate the billing form for payment method |
|
1151 | - $billing_form = $currently_selected |
|
1152 | - ? $this->_get_billing_form_for_payment_method($payment_method) |
|
1153 | - : new EE_Form_Section_HTML(); |
|
1154 | - $this->checkout->billing_form = $currently_selected |
|
1155 | - ? $billing_form |
|
1156 | - : $this->checkout->billing_form; |
|
1157 | - // it's all in the details |
|
1158 | - $info_html = EEH_HTML::h3( |
|
1159 | - esc_html__('Important information regarding your payment', 'event_espresso'), |
|
1160 | - '', |
|
1161 | - 'spco-payment-method-hdr' |
|
1162 | - ); |
|
1163 | - // add some info regarding the step, either from what's saved in the admin, |
|
1164 | - // or a default string depending on whether the PM has a billing form or not |
|
1165 | - if ($payment_method->description()) { |
|
1166 | - $payment_method_info = $payment_method->description(); |
|
1167 | - } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
1168 | - $payment_method_info = sprintf( |
|
1169 | - esc_html__( |
|
1170 | - 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
1171 | - 'event_espresso' |
|
1172 | - ), |
|
1173 | - $this->submit_button_text() |
|
1174 | - ); |
|
1175 | - } else { |
|
1176 | - $payment_method_info = sprintf( |
|
1177 | - esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
1178 | - $this->submit_button_text() |
|
1179 | - ); |
|
1180 | - } |
|
1181 | - $info_html .= EEH_HTML::div( |
|
1182 | - apply_filters( |
|
1183 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
1184 | - $payment_method_info |
|
1185 | - ), |
|
1186 | - '', |
|
1187 | - 'spco-payment-method-desc ee-attention' |
|
1188 | - ); |
|
1189 | - return new EE_Form_Section_Proper( |
|
1190 | - [ |
|
1191 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1192 | - 'html_class' => 'spco-payment-method-info-dv', |
|
1193 | - // only display the selected or default PM |
|
1194 | - 'html_style' => $currently_selected ? '' : 'display:none;', |
|
1195 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1196 | - 'subsections' => [ |
|
1197 | - 'info' => new EE_Form_Section_HTML($info_html), |
|
1198 | - 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
1199 | - ], |
|
1200 | - ] |
|
1201 | - ); |
|
1202 | - } |
|
1203 | - |
|
1204 | - |
|
1205 | - /** |
|
1206 | - * get_billing_form_html_for_payment_method |
|
1207 | - * |
|
1208 | - * @return bool |
|
1209 | - * @throws EE_Error |
|
1210 | - * @throws InvalidArgumentException |
|
1211 | - * @throws ReflectionException |
|
1212 | - * @throws InvalidDataTypeException |
|
1213 | - * @throws InvalidInterfaceException |
|
1214 | - */ |
|
1215 | - public function get_billing_form_html_for_payment_method() |
|
1216 | - { |
|
1217 | - // how have they chosen to pay? |
|
1218 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1219 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1220 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1221 | - return false; |
|
1222 | - } |
|
1223 | - if ( |
|
1224 | - apply_filters( |
|
1225 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1226 | - false |
|
1227 | - ) |
|
1228 | - ) { |
|
1229 | - EE_Error::add_success( |
|
1230 | - apply_filters( |
|
1231 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1232 | - sprintf( |
|
1233 | - esc_html__( |
|
1234 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1235 | - 'event_espresso' |
|
1236 | - ), |
|
1237 | - $this->checkout->payment_method->name() |
|
1238 | - ) |
|
1239 | - ) |
|
1240 | - ); |
|
1241 | - } |
|
1242 | - // now generate billing form for selected method of payment |
|
1243 | - $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
1244 | - // fill form with attendee info if applicable |
|
1245 | - if ( |
|
1246 | - $payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1247 | - && $this->checkout->transaction_has_primary_registrant() |
|
1248 | - ) { |
|
1249 | - $payment_method_billing_form->populate_from_attendee( |
|
1250 | - $this->checkout->transaction->primary_registration()->attendee() |
|
1251 | - ); |
|
1252 | - } |
|
1253 | - // and debug content |
|
1254 | - if ( |
|
1255 | - $payment_method_billing_form instanceof EE_Billing_Info_Form |
|
1256 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1257 | - ) { |
|
1258 | - $payment_method_billing_form = |
|
1259 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1260 | - $payment_method_billing_form |
|
1261 | - ); |
|
1262 | - } |
|
1263 | - $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
1264 | - ? $payment_method_billing_form->get_html() |
|
1265 | - : ''; |
|
1266 | - $this->checkout->json_response->set_return_data(['payment_method_info' => $billing_info]); |
|
1267 | - // localize validation rules for main form |
|
1268 | - $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
1269 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1270 | - return true; |
|
1271 | - } |
|
1272 | - |
|
1273 | - |
|
1274 | - /** |
|
1275 | - * _get_billing_form_for_payment_method |
|
1276 | - * |
|
1277 | - * @param EE_Payment_Method $payment_method |
|
1278 | - * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
1279 | - * @throws EE_Error |
|
1280 | - * @throws InvalidArgumentException |
|
1281 | - * @throws InvalidDataTypeException |
|
1282 | - * @throws InvalidInterfaceException |
|
1283 | - */ |
|
1284 | - private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
1285 | - { |
|
1286 | - $billing_form = $payment_method->type_obj()->billing_form( |
|
1287 | - $this->checkout->transaction, |
|
1288 | - ['amount_owing' => $this->checkout->amount_owing] |
|
1289 | - ); |
|
1290 | - if ($billing_form instanceof EE_Billing_Info_Form) { |
|
1291 | - if ( |
|
1292 | - apply_filters( |
|
1293 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1294 | - false |
|
1295 | - ) |
|
1296 | - && $this->request->requestParamIsSet('payment_method') |
|
1297 | - ) { |
|
1298 | - EE_Error::add_success( |
|
1299 | - apply_filters( |
|
1300 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1301 | - sprintf( |
|
1302 | - esc_html__( |
|
1303 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1304 | - 'event_espresso' |
|
1305 | - ), |
|
1306 | - $payment_method->name() |
|
1307 | - ) |
|
1308 | - ) |
|
1309 | - ); |
|
1310 | - } |
|
1311 | - return apply_filters( |
|
1312 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
1313 | - $billing_form, |
|
1314 | - $payment_method |
|
1315 | - ); |
|
1316 | - } |
|
1317 | - // no actual billing form, so return empty HTML form section |
|
1318 | - return new EE_Form_Section_HTML(); |
|
1319 | - } |
|
1320 | - |
|
1321 | - |
|
1322 | - /** |
|
1323 | - * _get_selected_method_of_payment |
|
1324 | - * |
|
1325 | - * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
1326 | - * is not found in the incoming request |
|
1327 | - * @param string $request_param |
|
1328 | - * @return NULL|string |
|
1329 | - * @throws EE_Error |
|
1330 | - * @throws InvalidArgumentException |
|
1331 | - * @throws InvalidDataTypeException |
|
1332 | - * @throws InvalidInterfaceException |
|
1333 | - */ |
|
1334 | - private function _get_selected_method_of_payment( |
|
1335 | - $required = false, |
|
1336 | - $request_param = 'selected_method_of_payment' |
|
1337 | - ) { |
|
1338 | - // is selected_method_of_payment set in the request ? |
|
1339 | - $selected_method_of_payment = $this->request->getRequestParam($request_param); |
|
1340 | - if ($selected_method_of_payment) { |
|
1341 | - // sanitize it |
|
1342 | - $selected_method_of_payment = is_array($selected_method_of_payment) |
|
1343 | - ? array_shift($selected_method_of_payment) |
|
1344 | - : $selected_method_of_payment; |
|
1345 | - $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
1346 | - // store it in the session so that it's available for all subsequent requests including AJAX |
|
1347 | - $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
1348 | - } else { |
|
1349 | - // or is is set in the session ? |
|
1350 | - $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
1351 | - 'selected_method_of_payment' |
|
1352 | - ); |
|
1353 | - } |
|
1354 | - // do ya really really gotta have it? |
|
1355 | - if (empty($selected_method_of_payment) && $required) { |
|
1356 | - EE_Error::add_error( |
|
1357 | - sprintf( |
|
1358 | - esc_html__( |
|
1359 | - '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.', |
|
1360 | - 'event_espresso' |
|
1361 | - ), |
|
1362 | - '<br/>', |
|
1363 | - '<br/>', |
|
1364 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1365 | - ), |
|
1366 | - __FILE__, |
|
1367 | - __FUNCTION__, |
|
1368 | - __LINE__ |
|
1369 | - ); |
|
1370 | - return null; |
|
1371 | - } |
|
1372 | - return $selected_method_of_payment; |
|
1373 | - } |
|
1374 | - |
|
1375 | - |
|
1376 | - |
|
1377 | - |
|
1378 | - |
|
1379 | - |
|
1380 | - /********************************************************************************************************/ |
|
1381 | - /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
1382 | - /********************************************************************************************************/ |
|
1383 | - /** |
|
1384 | - * switch_payment_method |
|
1385 | - * |
|
1386 | - * @return bool |
|
1387 | - * @throws EE_Error |
|
1388 | - * @throws InvalidArgumentException |
|
1389 | - * @throws InvalidDataTypeException |
|
1390 | - * @throws InvalidInterfaceException |
|
1391 | - * @throws ReflectionException |
|
1392 | - */ |
|
1393 | - public function switch_payment_method() |
|
1394 | - { |
|
1395 | - if (! $this->_verify_payment_method_is_set()) { |
|
1396 | - return false; |
|
1397 | - } |
|
1398 | - if ( |
|
1399 | - apply_filters( |
|
1400 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1401 | - false |
|
1402 | - ) |
|
1403 | - ) { |
|
1404 | - EE_Error::add_success( |
|
1405 | - apply_filters( |
|
1406 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1407 | - sprintf( |
|
1408 | - esc_html__( |
|
1409 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1410 | - 'event_espresso' |
|
1411 | - ), |
|
1412 | - $this->checkout->payment_method->name() |
|
1413 | - ) |
|
1414 | - ) |
|
1415 | - ); |
|
1416 | - } |
|
1417 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1418 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1419 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1420 | - $this->checkout->payment_method |
|
1421 | - ); |
|
1422 | - } |
|
1423 | - // fill form with attendee info if applicable |
|
1424 | - if ( |
|
1425 | - apply_filters( |
|
1426 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
1427 | - ( |
|
1428 | - $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1429 | - && $this->checkout->transaction_has_primary_registrant() |
|
1430 | - ), |
|
1431 | - $this->checkout->billing_form, |
|
1432 | - $this->checkout->transaction |
|
1433 | - ) |
|
1434 | - ) { |
|
1435 | - $this->checkout->billing_form->populate_from_attendee( |
|
1436 | - $this->checkout->transaction->primary_registration()->attendee() |
|
1437 | - ); |
|
1438 | - } |
|
1439 | - // and debug content |
|
1440 | - if ( |
|
1441 | - $this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1442 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1443 | - ) { |
|
1444 | - $this->checkout->billing_form = |
|
1445 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1446 | - $this->checkout->billing_form |
|
1447 | - ); |
|
1448 | - } |
|
1449 | - // get html and validation rules for form |
|
1450 | - if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
1451 | - $this->checkout->json_response->set_return_data( |
|
1452 | - ['payment_method_info' => $this->checkout->billing_form->get_html()] |
|
1453 | - ); |
|
1454 | - // localize validation rules for main form |
|
1455 | - $this->checkout->billing_form->localize_validation_rules(true); |
|
1456 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1457 | - } else { |
|
1458 | - $this->checkout->json_response->set_return_data(['payment_method_info' => '']); |
|
1459 | - } |
|
1460 | - // prevents advancement to next step |
|
1461 | - $this->checkout->continue_reg = false; |
|
1462 | - return true; |
|
1463 | - } |
|
1464 | - |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * _verify_payment_method_is_set |
|
1468 | - * |
|
1469 | - * @return bool |
|
1470 | - * @throws EE_Error |
|
1471 | - * @throws InvalidArgumentException |
|
1472 | - * @throws ReflectionException |
|
1473 | - * @throws InvalidDataTypeException |
|
1474 | - * @throws InvalidInterfaceException |
|
1475 | - */ |
|
1476 | - protected function _verify_payment_method_is_set() |
|
1477 | - { |
|
1478 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1479 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
1480 | - // how have they chosen to pay? |
|
1481 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1482 | - } else { |
|
1483 | - // choose your own adventure based on method_of_payment |
|
1484 | - switch ($this->checkout->selected_method_of_payment) { |
|
1485 | - case 'events_sold_out': |
|
1486 | - EE_Error::add_attention( |
|
1487 | - apply_filters( |
|
1488 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
1489 | - esc_html__( |
|
1490 | - '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.', |
|
1491 | - 'event_espresso' |
|
1492 | - ) |
|
1493 | - ), |
|
1494 | - __FILE__, |
|
1495 | - __FUNCTION__, |
|
1496 | - __LINE__ |
|
1497 | - ); |
|
1498 | - return false; |
|
1499 | - case 'payments_closed': |
|
1500 | - EE_Error::add_attention( |
|
1501 | - apply_filters( |
|
1502 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
1503 | - esc_html__( |
|
1504 | - '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.', |
|
1505 | - 'event_espresso' |
|
1506 | - ) |
|
1507 | - ), |
|
1508 | - __FILE__, |
|
1509 | - __FUNCTION__, |
|
1510 | - __LINE__ |
|
1511 | - ); |
|
1512 | - return false; |
|
1513 | - case 'no_payment_required': |
|
1514 | - EE_Error::add_attention( |
|
1515 | - apply_filters( |
|
1516 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
1517 | - esc_html__( |
|
1518 | - '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.', |
|
1519 | - 'event_espresso' |
|
1520 | - ) |
|
1521 | - ), |
|
1522 | - __FILE__, |
|
1523 | - __FUNCTION__, |
|
1524 | - __LINE__ |
|
1525 | - ); |
|
1526 | - return false; |
|
1527 | - default: |
|
1528 | - } |
|
1529 | - } |
|
1530 | - // verify payment method |
|
1531 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1532 | - // get payment method for selected method of payment |
|
1533 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1534 | - } |
|
1535 | - return $this->checkout->payment_method instanceof EE_Payment_Method; |
|
1536 | - } |
|
1537 | - |
|
1538 | - |
|
1539 | - |
|
1540 | - /********************************************************************************************************/ |
|
1541 | - /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
1542 | - /********************************************************************************************************/ |
|
1543 | - /** |
|
1544 | - * save_payer_details_via_ajax |
|
1545 | - * |
|
1546 | - * @return void |
|
1547 | - * @throws EE_Error |
|
1548 | - * @throws InvalidArgumentException |
|
1549 | - * @throws ReflectionException |
|
1550 | - * @throws RuntimeException |
|
1551 | - * @throws InvalidDataTypeException |
|
1552 | - * @throws InvalidInterfaceException |
|
1553 | - */ |
|
1554 | - public function save_payer_details_via_ajax() |
|
1555 | - { |
|
1556 | - if (! $this->_verify_payment_method_is_set()) { |
|
1557 | - return; |
|
1558 | - } |
|
1559 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1560 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1561 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1562 | - $this->checkout->payment_method |
|
1563 | - ); |
|
1564 | - } |
|
1565 | - // generate primary attendee from payer info if applicable |
|
1566 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
1567 | - $attendee = $this->_create_attendee_from_request_data(); |
|
1568 | - if ($attendee instanceof EE_Attendee) { |
|
1569 | - foreach ($this->checkout->transaction->registrations() as $registration) { |
|
1570 | - if ($registration->is_primary_registrant()) { |
|
1571 | - $this->checkout->primary_attendee_obj = $attendee; |
|
1572 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
1573 | - $registration->set_attendee_id($attendee->ID()); |
|
1574 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1575 | - } |
|
1576 | - } |
|
1577 | - } |
|
1578 | - } |
|
1579 | - } |
|
1580 | - |
|
1581 | - |
|
1582 | - /** |
|
1583 | - * create_attendee_from_request_data |
|
1584 | - * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
1585 | - * |
|
1586 | - * @return EE_Attendee |
|
1587 | - * @throws EE_Error |
|
1588 | - * @throws InvalidArgumentException |
|
1589 | - * @throws ReflectionException |
|
1590 | - * @throws InvalidDataTypeException |
|
1591 | - * @throws InvalidInterfaceException |
|
1592 | - */ |
|
1593 | - protected function _create_attendee_from_request_data() |
|
1594 | - { |
|
1595 | - // get State ID |
|
1596 | - $STA_ID = $this->request->getRequestParam('state'); |
|
1597 | - if (! empty($STA_ID)) { |
|
1598 | - // can we get state object from name ? |
|
1599 | - EE_Registry::instance()->load_model('State'); |
|
1600 | - $state = EEM_State::instance()->get_col([['STA_name' => $STA_ID], 'limit' => 1], 'STA_ID'); |
|
1601 | - $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
1602 | - } |
|
1603 | - // get Country ISO |
|
1604 | - $CNT_ISO = $this->request->getRequestParam('country'); |
|
1605 | - if (! empty($CNT_ISO)) { |
|
1606 | - // can we get country object from name ? |
|
1607 | - EE_Registry::instance()->load_model('Country'); |
|
1608 | - $country = EEM_Country::instance()->get_col( |
|
1609 | - [['CNT_name' => $CNT_ISO], 'limit' => 1], |
|
1610 | - 'CNT_ISO' |
|
1611 | - ); |
|
1612 | - $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
1613 | - } |
|
1614 | - // grab attendee data |
|
1615 | - $attendee_data = [ |
|
1616 | - 'ATT_fname' => $this->request->getRequestParam('first_name'), |
|
1617 | - 'ATT_lname' => $this->request->getRequestParam('last_name'), |
|
1618 | - 'ATT_email' => $this->request->getRequestParam('email'), |
|
1619 | - 'ATT_address' => $this->request->getRequestParam('address'), |
|
1620 | - 'ATT_address2' => $this->request->getRequestParam('address2'), |
|
1621 | - 'ATT_city' => $this->request->getRequestParam('city'), |
|
1622 | - 'STA_ID' => $STA_ID, |
|
1623 | - 'CNT_ISO' => $CNT_ISO, |
|
1624 | - 'ATT_zip' => $this->request->getRequestParam('zip'), |
|
1625 | - 'ATT_phone' => $this->request->getRequestParam('phone'), |
|
1626 | - ]; |
|
1627 | - // validate the email address since it is the most important piece of info |
|
1628 | - if (empty($attendee_data['ATT_email'])) { |
|
1629 | - EE_Error::add_error( |
|
1630 | - esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
1631 | - __FILE__, |
|
1632 | - __FUNCTION__, |
|
1633 | - __LINE__ |
|
1634 | - ); |
|
1635 | - } |
|
1636 | - // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
1637 | - // AND email address |
|
1638 | - if ( |
|
1639 | - ! empty($attendee_data['ATT_fname']) |
|
1640 | - && ! empty($attendee_data['ATT_lname']) |
|
1641 | - && ! empty($attendee_data['ATT_email']) |
|
1642 | - ) { |
|
1643 | - $existing_attendee = EEM_Attendee::instance()->find_existing_attendee( |
|
1644 | - [ |
|
1645 | - 'ATT_fname' => $attendee_data['ATT_fname'], |
|
1646 | - 'ATT_lname' => $attendee_data['ATT_lname'], |
|
1647 | - 'ATT_email' => $attendee_data['ATT_email'], |
|
1648 | - ] |
|
1649 | - ); |
|
1650 | - if ($existing_attendee instanceof EE_Attendee) { |
|
1651 | - return $existing_attendee; |
|
1652 | - } |
|
1653 | - } |
|
1654 | - // no existing attendee? kk let's create a new one |
|
1655 | - // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
1656 | - // don't exist |
|
1657 | - $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
1658 | - ? $attendee_data['ATT_fname'] |
|
1659 | - : $attendee_data['ATT_email']; |
|
1660 | - $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
1661 | - ? $attendee_data['ATT_lname'] |
|
1662 | - : $attendee_data['ATT_email']; |
|
1663 | - return EE_Attendee::new_instance($attendee_data); |
|
1664 | - } |
|
1665 | - |
|
1666 | - |
|
1667 | - |
|
1668 | - /********************************************************************************************************/ |
|
1669 | - /**************************************** PROCESS REG STEP *****************************************/ |
|
1670 | - /********************************************************************************************************/ |
|
1671 | - /** |
|
1672 | - * process_reg_step |
|
1673 | - * |
|
1674 | - * @return bool |
|
1675 | - * @throws EE_Error |
|
1676 | - * @throws InvalidArgumentException |
|
1677 | - * @throws ReflectionException |
|
1678 | - * @throws EntityNotFoundException |
|
1679 | - * @throws InvalidDataTypeException |
|
1680 | - * @throws InvalidInterfaceException |
|
1681 | - * @throws InvalidStatusException |
|
1682 | - */ |
|
1683 | - public function process_reg_step() |
|
1684 | - { |
|
1685 | - // how have they chosen to pay? |
|
1686 | - $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
1687 | - ? 'no_payment_required' |
|
1688 | - : $this->_get_selected_method_of_payment(true); |
|
1689 | - // choose your own adventure based on method_of_payment |
|
1690 | - switch ($this->checkout->selected_method_of_payment) { |
|
1691 | - case 'events_sold_out': |
|
1692 | - $this->checkout->redirect = true; |
|
1693 | - $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
1694 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1695 | - // mark this reg step as completed |
|
1696 | - $this->set_completed(); |
|
1697 | - return false; |
|
1698 | - |
|
1699 | - case 'payments_closed': |
|
1700 | - if ( |
|
1701 | - apply_filters( |
|
1702 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
1703 | - false |
|
1704 | - ) |
|
1705 | - ) { |
|
1706 | - EE_Error::add_success( |
|
1707 | - esc_html__('no payment required at this time.', 'event_espresso'), |
|
1708 | - __FILE__, |
|
1709 | - __FUNCTION__, |
|
1710 | - __LINE__ |
|
1711 | - ); |
|
1712 | - } |
|
1713 | - // mark this reg step as completed |
|
1714 | - $this->set_completed(); |
|
1715 | - return true; |
|
1716 | - |
|
1717 | - case 'no_payment_required': |
|
1718 | - if ( |
|
1719 | - apply_filters( |
|
1720 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
1721 | - false |
|
1722 | - ) |
|
1723 | - ) { |
|
1724 | - EE_Error::add_success( |
|
1725 | - esc_html__('no payment required.', 'event_espresso'), |
|
1726 | - __FILE__, |
|
1727 | - __FUNCTION__, |
|
1728 | - __LINE__ |
|
1729 | - ); |
|
1730 | - } |
|
1731 | - // mark this reg step as completed |
|
1732 | - $this->set_completed(); |
|
1733 | - return true; |
|
1734 | - |
|
1735 | - default: |
|
1736 | - $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
1737 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
1738 | - ); |
|
1739 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
1740 | - $registrations, |
|
1741 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
1742 | - ); |
|
1743 | - // calculate difference between the two arrays |
|
1744 | - $registrations = array_diff($registrations, $ejected_registrations); |
|
1745 | - if (empty($registrations)) { |
|
1746 | - $this->_redirect_because_event_sold_out(); |
|
1747 | - return false; |
|
1748 | - } |
|
1749 | - $payment = $this->_process_payment(); |
|
1750 | - if ($payment instanceof EE_Payment) { |
|
1751 | - $this->checkout->continue_reg = true; |
|
1752 | - $this->_maybe_set_completed($payment); |
|
1753 | - } else { |
|
1754 | - $this->checkout->continue_reg = false; |
|
1755 | - } |
|
1756 | - return $payment instanceof EE_Payment; |
|
1757 | - } |
|
1758 | - } |
|
1759 | - |
|
1760 | - |
|
1761 | - /** |
|
1762 | - * _redirect_because_event_sold_out |
|
1763 | - * |
|
1764 | - * @return void |
|
1765 | - */ |
|
1766 | - protected function _redirect_because_event_sold_out() |
|
1767 | - { |
|
1768 | - $this->checkout->continue_reg = false; |
|
1769 | - // set redirect URL |
|
1770 | - $this->checkout->redirect_url = add_query_arg( |
|
1771 | - ['e_reg_url_link' => $this->checkout->reg_url_link], |
|
1772 | - $this->checkout->current_step->reg_step_url() |
|
1773 | - ); |
|
1774 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1775 | - } |
|
1776 | - |
|
1777 | - |
|
1778 | - /** |
|
1779 | - * _maybe_set_completed |
|
1780 | - * |
|
1781 | - * @param EE_Payment_Method $payment_method |
|
1782 | - * @return void |
|
1783 | - * @throws EE_Error |
|
1784 | - */ |
|
1785 | - protected function _maybe_set_completed(EE_Payment $payment) |
|
1786 | - { |
|
1787 | - // Do we need to redirect them? If so, there's more work to be done. |
|
1788 | - if (! $payment->redirect_url()){ |
|
1789 | - $this->set_completed(); |
|
1790 | - } |
|
1791 | - } |
|
1792 | - |
|
1793 | - |
|
1794 | - /** |
|
1795 | - * update_reg_step |
|
1796 | - * this is the final step after a user revisits the site to retry a payment |
|
1797 | - * |
|
1798 | - * @return bool |
|
1799 | - * @throws EE_Error |
|
1800 | - * @throws InvalidArgumentException |
|
1801 | - * @throws ReflectionException |
|
1802 | - * @throws EntityNotFoundException |
|
1803 | - * @throws InvalidDataTypeException |
|
1804 | - * @throws InvalidInterfaceException |
|
1805 | - * @throws InvalidStatusException |
|
1806 | - */ |
|
1807 | - public function update_reg_step() |
|
1808 | - { |
|
1809 | - $success = true; |
|
1810 | - // if payment required |
|
1811 | - if ($this->checkout->transaction->total() > 0) { |
|
1812 | - do_action( |
|
1813 | - 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
1814 | - $this->checkout->transaction |
|
1815 | - ); |
|
1816 | - // attempt payment via payment method |
|
1817 | - $success = $this->process_reg_step(); |
|
1818 | - } |
|
1819 | - if ($success && ! $this->checkout->redirect) { |
|
1820 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
1821 | - $this->checkout->transaction->ID() |
|
1822 | - ); |
|
1823 | - // set return URL |
|
1824 | - $this->checkout->redirect_url = add_query_arg( |
|
1825 | - ['e_reg_url_link' => $this->checkout->reg_url_link], |
|
1826 | - $this->checkout->thank_you_page_url |
|
1827 | - ); |
|
1828 | - } |
|
1829 | - return $success; |
|
1830 | - } |
|
1831 | - |
|
1832 | - |
|
1833 | - /** |
|
1834 | - * @return EE_Payment|null |
|
1835 | - * @throws EE_Error |
|
1836 | - * @throws InvalidArgumentException |
|
1837 | - * @throws ReflectionException |
|
1838 | - * @throws RuntimeException |
|
1839 | - * @throws InvalidDataTypeException |
|
1840 | - * @throws 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 null; |
|
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 null; |
|
1854 | - } |
|
1855 | - // get EE_Payment_Method object |
|
1856 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1857 | - return null; |
|
1858 | - } |
|
1859 | - // setup billing form |
|
1860 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
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 null; |
|
1867 | - } |
|
1868 | - } |
|
1869 | - // ensure primary registrant has been fully processed |
|
1870 | - if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1871 | - return null; |
|
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 $payment; |
|
1901 | - } |
|
1902 | - return null; |
|
1903 | - } |
|
1904 | - if ($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 $payment; |
|
1909 | - } |
|
1910 | - // where's my money? |
|
1911 | - return null; |
|
1912 | - } |
|
1913 | - |
|
1914 | - |
|
1915 | - /** |
|
1916 | - * _last_second_ticket_verifications |
|
1917 | - * |
|
1918 | - * @return bool |
|
1919 | - * @throws EE_Error |
|
1920 | - * @throws ReflectionException |
|
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 | - * @return bool |
|
1963 | - * @throws EE_Error |
|
1964 | - * @throws InvalidArgumentException |
|
1965 | - * @throws ReflectionException |
|
1966 | - * @throws InvalidDataTypeException |
|
1967 | - * @throws InvalidInterfaceException |
|
1968 | - */ |
|
1969 | - public function redirect_form() |
|
1970 | - { |
|
1971 | - $payment_method_billing_info = $this->_payment_method_billing_info( |
|
1972 | - $this->_get_payment_method_for_selected_method_of_payment() |
|
1973 | - ); |
|
1974 | - $html = $payment_method_billing_info->get_html(); |
|
1975 | - $html .= $this->checkout->redirect_form; |
|
1976 | - /** @var ResponseInterface $response */ |
|
1977 | - $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class); |
|
1978 | - $response->addOutput($html); |
|
1979 | - return true; |
|
1980 | - } |
|
1981 | - |
|
1982 | - |
|
1983 | - /** |
|
1984 | - * _billing_form_is_valid |
|
1985 | - * |
|
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 = []; |
|
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 | - * @return bool |
|
2062 | - * @throws EE_Error |
|
2063 | - * @throws InvalidArgumentException |
|
2064 | - * @throws ReflectionException |
|
2065 | - * @throws RuntimeException |
|
2066 | - * @throws InvalidDataTypeException |
|
2067 | - * @throws InvalidInterfaceException |
|
2068 | - */ |
|
2069 | - private function _setup_primary_registrant_prior_to_payment() |
|
2070 | - { |
|
2071 | - // check if transaction has a primary registrant and that it has a related Attendee object |
|
2072 | - // if not, then we need to at least gather some primary registrant data before attempting payment |
|
2073 | - if ( |
|
2074 | - $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 | - * @return bool |
|
2099 | - * @throws EE_Error |
|
2100 | - * @throws InvalidArgumentException |
|
2101 | - * @throws ReflectionException |
|
2102 | - * @throws InvalidDataTypeException |
|
2103 | - * @throws InvalidInterfaceException |
|
2104 | - */ |
|
2105 | - private function _capture_primary_registration_data_from_billing_form() |
|
2106 | - { |
|
2107 | - // convert billing form data into an attendee |
|
2108 | - $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
2109 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2110 | - EE_Error::add_error( |
|
2111 | - sprintf( |
|
2112 | - esc_html__( |
|
2113 | - 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2114 | - 'event_espresso' |
|
2115 | - ), |
|
2116 | - '<br/>', |
|
2117 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2118 | - ), |
|
2119 | - __FILE__, |
|
2120 | - __FUNCTION__, |
|
2121 | - __LINE__ |
|
2122 | - ); |
|
2123 | - return false; |
|
2124 | - } |
|
2125 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2126 | - if (! $primary_registration instanceof EE_Registration) { |
|
2127 | - EE_Error::add_error( |
|
2128 | - sprintf( |
|
2129 | - esc_html__( |
|
2130 | - 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2131 | - 'event_espresso' |
|
2132 | - ), |
|
2133 | - '<br/>', |
|
2134 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2135 | - ), |
|
2136 | - __FILE__, |
|
2137 | - __FUNCTION__, |
|
2138 | - __LINE__ |
|
2139 | - ); |
|
2140 | - return false; |
|
2141 | - } |
|
2142 | - if ( |
|
2143 | - ! $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 | - * @return EE_Payment_Method |
|
2175 | - * @throws EE_Error |
|
2176 | - * @throws InvalidArgumentException |
|
2177 | - * @throws ReflectionException |
|
2178 | - * @throws InvalidDataTypeException |
|
2179 | - * @throws InvalidInterfaceException |
|
2180 | - */ |
|
2181 | - private function _get_payment_method_for_selected_method_of_payment() |
|
2182 | - { |
|
2183 | - if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
2184 | - $this->_redirect_because_event_sold_out(); |
|
2185 | - return null; |
|
2186 | - } |
|
2187 | - // get EE_Payment_Method object |
|
2188 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
2189 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2190 | - } else { |
|
2191 | - // load EEM_Payment_Method |
|
2192 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
2193 | - $EEM_Payment_Method = EEM_Payment_Method::instance(); |
|
2194 | - $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
2195 | - } |
|
2196 | - // verify $payment_method |
|
2197 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
2198 | - // not a payment |
|
2199 | - EE_Error::add_error( |
|
2200 | - sprintf( |
|
2201 | - esc_html__( |
|
2202 | - 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2203 | - 'event_espresso' |
|
2204 | - ), |
|
2205 | - '<br/>', |
|
2206 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2207 | - ), |
|
2208 | - __FILE__, |
|
2209 | - __FUNCTION__, |
|
2210 | - __LINE__ |
|
2211 | - ); |
|
2212 | - return null; |
|
2213 | - } |
|
2214 | - // and verify it has a valid Payment_Method Type object |
|
2215 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2216 | - // not a payment |
|
2217 | - EE_Error::add_error( |
|
2218 | - sprintf( |
|
2219 | - esc_html__( |
|
2220 | - 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2221 | - 'event_espresso' |
|
2222 | - ), |
|
2223 | - '<br/>', |
|
2224 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2225 | - ), |
|
2226 | - __FILE__, |
|
2227 | - __FUNCTION__, |
|
2228 | - __LINE__ |
|
2229 | - ); |
|
2230 | - return null; |
|
2231 | - } |
|
2232 | - return $payment_method; |
|
2233 | - } |
|
2234 | - |
|
2235 | - |
|
2236 | - /** |
|
2237 | - * _attempt_payment |
|
2238 | - * |
|
2239 | - * @access private |
|
2240 | - * @type EE_Payment_Method $payment_method |
|
2241 | - * @return mixed EE_Payment | boolean |
|
2242 | - * @throws EE_Error |
|
2243 | - * @throws InvalidArgumentException |
|
2244 | - * @throws ReflectionException |
|
2245 | - * @throws InvalidDataTypeException |
|
2246 | - * @throws InvalidInterfaceException |
|
2247 | - */ |
|
2248 | - private function _attempt_payment(EE_Payment_Method $payment_method) |
|
2249 | - { |
|
2250 | - $payment = null; |
|
2251 | - $this->checkout->transaction->save(); |
|
2252 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2253 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
2254 | - return false; |
|
2255 | - } |
|
2256 | - try { |
|
2257 | - $payment_processor->set_revisit($this->checkout->revisit); |
|
2258 | - // generate payment object |
|
2259 | - $payment = $payment_processor->process_payment( |
|
2260 | - $payment_method, |
|
2261 | - $this->checkout->transaction, |
|
2262 | - $this->checkout->amount_owing, |
|
2263 | - $this->checkout->billing_form, |
|
2264 | - $this->_get_return_url($payment_method), |
|
2265 | - 'CART', |
|
2266 | - $this->checkout->admin_request, |
|
2267 | - true, |
|
2268 | - $this->reg_step_url() |
|
2269 | - ); |
|
2270 | - } catch (Exception $e) { |
|
2271 | - $this->_handle_payment_processor_exception($e); |
|
2272 | - } |
|
2273 | - return $payment; |
|
2274 | - } |
|
2275 | - |
|
2276 | - |
|
2277 | - /** |
|
2278 | - * _handle_payment_processor_exception |
|
2279 | - * |
|
2280 | - * @param Exception $e |
|
2281 | - * @return void |
|
2282 | - * @throws EE_Error |
|
2283 | - * @throws InvalidArgumentException |
|
2284 | - * @throws InvalidDataTypeException |
|
2285 | - * @throws InvalidInterfaceException |
|
2286 | - */ |
|
2287 | - protected function _handle_payment_processor_exception(Exception $e) |
|
2288 | - { |
|
2289 | - EE_Error::add_error( |
|
2290 | - sprintf( |
|
2291 | - esc_html__( |
|
2292 | - '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', |
|
2293 | - 'event_espresso' |
|
2294 | - ), |
|
2295 | - '<br/>', |
|
2296 | - EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
2297 | - $e->getMessage(), |
|
2298 | - $e->getFile(), |
|
2299 | - $e->getLine() |
|
2300 | - ), |
|
2301 | - __FILE__, |
|
2302 | - __FUNCTION__, |
|
2303 | - __LINE__ |
|
2304 | - ); |
|
2305 | - } |
|
2306 | - |
|
2307 | - |
|
2308 | - /** |
|
2309 | - * _get_return_url |
|
2310 | - * |
|
2311 | - * @param EE_Payment_Method $payment_method |
|
2312 | - * @return string |
|
2313 | - * @throws EE_Error |
|
2314 | - * @throws ReflectionException |
|
2315 | - */ |
|
2316 | - protected function _get_return_url(EE_Payment_Method $payment_method) |
|
2317 | - { |
|
2318 | - $return_url = ''; |
|
2319 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
2320 | - case EE_PMT_Base::offsite: |
|
2321 | - $return_url = add_query_arg( |
|
2322 | - [ |
|
2323 | - 'action' => 'process_gateway_response', |
|
2324 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2325 | - 'spco_txn' => $this->checkout->transaction->ID(), |
|
2326 | - ], |
|
2327 | - $this->reg_step_url() |
|
2328 | - ); |
|
2329 | - break; |
|
2330 | - case EE_PMT_Base::onsite: |
|
2331 | - case EE_PMT_Base::offline: |
|
2332 | - $return_url = $this->checkout->next_step->reg_step_url(); |
|
2333 | - break; |
|
2334 | - } |
|
2335 | - return $return_url; |
|
2336 | - } |
|
2337 | - |
|
2338 | - |
|
2339 | - /** |
|
2340 | - * _validate_payment |
|
2341 | - * |
|
2342 | - * @param EE_Payment $payment |
|
2343 | - * @return EE_Payment|FALSE |
|
2344 | - * @throws EE_Error |
|
2345 | - * @throws InvalidArgumentException |
|
2346 | - * @throws InvalidDataTypeException |
|
2347 | - * @throws InvalidInterfaceException |
|
2348 | - */ |
|
2349 | - private function _validate_payment($payment = null) |
|
2350 | - { |
|
2351 | - if ($this->checkout->payment_method->is_off_line()) { |
|
2352 | - return true; |
|
2353 | - } |
|
2354 | - // verify payment object |
|
2355 | - if (! $payment instanceof EE_Payment) { |
|
2356 | - // not a payment |
|
2357 | - EE_Error::add_error( |
|
2358 | - sprintf( |
|
2359 | - esc_html__( |
|
2360 | - 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
2361 | - 'event_espresso' |
|
2362 | - ), |
|
2363 | - '<br/>', |
|
2364 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2365 | - ), |
|
2366 | - __FILE__, |
|
2367 | - __FUNCTION__, |
|
2368 | - __LINE__ |
|
2369 | - ); |
|
2370 | - return false; |
|
2371 | - } |
|
2372 | - return $payment; |
|
2373 | - } |
|
2374 | - |
|
2375 | - |
|
2376 | - /** |
|
2377 | - * _post_payment_processing |
|
2378 | - * |
|
2379 | - * @param EE_Payment|bool $payment |
|
2380 | - * @return bool |
|
2381 | - * @throws EE_Error |
|
2382 | - * @throws InvalidArgumentException |
|
2383 | - * @throws InvalidDataTypeException |
|
2384 | - * @throws InvalidInterfaceException |
|
2385 | - * @throws ReflectionException |
|
2386 | - */ |
|
2387 | - private function _post_payment_processing($payment = null) |
|
2388 | - { |
|
2389 | - // Off-Line payment? |
|
2390 | - if ($payment === true) { |
|
2391 | - return true; |
|
2392 | - } elseif ($payment instanceof EE_Payment){ |
|
2393 | - // Should the user be redirected? |
|
2394 | - if($payment->redirect_url()) { |
|
2395 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
2396 | - $this->checkout->redirect = true; |
|
2397 | - $this->checkout->redirect_form = $payment->redirect_form(); |
|
2398 | - $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
2399 | - // set JSON response |
|
2400 | - $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
2401 | - // and lastly, let's bump the payment status to pending |
|
2402 | - $payment->set_status(EEM_Payment::status_id_pending); |
|
2403 | - $payment->save(); |
|
2404 | - } else |
|
2405 | - // User shouldn't be redirected. So let's process it here. |
|
2406 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2407 | - // $this->_setup_redirect_for_next_step(); |
|
2408 | - $this->checkout->continue_reg = false; |
|
2409 | - } |
|
2410 | - } else { |
|
2411 | - // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
2412 | - $this->checkout->continue_reg = false; |
|
2413 | - return false; |
|
2414 | - } |
|
2415 | - return $payment; |
|
2416 | - } |
|
2417 | - |
|
2418 | - |
|
2419 | - /** |
|
2420 | - * _process_payment_status |
|
2421 | - * |
|
2422 | - * @type EE_Payment $payment |
|
2423 | - * @param string $payment_occurs |
|
2424 | - * @return bool |
|
2425 | - * @throws EE_Error |
|
2426 | - * @throws InvalidArgumentException |
|
2427 | - * @throws InvalidDataTypeException |
|
2428 | - * @throws InvalidInterfaceException |
|
2429 | - */ |
|
2430 | - private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
2431 | - { |
|
2432 | - // off-line payment? carry on |
|
2433 | - if ($payment_occurs === EE_PMT_Base::offline) { |
|
2434 | - return true; |
|
2435 | - } |
|
2436 | - // verify payment validity |
|
2437 | - if ($payment instanceof EE_Payment) { |
|
2438 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
2439 | - $msg = $payment->gateway_response(); |
|
2440 | - // check results |
|
2441 | - switch ($payment->status()) { |
|
2442 | - // good payment |
|
2443 | - case EEM_Payment::status_id_approved: |
|
2444 | - EE_Error::add_success( |
|
2445 | - esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
2446 | - __FILE__, |
|
2447 | - __FUNCTION__, |
|
2448 | - __LINE__ |
|
2449 | - ); |
|
2450 | - return true; |
|
2451 | - // slow payment |
|
2452 | - case EEM_Payment::status_id_pending: |
|
2453 | - if (empty($msg)) { |
|
2454 | - $msg = esc_html__( |
|
2455 | - 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
2456 | - 'event_espresso' |
|
2457 | - ); |
|
2458 | - } |
|
2459 | - EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2460 | - return true; |
|
2461 | - // don't wanna payment |
|
2462 | - case EEM_Payment::status_id_cancelled: |
|
2463 | - if (empty($msg)) { |
|
2464 | - $msg = _n( |
|
2465 | - 'Payment cancelled. Please try again.', |
|
2466 | - 'Payment cancelled. Please try again or select another method of payment.', |
|
2467 | - count($this->checkout->available_payment_methods), |
|
2468 | - 'event_espresso' |
|
2469 | - ); |
|
2470 | - } |
|
2471 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2472 | - return false; |
|
2473 | - // not enough payment |
|
2474 | - case EEM_Payment::status_id_declined: |
|
2475 | - if (empty($msg)) { |
|
2476 | - $msg = _n( |
|
2477 | - 'We\'re sorry but your payment was declined. Please try again.', |
|
2478 | - 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
2479 | - count($this->checkout->available_payment_methods), |
|
2480 | - 'event_espresso' |
|
2481 | - ); |
|
2482 | - } |
|
2483 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2484 | - return false; |
|
2485 | - // bad payment |
|
2486 | - case EEM_Payment::status_id_failed: |
|
2487 | - if (! empty($msg)) { |
|
2488 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2489 | - return false; |
|
2490 | - } |
|
2491 | - // default to error below |
|
2492 | - break; |
|
2493 | - } |
|
2494 | - } |
|
2495 | - // off-site payment gateway responses are too unreliable, so let's just assume that |
|
2496 | - // the payment processing is just running slower than the registrant's request |
|
2497 | - if ($payment_occurs === EE_PMT_Base::offsite) { |
|
2498 | - return true; |
|
2499 | - } |
|
2500 | - EE_Error::add_error( |
|
2501 | - sprintf( |
|
2502 | - esc_html__( |
|
2503 | - 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2504 | - 'event_espresso' |
|
2505 | - ), |
|
2506 | - '<br/>', |
|
2507 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2508 | - ), |
|
2509 | - __FILE__, |
|
2510 | - __FUNCTION__, |
|
2511 | - __LINE__ |
|
2512 | - ); |
|
2513 | - return false; |
|
2514 | - } |
|
2515 | - |
|
2516 | - |
|
2517 | - |
|
2518 | - |
|
2519 | - |
|
2520 | - |
|
2521 | - /********************************************************************************************************/ |
|
2522 | - /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
2523 | - /********************************************************************************************************/ |
|
2524 | - /** |
|
2525 | - * process_gateway_response |
|
2526 | - * this is the return point for Off-Site Payment Methods |
|
2527 | - * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
2528 | - * otherwise, it will load up the last payment made for the TXN. |
|
2529 | - * If the payment retrieved looks good, it will then either: |
|
2530 | - * complete the current step and allow advancement to the next reg step |
|
2531 | - * or present the payment options again |
|
2532 | - * |
|
2533 | - * @return bool |
|
2534 | - * @throws EE_Error |
|
2535 | - * @throws InvalidArgumentException |
|
2536 | - * @throws ReflectionException |
|
2537 | - * @throws InvalidDataTypeException |
|
2538 | - * @throws InvalidInterfaceException |
|
2539 | - */ |
|
2540 | - public function process_gateway_response() |
|
2541 | - { |
|
2542 | - // how have they chosen to pay? |
|
2543 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
2544 | - // get EE_Payment_Method object |
|
2545 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2546 | - $this->checkout->continue_reg = false; |
|
2547 | - return false; |
|
2548 | - } |
|
2549 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
2550 | - return false; |
|
2551 | - } |
|
2552 | - $this->_validate_offsite_return(); |
|
2553 | - // verify TXN |
|
2554 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
2555 | - $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
2556 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
2557 | - $this->checkout->continue_reg = false; |
|
2558 | - return false; |
|
2559 | - } |
|
2560 | - $payment = $this->_process_off_site_payment($gateway); |
|
2561 | - $payment = $this->_process_cancelled_payments($payment); |
|
2562 | - $payment = $this->_validate_payment($payment); |
|
2563 | - // if payment was not declined by the payment gateway or cancelled by the registrant |
|
2564 | - if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
2565 | - // $this->_setup_redirect_for_next_step(); |
|
2566 | - // store that for later |
|
2567 | - $this->checkout->payment = $payment; |
|
2568 | - // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
2569 | - // because we will complete this step during the IPN processing then |
|
2570 | - if (! $this->handle_IPN_in_this_request()) { |
|
2571 | - $this->set_completed(); |
|
2572 | - } |
|
2573 | - return true; |
|
2574 | - } |
|
2575 | - } |
|
2576 | - // DEBUG LOG |
|
2577 | - // $this->checkout->log( |
|
2578 | - // __CLASS__, |
|
2579 | - // __FUNCTION__, |
|
2580 | - // __LINE__, |
|
2581 | - // array('payment' => $payment) |
|
2582 | - // ); |
|
2583 | - $this->checkout->continue_reg = false; |
|
2584 | - return false; |
|
2585 | - } |
|
2586 | - |
|
2587 | - |
|
2588 | - /** |
|
2589 | - * _validate_return |
|
2590 | - * |
|
2591 | - * @return void |
|
2592 | - * @throws EE_Error |
|
2593 | - * @throws InvalidArgumentException |
|
2594 | - * @throws InvalidDataTypeException |
|
2595 | - * @throws InvalidInterfaceException |
|
2596 | - * @throws ReflectionException |
|
2597 | - */ |
|
2598 | - private function _validate_offsite_return() |
|
2599 | - { |
|
2600 | - $TXN_ID = $this->request->getRequestParam('spco_txn', 0, 'int'); |
|
2601 | - if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
2602 | - // Houston... we might have a problem |
|
2603 | - $invalid_TXN = false; |
|
2604 | - // first gather some info |
|
2605 | - $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2606 | - $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
2607 | - ? $valid_TXN->primary_registration() |
|
2608 | - : null; |
|
2609 | - // let's start by retrieving the cart for this TXN |
|
2610 | - $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
2611 | - if ($cart instanceof EE_Cart) { |
|
2612 | - // verify that the current cart has tickets |
|
2613 | - $tickets = $cart->get_tickets(); |
|
2614 | - if (empty($tickets)) { |
|
2615 | - $invalid_TXN = true; |
|
2616 | - } |
|
2617 | - } else { |
|
2618 | - $invalid_TXN = true; |
|
2619 | - } |
|
2620 | - $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
2621 | - ? $primary_registrant->session_ID() |
|
2622 | - : null; |
|
2623 | - // validate current Session ID and compare against valid TXN session ID |
|
2624 | - if ( |
|
2625 | - $invalid_TXN // if this is already true, then skip other checks |
|
2626 | - || EE_Session::instance()->id() === null |
|
2627 | - || ( |
|
2628 | - // WARNING !!! |
|
2629 | - // this could be PayPal sending back duplicate requests (ya they do that) |
|
2630 | - // or it **could** mean someone is simply registering AGAIN after having just done so |
|
2631 | - // so now we need to determine if this current TXN looks valid or not |
|
2632 | - // and whether this reg step has even been started ? |
|
2633 | - EE_Session::instance()->id() === $valid_TXN_SID |
|
2634 | - // really? you're half way through this reg step, but you never started it ? |
|
2635 | - && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
2636 | - ) |
|
2637 | - ) { |
|
2638 | - $invalid_TXN = true; |
|
2639 | - } |
|
2640 | - if ($invalid_TXN) { |
|
2641 | - // is the valid TXN completed ? |
|
2642 | - if ($valid_TXN instanceof EE_Transaction) { |
|
2643 | - // has this step even been started ? |
|
2644 | - $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
2645 | - if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
2646 | - // so it **looks** like this is a double request from PayPal |
|
2647 | - // so let's try to pick up where we left off |
|
2648 | - $this->checkout->transaction = $valid_TXN; |
|
2649 | - $this->checkout->refresh_all_entities(true); |
|
2650 | - return; |
|
2651 | - } |
|
2652 | - } |
|
2653 | - // you appear to be lost? |
|
2654 | - $this->_redirect_wayward_request($primary_registrant); |
|
2655 | - } |
|
2656 | - } |
|
2657 | - } |
|
2658 | - |
|
2659 | - |
|
2660 | - /** |
|
2661 | - * _redirect_wayward_request |
|
2662 | - * |
|
2663 | - * @param EE_Registration|null $primary_registrant |
|
2664 | - * @return void |
|
2665 | - * @throws EE_Error |
|
2666 | - * @throws InvalidArgumentException |
|
2667 | - * @throws InvalidDataTypeException |
|
2668 | - * @throws InvalidInterfaceException |
|
2669 | - * @throws ReflectionException |
|
2670 | - */ |
|
2671 | - private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
2672 | - { |
|
2673 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2674 | - // try redirecting based on the current TXN |
|
2675 | - $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
2676 | - ? $this->checkout->transaction->primary_registration() |
|
2677 | - : null; |
|
2678 | - } |
|
2679 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2680 | - EE_Error::add_error( |
|
2681 | - sprintf( |
|
2682 | - esc_html__( |
|
2683 | - '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.', |
|
2684 | - 'event_espresso' |
|
2685 | - ), |
|
2686 | - '<br/>', |
|
2687 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2688 | - ), |
|
2689 | - __FILE__, |
|
2690 | - __FUNCTION__, |
|
2691 | - __LINE__ |
|
2692 | - ); |
|
2693 | - return; |
|
2694 | - } |
|
2695 | - // make sure transaction is not locked |
|
2696 | - $this->checkout->transaction->unlock(); |
|
2697 | - wp_safe_redirect( |
|
2698 | - add_query_arg( |
|
2699 | - [ |
|
2700 | - 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
2701 | - ], |
|
2702 | - $this->checkout->thank_you_page_url |
|
2703 | - ) |
|
2704 | - ); |
|
2705 | - exit(); |
|
2706 | - } |
|
2707 | - |
|
2708 | - |
|
2709 | - /** |
|
2710 | - * _process_off_site_payment |
|
2711 | - * |
|
2712 | - * @param EE_Offsite_Gateway $gateway |
|
2713 | - * @return EE_Payment |
|
2714 | - * @throws EE_Error |
|
2715 | - * @throws InvalidArgumentException |
|
2716 | - * @throws InvalidDataTypeException |
|
2717 | - * @throws InvalidInterfaceException |
|
2718 | - * @throws ReflectionException |
|
2719 | - */ |
|
2720 | - private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
2721 | - { |
|
2722 | - try { |
|
2723 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
2724 | - $request_data = $request->requestParams(); |
|
2725 | - // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
2726 | - $this->set_handle_IPN_in_this_request( |
|
2727 | - $gateway->handle_IPN_in_this_request($request_data, false) |
|
2728 | - ); |
|
2729 | - if ($this->handle_IPN_in_this_request()) { |
|
2730 | - // get payment details and process results |
|
2731 | - /** @type EE_Payment_Processor $payment_processor */ |
|
2732 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2733 | - $payment = $payment_processor->process_ipn( |
|
2734 | - $request_data, |
|
2735 | - $this->checkout->transaction, |
|
2736 | - $this->checkout->payment_method, |
|
2737 | - true, |
|
2738 | - false |
|
2739 | - ); |
|
2740 | - // $payment_source = 'process_ipn'; |
|
2741 | - } else { |
|
2742 | - $payment = $this->checkout->transaction->last_payment(); |
|
2743 | - // $payment_source = 'last_payment'; |
|
2744 | - } |
|
2745 | - } catch (Exception $e) { |
|
2746 | - // let's just eat the exception and try to move on using any previously set payment info |
|
2747 | - $payment = $this->checkout->transaction->last_payment(); |
|
2748 | - // $payment_source = 'last_payment after Exception'; |
|
2749 | - // but if we STILL don't have a payment object |
|
2750 | - if (! $payment instanceof EE_Payment) { |
|
2751 | - // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
2752 | - $this->_handle_payment_processor_exception($e); |
|
2753 | - } |
|
2754 | - } |
|
2755 | - return $payment; |
|
2756 | - } |
|
2757 | - |
|
2758 | - |
|
2759 | - /** |
|
2760 | - * _process_cancelled_payments |
|
2761 | - * just makes sure that the payment status gets updated correctly |
|
2762 | - * so tha tan error isn't generated during payment validation |
|
2763 | - * |
|
2764 | - * @param EE_Payment $payment |
|
2765 | - * @return EE_Payment|null |
|
2766 | - * @throws EE_Error |
|
2767 | - */ |
|
2768 | - private function _process_cancelled_payments($payment = null) |
|
2769 | - { |
|
2770 | - if ( |
|
2771 | - $payment instanceof EE_Payment |
|
2772 | - && $this->request->requestParamIsSet('ee_cancel_payment') |
|
2773 | - && $payment->status() === EEM_Payment::status_id_failed |
|
2774 | - ) { |
|
2775 | - $payment->set_status(EEM_Payment::status_id_cancelled); |
|
2776 | - } |
|
2777 | - return $payment; |
|
2778 | - } |
|
2779 | - |
|
2780 | - |
|
2781 | - /** |
|
2782 | - * get_transaction_details_for_gateways |
|
2783 | - * |
|
2784 | - * @access public |
|
2785 | - * @return void |
|
2786 | - * @throws EE_Error |
|
2787 | - * @throws InvalidArgumentException |
|
2788 | - * @throws ReflectionException |
|
2789 | - * @throws InvalidDataTypeException |
|
2790 | - * @throws InvalidInterfaceException |
|
2791 | - */ |
|
2792 | - public function get_transaction_details_for_gateways() |
|
2793 | - { |
|
2794 | - $txn_details = []; |
|
2795 | - // ya gotta make a choice man |
|
2796 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
2797 | - $txn_details = [ |
|
2798 | - 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
2799 | - ]; |
|
2800 | - } |
|
2801 | - // get EE_Payment_Method object |
|
2802 | - if ( |
|
2803 | - empty($txn_details) |
|
2804 | - && ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
2805 | - ) { |
|
2806 | - $txn_details = [ |
|
2807 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2808 | - 'error' => esc_html__( |
|
2809 | - 'A valid Payment Method could not be determined.', |
|
2810 | - 'event_espresso' |
|
2811 | - ), |
|
2812 | - ]; |
|
2813 | - } |
|
2814 | - if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
2815 | - $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
2816 | - $txn_details = [ |
|
2817 | - 'TXN_ID' => $this->checkout->transaction->ID(), |
|
2818 | - 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
2819 | - 'TXN_total' => $this->checkout->transaction->total(), |
|
2820 | - 'TXN_paid' => $this->checkout->transaction->paid(), |
|
2821 | - 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
2822 | - 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
2823 | - 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
2824 | - 'payment_amount' => $this->checkout->amount_owing, |
|
2825 | - 'return_url' => $return_url, |
|
2826 | - 'cancel_url' => add_query_arg(['ee_cancel_payment' => true], $return_url), |
|
2827 | - 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
2828 | - [ |
|
2829 | - 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
2830 | - 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
2831 | - ] |
|
2832 | - ), |
|
2833 | - ]; |
|
2834 | - } |
|
2835 | - echo wp_json_encode($txn_details); |
|
2836 | - exit(); |
|
2837 | - } |
|
2838 | - |
|
2839 | - |
|
2840 | - /** |
|
2841 | - * __sleep |
|
2842 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
2843 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
2844 | - * reg form, because if needed, it will be regenerated anyways |
|
2845 | - * |
|
2846 | - * @return array |
|
2847 | - */ |
|
2848 | - public function __sleep() |
|
2849 | - { |
|
2850 | - // remove the reg form and the checkout |
|
2851 | - return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout', 'line_item_display']); |
|
2852 | - } |
|
23 | + /** |
|
24 | + * @var EE_Line_Item_Display $Line_Item_Display |
|
25 | + */ |
|
26 | + protected $line_item_display; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var boolean $handle_IPN_in_this_request |
|
30 | + */ |
|
31 | + protected $handle_IPN_in_this_request = false; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
36 | + * |
|
37 | + * @access public |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public static function set_hooks() |
|
41 | + { |
|
42 | + add_filter( |
|
43 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
44 | + ['EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters'] |
|
45 | + ); |
|
46 | + add_action( |
|
47 | + 'wp_ajax_switch_spco_billing_form', |
|
48 | + ['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form'] |
|
49 | + ); |
|
50 | + add_action( |
|
51 | + 'wp_ajax_nopriv_switch_spco_billing_form', |
|
52 | + ['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form'] |
|
53 | + ); |
|
54 | + add_action('wp_ajax_save_payer_details', ['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details']); |
|
55 | + add_action( |
|
56 | + 'wp_ajax_nopriv_save_payer_details', |
|
57 | + ['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details'] |
|
58 | + ); |
|
59 | + add_action( |
|
60 | + 'wp_ajax_get_transaction_details_for_gateways', |
|
61 | + ['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details'] |
|
62 | + ); |
|
63 | + add_action( |
|
64 | + 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
65 | + ['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details'] |
|
66 | + ); |
|
67 | + add_filter( |
|
68 | + 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
69 | + ['EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'], |
|
70 | + 10, |
|
71 | + 1 |
|
72 | + ); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * ajax switch_spco_billing_form |
|
78 | + * |
|
79 | + */ |
|
80 | + public static function switch_spco_billing_form() |
|
81 | + { |
|
82 | + EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * ajax save_payer_details |
|
88 | + * |
|
89 | + */ |
|
90 | + public static function save_payer_details() |
|
91 | + { |
|
92 | + EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * ajax get_transaction_details |
|
98 | + * |
|
99 | + */ |
|
100 | + public static function get_transaction_details() |
|
101 | + { |
|
102 | + EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * bypass_recaptcha_for_load_payment_method |
|
108 | + * |
|
109 | + * @access public |
|
110 | + * @return array |
|
111 | + * @throws InvalidArgumentException |
|
112 | + * @throws InvalidDataTypeException |
|
113 | + * @throws InvalidInterfaceException |
|
114 | + */ |
|
115 | + public static function bypass_recaptcha_for_load_payment_method() |
|
116 | + { |
|
117 | + return [ |
|
118 | + 'EESID' => EE_Registry::instance()->SSN->id(), |
|
119 | + 'step' => 'payment_options', |
|
120 | + 'action' => 'spco_billing_form', |
|
121 | + ]; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * class constructor |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param EE_Checkout $checkout |
|
130 | + */ |
|
131 | + public function __construct(EE_Checkout $checkout) |
|
132 | + { |
|
133 | + $this->request = EED_Single_Page_Checkout::getRequest(); |
|
134 | + $this->_slug = 'payment_options'; |
|
135 | + $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
136 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php'; |
|
137 | + $this->checkout = $checkout; |
|
138 | + $this->_reset_success_message(); |
|
139 | + $this->set_instructions( |
|
140 | + esc_html__( |
|
141 | + 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
142 | + 'event_espresso' |
|
143 | + ) |
|
144 | + ); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @return null |
|
150 | + */ |
|
151 | + public function line_item_display() |
|
152 | + { |
|
153 | + return $this->line_item_display; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @param null $line_item_display |
|
159 | + */ |
|
160 | + public function set_line_item_display($line_item_display) |
|
161 | + { |
|
162 | + $this->line_item_display = $line_item_display; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @return boolean |
|
168 | + */ |
|
169 | + public function handle_IPN_in_this_request() |
|
170 | + { |
|
171 | + return $this->handle_IPN_in_this_request; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @param boolean $handle_IPN_in_this_request |
|
177 | + */ |
|
178 | + public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
179 | + { |
|
180 | + $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * translate_js_strings |
|
186 | + * |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + public function translate_js_strings() |
|
190 | + { |
|
191 | + EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
192 | + 'Please select a method of payment in order to continue.', |
|
193 | + 'event_espresso' |
|
194 | + ); |
|
195 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
196 | + 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
197 | + 'event_espresso' |
|
198 | + ); |
|
199 | + EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
200 | + 'Forwarding to Secure Payment Provider.', |
|
201 | + 'event_espresso' |
|
202 | + ); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * enqueue_styles_and_scripts |
|
208 | + * |
|
209 | + * @return void |
|
210 | + * @throws EE_Error |
|
211 | + * @throws InvalidArgumentException |
|
212 | + * @throws InvalidDataTypeException |
|
213 | + * @throws InvalidInterfaceException |
|
214 | + * @throws ReflectionException |
|
215 | + */ |
|
216 | + public function enqueue_styles_and_scripts() |
|
217 | + { |
|
218 | + $transaction = $this->checkout->transaction; |
|
219 | + // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
220 | + if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
221 | + return; |
|
222 | + } |
|
223 | + foreach ( |
|
224 | + EEM_Payment_Method::instance()->get_all_for_transaction( |
|
225 | + $transaction, |
|
226 | + EEM_Payment_Method::scope_cart |
|
227 | + ) as $payment_method |
|
228 | + ) { |
|
229 | + $type_obj = $payment_method->type_obj(); |
|
230 | + if ($type_obj instanceof EE_PMT_Base) { |
|
231 | + $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
232 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
233 | + $billing_form->enqueue_js(); |
|
234 | + } |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * initialize_reg_step |
|
242 | + * |
|
243 | + * @return bool |
|
244 | + * @throws EE_Error |
|
245 | + * @throws InvalidArgumentException |
|
246 | + * @throws ReflectionException |
|
247 | + * @throws InvalidDataTypeException |
|
248 | + * @throws InvalidInterfaceException |
|
249 | + */ |
|
250 | + public function initialize_reg_step() |
|
251 | + { |
|
252 | + // TODO: if /when we implement donations, then this will need overriding |
|
253 | + if ( |
|
254 | + // don't need payment options for: |
|
255 | + // registrations made via the admin |
|
256 | + // completed transactions |
|
257 | + // overpaid transactions |
|
258 | + // $ 0.00 transactions(no payment required) |
|
259 | + ! $this->checkout->payment_required() |
|
260 | + // but do NOT remove if current action being called belongs to this reg step |
|
261 | + && ! is_callable([$this, $this->checkout->action]) |
|
262 | + && ! $this->completed() |
|
263 | + ) { |
|
264 | + // and if so, then we no longer need the Payment Options step |
|
265 | + if ($this->is_current_step()) { |
|
266 | + $this->checkout->generate_reg_form = false; |
|
267 | + } |
|
268 | + $this->checkout->remove_reg_step($this->_slug); |
|
269 | + // DEBUG LOG |
|
270 | + // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
271 | + return false; |
|
272 | + } |
|
273 | + // load EEM_Payment_Method |
|
274 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
275 | + // get all active payment methods |
|
276 | + $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
277 | + $this->checkout->transaction, |
|
278 | + EEM_Payment_Method::scope_cart |
|
279 | + ); |
|
280 | + return true; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @return EE_Form_Section_Proper |
|
286 | + * @throws EE_Error |
|
287 | + * @throws InvalidArgumentException |
|
288 | + * @throws ReflectionException |
|
289 | + * @throws EntityNotFoundException |
|
290 | + * @throws InvalidDataTypeException |
|
291 | + * @throws InvalidInterfaceException |
|
292 | + * @throws InvalidStatusException |
|
293 | + */ |
|
294 | + public function generate_reg_form() |
|
295 | + { |
|
296 | + // reset in case someone changes their mind |
|
297 | + $this->_reset_selected_method_of_payment(); |
|
298 | + // set some defaults |
|
299 | + $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
300 | + $registrations_requiring_payment = []; |
|
301 | + $registrations_for_free_events = []; |
|
302 | + $registrations_requiring_pre_approval = []; |
|
303 | + $sold_out_events = []; |
|
304 | + $insufficient_spaces_available = []; |
|
305 | + $no_payment_required = true; |
|
306 | + // loop thru registrations to gather info |
|
307 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
308 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
309 | + $registrations, |
|
310 | + $this->checkout->revisit |
|
311 | + ); |
|
312 | + foreach ($registrations as $REG_ID => $registration) { |
|
313 | + /** @var $registration EE_Registration */ |
|
314 | + // has this registration lost it's space ? |
|
315 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
316 | + if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
317 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
318 | + } else { |
|
319 | + $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
320 | + } |
|
321 | + continue; |
|
322 | + } |
|
323 | + // event requires admin approval |
|
324 | + if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
325 | + // add event to list of events with pre-approval reg status |
|
326 | + $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
327 | + do_action( |
|
328 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
329 | + $registration->event(), |
|
330 | + $this |
|
331 | + ); |
|
332 | + continue; |
|
333 | + } |
|
334 | + if ( |
|
335 | + $this->checkout->revisit |
|
336 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
337 | + && ( |
|
338 | + $registration->event()->is_sold_out() |
|
339 | + || $registration->event()->is_sold_out(true) |
|
340 | + ) |
|
341 | + ) { |
|
342 | + // add event to list of events that are sold out |
|
343 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
344 | + do_action( |
|
345 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
346 | + $registration->event(), |
|
347 | + $this |
|
348 | + ); |
|
349 | + continue; |
|
350 | + } |
|
351 | + // are they allowed to pay now and is there monies owing? |
|
352 | + if ($registration->owes_monies_and_can_pay()) { |
|
353 | + $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
354 | + do_action( |
|
355 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
356 | + $registration->event(), |
|
357 | + $this |
|
358 | + ); |
|
359 | + } elseif ( |
|
360 | + ! $this->checkout->revisit |
|
361 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
362 | + && $registration->ticket()->is_free() |
|
363 | + ) { |
|
364 | + $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
365 | + } |
|
366 | + } |
|
367 | + $subsections = []; |
|
368 | + // now decide which template to load |
|
369 | + if (! empty($sold_out_events)) { |
|
370 | + $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
371 | + } |
|
372 | + if (! empty($insufficient_spaces_available)) { |
|
373 | + $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
374 | + $insufficient_spaces_available |
|
375 | + ); |
|
376 | + } |
|
377 | + if (! empty($registrations_requiring_pre_approval)) { |
|
378 | + $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
379 | + $registrations_requiring_pre_approval |
|
380 | + ); |
|
381 | + } |
|
382 | + if (! empty($registrations_for_free_events)) { |
|
383 | + $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
384 | + } |
|
385 | + if (! empty($registrations_requiring_payment)) { |
|
386 | + if ($this->checkout->amount_owing > 0) { |
|
387 | + // autoload Line_Item_Display classes |
|
388 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
389 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
390 | + apply_filters( |
|
391 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
392 | + new EE_Line_Item_Filter_Collection() |
|
393 | + ), |
|
394 | + $this->checkout->cart->get_grand_total() |
|
395 | + ); |
|
396 | + /** @var EE_Line_Item $filtered_line_item_tree */ |
|
397 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
398 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
399 | + $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
400 | + $subsections['payment_options'] = $this->_display_payment_options( |
|
401 | + $this->line_item_display->display_line_item( |
|
402 | + $filtered_line_item_tree, |
|
403 | + ['registrations' => $registrations] |
|
404 | + ) |
|
405 | + ); |
|
406 | + $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
407 | + $this->_apply_registration_payments_to_amount_owing($registrations); |
|
408 | + } |
|
409 | + $no_payment_required = false; |
|
410 | + } else { |
|
411 | + $this->_hide_reg_step_submit_button_if_revisit(); |
|
412 | + } |
|
413 | + $this->_save_selected_method_of_payment(); |
|
414 | + |
|
415 | + $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
416 | + $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
417 | + |
|
418 | + return new EE_Form_Section_Proper( |
|
419 | + [ |
|
420 | + 'name' => $this->reg_form_name(), |
|
421 | + 'html_id' => $this->reg_form_name(), |
|
422 | + 'subsections' => $subsections, |
|
423 | + 'layout_strategy' => new EE_No_Layout(), |
|
424 | + ] |
|
425 | + ); |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * add line item filters required for this reg step |
|
431 | + * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
432 | + * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
433 | + * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
434 | + * payment options reg step, can apply these filters via the following: apply_filters( |
|
435 | + * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
436 | + * filter collection by passing that instead of instantiating a new collection |
|
437 | + * |
|
438 | + * @param EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
439 | + * @return EE_Line_Item_Filter_Collection |
|
440 | + * @throws EE_Error |
|
441 | + * @throws InvalidArgumentException |
|
442 | + * @throws ReflectionException |
|
443 | + * @throws EntityNotFoundException |
|
444 | + * @throws InvalidDataTypeException |
|
445 | + * @throws InvalidInterfaceException |
|
446 | + * @throws InvalidStatusException |
|
447 | + */ |
|
448 | + public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
449 | + { |
|
450 | + if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
451 | + return $line_item_filter_collection; |
|
452 | + } |
|
453 | + if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
454 | + return $line_item_filter_collection; |
|
455 | + } |
|
456 | + if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
457 | + return $line_item_filter_collection; |
|
458 | + } |
|
459 | + $line_item_filter_collection->add( |
|
460 | + new EE_Billable_Line_Item_Filter( |
|
461 | + EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
462 | + EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
463 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
464 | + ) |
|
465 | + ) |
|
466 | + ) |
|
467 | + ); |
|
468 | + $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
469 | + return $line_item_filter_collection; |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * remove_ejected_registrations |
|
475 | + * if a registrant has lost their potential space at an event due to lack of payment, |
|
476 | + * then this method removes them from the list of registrations being paid for during this request |
|
477 | + * |
|
478 | + * @param EE_Registration[] $registrations |
|
479 | + * @return EE_Registration[] |
|
480 | + * @throws EE_Error |
|
481 | + * @throws InvalidArgumentException |
|
482 | + * @throws ReflectionException |
|
483 | + * @throws EntityNotFoundException |
|
484 | + * @throws InvalidDataTypeException |
|
485 | + * @throws InvalidInterfaceException |
|
486 | + * @throws InvalidStatusException |
|
487 | + */ |
|
488 | + public static function remove_ejected_registrations(array $registrations) |
|
489 | + { |
|
490 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
491 | + $registrations, |
|
492 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
493 | + ); |
|
494 | + foreach ($registrations as $REG_ID => $registration) { |
|
495 | + // has this registration lost it's space ? |
|
496 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
497 | + unset($registrations[ $REG_ID ]); |
|
498 | + } |
|
499 | + } |
|
500 | + return $registrations; |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * find_registrations_that_lost_their_space |
|
506 | + * If a registrant chooses an offline payment method like Invoice, |
|
507 | + * then no space is reserved for them at the event until they fully pay fo that site |
|
508 | + * (unless the event's default reg status is set to APPROVED) |
|
509 | + * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
510 | + * then this method will determine which registrations have lost the ability to complete the reg process. |
|
511 | + * |
|
512 | + * @param EE_Registration[] $registrations |
|
513 | + * @param bool $revisit |
|
514 | + * @return array |
|
515 | + * @throws EE_Error |
|
516 | + * @throws InvalidArgumentException |
|
517 | + * @throws ReflectionException |
|
518 | + * @throws EntityNotFoundException |
|
519 | + * @throws InvalidDataTypeException |
|
520 | + * @throws InvalidInterfaceException |
|
521 | + * @throws InvalidStatusException |
|
522 | + */ |
|
523 | + public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
524 | + { |
|
525 | + // registrations per event |
|
526 | + $event_reg_count = []; |
|
527 | + // spaces left per event |
|
528 | + $event_spaces_remaining = []; |
|
529 | + // tickets left sorted by ID |
|
530 | + $tickets_remaining = []; |
|
531 | + // registrations that have lost their space |
|
532 | + $ejected_registrations = []; |
|
533 | + foreach ($registrations as $REG_ID => $registration) { |
|
534 | + if ( |
|
535 | + $registration->status_ID() === EEM_Registration::status_id_approved |
|
536 | + || apply_filters( |
|
537 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
538 | + false, |
|
539 | + $registration, |
|
540 | + $revisit |
|
541 | + ) |
|
542 | + ) { |
|
543 | + continue; |
|
544 | + } |
|
545 | + $EVT_ID = $registration->event_ID(); |
|
546 | + $ticket = $registration->ticket(); |
|
547 | + if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
548 | + $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
549 | + } |
|
550 | + if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
551 | + if (! isset($event_reg_count[ $EVT_ID ])) { |
|
552 | + $event_reg_count[ $EVT_ID ] = 0; |
|
553 | + } |
|
554 | + $event_reg_count[ $EVT_ID ]++; |
|
555 | + if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
556 | + $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
557 | + } |
|
558 | + } |
|
559 | + if ( |
|
560 | + $revisit |
|
561 | + && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
562 | + || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
563 | + ) |
|
564 | + ) { |
|
565 | + $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
566 | + if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
567 | + /** @type EE_Registration_Processor $registration_processor */ |
|
568 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
569 | + // at this point, we should have enough details about the registrant to consider the registration |
|
570 | + // NOT incomplete |
|
571 | + $registration_processor->manually_update_registration_status( |
|
572 | + $registration, |
|
573 | + EEM_Registration::status_id_wait_list |
|
574 | + ); |
|
575 | + } |
|
576 | + } |
|
577 | + } |
|
578 | + return $ejected_registrations; |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * _hide_reg_step_submit_button |
|
584 | + * removes the html for the reg step submit button |
|
585 | + * by replacing it with an empty string via filter callback |
|
586 | + * |
|
587 | + * @return void |
|
588 | + */ |
|
589 | + protected function _adjust_registration_status_if_event_old_sold() |
|
590 | + { |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * _hide_reg_step_submit_button |
|
596 | + * removes the html for the reg step submit button |
|
597 | + * by replacing it with an empty string via filter callback |
|
598 | + * |
|
599 | + * @return void |
|
600 | + */ |
|
601 | + protected function _hide_reg_step_submit_button_if_revisit() |
|
602 | + { |
|
603 | + if ($this->checkout->revisit) { |
|
604 | + add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
605 | + } |
|
606 | + } |
|
607 | + |
|
608 | + |
|
609 | + /** |
|
610 | + * sold_out_events |
|
611 | + * displays notices regarding events that have sold out since hte registrant first signed up |
|
612 | + * |
|
613 | + * @param EE_Event[] $sold_out_events_array |
|
614 | + * @return EE_Form_Section_Proper |
|
615 | + * @throws EE_Error |
|
616 | + */ |
|
617 | + private function _sold_out_events($sold_out_events_array = []) |
|
618 | + { |
|
619 | + // set some defaults |
|
620 | + $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
621 | + $sold_out_events = ''; |
|
622 | + foreach ($sold_out_events_array as $sold_out_event) { |
|
623 | + $sold_out_events .= EEH_HTML::li( |
|
624 | + EEH_HTML::span( |
|
625 | + ' ' . $sold_out_event->name(), |
|
626 | + '', |
|
627 | + 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
628 | + ) |
|
629 | + ); |
|
630 | + } |
|
631 | + return new EE_Form_Section_Proper( |
|
632 | + [ |
|
633 | + 'layout_strategy' => new EE_Template_Layout( |
|
634 | + [ |
|
635 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
636 | + . $this->_slug |
|
637 | + . '/sold_out_events.template.php', |
|
638 | + 'template_args' => apply_filters( |
|
639 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
640 | + [ |
|
641 | + 'sold_out_events' => $sold_out_events, |
|
642 | + 'sold_out_events_msg' => apply_filters( |
|
643 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
644 | + sprintf( |
|
645 | + esc_html__( |
|
646 | + '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', |
|
647 | + 'event_espresso' |
|
648 | + ), |
|
649 | + '<strong>', |
|
650 | + '</strong>', |
|
651 | + '<br />' |
|
652 | + ) |
|
653 | + ), |
|
654 | + ] |
|
655 | + ), |
|
656 | + ] |
|
657 | + ), |
|
658 | + ] |
|
659 | + ); |
|
660 | + } |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * _insufficient_spaces_available |
|
665 | + * displays notices regarding events that do not have enough remaining spaces |
|
666 | + * to satisfy the current number of registrations looking to pay |
|
667 | + * |
|
668 | + * @param EE_Event[] $insufficient_spaces_events_array |
|
669 | + * @return EE_Form_Section_Proper |
|
670 | + * @throws EE_Error |
|
671 | + * @throws ReflectionException |
|
672 | + */ |
|
673 | + private function _insufficient_spaces_available($insufficient_spaces_events_array = []) |
|
674 | + { |
|
675 | + // set some defaults |
|
676 | + $this->checkout->selected_method_of_payment = 'invoice'; |
|
677 | + $insufficient_space_events = ''; |
|
678 | + foreach ($insufficient_spaces_events_array as $event) { |
|
679 | + if ($event instanceof EE_Event) { |
|
680 | + $insufficient_space_events .= EEH_HTML::li( |
|
681 | + EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
682 | + ); |
|
683 | + } |
|
684 | + } |
|
685 | + return new EE_Form_Section_Proper( |
|
686 | + [ |
|
687 | + 'subsections' => [ |
|
688 | + 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
689 | + 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
690 | + ], |
|
691 | + 'layout_strategy' => new EE_Template_Layout( |
|
692 | + [ |
|
693 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
694 | + . $this->_slug |
|
695 | + . '/sold_out_events.template.php', |
|
696 | + 'template_args' => apply_filters( |
|
697 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
698 | + [ |
|
699 | + 'sold_out_events' => $insufficient_space_events, |
|
700 | + 'sold_out_events_msg' => apply_filters( |
|
701 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
702 | + esc_html__( |
|
703 | + '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.', |
|
704 | + 'event_espresso' |
|
705 | + ) |
|
706 | + ), |
|
707 | + ] |
|
708 | + ), |
|
709 | + ] |
|
710 | + ), |
|
711 | + ] |
|
712 | + ); |
|
713 | + } |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * registrations_requiring_pre_approval |
|
718 | + * |
|
719 | + * @param array $registrations_requiring_pre_approval |
|
720 | + * @return EE_Form_Section_Proper |
|
721 | + * @throws EE_Error |
|
722 | + * @throws EntityNotFoundException |
|
723 | + * @throws ReflectionException |
|
724 | + */ |
|
725 | + private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = []) |
|
726 | + { |
|
727 | + $events_requiring_pre_approval = []; |
|
728 | + foreach ($registrations_requiring_pre_approval as $registration) { |
|
729 | + if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
730 | + $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
731 | + EEH_HTML::span( |
|
732 | + '', |
|
733 | + '', |
|
734 | + 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
735 | + ) |
|
736 | + . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
737 | + ); |
|
738 | + } |
|
739 | + } |
|
740 | + return new EE_Form_Section_Proper( |
|
741 | + [ |
|
742 | + 'layout_strategy' => new EE_Template_Layout( |
|
743 | + [ |
|
744 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
745 | + . $this->_slug |
|
746 | + . '/events_requiring_pre_approval.template.php', // layout_template |
|
747 | + 'template_args' => apply_filters( |
|
748 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
749 | + [ |
|
750 | + 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
751 | + 'events_requiring_pre_approval_msg' => apply_filters( |
|
752 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
753 | + esc_html__( |
|
754 | + '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.', |
|
755 | + 'event_espresso' |
|
756 | + ) |
|
757 | + ), |
|
758 | + ] |
|
759 | + ), |
|
760 | + ] |
|
761 | + ), |
|
762 | + ] |
|
763 | + ); |
|
764 | + } |
|
765 | + |
|
766 | + |
|
767 | + /** |
|
768 | + * _no_payment_required |
|
769 | + * |
|
770 | + * @param EE_Event[] $registrations_for_free_events |
|
771 | + * @return EE_Form_Section_Proper |
|
772 | + * @throws EE_Error |
|
773 | + */ |
|
774 | + private function _no_payment_required($registrations_for_free_events = []) |
|
775 | + { |
|
776 | + // set some defaults |
|
777 | + $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
778 | + // generate no_payment_required form |
|
779 | + return new EE_Form_Section_Proper( |
|
780 | + [ |
|
781 | + 'layout_strategy' => new EE_Template_Layout( |
|
782 | + [ |
|
783 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
784 | + . $this->_slug |
|
785 | + . '/no_payment_required.template.php', // layout_template |
|
786 | + 'template_args' => apply_filters( |
|
787 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
788 | + [ |
|
789 | + 'revisit' => $this->checkout->revisit, |
|
790 | + 'registrations' => [], |
|
791 | + 'ticket_count' => [], |
|
792 | + 'registrations_for_free_events' => $registrations_for_free_events, |
|
793 | + 'no_payment_required_msg' => EEH_HTML::p( |
|
794 | + esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
795 | + ), |
|
796 | + ] |
|
797 | + ), |
|
798 | + ] |
|
799 | + ), |
|
800 | + ] |
|
801 | + ); |
|
802 | + } |
|
803 | + |
|
804 | + |
|
805 | + /** |
|
806 | + * _display_payment_options |
|
807 | + * |
|
808 | + * @param string $transaction_details |
|
809 | + * @return EE_Form_Section_Proper |
|
810 | + * @throws EE_Error |
|
811 | + * @throws InvalidArgumentException |
|
812 | + * @throws InvalidDataTypeException |
|
813 | + * @throws InvalidInterfaceException |
|
814 | + */ |
|
815 | + private function _display_payment_options($transaction_details = '') |
|
816 | + { |
|
817 | + // has method_of_payment been set by no-js user? |
|
818 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
819 | + // build payment options form |
|
820 | + return apply_filters( |
|
821 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
822 | + new EE_Form_Section_Proper( |
|
823 | + [ |
|
824 | + 'subsections' => [ |
|
825 | + 'before_payment_options' => apply_filters( |
|
826 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
827 | + new EE_Form_Section_Proper( |
|
828 | + ['layout_strategy' => new EE_Div_Per_Section_Layout()] |
|
829 | + ) |
|
830 | + ), |
|
831 | + 'payment_options' => $this->_setup_payment_options(), |
|
832 | + 'after_payment_options' => apply_filters( |
|
833 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
834 | + new EE_Form_Section_Proper( |
|
835 | + ['layout_strategy' => new EE_Div_Per_Section_Layout()] |
|
836 | + ) |
|
837 | + ), |
|
838 | + ], |
|
839 | + 'layout_strategy' => new EE_Template_Layout( |
|
840 | + [ |
|
841 | + 'layout_template_file' => $this->_template, |
|
842 | + 'template_args' => apply_filters( |
|
843 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
844 | + [ |
|
845 | + 'reg_count' => $this->line_item_display->total_items(), |
|
846 | + 'transaction_details' => $transaction_details, |
|
847 | + 'available_payment_methods' => [], |
|
848 | + ] |
|
849 | + ), |
|
850 | + ] |
|
851 | + ), |
|
852 | + ] |
|
853 | + ) |
|
854 | + ); |
|
855 | + } |
|
856 | + |
|
857 | + |
|
858 | + /** |
|
859 | + * _extra_hidden_inputs |
|
860 | + * |
|
861 | + * @param bool $no_payment_required |
|
862 | + * @return EE_Form_Section_Proper |
|
863 | + * @throws EE_Error |
|
864 | + * @throws ReflectionException |
|
865 | + */ |
|
866 | + private function _extra_hidden_inputs($no_payment_required = true) |
|
867 | + { |
|
868 | + return new EE_Form_Section_Proper( |
|
869 | + [ |
|
870 | + 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
871 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
872 | + 'subsections' => [ |
|
873 | + 'spco_no_payment_required' => new EE_Hidden_Input( |
|
874 | + [ |
|
875 | + 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
876 | + 'html_name' => 'spco_no_payment_required', |
|
877 | + 'html_id' => 'spco-no-payment-required-payment_options', |
|
878 | + 'default' => $no_payment_required, |
|
879 | + ] |
|
880 | + ), |
|
881 | + 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
882 | + [ |
|
883 | + 'normalization_strategy' => new EE_Int_Normalization(), |
|
884 | + 'html_name' => 'spco_transaction_id', |
|
885 | + 'html_id' => 'spco-transaction-id', |
|
886 | + 'default' => $this->checkout->transaction->ID(), |
|
887 | + ] |
|
888 | + ), |
|
889 | + ], |
|
890 | + ] |
|
891 | + ); |
|
892 | + } |
|
893 | + |
|
894 | + |
|
895 | + /** |
|
896 | + * _apply_registration_payments_to_amount_owing |
|
897 | + * |
|
898 | + * @param array $registrations |
|
899 | + * @throws EE_Error |
|
900 | + */ |
|
901 | + protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
902 | + { |
|
903 | + $payments = []; |
|
904 | + foreach ($registrations as $registration) { |
|
905 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
906 | + $payments += $registration->registration_payments(); |
|
907 | + } |
|
908 | + } |
|
909 | + if (! empty($payments)) { |
|
910 | + foreach ($payments as $payment) { |
|
911 | + if ($payment instanceof EE_Registration_Payment) { |
|
912 | + $this->checkout->amount_owing -= $payment->amount(); |
|
913 | + } |
|
914 | + } |
|
915 | + } |
|
916 | + } |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * _reset_selected_method_of_payment |
|
921 | + * |
|
922 | + * @access private |
|
923 | + * @param bool $force_reset |
|
924 | + * @return void |
|
925 | + * @throws InvalidArgumentException |
|
926 | + * @throws InvalidDataTypeException |
|
927 | + * @throws InvalidInterfaceException |
|
928 | + */ |
|
929 | + private function _reset_selected_method_of_payment($force_reset = false) |
|
930 | + { |
|
931 | + /** @var RequestInterface $request */ |
|
932 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
933 | + $reset_payment_method = $request->getRequestParam('reset_payment_method', $force_reset, 'bool'); |
|
934 | + if ($reset_payment_method) { |
|
935 | + $this->checkout->selected_method_of_payment = null; |
|
936 | + $this->checkout->payment_method = null; |
|
937 | + $this->checkout->billing_form = null; |
|
938 | + $this->_save_selected_method_of_payment(); |
|
939 | + } |
|
940 | + } |
|
941 | + |
|
942 | + |
|
943 | + /** |
|
944 | + * _save_selected_method_of_payment |
|
945 | + * stores the selected_method_of_payment in the session |
|
946 | + * so that it's available for all subsequent requests including AJAX |
|
947 | + * |
|
948 | + * @access private |
|
949 | + * @param string $selected_method_of_payment |
|
950 | + * @return void |
|
951 | + * @throws InvalidArgumentException |
|
952 | + * @throws InvalidDataTypeException |
|
953 | + * @throws InvalidInterfaceException |
|
954 | + */ |
|
955 | + private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
956 | + { |
|
957 | + $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
958 | + ? $selected_method_of_payment |
|
959 | + : $this->checkout->selected_method_of_payment; |
|
960 | + EE_Registry::instance()->SSN->set_session_data( |
|
961 | + ['selected_method_of_payment' => $selected_method_of_payment] |
|
962 | + ); |
|
963 | + } |
|
964 | + |
|
965 | + |
|
966 | + /** |
|
967 | + * _setup_payment_options |
|
968 | + * |
|
969 | + * @return EE_Form_Section_Proper |
|
970 | + * @throws EE_Error |
|
971 | + * @throws InvalidArgumentException |
|
972 | + * @throws InvalidDataTypeException |
|
973 | + * @throws InvalidInterfaceException |
|
974 | + */ |
|
975 | + public function _setup_payment_options() |
|
976 | + { |
|
977 | + // load payment method classes |
|
978 | + $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
979 | + if (empty($this->checkout->available_payment_methods)) { |
|
980 | + EE_Error::add_error( |
|
981 | + apply_filters( |
|
982 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
983 | + sprintf( |
|
984 | + esc_html__( |
|
985 | + '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.', |
|
986 | + 'event_espresso' |
|
987 | + ), |
|
988 | + '<br>', |
|
989 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
990 | + ) |
|
991 | + ), |
|
992 | + __FILE__, |
|
993 | + __FUNCTION__, |
|
994 | + __LINE__ |
|
995 | + ); |
|
996 | + } |
|
997 | + // switch up header depending on number of available payment methods |
|
998 | + $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
999 | + ? apply_filters( |
|
1000 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
1001 | + esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
1002 | + ) |
|
1003 | + : apply_filters( |
|
1004 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
1005 | + esc_html__('Method of Payment', 'event_espresso') |
|
1006 | + ); |
|
1007 | + $available_payment_methods = [ |
|
1008 | + // display the "Payment Method" header |
|
1009 | + 'payment_method_header' => new EE_Form_Section_HTML( |
|
1010 | + apply_filters( |
|
1011 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header', |
|
1012 | + EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'), |
|
1013 | + $payment_method_header |
|
1014 | + ) |
|
1015 | + ), |
|
1016 | + ]; |
|
1017 | + // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
1018 | + $available_payment_method_options = []; |
|
1019 | + $default_payment_method_option = []; |
|
1020 | + // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
1021 | + $payment_methods_billing_info = [ |
|
1022 | + new EE_Form_Section_HTML( |
|
1023 | + EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
1024 | + ), |
|
1025 | + ]; |
|
1026 | + // loop through payment methods |
|
1027 | + foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
1028 | + if ($payment_method instanceof EE_Payment_Method) { |
|
1029 | + $payment_method_button = EEH_HTML::img( |
|
1030 | + $payment_method->button_url(), |
|
1031 | + $payment_method->name(), |
|
1032 | + 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
1033 | + 'spco-payment-method-btn-img' |
|
1034 | + ); |
|
1035 | + // check if any payment methods are set as default |
|
1036 | + // if payment method is already selected OR nothing is selected and this payment method should be |
|
1037 | + // open_by_default |
|
1038 | + if ( |
|
1039 | + ($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
1040 | + || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1041 | + ) { |
|
1042 | + $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
1043 | + $this->_save_selected_method_of_payment(); |
|
1044 | + $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
1045 | + } else { |
|
1046 | + $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
1047 | + } |
|
1048 | + $payment_methods_billing_info[ $payment_method->slug() . '-info' ] = |
|
1049 | + $this->_payment_method_billing_info( |
|
1050 | + $payment_method |
|
1051 | + ); |
|
1052 | + } |
|
1053 | + } |
|
1054 | + // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
1055 | + // of PMs |
|
1056 | + $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
1057 | + // now generate the actual form inputs |
|
1058 | + $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
1059 | + $available_payment_method_options |
|
1060 | + ); |
|
1061 | + $available_payment_methods += $payment_methods_billing_info; |
|
1062 | + // build the available payment methods form |
|
1063 | + return new EE_Form_Section_Proper( |
|
1064 | + [ |
|
1065 | + 'html_id' => 'spco-available-methods-of-payment-dv', |
|
1066 | + 'subsections' => $available_payment_methods, |
|
1067 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1068 | + ] |
|
1069 | + ); |
|
1070 | + } |
|
1071 | + |
|
1072 | + |
|
1073 | + /** |
|
1074 | + * _get_available_payment_methods |
|
1075 | + * |
|
1076 | + * @return EE_Payment_Method[] |
|
1077 | + * @throws EE_Error |
|
1078 | + * @throws InvalidArgumentException |
|
1079 | + * @throws InvalidDataTypeException |
|
1080 | + * @throws InvalidInterfaceException |
|
1081 | + */ |
|
1082 | + protected function _get_available_payment_methods() |
|
1083 | + { |
|
1084 | + if (! empty($this->checkout->available_payment_methods)) { |
|
1085 | + return $this->checkout->available_payment_methods; |
|
1086 | + } |
|
1087 | + $available_payment_methods = []; |
|
1088 | + $EEM_Payment_Method = EEM_Payment_Method::instance(); |
|
1089 | + // get all active payment methods |
|
1090 | + $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
1091 | + $this->checkout->transaction, |
|
1092 | + EEM_Payment_Method::scope_cart |
|
1093 | + ); |
|
1094 | + foreach ($payment_methods as $payment_method) { |
|
1095 | + if ($payment_method instanceof EE_Payment_Method) { |
|
1096 | + $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1097 | + } |
|
1098 | + } |
|
1099 | + return $available_payment_methods; |
|
1100 | + } |
|
1101 | + |
|
1102 | + |
|
1103 | + /** |
|
1104 | + * _available_payment_method_inputs |
|
1105 | + * |
|
1106 | + * @access private |
|
1107 | + * @param array $available_payment_method_options |
|
1108 | + * @return EE_Form_Section_Proper |
|
1109 | + * @throws EE_Error |
|
1110 | + * @throws EE_Error |
|
1111 | + */ |
|
1112 | + private function _available_payment_method_inputs($available_payment_method_options = []) |
|
1113 | + { |
|
1114 | + // generate inputs |
|
1115 | + return new EE_Form_Section_Proper( |
|
1116 | + [ |
|
1117 | + 'html_id' => 'ee-available-payment-method-inputs', |
|
1118 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1119 | + 'subsections' => [ |
|
1120 | + '' => new EE_Radio_Button_Input( |
|
1121 | + $available_payment_method_options, |
|
1122 | + [ |
|
1123 | + 'html_name' => 'selected_method_of_payment', |
|
1124 | + 'html_class' => 'spco-payment-method', |
|
1125 | + 'default' => $this->checkout->selected_method_of_payment, |
|
1126 | + 'label_size' => 11, |
|
1127 | + 'enforce_label_size' => true, |
|
1128 | + ] |
|
1129 | + ), |
|
1130 | + ], |
|
1131 | + ] |
|
1132 | + ); |
|
1133 | + } |
|
1134 | + |
|
1135 | + |
|
1136 | + /** |
|
1137 | + * _payment_method_billing_info |
|
1138 | + * |
|
1139 | + * @access private |
|
1140 | + * @param EE_Payment_Method $payment_method |
|
1141 | + * @return EE_Form_Section_Proper |
|
1142 | + * @throws EE_Error |
|
1143 | + * @throws InvalidArgumentException |
|
1144 | + * @throws InvalidDataTypeException |
|
1145 | + * @throws InvalidInterfaceException |
|
1146 | + */ |
|
1147 | + private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
1148 | + { |
|
1149 | + $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug(); |
|
1150 | + // generate the billing form for payment method |
|
1151 | + $billing_form = $currently_selected |
|
1152 | + ? $this->_get_billing_form_for_payment_method($payment_method) |
|
1153 | + : new EE_Form_Section_HTML(); |
|
1154 | + $this->checkout->billing_form = $currently_selected |
|
1155 | + ? $billing_form |
|
1156 | + : $this->checkout->billing_form; |
|
1157 | + // it's all in the details |
|
1158 | + $info_html = EEH_HTML::h3( |
|
1159 | + esc_html__('Important information regarding your payment', 'event_espresso'), |
|
1160 | + '', |
|
1161 | + 'spco-payment-method-hdr' |
|
1162 | + ); |
|
1163 | + // add some info regarding the step, either from what's saved in the admin, |
|
1164 | + // or a default string depending on whether the PM has a billing form or not |
|
1165 | + if ($payment_method->description()) { |
|
1166 | + $payment_method_info = $payment_method->description(); |
|
1167 | + } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
1168 | + $payment_method_info = sprintf( |
|
1169 | + esc_html__( |
|
1170 | + 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
1171 | + 'event_espresso' |
|
1172 | + ), |
|
1173 | + $this->submit_button_text() |
|
1174 | + ); |
|
1175 | + } else { |
|
1176 | + $payment_method_info = sprintf( |
|
1177 | + esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
1178 | + $this->submit_button_text() |
|
1179 | + ); |
|
1180 | + } |
|
1181 | + $info_html .= EEH_HTML::div( |
|
1182 | + apply_filters( |
|
1183 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
1184 | + $payment_method_info |
|
1185 | + ), |
|
1186 | + '', |
|
1187 | + 'spco-payment-method-desc ee-attention' |
|
1188 | + ); |
|
1189 | + return new EE_Form_Section_Proper( |
|
1190 | + [ |
|
1191 | + 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1192 | + 'html_class' => 'spco-payment-method-info-dv', |
|
1193 | + // only display the selected or default PM |
|
1194 | + 'html_style' => $currently_selected ? '' : 'display:none;', |
|
1195 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1196 | + 'subsections' => [ |
|
1197 | + 'info' => new EE_Form_Section_HTML($info_html), |
|
1198 | + 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
1199 | + ], |
|
1200 | + ] |
|
1201 | + ); |
|
1202 | + } |
|
1203 | + |
|
1204 | + |
|
1205 | + /** |
|
1206 | + * get_billing_form_html_for_payment_method |
|
1207 | + * |
|
1208 | + * @return bool |
|
1209 | + * @throws EE_Error |
|
1210 | + * @throws InvalidArgumentException |
|
1211 | + * @throws ReflectionException |
|
1212 | + * @throws InvalidDataTypeException |
|
1213 | + * @throws InvalidInterfaceException |
|
1214 | + */ |
|
1215 | + public function get_billing_form_html_for_payment_method() |
|
1216 | + { |
|
1217 | + // how have they chosen to pay? |
|
1218 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1219 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1220 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1221 | + return false; |
|
1222 | + } |
|
1223 | + if ( |
|
1224 | + apply_filters( |
|
1225 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1226 | + false |
|
1227 | + ) |
|
1228 | + ) { |
|
1229 | + EE_Error::add_success( |
|
1230 | + apply_filters( |
|
1231 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1232 | + sprintf( |
|
1233 | + esc_html__( |
|
1234 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1235 | + 'event_espresso' |
|
1236 | + ), |
|
1237 | + $this->checkout->payment_method->name() |
|
1238 | + ) |
|
1239 | + ) |
|
1240 | + ); |
|
1241 | + } |
|
1242 | + // now generate billing form for selected method of payment |
|
1243 | + $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
1244 | + // fill form with attendee info if applicable |
|
1245 | + if ( |
|
1246 | + $payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1247 | + && $this->checkout->transaction_has_primary_registrant() |
|
1248 | + ) { |
|
1249 | + $payment_method_billing_form->populate_from_attendee( |
|
1250 | + $this->checkout->transaction->primary_registration()->attendee() |
|
1251 | + ); |
|
1252 | + } |
|
1253 | + // and debug content |
|
1254 | + if ( |
|
1255 | + $payment_method_billing_form instanceof EE_Billing_Info_Form |
|
1256 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1257 | + ) { |
|
1258 | + $payment_method_billing_form = |
|
1259 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1260 | + $payment_method_billing_form |
|
1261 | + ); |
|
1262 | + } |
|
1263 | + $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
1264 | + ? $payment_method_billing_form->get_html() |
|
1265 | + : ''; |
|
1266 | + $this->checkout->json_response->set_return_data(['payment_method_info' => $billing_info]); |
|
1267 | + // localize validation rules for main form |
|
1268 | + $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
1269 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1270 | + return true; |
|
1271 | + } |
|
1272 | + |
|
1273 | + |
|
1274 | + /** |
|
1275 | + * _get_billing_form_for_payment_method |
|
1276 | + * |
|
1277 | + * @param EE_Payment_Method $payment_method |
|
1278 | + * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
1279 | + * @throws EE_Error |
|
1280 | + * @throws InvalidArgumentException |
|
1281 | + * @throws InvalidDataTypeException |
|
1282 | + * @throws InvalidInterfaceException |
|
1283 | + */ |
|
1284 | + private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
1285 | + { |
|
1286 | + $billing_form = $payment_method->type_obj()->billing_form( |
|
1287 | + $this->checkout->transaction, |
|
1288 | + ['amount_owing' => $this->checkout->amount_owing] |
|
1289 | + ); |
|
1290 | + if ($billing_form instanceof EE_Billing_Info_Form) { |
|
1291 | + if ( |
|
1292 | + apply_filters( |
|
1293 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1294 | + false |
|
1295 | + ) |
|
1296 | + && $this->request->requestParamIsSet('payment_method') |
|
1297 | + ) { |
|
1298 | + EE_Error::add_success( |
|
1299 | + apply_filters( |
|
1300 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1301 | + sprintf( |
|
1302 | + esc_html__( |
|
1303 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1304 | + 'event_espresso' |
|
1305 | + ), |
|
1306 | + $payment_method->name() |
|
1307 | + ) |
|
1308 | + ) |
|
1309 | + ); |
|
1310 | + } |
|
1311 | + return apply_filters( |
|
1312 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
1313 | + $billing_form, |
|
1314 | + $payment_method |
|
1315 | + ); |
|
1316 | + } |
|
1317 | + // no actual billing form, so return empty HTML form section |
|
1318 | + return new EE_Form_Section_HTML(); |
|
1319 | + } |
|
1320 | + |
|
1321 | + |
|
1322 | + /** |
|
1323 | + * _get_selected_method_of_payment |
|
1324 | + * |
|
1325 | + * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
1326 | + * is not found in the incoming request |
|
1327 | + * @param string $request_param |
|
1328 | + * @return NULL|string |
|
1329 | + * @throws EE_Error |
|
1330 | + * @throws InvalidArgumentException |
|
1331 | + * @throws InvalidDataTypeException |
|
1332 | + * @throws InvalidInterfaceException |
|
1333 | + */ |
|
1334 | + private function _get_selected_method_of_payment( |
|
1335 | + $required = false, |
|
1336 | + $request_param = 'selected_method_of_payment' |
|
1337 | + ) { |
|
1338 | + // is selected_method_of_payment set in the request ? |
|
1339 | + $selected_method_of_payment = $this->request->getRequestParam($request_param); |
|
1340 | + if ($selected_method_of_payment) { |
|
1341 | + // sanitize it |
|
1342 | + $selected_method_of_payment = is_array($selected_method_of_payment) |
|
1343 | + ? array_shift($selected_method_of_payment) |
|
1344 | + : $selected_method_of_payment; |
|
1345 | + $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
1346 | + // store it in the session so that it's available for all subsequent requests including AJAX |
|
1347 | + $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
1348 | + } else { |
|
1349 | + // or is is set in the session ? |
|
1350 | + $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
1351 | + 'selected_method_of_payment' |
|
1352 | + ); |
|
1353 | + } |
|
1354 | + // do ya really really gotta have it? |
|
1355 | + if (empty($selected_method_of_payment) && $required) { |
|
1356 | + EE_Error::add_error( |
|
1357 | + sprintf( |
|
1358 | + esc_html__( |
|
1359 | + '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.', |
|
1360 | + 'event_espresso' |
|
1361 | + ), |
|
1362 | + '<br/>', |
|
1363 | + '<br/>', |
|
1364 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1365 | + ), |
|
1366 | + __FILE__, |
|
1367 | + __FUNCTION__, |
|
1368 | + __LINE__ |
|
1369 | + ); |
|
1370 | + return null; |
|
1371 | + } |
|
1372 | + return $selected_method_of_payment; |
|
1373 | + } |
|
1374 | + |
|
1375 | + |
|
1376 | + |
|
1377 | + |
|
1378 | + |
|
1379 | + |
|
1380 | + /********************************************************************************************************/ |
|
1381 | + /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
1382 | + /********************************************************************************************************/ |
|
1383 | + /** |
|
1384 | + * switch_payment_method |
|
1385 | + * |
|
1386 | + * @return bool |
|
1387 | + * @throws EE_Error |
|
1388 | + * @throws InvalidArgumentException |
|
1389 | + * @throws InvalidDataTypeException |
|
1390 | + * @throws InvalidInterfaceException |
|
1391 | + * @throws ReflectionException |
|
1392 | + */ |
|
1393 | + public function switch_payment_method() |
|
1394 | + { |
|
1395 | + if (! $this->_verify_payment_method_is_set()) { |
|
1396 | + return false; |
|
1397 | + } |
|
1398 | + if ( |
|
1399 | + apply_filters( |
|
1400 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1401 | + false |
|
1402 | + ) |
|
1403 | + ) { |
|
1404 | + EE_Error::add_success( |
|
1405 | + apply_filters( |
|
1406 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1407 | + sprintf( |
|
1408 | + esc_html__( |
|
1409 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1410 | + 'event_espresso' |
|
1411 | + ), |
|
1412 | + $this->checkout->payment_method->name() |
|
1413 | + ) |
|
1414 | + ) |
|
1415 | + ); |
|
1416 | + } |
|
1417 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1418 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1419 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1420 | + $this->checkout->payment_method |
|
1421 | + ); |
|
1422 | + } |
|
1423 | + // fill form with attendee info if applicable |
|
1424 | + if ( |
|
1425 | + apply_filters( |
|
1426 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
1427 | + ( |
|
1428 | + $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1429 | + && $this->checkout->transaction_has_primary_registrant() |
|
1430 | + ), |
|
1431 | + $this->checkout->billing_form, |
|
1432 | + $this->checkout->transaction |
|
1433 | + ) |
|
1434 | + ) { |
|
1435 | + $this->checkout->billing_form->populate_from_attendee( |
|
1436 | + $this->checkout->transaction->primary_registration()->attendee() |
|
1437 | + ); |
|
1438 | + } |
|
1439 | + // and debug content |
|
1440 | + if ( |
|
1441 | + $this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1442 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1443 | + ) { |
|
1444 | + $this->checkout->billing_form = |
|
1445 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1446 | + $this->checkout->billing_form |
|
1447 | + ); |
|
1448 | + } |
|
1449 | + // get html and validation rules for form |
|
1450 | + if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
1451 | + $this->checkout->json_response->set_return_data( |
|
1452 | + ['payment_method_info' => $this->checkout->billing_form->get_html()] |
|
1453 | + ); |
|
1454 | + // localize validation rules for main form |
|
1455 | + $this->checkout->billing_form->localize_validation_rules(true); |
|
1456 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1457 | + } else { |
|
1458 | + $this->checkout->json_response->set_return_data(['payment_method_info' => '']); |
|
1459 | + } |
|
1460 | + // prevents advancement to next step |
|
1461 | + $this->checkout->continue_reg = false; |
|
1462 | + return true; |
|
1463 | + } |
|
1464 | + |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * _verify_payment_method_is_set |
|
1468 | + * |
|
1469 | + * @return bool |
|
1470 | + * @throws EE_Error |
|
1471 | + * @throws InvalidArgumentException |
|
1472 | + * @throws ReflectionException |
|
1473 | + * @throws InvalidDataTypeException |
|
1474 | + * @throws InvalidInterfaceException |
|
1475 | + */ |
|
1476 | + protected function _verify_payment_method_is_set() |
|
1477 | + { |
|
1478 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1479 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
1480 | + // how have they chosen to pay? |
|
1481 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1482 | + } else { |
|
1483 | + // choose your own adventure based on method_of_payment |
|
1484 | + switch ($this->checkout->selected_method_of_payment) { |
|
1485 | + case 'events_sold_out': |
|
1486 | + EE_Error::add_attention( |
|
1487 | + apply_filters( |
|
1488 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
1489 | + esc_html__( |
|
1490 | + '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.', |
|
1491 | + 'event_espresso' |
|
1492 | + ) |
|
1493 | + ), |
|
1494 | + __FILE__, |
|
1495 | + __FUNCTION__, |
|
1496 | + __LINE__ |
|
1497 | + ); |
|
1498 | + return false; |
|
1499 | + case 'payments_closed': |
|
1500 | + EE_Error::add_attention( |
|
1501 | + apply_filters( |
|
1502 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
1503 | + esc_html__( |
|
1504 | + '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.', |
|
1505 | + 'event_espresso' |
|
1506 | + ) |
|
1507 | + ), |
|
1508 | + __FILE__, |
|
1509 | + __FUNCTION__, |
|
1510 | + __LINE__ |
|
1511 | + ); |
|
1512 | + return false; |
|
1513 | + case 'no_payment_required': |
|
1514 | + EE_Error::add_attention( |
|
1515 | + apply_filters( |
|
1516 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
1517 | + esc_html__( |
|
1518 | + '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.', |
|
1519 | + 'event_espresso' |
|
1520 | + ) |
|
1521 | + ), |
|
1522 | + __FILE__, |
|
1523 | + __FUNCTION__, |
|
1524 | + __LINE__ |
|
1525 | + ); |
|
1526 | + return false; |
|
1527 | + default: |
|
1528 | + } |
|
1529 | + } |
|
1530 | + // verify payment method |
|
1531 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1532 | + // get payment method for selected method of payment |
|
1533 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1534 | + } |
|
1535 | + return $this->checkout->payment_method instanceof EE_Payment_Method; |
|
1536 | + } |
|
1537 | + |
|
1538 | + |
|
1539 | + |
|
1540 | + /********************************************************************************************************/ |
|
1541 | + /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
1542 | + /********************************************************************************************************/ |
|
1543 | + /** |
|
1544 | + * save_payer_details_via_ajax |
|
1545 | + * |
|
1546 | + * @return void |
|
1547 | + * @throws EE_Error |
|
1548 | + * @throws InvalidArgumentException |
|
1549 | + * @throws ReflectionException |
|
1550 | + * @throws RuntimeException |
|
1551 | + * @throws InvalidDataTypeException |
|
1552 | + * @throws InvalidInterfaceException |
|
1553 | + */ |
|
1554 | + public function save_payer_details_via_ajax() |
|
1555 | + { |
|
1556 | + if (! $this->_verify_payment_method_is_set()) { |
|
1557 | + return; |
|
1558 | + } |
|
1559 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1560 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1561 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1562 | + $this->checkout->payment_method |
|
1563 | + ); |
|
1564 | + } |
|
1565 | + // generate primary attendee from payer info if applicable |
|
1566 | + if (! $this->checkout->transaction_has_primary_registrant()) { |
|
1567 | + $attendee = $this->_create_attendee_from_request_data(); |
|
1568 | + if ($attendee instanceof EE_Attendee) { |
|
1569 | + foreach ($this->checkout->transaction->registrations() as $registration) { |
|
1570 | + if ($registration->is_primary_registrant()) { |
|
1571 | + $this->checkout->primary_attendee_obj = $attendee; |
|
1572 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1573 | + $registration->set_attendee_id($attendee->ID()); |
|
1574 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1575 | + } |
|
1576 | + } |
|
1577 | + } |
|
1578 | + } |
|
1579 | + } |
|
1580 | + |
|
1581 | + |
|
1582 | + /** |
|
1583 | + * create_attendee_from_request_data |
|
1584 | + * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
1585 | + * |
|
1586 | + * @return EE_Attendee |
|
1587 | + * @throws EE_Error |
|
1588 | + * @throws InvalidArgumentException |
|
1589 | + * @throws ReflectionException |
|
1590 | + * @throws InvalidDataTypeException |
|
1591 | + * @throws InvalidInterfaceException |
|
1592 | + */ |
|
1593 | + protected function _create_attendee_from_request_data() |
|
1594 | + { |
|
1595 | + // get State ID |
|
1596 | + $STA_ID = $this->request->getRequestParam('state'); |
|
1597 | + if (! empty($STA_ID)) { |
|
1598 | + // can we get state object from name ? |
|
1599 | + EE_Registry::instance()->load_model('State'); |
|
1600 | + $state = EEM_State::instance()->get_col([['STA_name' => $STA_ID], 'limit' => 1], 'STA_ID'); |
|
1601 | + $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
1602 | + } |
|
1603 | + // get Country ISO |
|
1604 | + $CNT_ISO = $this->request->getRequestParam('country'); |
|
1605 | + if (! empty($CNT_ISO)) { |
|
1606 | + // can we get country object from name ? |
|
1607 | + EE_Registry::instance()->load_model('Country'); |
|
1608 | + $country = EEM_Country::instance()->get_col( |
|
1609 | + [['CNT_name' => $CNT_ISO], 'limit' => 1], |
|
1610 | + 'CNT_ISO' |
|
1611 | + ); |
|
1612 | + $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
1613 | + } |
|
1614 | + // grab attendee data |
|
1615 | + $attendee_data = [ |
|
1616 | + 'ATT_fname' => $this->request->getRequestParam('first_name'), |
|
1617 | + 'ATT_lname' => $this->request->getRequestParam('last_name'), |
|
1618 | + 'ATT_email' => $this->request->getRequestParam('email'), |
|
1619 | + 'ATT_address' => $this->request->getRequestParam('address'), |
|
1620 | + 'ATT_address2' => $this->request->getRequestParam('address2'), |
|
1621 | + 'ATT_city' => $this->request->getRequestParam('city'), |
|
1622 | + 'STA_ID' => $STA_ID, |
|
1623 | + 'CNT_ISO' => $CNT_ISO, |
|
1624 | + 'ATT_zip' => $this->request->getRequestParam('zip'), |
|
1625 | + 'ATT_phone' => $this->request->getRequestParam('phone'), |
|
1626 | + ]; |
|
1627 | + // validate the email address since it is the most important piece of info |
|
1628 | + if (empty($attendee_data['ATT_email'])) { |
|
1629 | + EE_Error::add_error( |
|
1630 | + esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
1631 | + __FILE__, |
|
1632 | + __FUNCTION__, |
|
1633 | + __LINE__ |
|
1634 | + ); |
|
1635 | + } |
|
1636 | + // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
1637 | + // AND email address |
|
1638 | + if ( |
|
1639 | + ! empty($attendee_data['ATT_fname']) |
|
1640 | + && ! empty($attendee_data['ATT_lname']) |
|
1641 | + && ! empty($attendee_data['ATT_email']) |
|
1642 | + ) { |
|
1643 | + $existing_attendee = EEM_Attendee::instance()->find_existing_attendee( |
|
1644 | + [ |
|
1645 | + 'ATT_fname' => $attendee_data['ATT_fname'], |
|
1646 | + 'ATT_lname' => $attendee_data['ATT_lname'], |
|
1647 | + 'ATT_email' => $attendee_data['ATT_email'], |
|
1648 | + ] |
|
1649 | + ); |
|
1650 | + if ($existing_attendee instanceof EE_Attendee) { |
|
1651 | + return $existing_attendee; |
|
1652 | + } |
|
1653 | + } |
|
1654 | + // no existing attendee? kk let's create a new one |
|
1655 | + // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
1656 | + // don't exist |
|
1657 | + $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
1658 | + ? $attendee_data['ATT_fname'] |
|
1659 | + : $attendee_data['ATT_email']; |
|
1660 | + $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
1661 | + ? $attendee_data['ATT_lname'] |
|
1662 | + : $attendee_data['ATT_email']; |
|
1663 | + return EE_Attendee::new_instance($attendee_data); |
|
1664 | + } |
|
1665 | + |
|
1666 | + |
|
1667 | + |
|
1668 | + /********************************************************************************************************/ |
|
1669 | + /**************************************** PROCESS REG STEP *****************************************/ |
|
1670 | + /********************************************************************************************************/ |
|
1671 | + /** |
|
1672 | + * process_reg_step |
|
1673 | + * |
|
1674 | + * @return bool |
|
1675 | + * @throws EE_Error |
|
1676 | + * @throws InvalidArgumentException |
|
1677 | + * @throws ReflectionException |
|
1678 | + * @throws EntityNotFoundException |
|
1679 | + * @throws InvalidDataTypeException |
|
1680 | + * @throws InvalidInterfaceException |
|
1681 | + * @throws InvalidStatusException |
|
1682 | + */ |
|
1683 | + public function process_reg_step() |
|
1684 | + { |
|
1685 | + // how have they chosen to pay? |
|
1686 | + $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
1687 | + ? 'no_payment_required' |
|
1688 | + : $this->_get_selected_method_of_payment(true); |
|
1689 | + // choose your own adventure based on method_of_payment |
|
1690 | + switch ($this->checkout->selected_method_of_payment) { |
|
1691 | + case 'events_sold_out': |
|
1692 | + $this->checkout->redirect = true; |
|
1693 | + $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
1694 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1695 | + // mark this reg step as completed |
|
1696 | + $this->set_completed(); |
|
1697 | + return false; |
|
1698 | + |
|
1699 | + case 'payments_closed': |
|
1700 | + if ( |
|
1701 | + apply_filters( |
|
1702 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
1703 | + false |
|
1704 | + ) |
|
1705 | + ) { |
|
1706 | + EE_Error::add_success( |
|
1707 | + esc_html__('no payment required at this time.', 'event_espresso'), |
|
1708 | + __FILE__, |
|
1709 | + __FUNCTION__, |
|
1710 | + __LINE__ |
|
1711 | + ); |
|
1712 | + } |
|
1713 | + // mark this reg step as completed |
|
1714 | + $this->set_completed(); |
|
1715 | + return true; |
|
1716 | + |
|
1717 | + case 'no_payment_required': |
|
1718 | + if ( |
|
1719 | + apply_filters( |
|
1720 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
1721 | + false |
|
1722 | + ) |
|
1723 | + ) { |
|
1724 | + EE_Error::add_success( |
|
1725 | + esc_html__('no payment required.', 'event_espresso'), |
|
1726 | + __FILE__, |
|
1727 | + __FUNCTION__, |
|
1728 | + __LINE__ |
|
1729 | + ); |
|
1730 | + } |
|
1731 | + // mark this reg step as completed |
|
1732 | + $this->set_completed(); |
|
1733 | + return true; |
|
1734 | + |
|
1735 | + default: |
|
1736 | + $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
1737 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
1738 | + ); |
|
1739 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
1740 | + $registrations, |
|
1741 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
1742 | + ); |
|
1743 | + // calculate difference between the two arrays |
|
1744 | + $registrations = array_diff($registrations, $ejected_registrations); |
|
1745 | + if (empty($registrations)) { |
|
1746 | + $this->_redirect_because_event_sold_out(); |
|
1747 | + return false; |
|
1748 | + } |
|
1749 | + $payment = $this->_process_payment(); |
|
1750 | + if ($payment instanceof EE_Payment) { |
|
1751 | + $this->checkout->continue_reg = true; |
|
1752 | + $this->_maybe_set_completed($payment); |
|
1753 | + } else { |
|
1754 | + $this->checkout->continue_reg = false; |
|
1755 | + } |
|
1756 | + return $payment instanceof EE_Payment; |
|
1757 | + } |
|
1758 | + } |
|
1759 | + |
|
1760 | + |
|
1761 | + /** |
|
1762 | + * _redirect_because_event_sold_out |
|
1763 | + * |
|
1764 | + * @return void |
|
1765 | + */ |
|
1766 | + protected function _redirect_because_event_sold_out() |
|
1767 | + { |
|
1768 | + $this->checkout->continue_reg = false; |
|
1769 | + // set redirect URL |
|
1770 | + $this->checkout->redirect_url = add_query_arg( |
|
1771 | + ['e_reg_url_link' => $this->checkout->reg_url_link], |
|
1772 | + $this->checkout->current_step->reg_step_url() |
|
1773 | + ); |
|
1774 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1775 | + } |
|
1776 | + |
|
1777 | + |
|
1778 | + /** |
|
1779 | + * _maybe_set_completed |
|
1780 | + * |
|
1781 | + * @param EE_Payment_Method $payment_method |
|
1782 | + * @return void |
|
1783 | + * @throws EE_Error |
|
1784 | + */ |
|
1785 | + protected function _maybe_set_completed(EE_Payment $payment) |
|
1786 | + { |
|
1787 | + // Do we need to redirect them? If so, there's more work to be done. |
|
1788 | + if (! $payment->redirect_url()){ |
|
1789 | + $this->set_completed(); |
|
1790 | + } |
|
1791 | + } |
|
1792 | + |
|
1793 | + |
|
1794 | + /** |
|
1795 | + * update_reg_step |
|
1796 | + * this is the final step after a user revisits the site to retry a payment |
|
1797 | + * |
|
1798 | + * @return bool |
|
1799 | + * @throws EE_Error |
|
1800 | + * @throws InvalidArgumentException |
|
1801 | + * @throws ReflectionException |
|
1802 | + * @throws EntityNotFoundException |
|
1803 | + * @throws InvalidDataTypeException |
|
1804 | + * @throws InvalidInterfaceException |
|
1805 | + * @throws InvalidStatusException |
|
1806 | + */ |
|
1807 | + public function update_reg_step() |
|
1808 | + { |
|
1809 | + $success = true; |
|
1810 | + // if payment required |
|
1811 | + if ($this->checkout->transaction->total() > 0) { |
|
1812 | + do_action( |
|
1813 | + 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
1814 | + $this->checkout->transaction |
|
1815 | + ); |
|
1816 | + // attempt payment via payment method |
|
1817 | + $success = $this->process_reg_step(); |
|
1818 | + } |
|
1819 | + if ($success && ! $this->checkout->redirect) { |
|
1820 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
1821 | + $this->checkout->transaction->ID() |
|
1822 | + ); |
|
1823 | + // set return URL |
|
1824 | + $this->checkout->redirect_url = add_query_arg( |
|
1825 | + ['e_reg_url_link' => $this->checkout->reg_url_link], |
|
1826 | + $this->checkout->thank_you_page_url |
|
1827 | + ); |
|
1828 | + } |
|
1829 | + return $success; |
|
1830 | + } |
|
1831 | + |
|
1832 | + |
|
1833 | + /** |
|
1834 | + * @return EE_Payment|null |
|
1835 | + * @throws EE_Error |
|
1836 | + * @throws InvalidArgumentException |
|
1837 | + * @throws ReflectionException |
|
1838 | + * @throws RuntimeException |
|
1839 | + * @throws InvalidDataTypeException |
|
1840 | + * @throws 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 null; |
|
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 null; |
|
1854 | + } |
|
1855 | + // get EE_Payment_Method object |
|
1856 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1857 | + return null; |
|
1858 | + } |
|
1859 | + // setup billing form |
|
1860 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
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 null; |
|
1867 | + } |
|
1868 | + } |
|
1869 | + // ensure primary registrant has been fully processed |
|
1870 | + if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1871 | + return null; |
|
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 $payment; |
|
1901 | + } |
|
1902 | + return null; |
|
1903 | + } |
|
1904 | + if ($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 $payment; |
|
1909 | + } |
|
1910 | + // where's my money? |
|
1911 | + return null; |
|
1912 | + } |
|
1913 | + |
|
1914 | + |
|
1915 | + /** |
|
1916 | + * _last_second_ticket_verifications |
|
1917 | + * |
|
1918 | + * @return bool |
|
1919 | + * @throws EE_Error |
|
1920 | + * @throws ReflectionException |
|
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 | + * @return bool |
|
1963 | + * @throws EE_Error |
|
1964 | + * @throws InvalidArgumentException |
|
1965 | + * @throws ReflectionException |
|
1966 | + * @throws InvalidDataTypeException |
|
1967 | + * @throws InvalidInterfaceException |
|
1968 | + */ |
|
1969 | + public function redirect_form() |
|
1970 | + { |
|
1971 | + $payment_method_billing_info = $this->_payment_method_billing_info( |
|
1972 | + $this->_get_payment_method_for_selected_method_of_payment() |
|
1973 | + ); |
|
1974 | + $html = $payment_method_billing_info->get_html(); |
|
1975 | + $html .= $this->checkout->redirect_form; |
|
1976 | + /** @var ResponseInterface $response */ |
|
1977 | + $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class); |
|
1978 | + $response->addOutput($html); |
|
1979 | + return true; |
|
1980 | + } |
|
1981 | + |
|
1982 | + |
|
1983 | + /** |
|
1984 | + * _billing_form_is_valid |
|
1985 | + * |
|
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 = []; |
|
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 | + * @return bool |
|
2062 | + * @throws EE_Error |
|
2063 | + * @throws InvalidArgumentException |
|
2064 | + * @throws ReflectionException |
|
2065 | + * @throws RuntimeException |
|
2066 | + * @throws InvalidDataTypeException |
|
2067 | + * @throws InvalidInterfaceException |
|
2068 | + */ |
|
2069 | + private function _setup_primary_registrant_prior_to_payment() |
|
2070 | + { |
|
2071 | + // check if transaction has a primary registrant and that it has a related Attendee object |
|
2072 | + // if not, then we need to at least gather some primary registrant data before attempting payment |
|
2073 | + if ( |
|
2074 | + $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 | + * @return bool |
|
2099 | + * @throws EE_Error |
|
2100 | + * @throws InvalidArgumentException |
|
2101 | + * @throws ReflectionException |
|
2102 | + * @throws InvalidDataTypeException |
|
2103 | + * @throws InvalidInterfaceException |
|
2104 | + */ |
|
2105 | + private function _capture_primary_registration_data_from_billing_form() |
|
2106 | + { |
|
2107 | + // convert billing form data into an attendee |
|
2108 | + $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
2109 | + if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2110 | + EE_Error::add_error( |
|
2111 | + sprintf( |
|
2112 | + esc_html__( |
|
2113 | + 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2114 | + 'event_espresso' |
|
2115 | + ), |
|
2116 | + '<br/>', |
|
2117 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2118 | + ), |
|
2119 | + __FILE__, |
|
2120 | + __FUNCTION__, |
|
2121 | + __LINE__ |
|
2122 | + ); |
|
2123 | + return false; |
|
2124 | + } |
|
2125 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2126 | + if (! $primary_registration instanceof EE_Registration) { |
|
2127 | + EE_Error::add_error( |
|
2128 | + sprintf( |
|
2129 | + esc_html__( |
|
2130 | + 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2131 | + 'event_espresso' |
|
2132 | + ), |
|
2133 | + '<br/>', |
|
2134 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2135 | + ), |
|
2136 | + __FILE__, |
|
2137 | + __FUNCTION__, |
|
2138 | + __LINE__ |
|
2139 | + ); |
|
2140 | + return false; |
|
2141 | + } |
|
2142 | + if ( |
|
2143 | + ! $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 | + * @return EE_Payment_Method |
|
2175 | + * @throws EE_Error |
|
2176 | + * @throws InvalidArgumentException |
|
2177 | + * @throws ReflectionException |
|
2178 | + * @throws InvalidDataTypeException |
|
2179 | + * @throws InvalidInterfaceException |
|
2180 | + */ |
|
2181 | + private function _get_payment_method_for_selected_method_of_payment() |
|
2182 | + { |
|
2183 | + if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
2184 | + $this->_redirect_because_event_sold_out(); |
|
2185 | + return null; |
|
2186 | + } |
|
2187 | + // get EE_Payment_Method object |
|
2188 | + if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
2189 | + $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2190 | + } else { |
|
2191 | + // load EEM_Payment_Method |
|
2192 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
2193 | + $EEM_Payment_Method = EEM_Payment_Method::instance(); |
|
2194 | + $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
2195 | + } |
|
2196 | + // verify $payment_method |
|
2197 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
2198 | + // not a payment |
|
2199 | + EE_Error::add_error( |
|
2200 | + sprintf( |
|
2201 | + esc_html__( |
|
2202 | + 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2203 | + 'event_espresso' |
|
2204 | + ), |
|
2205 | + '<br/>', |
|
2206 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2207 | + ), |
|
2208 | + __FILE__, |
|
2209 | + __FUNCTION__, |
|
2210 | + __LINE__ |
|
2211 | + ); |
|
2212 | + return null; |
|
2213 | + } |
|
2214 | + // and verify it has a valid Payment_Method Type object |
|
2215 | + if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2216 | + // not a payment |
|
2217 | + EE_Error::add_error( |
|
2218 | + sprintf( |
|
2219 | + esc_html__( |
|
2220 | + 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2221 | + 'event_espresso' |
|
2222 | + ), |
|
2223 | + '<br/>', |
|
2224 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2225 | + ), |
|
2226 | + __FILE__, |
|
2227 | + __FUNCTION__, |
|
2228 | + __LINE__ |
|
2229 | + ); |
|
2230 | + return null; |
|
2231 | + } |
|
2232 | + return $payment_method; |
|
2233 | + } |
|
2234 | + |
|
2235 | + |
|
2236 | + /** |
|
2237 | + * _attempt_payment |
|
2238 | + * |
|
2239 | + * @access private |
|
2240 | + * @type EE_Payment_Method $payment_method |
|
2241 | + * @return mixed EE_Payment | boolean |
|
2242 | + * @throws EE_Error |
|
2243 | + * @throws InvalidArgumentException |
|
2244 | + * @throws ReflectionException |
|
2245 | + * @throws InvalidDataTypeException |
|
2246 | + * @throws InvalidInterfaceException |
|
2247 | + */ |
|
2248 | + private function _attempt_payment(EE_Payment_Method $payment_method) |
|
2249 | + { |
|
2250 | + $payment = null; |
|
2251 | + $this->checkout->transaction->save(); |
|
2252 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2253 | + if (! $payment_processor instanceof EE_Payment_Processor) { |
|
2254 | + return false; |
|
2255 | + } |
|
2256 | + try { |
|
2257 | + $payment_processor->set_revisit($this->checkout->revisit); |
|
2258 | + // generate payment object |
|
2259 | + $payment = $payment_processor->process_payment( |
|
2260 | + $payment_method, |
|
2261 | + $this->checkout->transaction, |
|
2262 | + $this->checkout->amount_owing, |
|
2263 | + $this->checkout->billing_form, |
|
2264 | + $this->_get_return_url($payment_method), |
|
2265 | + 'CART', |
|
2266 | + $this->checkout->admin_request, |
|
2267 | + true, |
|
2268 | + $this->reg_step_url() |
|
2269 | + ); |
|
2270 | + } catch (Exception $e) { |
|
2271 | + $this->_handle_payment_processor_exception($e); |
|
2272 | + } |
|
2273 | + return $payment; |
|
2274 | + } |
|
2275 | + |
|
2276 | + |
|
2277 | + /** |
|
2278 | + * _handle_payment_processor_exception |
|
2279 | + * |
|
2280 | + * @param Exception $e |
|
2281 | + * @return void |
|
2282 | + * @throws EE_Error |
|
2283 | + * @throws InvalidArgumentException |
|
2284 | + * @throws InvalidDataTypeException |
|
2285 | + * @throws InvalidInterfaceException |
|
2286 | + */ |
|
2287 | + protected function _handle_payment_processor_exception(Exception $e) |
|
2288 | + { |
|
2289 | + EE_Error::add_error( |
|
2290 | + sprintf( |
|
2291 | + esc_html__( |
|
2292 | + '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', |
|
2293 | + 'event_espresso' |
|
2294 | + ), |
|
2295 | + '<br/>', |
|
2296 | + EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
2297 | + $e->getMessage(), |
|
2298 | + $e->getFile(), |
|
2299 | + $e->getLine() |
|
2300 | + ), |
|
2301 | + __FILE__, |
|
2302 | + __FUNCTION__, |
|
2303 | + __LINE__ |
|
2304 | + ); |
|
2305 | + } |
|
2306 | + |
|
2307 | + |
|
2308 | + /** |
|
2309 | + * _get_return_url |
|
2310 | + * |
|
2311 | + * @param EE_Payment_Method $payment_method |
|
2312 | + * @return string |
|
2313 | + * @throws EE_Error |
|
2314 | + * @throws ReflectionException |
|
2315 | + */ |
|
2316 | + protected function _get_return_url(EE_Payment_Method $payment_method) |
|
2317 | + { |
|
2318 | + $return_url = ''; |
|
2319 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
2320 | + case EE_PMT_Base::offsite: |
|
2321 | + $return_url = add_query_arg( |
|
2322 | + [ |
|
2323 | + 'action' => 'process_gateway_response', |
|
2324 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2325 | + 'spco_txn' => $this->checkout->transaction->ID(), |
|
2326 | + ], |
|
2327 | + $this->reg_step_url() |
|
2328 | + ); |
|
2329 | + break; |
|
2330 | + case EE_PMT_Base::onsite: |
|
2331 | + case EE_PMT_Base::offline: |
|
2332 | + $return_url = $this->checkout->next_step->reg_step_url(); |
|
2333 | + break; |
|
2334 | + } |
|
2335 | + return $return_url; |
|
2336 | + } |
|
2337 | + |
|
2338 | + |
|
2339 | + /** |
|
2340 | + * _validate_payment |
|
2341 | + * |
|
2342 | + * @param EE_Payment $payment |
|
2343 | + * @return EE_Payment|FALSE |
|
2344 | + * @throws EE_Error |
|
2345 | + * @throws InvalidArgumentException |
|
2346 | + * @throws InvalidDataTypeException |
|
2347 | + * @throws InvalidInterfaceException |
|
2348 | + */ |
|
2349 | + private function _validate_payment($payment = null) |
|
2350 | + { |
|
2351 | + if ($this->checkout->payment_method->is_off_line()) { |
|
2352 | + return true; |
|
2353 | + } |
|
2354 | + // verify payment object |
|
2355 | + if (! $payment instanceof EE_Payment) { |
|
2356 | + // not a payment |
|
2357 | + EE_Error::add_error( |
|
2358 | + sprintf( |
|
2359 | + esc_html__( |
|
2360 | + 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
2361 | + 'event_espresso' |
|
2362 | + ), |
|
2363 | + '<br/>', |
|
2364 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2365 | + ), |
|
2366 | + __FILE__, |
|
2367 | + __FUNCTION__, |
|
2368 | + __LINE__ |
|
2369 | + ); |
|
2370 | + return false; |
|
2371 | + } |
|
2372 | + return $payment; |
|
2373 | + } |
|
2374 | + |
|
2375 | + |
|
2376 | + /** |
|
2377 | + * _post_payment_processing |
|
2378 | + * |
|
2379 | + * @param EE_Payment|bool $payment |
|
2380 | + * @return bool |
|
2381 | + * @throws EE_Error |
|
2382 | + * @throws InvalidArgumentException |
|
2383 | + * @throws InvalidDataTypeException |
|
2384 | + * @throws InvalidInterfaceException |
|
2385 | + * @throws ReflectionException |
|
2386 | + */ |
|
2387 | + private function _post_payment_processing($payment = null) |
|
2388 | + { |
|
2389 | + // Off-Line payment? |
|
2390 | + if ($payment === true) { |
|
2391 | + return true; |
|
2392 | + } elseif ($payment instanceof EE_Payment){ |
|
2393 | + // Should the user be redirected? |
|
2394 | + if($payment->redirect_url()) { |
|
2395 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
2396 | + $this->checkout->redirect = true; |
|
2397 | + $this->checkout->redirect_form = $payment->redirect_form(); |
|
2398 | + $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
2399 | + // set JSON response |
|
2400 | + $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
2401 | + // and lastly, let's bump the payment status to pending |
|
2402 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
2403 | + $payment->save(); |
|
2404 | + } else |
|
2405 | + // User shouldn't be redirected. So let's process it here. |
|
2406 | + if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2407 | + // $this->_setup_redirect_for_next_step(); |
|
2408 | + $this->checkout->continue_reg = false; |
|
2409 | + } |
|
2410 | + } else { |
|
2411 | + // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
2412 | + $this->checkout->continue_reg = false; |
|
2413 | + return false; |
|
2414 | + } |
|
2415 | + return $payment; |
|
2416 | + } |
|
2417 | + |
|
2418 | + |
|
2419 | + /** |
|
2420 | + * _process_payment_status |
|
2421 | + * |
|
2422 | + * @type EE_Payment $payment |
|
2423 | + * @param string $payment_occurs |
|
2424 | + * @return bool |
|
2425 | + * @throws EE_Error |
|
2426 | + * @throws InvalidArgumentException |
|
2427 | + * @throws InvalidDataTypeException |
|
2428 | + * @throws InvalidInterfaceException |
|
2429 | + */ |
|
2430 | + private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
2431 | + { |
|
2432 | + // off-line payment? carry on |
|
2433 | + if ($payment_occurs === EE_PMT_Base::offline) { |
|
2434 | + return true; |
|
2435 | + } |
|
2436 | + // verify payment validity |
|
2437 | + if ($payment instanceof EE_Payment) { |
|
2438 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
2439 | + $msg = $payment->gateway_response(); |
|
2440 | + // check results |
|
2441 | + switch ($payment->status()) { |
|
2442 | + // good payment |
|
2443 | + case EEM_Payment::status_id_approved: |
|
2444 | + EE_Error::add_success( |
|
2445 | + esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
2446 | + __FILE__, |
|
2447 | + __FUNCTION__, |
|
2448 | + __LINE__ |
|
2449 | + ); |
|
2450 | + return true; |
|
2451 | + // slow payment |
|
2452 | + case EEM_Payment::status_id_pending: |
|
2453 | + if (empty($msg)) { |
|
2454 | + $msg = esc_html__( |
|
2455 | + 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
2456 | + 'event_espresso' |
|
2457 | + ); |
|
2458 | + } |
|
2459 | + EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2460 | + return true; |
|
2461 | + // don't wanna payment |
|
2462 | + case EEM_Payment::status_id_cancelled: |
|
2463 | + if (empty($msg)) { |
|
2464 | + $msg = _n( |
|
2465 | + 'Payment cancelled. Please try again.', |
|
2466 | + 'Payment cancelled. Please try again or select another method of payment.', |
|
2467 | + count($this->checkout->available_payment_methods), |
|
2468 | + 'event_espresso' |
|
2469 | + ); |
|
2470 | + } |
|
2471 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2472 | + return false; |
|
2473 | + // not enough payment |
|
2474 | + case EEM_Payment::status_id_declined: |
|
2475 | + if (empty($msg)) { |
|
2476 | + $msg = _n( |
|
2477 | + 'We\'re sorry but your payment was declined. Please try again.', |
|
2478 | + 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
2479 | + count($this->checkout->available_payment_methods), |
|
2480 | + 'event_espresso' |
|
2481 | + ); |
|
2482 | + } |
|
2483 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2484 | + return false; |
|
2485 | + // bad payment |
|
2486 | + case EEM_Payment::status_id_failed: |
|
2487 | + if (! empty($msg)) { |
|
2488 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2489 | + return false; |
|
2490 | + } |
|
2491 | + // default to error below |
|
2492 | + break; |
|
2493 | + } |
|
2494 | + } |
|
2495 | + // off-site payment gateway responses are too unreliable, so let's just assume that |
|
2496 | + // the payment processing is just running slower than the registrant's request |
|
2497 | + if ($payment_occurs === EE_PMT_Base::offsite) { |
|
2498 | + return true; |
|
2499 | + } |
|
2500 | + EE_Error::add_error( |
|
2501 | + sprintf( |
|
2502 | + esc_html__( |
|
2503 | + 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2504 | + 'event_espresso' |
|
2505 | + ), |
|
2506 | + '<br/>', |
|
2507 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2508 | + ), |
|
2509 | + __FILE__, |
|
2510 | + __FUNCTION__, |
|
2511 | + __LINE__ |
|
2512 | + ); |
|
2513 | + return false; |
|
2514 | + } |
|
2515 | + |
|
2516 | + |
|
2517 | + |
|
2518 | + |
|
2519 | + |
|
2520 | + |
|
2521 | + /********************************************************************************************************/ |
|
2522 | + /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
2523 | + /********************************************************************************************************/ |
|
2524 | + /** |
|
2525 | + * process_gateway_response |
|
2526 | + * this is the return point for Off-Site Payment Methods |
|
2527 | + * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
2528 | + * otherwise, it will load up the last payment made for the TXN. |
|
2529 | + * If the payment retrieved looks good, it will then either: |
|
2530 | + * complete the current step and allow advancement to the next reg step |
|
2531 | + * or present the payment options again |
|
2532 | + * |
|
2533 | + * @return bool |
|
2534 | + * @throws EE_Error |
|
2535 | + * @throws InvalidArgumentException |
|
2536 | + * @throws ReflectionException |
|
2537 | + * @throws InvalidDataTypeException |
|
2538 | + * @throws InvalidInterfaceException |
|
2539 | + */ |
|
2540 | + public function process_gateway_response() |
|
2541 | + { |
|
2542 | + // how have they chosen to pay? |
|
2543 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
2544 | + // get EE_Payment_Method object |
|
2545 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2546 | + $this->checkout->continue_reg = false; |
|
2547 | + return false; |
|
2548 | + } |
|
2549 | + if (! $this->checkout->payment_method->is_off_site()) { |
|
2550 | + return false; |
|
2551 | + } |
|
2552 | + $this->_validate_offsite_return(); |
|
2553 | + // verify TXN |
|
2554 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
2555 | + $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
2556 | + if (! $gateway instanceof EE_Offsite_Gateway) { |
|
2557 | + $this->checkout->continue_reg = false; |
|
2558 | + return false; |
|
2559 | + } |
|
2560 | + $payment = $this->_process_off_site_payment($gateway); |
|
2561 | + $payment = $this->_process_cancelled_payments($payment); |
|
2562 | + $payment = $this->_validate_payment($payment); |
|
2563 | + // if payment was not declined by the payment gateway or cancelled by the registrant |
|
2564 | + if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
2565 | + // $this->_setup_redirect_for_next_step(); |
|
2566 | + // store that for later |
|
2567 | + $this->checkout->payment = $payment; |
|
2568 | + // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
2569 | + // because we will complete this step during the IPN processing then |
|
2570 | + if (! $this->handle_IPN_in_this_request()) { |
|
2571 | + $this->set_completed(); |
|
2572 | + } |
|
2573 | + return true; |
|
2574 | + } |
|
2575 | + } |
|
2576 | + // DEBUG LOG |
|
2577 | + // $this->checkout->log( |
|
2578 | + // __CLASS__, |
|
2579 | + // __FUNCTION__, |
|
2580 | + // __LINE__, |
|
2581 | + // array('payment' => $payment) |
|
2582 | + // ); |
|
2583 | + $this->checkout->continue_reg = false; |
|
2584 | + return false; |
|
2585 | + } |
|
2586 | + |
|
2587 | + |
|
2588 | + /** |
|
2589 | + * _validate_return |
|
2590 | + * |
|
2591 | + * @return void |
|
2592 | + * @throws EE_Error |
|
2593 | + * @throws InvalidArgumentException |
|
2594 | + * @throws InvalidDataTypeException |
|
2595 | + * @throws InvalidInterfaceException |
|
2596 | + * @throws ReflectionException |
|
2597 | + */ |
|
2598 | + private function _validate_offsite_return() |
|
2599 | + { |
|
2600 | + $TXN_ID = $this->request->getRequestParam('spco_txn', 0, 'int'); |
|
2601 | + if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
2602 | + // Houston... we might have a problem |
|
2603 | + $invalid_TXN = false; |
|
2604 | + // first gather some info |
|
2605 | + $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2606 | + $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
2607 | + ? $valid_TXN->primary_registration() |
|
2608 | + : null; |
|
2609 | + // let's start by retrieving the cart for this TXN |
|
2610 | + $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
2611 | + if ($cart instanceof EE_Cart) { |
|
2612 | + // verify that the current cart has tickets |
|
2613 | + $tickets = $cart->get_tickets(); |
|
2614 | + if (empty($tickets)) { |
|
2615 | + $invalid_TXN = true; |
|
2616 | + } |
|
2617 | + } else { |
|
2618 | + $invalid_TXN = true; |
|
2619 | + } |
|
2620 | + $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
2621 | + ? $primary_registrant->session_ID() |
|
2622 | + : null; |
|
2623 | + // validate current Session ID and compare against valid TXN session ID |
|
2624 | + if ( |
|
2625 | + $invalid_TXN // if this is already true, then skip other checks |
|
2626 | + || EE_Session::instance()->id() === null |
|
2627 | + || ( |
|
2628 | + // WARNING !!! |
|
2629 | + // this could be PayPal sending back duplicate requests (ya they do that) |
|
2630 | + // or it **could** mean someone is simply registering AGAIN after having just done so |
|
2631 | + // so now we need to determine if this current TXN looks valid or not |
|
2632 | + // and whether this reg step has even been started ? |
|
2633 | + EE_Session::instance()->id() === $valid_TXN_SID |
|
2634 | + // really? you're half way through this reg step, but you never started it ? |
|
2635 | + && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
2636 | + ) |
|
2637 | + ) { |
|
2638 | + $invalid_TXN = true; |
|
2639 | + } |
|
2640 | + if ($invalid_TXN) { |
|
2641 | + // is the valid TXN completed ? |
|
2642 | + if ($valid_TXN instanceof EE_Transaction) { |
|
2643 | + // has this step even been started ? |
|
2644 | + $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
2645 | + if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
2646 | + // so it **looks** like this is a double request from PayPal |
|
2647 | + // so let's try to pick up where we left off |
|
2648 | + $this->checkout->transaction = $valid_TXN; |
|
2649 | + $this->checkout->refresh_all_entities(true); |
|
2650 | + return; |
|
2651 | + } |
|
2652 | + } |
|
2653 | + // you appear to be lost? |
|
2654 | + $this->_redirect_wayward_request($primary_registrant); |
|
2655 | + } |
|
2656 | + } |
|
2657 | + } |
|
2658 | + |
|
2659 | + |
|
2660 | + /** |
|
2661 | + * _redirect_wayward_request |
|
2662 | + * |
|
2663 | + * @param EE_Registration|null $primary_registrant |
|
2664 | + * @return void |
|
2665 | + * @throws EE_Error |
|
2666 | + * @throws InvalidArgumentException |
|
2667 | + * @throws InvalidDataTypeException |
|
2668 | + * @throws InvalidInterfaceException |
|
2669 | + * @throws ReflectionException |
|
2670 | + */ |
|
2671 | + private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
2672 | + { |
|
2673 | + if (! $primary_registrant instanceof EE_Registration) { |
|
2674 | + // try redirecting based on the current TXN |
|
2675 | + $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
2676 | + ? $this->checkout->transaction->primary_registration() |
|
2677 | + : null; |
|
2678 | + } |
|
2679 | + if (! $primary_registrant instanceof EE_Registration) { |
|
2680 | + EE_Error::add_error( |
|
2681 | + sprintf( |
|
2682 | + esc_html__( |
|
2683 | + '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.', |
|
2684 | + 'event_espresso' |
|
2685 | + ), |
|
2686 | + '<br/>', |
|
2687 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2688 | + ), |
|
2689 | + __FILE__, |
|
2690 | + __FUNCTION__, |
|
2691 | + __LINE__ |
|
2692 | + ); |
|
2693 | + return; |
|
2694 | + } |
|
2695 | + // make sure transaction is not locked |
|
2696 | + $this->checkout->transaction->unlock(); |
|
2697 | + wp_safe_redirect( |
|
2698 | + add_query_arg( |
|
2699 | + [ |
|
2700 | + 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
2701 | + ], |
|
2702 | + $this->checkout->thank_you_page_url |
|
2703 | + ) |
|
2704 | + ); |
|
2705 | + exit(); |
|
2706 | + } |
|
2707 | + |
|
2708 | + |
|
2709 | + /** |
|
2710 | + * _process_off_site_payment |
|
2711 | + * |
|
2712 | + * @param EE_Offsite_Gateway $gateway |
|
2713 | + * @return EE_Payment |
|
2714 | + * @throws EE_Error |
|
2715 | + * @throws InvalidArgumentException |
|
2716 | + * @throws InvalidDataTypeException |
|
2717 | + * @throws InvalidInterfaceException |
|
2718 | + * @throws ReflectionException |
|
2719 | + */ |
|
2720 | + private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
2721 | + { |
|
2722 | + try { |
|
2723 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
2724 | + $request_data = $request->requestParams(); |
|
2725 | + // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
2726 | + $this->set_handle_IPN_in_this_request( |
|
2727 | + $gateway->handle_IPN_in_this_request($request_data, false) |
|
2728 | + ); |
|
2729 | + if ($this->handle_IPN_in_this_request()) { |
|
2730 | + // get payment details and process results |
|
2731 | + /** @type EE_Payment_Processor $payment_processor */ |
|
2732 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2733 | + $payment = $payment_processor->process_ipn( |
|
2734 | + $request_data, |
|
2735 | + $this->checkout->transaction, |
|
2736 | + $this->checkout->payment_method, |
|
2737 | + true, |
|
2738 | + false |
|
2739 | + ); |
|
2740 | + // $payment_source = 'process_ipn'; |
|
2741 | + } else { |
|
2742 | + $payment = $this->checkout->transaction->last_payment(); |
|
2743 | + // $payment_source = 'last_payment'; |
|
2744 | + } |
|
2745 | + } catch (Exception $e) { |
|
2746 | + // let's just eat the exception and try to move on using any previously set payment info |
|
2747 | + $payment = $this->checkout->transaction->last_payment(); |
|
2748 | + // $payment_source = 'last_payment after Exception'; |
|
2749 | + // but if we STILL don't have a payment object |
|
2750 | + if (! $payment instanceof EE_Payment) { |
|
2751 | + // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
2752 | + $this->_handle_payment_processor_exception($e); |
|
2753 | + } |
|
2754 | + } |
|
2755 | + return $payment; |
|
2756 | + } |
|
2757 | + |
|
2758 | + |
|
2759 | + /** |
|
2760 | + * _process_cancelled_payments |
|
2761 | + * just makes sure that the payment status gets updated correctly |
|
2762 | + * so tha tan error isn't generated during payment validation |
|
2763 | + * |
|
2764 | + * @param EE_Payment $payment |
|
2765 | + * @return EE_Payment|null |
|
2766 | + * @throws EE_Error |
|
2767 | + */ |
|
2768 | + private function _process_cancelled_payments($payment = null) |
|
2769 | + { |
|
2770 | + if ( |
|
2771 | + $payment instanceof EE_Payment |
|
2772 | + && $this->request->requestParamIsSet('ee_cancel_payment') |
|
2773 | + && $payment->status() === EEM_Payment::status_id_failed |
|
2774 | + ) { |
|
2775 | + $payment->set_status(EEM_Payment::status_id_cancelled); |
|
2776 | + } |
|
2777 | + return $payment; |
|
2778 | + } |
|
2779 | + |
|
2780 | + |
|
2781 | + /** |
|
2782 | + * get_transaction_details_for_gateways |
|
2783 | + * |
|
2784 | + * @access public |
|
2785 | + * @return void |
|
2786 | + * @throws EE_Error |
|
2787 | + * @throws InvalidArgumentException |
|
2788 | + * @throws ReflectionException |
|
2789 | + * @throws InvalidDataTypeException |
|
2790 | + * @throws InvalidInterfaceException |
|
2791 | + */ |
|
2792 | + public function get_transaction_details_for_gateways() |
|
2793 | + { |
|
2794 | + $txn_details = []; |
|
2795 | + // ya gotta make a choice man |
|
2796 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
2797 | + $txn_details = [ |
|
2798 | + 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
2799 | + ]; |
|
2800 | + } |
|
2801 | + // get EE_Payment_Method object |
|
2802 | + if ( |
|
2803 | + empty($txn_details) |
|
2804 | + && ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
2805 | + ) { |
|
2806 | + $txn_details = [ |
|
2807 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2808 | + 'error' => esc_html__( |
|
2809 | + 'A valid Payment Method could not be determined.', |
|
2810 | + 'event_espresso' |
|
2811 | + ), |
|
2812 | + ]; |
|
2813 | + } |
|
2814 | + if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
2815 | + $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
2816 | + $txn_details = [ |
|
2817 | + 'TXN_ID' => $this->checkout->transaction->ID(), |
|
2818 | + 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
2819 | + 'TXN_total' => $this->checkout->transaction->total(), |
|
2820 | + 'TXN_paid' => $this->checkout->transaction->paid(), |
|
2821 | + 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
2822 | + 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
2823 | + 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
2824 | + 'payment_amount' => $this->checkout->amount_owing, |
|
2825 | + 'return_url' => $return_url, |
|
2826 | + 'cancel_url' => add_query_arg(['ee_cancel_payment' => true], $return_url), |
|
2827 | + 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
2828 | + [ |
|
2829 | + 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
2830 | + 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
2831 | + ] |
|
2832 | + ), |
|
2833 | + ]; |
|
2834 | + } |
|
2835 | + echo wp_json_encode($txn_details); |
|
2836 | + exit(); |
|
2837 | + } |
|
2838 | + |
|
2839 | + |
|
2840 | + /** |
|
2841 | + * __sleep |
|
2842 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
2843 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
2844 | + * reg form, because if needed, it will be regenerated anyways |
|
2845 | + * |
|
2846 | + * @return array |
|
2847 | + */ |
|
2848 | + public function __sleep() |
|
2849 | + { |
|
2850 | + // remove the reg form and the checkout |
|
2851 | + return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout', 'line_item_display']); |
|
2852 | + } |
|
2853 | 2853 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $this->request = EED_Single_Page_Checkout::getRequest(); |
134 | 134 | $this->_slug = 'payment_options'; |
135 | 135 | $this->_name = esc_html__('Payment Options', 'event_espresso'); |
136 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php'; |
|
136 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.'/payment_options_main.template.php'; |
|
137 | 137 | $this->checkout = $checkout; |
138 | 138 | $this->_reset_success_message(); |
139 | 139 | $this->set_instructions( |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function translate_js_strings() |
190 | 190 | { |
191 | - EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
191 | + EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
192 | 192 | 'Please select a method of payment in order to continue.', |
193 | 193 | 'event_espresso' |
194 | 194 | ); |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | 'A valid method of payment could not be determined. Please refresh the page and try again.', |
197 | 197 | 'event_espresso' |
198 | 198 | ); |
199 | - EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
199 | + EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
200 | 200 | 'Forwarding to Secure Payment Provider.', |
201 | 201 | 'event_espresso' |
202 | 202 | ); |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | { |
218 | 218 | $transaction = $this->checkout->transaction; |
219 | 219 | // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
220 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
220 | + if ( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
221 | 221 | return; |
222 | 222 | } |
223 | 223 | foreach ( |
@@ -312,18 +312,18 @@ discard block |
||
312 | 312 | foreach ($registrations as $REG_ID => $registration) { |
313 | 313 | /** @var $registration EE_Registration */ |
314 | 314 | // has this registration lost it's space ? |
315 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
315 | + if (isset($ejected_registrations[$REG_ID])) { |
|
316 | 316 | if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
317 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
317 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
318 | 318 | } else { |
319 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
319 | + $insufficient_spaces_available[$registration->event()->ID()] = $registration->event(); |
|
320 | 320 | } |
321 | 321 | continue; |
322 | 322 | } |
323 | 323 | // event requires admin approval |
324 | 324 | if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
325 | 325 | // add event to list of events with pre-approval reg status |
326 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
326 | + $registrations_requiring_pre_approval[$REG_ID] = $registration; |
|
327 | 327 | do_action( |
328 | 328 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
329 | 329 | $registration->event(), |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | ) |
341 | 341 | ) { |
342 | 342 | // add event to list of events that are sold out |
343 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
343 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
344 | 344 | do_action( |
345 | 345 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
346 | 346 | $registration->event(), |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | } |
351 | 351 | // are they allowed to pay now and is there monies owing? |
352 | 352 | if ($registration->owes_monies_and_can_pay()) { |
353 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
353 | + $registrations_requiring_payment[$REG_ID] = $registration; |
|
354 | 354 | do_action( |
355 | 355 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
356 | 356 | $registration->event(), |
@@ -361,28 +361,28 @@ discard block |
||
361 | 361 | && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
362 | 362 | && $registration->ticket()->is_free() |
363 | 363 | ) { |
364 | - $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
364 | + $registrations_for_free_events[$registration->ticket()->ID()] = $registration; |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | $subsections = []; |
368 | 368 | // now decide which template to load |
369 | - if (! empty($sold_out_events)) { |
|
369 | + if ( ! empty($sold_out_events)) { |
|
370 | 370 | $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
371 | 371 | } |
372 | - if (! empty($insufficient_spaces_available)) { |
|
372 | + if ( ! empty($insufficient_spaces_available)) { |
|
373 | 373 | $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
374 | 374 | $insufficient_spaces_available |
375 | 375 | ); |
376 | 376 | } |
377 | - if (! empty($registrations_requiring_pre_approval)) { |
|
377 | + if ( ! empty($registrations_requiring_pre_approval)) { |
|
378 | 378 | $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
379 | 379 | $registrations_requiring_pre_approval |
380 | 380 | ); |
381 | 381 | } |
382 | - if (! empty($registrations_for_free_events)) { |
|
382 | + if ( ! empty($registrations_for_free_events)) { |
|
383 | 383 | $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
384 | 384 | } |
385 | - if (! empty($registrations_requiring_payment)) { |
|
385 | + if ( ! empty($registrations_requiring_payment)) { |
|
386 | 386 | if ($this->checkout->amount_owing > 0) { |
387 | 387 | // autoload Line_Item_Display classes |
388 | 388 | EEH_Autoloader::register_line_item_filter_autoloaders(); |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | ['registrations' => $registrations] |
404 | 404 | ) |
405 | 405 | ); |
406 | - $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
406 | + $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
407 | 407 | $this->_apply_registration_payments_to_amount_owing($registrations); |
408 | 408 | } |
409 | 409 | $no_payment_required = false; |
@@ -447,13 +447,13 @@ discard block |
||
447 | 447 | */ |
448 | 448 | public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
449 | 449 | { |
450 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
450 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
451 | 451 | return $line_item_filter_collection; |
452 | 452 | } |
453 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
453 | + if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
454 | 454 | return $line_item_filter_collection; |
455 | 455 | } |
456 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
456 | + if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
457 | 457 | return $line_item_filter_collection; |
458 | 458 | } |
459 | 459 | $line_item_filter_collection->add( |
@@ -493,8 +493,8 @@ discard block |
||
493 | 493 | ); |
494 | 494 | foreach ($registrations as $REG_ID => $registration) { |
495 | 495 | // has this registration lost it's space ? |
496 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
497 | - unset($registrations[ $REG_ID ]); |
|
496 | + if (isset($ejected_registrations[$REG_ID])) { |
|
497 | + unset($registrations[$REG_ID]); |
|
498 | 498 | } |
499 | 499 | } |
500 | 500 | return $registrations; |
@@ -544,25 +544,25 @@ discard block |
||
544 | 544 | } |
545 | 545 | $EVT_ID = $registration->event_ID(); |
546 | 546 | $ticket = $registration->ticket(); |
547 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
548 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
547 | + if ( ! isset($tickets_remaining[$ticket->ID()])) { |
|
548 | + $tickets_remaining[$ticket->ID()] = $ticket->remaining(); |
|
549 | 549 | } |
550 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
551 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
552 | - $event_reg_count[ $EVT_ID ] = 0; |
|
550 | + if ($tickets_remaining[$ticket->ID()] > 0) { |
|
551 | + if ( ! isset($event_reg_count[$EVT_ID])) { |
|
552 | + $event_reg_count[$EVT_ID] = 0; |
|
553 | 553 | } |
554 | - $event_reg_count[ $EVT_ID ]++; |
|
555 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
556 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
554 | + $event_reg_count[$EVT_ID]++; |
|
555 | + if ( ! isset($event_spaces_remaining[$EVT_ID])) { |
|
556 | + $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale(); |
|
557 | 557 | } |
558 | 558 | } |
559 | 559 | if ( |
560 | 560 | $revisit |
561 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
562 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
561 | + && ($tickets_remaining[$ticket->ID()] === 0 |
|
562 | + || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID] |
|
563 | 563 | ) |
564 | 564 | ) { |
565 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
565 | + $ejected_registrations[$REG_ID] = $registration->event(); |
|
566 | 566 | if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
567 | 567 | /** @type EE_Registration_Processor $registration_processor */ |
568 | 568 | $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | foreach ($sold_out_events_array as $sold_out_event) { |
623 | 623 | $sold_out_events .= EEH_HTML::li( |
624 | 624 | EEH_HTML::span( |
625 | - ' ' . $sold_out_event->name(), |
|
625 | + ' '.$sold_out_event->name(), |
|
626 | 626 | '', |
627 | 627 | 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
628 | 628 | ) |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | foreach ($insufficient_spaces_events_array as $event) { |
679 | 679 | if ($event instanceof EE_Event) { |
680 | 680 | $insufficient_space_events .= EEH_HTML::li( |
681 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
681 | + EEH_HTML::span(' '.$event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
682 | 682 | ); |
683 | 683 | } |
684 | 684 | } |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | $events_requiring_pre_approval = []; |
728 | 728 | foreach ($registrations_requiring_pre_approval as $registration) { |
729 | 729 | if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
730 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
730 | + $events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li( |
|
731 | 731 | EEH_HTML::span( |
732 | 732 | '', |
733 | 733 | '', |
@@ -867,7 +867,7 @@ discard block |
||
867 | 867 | { |
868 | 868 | return new EE_Form_Section_Proper( |
869 | 869 | [ |
870 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
870 | + 'html_id' => 'ee-'.$this->slug().'-extra-hidden-inputs', |
|
871 | 871 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
872 | 872 | 'subsections' => [ |
873 | 873 | 'spco_no_payment_required' => new EE_Hidden_Input( |
@@ -906,7 +906,7 @@ discard block |
||
906 | 906 | $payments += $registration->registration_payments(); |
907 | 907 | } |
908 | 908 | } |
909 | - if (! empty($payments)) { |
|
909 | + if ( ! empty($payments)) { |
|
910 | 910 | foreach ($payments as $payment) { |
911 | 911 | if ($payment instanceof EE_Registration_Payment) { |
912 | 912 | $this->checkout->amount_owing -= $payment->amount(); |
@@ -995,7 +995,7 @@ discard block |
||
995 | 995 | ); |
996 | 996 | } |
997 | 997 | // switch up header depending on number of available payment methods |
998 | - $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
998 | + $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
999 | 999 | ? apply_filters( |
1000 | 1000 | 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
1001 | 1001 | esc_html__('Please Select Your Method of Payment', 'event_espresso') |
@@ -1029,7 +1029,7 @@ discard block |
||
1029 | 1029 | $payment_method_button = EEH_HTML::img( |
1030 | 1030 | $payment_method->button_url(), |
1031 | 1031 | $payment_method->name(), |
1032 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
1032 | + 'spco-payment-method-'.$payment_method->slug().'-btn-img', |
|
1033 | 1033 | 'spco-payment-method-btn-img' |
1034 | 1034 | ); |
1035 | 1035 | // check if any payment methods are set as default |
@@ -1037,15 +1037,15 @@ discard block |
||
1037 | 1037 | // open_by_default |
1038 | 1038 | if ( |
1039 | 1039 | ($this->checkout->selected_method_of_payment === $payment_method->slug()) |
1040 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1040 | + || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1041 | 1041 | ) { |
1042 | 1042 | $this->checkout->selected_method_of_payment = $payment_method->slug(); |
1043 | 1043 | $this->_save_selected_method_of_payment(); |
1044 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
1044 | + $default_payment_method_option[$payment_method->slug()] = $payment_method_button; |
|
1045 | 1045 | } else { |
1046 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
1046 | + $available_payment_method_options[$payment_method->slug()] = $payment_method_button; |
|
1047 | 1047 | } |
1048 | - $payment_methods_billing_info[ $payment_method->slug() . '-info' ] = |
|
1048 | + $payment_methods_billing_info[$payment_method->slug().'-info'] = |
|
1049 | 1049 | $this->_payment_method_billing_info( |
1050 | 1050 | $payment_method |
1051 | 1051 | ); |
@@ -1058,7 +1058,7 @@ discard block |
||
1058 | 1058 | $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
1059 | 1059 | $available_payment_method_options |
1060 | 1060 | ); |
1061 | - $available_payment_methods += $payment_methods_billing_info; |
|
1061 | + $available_payment_methods += $payment_methods_billing_info; |
|
1062 | 1062 | // build the available payment methods form |
1063 | 1063 | return new EE_Form_Section_Proper( |
1064 | 1064 | [ |
@@ -1081,7 +1081,7 @@ discard block |
||
1081 | 1081 | */ |
1082 | 1082 | protected function _get_available_payment_methods() |
1083 | 1083 | { |
1084 | - if (! empty($this->checkout->available_payment_methods)) { |
|
1084 | + if ( ! empty($this->checkout->available_payment_methods)) { |
|
1085 | 1085 | return $this->checkout->available_payment_methods; |
1086 | 1086 | } |
1087 | 1087 | $available_payment_methods = []; |
@@ -1093,7 +1093,7 @@ discard block |
||
1093 | 1093 | ); |
1094 | 1094 | foreach ($payment_methods as $payment_method) { |
1095 | 1095 | if ($payment_method instanceof EE_Payment_Method) { |
1096 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1096 | + $available_payment_methods[$payment_method->slug()] = $payment_method; |
|
1097 | 1097 | } |
1098 | 1098 | } |
1099 | 1099 | return $available_payment_methods; |
@@ -1188,7 +1188,7 @@ discard block |
||
1188 | 1188 | ); |
1189 | 1189 | return new EE_Form_Section_Proper( |
1190 | 1190 | [ |
1191 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1191 | + 'html_id' => 'spco-payment-method-info-'.$payment_method->slug(), |
|
1192 | 1192 | 'html_class' => 'spco-payment-method-info-dv', |
1193 | 1193 | // only display the selected or default PM |
1194 | 1194 | 'html_style' => $currently_selected ? '' : 'display:none;', |
@@ -1217,7 +1217,7 @@ discard block |
||
1217 | 1217 | // how have they chosen to pay? |
1218 | 1218 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
1219 | 1219 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
1220 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1220 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1221 | 1221 | return false; |
1222 | 1222 | } |
1223 | 1223 | if ( |
@@ -1392,7 +1392,7 @@ discard block |
||
1392 | 1392 | */ |
1393 | 1393 | public function switch_payment_method() |
1394 | 1394 | { |
1395 | - if (! $this->_verify_payment_method_is_set()) { |
|
1395 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
1396 | 1396 | return false; |
1397 | 1397 | } |
1398 | 1398 | if ( |
@@ -1528,7 +1528,7 @@ discard block |
||
1528 | 1528 | } |
1529 | 1529 | } |
1530 | 1530 | // verify payment method |
1531 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1531 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1532 | 1532 | // get payment method for selected method of payment |
1533 | 1533 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
1534 | 1534 | } |
@@ -1553,7 +1553,7 @@ discard block |
||
1553 | 1553 | */ |
1554 | 1554 | public function save_payer_details_via_ajax() |
1555 | 1555 | { |
1556 | - if (! $this->_verify_payment_method_is_set()) { |
|
1556 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
1557 | 1557 | return; |
1558 | 1558 | } |
1559 | 1559 | // generate billing form for selected method of payment if it hasn't been done already |
@@ -1563,7 +1563,7 @@ discard block |
||
1563 | 1563 | ); |
1564 | 1564 | } |
1565 | 1565 | // generate primary attendee from payer info if applicable |
1566 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
1566 | + if ( ! $this->checkout->transaction_has_primary_registrant()) { |
|
1567 | 1567 | $attendee = $this->_create_attendee_from_request_data(); |
1568 | 1568 | if ($attendee instanceof EE_Attendee) { |
1569 | 1569 | foreach ($this->checkout->transaction->registrations() as $registration) { |
@@ -1594,7 +1594,7 @@ discard block |
||
1594 | 1594 | { |
1595 | 1595 | // get State ID |
1596 | 1596 | $STA_ID = $this->request->getRequestParam('state'); |
1597 | - if (! empty($STA_ID)) { |
|
1597 | + if ( ! empty($STA_ID)) { |
|
1598 | 1598 | // can we get state object from name ? |
1599 | 1599 | EE_Registry::instance()->load_model('State'); |
1600 | 1600 | $state = EEM_State::instance()->get_col([['STA_name' => $STA_ID], 'limit' => 1], 'STA_ID'); |
@@ -1602,7 +1602,7 @@ discard block |
||
1602 | 1602 | } |
1603 | 1603 | // get Country ISO |
1604 | 1604 | $CNT_ISO = $this->request->getRequestParam('country'); |
1605 | - if (! empty($CNT_ISO)) { |
|
1605 | + if ( ! empty($CNT_ISO)) { |
|
1606 | 1606 | // can we get country object from name ? |
1607 | 1607 | EE_Registry::instance()->load_model('Country'); |
1608 | 1608 | $country = EEM_Country::instance()->get_col( |
@@ -1785,7 +1785,7 @@ discard block |
||
1785 | 1785 | protected function _maybe_set_completed(EE_Payment $payment) |
1786 | 1786 | { |
1787 | 1787 | // Do we need to redirect them? If so, there's more work to be done. |
1788 | - if (! $payment->redirect_url()){ |
|
1788 | + if ( ! $payment->redirect_url()) { |
|
1789 | 1789 | $this->set_completed(); |
1790 | 1790 | } |
1791 | 1791 | } |
@@ -1842,7 +1842,7 @@ discard block |
||
1842 | 1842 | private function _process_payment() |
1843 | 1843 | { |
1844 | 1844 | // basically confirm that the event hasn't sold out since they hit the page |
1845 | - if (! $this->_last_second_ticket_verifications()) { |
|
1845 | + if ( ! $this->_last_second_ticket_verifications()) { |
|
1846 | 1846 | return null; |
1847 | 1847 | } |
1848 | 1848 | // ya gotta make a choice man |
@@ -1853,7 +1853,7 @@ discard block |
||
1853 | 1853 | return null; |
1854 | 1854 | } |
1855 | 1855 | // get EE_Payment_Method object |
1856 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1856 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1857 | 1857 | return null; |
1858 | 1858 | } |
1859 | 1859 | // setup billing form |
@@ -1862,12 +1862,12 @@ discard block |
||
1862 | 1862 | $this->checkout->payment_method |
1863 | 1863 | ); |
1864 | 1864 | // bad billing form ? |
1865 | - if (! $this->_billing_form_is_valid()) { |
|
1865 | + if ( ! $this->_billing_form_is_valid()) { |
|
1866 | 1866 | return null; |
1867 | 1867 | } |
1868 | 1868 | } |
1869 | 1869 | // ensure primary registrant has been fully processed |
1870 | - if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1870 | + if ( ! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1871 | 1871 | return null; |
1872 | 1872 | } |
1873 | 1873 | // if session is close to expiring (under 10 minutes by default) |
@@ -1922,7 +1922,7 @@ discard block |
||
1922 | 1922 | protected function _last_second_ticket_verifications() |
1923 | 1923 | { |
1924 | 1924 | // don't bother re-validating if not a return visit |
1925 | - if (! $this->checkout->revisit) { |
|
1925 | + if ( ! $this->checkout->revisit) { |
|
1926 | 1926 | return true; |
1927 | 1927 | } |
1928 | 1928 | $registrations = $this->checkout->transaction->registrations(); |
@@ -1972,7 +1972,7 @@ discard block |
||
1972 | 1972 | $this->_get_payment_method_for_selected_method_of_payment() |
1973 | 1973 | ); |
1974 | 1974 | $html = $payment_method_billing_info->get_html(); |
1975 | - $html .= $this->checkout->redirect_form; |
|
1975 | + $html .= $this->checkout->redirect_form; |
|
1976 | 1976 | /** @var ResponseInterface $response */ |
1977 | 1977 | $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class); |
1978 | 1978 | $response->addOutput($html); |
@@ -1988,7 +1988,7 @@ discard block |
||
1988 | 1988 | */ |
1989 | 1989 | private function _billing_form_is_valid() |
1990 | 1990 | { |
1991 | - if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1991 | + if ( ! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1992 | 1992 | return true; |
1993 | 1993 | } |
1994 | 1994 | if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
@@ -2106,7 +2106,7 @@ discard block |
||
2106 | 2106 | { |
2107 | 2107 | // convert billing form data into an attendee |
2108 | 2108 | $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
2109 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2109 | + if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2110 | 2110 | EE_Error::add_error( |
2111 | 2111 | sprintf( |
2112 | 2112 | esc_html__( |
@@ -2123,7 +2123,7 @@ discard block |
||
2123 | 2123 | return false; |
2124 | 2124 | } |
2125 | 2125 | $primary_registration = $this->checkout->transaction->primary_registration(); |
2126 | - if (! $primary_registration instanceof EE_Registration) { |
|
2126 | + if ( ! $primary_registration instanceof EE_Registration) { |
|
2127 | 2127 | EE_Error::add_error( |
2128 | 2128 | sprintf( |
2129 | 2129 | esc_html__( |
@@ -2185,8 +2185,8 @@ discard block |
||
2185 | 2185 | return null; |
2186 | 2186 | } |
2187 | 2187 | // get EE_Payment_Method object |
2188 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
2189 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2188 | + if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) { |
|
2189 | + $payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment]; |
|
2190 | 2190 | } else { |
2191 | 2191 | // load EEM_Payment_Method |
2192 | 2192 | EE_Registry::instance()->load_model('Payment_Method'); |
@@ -2194,7 +2194,7 @@ discard block |
||
2194 | 2194 | $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
2195 | 2195 | } |
2196 | 2196 | // verify $payment_method |
2197 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
2197 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
2198 | 2198 | // not a payment |
2199 | 2199 | EE_Error::add_error( |
2200 | 2200 | sprintf( |
@@ -2212,7 +2212,7 @@ discard block |
||
2212 | 2212 | return null; |
2213 | 2213 | } |
2214 | 2214 | // and verify it has a valid Payment_Method Type object |
2215 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2215 | + if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2216 | 2216 | // not a payment |
2217 | 2217 | EE_Error::add_error( |
2218 | 2218 | sprintf( |
@@ -2250,7 +2250,7 @@ discard block |
||
2250 | 2250 | $payment = null; |
2251 | 2251 | $this->checkout->transaction->save(); |
2252 | 2252 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
2253 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
2253 | + if ( ! $payment_processor instanceof EE_Payment_Processor) { |
|
2254 | 2254 | return false; |
2255 | 2255 | } |
2256 | 2256 | try { |
@@ -2352,7 +2352,7 @@ discard block |
||
2352 | 2352 | return true; |
2353 | 2353 | } |
2354 | 2354 | // verify payment object |
2355 | - if (! $payment instanceof EE_Payment) { |
|
2355 | + if ( ! $payment instanceof EE_Payment) { |
|
2356 | 2356 | // not a payment |
2357 | 2357 | EE_Error::add_error( |
2358 | 2358 | sprintf( |
@@ -2389,9 +2389,9 @@ discard block |
||
2389 | 2389 | // Off-Line payment? |
2390 | 2390 | if ($payment === true) { |
2391 | 2391 | return true; |
2392 | - } elseif ($payment instanceof EE_Payment){ |
|
2392 | + } elseif ($payment instanceof EE_Payment) { |
|
2393 | 2393 | // Should the user be redirected? |
2394 | - if($payment->redirect_url()) { |
|
2394 | + if ($payment->redirect_url()) { |
|
2395 | 2395 | do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
2396 | 2396 | $this->checkout->redirect = true; |
2397 | 2397 | $this->checkout->redirect_form = $payment->redirect_form(); |
@@ -2403,7 +2403,7 @@ discard block |
||
2403 | 2403 | $payment->save(); |
2404 | 2404 | } else |
2405 | 2405 | // User shouldn't be redirected. So let's process it here. |
2406 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2406 | + if ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2407 | 2407 | // $this->_setup_redirect_for_next_step(); |
2408 | 2408 | $this->checkout->continue_reg = false; |
2409 | 2409 | } |
@@ -2484,7 +2484,7 @@ discard block |
||
2484 | 2484 | return false; |
2485 | 2485 | // bad payment |
2486 | 2486 | case EEM_Payment::status_id_failed: |
2487 | - if (! empty($msg)) { |
|
2487 | + if ( ! empty($msg)) { |
|
2488 | 2488 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
2489 | 2489 | return false; |
2490 | 2490 | } |
@@ -2542,18 +2542,18 @@ discard block |
||
2542 | 2542 | // how have they chosen to pay? |
2543 | 2543 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
2544 | 2544 | // get EE_Payment_Method object |
2545 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2545 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2546 | 2546 | $this->checkout->continue_reg = false; |
2547 | 2547 | return false; |
2548 | 2548 | } |
2549 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
2549 | + if ( ! $this->checkout->payment_method->is_off_site()) { |
|
2550 | 2550 | return false; |
2551 | 2551 | } |
2552 | 2552 | $this->_validate_offsite_return(); |
2553 | 2553 | // verify TXN |
2554 | 2554 | if ($this->checkout->transaction instanceof EE_Transaction) { |
2555 | 2555 | $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
2556 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
2556 | + if ( ! $gateway instanceof EE_Offsite_Gateway) { |
|
2557 | 2557 | $this->checkout->continue_reg = false; |
2558 | 2558 | return false; |
2559 | 2559 | } |
@@ -2567,7 +2567,7 @@ discard block |
||
2567 | 2567 | $this->checkout->payment = $payment; |
2568 | 2568 | // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
2569 | 2569 | // because we will complete this step during the IPN processing then |
2570 | - if (! $this->handle_IPN_in_this_request()) { |
|
2570 | + if ( ! $this->handle_IPN_in_this_request()) { |
|
2571 | 2571 | $this->set_completed(); |
2572 | 2572 | } |
2573 | 2573 | return true; |
@@ -2670,13 +2670,13 @@ discard block |
||
2670 | 2670 | */ |
2671 | 2671 | private function _redirect_wayward_request(EE_Registration $primary_registrant) |
2672 | 2672 | { |
2673 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2673 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
2674 | 2674 | // try redirecting based on the current TXN |
2675 | 2675 | $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
2676 | 2676 | ? $this->checkout->transaction->primary_registration() |
2677 | 2677 | : null; |
2678 | 2678 | } |
2679 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2679 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
2680 | 2680 | EE_Error::add_error( |
2681 | 2681 | sprintf( |
2682 | 2682 | esc_html__( |
@@ -2747,7 +2747,7 @@ discard block |
||
2747 | 2747 | $payment = $this->checkout->transaction->last_payment(); |
2748 | 2748 | // $payment_source = 'last_payment after Exception'; |
2749 | 2749 | // but if we STILL don't have a payment object |
2750 | - if (! $payment instanceof EE_Payment) { |
|
2750 | + if ( ! $payment instanceof EE_Payment) { |
|
2751 | 2751 | // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
2752 | 2752 | $this->_handle_payment_processor_exception($e); |
2753 | 2753 | } |