@@ -17,818 +17,818 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @return EED_Module|EED_Add_New_State |
|
22 | - */ |
|
23 | - public static function instance() |
|
24 | - { |
|
25 | - return parent::get_instance(__CLASS__); |
|
26 | - } |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public static function set_hooks() |
|
35 | - { |
|
36 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
37 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
38 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
39 | - add_filter( |
|
40 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
41 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
42 | - 1, |
|
43 | - 1 |
|
44 | - ); |
|
45 | - add_filter( |
|
46 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
47 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
48 | - 1, |
|
49 | - 1 |
|
50 | - ); |
|
51 | - add_filter( |
|
52 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
53 | - array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
54 | - 10, |
|
55 | - 1 |
|
56 | - ); |
|
57 | - add_filter( |
|
58 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
59 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
60 | - 10, |
|
61 | - 5 |
|
62 | - ); |
|
63 | - add_filter( |
|
64 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
65 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
66 | - 10, |
|
67 | - 5 |
|
68 | - ); |
|
69 | - add_filter( |
|
70 | - 'FHEE__EE_State_Select_Input____construct__state_options', |
|
71 | - array('EED_Add_New_State', 'state_options'), |
|
72 | - 10, |
|
73 | - 1 |
|
74 | - ); |
|
75 | - add_filter( |
|
76 | - 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
77 | - array('EED_Add_New_State', 'country_options'), |
|
78 | - 10, |
|
79 | - 1 |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
86 | - * |
|
87 | - * @return void |
|
88 | - */ |
|
89 | - public static function set_hooks_admin() |
|
90 | - { |
|
91 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
92 | - add_filter( |
|
93 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
94 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
95 | - 1, |
|
96 | - 1 |
|
97 | - ); |
|
98 | - add_filter( |
|
99 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
100 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
101 | - 1, |
|
102 | - 1 |
|
103 | - ); |
|
104 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
105 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
106 | - add_filter( |
|
107 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
108 | - array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
109 | - 10, |
|
110 | - 1 |
|
111 | - ); |
|
112 | - add_action( |
|
113 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
114 | - array('EED_Add_New_State', 'update_country_settings'), |
|
115 | - 10, |
|
116 | - 3 |
|
117 | - ); |
|
118 | - add_action( |
|
119 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
120 | - array('EED_Add_New_State', 'update_country_settings'), |
|
121 | - 10, |
|
122 | - 3 |
|
123 | - ); |
|
124 | - add_filter( |
|
125 | - 'FHEE__EE_State_Select_Input____construct__state_options', |
|
126 | - array('EED_Add_New_State', 'state_options'), |
|
127 | - 10, |
|
128 | - 1 |
|
129 | - ); |
|
130 | - add_filter( |
|
131 | - 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
132 | - array('EED_Add_New_State', 'country_options'), |
|
133 | - 10, |
|
134 | - 1 |
|
135 | - ); |
|
136 | - add_filter( |
|
137 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
138 | - array('EED_Add_New_State', 'filter_checkout_request_params'), |
|
139 | - 10, |
|
140 | - 1 |
|
141 | - ); |
|
142 | - add_filter( |
|
143 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
144 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
145 | - 10, |
|
146 | - 5 |
|
147 | - ); |
|
148 | - add_filter( |
|
149 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
150 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
151 | - 10, |
|
152 | - 5 |
|
153 | - ); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - public static function set_definitions() |
|
161 | - { |
|
162 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
163 | - define( |
|
164 | - 'ANS_TEMPLATES_PATH', |
|
165 | - str_replace( |
|
166 | - '\\', |
|
167 | - DS, |
|
168 | - plugin_dir_path(__FILE__) |
|
169 | - ) . 'templates' . DS |
|
170 | - ); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @param WP $WP |
|
176 | - * @return void |
|
177 | - */ |
|
178 | - public function run($WP) |
|
179 | - { |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @return void |
|
185 | - */ |
|
186 | - public static function translate_js_strings() |
|
187 | - { |
|
188 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
189 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
190 | - 'event_espresso' |
|
191 | - ); |
|
192 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
193 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
194 | - 'event_espresso' |
|
195 | - ); |
|
196 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
197 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
198 | - 'event_espresso' |
|
199 | - ); |
|
200 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
201 | - 'The new state was successfully saved to the database.', |
|
202 | - 'event_espresso' |
|
203 | - ); |
|
204 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
205 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
206 | - 'event_espresso' |
|
207 | - ); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @return void |
|
213 | - */ |
|
214 | - public static function wp_enqueue_scripts() |
|
215 | - { |
|
216 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
217 | - wp_register_script( |
|
218 | - 'add_new_state', |
|
219 | - ANS_ASSETS_URL . 'add_new_state.js', |
|
220 | - array('espresso_core', 'single_page_checkout'), |
|
221 | - EVENT_ESPRESSO_VERSION, |
|
222 | - true |
|
223 | - ); |
|
224 | - wp_enqueue_script('add_new_state'); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * display_add_new_state_micro_form |
|
232 | - * |
|
233 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
234 | - * @return string |
|
235 | - * @throws EE_Error |
|
236 | - * @throws InvalidArgumentException |
|
237 | - * @throws InvalidDataTypeException |
|
238 | - * @throws InvalidInterfaceException |
|
239 | - */ |
|
240 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
241 | - { |
|
242 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
243 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
244 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
245 | - // is the "state" question in this form section? |
|
246 | - $input = $question_group_reg_form->get_subsection('state'); |
|
247 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
248 | - // ok then all we need to do is make sure the input's HTML name is consistent |
|
249 | - // by forcing it to set it now, like it did while getting the form for display |
|
250 | - if ($input instanceof EE_State_Select_Input) { |
|
251 | - $input->html_name(); |
|
252 | - } |
|
253 | - return $question_group_reg_form; |
|
254 | - } |
|
255 | - // we're only doing this for state select inputs |
|
256 | - if ($input instanceof EE_State_Select_Input |
|
257 | - && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy |
|
258 | - ) { |
|
259 | - // grab any set values from the request |
|
260 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
261 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
262 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
263 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
264 | - $country_options = array(); |
|
265 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
266 | - if (! empty($countries)) { |
|
267 | - foreach ($countries as $country) { |
|
268 | - if ($country instanceof EE_Country) { |
|
269 | - $country_options[ $country->ID() ] = $country->name(); |
|
270 | - } |
|
271 | - } |
|
272 | - } |
|
273 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
274 | - array( |
|
275 | - 'name' => 'new_state_micro_form', |
|
276 | - 'html_id' => 'new_state_micro_form', |
|
277 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
278 | - 'subsections' => array( |
|
279 | - // add hidden input to indicate that a new state is being added |
|
280 | - 'add_new_state' => new EE_Hidden_Input( |
|
281 | - array( |
|
282 | - 'html_name' => str_replace( |
|
283 | - 'state', |
|
284 | - 'nsmf_add_new_state', |
|
285 | - $input->html_name() |
|
286 | - ), |
|
287 | - 'html_id' => str_replace( |
|
288 | - 'state', |
|
289 | - 'nsmf_add_new_state', |
|
290 | - $input->html_id() |
|
291 | - ), |
|
292 | - 'default' => 0, |
|
293 | - ) |
|
294 | - ), |
|
295 | - // add link for displaying hidden container |
|
296 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
297 | - apply_filters( |
|
298 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
299 | - EEH_HTML::link( |
|
300 | - '', |
|
301 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
302 | - '', |
|
303 | - 'display-' . $input->html_id(), |
|
304 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
305 | - '', |
|
306 | - 'data-target="' . $input->html_id() . '"' |
|
307 | - ) |
|
308 | - ) |
|
309 | - ), |
|
310 | - // add initial html for hidden container |
|
311 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
312 | - apply_filters( |
|
313 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
314 | - EEH_HTML::div( |
|
315 | - '', |
|
316 | - $input->html_id() . '-dv', |
|
317 | - 'ee-form-add-new-state-dv', |
|
318 | - 'display: none;' |
|
319 | - ) . |
|
320 | - EEH_HTML::h6( |
|
321 | - esc_html__( |
|
322 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
323 | - 'event_espresso' |
|
324 | - ) |
|
325 | - ) . |
|
326 | - EEH_HTML::ul() . |
|
327 | - EEH_HTML::li( |
|
328 | - esc_html__( |
|
329 | - 'first select the Country that your State/Province belongs to', |
|
330 | - 'event_espresso' |
|
331 | - ) |
|
332 | - ) . |
|
333 | - EEH_HTML::li( |
|
334 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
335 | - ) . |
|
336 | - EEH_HTML::li( |
|
337 | - esc_html__( |
|
338 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
339 | - 'event_espresso' |
|
340 | - ) |
|
341 | - ) . |
|
342 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
343 | - EEH_HTML::ulx() |
|
344 | - ) |
|
345 | - ), |
|
346 | - // NEW STATE COUNTRY |
|
347 | - 'new_state_country' => new EE_Country_Select_Input( |
|
348 | - $country_options, |
|
349 | - array( |
|
350 | - 'html_name' => $country_name, |
|
351 | - 'html_id' => str_replace( |
|
352 | - 'state', |
|
353 | - 'nsmf_new_state_country', |
|
354 | - $input->html_id() |
|
355 | - ), |
|
356 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
357 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
358 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
359 | - 'required' => false, |
|
360 | - ) |
|
361 | - ), |
|
362 | - // NEW STATE NAME |
|
363 | - 'new_state_name' => new EE_Text_Input( |
|
364 | - array( |
|
365 | - 'html_name' => $state_name, |
|
366 | - 'html_id' => str_replace( |
|
367 | - 'state', |
|
368 | - 'nsmf_new_state_name', |
|
369 | - $input->html_id() |
|
370 | - ), |
|
371 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
372 | - 'html_label_text' => esc_html__( |
|
373 | - 'New State/Province Name', |
|
374 | - 'event_espresso' |
|
375 | - ), |
|
376 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
377 | - 'required' => false, |
|
378 | - ) |
|
379 | - ), |
|
380 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
381 | - // NEW STATE NAME |
|
382 | - 'new_state_abbrv' => new EE_Text_Input( |
|
383 | - array( |
|
384 | - 'html_name' => $abbrv_name, |
|
385 | - 'html_id' => str_replace( |
|
386 | - 'state', |
|
387 | - 'nsmf_new_state_abbrv', |
|
388 | - $input->html_id() |
|
389 | - ), |
|
390 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
391 | - 'html_label_text' => esc_html__( |
|
392 | - 'New State/Province Abbreviation', |
|
393 | - 'event_espresso' |
|
394 | - ) . ' *', |
|
395 | - 'html_other_attributes' => 'size="24"', |
|
396 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
397 | - 'required' => false, |
|
398 | - ) |
|
399 | - ), |
|
400 | - // "submit" button |
|
401 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
402 | - apply_filters( |
|
403 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
404 | - EEH_HTML::nbsp(3) . |
|
405 | - EEH_HTML::link( |
|
406 | - '', |
|
407 | - esc_html__('ADD', 'event_espresso'), |
|
408 | - '', |
|
409 | - 'submit-' . $new_state_submit_id, |
|
410 | - 'ee-form-add-new-state-submit button button-secondary', |
|
411 | - '', |
|
412 | - 'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"' |
|
413 | - ) |
|
414 | - ) |
|
415 | - ), |
|
416 | - // extra info |
|
417 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
418 | - apply_filters( |
|
419 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
420 | - EEH_HTML::br(2) |
|
421 | - . |
|
422 | - EEH_HTML::div('', '', 'small-text') |
|
423 | - . |
|
424 | - EEH_HTML::strong( |
|
425 | - '* ' . |
|
426 | - esc_html__( |
|
427 | - 'Don\'t know your State/Province Abbreviation?', |
|
428 | - 'event_espresso' |
|
429 | - ) |
|
430 | - ) |
|
431 | - . |
|
432 | - EEH_HTML::br() |
|
433 | - . |
|
434 | - sprintf( |
|
435 | - esc_html__( |
|
436 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
437 | - 'event_espresso' |
|
438 | - ), |
|
439 | - EEH_HTML::link( |
|
440 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
441 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
442 | - '', |
|
443 | - '', |
|
444 | - 'ee-form-add-new-state-wiki-lnk', |
|
445 | - '', |
|
446 | - 'target="_blank"' |
|
447 | - ) |
|
448 | - ) |
|
449 | - . |
|
450 | - EEH_HTML::divx() |
|
451 | - . |
|
452 | - EEH_HTML::br() |
|
453 | - . |
|
454 | - EEH_HTML::link( |
|
455 | - '', |
|
456 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
457 | - '', |
|
458 | - 'hide-' . $input->html_id(), |
|
459 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
460 | - '', |
|
461 | - 'data-target="' . $input->html_id() . '"' |
|
462 | - ) |
|
463 | - . |
|
464 | - EEH_HTML::divx() |
|
465 | - . |
|
466 | - EEH_HTML::br() |
|
467 | - ) |
|
468 | - ), |
|
469 | - ), |
|
470 | - ) |
|
471 | - ); |
|
472 | - $question_group_reg_form->add_subsections( |
|
473 | - array('new_state_micro_form' => $new_state_micro_form), |
|
474 | - 'state', |
|
475 | - false |
|
476 | - ); |
|
477 | - } |
|
478 | - return $question_group_reg_form; |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * set_new_state_input_width |
|
484 | - * |
|
485 | - * @return int|string |
|
486 | - * @throws EE_Error |
|
487 | - * @throws InvalidArgumentException |
|
488 | - * @throws InvalidDataTypeException |
|
489 | - * @throws InvalidInterfaceException |
|
490 | - * @throws ReflectionException |
|
491 | - */ |
|
492 | - public static function add_new_state() |
|
493 | - { |
|
494 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
495 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
496 | - EE_Registry::instance()->load_model('State'); |
|
497 | - // grab country ISO code, new state name, and new state abbreviation |
|
498 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
499 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
500 | - : false; |
|
501 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
502 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
503 | - : false; |
|
504 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
505 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
506 | - : false; |
|
507 | - if ($state_country && $state_name && $state_abbr) { |
|
508 | - $new_state = EED_Add_New_State::save_new_state_to_db( |
|
509 | - array( |
|
510 | - 'CNT_ISO' => strtoupper($state_country), |
|
511 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
512 | - 'STA_name' => ucwords($state_name), |
|
513 | - 'STA_active' => false, |
|
514 | - ) |
|
515 | - ); |
|
516 | - if ($new_state instanceof EE_State) { |
|
517 | - // clean house |
|
518 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
519 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
520 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
521 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
522 | - // get any existing new states |
|
523 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
524 | - 'nsmf_new_states' |
|
525 | - ); |
|
526 | - $new_states[ $new_state->ID() ] = $new_state; |
|
527 | - EE_Registry::instance()->SSN->set_session_data( |
|
528 | - array('nsmf_new_states' => $new_states) |
|
529 | - ); |
|
530 | - if (EE_Registry::instance()->REQ->ajax) { |
|
531 | - echo wp_json_encode( |
|
532 | - array( |
|
533 | - 'success' => true, |
|
534 | - 'id' => $new_state->ID(), |
|
535 | - 'name' => $new_state->name(), |
|
536 | - 'abbrev' => $new_state->abbrev(), |
|
537 | - 'country_iso' => $new_state->country_iso(), |
|
538 | - 'country_name' => $new_state->country()->name(), |
|
539 | - ) |
|
540 | - ); |
|
541 | - exit(); |
|
542 | - } |
|
543 | - return $new_state->ID(); |
|
544 | - } |
|
545 | - } else { |
|
546 | - $error = esc_html__( |
|
547 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
548 | - 'event_espresso' |
|
549 | - ); |
|
550 | - if (EE_Registry::instance()->REQ->ajax) { |
|
551 | - echo wp_json_encode(array('error' => $error)); |
|
552 | - exit(); |
|
553 | - } |
|
554 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
555 | - } |
|
556 | - } |
|
557 | - return false; |
|
558 | - } |
|
559 | - |
|
560 | - |
|
561 | - /** |
|
562 | - * recursively drills down through request params to remove any that were added by this module |
|
563 | - * |
|
564 | - * @param array $request_params |
|
565 | - * @return array |
|
566 | - */ |
|
567 | - public static function filter_checkout_request_params($request_params) |
|
568 | - { |
|
569 | - foreach ($request_params as $form_section) { |
|
570 | - if (is_array($form_section)) { |
|
571 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
572 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
573 | - } |
|
574 | - } |
|
575 | - return $request_params; |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * @param array $request_params |
|
581 | - * @return array |
|
582 | - */ |
|
583 | - public static function unset_new_state_request_params($request_params) |
|
584 | - { |
|
585 | - unset( |
|
586 | - $request_params['new_state_micro_form'], |
|
587 | - $request_params['new_state_micro_add_new_state'], |
|
588 | - $request_params['new_state_micro_new_state_country'], |
|
589 | - $request_params['new_state_micro_new_state_name'], |
|
590 | - $request_params['new_state_micro_new_state_abbrv'] |
|
591 | - ); |
|
592 | - return $request_params; |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - /** |
|
597 | - * @param array $props_n_values |
|
598 | - * @return bool |
|
599 | - * @throws EE_Error |
|
600 | - * @throws InvalidArgumentException |
|
601 | - * @throws InvalidDataTypeException |
|
602 | - * @throws InvalidInterfaceException |
|
603 | - */ |
|
604 | - public static function save_new_state_to_db($props_n_values = array()) |
|
605 | - { |
|
606 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
607 | - if (! empty($existing_state)) { |
|
608 | - return array_pop($existing_state); |
|
609 | - } |
|
610 | - $new_state = EE_State::new_instance($props_n_values); |
|
611 | - if ($new_state instanceof EE_State) { |
|
612 | - $country_settings_url = add_query_arg( |
|
613 | - array( |
|
614 | - 'page' => 'espresso_general_settings', |
|
615 | - 'action' => 'country_settings', |
|
616 | - 'country' => $new_state->country_iso(), |
|
617 | - ), |
|
618 | - admin_url('admin.php') |
|
619 | - ); |
|
620 | - // if not non-ajax admin |
|
621 | - new PersistentAdminNotice( |
|
622 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
623 | - sprintf( |
|
624 | - esc_html__( |
|
625 | - 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
626 | - 'event_espresso' |
|
627 | - ), |
|
628 | - '<b>' . $new_state->name() . '</b>', |
|
629 | - '<b>' . $new_state->abbrev() . '</b>', |
|
630 | - '<b>' . $new_state->country()->name() . '</b>', |
|
631 | - '<a href="' |
|
632 | - . $country_settings_url |
|
633 | - . '">' |
|
634 | - . esc_html__( |
|
635 | - 'Event Espresso - General Settings > Countries Tab', |
|
636 | - 'event_espresso' |
|
637 | - ) |
|
638 | - . '</a>', |
|
639 | - '<br />' |
|
640 | - ) |
|
641 | - ); |
|
642 | - $new_state->save(); |
|
643 | - EEM_State::instance()->reset_cached_states(); |
|
644 | - return $new_state; |
|
645 | - } |
|
646 | - return false; |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * @param string $CNT_ISO |
|
652 | - * @param string $STA_ID |
|
653 | - * @param array $cols_n_values |
|
654 | - * @return void |
|
655 | - * @throws DomainException |
|
656 | - * @throws EE_Error |
|
657 | - * @throws InvalidArgumentException |
|
658 | - * @throws InvalidDataTypeException |
|
659 | - * @throws InvalidInterfaceException |
|
660 | - */ |
|
661 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
662 | - { |
|
663 | - if (! $CNT_ISO) { |
|
664 | - EE_Error::add_error( |
|
665 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
666 | - __FILE__, |
|
667 | - __FUNCTION__, |
|
668 | - __LINE__ |
|
669 | - ); |
|
670 | - } |
|
671 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
672 | - : false; |
|
673 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
674 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
675 | - if ($state instanceof EE_State) { |
|
676 | - $STA_abbrev = $state->abbrev(); |
|
677 | - } |
|
678 | - } |
|
679 | - if (! $STA_abbrev) { |
|
680 | - EE_Error::add_error( |
|
681 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
682 | - __FILE__, |
|
683 | - __FUNCTION__, |
|
684 | - __LINE__ |
|
685 | - ); |
|
686 | - } |
|
687 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
688 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
689 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
690 | - ); |
|
691 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
692 | - } |
|
693 | - |
|
694 | - |
|
695 | - /** |
|
696 | - * @param EE_State[] $state_options |
|
697 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
698 | - * @param EE_Registration $registration |
|
699 | - * @param EE_Question $question |
|
700 | - * @param $answer |
|
701 | - * @return array |
|
702 | - * @throws EE_Error |
|
703 | - * @throws InvalidArgumentException |
|
704 | - * @throws InvalidDataTypeException |
|
705 | - * @throws InvalidInterfaceException |
|
706 | - */ |
|
707 | - public static function inject_new_reg_state_into_options( |
|
708 | - $state_options = array(), |
|
709 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
710 | - EE_Registration $registration, |
|
711 | - EE_Question $question, |
|
712 | - $answer |
|
713 | - ) { |
|
714 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
715 | - && $question->type() === EEM_Question::QST_type_state |
|
716 | - ) { |
|
717 | - $STA_ID = $answer->value(); |
|
718 | - if (! empty($STA_ID)) { |
|
719 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
720 | - if ($state instanceof EE_State) { |
|
721 | - $country = $state->country(); |
|
722 | - if ($country instanceof EE_Country) { |
|
723 | - if (! isset($state_options[ $country->name() ])) { |
|
724 | - $state_options[ $country->name() ] = array(); |
|
725 | - } |
|
726 | - if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
727 | - $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
728 | - } |
|
729 | - } |
|
730 | - } |
|
731 | - } |
|
732 | - } |
|
733 | - return $state_options; |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - /** |
|
738 | - * @param EE_Country[] $country_options |
|
739 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
740 | - * @param EE_Registration $registration |
|
741 | - * @param EE_Question $question |
|
742 | - * @param $answer |
|
743 | - * @return array |
|
744 | - * @throws EE_Error |
|
745 | - * @throws InvalidArgumentException |
|
746 | - * @throws InvalidDataTypeException |
|
747 | - * @throws InvalidInterfaceException |
|
748 | - */ |
|
749 | - public static function inject_new_reg_country_into_options( |
|
750 | - $country_options = array(), |
|
751 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
752 | - EE_Registration $registration, |
|
753 | - EE_Question $question, |
|
754 | - $answer |
|
755 | - ) { |
|
756 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
757 | - && $question->type() |
|
758 | - === EEM_Question::QST_type_country |
|
759 | - ) { |
|
760 | - $CNT_ISO = $answer->value(); |
|
761 | - if (! empty($CNT_ISO)) { |
|
762 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
763 | - if ($country instanceof EE_Country) { |
|
764 | - if (! isset($country_options[ $CNT_ISO ])) { |
|
765 | - $country_options[ $CNT_ISO ] = $country->name(); |
|
766 | - } |
|
767 | - } |
|
768 | - } |
|
769 | - } |
|
770 | - return $country_options; |
|
771 | - } |
|
772 | - |
|
773 | - |
|
774 | - /** |
|
775 | - * @param EE_State[] $state_options |
|
776 | - * @return array |
|
777 | - * @throws EE_Error |
|
778 | - * @throws InvalidArgumentException |
|
779 | - * @throws InvalidDataTypeException |
|
780 | - * @throws InvalidInterfaceException |
|
781 | - */ |
|
782 | - public static function state_options($state_options = array()) |
|
783 | - { |
|
784 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
785 | - foreach ($new_states as $new_state) { |
|
786 | - if ($new_state instanceof EE_State |
|
787 | - && $new_state->country() instanceof EE_Country |
|
788 | - ) { |
|
789 | - $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
790 | - } |
|
791 | - } |
|
792 | - return $state_options; |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * @return array |
|
798 | - * @throws InvalidArgumentException |
|
799 | - * @throws InvalidDataTypeException |
|
800 | - * @throws InvalidInterfaceException |
|
801 | - */ |
|
802 | - protected static function _get_new_states() |
|
803 | - { |
|
804 | - $new_states = array(); |
|
805 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
806 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
807 | - 'nsmf_new_states' |
|
808 | - ); |
|
809 | - } |
|
810 | - return is_array($new_states) ? $new_states : array(); |
|
811 | - } |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * @param EE_Country[] $country_options |
|
816 | - * @return array |
|
817 | - * @throws EE_Error |
|
818 | - * @throws InvalidArgumentException |
|
819 | - * @throws InvalidDataTypeException |
|
820 | - * @throws InvalidInterfaceException |
|
821 | - */ |
|
822 | - public static function country_options($country_options = array()) |
|
823 | - { |
|
824 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
825 | - foreach ($new_states as $new_state) { |
|
826 | - if ($new_state instanceof EE_State |
|
827 | - && $new_state->country() instanceof EE_Country |
|
828 | - ) { |
|
829 | - $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
830 | - } |
|
831 | - } |
|
832 | - return $country_options; |
|
833 | - } |
|
20 | + /** |
|
21 | + * @return EED_Module|EED_Add_New_State |
|
22 | + */ |
|
23 | + public static function instance() |
|
24 | + { |
|
25 | + return parent::get_instance(__CLASS__); |
|
26 | + } |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public static function set_hooks() |
|
35 | + { |
|
36 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
37 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
38 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
39 | + add_filter( |
|
40 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
41 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
42 | + 1, |
|
43 | + 1 |
|
44 | + ); |
|
45 | + add_filter( |
|
46 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
47 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
48 | + 1, |
|
49 | + 1 |
|
50 | + ); |
|
51 | + add_filter( |
|
52 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
53 | + array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
54 | + 10, |
|
55 | + 1 |
|
56 | + ); |
|
57 | + add_filter( |
|
58 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
59 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
60 | + 10, |
|
61 | + 5 |
|
62 | + ); |
|
63 | + add_filter( |
|
64 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
65 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
66 | + 10, |
|
67 | + 5 |
|
68 | + ); |
|
69 | + add_filter( |
|
70 | + 'FHEE__EE_State_Select_Input____construct__state_options', |
|
71 | + array('EED_Add_New_State', 'state_options'), |
|
72 | + 10, |
|
73 | + 1 |
|
74 | + ); |
|
75 | + add_filter( |
|
76 | + 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
77 | + array('EED_Add_New_State', 'country_options'), |
|
78 | + 10, |
|
79 | + 1 |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
86 | + * |
|
87 | + * @return void |
|
88 | + */ |
|
89 | + public static function set_hooks_admin() |
|
90 | + { |
|
91 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
92 | + add_filter( |
|
93 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
94 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
95 | + 1, |
|
96 | + 1 |
|
97 | + ); |
|
98 | + add_filter( |
|
99 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
100 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
101 | + 1, |
|
102 | + 1 |
|
103 | + ); |
|
104 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
105 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
106 | + add_filter( |
|
107 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
108 | + array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
109 | + 10, |
|
110 | + 1 |
|
111 | + ); |
|
112 | + add_action( |
|
113 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
114 | + array('EED_Add_New_State', 'update_country_settings'), |
|
115 | + 10, |
|
116 | + 3 |
|
117 | + ); |
|
118 | + add_action( |
|
119 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
120 | + array('EED_Add_New_State', 'update_country_settings'), |
|
121 | + 10, |
|
122 | + 3 |
|
123 | + ); |
|
124 | + add_filter( |
|
125 | + 'FHEE__EE_State_Select_Input____construct__state_options', |
|
126 | + array('EED_Add_New_State', 'state_options'), |
|
127 | + 10, |
|
128 | + 1 |
|
129 | + ); |
|
130 | + add_filter( |
|
131 | + 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
132 | + array('EED_Add_New_State', 'country_options'), |
|
133 | + 10, |
|
134 | + 1 |
|
135 | + ); |
|
136 | + add_filter( |
|
137 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
138 | + array('EED_Add_New_State', 'filter_checkout_request_params'), |
|
139 | + 10, |
|
140 | + 1 |
|
141 | + ); |
|
142 | + add_filter( |
|
143 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
144 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
145 | + 10, |
|
146 | + 5 |
|
147 | + ); |
|
148 | + add_filter( |
|
149 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
150 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
151 | + 10, |
|
152 | + 5 |
|
153 | + ); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + public static function set_definitions() |
|
161 | + { |
|
162 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
163 | + define( |
|
164 | + 'ANS_TEMPLATES_PATH', |
|
165 | + str_replace( |
|
166 | + '\\', |
|
167 | + DS, |
|
168 | + plugin_dir_path(__FILE__) |
|
169 | + ) . 'templates' . DS |
|
170 | + ); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @param WP $WP |
|
176 | + * @return void |
|
177 | + */ |
|
178 | + public function run($WP) |
|
179 | + { |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @return void |
|
185 | + */ |
|
186 | + public static function translate_js_strings() |
|
187 | + { |
|
188 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
189 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
190 | + 'event_espresso' |
|
191 | + ); |
|
192 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
193 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
194 | + 'event_espresso' |
|
195 | + ); |
|
196 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
197 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
198 | + 'event_espresso' |
|
199 | + ); |
|
200 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
201 | + 'The new state was successfully saved to the database.', |
|
202 | + 'event_espresso' |
|
203 | + ); |
|
204 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
205 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
206 | + 'event_espresso' |
|
207 | + ); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @return void |
|
213 | + */ |
|
214 | + public static function wp_enqueue_scripts() |
|
215 | + { |
|
216 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
217 | + wp_register_script( |
|
218 | + 'add_new_state', |
|
219 | + ANS_ASSETS_URL . 'add_new_state.js', |
|
220 | + array('espresso_core', 'single_page_checkout'), |
|
221 | + EVENT_ESPRESSO_VERSION, |
|
222 | + true |
|
223 | + ); |
|
224 | + wp_enqueue_script('add_new_state'); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * display_add_new_state_micro_form |
|
232 | + * |
|
233 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
234 | + * @return string |
|
235 | + * @throws EE_Error |
|
236 | + * @throws InvalidArgumentException |
|
237 | + * @throws InvalidDataTypeException |
|
238 | + * @throws InvalidInterfaceException |
|
239 | + */ |
|
240 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
241 | + { |
|
242 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
243 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
244 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
245 | + // is the "state" question in this form section? |
|
246 | + $input = $question_group_reg_form->get_subsection('state'); |
|
247 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
248 | + // ok then all we need to do is make sure the input's HTML name is consistent |
|
249 | + // by forcing it to set it now, like it did while getting the form for display |
|
250 | + if ($input instanceof EE_State_Select_Input) { |
|
251 | + $input->html_name(); |
|
252 | + } |
|
253 | + return $question_group_reg_form; |
|
254 | + } |
|
255 | + // we're only doing this for state select inputs |
|
256 | + if ($input instanceof EE_State_Select_Input |
|
257 | + && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy |
|
258 | + ) { |
|
259 | + // grab any set values from the request |
|
260 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
261 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
262 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
263 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
264 | + $country_options = array(); |
|
265 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
266 | + if (! empty($countries)) { |
|
267 | + foreach ($countries as $country) { |
|
268 | + if ($country instanceof EE_Country) { |
|
269 | + $country_options[ $country->ID() ] = $country->name(); |
|
270 | + } |
|
271 | + } |
|
272 | + } |
|
273 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
274 | + array( |
|
275 | + 'name' => 'new_state_micro_form', |
|
276 | + 'html_id' => 'new_state_micro_form', |
|
277 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
278 | + 'subsections' => array( |
|
279 | + // add hidden input to indicate that a new state is being added |
|
280 | + 'add_new_state' => new EE_Hidden_Input( |
|
281 | + array( |
|
282 | + 'html_name' => str_replace( |
|
283 | + 'state', |
|
284 | + 'nsmf_add_new_state', |
|
285 | + $input->html_name() |
|
286 | + ), |
|
287 | + 'html_id' => str_replace( |
|
288 | + 'state', |
|
289 | + 'nsmf_add_new_state', |
|
290 | + $input->html_id() |
|
291 | + ), |
|
292 | + 'default' => 0, |
|
293 | + ) |
|
294 | + ), |
|
295 | + // add link for displaying hidden container |
|
296 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
297 | + apply_filters( |
|
298 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
299 | + EEH_HTML::link( |
|
300 | + '', |
|
301 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
302 | + '', |
|
303 | + 'display-' . $input->html_id(), |
|
304 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
305 | + '', |
|
306 | + 'data-target="' . $input->html_id() . '"' |
|
307 | + ) |
|
308 | + ) |
|
309 | + ), |
|
310 | + // add initial html for hidden container |
|
311 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
312 | + apply_filters( |
|
313 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
314 | + EEH_HTML::div( |
|
315 | + '', |
|
316 | + $input->html_id() . '-dv', |
|
317 | + 'ee-form-add-new-state-dv', |
|
318 | + 'display: none;' |
|
319 | + ) . |
|
320 | + EEH_HTML::h6( |
|
321 | + esc_html__( |
|
322 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
323 | + 'event_espresso' |
|
324 | + ) |
|
325 | + ) . |
|
326 | + EEH_HTML::ul() . |
|
327 | + EEH_HTML::li( |
|
328 | + esc_html__( |
|
329 | + 'first select the Country that your State/Province belongs to', |
|
330 | + 'event_espresso' |
|
331 | + ) |
|
332 | + ) . |
|
333 | + EEH_HTML::li( |
|
334 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
335 | + ) . |
|
336 | + EEH_HTML::li( |
|
337 | + esc_html__( |
|
338 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
339 | + 'event_espresso' |
|
340 | + ) |
|
341 | + ) . |
|
342 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
343 | + EEH_HTML::ulx() |
|
344 | + ) |
|
345 | + ), |
|
346 | + // NEW STATE COUNTRY |
|
347 | + 'new_state_country' => new EE_Country_Select_Input( |
|
348 | + $country_options, |
|
349 | + array( |
|
350 | + 'html_name' => $country_name, |
|
351 | + 'html_id' => str_replace( |
|
352 | + 'state', |
|
353 | + 'nsmf_new_state_country', |
|
354 | + $input->html_id() |
|
355 | + ), |
|
356 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
357 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
358 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
359 | + 'required' => false, |
|
360 | + ) |
|
361 | + ), |
|
362 | + // NEW STATE NAME |
|
363 | + 'new_state_name' => new EE_Text_Input( |
|
364 | + array( |
|
365 | + 'html_name' => $state_name, |
|
366 | + 'html_id' => str_replace( |
|
367 | + 'state', |
|
368 | + 'nsmf_new_state_name', |
|
369 | + $input->html_id() |
|
370 | + ), |
|
371 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
372 | + 'html_label_text' => esc_html__( |
|
373 | + 'New State/Province Name', |
|
374 | + 'event_espresso' |
|
375 | + ), |
|
376 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
377 | + 'required' => false, |
|
378 | + ) |
|
379 | + ), |
|
380 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
381 | + // NEW STATE NAME |
|
382 | + 'new_state_abbrv' => new EE_Text_Input( |
|
383 | + array( |
|
384 | + 'html_name' => $abbrv_name, |
|
385 | + 'html_id' => str_replace( |
|
386 | + 'state', |
|
387 | + 'nsmf_new_state_abbrv', |
|
388 | + $input->html_id() |
|
389 | + ), |
|
390 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
391 | + 'html_label_text' => esc_html__( |
|
392 | + 'New State/Province Abbreviation', |
|
393 | + 'event_espresso' |
|
394 | + ) . ' *', |
|
395 | + 'html_other_attributes' => 'size="24"', |
|
396 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
397 | + 'required' => false, |
|
398 | + ) |
|
399 | + ), |
|
400 | + // "submit" button |
|
401 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
402 | + apply_filters( |
|
403 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
404 | + EEH_HTML::nbsp(3) . |
|
405 | + EEH_HTML::link( |
|
406 | + '', |
|
407 | + esc_html__('ADD', 'event_espresso'), |
|
408 | + '', |
|
409 | + 'submit-' . $new_state_submit_id, |
|
410 | + 'ee-form-add-new-state-submit button button-secondary', |
|
411 | + '', |
|
412 | + 'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"' |
|
413 | + ) |
|
414 | + ) |
|
415 | + ), |
|
416 | + // extra info |
|
417 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
418 | + apply_filters( |
|
419 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
420 | + EEH_HTML::br(2) |
|
421 | + . |
|
422 | + EEH_HTML::div('', '', 'small-text') |
|
423 | + . |
|
424 | + EEH_HTML::strong( |
|
425 | + '* ' . |
|
426 | + esc_html__( |
|
427 | + 'Don\'t know your State/Province Abbreviation?', |
|
428 | + 'event_espresso' |
|
429 | + ) |
|
430 | + ) |
|
431 | + . |
|
432 | + EEH_HTML::br() |
|
433 | + . |
|
434 | + sprintf( |
|
435 | + esc_html__( |
|
436 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
437 | + 'event_espresso' |
|
438 | + ), |
|
439 | + EEH_HTML::link( |
|
440 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
441 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
442 | + '', |
|
443 | + '', |
|
444 | + 'ee-form-add-new-state-wiki-lnk', |
|
445 | + '', |
|
446 | + 'target="_blank"' |
|
447 | + ) |
|
448 | + ) |
|
449 | + . |
|
450 | + EEH_HTML::divx() |
|
451 | + . |
|
452 | + EEH_HTML::br() |
|
453 | + . |
|
454 | + EEH_HTML::link( |
|
455 | + '', |
|
456 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
457 | + '', |
|
458 | + 'hide-' . $input->html_id(), |
|
459 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
460 | + '', |
|
461 | + 'data-target="' . $input->html_id() . '"' |
|
462 | + ) |
|
463 | + . |
|
464 | + EEH_HTML::divx() |
|
465 | + . |
|
466 | + EEH_HTML::br() |
|
467 | + ) |
|
468 | + ), |
|
469 | + ), |
|
470 | + ) |
|
471 | + ); |
|
472 | + $question_group_reg_form->add_subsections( |
|
473 | + array('new_state_micro_form' => $new_state_micro_form), |
|
474 | + 'state', |
|
475 | + false |
|
476 | + ); |
|
477 | + } |
|
478 | + return $question_group_reg_form; |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * set_new_state_input_width |
|
484 | + * |
|
485 | + * @return int|string |
|
486 | + * @throws EE_Error |
|
487 | + * @throws InvalidArgumentException |
|
488 | + * @throws InvalidDataTypeException |
|
489 | + * @throws InvalidInterfaceException |
|
490 | + * @throws ReflectionException |
|
491 | + */ |
|
492 | + public static function add_new_state() |
|
493 | + { |
|
494 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
495 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
496 | + EE_Registry::instance()->load_model('State'); |
|
497 | + // grab country ISO code, new state name, and new state abbreviation |
|
498 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
499 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
500 | + : false; |
|
501 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
502 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
503 | + : false; |
|
504 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
505 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
506 | + : false; |
|
507 | + if ($state_country && $state_name && $state_abbr) { |
|
508 | + $new_state = EED_Add_New_State::save_new_state_to_db( |
|
509 | + array( |
|
510 | + 'CNT_ISO' => strtoupper($state_country), |
|
511 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
512 | + 'STA_name' => ucwords($state_name), |
|
513 | + 'STA_active' => false, |
|
514 | + ) |
|
515 | + ); |
|
516 | + if ($new_state instanceof EE_State) { |
|
517 | + // clean house |
|
518 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
519 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
520 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
521 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
522 | + // get any existing new states |
|
523 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
524 | + 'nsmf_new_states' |
|
525 | + ); |
|
526 | + $new_states[ $new_state->ID() ] = $new_state; |
|
527 | + EE_Registry::instance()->SSN->set_session_data( |
|
528 | + array('nsmf_new_states' => $new_states) |
|
529 | + ); |
|
530 | + if (EE_Registry::instance()->REQ->ajax) { |
|
531 | + echo wp_json_encode( |
|
532 | + array( |
|
533 | + 'success' => true, |
|
534 | + 'id' => $new_state->ID(), |
|
535 | + 'name' => $new_state->name(), |
|
536 | + 'abbrev' => $new_state->abbrev(), |
|
537 | + 'country_iso' => $new_state->country_iso(), |
|
538 | + 'country_name' => $new_state->country()->name(), |
|
539 | + ) |
|
540 | + ); |
|
541 | + exit(); |
|
542 | + } |
|
543 | + return $new_state->ID(); |
|
544 | + } |
|
545 | + } else { |
|
546 | + $error = esc_html__( |
|
547 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
548 | + 'event_espresso' |
|
549 | + ); |
|
550 | + if (EE_Registry::instance()->REQ->ajax) { |
|
551 | + echo wp_json_encode(array('error' => $error)); |
|
552 | + exit(); |
|
553 | + } |
|
554 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
555 | + } |
|
556 | + } |
|
557 | + return false; |
|
558 | + } |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * recursively drills down through request params to remove any that were added by this module |
|
563 | + * |
|
564 | + * @param array $request_params |
|
565 | + * @return array |
|
566 | + */ |
|
567 | + public static function filter_checkout_request_params($request_params) |
|
568 | + { |
|
569 | + foreach ($request_params as $form_section) { |
|
570 | + if (is_array($form_section)) { |
|
571 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
572 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
573 | + } |
|
574 | + } |
|
575 | + return $request_params; |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * @param array $request_params |
|
581 | + * @return array |
|
582 | + */ |
|
583 | + public static function unset_new_state_request_params($request_params) |
|
584 | + { |
|
585 | + unset( |
|
586 | + $request_params['new_state_micro_form'], |
|
587 | + $request_params['new_state_micro_add_new_state'], |
|
588 | + $request_params['new_state_micro_new_state_country'], |
|
589 | + $request_params['new_state_micro_new_state_name'], |
|
590 | + $request_params['new_state_micro_new_state_abbrv'] |
|
591 | + ); |
|
592 | + return $request_params; |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + /** |
|
597 | + * @param array $props_n_values |
|
598 | + * @return bool |
|
599 | + * @throws EE_Error |
|
600 | + * @throws InvalidArgumentException |
|
601 | + * @throws InvalidDataTypeException |
|
602 | + * @throws InvalidInterfaceException |
|
603 | + */ |
|
604 | + public static function save_new_state_to_db($props_n_values = array()) |
|
605 | + { |
|
606 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
607 | + if (! empty($existing_state)) { |
|
608 | + return array_pop($existing_state); |
|
609 | + } |
|
610 | + $new_state = EE_State::new_instance($props_n_values); |
|
611 | + if ($new_state instanceof EE_State) { |
|
612 | + $country_settings_url = add_query_arg( |
|
613 | + array( |
|
614 | + 'page' => 'espresso_general_settings', |
|
615 | + 'action' => 'country_settings', |
|
616 | + 'country' => $new_state->country_iso(), |
|
617 | + ), |
|
618 | + admin_url('admin.php') |
|
619 | + ); |
|
620 | + // if not non-ajax admin |
|
621 | + new PersistentAdminNotice( |
|
622 | + 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
623 | + sprintf( |
|
624 | + esc_html__( |
|
625 | + 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
626 | + 'event_espresso' |
|
627 | + ), |
|
628 | + '<b>' . $new_state->name() . '</b>', |
|
629 | + '<b>' . $new_state->abbrev() . '</b>', |
|
630 | + '<b>' . $new_state->country()->name() . '</b>', |
|
631 | + '<a href="' |
|
632 | + . $country_settings_url |
|
633 | + . '">' |
|
634 | + . esc_html__( |
|
635 | + 'Event Espresso - General Settings > Countries Tab', |
|
636 | + 'event_espresso' |
|
637 | + ) |
|
638 | + . '</a>', |
|
639 | + '<br />' |
|
640 | + ) |
|
641 | + ); |
|
642 | + $new_state->save(); |
|
643 | + EEM_State::instance()->reset_cached_states(); |
|
644 | + return $new_state; |
|
645 | + } |
|
646 | + return false; |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * @param string $CNT_ISO |
|
652 | + * @param string $STA_ID |
|
653 | + * @param array $cols_n_values |
|
654 | + * @return void |
|
655 | + * @throws DomainException |
|
656 | + * @throws EE_Error |
|
657 | + * @throws InvalidArgumentException |
|
658 | + * @throws InvalidDataTypeException |
|
659 | + * @throws InvalidInterfaceException |
|
660 | + */ |
|
661 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
662 | + { |
|
663 | + if (! $CNT_ISO) { |
|
664 | + EE_Error::add_error( |
|
665 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
666 | + __FILE__, |
|
667 | + __FUNCTION__, |
|
668 | + __LINE__ |
|
669 | + ); |
|
670 | + } |
|
671 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
672 | + : false; |
|
673 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
674 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
675 | + if ($state instanceof EE_State) { |
|
676 | + $STA_abbrev = $state->abbrev(); |
|
677 | + } |
|
678 | + } |
|
679 | + if (! $STA_abbrev) { |
|
680 | + EE_Error::add_error( |
|
681 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
682 | + __FILE__, |
|
683 | + __FUNCTION__, |
|
684 | + __LINE__ |
|
685 | + ); |
|
686 | + } |
|
687 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
688 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
689 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
690 | + ); |
|
691 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
692 | + } |
|
693 | + |
|
694 | + |
|
695 | + /** |
|
696 | + * @param EE_State[] $state_options |
|
697 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
698 | + * @param EE_Registration $registration |
|
699 | + * @param EE_Question $question |
|
700 | + * @param $answer |
|
701 | + * @return array |
|
702 | + * @throws EE_Error |
|
703 | + * @throws InvalidArgumentException |
|
704 | + * @throws InvalidDataTypeException |
|
705 | + * @throws InvalidInterfaceException |
|
706 | + */ |
|
707 | + public static function inject_new_reg_state_into_options( |
|
708 | + $state_options = array(), |
|
709 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
710 | + EE_Registration $registration, |
|
711 | + EE_Question $question, |
|
712 | + $answer |
|
713 | + ) { |
|
714 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
715 | + && $question->type() === EEM_Question::QST_type_state |
|
716 | + ) { |
|
717 | + $STA_ID = $answer->value(); |
|
718 | + if (! empty($STA_ID)) { |
|
719 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
720 | + if ($state instanceof EE_State) { |
|
721 | + $country = $state->country(); |
|
722 | + if ($country instanceof EE_Country) { |
|
723 | + if (! isset($state_options[ $country->name() ])) { |
|
724 | + $state_options[ $country->name() ] = array(); |
|
725 | + } |
|
726 | + if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
727 | + $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
728 | + } |
|
729 | + } |
|
730 | + } |
|
731 | + } |
|
732 | + } |
|
733 | + return $state_options; |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + /** |
|
738 | + * @param EE_Country[] $country_options |
|
739 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
740 | + * @param EE_Registration $registration |
|
741 | + * @param EE_Question $question |
|
742 | + * @param $answer |
|
743 | + * @return array |
|
744 | + * @throws EE_Error |
|
745 | + * @throws InvalidArgumentException |
|
746 | + * @throws InvalidDataTypeException |
|
747 | + * @throws InvalidInterfaceException |
|
748 | + */ |
|
749 | + public static function inject_new_reg_country_into_options( |
|
750 | + $country_options = array(), |
|
751 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
752 | + EE_Registration $registration, |
|
753 | + EE_Question $question, |
|
754 | + $answer |
|
755 | + ) { |
|
756 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
757 | + && $question->type() |
|
758 | + === EEM_Question::QST_type_country |
|
759 | + ) { |
|
760 | + $CNT_ISO = $answer->value(); |
|
761 | + if (! empty($CNT_ISO)) { |
|
762 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
763 | + if ($country instanceof EE_Country) { |
|
764 | + if (! isset($country_options[ $CNT_ISO ])) { |
|
765 | + $country_options[ $CNT_ISO ] = $country->name(); |
|
766 | + } |
|
767 | + } |
|
768 | + } |
|
769 | + } |
|
770 | + return $country_options; |
|
771 | + } |
|
772 | + |
|
773 | + |
|
774 | + /** |
|
775 | + * @param EE_State[] $state_options |
|
776 | + * @return array |
|
777 | + * @throws EE_Error |
|
778 | + * @throws InvalidArgumentException |
|
779 | + * @throws InvalidDataTypeException |
|
780 | + * @throws InvalidInterfaceException |
|
781 | + */ |
|
782 | + public static function state_options($state_options = array()) |
|
783 | + { |
|
784 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
785 | + foreach ($new_states as $new_state) { |
|
786 | + if ($new_state instanceof EE_State |
|
787 | + && $new_state->country() instanceof EE_Country |
|
788 | + ) { |
|
789 | + $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
790 | + } |
|
791 | + } |
|
792 | + return $state_options; |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * @return array |
|
798 | + * @throws InvalidArgumentException |
|
799 | + * @throws InvalidDataTypeException |
|
800 | + * @throws InvalidInterfaceException |
|
801 | + */ |
|
802 | + protected static function _get_new_states() |
|
803 | + { |
|
804 | + $new_states = array(); |
|
805 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
806 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
807 | + 'nsmf_new_states' |
|
808 | + ); |
|
809 | + } |
|
810 | + return is_array($new_states) ? $new_states : array(); |
|
811 | + } |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * @param EE_Country[] $country_options |
|
816 | + * @return array |
|
817 | + * @throws EE_Error |
|
818 | + * @throws InvalidArgumentException |
|
819 | + * @throws InvalidDataTypeException |
|
820 | + * @throws InvalidInterfaceException |
|
821 | + */ |
|
822 | + public static function country_options($country_options = array()) |
|
823 | + { |
|
824 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
825 | + foreach ($new_states as $new_state) { |
|
826 | + if ($new_state instanceof EE_State |
|
827 | + && $new_state->country() instanceof EE_Country |
|
828 | + ) { |
|
829 | + $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
830 | + } |
|
831 | + } |
|
832 | + return $country_options; |
|
833 | + } |
|
834 | 834 | } |
@@ -159,14 +159,14 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public static function set_definitions() |
161 | 161 | { |
162 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
162 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
163 | 163 | define( |
164 | 164 | 'ANS_TEMPLATES_PATH', |
165 | 165 | str_replace( |
166 | 166 | '\\', |
167 | 167 | DS, |
168 | 168 | plugin_dir_path(__FILE__) |
169 | - ) . 'templates' . DS |
|
169 | + ).'templates'.DS |
|
170 | 170 | ); |
171 | 171 | } |
172 | 172 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
217 | 217 | wp_register_script( |
218 | 218 | 'add_new_state', |
219 | - ANS_ASSETS_URL . 'add_new_state.js', |
|
219 | + ANS_ASSETS_URL.'add_new_state.js', |
|
220 | 220 | array('espresso_core', 'single_page_checkout'), |
221 | 221 | EVENT_ESPRESSO_VERSION, |
222 | 222 | true |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
264 | 264 | $country_options = array(); |
265 | 265 | $countries = EEM_Country::instance()->get_all_countries(); |
266 | - if (! empty($countries)) { |
|
266 | + if ( ! empty($countries)) { |
|
267 | 267 | foreach ($countries as $country) { |
268 | 268 | if ($country instanceof EE_Country) { |
269 | - $country_options[ $country->ID() ] = $country->name(); |
|
269 | + $country_options[$country->ID()] = $country->name(); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | } |
@@ -300,10 +300,10 @@ discard block |
||
300 | 300 | '', |
301 | 301 | esc_html__('click here to add a new state/province', 'event_espresso'), |
302 | 302 | '', |
303 | - 'display-' . $input->html_id(), |
|
303 | + 'display-'.$input->html_id(), |
|
304 | 304 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
305 | 305 | '', |
306 | - 'data-target="' . $input->html_id() . '"' |
|
306 | + 'data-target="'.$input->html_id().'"' |
|
307 | 307 | ) |
308 | 308 | ) |
309 | 309 | ), |
@@ -313,33 +313,33 @@ discard block |
||
313 | 313 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
314 | 314 | EEH_HTML::div( |
315 | 315 | '', |
316 | - $input->html_id() . '-dv', |
|
316 | + $input->html_id().'-dv', |
|
317 | 317 | 'ee-form-add-new-state-dv', |
318 | 318 | 'display: none;' |
319 | - ) . |
|
319 | + ). |
|
320 | 320 | EEH_HTML::h6( |
321 | 321 | esc_html__( |
322 | 322 | 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
323 | 323 | 'event_espresso' |
324 | 324 | ) |
325 | - ) . |
|
326 | - EEH_HTML::ul() . |
|
325 | + ). |
|
326 | + EEH_HTML::ul(). |
|
327 | 327 | EEH_HTML::li( |
328 | 328 | esc_html__( |
329 | 329 | 'first select the Country that your State/Province belongs to', |
330 | 330 | 'event_espresso' |
331 | 331 | ) |
332 | - ) . |
|
332 | + ). |
|
333 | 333 | EEH_HTML::li( |
334 | 334 | esc_html__('enter the name of your State/Province', 'event_espresso') |
335 | - ) . |
|
335 | + ). |
|
336 | 336 | EEH_HTML::li( |
337 | 337 | esc_html__( |
338 | 338 | 'enter a two to six letter abbreviation for the name of your State/Province', |
339 | 339 | 'event_espresso' |
340 | 340 | ) |
341 | - ) . |
|
342 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
341 | + ). |
|
342 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')). |
|
343 | 343 | EEH_HTML::ulx() |
344 | 344 | ) |
345 | 345 | ), |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | 'nsmf_new_state_country', |
354 | 354 | $input->html_id() |
355 | 355 | ), |
356 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
356 | + 'html_class' => $input->html_class().' new-state-country', |
|
357 | 357 | 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
358 | 358 | 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
359 | 359 | 'required' => false, |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | 'nsmf_new_state_name', |
369 | 369 | $input->html_id() |
370 | 370 | ), |
371 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
371 | + 'html_class' => $input->html_class().' new-state-state', |
|
372 | 372 | 'html_label_text' => esc_html__( |
373 | 373 | 'New State/Province Name', |
374 | 374 | 'event_espresso' |
@@ -387,11 +387,11 @@ discard block |
||
387 | 387 | 'nsmf_new_state_abbrv', |
388 | 388 | $input->html_id() |
389 | 389 | ), |
390 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
390 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
391 | 391 | 'html_label_text' => esc_html__( |
392 | 392 | 'New State/Province Abbreviation', |
393 | 393 | 'event_espresso' |
394 | - ) . ' *', |
|
394 | + ).' *', |
|
395 | 395 | 'html_other_attributes' => 'size="24"', |
396 | 396 | 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
397 | 397 | 'required' => false, |
@@ -401,15 +401,15 @@ discard block |
||
401 | 401 | 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
402 | 402 | apply_filters( |
403 | 403 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
404 | - EEH_HTML::nbsp(3) . |
|
404 | + EEH_HTML::nbsp(3). |
|
405 | 405 | EEH_HTML::link( |
406 | 406 | '', |
407 | 407 | esc_html__('ADD', 'event_espresso'), |
408 | 408 | '', |
409 | - 'submit-' . $new_state_submit_id, |
|
409 | + 'submit-'.$new_state_submit_id, |
|
410 | 410 | 'ee-form-add-new-state-submit button button-secondary', |
411 | 411 | '', |
412 | - 'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"' |
|
412 | + 'data-target="'.$new_state_submit_id.'" data-value-field-name="'.$input->valueFieldName().'"' |
|
413 | 413 | ) |
414 | 414 | ) |
415 | 415 | ), |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | EEH_HTML::div('', '', 'small-text') |
423 | 423 | . |
424 | 424 | EEH_HTML::strong( |
425 | - '* ' . |
|
425 | + '* '. |
|
426 | 426 | esc_html__( |
427 | 427 | 'Don\'t know your State/Province Abbreviation?', |
428 | 428 | 'event_espresso' |
@@ -455,10 +455,10 @@ discard block |
||
455 | 455 | '', |
456 | 456 | esc_html__('cancel new State/Province', 'event_espresso'), |
457 | 457 | '', |
458 | - 'hide-' . $input->html_id(), |
|
458 | + 'hide-'.$input->html_id(), |
|
459 | 459 | 'ee-form-cancel-new-state-lnk smaller-text', |
460 | 460 | '', |
461 | - 'data-target="' . $input->html_id() . '"' |
|
461 | + 'data-target="'.$input->html_id().'"' |
|
462 | 462 | ) |
463 | 463 | . |
464 | 464 | EEH_HTML::divx() |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | $new_states = EE_Registry::instance()->SSN->get_session_data( |
524 | 524 | 'nsmf_new_states' |
525 | 525 | ); |
526 | - $new_states[ $new_state->ID() ] = $new_state; |
|
526 | + $new_states[$new_state->ID()] = $new_state; |
|
527 | 527 | EE_Registry::instance()->SSN->set_session_data( |
528 | 528 | array('nsmf_new_states' => $new_states) |
529 | 529 | ); |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | public static function save_new_state_to_db($props_n_values = array()) |
605 | 605 | { |
606 | 606 | $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
607 | - if (! empty($existing_state)) { |
|
607 | + if ( ! empty($existing_state)) { |
|
608 | 608 | return array_pop($existing_state); |
609 | 609 | } |
610 | 610 | $new_state = EE_State::new_instance($props_n_values); |
@@ -619,15 +619,15 @@ discard block |
||
619 | 619 | ); |
620 | 620 | // if not non-ajax admin |
621 | 621 | new PersistentAdminNotice( |
622 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
622 | + 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(), |
|
623 | 623 | sprintf( |
624 | 624 | esc_html__( |
625 | 625 | 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
626 | 626 | 'event_espresso' |
627 | 627 | ), |
628 | - '<b>' . $new_state->name() . '</b>', |
|
629 | - '<b>' . $new_state->abbrev() . '</b>', |
|
630 | - '<b>' . $new_state->country()->name() . '</b>', |
|
628 | + '<b>'.$new_state->name().'</b>', |
|
629 | + '<b>'.$new_state->abbrev().'</b>', |
|
630 | + '<b>'.$new_state->country()->name().'</b>', |
|
631 | 631 | '<a href="' |
632 | 632 | . $country_settings_url |
633 | 633 | . '">' |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | */ |
661 | 661 | public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
662 | 662 | { |
663 | - if (! $CNT_ISO) { |
|
663 | + if ( ! $CNT_ISO) { |
|
664 | 664 | EE_Error::add_error( |
665 | 665 | esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
666 | 666 | __FILE__, |
@@ -670,13 +670,13 @@ discard block |
||
670 | 670 | } |
671 | 671 | $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
672 | 672 | : false; |
673 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
673 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
674 | 674 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
675 | 675 | if ($state instanceof EE_State) { |
676 | 676 | $STA_abbrev = $state->abbrev(); |
677 | 677 | } |
678 | 678 | } |
679 | - if (! $STA_abbrev) { |
|
679 | + if ( ! $STA_abbrev) { |
|
680 | 680 | EE_Error::add_error( |
681 | 681 | esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
682 | 682 | __FILE__, |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
689 | 689 | 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
690 | 690 | ); |
691 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
691 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO.'-'.$STA_abbrev, true, true); |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | |
@@ -715,16 +715,16 @@ discard block |
||
715 | 715 | && $question->type() === EEM_Question::QST_type_state |
716 | 716 | ) { |
717 | 717 | $STA_ID = $answer->value(); |
718 | - if (! empty($STA_ID)) { |
|
718 | + if ( ! empty($STA_ID)) { |
|
719 | 719 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
720 | 720 | if ($state instanceof EE_State) { |
721 | 721 | $country = $state->country(); |
722 | 722 | if ($country instanceof EE_Country) { |
723 | - if (! isset($state_options[ $country->name() ])) { |
|
724 | - $state_options[ $country->name() ] = array(); |
|
723 | + if ( ! isset($state_options[$country->name()])) { |
|
724 | + $state_options[$country->name()] = array(); |
|
725 | 725 | } |
726 | - if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
727 | - $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
726 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
727 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
728 | 728 | } |
729 | 729 | } |
730 | 730 | } |
@@ -758,11 +758,11 @@ discard block |
||
758 | 758 | === EEM_Question::QST_type_country |
759 | 759 | ) { |
760 | 760 | $CNT_ISO = $answer->value(); |
761 | - if (! empty($CNT_ISO)) { |
|
761 | + if ( ! empty($CNT_ISO)) { |
|
762 | 762 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
763 | 763 | if ($country instanceof EE_Country) { |
764 | - if (! isset($country_options[ $CNT_ISO ])) { |
|
765 | - $country_options[ $CNT_ISO ] = $country->name(); |
|
764 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
765 | + $country_options[$CNT_ISO] = $country->name(); |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | } |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | if ($new_state instanceof EE_State |
787 | 787 | && $new_state->country() instanceof EE_Country |
788 | 788 | ) { |
789 | - $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
789 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
790 | 790 | } |
791 | 791 | } |
792 | 792 | return $state_options; |
@@ -826,7 +826,7 @@ discard block |
||
826 | 826 | if ($new_state instanceof EE_State |
827 | 827 | && $new_state->country() instanceof EE_Country |
828 | 828 | ) { |
829 | - $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
829 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
830 | 830 | } |
831 | 831 | } |
832 | 832 | return $country_options; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | { |
37 | 37 | if (isset($input_settings['value_field_name'])) { |
38 | 38 | $this->valueFieldName = $input_settings['value_field_name']; |
39 | - if (! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
39 | + if ( ! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
40 | 40 | throw new InvalidArgumentException( |
41 | 41 | sprintf( |
42 | 42 | esc_html__('An invalid state field "%1$s" was specified for the state input\'s option values.', 'event_espresso'), |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $this |
54 | 54 | ); |
55 | 55 | $input_settings['html_class'] = isset($input_settings['html_class']) |
56 | - ? $input_settings['html_class'] . ' ee-state-select-js' |
|
56 | + ? $input_settings['html_class'].' ee-state-select-js' |
|
57 | 57 | : 'ee-state-select-js'; |
58 | 58 | parent::__construct($state_options, $input_settings); |
59 | 59 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | public function get_state_answer_options($state_options = null) |
84 | 84 | { |
85 | 85 | // if passed something that is NOT an array |
86 | - if (! is_array($state_options) || empty($state_options)) { |
|
86 | + if ( ! is_array($state_options) || empty($state_options)) { |
|
87 | 87 | // get possibly cached list of states |
88 | 88 | $states = EEM_State::instance()->get_all_active_states(); |
89 | 89 | } |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | $states = $state_options; |
92 | 92 | $state_options = array(); |
93 | 93 | } |
94 | - if (! empty($states)) { |
|
94 | + if ( ! empty($states)) { |
|
95 | 95 | // set the default |
96 | 96 | $state_options[''][''] = ''; |
97 | 97 | foreach ($states as $state) { |
98 | 98 | if ($state instanceof EE_State) { |
99 | - $state_options[ $state->country()->name() ][ $state->get($this->valueFieldName()) ] = $state->name(); |
|
99 | + $state_options[$state->country()->name()][$state->get($this->valueFieldName())] = $state->name(); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
@@ -12,94 +12,94 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_State_Select_Input extends EE_Select_Input |
14 | 14 | { |
15 | - /** |
|
16 | - * @var string the name of the EE_State field to use for option values in the HTML form input. |
|
17 | - */ |
|
18 | - protected $valueFieldName; |
|
15 | + /** |
|
16 | + * @var string the name of the EE_State field to use for option values in the HTML form input. |
|
17 | + */ |
|
18 | + protected $valueFieldName; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @param EE_State[]|array|null $state_options. If a flat array of string is provided, |
|
22 | - * $input_settings['value_field_name'] is ignored. If an array of states is passed, that field will be used for |
|
23 | - * the keys (which will become the option values). If null or empty is passed, all active states will be used, |
|
24 | - * and $input_settings['value_field_name'] will again be used. * |
|
25 | - * @param array $input_settings same as parent, but also { |
|
26 | - * @type string $value_field_name the name of the field to use |
|
27 | - * for the HTML option values, ie, `STA_ID`, `STA_abbrev`, or `STA_name`. |
|
28 | - * } |
|
29 | - * @throws EE_Error |
|
30 | - * @throws InvalidArgumentException |
|
31 | - * @throws InvalidDataTypeException |
|
32 | - * @throws InvalidInterfaceException |
|
33 | - * @throws ReflectionException |
|
34 | - */ |
|
35 | - public function __construct($state_options, $input_settings = array()) |
|
36 | - { |
|
37 | - if (isset($input_settings['value_field_name'])) { |
|
38 | - $this->valueFieldName = $input_settings['value_field_name']; |
|
39 | - if (! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
40 | - throw new InvalidArgumentException( |
|
41 | - sprintf( |
|
42 | - esc_html__('An invalid state field "%1$s" was specified for the state input\'s option values.', 'event_espresso'), |
|
43 | - $this->valueFieldName() |
|
44 | - ) |
|
45 | - ); |
|
46 | - } |
|
47 | - } else { |
|
48 | - $this->valueFieldName = 'STA_ID'; |
|
49 | - } |
|
50 | - $state_options = apply_filters( |
|
51 | - 'FHEE__EE_State_Select_Input____construct__state_options', |
|
52 | - $this->get_state_answer_options($state_options), |
|
53 | - $this |
|
54 | - ); |
|
55 | - $input_settings['html_class'] = isset($input_settings['html_class']) |
|
56 | - ? $input_settings['html_class'] . ' ee-state-select-js' |
|
57 | - : 'ee-state-select-js'; |
|
58 | - parent::__construct($state_options, $input_settings); |
|
59 | - } |
|
20 | + /** |
|
21 | + * @param EE_State[]|array|null $state_options. If a flat array of string is provided, |
|
22 | + * $input_settings['value_field_name'] is ignored. If an array of states is passed, that field will be used for |
|
23 | + * the keys (which will become the option values). If null or empty is passed, all active states will be used, |
|
24 | + * and $input_settings['value_field_name'] will again be used. * |
|
25 | + * @param array $input_settings same as parent, but also { |
|
26 | + * @type string $value_field_name the name of the field to use |
|
27 | + * for the HTML option values, ie, `STA_ID`, `STA_abbrev`, or `STA_name`. |
|
28 | + * } |
|
29 | + * @throws EE_Error |
|
30 | + * @throws InvalidArgumentException |
|
31 | + * @throws InvalidDataTypeException |
|
32 | + * @throws InvalidInterfaceException |
|
33 | + * @throws ReflectionException |
|
34 | + */ |
|
35 | + public function __construct($state_options, $input_settings = array()) |
|
36 | + { |
|
37 | + if (isset($input_settings['value_field_name'])) { |
|
38 | + $this->valueFieldName = $input_settings['value_field_name']; |
|
39 | + if (! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
40 | + throw new InvalidArgumentException( |
|
41 | + sprintf( |
|
42 | + esc_html__('An invalid state field "%1$s" was specified for the state input\'s option values.', 'event_espresso'), |
|
43 | + $this->valueFieldName() |
|
44 | + ) |
|
45 | + ); |
|
46 | + } |
|
47 | + } else { |
|
48 | + $this->valueFieldName = 'STA_ID'; |
|
49 | + } |
|
50 | + $state_options = apply_filters( |
|
51 | + 'FHEE__EE_State_Select_Input____construct__state_options', |
|
52 | + $this->get_state_answer_options($state_options), |
|
53 | + $this |
|
54 | + ); |
|
55 | + $input_settings['html_class'] = isset($input_settings['html_class']) |
|
56 | + ? $input_settings['html_class'] . ' ee-state-select-js' |
|
57 | + : 'ee-state-select-js'; |
|
58 | + parent::__construct($state_options, $input_settings); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Returns the name of the state field used for the HTML option values. |
|
63 | - * @since $VID:$ |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - public function valueFieldName() |
|
67 | - { |
|
68 | - return $this->valueFieldName; |
|
69 | - } |
|
61 | + /** |
|
62 | + * Returns the name of the state field used for the HTML option values. |
|
63 | + * @since $VID:$ |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + public function valueFieldName() |
|
67 | + { |
|
68 | + return $this->valueFieldName; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * get_state_answer_options |
|
74 | - * |
|
75 | - * @param array $state_options |
|
76 | - * @return array |
|
77 | - * @throws EE_Error |
|
78 | - * @throws InvalidArgumentException |
|
79 | - * @throws ReflectionException |
|
80 | - * @throws InvalidDataTypeException |
|
81 | - * @throws InvalidInterfaceException |
|
82 | - */ |
|
83 | - public function get_state_answer_options($state_options = null) |
|
84 | - { |
|
85 | - // if passed something that is NOT an array |
|
86 | - if (! is_array($state_options) || empty($state_options)) { |
|
87 | - // get possibly cached list of states |
|
88 | - $states = EEM_State::instance()->get_all_active_states(); |
|
89 | - } |
|
90 | - if (is_array($state_options) && reset($state_options) instanceof EE_State) { |
|
91 | - $states = $state_options; |
|
92 | - $state_options = array(); |
|
93 | - } |
|
94 | - if (! empty($states)) { |
|
95 | - // set the default |
|
96 | - $state_options[''][''] = ''; |
|
97 | - foreach ($states as $state) { |
|
98 | - if ($state instanceof EE_State) { |
|
99 | - $state_options[ $state->country()->name() ][ $state->get($this->valueFieldName()) ] = $state->name(); |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - return $state_options; |
|
104 | - } |
|
72 | + /** |
|
73 | + * get_state_answer_options |
|
74 | + * |
|
75 | + * @param array $state_options |
|
76 | + * @return array |
|
77 | + * @throws EE_Error |
|
78 | + * @throws InvalidArgumentException |
|
79 | + * @throws ReflectionException |
|
80 | + * @throws InvalidDataTypeException |
|
81 | + * @throws InvalidInterfaceException |
|
82 | + */ |
|
83 | + public function get_state_answer_options($state_options = null) |
|
84 | + { |
|
85 | + // if passed something that is NOT an array |
|
86 | + if (! is_array($state_options) || empty($state_options)) { |
|
87 | + // get possibly cached list of states |
|
88 | + $states = EEM_State::instance()->get_all_active_states(); |
|
89 | + } |
|
90 | + if (is_array($state_options) && reset($state_options) instanceof EE_State) { |
|
91 | + $states = $state_options; |
|
92 | + $state_options = array(); |
|
93 | + } |
|
94 | + if (! empty($states)) { |
|
95 | + // set the default |
|
96 | + $state_options[''][''] = ''; |
|
97 | + foreach ($states as $state) { |
|
98 | + if ($state instanceof EE_State) { |
|
99 | + $state_options[ $state->country()->name() ][ $state->get($this->valueFieldName()) ] = $state->name(); |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + return $state_options; |
|
104 | + } |
|
105 | 105 | } |
@@ -14,172 +14,172 @@ |
||
14 | 14 | class EE_Billing_Attendee_Info_Form extends EE_Billing_Info_Form |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * |
|
19 | - * @param EE_Payment_Method $payment_method |
|
20 | - * @param array $options_array @see EE_Form_Section_Proper::__construct() |
|
21 | - */ |
|
22 | - public function __construct(EE_Payment_Method $payment_method, $options_array = array()) |
|
23 | - { |
|
24 | - $options_array['subsections'] = array_merge( |
|
25 | - array( |
|
26 | - 'first_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => __('First Name', 'event_espresso') )), |
|
27 | - 'last_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => __('Last Name', 'event_espresso') )), |
|
28 | - 'email' => new EE_Email_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => __('Email', 'event_espresso') )), |
|
29 | - 'address' => new EE_Text_Input(array( 'html_label_text'=> __('Address', 'event_espresso'), 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )), |
|
30 | - 'address2' => new EE_Text_Input(array( 'html_label_text'=> __('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )), |
|
31 | - 'city' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => __('City', 'event_espresso') )), |
|
32 | - 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => __('State', 'event_espresso') ))), |
|
33 | - 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => __('Country', 'event_espresso') ))), |
|
34 | - 'zip' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => __('Zip', 'event_espresso') )), |
|
35 | - 'phone' => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => __('Phone', 'event_espresso') )), |
|
36 | - ), |
|
37 | - isset($options_array['subsections']) ? $options_array['subsections'] : array() |
|
38 | - ); |
|
17 | + /** |
|
18 | + * |
|
19 | + * @param EE_Payment_Method $payment_method |
|
20 | + * @param array $options_array @see EE_Form_Section_Proper::__construct() |
|
21 | + */ |
|
22 | + public function __construct(EE_Payment_Method $payment_method, $options_array = array()) |
|
23 | + { |
|
24 | + $options_array['subsections'] = array_merge( |
|
25 | + array( |
|
26 | + 'first_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => __('First Name', 'event_espresso') )), |
|
27 | + 'last_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => __('Last Name', 'event_espresso') )), |
|
28 | + 'email' => new EE_Email_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => __('Email', 'event_espresso') )), |
|
29 | + 'address' => new EE_Text_Input(array( 'html_label_text'=> __('Address', 'event_espresso'), 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )), |
|
30 | + 'address2' => new EE_Text_Input(array( 'html_label_text'=> __('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )), |
|
31 | + 'city' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => __('City', 'event_espresso') )), |
|
32 | + 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => __('State', 'event_espresso') ))), |
|
33 | + 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => __('Country', 'event_espresso') ))), |
|
34 | + 'zip' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => __('Zip', 'event_espresso') )), |
|
35 | + 'phone' => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => __('Phone', 'event_espresso') )), |
|
36 | + ), |
|
37 | + isset($options_array['subsections']) ? $options_array['subsections'] : array() |
|
38 | + ); |
|
39 | 39 | |
40 | - parent::__construct($payment_method, $options_array); |
|
41 | - } |
|
40 | + parent::__construct($payment_method, $options_array); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Sets the defaults for the billing form according to the attendee's details |
|
45 | - * @param EE_Attendee $attendee |
|
46 | - */ |
|
47 | - public function populate_from_attendee($attendee) |
|
48 | - { |
|
49 | - $attendee = EEM_Attendee::instance()->ensure_is_obj($attendee); |
|
43 | + /** |
|
44 | + * Sets the defaults for the billing form according to the attendee's details |
|
45 | + * @param EE_Attendee $attendee |
|
46 | + */ |
|
47 | + public function populate_from_attendee($attendee) |
|
48 | + { |
|
49 | + $attendee = EEM_Attendee::instance()->ensure_is_obj($attendee); |
|
50 | 50 | |
51 | - /** @var $attendee EE_Attendee */ |
|
52 | - $this->populate_defaults( |
|
53 | - apply_filters( |
|
54 | - 'FHEE__EE_Billing_Attendee_Info_Form__populate_from_attendee', |
|
55 | - array( |
|
56 | - 'first_name'=>$attendee->fname(), |
|
57 | - 'last_name'=>$attendee->lname(), |
|
58 | - 'email'=>$attendee->email(), |
|
59 | - 'address'=>$attendee->address(), |
|
60 | - 'address2'=>$attendee->address2(), |
|
61 | - 'city'=>$attendee->city(), |
|
62 | - 'state'=> $this->getAttendeeStateValueForForm($attendee), |
|
63 | - 'country'=> $attendee->country_ID(), |
|
64 | - 'zip'=>$attendee->zip(), |
|
65 | - 'phone'=>$attendee->phone(), |
|
66 | - ), |
|
67 | - $attendee, |
|
68 | - $this |
|
69 | - ) |
|
70 | - ); |
|
71 | - } |
|
51 | + /** @var $attendee EE_Attendee */ |
|
52 | + $this->populate_defaults( |
|
53 | + apply_filters( |
|
54 | + 'FHEE__EE_Billing_Attendee_Info_Form__populate_from_attendee', |
|
55 | + array( |
|
56 | + 'first_name'=>$attendee->fname(), |
|
57 | + 'last_name'=>$attendee->lname(), |
|
58 | + 'email'=>$attendee->email(), |
|
59 | + 'address'=>$attendee->address(), |
|
60 | + 'address2'=>$attendee->address2(), |
|
61 | + 'city'=>$attendee->city(), |
|
62 | + 'state'=> $this->getAttendeeStateValueForForm($attendee), |
|
63 | + 'country'=> $attendee->country_ID(), |
|
64 | + 'zip'=>$attendee->zip(), |
|
65 | + 'phone'=>$attendee->phone(), |
|
66 | + ), |
|
67 | + $attendee, |
|
68 | + $this |
|
69 | + ) |
|
70 | + ); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Gets the default value to use for the billing form's state value. |
|
75 | - * @since $VID:$ |
|
76 | - * @param EE_Attendee $attendee |
|
77 | - * @return string |
|
78 | - * @throws EE_Error2 |
|
79 | - */ |
|
80 | - protected function getAttendeeStateValueForForm(EE_Attendee $attendee) |
|
81 | - { |
|
82 | - // If the state input was removed, just return a blank string. |
|
83 | - if (! $this->has_subsection('state')) { |
|
84 | - return ''; |
|
85 | - } |
|
86 | - $state_input = $this->get_input('state', false); |
|
87 | - if ($state_input instanceof EE_State_Select_Input) { |
|
88 | - $state_field_to_use = $state_input->valueFieldName(); |
|
89 | - } else { |
|
90 | - $state_field_to_use = 'STA_ID'; |
|
91 | - } |
|
92 | - switch ($state_field_to_use) { |
|
93 | - case 'STA_abbrev': |
|
94 | - $state_value = $attendee->state_abbrev(); |
|
95 | - break; |
|
96 | - case 'STA_name': |
|
97 | - $state_value = $attendee->state_name(); |
|
98 | - break; |
|
99 | - default: |
|
100 | - $state_value = $attendee->state_ID(); |
|
101 | - } |
|
102 | - return $state_value; |
|
103 | - } |
|
73 | + /** |
|
74 | + * Gets the default value to use for the billing form's state value. |
|
75 | + * @since $VID:$ |
|
76 | + * @param EE_Attendee $attendee |
|
77 | + * @return string |
|
78 | + * @throws EE_Error2 |
|
79 | + */ |
|
80 | + protected function getAttendeeStateValueForForm(EE_Attendee $attendee) |
|
81 | + { |
|
82 | + // If the state input was removed, just return a blank string. |
|
83 | + if (! $this->has_subsection('state')) { |
|
84 | + return ''; |
|
85 | + } |
|
86 | + $state_input = $this->get_input('state', false); |
|
87 | + if ($state_input instanceof EE_State_Select_Input) { |
|
88 | + $state_field_to_use = $state_input->valueFieldName(); |
|
89 | + } else { |
|
90 | + $state_field_to_use = 'STA_ID'; |
|
91 | + } |
|
92 | + switch ($state_field_to_use) { |
|
93 | + case 'STA_abbrev': |
|
94 | + $state_value = $attendee->state_abbrev(); |
|
95 | + break; |
|
96 | + case 'STA_name': |
|
97 | + $state_value = $attendee->state_name(); |
|
98 | + break; |
|
99 | + default: |
|
100 | + $state_value = $attendee->state_ID(); |
|
101 | + } |
|
102 | + return $state_value; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * copy_billing_form_data_to_attendee |
|
109 | - * copies info from the billing form to the attendee's details |
|
110 | - * @param \EE_Attendee $attendee - the attendee object to copy details to |
|
111 | - * @return \EE_Attendee |
|
112 | - */ |
|
113 | - public function copy_billing_form_data_to_attendee(EE_Attendee $attendee) |
|
114 | - { |
|
115 | - // grab billing form data |
|
116 | - $data = $this->valid_data(); |
|
117 | - // copy first_name |
|
118 | - if (! empty($data['first_name'])) { |
|
119 | - $attendee->set_fname($data['first_name']); |
|
120 | - } |
|
121 | - // copy last_name |
|
122 | - if (! empty($data['last_name'])) { |
|
123 | - $attendee->set_lname($data['last_name']); |
|
124 | - } |
|
125 | - // copy email |
|
126 | - if (! empty($data['email'])) { |
|
127 | - $attendee->set_email($data['email']); |
|
128 | - } |
|
129 | - // copy address |
|
130 | - if (! empty($data['address'])) { |
|
131 | - $attendee->set_address($data['address']); |
|
132 | - } |
|
133 | - // copy address2 |
|
134 | - if (! empty($data['address2'])) { |
|
135 | - $attendee->set_address2($data['address2']); |
|
136 | - } |
|
137 | - // copy city |
|
138 | - if (! empty($data['city'])) { |
|
139 | - $attendee->set_city($data['city']); |
|
140 | - } |
|
141 | - // copy state |
|
142 | - if (! empty($data['state'])) { |
|
143 | - $attendee->set_state($data['state']); |
|
144 | - } |
|
145 | - // copy country |
|
146 | - if (! empty($data['country'])) { |
|
147 | - $attendee->set_country($data['country']); |
|
148 | - } |
|
149 | - // copy zip |
|
150 | - if (! empty($data['zip'])) { |
|
151 | - $attendee->set_zip($data['zip']); |
|
152 | - } |
|
153 | - // copy phone |
|
154 | - if (! empty($data['phone'])) { |
|
155 | - $attendee->set_phone($data['phone']); |
|
156 | - } |
|
157 | - return $attendee; |
|
158 | - } |
|
107 | + /** |
|
108 | + * copy_billing_form_data_to_attendee |
|
109 | + * copies info from the billing form to the attendee's details |
|
110 | + * @param \EE_Attendee $attendee - the attendee object to copy details to |
|
111 | + * @return \EE_Attendee |
|
112 | + */ |
|
113 | + public function copy_billing_form_data_to_attendee(EE_Attendee $attendee) |
|
114 | + { |
|
115 | + // grab billing form data |
|
116 | + $data = $this->valid_data(); |
|
117 | + // copy first_name |
|
118 | + if (! empty($data['first_name'])) { |
|
119 | + $attendee->set_fname($data['first_name']); |
|
120 | + } |
|
121 | + // copy last_name |
|
122 | + if (! empty($data['last_name'])) { |
|
123 | + $attendee->set_lname($data['last_name']); |
|
124 | + } |
|
125 | + // copy email |
|
126 | + if (! empty($data['email'])) { |
|
127 | + $attendee->set_email($data['email']); |
|
128 | + } |
|
129 | + // copy address |
|
130 | + if (! empty($data['address'])) { |
|
131 | + $attendee->set_address($data['address']); |
|
132 | + } |
|
133 | + // copy address2 |
|
134 | + if (! empty($data['address2'])) { |
|
135 | + $attendee->set_address2($data['address2']); |
|
136 | + } |
|
137 | + // copy city |
|
138 | + if (! empty($data['city'])) { |
|
139 | + $attendee->set_city($data['city']); |
|
140 | + } |
|
141 | + // copy state |
|
142 | + if (! empty($data['state'])) { |
|
143 | + $attendee->set_state($data['state']); |
|
144 | + } |
|
145 | + // copy country |
|
146 | + if (! empty($data['country'])) { |
|
147 | + $attendee->set_country($data['country']); |
|
148 | + } |
|
149 | + // copy zip |
|
150 | + if (! empty($data['zip'])) { |
|
151 | + $attendee->set_zip($data['zip']); |
|
152 | + } |
|
153 | + // copy phone |
|
154 | + if (! empty($data['phone'])) { |
|
155 | + $attendee->set_phone($data['phone']); |
|
156 | + } |
|
157 | + return $attendee; |
|
158 | + } |
|
159 | 159 | |
160 | 160 | |
161 | - /** |
|
162 | - * create_attendee_from_billing_form_data |
|
163 | - * uses info from the billing form to create a new attendee |
|
164 | - * @return \EE_Attendee |
|
165 | - */ |
|
166 | - public function create_attendee_from_billing_form_data() |
|
167 | - { |
|
168 | - // grab billing form data |
|
169 | - $data = $this->valid_data(); |
|
170 | - return EE_Attendee::new_instance(array( |
|
171 | - 'ATT_fname' => ! empty($data['first_name']) ? $data['first_name'] : '', |
|
172 | - 'ATT_lname' => ! empty($data['last_name']) ? $data['last_name'] : '', |
|
173 | - 'ATT_email' => ! empty($data['email']) ? $data['email'] : '', |
|
174 | - 'ATT_address' => ! empty($data['address']) ? $data['address'] : '', |
|
175 | - 'ATT_address2' => ! empty($data['address2']) ? $data['address2'] : '', |
|
176 | - 'ATT_city' => ! empty($data['city']) ? $data['city'] : '', |
|
177 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : '', |
|
178 | - 'CNT_ISO' => ! empty($data['country']) ? $data['country'] : '', |
|
179 | - 'ATT_zip' => ! empty($data['zip']) ? $data['zip'] : '', |
|
180 | - 'ATT_phone' => ! empty($data['phone']) ? $data['phone'] : '', |
|
181 | - )); |
|
182 | - } |
|
161 | + /** |
|
162 | + * create_attendee_from_billing_form_data |
|
163 | + * uses info from the billing form to create a new attendee |
|
164 | + * @return \EE_Attendee |
|
165 | + */ |
|
166 | + public function create_attendee_from_billing_form_data() |
|
167 | + { |
|
168 | + // grab billing form data |
|
169 | + $data = $this->valid_data(); |
|
170 | + return EE_Attendee::new_instance(array( |
|
171 | + 'ATT_fname' => ! empty($data['first_name']) ? $data['first_name'] : '', |
|
172 | + 'ATT_lname' => ! empty($data['last_name']) ? $data['last_name'] : '', |
|
173 | + 'ATT_email' => ! empty($data['email']) ? $data['email'] : '', |
|
174 | + 'ATT_address' => ! empty($data['address']) ? $data['address'] : '', |
|
175 | + 'ATT_address2' => ! empty($data['address2']) ? $data['address2'] : '', |
|
176 | + 'ATT_city' => ! empty($data['city']) ? $data['city'] : '', |
|
177 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : '', |
|
178 | + 'CNT_ISO' => ! empty($data['country']) ? $data['country'] : '', |
|
179 | + 'ATT_zip' => ! empty($data['zip']) ? $data['zip'] : '', |
|
180 | + 'ATT_phone' => ! empty($data['phone']) ? $data['phone'] : '', |
|
181 | + )); |
|
182 | + } |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | // End of file EE_Billing_Attendee_Info_Form.form.php |
@@ -23,16 +23,16 @@ discard block |
||
23 | 23 | { |
24 | 24 | $options_array['subsections'] = array_merge( |
25 | 25 | array( |
26 | - 'first_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => __('First Name', 'event_espresso') )), |
|
27 | - 'last_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => __('Last Name', 'event_espresso') )), |
|
28 | - 'email' => new EE_Email_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => __('Email', 'event_espresso') )), |
|
29 | - 'address' => new EE_Text_Input(array( 'html_label_text'=> __('Address', 'event_espresso'), 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )), |
|
30 | - 'address2' => new EE_Text_Input(array( 'html_label_text'=> __('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )), |
|
31 | - 'city' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => __('City', 'event_espresso') )), |
|
32 | - 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => __('State', 'event_espresso') ))), |
|
33 | - 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => __('Country', 'event_espresso') ))), |
|
34 | - 'zip' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => __('Zip', 'event_espresso') )), |
|
35 | - 'phone' => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => __('Phone', 'event_espresso') )), |
|
26 | + 'first_name' => new EE_Text_Input(array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => __('First Name', 'event_espresso'))), |
|
27 | + 'last_name' => new EE_Text_Input(array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => __('Last Name', 'event_espresso'))), |
|
28 | + 'email' => new EE_Email_Input(array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => __('Email', 'event_espresso'))), |
|
29 | + 'address' => new EE_Text_Input(array('html_label_text'=> __('Address', 'event_espresso'), 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address')), |
|
30 | + 'address2' => new EE_Text_Input(array('html_label_text'=> __('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2')), |
|
31 | + 'city' => new EE_Text_Input(array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => __('City', 'event_espresso'))), |
|
32 | + 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => __('State', 'event_espresso')))), |
|
33 | + 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => __('Country', 'event_espresso')))), |
|
34 | + 'zip' => new EE_Text_Input(array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => __('Zip', 'event_espresso'))), |
|
35 | + 'phone' => new EE_Text_Input(array('html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => __('Phone', 'event_espresso'))), |
|
36 | 36 | ), |
37 | 37 | isset($options_array['subsections']) ? $options_array['subsections'] : array() |
38 | 38 | ); |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | protected function getAttendeeStateValueForForm(EE_Attendee $attendee) |
81 | 81 | { |
82 | 82 | // If the state input was removed, just return a blank string. |
83 | - if (! $this->has_subsection('state')) { |
|
83 | + if ( ! $this->has_subsection('state')) { |
|
84 | 84 | return ''; |
85 | 85 | } |
86 | - $state_input = $this->get_input('state', false); |
|
86 | + $state_input = $this->get_input('state', false); |
|
87 | 87 | if ($state_input instanceof EE_State_Select_Input) { |
88 | - $state_field_to_use = $state_input->valueFieldName(); |
|
88 | + $state_field_to_use = $state_input->valueFieldName(); |
|
89 | 89 | } else { |
90 | 90 | $state_field_to_use = 'STA_ID'; |
91 | 91 | } |
@@ -115,43 +115,43 @@ discard block |
||
115 | 115 | // grab billing form data |
116 | 116 | $data = $this->valid_data(); |
117 | 117 | // copy first_name |
118 | - if (! empty($data['first_name'])) { |
|
118 | + if ( ! empty($data['first_name'])) { |
|
119 | 119 | $attendee->set_fname($data['first_name']); |
120 | 120 | } |
121 | 121 | // copy last_name |
122 | - if (! empty($data['last_name'])) { |
|
122 | + if ( ! empty($data['last_name'])) { |
|
123 | 123 | $attendee->set_lname($data['last_name']); |
124 | 124 | } |
125 | 125 | // copy email |
126 | - if (! empty($data['email'])) { |
|
126 | + if ( ! empty($data['email'])) { |
|
127 | 127 | $attendee->set_email($data['email']); |
128 | 128 | } |
129 | 129 | // copy address |
130 | - if (! empty($data['address'])) { |
|
130 | + if ( ! empty($data['address'])) { |
|
131 | 131 | $attendee->set_address($data['address']); |
132 | 132 | } |
133 | 133 | // copy address2 |
134 | - if (! empty($data['address2'])) { |
|
134 | + if ( ! empty($data['address2'])) { |
|
135 | 135 | $attendee->set_address2($data['address2']); |
136 | 136 | } |
137 | 137 | // copy city |
138 | - if (! empty($data['city'])) { |
|
138 | + if ( ! empty($data['city'])) { |
|
139 | 139 | $attendee->set_city($data['city']); |
140 | 140 | } |
141 | 141 | // copy state |
142 | - if (! empty($data['state'])) { |
|
142 | + if ( ! empty($data['state'])) { |
|
143 | 143 | $attendee->set_state($data['state']); |
144 | 144 | } |
145 | 145 | // copy country |
146 | - if (! empty($data['country'])) { |
|
146 | + if ( ! empty($data['country'])) { |
|
147 | 147 | $attendee->set_country($data['country']); |
148 | 148 | } |
149 | 149 | // copy zip |
150 | - if (! empty($data['zip'])) { |
|
150 | + if ( ! empty($data['zip'])) { |
|
151 | 151 | $attendee->set_zip($data['zip']); |
152 | 152 | } |
153 | 153 | // copy phone |
154 | - if (! empty($data['phone'])) { |
|
154 | + if ( ! empty($data['phone'])) { |
|
155 | 155 | $attendee->set_phone($data['phone']); |
156 | 156 | } |
157 | 157 | return $attendee; |
@@ -12,2893 +12,2893 @@ |
||
12 | 12 | class EE_SPCO_Reg_Step_Payment_Options extends EE_SPCO_Reg_Step |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @access protected |
|
17 | - * @var EE_Line_Item_Display $Line_Item_Display |
|
18 | - */ |
|
19 | - protected $line_item_display; |
|
20 | - |
|
21 | - /** |
|
22 | - * @access protected |
|
23 | - * @var boolean $handle_IPN_in_this_request |
|
24 | - */ |
|
25 | - protected $handle_IPN_in_this_request = false; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
30 | - * |
|
31 | - * @access public |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public static function set_hooks() |
|
35 | - { |
|
36 | - add_filter( |
|
37 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
38 | - array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
39 | - ); |
|
40 | - add_action( |
|
41 | - 'wp_ajax_switch_spco_billing_form', |
|
42 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
43 | - ); |
|
44 | - add_action( |
|
45 | - 'wp_ajax_nopriv_switch_spco_billing_form', |
|
46 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
47 | - ); |
|
48 | - add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
49 | - add_action( |
|
50 | - 'wp_ajax_nopriv_save_payer_details', |
|
51 | - array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
52 | - ); |
|
53 | - add_action( |
|
54 | - 'wp_ajax_get_transaction_details_for_gateways', |
|
55 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
56 | - ); |
|
57 | - add_action( |
|
58 | - 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
59 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
60 | - ); |
|
61 | - add_filter( |
|
62 | - 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
63 | - array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
64 | - 10, |
|
65 | - 1 |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * ajax switch_spco_billing_form |
|
72 | - * |
|
73 | - * @throws \EE_Error |
|
74 | - */ |
|
75 | - public static function switch_spco_billing_form() |
|
76 | - { |
|
77 | - EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * ajax save_payer_details |
|
83 | - * |
|
84 | - * @throws \EE_Error |
|
85 | - */ |
|
86 | - public static function save_payer_details() |
|
87 | - { |
|
88 | - EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * ajax get_transaction_details |
|
94 | - * |
|
95 | - * @throws \EE_Error |
|
96 | - */ |
|
97 | - public static function get_transaction_details() |
|
98 | - { |
|
99 | - EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * bypass_recaptcha_for_load_payment_method |
|
105 | - * |
|
106 | - * @access public |
|
107 | - * @return array |
|
108 | - * @throws InvalidArgumentException |
|
109 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
110 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
111 | - */ |
|
112 | - public static function bypass_recaptcha_for_load_payment_method() |
|
113 | - { |
|
114 | - return array( |
|
115 | - 'EESID' => EE_Registry::instance()->SSN->id(), |
|
116 | - 'step' => 'payment_options', |
|
117 | - 'action' => 'spco_billing_form', |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * class constructor |
|
124 | - * |
|
125 | - * @access public |
|
126 | - * @param EE_Checkout $checkout |
|
127 | - */ |
|
128 | - public function __construct(EE_Checkout $checkout) |
|
129 | - { |
|
130 | - $this->_slug = 'payment_options'; |
|
131 | - $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
133 | - $this->checkout = $checkout; |
|
134 | - $this->_reset_success_message(); |
|
135 | - $this->set_instructions( |
|
136 | - esc_html__( |
|
137 | - 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
138 | - 'event_espresso' |
|
139 | - ) |
|
140 | - ); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return null |
|
146 | - */ |
|
147 | - public function line_item_display() |
|
148 | - { |
|
149 | - return $this->line_item_display; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param null $line_item_display |
|
155 | - */ |
|
156 | - public function set_line_item_display($line_item_display) |
|
157 | - { |
|
158 | - $this->line_item_display = $line_item_display; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @return boolean |
|
164 | - */ |
|
165 | - public function handle_IPN_in_this_request() |
|
166 | - { |
|
167 | - return $this->handle_IPN_in_this_request; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param boolean $handle_IPN_in_this_request |
|
173 | - */ |
|
174 | - public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
175 | - { |
|
176 | - $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * translate_js_strings |
|
182 | - * |
|
183 | - * @return void |
|
184 | - */ |
|
185 | - public function translate_js_strings() |
|
186 | - { |
|
187 | - EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
188 | - 'Please select a method of payment in order to continue.', |
|
189 | - 'event_espresso' |
|
190 | - ); |
|
191 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
192 | - 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
193 | - 'event_espresso' |
|
194 | - ); |
|
195 | - EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
196 | - 'Forwarding to Secure Payment Provider.', |
|
197 | - 'event_espresso' |
|
198 | - ); |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * enqueue_styles_and_scripts |
|
204 | - * |
|
205 | - * @return void |
|
206 | - * @throws EE_Error |
|
207 | - * @throws InvalidArgumentException |
|
208 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
209 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
210 | - */ |
|
211 | - public function enqueue_styles_and_scripts() |
|
212 | - { |
|
213 | - $transaction = $this->checkout->transaction; |
|
214 | - // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
215 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
216 | - return; |
|
217 | - } |
|
218 | - foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
219 | - $transaction, |
|
220 | - EEM_Payment_Method::scope_cart |
|
221 | - ) as $payment_method) { |
|
222 | - $type_obj = $payment_method->type_obj(); |
|
223 | - if ($type_obj instanceof EE_PMT_Base) { |
|
224 | - $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
225 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
226 | - $billing_form->enqueue_js(); |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * initialize_reg_step |
|
235 | - * |
|
236 | - * @return bool |
|
237 | - * @throws EE_Error |
|
238 | - * @throws InvalidArgumentException |
|
239 | - * @throws ReflectionException |
|
240 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
241 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
242 | - */ |
|
243 | - public function initialize_reg_step() |
|
244 | - { |
|
245 | - // TODO: if /when we implement donations, then this will need overriding |
|
246 | - if (// don't need payment options for: |
|
247 | - // registrations made via the admin |
|
248 | - // completed transactions |
|
249 | - // overpaid transactions |
|
250 | - // $ 0.00 transactions(no payment required) |
|
251 | - ! $this->checkout->payment_required() |
|
252 | - // but do NOT remove if current action being called belongs to this reg step |
|
253 | - && ! is_callable(array($this, $this->checkout->action)) |
|
254 | - && ! $this->completed() |
|
255 | - ) { |
|
256 | - // and if so, then we no longer need the Payment Options step |
|
257 | - if ($this->is_current_step()) { |
|
258 | - $this->checkout->generate_reg_form = false; |
|
259 | - } |
|
260 | - $this->checkout->remove_reg_step($this->_slug); |
|
261 | - // DEBUG LOG |
|
262 | - // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
263 | - return false; |
|
264 | - } |
|
265 | - // load EEM_Payment_Method |
|
266 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
267 | - // get all active payment methods |
|
268 | - $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
269 | - $this->checkout->transaction, |
|
270 | - EEM_Payment_Method::scope_cart |
|
271 | - ); |
|
272 | - return true; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * @return EE_Form_Section_Proper |
|
278 | - * @throws EE_Error |
|
279 | - * @throws InvalidArgumentException |
|
280 | - * @throws ReflectionException |
|
281 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
282 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
283 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
284 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
285 | - */ |
|
286 | - public function generate_reg_form() |
|
287 | - { |
|
288 | - // reset in case someone changes their mind |
|
289 | - $this->_reset_selected_method_of_payment(); |
|
290 | - // set some defaults |
|
291 | - $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
292 | - $registrations_requiring_payment = array(); |
|
293 | - $registrations_for_free_events = array(); |
|
294 | - $registrations_requiring_pre_approval = array(); |
|
295 | - $sold_out_events = array(); |
|
296 | - $insufficient_spaces_available = array(); |
|
297 | - $no_payment_required = true; |
|
298 | - // loop thru registrations to gather info |
|
299 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
300 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
301 | - $registrations, |
|
302 | - $this->checkout->revisit |
|
303 | - ); |
|
304 | - foreach ($registrations as $REG_ID => $registration) { |
|
305 | - /** @var $registration EE_Registration */ |
|
306 | - // has this registration lost it's space ? |
|
307 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
308 | - if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
309 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
310 | - } else { |
|
311 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
312 | - } |
|
313 | - continue; |
|
314 | - } |
|
315 | - // event requires admin approval |
|
316 | - if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
317 | - // add event to list of events with pre-approval reg status |
|
318 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
319 | - do_action( |
|
320 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
321 | - $registration->event(), |
|
322 | - $this |
|
323 | - ); |
|
324 | - continue; |
|
325 | - } |
|
326 | - if ($this->checkout->revisit |
|
327 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
328 | - && ( |
|
329 | - $registration->event()->is_sold_out() |
|
330 | - || $registration->event()->is_sold_out(true) |
|
331 | - ) |
|
332 | - ) { |
|
333 | - // add event to list of events that are sold out |
|
334 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
335 | - do_action( |
|
336 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
337 | - $registration->event(), |
|
338 | - $this |
|
339 | - ); |
|
340 | - continue; |
|
341 | - } |
|
342 | - // are they allowed to pay now and is there monies owing? |
|
343 | - if ($registration->owes_monies_and_can_pay()) { |
|
344 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
345 | - do_action( |
|
346 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
347 | - $registration->event(), |
|
348 | - $this |
|
349 | - ); |
|
350 | - } elseif (! $this->checkout->revisit |
|
351 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
352 | - && $registration->ticket()->is_free() |
|
353 | - ) { |
|
354 | - $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
355 | - } |
|
356 | - } |
|
357 | - $subsections = array(); |
|
358 | - // now decide which template to load |
|
359 | - if (! empty($sold_out_events)) { |
|
360 | - $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
361 | - } |
|
362 | - if (! empty($insufficient_spaces_available)) { |
|
363 | - $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
364 | - $insufficient_spaces_available |
|
365 | - ); |
|
366 | - } |
|
367 | - if (! empty($registrations_requiring_pre_approval)) { |
|
368 | - $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
369 | - $registrations_requiring_pre_approval |
|
370 | - ); |
|
371 | - } |
|
372 | - if (! empty($registrations_for_free_events)) { |
|
373 | - $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
374 | - } |
|
375 | - if (! empty($registrations_requiring_payment)) { |
|
376 | - if ($this->checkout->amount_owing > 0) { |
|
377 | - // autoload Line_Item_Display classes |
|
378 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
379 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
380 | - apply_filters( |
|
381 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
382 | - new EE_Line_Item_Filter_Collection() |
|
383 | - ), |
|
384 | - $this->checkout->cart->get_grand_total() |
|
385 | - ); |
|
386 | - /** @var EE_Line_Item $filtered_line_item_tree */ |
|
387 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
388 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
389 | - $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
390 | - $subsections['payment_options'] = $this->_display_payment_options( |
|
391 | - $this->line_item_display->display_line_item( |
|
392 | - $filtered_line_item_tree, |
|
393 | - array('registrations' => $registrations) |
|
394 | - ) |
|
395 | - ); |
|
396 | - $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
397 | - $this->_apply_registration_payments_to_amount_owing($registrations); |
|
398 | - } |
|
399 | - $no_payment_required = false; |
|
400 | - } else { |
|
401 | - $this->_hide_reg_step_submit_button_if_revisit(); |
|
402 | - } |
|
403 | - $this->_save_selected_method_of_payment(); |
|
404 | - |
|
405 | - $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
406 | - $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
407 | - |
|
408 | - return new EE_Form_Section_Proper( |
|
409 | - array( |
|
410 | - 'name' => $this->reg_form_name(), |
|
411 | - 'html_id' => $this->reg_form_name(), |
|
412 | - 'subsections' => $subsections, |
|
413 | - 'layout_strategy' => new EE_No_Layout(), |
|
414 | - ) |
|
415 | - ); |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * add line item filters required for this reg step |
|
421 | - * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
422 | - * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
423 | - * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
424 | - * payment options reg step, can apply these filters via the following: apply_filters( |
|
425 | - * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
426 | - * filter collection by passing that instead of instantiating a new collection |
|
427 | - * |
|
428 | - * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
429 | - * @return EE_Line_Item_Filter_Collection |
|
430 | - * @throws EE_Error |
|
431 | - * @throws InvalidArgumentException |
|
432 | - * @throws ReflectionException |
|
433 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
434 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
435 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
436 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
437 | - */ |
|
438 | - public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
439 | - { |
|
440 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
441 | - return $line_item_filter_collection; |
|
442 | - } |
|
443 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
444 | - return $line_item_filter_collection; |
|
445 | - } |
|
446 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
447 | - return $line_item_filter_collection; |
|
448 | - } |
|
449 | - $line_item_filter_collection->add( |
|
450 | - new EE_Billable_Line_Item_Filter( |
|
451 | - EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
452 | - EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
453 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
454 | - ) |
|
455 | - ) |
|
456 | - ) |
|
457 | - ); |
|
458 | - $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
459 | - return $line_item_filter_collection; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * remove_ejected_registrations |
|
465 | - * if a registrant has lost their potential space at an event due to lack of payment, |
|
466 | - * then this method removes them from the list of registrations being paid for during this request |
|
467 | - * |
|
468 | - * @param \EE_Registration[] $registrations |
|
469 | - * @return EE_Registration[] |
|
470 | - * @throws EE_Error |
|
471 | - * @throws InvalidArgumentException |
|
472 | - * @throws ReflectionException |
|
473 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
474 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
475 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
476 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
477 | - */ |
|
478 | - public static function remove_ejected_registrations(array $registrations) |
|
479 | - { |
|
480 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
481 | - $registrations, |
|
482 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
483 | - ); |
|
484 | - foreach ($registrations as $REG_ID => $registration) { |
|
485 | - // has this registration lost it's space ? |
|
486 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
487 | - unset($registrations[ $REG_ID ]); |
|
488 | - continue; |
|
489 | - } |
|
490 | - } |
|
491 | - return $registrations; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * find_registrations_that_lost_their_space |
|
497 | - * If a registrant chooses an offline payment method like Invoice, |
|
498 | - * then no space is reserved for them at the event until they fully pay fo that site |
|
499 | - * (unless the event's default reg status is set to APPROVED) |
|
500 | - * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
501 | - * then this method will determine which registrations have lost the ability to complete the reg process. |
|
502 | - * |
|
503 | - * @param \EE_Registration[] $registrations |
|
504 | - * @param bool $revisit |
|
505 | - * @return array |
|
506 | - * @throws EE_Error |
|
507 | - * @throws InvalidArgumentException |
|
508 | - * @throws ReflectionException |
|
509 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
510 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
511 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
512 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
513 | - */ |
|
514 | - public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
515 | - { |
|
516 | - // registrations per event |
|
517 | - $event_reg_count = array(); |
|
518 | - // spaces left per event |
|
519 | - $event_spaces_remaining = array(); |
|
520 | - // tickets left sorted by ID |
|
521 | - $tickets_remaining = array(); |
|
522 | - // registrations that have lost their space |
|
523 | - $ejected_registrations = array(); |
|
524 | - foreach ($registrations as $REG_ID => $registration) { |
|
525 | - if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
526 | - || apply_filters( |
|
527 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
528 | - false, |
|
529 | - $registration, |
|
530 | - $revisit |
|
531 | - ) |
|
532 | - ) { |
|
533 | - continue; |
|
534 | - } |
|
535 | - $EVT_ID = $registration->event_ID(); |
|
536 | - $ticket = $registration->ticket(); |
|
537 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
538 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
539 | - } |
|
540 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
541 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
542 | - $event_reg_count[ $EVT_ID ] = 0; |
|
543 | - } |
|
544 | - $event_reg_count[ $EVT_ID ]++; |
|
545 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
546 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
547 | - } |
|
548 | - } |
|
549 | - if ($revisit |
|
550 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
551 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
552 | - ) |
|
553 | - ) { |
|
554 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
555 | - if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
556 | - /** @type EE_Registration_Processor $registration_processor */ |
|
557 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
558 | - // at this point, we should have enough details about the registrant to consider the registration |
|
559 | - // NOT incomplete |
|
560 | - $registration_processor->manually_update_registration_status( |
|
561 | - $registration, |
|
562 | - EEM_Registration::status_id_wait_list |
|
563 | - ); |
|
564 | - } |
|
565 | - } |
|
566 | - } |
|
567 | - return $ejected_registrations; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * _hide_reg_step_submit_button |
|
573 | - * removes the html for the reg step submit button |
|
574 | - * by replacing it with an empty string via filter callback |
|
575 | - * |
|
576 | - * @return void |
|
577 | - */ |
|
578 | - protected function _adjust_registration_status_if_event_old_sold() |
|
579 | - { |
|
580 | - } |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * _hide_reg_step_submit_button |
|
585 | - * removes the html for the reg step submit button |
|
586 | - * by replacing it with an empty string via filter callback |
|
587 | - * |
|
588 | - * @return void |
|
589 | - */ |
|
590 | - protected function _hide_reg_step_submit_button_if_revisit() |
|
591 | - { |
|
592 | - if ($this->checkout->revisit) { |
|
593 | - add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
594 | - } |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - /** |
|
599 | - * sold_out_events |
|
600 | - * displays notices regarding events that have sold out since hte registrant first signed up |
|
601 | - * |
|
602 | - * @param \EE_Event[] $sold_out_events_array |
|
603 | - * @return \EE_Form_Section_Proper |
|
604 | - * @throws \EE_Error |
|
605 | - */ |
|
606 | - private function _sold_out_events($sold_out_events_array = array()) |
|
607 | - { |
|
608 | - // set some defaults |
|
609 | - $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
610 | - $sold_out_events = ''; |
|
611 | - foreach ($sold_out_events_array as $sold_out_event) { |
|
612 | - $sold_out_events .= EEH_HTML::li( |
|
613 | - EEH_HTML::span( |
|
614 | - ' ' . $sold_out_event->name(), |
|
615 | - '', |
|
616 | - 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
617 | - ) |
|
618 | - ); |
|
619 | - } |
|
620 | - return new EE_Form_Section_Proper( |
|
621 | - array( |
|
622 | - 'layout_strategy' => new EE_Template_Layout( |
|
623 | - array( |
|
624 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
625 | - . $this->_slug |
|
626 | - . DS |
|
627 | - . 'sold_out_events.template.php', |
|
628 | - 'template_args' => apply_filters( |
|
629 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
630 | - array( |
|
631 | - 'sold_out_events' => $sold_out_events, |
|
632 | - 'sold_out_events_msg' => apply_filters( |
|
633 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
634 | - sprintf( |
|
635 | - esc_html__( |
|
636 | - 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', |
|
637 | - 'event_espresso' |
|
638 | - ), |
|
639 | - '<strong>', |
|
640 | - '</strong>', |
|
641 | - '<br />' |
|
642 | - ) |
|
643 | - ), |
|
644 | - ) |
|
645 | - ), |
|
646 | - ) |
|
647 | - ), |
|
648 | - ) |
|
649 | - ); |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * _insufficient_spaces_available |
|
655 | - * displays notices regarding events that do not have enough remaining spaces |
|
656 | - * to satisfy the current number of registrations looking to pay |
|
657 | - * |
|
658 | - * @param \EE_Event[] $insufficient_spaces_events_array |
|
659 | - * @return \EE_Form_Section_Proper |
|
660 | - * @throws \EE_Error |
|
661 | - */ |
|
662 | - private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
663 | - { |
|
664 | - // set some defaults |
|
665 | - $this->checkout->selected_method_of_payment = 'invoice'; |
|
666 | - $insufficient_space_events = ''; |
|
667 | - foreach ($insufficient_spaces_events_array as $event) { |
|
668 | - if ($event instanceof EE_Event) { |
|
669 | - $insufficient_space_events .= EEH_HTML::li( |
|
670 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
671 | - ); |
|
672 | - } |
|
673 | - } |
|
674 | - return new EE_Form_Section_Proper( |
|
675 | - array( |
|
676 | - 'subsections' => array( |
|
677 | - 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
678 | - 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
679 | - ), |
|
680 | - 'layout_strategy' => new EE_Template_Layout( |
|
681 | - array( |
|
682 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
683 | - . $this->_slug |
|
684 | - . DS |
|
685 | - . 'sold_out_events.template.php', |
|
686 | - 'template_args' => apply_filters( |
|
687 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
688 | - array( |
|
689 | - 'sold_out_events' => $insufficient_space_events, |
|
690 | - 'sold_out_events_msg' => apply_filters( |
|
691 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
692 | - esc_html__( |
|
693 | - 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
694 | - 'event_espresso' |
|
695 | - ) |
|
696 | - ), |
|
697 | - ) |
|
698 | - ), |
|
699 | - ) |
|
700 | - ), |
|
701 | - ) |
|
702 | - ); |
|
703 | - } |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * registrations_requiring_pre_approval |
|
708 | - * |
|
709 | - * @param array $registrations_requiring_pre_approval |
|
710 | - * @return EE_Form_Section_Proper |
|
711 | - * @throws EE_Error |
|
712 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
713 | - */ |
|
714 | - private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
715 | - { |
|
716 | - $events_requiring_pre_approval = array(); |
|
717 | - foreach ($registrations_requiring_pre_approval as $registration) { |
|
718 | - if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
719 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
720 | - EEH_HTML::span( |
|
721 | - '', |
|
722 | - '', |
|
723 | - 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
724 | - ) |
|
725 | - . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
726 | - ); |
|
727 | - } |
|
728 | - } |
|
729 | - return new EE_Form_Section_Proper( |
|
730 | - array( |
|
731 | - 'layout_strategy' => new EE_Template_Layout( |
|
732 | - array( |
|
733 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
734 | - . $this->_slug |
|
735 | - . DS |
|
736 | - . 'events_requiring_pre_approval.template.php', // layout_template |
|
737 | - 'template_args' => apply_filters( |
|
738 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
739 | - array( |
|
740 | - 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
741 | - 'events_requiring_pre_approval_msg' => apply_filters( |
|
742 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
743 | - esc_html__( |
|
744 | - 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
745 | - 'event_espresso' |
|
746 | - ) |
|
747 | - ), |
|
748 | - ) |
|
749 | - ), |
|
750 | - ) |
|
751 | - ), |
|
752 | - ) |
|
753 | - ); |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * _no_payment_required |
|
759 | - * |
|
760 | - * @param \EE_Event[] $registrations_for_free_events |
|
761 | - * @return \EE_Form_Section_Proper |
|
762 | - * @throws \EE_Error |
|
763 | - */ |
|
764 | - private function _no_payment_required($registrations_for_free_events = array()) |
|
765 | - { |
|
766 | - // set some defaults |
|
767 | - $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
768 | - // generate no_payment_required form |
|
769 | - return new EE_Form_Section_Proper( |
|
770 | - array( |
|
771 | - 'layout_strategy' => new EE_Template_Layout( |
|
772 | - array( |
|
773 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
774 | - . $this->_slug |
|
775 | - . DS |
|
776 | - . 'no_payment_required.template.php', // layout_template |
|
777 | - 'template_args' => apply_filters( |
|
778 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
779 | - array( |
|
780 | - 'revisit' => $this->checkout->revisit, |
|
781 | - 'registrations' => array(), |
|
782 | - 'ticket_count' => array(), |
|
783 | - 'registrations_for_free_events' => $registrations_for_free_events, |
|
784 | - 'no_payment_required_msg' => EEH_HTML::p( |
|
785 | - esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
786 | - ), |
|
787 | - ) |
|
788 | - ), |
|
789 | - ) |
|
790 | - ), |
|
791 | - ) |
|
792 | - ); |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * _display_payment_options |
|
798 | - * |
|
799 | - * @param string $transaction_details |
|
800 | - * @return EE_Form_Section_Proper |
|
801 | - * @throws EE_Error |
|
802 | - * @throws InvalidArgumentException |
|
803 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
804 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
805 | - */ |
|
806 | - private function _display_payment_options($transaction_details = '') |
|
807 | - { |
|
808 | - // has method_of_payment been set by no-js user? |
|
809 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
810 | - // build payment options form |
|
811 | - return apply_filters( |
|
812 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
813 | - new EE_Form_Section_Proper( |
|
814 | - array( |
|
815 | - 'subsections' => array( |
|
816 | - 'before_payment_options' => apply_filters( |
|
817 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
818 | - new EE_Form_Section_Proper( |
|
819 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
820 | - ) |
|
821 | - ), |
|
822 | - 'payment_options' => $this->_setup_payment_options(), |
|
823 | - 'after_payment_options' => apply_filters( |
|
824 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
825 | - new EE_Form_Section_Proper( |
|
826 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
827 | - ) |
|
828 | - ), |
|
829 | - ), |
|
830 | - 'layout_strategy' => new EE_Template_Layout( |
|
831 | - array( |
|
832 | - 'layout_template_file' => $this->_template, |
|
833 | - 'template_args' => apply_filters( |
|
834 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
835 | - array( |
|
836 | - 'reg_count' => $this->line_item_display->total_items(), |
|
837 | - 'transaction_details' => $transaction_details, |
|
838 | - 'available_payment_methods' => array(), |
|
839 | - ) |
|
840 | - ), |
|
841 | - ) |
|
842 | - ), |
|
843 | - ) |
|
844 | - ) |
|
845 | - ); |
|
846 | - } |
|
847 | - |
|
848 | - |
|
849 | - /** |
|
850 | - * _extra_hidden_inputs |
|
851 | - * |
|
852 | - * @param bool $no_payment_required |
|
853 | - * @return \EE_Form_Section_Proper |
|
854 | - * @throws \EE_Error |
|
855 | - */ |
|
856 | - private function _extra_hidden_inputs($no_payment_required = true) |
|
857 | - { |
|
858 | - return new EE_Form_Section_Proper( |
|
859 | - array( |
|
860 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
861 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
862 | - 'subsections' => array( |
|
863 | - 'spco_no_payment_required' => new EE_Hidden_Input( |
|
864 | - array( |
|
865 | - 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
866 | - 'html_name' => 'spco_no_payment_required', |
|
867 | - 'html_id' => 'spco-no-payment-required-payment_options', |
|
868 | - 'default' => $no_payment_required, |
|
869 | - ) |
|
870 | - ), |
|
871 | - 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
872 | - array( |
|
873 | - 'normalization_strategy' => new EE_Int_Normalization(), |
|
874 | - 'html_name' => 'spco_transaction_id', |
|
875 | - 'html_id' => 'spco-transaction-id', |
|
876 | - 'default' => $this->checkout->transaction->ID(), |
|
877 | - ) |
|
878 | - ), |
|
879 | - ), |
|
880 | - ) |
|
881 | - ); |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - /** |
|
886 | - * _apply_registration_payments_to_amount_owing |
|
887 | - * |
|
888 | - * @access protected |
|
889 | - * @param array $registrations |
|
890 | - * @throws EE_Error |
|
891 | - */ |
|
892 | - protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
893 | - { |
|
894 | - $payments = array(); |
|
895 | - foreach ($registrations as $registration) { |
|
896 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
897 | - $payments += $registration->registration_payments(); |
|
898 | - } |
|
899 | - } |
|
900 | - if (! empty($payments)) { |
|
901 | - foreach ($payments as $payment) { |
|
902 | - if ($payment instanceof EE_Registration_Payment) { |
|
903 | - $this->checkout->amount_owing -= $payment->amount(); |
|
904 | - } |
|
905 | - } |
|
906 | - } |
|
907 | - } |
|
908 | - |
|
909 | - |
|
910 | - /** |
|
911 | - * _reset_selected_method_of_payment |
|
912 | - * |
|
913 | - * @access private |
|
914 | - * @param bool $force_reset |
|
915 | - * @return void |
|
916 | - * @throws InvalidArgumentException |
|
917 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
918 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
919 | - */ |
|
920 | - private function _reset_selected_method_of_payment($force_reset = false) |
|
921 | - { |
|
922 | - $reset_payment_method = $force_reset |
|
923 | - ? true |
|
924 | - : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
925 | - if ($reset_payment_method) { |
|
926 | - $this->checkout->selected_method_of_payment = null; |
|
927 | - $this->checkout->payment_method = null; |
|
928 | - $this->checkout->billing_form = null; |
|
929 | - $this->_save_selected_method_of_payment(); |
|
930 | - } |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - /** |
|
935 | - * _save_selected_method_of_payment |
|
936 | - * stores the selected_method_of_payment in the session |
|
937 | - * so that it's available for all subsequent requests including AJAX |
|
938 | - * |
|
939 | - * @access private |
|
940 | - * @param string $selected_method_of_payment |
|
941 | - * @return void |
|
942 | - * @throws InvalidArgumentException |
|
943 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
944 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
945 | - */ |
|
946 | - private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
947 | - { |
|
948 | - $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
949 | - ? $selected_method_of_payment |
|
950 | - : $this->checkout->selected_method_of_payment; |
|
951 | - EE_Registry::instance()->SSN->set_session_data( |
|
952 | - array('selected_method_of_payment' => $selected_method_of_payment) |
|
953 | - ); |
|
954 | - } |
|
955 | - |
|
956 | - |
|
957 | - /** |
|
958 | - * _setup_payment_options |
|
959 | - * |
|
960 | - * @return EE_Form_Section_Proper |
|
961 | - * @throws EE_Error |
|
962 | - * @throws InvalidArgumentException |
|
963 | - * @throws ReflectionException |
|
964 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
965 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
966 | - */ |
|
967 | - public function _setup_payment_options() |
|
968 | - { |
|
969 | - // load payment method classes |
|
970 | - $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
971 | - if (empty($this->checkout->available_payment_methods)) { |
|
972 | - EE_Error::add_error( |
|
973 | - apply_filters( |
|
974 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
975 | - sprintf( |
|
976 | - esc_html__( |
|
977 | - 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
978 | - 'event_espresso' |
|
979 | - ), |
|
980 | - '<br>', |
|
981 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
982 | - ) |
|
983 | - ), |
|
984 | - __FILE__, |
|
985 | - __FUNCTION__, |
|
986 | - __LINE__ |
|
987 | - ); |
|
988 | - } |
|
989 | - // switch up header depending on number of available payment methods |
|
990 | - $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
991 | - ? apply_filters( |
|
992 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
993 | - esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
994 | - ) |
|
995 | - : apply_filters( |
|
996 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
997 | - esc_html__('Method of Payment', 'event_espresso') |
|
998 | - ); |
|
999 | - $available_payment_methods = array( |
|
1000 | - // display the "Payment Method" header |
|
1001 | - 'payment_method_header' => new EE_Form_Section_HTML( |
|
1002 | - apply_filters( |
|
1003 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header', |
|
1004 | - EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'), |
|
1005 | - $payment_method_header |
|
1006 | - ) |
|
1007 | - ), |
|
1008 | - ); |
|
1009 | - // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
1010 | - $available_payment_method_options = array(); |
|
1011 | - $default_payment_method_option = array(); |
|
1012 | - // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
1013 | - $payment_methods_billing_info = array( |
|
1014 | - new EE_Form_Section_HTML( |
|
1015 | - EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
1016 | - ), |
|
1017 | - ); |
|
1018 | - // loop through payment methods |
|
1019 | - foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
1020 | - if ($payment_method instanceof EE_Payment_Method) { |
|
1021 | - $payment_method_button = EEH_HTML::img( |
|
1022 | - $payment_method->button_url(), |
|
1023 | - $payment_method->name(), |
|
1024 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
1025 | - 'spco-payment-method-btn-img' |
|
1026 | - ); |
|
1027 | - // check if any payment methods are set as default |
|
1028 | - // if payment method is already selected OR nothing is selected and this payment method should be |
|
1029 | - // open_by_default |
|
1030 | - if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
1031 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1032 | - ) { |
|
1033 | - $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
1034 | - $this->_save_selected_method_of_payment(); |
|
1035 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
1036 | - } else { |
|
1037 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
1038 | - } |
|
1039 | - $payment_methods_billing_info[ $payment_method->slug( |
|
1040 | - ) . '-info' ] = $this->_payment_method_billing_info( |
|
1041 | - $payment_method |
|
1042 | - ); |
|
1043 | - } |
|
1044 | - } |
|
1045 | - // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
1046 | - // of PMs |
|
1047 | - $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
1048 | - // now generate the actual form inputs |
|
1049 | - $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
1050 | - $available_payment_method_options |
|
1051 | - ); |
|
1052 | - $available_payment_methods += $payment_methods_billing_info; |
|
1053 | - // build the available payment methods form |
|
1054 | - return new EE_Form_Section_Proper( |
|
1055 | - array( |
|
1056 | - 'html_id' => 'spco-available-methods-of-payment-dv', |
|
1057 | - 'subsections' => $available_payment_methods, |
|
1058 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1059 | - ) |
|
1060 | - ); |
|
1061 | - } |
|
1062 | - |
|
1063 | - |
|
1064 | - /** |
|
1065 | - * _get_available_payment_methods |
|
1066 | - * |
|
1067 | - * @return EE_Payment_Method[] |
|
1068 | - * @throws EE_Error |
|
1069 | - * @throws InvalidArgumentException |
|
1070 | - * @throws ReflectionException |
|
1071 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1072 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1073 | - */ |
|
1074 | - protected function _get_available_payment_methods() |
|
1075 | - { |
|
1076 | - if (! empty($this->checkout->available_payment_methods)) { |
|
1077 | - return $this->checkout->available_payment_methods; |
|
1078 | - } |
|
1079 | - $available_payment_methods = array(); |
|
1080 | - // load EEM_Payment_Method |
|
1081 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
1082 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
1083 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
1084 | - // get all active payment methods |
|
1085 | - $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
1086 | - $this->checkout->transaction, |
|
1087 | - EEM_Payment_Method::scope_cart |
|
1088 | - ); |
|
1089 | - foreach ($payment_methods as $payment_method) { |
|
1090 | - if ($payment_method instanceof EE_Payment_Method) { |
|
1091 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1092 | - } |
|
1093 | - } |
|
1094 | - return $available_payment_methods; |
|
1095 | - } |
|
1096 | - |
|
1097 | - |
|
1098 | - /** |
|
1099 | - * _available_payment_method_inputs |
|
1100 | - * |
|
1101 | - * @access private |
|
1102 | - * @param array $available_payment_method_options |
|
1103 | - * @return \EE_Form_Section_Proper |
|
1104 | - */ |
|
1105 | - private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
1106 | - { |
|
1107 | - // generate inputs |
|
1108 | - return new EE_Form_Section_Proper( |
|
1109 | - array( |
|
1110 | - 'html_id' => 'ee-available-payment-method-inputs', |
|
1111 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1112 | - 'subsections' => array( |
|
1113 | - '' => new EE_Radio_Button_Input( |
|
1114 | - $available_payment_method_options, |
|
1115 | - array( |
|
1116 | - 'html_name' => 'selected_method_of_payment', |
|
1117 | - 'html_class' => 'spco-payment-method', |
|
1118 | - 'default' => $this->checkout->selected_method_of_payment, |
|
1119 | - 'label_size' => 11, |
|
1120 | - 'enforce_label_size' => true, |
|
1121 | - ) |
|
1122 | - ), |
|
1123 | - ), |
|
1124 | - ) |
|
1125 | - ); |
|
1126 | - } |
|
1127 | - |
|
1128 | - |
|
1129 | - /** |
|
1130 | - * _payment_method_billing_info |
|
1131 | - * |
|
1132 | - * @access private |
|
1133 | - * @param EE_Payment_Method $payment_method |
|
1134 | - * @return EE_Form_Section_Proper |
|
1135 | - * @throws EE_Error |
|
1136 | - * @throws InvalidArgumentException |
|
1137 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1138 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1139 | - */ |
|
1140 | - private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
1141 | - { |
|
1142 | - $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
1143 | - ? true |
|
1144 | - : false; |
|
1145 | - // generate the billing form for payment method |
|
1146 | - $billing_form = $currently_selected |
|
1147 | - ? $this->_get_billing_form_for_payment_method($payment_method) |
|
1148 | - : new EE_Form_Section_HTML(); |
|
1149 | - $this->checkout->billing_form = $currently_selected |
|
1150 | - ? $billing_form |
|
1151 | - : $this->checkout->billing_form; |
|
1152 | - // it's all in the details |
|
1153 | - $info_html = EEH_HTML::h3( |
|
1154 | - esc_html__('Important information regarding your payment', 'event_espresso'), |
|
1155 | - '', |
|
1156 | - 'spco-payment-method-hdr' |
|
1157 | - ); |
|
1158 | - // add some info regarding the step, either from what's saved in the admin, |
|
1159 | - // or a default string depending on whether the PM has a billing form or not |
|
1160 | - if ($payment_method->description()) { |
|
1161 | - $payment_method_info = $payment_method->description(); |
|
1162 | - } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
1163 | - $payment_method_info = sprintf( |
|
1164 | - esc_html__( |
|
1165 | - 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
1166 | - 'event_espresso' |
|
1167 | - ), |
|
1168 | - $this->submit_button_text() |
|
1169 | - ); |
|
1170 | - } else { |
|
1171 | - $payment_method_info = sprintf( |
|
1172 | - esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
1173 | - $this->submit_button_text() |
|
1174 | - ); |
|
1175 | - } |
|
1176 | - $info_html .= EEH_HTML::div( |
|
1177 | - apply_filters( |
|
1178 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
1179 | - $payment_method_info |
|
1180 | - ), |
|
1181 | - '', |
|
1182 | - 'spco-payment-method-desc ee-attention' |
|
1183 | - ); |
|
1184 | - return new EE_Form_Section_Proper( |
|
1185 | - array( |
|
1186 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1187 | - 'html_class' => 'spco-payment-method-info-dv', |
|
1188 | - // only display the selected or default PM |
|
1189 | - 'html_style' => $currently_selected ? '' : 'display:none;', |
|
1190 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1191 | - 'subsections' => array( |
|
1192 | - 'info' => new EE_Form_Section_HTML($info_html), |
|
1193 | - 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
1194 | - ), |
|
1195 | - ) |
|
1196 | - ); |
|
1197 | - } |
|
1198 | - |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * get_billing_form_html_for_payment_method |
|
1202 | - * |
|
1203 | - * @access public |
|
1204 | - * @return string |
|
1205 | - * @throws EE_Error |
|
1206 | - * @throws InvalidArgumentException |
|
1207 | - * @throws ReflectionException |
|
1208 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1209 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1210 | - */ |
|
1211 | - public function get_billing_form_html_for_payment_method() |
|
1212 | - { |
|
1213 | - // how have they chosen to pay? |
|
1214 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1215 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1216 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1217 | - return false; |
|
1218 | - } |
|
1219 | - if (apply_filters( |
|
1220 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1221 | - false |
|
1222 | - )) { |
|
1223 | - EE_Error::add_success( |
|
1224 | - apply_filters( |
|
1225 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1226 | - sprintf( |
|
1227 | - esc_html__( |
|
1228 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1229 | - 'event_espresso' |
|
1230 | - ), |
|
1231 | - $this->checkout->payment_method->name() |
|
1232 | - ) |
|
1233 | - ) |
|
1234 | - ); |
|
1235 | - } |
|
1236 | - // now generate billing form for selected method of payment |
|
1237 | - $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
1238 | - // fill form with attendee info if applicable |
|
1239 | - if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1240 | - && $this->checkout->transaction_has_primary_registrant() |
|
1241 | - ) { |
|
1242 | - $payment_method_billing_form->populate_from_attendee( |
|
1243 | - $this->checkout->transaction->primary_registration()->attendee() |
|
1244 | - ); |
|
1245 | - } |
|
1246 | - // and debug content |
|
1247 | - if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
1248 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1249 | - ) { |
|
1250 | - $payment_method_billing_form = |
|
1251 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1252 | - $payment_method_billing_form |
|
1253 | - ); |
|
1254 | - } |
|
1255 | - $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
1256 | - ? $payment_method_billing_form->get_html() |
|
1257 | - : ''; |
|
1258 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
1259 | - // localize validation rules for main form |
|
1260 | - $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
1261 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1262 | - return true; |
|
1263 | - } |
|
1264 | - |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * _get_billing_form_for_payment_method |
|
1268 | - * |
|
1269 | - * @access private |
|
1270 | - * @param EE_Payment_Method $payment_method |
|
1271 | - * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
1272 | - * @throws EE_Error |
|
1273 | - * @throws InvalidArgumentException |
|
1274 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1275 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1276 | - */ |
|
1277 | - private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
1278 | - { |
|
1279 | - $billing_form = $payment_method->type_obj()->billing_form( |
|
1280 | - $this->checkout->transaction, |
|
1281 | - array('amount_owing' => $this->checkout->amount_owing) |
|
1282 | - ); |
|
1283 | - if ($billing_form instanceof EE_Billing_Info_Form) { |
|
1284 | - if (apply_filters( |
|
1285 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1286 | - false |
|
1287 | - ) |
|
1288 | - && EE_Registry::instance()->REQ->is_set('payment_method') |
|
1289 | - ) { |
|
1290 | - EE_Error::add_success( |
|
1291 | - apply_filters( |
|
1292 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1293 | - sprintf( |
|
1294 | - esc_html__( |
|
1295 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1296 | - 'event_espresso' |
|
1297 | - ), |
|
1298 | - $payment_method->name() |
|
1299 | - ) |
|
1300 | - ) |
|
1301 | - ); |
|
1302 | - } |
|
1303 | - return apply_filters( |
|
1304 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
1305 | - $billing_form, |
|
1306 | - $payment_method |
|
1307 | - ); |
|
1308 | - } |
|
1309 | - // no actual billing form, so return empty HTML form section |
|
1310 | - return new EE_Form_Section_HTML(); |
|
1311 | - } |
|
1312 | - |
|
1313 | - |
|
1314 | - /** |
|
1315 | - * _get_selected_method_of_payment |
|
1316 | - * |
|
1317 | - * @access private |
|
1318 | - * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
1319 | - * is not found in the incoming request |
|
1320 | - * @param string $request_param |
|
1321 | - * @return NULL|string |
|
1322 | - * @throws EE_Error |
|
1323 | - * @throws InvalidArgumentException |
|
1324 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1325 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1326 | - */ |
|
1327 | - private function _get_selected_method_of_payment( |
|
1328 | - $required = false, |
|
1329 | - $request_param = 'selected_method_of_payment' |
|
1330 | - ) { |
|
1331 | - // is selected_method_of_payment set in the request ? |
|
1332 | - $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
1333 | - if ($selected_method_of_payment) { |
|
1334 | - // sanitize it |
|
1335 | - $selected_method_of_payment = is_array($selected_method_of_payment) |
|
1336 | - ? array_shift($selected_method_of_payment) |
|
1337 | - : $selected_method_of_payment; |
|
1338 | - $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
1339 | - // store it in the session so that it's available for all subsequent requests including AJAX |
|
1340 | - $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
1341 | - } else { |
|
1342 | - // or is is set in the session ? |
|
1343 | - $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
1344 | - 'selected_method_of_payment' |
|
1345 | - ); |
|
1346 | - } |
|
1347 | - // do ya really really gotta have it? |
|
1348 | - if (empty($selected_method_of_payment) && $required) { |
|
1349 | - EE_Error::add_error( |
|
1350 | - sprintf( |
|
1351 | - esc_html__( |
|
1352 | - 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
1353 | - 'event_espresso' |
|
1354 | - ), |
|
1355 | - '<br/>', |
|
1356 | - '<br/>', |
|
1357 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1358 | - ), |
|
1359 | - __FILE__, |
|
1360 | - __FUNCTION__, |
|
1361 | - __LINE__ |
|
1362 | - ); |
|
1363 | - return null; |
|
1364 | - } |
|
1365 | - return $selected_method_of_payment; |
|
1366 | - } |
|
1367 | - |
|
1368 | - |
|
1369 | - |
|
1370 | - |
|
1371 | - |
|
1372 | - |
|
1373 | - /********************************************************************************************************/ |
|
1374 | - /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
1375 | - /********************************************************************************************************/ |
|
1376 | - /** |
|
1377 | - * switch_payment_method |
|
1378 | - * |
|
1379 | - * @access public |
|
1380 | - * @return string |
|
1381 | - * @throws EE_Error |
|
1382 | - * @throws InvalidArgumentException |
|
1383 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1384 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1385 | - */ |
|
1386 | - public function switch_payment_method() |
|
1387 | - { |
|
1388 | - if (! $this->_verify_payment_method_is_set()) { |
|
1389 | - return false; |
|
1390 | - } |
|
1391 | - if (apply_filters( |
|
1392 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1393 | - false |
|
1394 | - )) { |
|
1395 | - EE_Error::add_success( |
|
1396 | - apply_filters( |
|
1397 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1398 | - sprintf( |
|
1399 | - esc_html__( |
|
1400 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1401 | - 'event_espresso' |
|
1402 | - ), |
|
1403 | - $this->checkout->payment_method->name() |
|
1404 | - ) |
|
1405 | - ) |
|
1406 | - ); |
|
1407 | - } |
|
1408 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1409 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1410 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1411 | - $this->checkout->payment_method |
|
1412 | - ); |
|
1413 | - } |
|
1414 | - // fill form with attendee info if applicable |
|
1415 | - if (apply_filters( |
|
1416 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
1417 | - ( |
|
1418 | - $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1419 | - && $this->checkout->transaction_has_primary_registrant() |
|
1420 | - ), |
|
1421 | - $this->checkout->billing_form, |
|
1422 | - $this->checkout->transaction |
|
1423 | - ) |
|
1424 | - ) { |
|
1425 | - $this->checkout->billing_form->populate_from_attendee( |
|
1426 | - $this->checkout->transaction->primary_registration()->attendee() |
|
1427 | - ); |
|
1428 | - } |
|
1429 | - // and debug content |
|
1430 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1431 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1432 | - ) { |
|
1433 | - $this->checkout->billing_form = |
|
1434 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1435 | - $this->checkout->billing_form |
|
1436 | - ); |
|
1437 | - } |
|
1438 | - // get html and validation rules for form |
|
1439 | - if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
1440 | - $this->checkout->json_response->set_return_data( |
|
1441 | - array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
1442 | - ); |
|
1443 | - // localize validation rules for main form |
|
1444 | - $this->checkout->billing_form->localize_validation_rules(true); |
|
1445 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1446 | - } else { |
|
1447 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
1448 | - } |
|
1449 | - // prevents advancement to next step |
|
1450 | - $this->checkout->continue_reg = false; |
|
1451 | - return true; |
|
1452 | - } |
|
1453 | - |
|
1454 | - |
|
1455 | - /** |
|
1456 | - * _verify_payment_method_is_set |
|
1457 | - * |
|
1458 | - * @return bool |
|
1459 | - * @throws EE_Error |
|
1460 | - * @throws InvalidArgumentException |
|
1461 | - * @throws ReflectionException |
|
1462 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1463 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1464 | - */ |
|
1465 | - protected function _verify_payment_method_is_set() |
|
1466 | - { |
|
1467 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1468 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
1469 | - // how have they chosen to pay? |
|
1470 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1471 | - } else { |
|
1472 | - // choose your own adventure based on method_of_payment |
|
1473 | - switch ($this->checkout->selected_method_of_payment) { |
|
1474 | - case 'events_sold_out': |
|
1475 | - EE_Error::add_attention( |
|
1476 | - apply_filters( |
|
1477 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
1478 | - esc_html__( |
|
1479 | - 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
1480 | - 'event_espresso' |
|
1481 | - ) |
|
1482 | - ), |
|
1483 | - __FILE__, |
|
1484 | - __FUNCTION__, |
|
1485 | - __LINE__ |
|
1486 | - ); |
|
1487 | - return false; |
|
1488 | - break; |
|
1489 | - case 'payments_closed': |
|
1490 | - EE_Error::add_attention( |
|
1491 | - apply_filters( |
|
1492 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
1493 | - esc_html__( |
|
1494 | - 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
1495 | - 'event_espresso' |
|
1496 | - ) |
|
1497 | - ), |
|
1498 | - __FILE__, |
|
1499 | - __FUNCTION__, |
|
1500 | - __LINE__ |
|
1501 | - ); |
|
1502 | - return false; |
|
1503 | - break; |
|
1504 | - case 'no_payment_required': |
|
1505 | - EE_Error::add_attention( |
|
1506 | - apply_filters( |
|
1507 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
1508 | - esc_html__( |
|
1509 | - 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
1510 | - 'event_espresso' |
|
1511 | - ) |
|
1512 | - ), |
|
1513 | - __FILE__, |
|
1514 | - __FUNCTION__, |
|
1515 | - __LINE__ |
|
1516 | - ); |
|
1517 | - return false; |
|
1518 | - break; |
|
1519 | - default: |
|
1520 | - } |
|
1521 | - } |
|
1522 | - // verify payment method |
|
1523 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1524 | - // get payment method for selected method of payment |
|
1525 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1526 | - } |
|
1527 | - return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
1528 | - } |
|
1529 | - |
|
1530 | - |
|
1531 | - |
|
1532 | - /********************************************************************************************************/ |
|
1533 | - /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
1534 | - /********************************************************************************************************/ |
|
1535 | - /** |
|
1536 | - * save_payer_details_via_ajax |
|
1537 | - * |
|
1538 | - * @return void |
|
1539 | - * @throws EE_Error |
|
1540 | - * @throws InvalidArgumentException |
|
1541 | - * @throws ReflectionException |
|
1542 | - * @throws RuntimeException |
|
1543 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1544 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1545 | - */ |
|
1546 | - public function save_payer_details_via_ajax() |
|
1547 | - { |
|
1548 | - if (! $this->_verify_payment_method_is_set()) { |
|
1549 | - return; |
|
1550 | - } |
|
1551 | - // generate billing form for selected method of payment if it hasn't been done already |
|
1552 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1553 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1554 | - $this->checkout->payment_method |
|
1555 | - ); |
|
1556 | - } |
|
1557 | - // generate primary attendee from payer info if applicable |
|
1558 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
1559 | - $attendee = $this->_create_attendee_from_request_data(); |
|
1560 | - if ($attendee instanceof EE_Attendee) { |
|
1561 | - foreach ($this->checkout->transaction->registrations() as $registration) { |
|
1562 | - if ($registration->is_primary_registrant()) { |
|
1563 | - $this->checkout->primary_attendee_obj = $attendee; |
|
1564 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
1565 | - $registration->set_attendee_id($attendee->ID()); |
|
1566 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1567 | - } |
|
1568 | - } |
|
1569 | - } |
|
1570 | - } |
|
1571 | - } |
|
1572 | - |
|
1573 | - |
|
1574 | - /** |
|
1575 | - * create_attendee_from_request_data |
|
1576 | - * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
1577 | - * |
|
1578 | - * @return EE_Attendee |
|
1579 | - * @throws EE_Error |
|
1580 | - * @throws InvalidArgumentException |
|
1581 | - * @throws ReflectionException |
|
1582 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1583 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1584 | - */ |
|
1585 | - protected function _create_attendee_from_request_data() |
|
1586 | - { |
|
1587 | - // get State ID |
|
1588 | - $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
1589 | - if (! empty($STA_ID)) { |
|
1590 | - // can we get state object from name ? |
|
1591 | - EE_Registry::instance()->load_model('State'); |
|
1592 | - $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
1593 | - $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
1594 | - } |
|
1595 | - // get Country ISO |
|
1596 | - $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
1597 | - if (! empty($CNT_ISO)) { |
|
1598 | - // can we get country object from name ? |
|
1599 | - EE_Registry::instance()->load_model('Country'); |
|
1600 | - $country = EEM_Country::instance()->get_col( |
|
1601 | - array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
1602 | - 'CNT_ISO' |
|
1603 | - ); |
|
1604 | - $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
1605 | - } |
|
1606 | - // grab attendee data |
|
1607 | - $attendee_data = array( |
|
1608 | - 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
1609 | - 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
1610 | - 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
1611 | - 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
1612 | - 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
1613 | - 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
1614 | - 'STA_ID' => $STA_ID, |
|
1615 | - 'CNT_ISO' => $CNT_ISO, |
|
1616 | - 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
1617 | - 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
1618 | - ); |
|
1619 | - // validate the email address since it is the most important piece of info |
|
1620 | - if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
1621 | - EE_Error::add_error( |
|
1622 | - esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
1623 | - __FILE__, |
|
1624 | - __FUNCTION__, |
|
1625 | - __LINE__ |
|
1626 | - ); |
|
1627 | - } |
|
1628 | - // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
1629 | - // AND email address |
|
1630 | - if (! empty($attendee_data['ATT_fname']) |
|
1631 | - && ! empty($attendee_data['ATT_lname']) |
|
1632 | - && ! empty($attendee_data['ATT_email']) |
|
1633 | - ) { |
|
1634 | - $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
1635 | - array( |
|
1636 | - 'ATT_fname' => $attendee_data['ATT_fname'], |
|
1637 | - 'ATT_lname' => $attendee_data['ATT_lname'], |
|
1638 | - 'ATT_email' => $attendee_data['ATT_email'], |
|
1639 | - ) |
|
1640 | - ); |
|
1641 | - if ($existing_attendee instanceof EE_Attendee) { |
|
1642 | - return $existing_attendee; |
|
1643 | - } |
|
1644 | - } |
|
1645 | - // no existing attendee? kk let's create a new one |
|
1646 | - // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
1647 | - // don't exist |
|
1648 | - $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
1649 | - ? $attendee_data['ATT_fname'] |
|
1650 | - : $attendee_data['ATT_email']; |
|
1651 | - $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
1652 | - ? $attendee_data['ATT_lname'] |
|
1653 | - : $attendee_data['ATT_email']; |
|
1654 | - return EE_Attendee::new_instance($attendee_data); |
|
1655 | - } |
|
1656 | - |
|
1657 | - |
|
1658 | - |
|
1659 | - /********************************************************************************************************/ |
|
1660 | - /**************************************** PROCESS REG STEP *****************************************/ |
|
1661 | - /********************************************************************************************************/ |
|
1662 | - /** |
|
1663 | - * process_reg_step |
|
1664 | - * |
|
1665 | - * @return bool |
|
1666 | - * @throws EE_Error |
|
1667 | - * @throws InvalidArgumentException |
|
1668 | - * @throws ReflectionException |
|
1669 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1670 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1671 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1672 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1673 | - */ |
|
1674 | - public function process_reg_step() |
|
1675 | - { |
|
1676 | - // how have they chosen to pay? |
|
1677 | - $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
1678 | - ? 'no_payment_required' |
|
1679 | - : $this->_get_selected_method_of_payment(true); |
|
1680 | - // choose your own adventure based on method_of_payment |
|
1681 | - switch ($this->checkout->selected_method_of_payment) { |
|
1682 | - case 'events_sold_out': |
|
1683 | - $this->checkout->redirect = true; |
|
1684 | - $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
1685 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1686 | - // mark this reg step as completed |
|
1687 | - $this->set_completed(); |
|
1688 | - return false; |
|
1689 | - break; |
|
1690 | - |
|
1691 | - case 'payments_closed': |
|
1692 | - if (apply_filters( |
|
1693 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
1694 | - false |
|
1695 | - )) { |
|
1696 | - EE_Error::add_success( |
|
1697 | - esc_html__('no payment required at this time.', 'event_espresso'), |
|
1698 | - __FILE__, |
|
1699 | - __FUNCTION__, |
|
1700 | - __LINE__ |
|
1701 | - ); |
|
1702 | - } |
|
1703 | - // mark this reg step as completed |
|
1704 | - $this->set_completed(); |
|
1705 | - return true; |
|
1706 | - break; |
|
1707 | - |
|
1708 | - case 'no_payment_required': |
|
1709 | - if (apply_filters( |
|
1710 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
1711 | - false |
|
1712 | - )) { |
|
1713 | - EE_Error::add_success( |
|
1714 | - esc_html__('no payment required.', 'event_espresso'), |
|
1715 | - __FILE__, |
|
1716 | - __FUNCTION__, |
|
1717 | - __LINE__ |
|
1718 | - ); |
|
1719 | - } |
|
1720 | - // mark this reg step as completed |
|
1721 | - $this->set_completed(); |
|
1722 | - return true; |
|
1723 | - break; |
|
1724 | - |
|
1725 | - default: |
|
1726 | - $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
1727 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
1728 | - ); |
|
1729 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
1730 | - $registrations, |
|
1731 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
1732 | - ); |
|
1733 | - // calculate difference between the two arrays |
|
1734 | - $registrations = array_diff($registrations, $ejected_registrations); |
|
1735 | - if (empty($registrations)) { |
|
1736 | - $this->_redirect_because_event_sold_out(); |
|
1737 | - return false; |
|
1738 | - } |
|
1739 | - $payment_successful = $this->_process_payment(); |
|
1740 | - if ($payment_successful) { |
|
1741 | - $this->checkout->continue_reg = true; |
|
1742 | - $this->_maybe_set_completed($this->checkout->payment_method); |
|
1743 | - } else { |
|
1744 | - $this->checkout->continue_reg = false; |
|
1745 | - } |
|
1746 | - return $payment_successful; |
|
1747 | - } |
|
1748 | - } |
|
1749 | - |
|
1750 | - |
|
1751 | - /** |
|
1752 | - * _redirect_because_event_sold_out |
|
1753 | - * |
|
1754 | - * @access protected |
|
1755 | - * @return void |
|
1756 | - */ |
|
1757 | - protected function _redirect_because_event_sold_out() |
|
1758 | - { |
|
1759 | - $this->checkout->continue_reg = false; |
|
1760 | - // set redirect URL |
|
1761 | - $this->checkout->redirect_url = add_query_arg( |
|
1762 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1763 | - $this->checkout->current_step->reg_step_url() |
|
1764 | - ); |
|
1765 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1766 | - } |
|
1767 | - |
|
1768 | - |
|
1769 | - /** |
|
1770 | - * _maybe_set_completed |
|
1771 | - * |
|
1772 | - * @access protected |
|
1773 | - * @param \EE_Payment_Method $payment_method |
|
1774 | - * @return void |
|
1775 | - * @throws \EE_Error |
|
1776 | - */ |
|
1777 | - protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
1778 | - { |
|
1779 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
1780 | - case EE_PMT_Base::offsite: |
|
1781 | - break; |
|
1782 | - case EE_PMT_Base::onsite: |
|
1783 | - case EE_PMT_Base::offline: |
|
1784 | - // mark this reg step as completed |
|
1785 | - $this->set_completed(); |
|
1786 | - break; |
|
1787 | - } |
|
1788 | - } |
|
1789 | - |
|
1790 | - |
|
1791 | - /** |
|
1792 | - * update_reg_step |
|
1793 | - * this is the final step after a user revisits the site to retry a payment |
|
1794 | - * |
|
1795 | - * @return bool |
|
1796 | - * @throws EE_Error |
|
1797 | - * @throws InvalidArgumentException |
|
1798 | - * @throws ReflectionException |
|
1799 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1800 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1801 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1802 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1803 | - */ |
|
1804 | - public function update_reg_step() |
|
1805 | - { |
|
1806 | - $success = true; |
|
1807 | - // if payment required |
|
1808 | - if ($this->checkout->transaction->total() > 0) { |
|
1809 | - do_action( |
|
1810 | - 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
1811 | - $this->checkout->transaction |
|
1812 | - ); |
|
1813 | - // attempt payment via payment method |
|
1814 | - $success = $this->process_reg_step(); |
|
1815 | - } |
|
1816 | - if ($success && ! $this->checkout->redirect) { |
|
1817 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
1818 | - $this->checkout->transaction->ID() |
|
1819 | - ); |
|
1820 | - // set return URL |
|
1821 | - $this->checkout->redirect_url = add_query_arg( |
|
1822 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1823 | - $this->checkout->thank_you_page_url |
|
1824 | - ); |
|
1825 | - } |
|
1826 | - return $success; |
|
1827 | - } |
|
1828 | - |
|
1829 | - |
|
1830 | - /** |
|
1831 | - * _process_payment |
|
1832 | - * |
|
1833 | - * @access private |
|
1834 | - * @return bool |
|
1835 | - * @throws EE_Error |
|
1836 | - * @throws InvalidArgumentException |
|
1837 | - * @throws ReflectionException |
|
1838 | - * @throws RuntimeException |
|
1839 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1840 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1841 | - */ |
|
1842 | - private function _process_payment() |
|
1843 | - { |
|
1844 | - // basically confirm that the event hasn't sold out since they hit the page |
|
1845 | - if (! $this->_last_second_ticket_verifications()) { |
|
1846 | - return false; |
|
1847 | - } |
|
1848 | - // ya gotta make a choice man |
|
1849 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
1850 | - $this->checkout->json_response->set_plz_select_method_of_payment( |
|
1851 | - esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
1852 | - ); |
|
1853 | - return false; |
|
1854 | - } |
|
1855 | - // get EE_Payment_Method object |
|
1856 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1857 | - return false; |
|
1858 | - } |
|
1859 | - // setup billing form |
|
1860 | - if ($this->checkout->payment_method->is_on_site()) { |
|
1861 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1862 | - $this->checkout->payment_method |
|
1863 | - ); |
|
1864 | - // bad billing form ? |
|
1865 | - if (! $this->_billing_form_is_valid()) { |
|
1866 | - return false; |
|
1867 | - } |
|
1868 | - } |
|
1869 | - // ensure primary registrant has been fully processed |
|
1870 | - if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1871 | - return false; |
|
1872 | - } |
|
1873 | - // if session is close to expiring (under 10 minutes by default) |
|
1874 | - if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
1875 | - // add some time to session expiration so that payment can be completed |
|
1876 | - EE_Registry::instance()->SSN->extend_expiration(); |
|
1877 | - } |
|
1878 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
1879 | - // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
1880 | - // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
1881 | - // for events with a default reg status of Approved |
|
1882 | - // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
1883 | - // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
1884 | - // ); |
|
1885 | - // attempt payment |
|
1886 | - $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
1887 | - // process results |
|
1888 | - $payment = $this->_validate_payment($payment); |
|
1889 | - $payment = $this->_post_payment_processing($payment); |
|
1890 | - // verify payment |
|
1891 | - if ($payment instanceof EE_Payment) { |
|
1892 | - // store that for later |
|
1893 | - $this->checkout->payment = $payment; |
|
1894 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
1895 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1896 | - $payment_status = $payment->status(); |
|
1897 | - if ($payment_status === EEM_Payment::status_id_approved |
|
1898 | - || $payment_status === EEM_Payment::status_id_pending |
|
1899 | - ) { |
|
1900 | - return true; |
|
1901 | - } else { |
|
1902 | - return false; |
|
1903 | - } |
|
1904 | - } elseif ($payment === true) { |
|
1905 | - // please note that offline payment methods will NOT make a payment, |
|
1906 | - // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
1907 | - $this->checkout->payment = $payment; |
|
1908 | - return true; |
|
1909 | - } |
|
1910 | - // where's my money? |
|
1911 | - return false; |
|
1912 | - } |
|
1913 | - |
|
1914 | - |
|
1915 | - /** |
|
1916 | - * _last_second_ticket_verifications |
|
1917 | - * |
|
1918 | - * @access public |
|
1919 | - * @return bool |
|
1920 | - * @throws EE_Error |
|
1921 | - */ |
|
1922 | - protected function _last_second_ticket_verifications() |
|
1923 | - { |
|
1924 | - // don't bother re-validating if not a return visit |
|
1925 | - if (! $this->checkout->revisit) { |
|
1926 | - return true; |
|
1927 | - } |
|
1928 | - $registrations = $this->checkout->transaction->registrations(); |
|
1929 | - if (empty($registrations)) { |
|
1930 | - return false; |
|
1931 | - } |
|
1932 | - foreach ($registrations as $registration) { |
|
1933 | - if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
1934 | - $event = $registration->event_obj(); |
|
1935 | - if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
1936 | - EE_Error::add_error( |
|
1937 | - apply_filters( |
|
1938 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
1939 | - sprintf( |
|
1940 | - esc_html__( |
|
1941 | - 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
1942 | - 'event_espresso' |
|
1943 | - ), |
|
1944 | - $event->name() |
|
1945 | - ) |
|
1946 | - ), |
|
1947 | - __FILE__, |
|
1948 | - __FUNCTION__, |
|
1949 | - __LINE__ |
|
1950 | - ); |
|
1951 | - return false; |
|
1952 | - } |
|
1953 | - } |
|
1954 | - } |
|
1955 | - return true; |
|
1956 | - } |
|
1957 | - |
|
1958 | - |
|
1959 | - /** |
|
1960 | - * redirect_form |
|
1961 | - * |
|
1962 | - * @access public |
|
1963 | - * @return bool |
|
1964 | - * @throws EE_Error |
|
1965 | - * @throws InvalidArgumentException |
|
1966 | - * @throws ReflectionException |
|
1967 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1968 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1969 | - */ |
|
1970 | - public function redirect_form() |
|
1971 | - { |
|
1972 | - $payment_method_billing_info = $this->_payment_method_billing_info( |
|
1973 | - $this->_get_payment_method_for_selected_method_of_payment() |
|
1974 | - ); |
|
1975 | - $html = $payment_method_billing_info->get_html(); |
|
1976 | - $html .= $this->checkout->redirect_form; |
|
1977 | - EE_Registry::instance()->REQ->add_output($html); |
|
1978 | - return true; |
|
1979 | - } |
|
1980 | - |
|
1981 | - |
|
1982 | - /** |
|
1983 | - * _billing_form_is_valid |
|
1984 | - * |
|
1985 | - * @access private |
|
1986 | - * @return bool |
|
1987 | - * @throws \EE_Error |
|
1988 | - */ |
|
1989 | - private function _billing_form_is_valid() |
|
1990 | - { |
|
1991 | - if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1992 | - return true; |
|
1993 | - } |
|
1994 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
1995 | - if ($this->checkout->billing_form->was_submitted()) { |
|
1996 | - $this->checkout->billing_form->receive_form_submission(); |
|
1997 | - if ($this->checkout->billing_form->is_valid()) { |
|
1998 | - return true; |
|
1999 | - } |
|
2000 | - $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
2001 | - $error_strings = array(); |
|
2002 | - foreach ($validation_errors as $validation_error) { |
|
2003 | - if ($validation_error instanceof EE_Validation_Error) { |
|
2004 | - $form_section = $validation_error->get_form_section(); |
|
2005 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
2006 | - $label = $form_section->html_label_text(); |
|
2007 | - } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
2008 | - $label = $form_section->name(); |
|
2009 | - } else { |
|
2010 | - $label = esc_html__('Validation Error', 'event_espresso'); |
|
2011 | - } |
|
2012 | - $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
2013 | - } |
|
2014 | - } |
|
2015 | - EE_Error::add_error( |
|
2016 | - sprintf( |
|
2017 | - esc_html__( |
|
2018 | - 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
2019 | - 'event_espresso' |
|
2020 | - ), |
|
2021 | - '<br/>', |
|
2022 | - implode('<br/>', $error_strings) |
|
2023 | - ), |
|
2024 | - __FILE__, |
|
2025 | - __FUNCTION__, |
|
2026 | - __LINE__ |
|
2027 | - ); |
|
2028 | - } else { |
|
2029 | - EE_Error::add_error( |
|
2030 | - esc_html__( |
|
2031 | - 'The billing form was not submitted or something prevented it\'s submission.', |
|
2032 | - 'event_espresso' |
|
2033 | - ), |
|
2034 | - __FILE__, |
|
2035 | - __FUNCTION__, |
|
2036 | - __LINE__ |
|
2037 | - ); |
|
2038 | - } |
|
2039 | - } else { |
|
2040 | - EE_Error::add_error( |
|
2041 | - esc_html__( |
|
2042 | - 'The submitted billing form is invalid possibly due to a technical reason.', |
|
2043 | - 'event_espresso' |
|
2044 | - ), |
|
2045 | - __FILE__, |
|
2046 | - __FUNCTION__, |
|
2047 | - __LINE__ |
|
2048 | - ); |
|
2049 | - } |
|
2050 | - return false; |
|
2051 | - } |
|
2052 | - |
|
2053 | - |
|
2054 | - /** |
|
2055 | - * _setup_primary_registrant_prior_to_payment |
|
2056 | - * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
2057 | - * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
2058 | - * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
2059 | - * yet) |
|
2060 | - * |
|
2061 | - * @access private |
|
2062 | - * @return bool |
|
2063 | - * @throws EE_Error |
|
2064 | - * @throws InvalidArgumentException |
|
2065 | - * @throws ReflectionException |
|
2066 | - * @throws RuntimeException |
|
2067 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2068 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2069 | - */ |
|
2070 | - private function _setup_primary_registrant_prior_to_payment() |
|
2071 | - { |
|
2072 | - // check if transaction has a primary registrant and that it has a related Attendee object |
|
2073 | - // if not, then we need to at least gather some primary registrant data before attempting payment |
|
2074 | - if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
2075 | - && ! $this->checkout->transaction_has_primary_registrant() |
|
2076 | - && ! $this->_capture_primary_registration_data_from_billing_form() |
|
2077 | - ) { |
|
2078 | - return false; |
|
2079 | - } |
|
2080 | - // because saving an object clears it's cache, we need to do the chevy shuffle |
|
2081 | - // grab the primary_registration object |
|
2082 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2083 | - // at this point we'll consider a TXN to not have been failed |
|
2084 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
2085 | - // save the TXN ( which clears cached copy of primary_registration) |
|
2086 | - $this->checkout->transaction->save(); |
|
2087 | - // grab TXN ID and save it to the primary_registration |
|
2088 | - $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
2089 | - // save what we have so far |
|
2090 | - $primary_registration->save(); |
|
2091 | - return true; |
|
2092 | - } |
|
2093 | - |
|
2094 | - |
|
2095 | - /** |
|
2096 | - * _capture_primary_registration_data_from_billing_form |
|
2097 | - * |
|
2098 | - * @access private |
|
2099 | - * @return bool |
|
2100 | - * @throws EE_Error |
|
2101 | - * @throws InvalidArgumentException |
|
2102 | - * @throws ReflectionException |
|
2103 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2104 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2105 | - */ |
|
2106 | - private function _capture_primary_registration_data_from_billing_form() |
|
2107 | - { |
|
2108 | - // convert billing form data into an attendee |
|
2109 | - $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
2110 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2111 | - EE_Error::add_error( |
|
2112 | - sprintf( |
|
2113 | - esc_html__( |
|
2114 | - 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2115 | - 'event_espresso' |
|
2116 | - ), |
|
2117 | - '<br/>', |
|
2118 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2119 | - ), |
|
2120 | - __FILE__, |
|
2121 | - __FUNCTION__, |
|
2122 | - __LINE__ |
|
2123 | - ); |
|
2124 | - return false; |
|
2125 | - } |
|
2126 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2127 | - if (! $primary_registration instanceof EE_Registration) { |
|
2128 | - EE_Error::add_error( |
|
2129 | - sprintf( |
|
2130 | - esc_html__( |
|
2131 | - 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2132 | - 'event_espresso' |
|
2133 | - ), |
|
2134 | - '<br/>', |
|
2135 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2136 | - ), |
|
2137 | - __FILE__, |
|
2138 | - __FUNCTION__, |
|
2139 | - __LINE__ |
|
2140 | - ); |
|
2141 | - return false; |
|
2142 | - } |
|
2143 | - if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
2144 | - instanceof |
|
2145 | - EE_Attendee |
|
2146 | - ) { |
|
2147 | - EE_Error::add_error( |
|
2148 | - sprintf( |
|
2149 | - esc_html__( |
|
2150 | - 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2151 | - 'event_espresso' |
|
2152 | - ), |
|
2153 | - '<br/>', |
|
2154 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2155 | - ), |
|
2156 | - __FILE__, |
|
2157 | - __FUNCTION__, |
|
2158 | - __LINE__ |
|
2159 | - ); |
|
2160 | - return false; |
|
2161 | - } |
|
2162 | - /** @type EE_Registration_Processor $registration_processor */ |
|
2163 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
2164 | - // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
2165 | - $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
2166 | - return true; |
|
2167 | - } |
|
2168 | - |
|
2169 | - |
|
2170 | - /** |
|
2171 | - * _get_payment_method_for_selected_method_of_payment |
|
2172 | - * retrieves a valid payment method |
|
2173 | - * |
|
2174 | - * @access public |
|
2175 | - * @return EE_Payment_Method |
|
2176 | - * @throws EE_Error |
|
2177 | - * @throws InvalidArgumentException |
|
2178 | - * @throws ReflectionException |
|
2179 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2180 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2181 | - */ |
|
2182 | - private function _get_payment_method_for_selected_method_of_payment() |
|
2183 | - { |
|
2184 | - if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
2185 | - $this->_redirect_because_event_sold_out(); |
|
2186 | - return null; |
|
2187 | - } |
|
2188 | - // get EE_Payment_Method object |
|
2189 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
2190 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2191 | - } else { |
|
2192 | - // load EEM_Payment_Method |
|
2193 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
2194 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
2195 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
2196 | - $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
2197 | - } |
|
2198 | - // verify $payment_method |
|
2199 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
2200 | - // not a payment |
|
2201 | - EE_Error::add_error( |
|
2202 | - sprintf( |
|
2203 | - esc_html__( |
|
2204 | - 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2205 | - 'event_espresso' |
|
2206 | - ), |
|
2207 | - '<br/>', |
|
2208 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2209 | - ), |
|
2210 | - __FILE__, |
|
2211 | - __FUNCTION__, |
|
2212 | - __LINE__ |
|
2213 | - ); |
|
2214 | - return null; |
|
2215 | - } |
|
2216 | - // and verify it has a valid Payment_Method Type object |
|
2217 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2218 | - // not a payment |
|
2219 | - EE_Error::add_error( |
|
2220 | - sprintf( |
|
2221 | - esc_html__( |
|
2222 | - 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2223 | - 'event_espresso' |
|
2224 | - ), |
|
2225 | - '<br/>', |
|
2226 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2227 | - ), |
|
2228 | - __FILE__, |
|
2229 | - __FUNCTION__, |
|
2230 | - __LINE__ |
|
2231 | - ); |
|
2232 | - return null; |
|
2233 | - } |
|
2234 | - return $payment_method; |
|
2235 | - } |
|
2236 | - |
|
2237 | - |
|
2238 | - /** |
|
2239 | - * _attempt_payment |
|
2240 | - * |
|
2241 | - * @access private |
|
2242 | - * @type EE_Payment_Method $payment_method |
|
2243 | - * @return mixed EE_Payment | boolean |
|
2244 | - * @throws EE_Error |
|
2245 | - * @throws InvalidArgumentException |
|
2246 | - * @throws ReflectionException |
|
2247 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2248 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2249 | - */ |
|
2250 | - private function _attempt_payment(EE_Payment_Method $payment_method) |
|
2251 | - { |
|
2252 | - $payment = null; |
|
2253 | - $this->checkout->transaction->save(); |
|
2254 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2255 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
2256 | - return false; |
|
2257 | - } |
|
2258 | - try { |
|
2259 | - $payment_processor->set_revisit($this->checkout->revisit); |
|
2260 | - // generate payment object |
|
2261 | - $payment = $payment_processor->process_payment( |
|
2262 | - $payment_method, |
|
2263 | - $this->checkout->transaction, |
|
2264 | - $this->checkout->amount_owing, |
|
2265 | - $this->checkout->billing_form, |
|
2266 | - $this->_get_return_url($payment_method), |
|
2267 | - 'CART', |
|
2268 | - $this->checkout->admin_request, |
|
2269 | - true, |
|
2270 | - $this->reg_step_url() |
|
2271 | - ); |
|
2272 | - } catch (Exception $e) { |
|
2273 | - $this->_handle_payment_processor_exception($e); |
|
2274 | - } |
|
2275 | - return $payment; |
|
2276 | - } |
|
2277 | - |
|
2278 | - |
|
2279 | - /** |
|
2280 | - * _handle_payment_processor_exception |
|
2281 | - * |
|
2282 | - * @access protected |
|
2283 | - * @param \Exception $e |
|
2284 | - * @return void |
|
2285 | - * @throws EE_Error |
|
2286 | - * @throws InvalidArgumentException |
|
2287 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2288 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2289 | - */ |
|
2290 | - protected function _handle_payment_processor_exception(Exception $e) |
|
2291 | - { |
|
2292 | - EE_Error::add_error( |
|
2293 | - sprintf( |
|
2294 | - esc_html__( |
|
2295 | - 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
2296 | - 'event_espresso' |
|
2297 | - ), |
|
2298 | - '<br/>', |
|
2299 | - EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
2300 | - $e->getMessage(), |
|
2301 | - $e->getFile(), |
|
2302 | - $e->getLine() |
|
2303 | - ), |
|
2304 | - __FILE__, |
|
2305 | - __FUNCTION__, |
|
2306 | - __LINE__ |
|
2307 | - ); |
|
2308 | - } |
|
2309 | - |
|
2310 | - |
|
2311 | - /** |
|
2312 | - * _get_return_url |
|
2313 | - * |
|
2314 | - * @access protected |
|
2315 | - * @param \EE_Payment_Method $payment_method |
|
2316 | - * @return string |
|
2317 | - * @throws \EE_Error |
|
2318 | - */ |
|
2319 | - protected function _get_return_url(EE_Payment_Method $payment_method) |
|
2320 | - { |
|
2321 | - $return_url = ''; |
|
2322 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
2323 | - case EE_PMT_Base::offsite: |
|
2324 | - $return_url = add_query_arg( |
|
2325 | - array( |
|
2326 | - 'action' => 'process_gateway_response', |
|
2327 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2328 | - 'spco_txn' => $this->checkout->transaction->ID(), |
|
2329 | - ), |
|
2330 | - $this->reg_step_url() |
|
2331 | - ); |
|
2332 | - break; |
|
2333 | - case EE_PMT_Base::onsite: |
|
2334 | - case EE_PMT_Base::offline: |
|
2335 | - $return_url = $this->checkout->next_step->reg_step_url(); |
|
2336 | - break; |
|
2337 | - } |
|
2338 | - return $return_url; |
|
2339 | - } |
|
2340 | - |
|
2341 | - |
|
2342 | - /** |
|
2343 | - * _validate_payment |
|
2344 | - * |
|
2345 | - * @access private |
|
2346 | - * @param EE_Payment $payment |
|
2347 | - * @return EE_Payment|FALSE |
|
2348 | - * @throws EE_Error |
|
2349 | - * @throws InvalidArgumentException |
|
2350 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2351 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2352 | - */ |
|
2353 | - private function _validate_payment($payment = null) |
|
2354 | - { |
|
2355 | - if ($this->checkout->payment_method->is_off_line()) { |
|
2356 | - return true; |
|
2357 | - } |
|
2358 | - // verify payment object |
|
2359 | - if (! $payment instanceof EE_Payment) { |
|
2360 | - // not a payment |
|
2361 | - EE_Error::add_error( |
|
2362 | - sprintf( |
|
2363 | - esc_html__( |
|
2364 | - 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
2365 | - 'event_espresso' |
|
2366 | - ), |
|
2367 | - '<br/>', |
|
2368 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2369 | - ), |
|
2370 | - __FILE__, |
|
2371 | - __FUNCTION__, |
|
2372 | - __LINE__ |
|
2373 | - ); |
|
2374 | - return false; |
|
2375 | - } |
|
2376 | - return $payment; |
|
2377 | - } |
|
2378 | - |
|
2379 | - |
|
2380 | - /** |
|
2381 | - * _post_payment_processing |
|
2382 | - * |
|
2383 | - * @access private |
|
2384 | - * @param EE_Payment|bool $payment |
|
2385 | - * @return bool |
|
2386 | - * @throws EE_Error |
|
2387 | - * @throws InvalidArgumentException |
|
2388 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2389 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2390 | - */ |
|
2391 | - private function _post_payment_processing($payment = null) |
|
2392 | - { |
|
2393 | - // Off-Line payment? |
|
2394 | - if ($payment === true) { |
|
2395 | - // $this->_setup_redirect_for_next_step(); |
|
2396 | - return true; |
|
2397 | - // On-Site payment? |
|
2398 | - } elseif ($this->checkout->payment_method->is_on_site()) { |
|
2399 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2400 | - // $this->_setup_redirect_for_next_step(); |
|
2401 | - $this->checkout->continue_reg = false; |
|
2402 | - } |
|
2403 | - // Off-Site payment? |
|
2404 | - } elseif ($this->checkout->payment_method->is_off_site()) { |
|
2405 | - // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
2406 | - if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
2407 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
2408 | - $this->checkout->redirect = true; |
|
2409 | - $this->checkout->redirect_form = $payment->redirect_form(); |
|
2410 | - $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
2411 | - // set JSON response |
|
2412 | - $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
2413 | - // and lastly, let's bump the payment status to pending |
|
2414 | - $payment->set_status(EEM_Payment::status_id_pending); |
|
2415 | - $payment->save(); |
|
2416 | - } else { |
|
2417 | - // not a payment |
|
2418 | - $this->checkout->continue_reg = false; |
|
2419 | - EE_Error::add_error( |
|
2420 | - sprintf( |
|
2421 | - esc_html__( |
|
2422 | - 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
2423 | - 'event_espresso' |
|
2424 | - ), |
|
2425 | - '<br/>', |
|
2426 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2427 | - ), |
|
2428 | - __FILE__, |
|
2429 | - __FUNCTION__, |
|
2430 | - __LINE__ |
|
2431 | - ); |
|
2432 | - } |
|
2433 | - } else { |
|
2434 | - // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
2435 | - $this->checkout->continue_reg = false; |
|
2436 | - return false; |
|
2437 | - } |
|
2438 | - return $payment; |
|
2439 | - } |
|
2440 | - |
|
2441 | - |
|
2442 | - /** |
|
2443 | - * _process_payment_status |
|
2444 | - * |
|
2445 | - * @access private |
|
2446 | - * @type EE_Payment $payment |
|
2447 | - * @param string $payment_occurs |
|
2448 | - * @return bool |
|
2449 | - * @throws EE_Error |
|
2450 | - * @throws InvalidArgumentException |
|
2451 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2452 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2453 | - */ |
|
2454 | - private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
2455 | - { |
|
2456 | - // off-line payment? carry on |
|
2457 | - if ($payment_occurs === EE_PMT_Base::offline) { |
|
2458 | - return true; |
|
2459 | - } |
|
2460 | - // verify payment validity |
|
2461 | - if ($payment instanceof EE_Payment) { |
|
2462 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
2463 | - $msg = $payment->gateway_response(); |
|
2464 | - // check results |
|
2465 | - switch ($payment->status()) { |
|
2466 | - // good payment |
|
2467 | - case EEM_Payment::status_id_approved: |
|
2468 | - EE_Error::add_success( |
|
2469 | - esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
2470 | - __FILE__, |
|
2471 | - __FUNCTION__, |
|
2472 | - __LINE__ |
|
2473 | - ); |
|
2474 | - return true; |
|
2475 | - break; |
|
2476 | - // slow payment |
|
2477 | - case EEM_Payment::status_id_pending: |
|
2478 | - if (empty($msg)) { |
|
2479 | - $msg = esc_html__( |
|
2480 | - 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
2481 | - 'event_espresso' |
|
2482 | - ); |
|
2483 | - } |
|
2484 | - EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2485 | - return true; |
|
2486 | - break; |
|
2487 | - // don't wanna payment |
|
2488 | - case EEM_Payment::status_id_cancelled: |
|
2489 | - if (empty($msg)) { |
|
2490 | - $msg = _n( |
|
2491 | - 'Payment cancelled. Please try again.', |
|
2492 | - 'Payment cancelled. Please try again or select another method of payment.', |
|
2493 | - count($this->checkout->available_payment_methods), |
|
2494 | - 'event_espresso' |
|
2495 | - ); |
|
2496 | - } |
|
2497 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2498 | - return false; |
|
2499 | - break; |
|
2500 | - // not enough payment |
|
2501 | - case EEM_Payment::status_id_declined: |
|
2502 | - if (empty($msg)) { |
|
2503 | - $msg = _n( |
|
2504 | - 'We\'re sorry but your payment was declined. Please try again.', |
|
2505 | - 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
2506 | - count($this->checkout->available_payment_methods), |
|
2507 | - 'event_espresso' |
|
2508 | - ); |
|
2509 | - } |
|
2510 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2511 | - return false; |
|
2512 | - break; |
|
2513 | - // bad payment |
|
2514 | - case EEM_Payment::status_id_failed: |
|
2515 | - if (! empty($msg)) { |
|
2516 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2517 | - return false; |
|
2518 | - } |
|
2519 | - // default to error below |
|
2520 | - break; |
|
2521 | - } |
|
2522 | - } |
|
2523 | - // off-site payment gateway responses are too unreliable, so let's just assume that |
|
2524 | - // the payment processing is just running slower than the registrant's request |
|
2525 | - if ($payment_occurs === EE_PMT_Base::offsite) { |
|
2526 | - return true; |
|
2527 | - } |
|
2528 | - EE_Error::add_error( |
|
2529 | - sprintf( |
|
2530 | - esc_html__( |
|
2531 | - 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2532 | - 'event_espresso' |
|
2533 | - ), |
|
2534 | - '<br/>', |
|
2535 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2536 | - ), |
|
2537 | - __FILE__, |
|
2538 | - __FUNCTION__, |
|
2539 | - __LINE__ |
|
2540 | - ); |
|
2541 | - return false; |
|
2542 | - } |
|
2543 | - |
|
2544 | - |
|
2545 | - |
|
2546 | - |
|
2547 | - |
|
2548 | - |
|
2549 | - /********************************************************************************************************/ |
|
2550 | - /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
2551 | - /********************************************************************************************************/ |
|
2552 | - /** |
|
2553 | - * process_gateway_response |
|
2554 | - * this is the return point for Off-Site Payment Methods |
|
2555 | - * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
2556 | - * otherwise, it will load up the last payment made for the TXN. |
|
2557 | - * If the payment retrieved looks good, it will then either: |
|
2558 | - * complete the current step and allow advancement to the next reg step |
|
2559 | - * or present the payment options again |
|
2560 | - * |
|
2561 | - * @access private |
|
2562 | - * @return EE_Payment|FALSE |
|
2563 | - * @throws EE_Error |
|
2564 | - * @throws InvalidArgumentException |
|
2565 | - * @throws ReflectionException |
|
2566 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2567 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2568 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2569 | - */ |
|
2570 | - public function process_gateway_response() |
|
2571 | - { |
|
2572 | - $payment = null; |
|
2573 | - // how have they chosen to pay? |
|
2574 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
2575 | - // get EE_Payment_Method object |
|
2576 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2577 | - $this->checkout->continue_reg = false; |
|
2578 | - return false; |
|
2579 | - } |
|
2580 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
2581 | - return false; |
|
2582 | - } |
|
2583 | - $this->_validate_offsite_return(); |
|
2584 | - // DEBUG LOG |
|
2585 | - // $this->checkout->log( |
|
2586 | - // __CLASS__, |
|
2587 | - // __FUNCTION__, |
|
2588 | - // __LINE__, |
|
2589 | - // array( |
|
2590 | - // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2591 | - // 'payment_method' => $this->checkout->payment_method, |
|
2592 | - // ), |
|
2593 | - // true |
|
2594 | - // ); |
|
2595 | - // verify TXN |
|
2596 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
2597 | - $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
2598 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
2599 | - $this->checkout->continue_reg = false; |
|
2600 | - return false; |
|
2601 | - } |
|
2602 | - $payment = $this->_process_off_site_payment($gateway); |
|
2603 | - $payment = $this->_process_cancelled_payments($payment); |
|
2604 | - $payment = $this->_validate_payment($payment); |
|
2605 | - // if payment was not declined by the payment gateway or cancelled by the registrant |
|
2606 | - if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
2607 | - // $this->_setup_redirect_for_next_step(); |
|
2608 | - // store that for later |
|
2609 | - $this->checkout->payment = $payment; |
|
2610 | - // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
2611 | - // because we will complete this step during the IPN processing then |
|
2612 | - if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
2613 | - $this->set_completed(); |
|
2614 | - } |
|
2615 | - return true; |
|
2616 | - } |
|
2617 | - } |
|
2618 | - // DEBUG LOG |
|
2619 | - // $this->checkout->log( |
|
2620 | - // __CLASS__, |
|
2621 | - // __FUNCTION__, |
|
2622 | - // __LINE__, |
|
2623 | - // array('payment' => $payment) |
|
2624 | - // ); |
|
2625 | - $this->checkout->continue_reg = false; |
|
2626 | - return false; |
|
2627 | - } |
|
2628 | - |
|
2629 | - |
|
2630 | - /** |
|
2631 | - * _validate_return |
|
2632 | - * |
|
2633 | - * @access private |
|
2634 | - * @return void |
|
2635 | - * @throws EE_Error |
|
2636 | - * @throws InvalidArgumentException |
|
2637 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2638 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2639 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2640 | - */ |
|
2641 | - private function _validate_offsite_return() |
|
2642 | - { |
|
2643 | - $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
2644 | - if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
2645 | - // Houston... we might have a problem |
|
2646 | - $invalid_TXN = false; |
|
2647 | - // first gather some info |
|
2648 | - $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2649 | - $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
2650 | - ? $valid_TXN->primary_registration() |
|
2651 | - : null; |
|
2652 | - // let's start by retrieving the cart for this TXN |
|
2653 | - $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
2654 | - if ($cart instanceof EE_Cart) { |
|
2655 | - // verify that the current cart has tickets |
|
2656 | - $tickets = $cart->get_tickets(); |
|
2657 | - if (empty($tickets)) { |
|
2658 | - $invalid_TXN = true; |
|
2659 | - } |
|
2660 | - } else { |
|
2661 | - $invalid_TXN = true; |
|
2662 | - } |
|
2663 | - $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
2664 | - ? $primary_registrant->session_ID() |
|
2665 | - : null; |
|
2666 | - // validate current Session ID and compare against valid TXN session ID |
|
2667 | - if ($invalid_TXN // if this is already true, then skip other checks |
|
2668 | - || EE_Session::instance()->id() === null |
|
2669 | - || ( |
|
2670 | - // WARNING !!! |
|
2671 | - // this could be PayPal sending back duplicate requests (ya they do that) |
|
2672 | - // or it **could** mean someone is simply registering AGAIN after having just done so |
|
2673 | - // so now we need to determine if this current TXN looks valid or not |
|
2674 | - // and whether this reg step has even been started ? |
|
2675 | - EE_Session::instance()->id() === $valid_TXN_SID |
|
2676 | - // really? you're half way through this reg step, but you never started it ? |
|
2677 | - && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
2678 | - ) |
|
2679 | - ) { |
|
2680 | - $invalid_TXN = true; |
|
2681 | - } |
|
2682 | - if ($invalid_TXN) { |
|
2683 | - // is the valid TXN completed ? |
|
2684 | - if ($valid_TXN instanceof EE_Transaction) { |
|
2685 | - // has this step even been started ? |
|
2686 | - $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
2687 | - if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
2688 | - // so it **looks** like this is a double request from PayPal |
|
2689 | - // so let's try to pick up where we left off |
|
2690 | - $this->checkout->transaction = $valid_TXN; |
|
2691 | - $this->checkout->refresh_all_entities(true); |
|
2692 | - return; |
|
2693 | - } |
|
2694 | - } |
|
2695 | - // you appear to be lost? |
|
2696 | - $this->_redirect_wayward_request($primary_registrant); |
|
2697 | - } |
|
2698 | - } |
|
2699 | - } |
|
2700 | - |
|
2701 | - |
|
2702 | - /** |
|
2703 | - * _redirect_wayward_request |
|
2704 | - * |
|
2705 | - * @access private |
|
2706 | - * @param \EE_Registration|null $primary_registrant |
|
2707 | - * @return bool |
|
2708 | - * @throws EE_Error |
|
2709 | - * @throws InvalidArgumentException |
|
2710 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2711 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2712 | - */ |
|
2713 | - private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
2714 | - { |
|
2715 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2716 | - // try redirecting based on the current TXN |
|
2717 | - $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
2718 | - ? $this->checkout->transaction->primary_registration() |
|
2719 | - : null; |
|
2720 | - } |
|
2721 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2722 | - EE_Error::add_error( |
|
2723 | - sprintf( |
|
2724 | - esc_html__( |
|
2725 | - 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
2726 | - 'event_espresso' |
|
2727 | - ), |
|
2728 | - '<br/>', |
|
2729 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2730 | - ), |
|
2731 | - __FILE__, |
|
2732 | - __FUNCTION__, |
|
2733 | - __LINE__ |
|
2734 | - ); |
|
2735 | - return false; |
|
2736 | - } |
|
2737 | - // make sure transaction is not locked |
|
2738 | - $this->checkout->transaction->unlock(); |
|
2739 | - wp_safe_redirect( |
|
2740 | - add_query_arg( |
|
2741 | - array( |
|
2742 | - 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
2743 | - ), |
|
2744 | - $this->checkout->thank_you_page_url |
|
2745 | - ) |
|
2746 | - ); |
|
2747 | - exit(); |
|
2748 | - } |
|
2749 | - |
|
2750 | - |
|
2751 | - /** |
|
2752 | - * _process_off_site_payment |
|
2753 | - * |
|
2754 | - * @access private |
|
2755 | - * @param \EE_Offsite_Gateway $gateway |
|
2756 | - * @return EE_Payment |
|
2757 | - * @throws EE_Error |
|
2758 | - * @throws InvalidArgumentException |
|
2759 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2760 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2761 | - */ |
|
2762 | - private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
2763 | - { |
|
2764 | - try { |
|
2765 | - $request_data = \EE_Registry::instance()->REQ->params(); |
|
2766 | - // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
2767 | - $this->set_handle_IPN_in_this_request( |
|
2768 | - $gateway->handle_IPN_in_this_request($request_data, false) |
|
2769 | - ); |
|
2770 | - if ($this->handle_IPN_in_this_request()) { |
|
2771 | - // get payment details and process results |
|
2772 | - /** @type EE_Payment_Processor $payment_processor */ |
|
2773 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2774 | - $payment = $payment_processor->process_ipn( |
|
2775 | - $request_data, |
|
2776 | - $this->checkout->transaction, |
|
2777 | - $this->checkout->payment_method, |
|
2778 | - true, |
|
2779 | - false |
|
2780 | - ); |
|
2781 | - // $payment_source = 'process_ipn'; |
|
2782 | - } else { |
|
2783 | - $payment = $this->checkout->transaction->last_payment(); |
|
2784 | - // $payment_source = 'last_payment'; |
|
2785 | - } |
|
2786 | - } catch (Exception $e) { |
|
2787 | - // let's just eat the exception and try to move on using any previously set payment info |
|
2788 | - $payment = $this->checkout->transaction->last_payment(); |
|
2789 | - // $payment_source = 'last_payment after Exception'; |
|
2790 | - // but if we STILL don't have a payment object |
|
2791 | - if (! $payment instanceof EE_Payment) { |
|
2792 | - // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
2793 | - $this->_handle_payment_processor_exception($e); |
|
2794 | - } |
|
2795 | - } |
|
2796 | - // DEBUG LOG |
|
2797 | - // $this->checkout->log( |
|
2798 | - // __CLASS__, |
|
2799 | - // __FUNCTION__, |
|
2800 | - // __LINE__, |
|
2801 | - // array( |
|
2802 | - // 'process_ipn_payment' => $payment, |
|
2803 | - // 'payment_source' => $payment_source, |
|
2804 | - // ) |
|
2805 | - // ); |
|
2806 | - return $payment; |
|
2807 | - } |
|
2808 | - |
|
2809 | - |
|
2810 | - /** |
|
2811 | - * _process_cancelled_payments |
|
2812 | - * just makes sure that the payment status gets updated correctly |
|
2813 | - * so tha tan error isn't generated during payment validation |
|
2814 | - * |
|
2815 | - * @access private |
|
2816 | - * @param EE_Payment $payment |
|
2817 | - * @return EE_Payment | FALSE |
|
2818 | - * @throws \EE_Error |
|
2819 | - */ |
|
2820 | - private function _process_cancelled_payments($payment = null) |
|
2821 | - { |
|
2822 | - if ($payment instanceof EE_Payment |
|
2823 | - && isset($_REQUEST['ee_cancel_payment']) |
|
2824 | - && $payment->status() === EEM_Payment::status_id_failed |
|
2825 | - ) { |
|
2826 | - $payment->set_status(EEM_Payment::status_id_cancelled); |
|
2827 | - } |
|
2828 | - return $payment; |
|
2829 | - } |
|
2830 | - |
|
2831 | - |
|
2832 | - /** |
|
2833 | - * get_transaction_details_for_gateways |
|
2834 | - * |
|
2835 | - * @access public |
|
2836 | - * @return int |
|
2837 | - * @throws EE_Error |
|
2838 | - * @throws InvalidArgumentException |
|
2839 | - * @throws ReflectionException |
|
2840 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2841 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2842 | - */ |
|
2843 | - public function get_transaction_details_for_gateways() |
|
2844 | - { |
|
2845 | - $txn_details = array(); |
|
2846 | - // ya gotta make a choice man |
|
2847 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
2848 | - $txn_details = array( |
|
2849 | - 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
2850 | - ); |
|
2851 | - } |
|
2852 | - // get EE_Payment_Method object |
|
2853 | - if (empty($txn_details) |
|
2854 | - && |
|
2855 | - ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
2856 | - ) { |
|
2857 | - $txn_details = array( |
|
2858 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2859 | - 'error' => esc_html__( |
|
2860 | - 'A valid Payment Method could not be determined.', |
|
2861 | - 'event_espresso' |
|
2862 | - ), |
|
2863 | - ); |
|
2864 | - } |
|
2865 | - if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
2866 | - $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
2867 | - $txn_details = array( |
|
2868 | - 'TXN_ID' => $this->checkout->transaction->ID(), |
|
2869 | - 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
2870 | - 'TXN_total' => $this->checkout->transaction->total(), |
|
2871 | - 'TXN_paid' => $this->checkout->transaction->paid(), |
|
2872 | - 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
2873 | - 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
2874 | - 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
2875 | - 'payment_amount' => $this->checkout->amount_owing, |
|
2876 | - 'return_url' => $return_url, |
|
2877 | - 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
2878 | - 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
2879 | - array( |
|
2880 | - 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
2881 | - 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
2882 | - ) |
|
2883 | - ), |
|
2884 | - ); |
|
2885 | - } |
|
2886 | - echo wp_json_encode($txn_details); |
|
2887 | - exit(); |
|
2888 | - } |
|
2889 | - |
|
2890 | - |
|
2891 | - /** |
|
2892 | - * __sleep |
|
2893 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
2894 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
2895 | - * reg form, because if needed, it will be regenerated anyways |
|
2896 | - * |
|
2897 | - * @return array |
|
2898 | - */ |
|
2899 | - public function __sleep() |
|
2900 | - { |
|
2901 | - // remove the reg form and the checkout |
|
2902 | - return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
2903 | - } |
|
15 | + /** |
|
16 | + * @access protected |
|
17 | + * @var EE_Line_Item_Display $Line_Item_Display |
|
18 | + */ |
|
19 | + protected $line_item_display; |
|
20 | + |
|
21 | + /** |
|
22 | + * @access protected |
|
23 | + * @var boolean $handle_IPN_in_this_request |
|
24 | + */ |
|
25 | + protected $handle_IPN_in_this_request = false; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
30 | + * |
|
31 | + * @access public |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public static function set_hooks() |
|
35 | + { |
|
36 | + add_filter( |
|
37 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
38 | + array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
39 | + ); |
|
40 | + add_action( |
|
41 | + 'wp_ajax_switch_spco_billing_form', |
|
42 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
43 | + ); |
|
44 | + add_action( |
|
45 | + 'wp_ajax_nopriv_switch_spco_billing_form', |
|
46 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
47 | + ); |
|
48 | + add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
49 | + add_action( |
|
50 | + 'wp_ajax_nopriv_save_payer_details', |
|
51 | + array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
52 | + ); |
|
53 | + add_action( |
|
54 | + 'wp_ajax_get_transaction_details_for_gateways', |
|
55 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
56 | + ); |
|
57 | + add_action( |
|
58 | + 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
59 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
60 | + ); |
|
61 | + add_filter( |
|
62 | + 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
63 | + array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
64 | + 10, |
|
65 | + 1 |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * ajax switch_spco_billing_form |
|
72 | + * |
|
73 | + * @throws \EE_Error |
|
74 | + */ |
|
75 | + public static function switch_spco_billing_form() |
|
76 | + { |
|
77 | + EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * ajax save_payer_details |
|
83 | + * |
|
84 | + * @throws \EE_Error |
|
85 | + */ |
|
86 | + public static function save_payer_details() |
|
87 | + { |
|
88 | + EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * ajax get_transaction_details |
|
94 | + * |
|
95 | + * @throws \EE_Error |
|
96 | + */ |
|
97 | + public static function get_transaction_details() |
|
98 | + { |
|
99 | + EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * bypass_recaptcha_for_load_payment_method |
|
105 | + * |
|
106 | + * @access public |
|
107 | + * @return array |
|
108 | + * @throws InvalidArgumentException |
|
109 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
110 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
111 | + */ |
|
112 | + public static function bypass_recaptcha_for_load_payment_method() |
|
113 | + { |
|
114 | + return array( |
|
115 | + 'EESID' => EE_Registry::instance()->SSN->id(), |
|
116 | + 'step' => 'payment_options', |
|
117 | + 'action' => 'spco_billing_form', |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * class constructor |
|
124 | + * |
|
125 | + * @access public |
|
126 | + * @param EE_Checkout $checkout |
|
127 | + */ |
|
128 | + public function __construct(EE_Checkout $checkout) |
|
129 | + { |
|
130 | + $this->_slug = 'payment_options'; |
|
131 | + $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
132 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
133 | + $this->checkout = $checkout; |
|
134 | + $this->_reset_success_message(); |
|
135 | + $this->set_instructions( |
|
136 | + esc_html__( |
|
137 | + 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
138 | + 'event_espresso' |
|
139 | + ) |
|
140 | + ); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return null |
|
146 | + */ |
|
147 | + public function line_item_display() |
|
148 | + { |
|
149 | + return $this->line_item_display; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param null $line_item_display |
|
155 | + */ |
|
156 | + public function set_line_item_display($line_item_display) |
|
157 | + { |
|
158 | + $this->line_item_display = $line_item_display; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @return boolean |
|
164 | + */ |
|
165 | + public function handle_IPN_in_this_request() |
|
166 | + { |
|
167 | + return $this->handle_IPN_in_this_request; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param boolean $handle_IPN_in_this_request |
|
173 | + */ |
|
174 | + public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
175 | + { |
|
176 | + $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * translate_js_strings |
|
182 | + * |
|
183 | + * @return void |
|
184 | + */ |
|
185 | + public function translate_js_strings() |
|
186 | + { |
|
187 | + EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
188 | + 'Please select a method of payment in order to continue.', |
|
189 | + 'event_espresso' |
|
190 | + ); |
|
191 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
192 | + 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
193 | + 'event_espresso' |
|
194 | + ); |
|
195 | + EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
196 | + 'Forwarding to Secure Payment Provider.', |
|
197 | + 'event_espresso' |
|
198 | + ); |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * enqueue_styles_and_scripts |
|
204 | + * |
|
205 | + * @return void |
|
206 | + * @throws EE_Error |
|
207 | + * @throws InvalidArgumentException |
|
208 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
209 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
210 | + */ |
|
211 | + public function enqueue_styles_and_scripts() |
|
212 | + { |
|
213 | + $transaction = $this->checkout->transaction; |
|
214 | + // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
215 | + if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
216 | + return; |
|
217 | + } |
|
218 | + foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
219 | + $transaction, |
|
220 | + EEM_Payment_Method::scope_cart |
|
221 | + ) as $payment_method) { |
|
222 | + $type_obj = $payment_method->type_obj(); |
|
223 | + if ($type_obj instanceof EE_PMT_Base) { |
|
224 | + $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
225 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
226 | + $billing_form->enqueue_js(); |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * initialize_reg_step |
|
235 | + * |
|
236 | + * @return bool |
|
237 | + * @throws EE_Error |
|
238 | + * @throws InvalidArgumentException |
|
239 | + * @throws ReflectionException |
|
240 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
241 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
242 | + */ |
|
243 | + public function initialize_reg_step() |
|
244 | + { |
|
245 | + // TODO: if /when we implement donations, then this will need overriding |
|
246 | + if (// don't need payment options for: |
|
247 | + // registrations made via the admin |
|
248 | + // completed transactions |
|
249 | + // overpaid transactions |
|
250 | + // $ 0.00 transactions(no payment required) |
|
251 | + ! $this->checkout->payment_required() |
|
252 | + // but do NOT remove if current action being called belongs to this reg step |
|
253 | + && ! is_callable(array($this, $this->checkout->action)) |
|
254 | + && ! $this->completed() |
|
255 | + ) { |
|
256 | + // and if so, then we no longer need the Payment Options step |
|
257 | + if ($this->is_current_step()) { |
|
258 | + $this->checkout->generate_reg_form = false; |
|
259 | + } |
|
260 | + $this->checkout->remove_reg_step($this->_slug); |
|
261 | + // DEBUG LOG |
|
262 | + // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
263 | + return false; |
|
264 | + } |
|
265 | + // load EEM_Payment_Method |
|
266 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
267 | + // get all active payment methods |
|
268 | + $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
269 | + $this->checkout->transaction, |
|
270 | + EEM_Payment_Method::scope_cart |
|
271 | + ); |
|
272 | + return true; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * @return EE_Form_Section_Proper |
|
278 | + * @throws EE_Error |
|
279 | + * @throws InvalidArgumentException |
|
280 | + * @throws ReflectionException |
|
281 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
282 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
283 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
284 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
285 | + */ |
|
286 | + public function generate_reg_form() |
|
287 | + { |
|
288 | + // reset in case someone changes their mind |
|
289 | + $this->_reset_selected_method_of_payment(); |
|
290 | + // set some defaults |
|
291 | + $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
292 | + $registrations_requiring_payment = array(); |
|
293 | + $registrations_for_free_events = array(); |
|
294 | + $registrations_requiring_pre_approval = array(); |
|
295 | + $sold_out_events = array(); |
|
296 | + $insufficient_spaces_available = array(); |
|
297 | + $no_payment_required = true; |
|
298 | + // loop thru registrations to gather info |
|
299 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
300 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
301 | + $registrations, |
|
302 | + $this->checkout->revisit |
|
303 | + ); |
|
304 | + foreach ($registrations as $REG_ID => $registration) { |
|
305 | + /** @var $registration EE_Registration */ |
|
306 | + // has this registration lost it's space ? |
|
307 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
308 | + if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
309 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
310 | + } else { |
|
311 | + $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
312 | + } |
|
313 | + continue; |
|
314 | + } |
|
315 | + // event requires admin approval |
|
316 | + if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
317 | + // add event to list of events with pre-approval reg status |
|
318 | + $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
319 | + do_action( |
|
320 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
321 | + $registration->event(), |
|
322 | + $this |
|
323 | + ); |
|
324 | + continue; |
|
325 | + } |
|
326 | + if ($this->checkout->revisit |
|
327 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
328 | + && ( |
|
329 | + $registration->event()->is_sold_out() |
|
330 | + || $registration->event()->is_sold_out(true) |
|
331 | + ) |
|
332 | + ) { |
|
333 | + // add event to list of events that are sold out |
|
334 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
335 | + do_action( |
|
336 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
337 | + $registration->event(), |
|
338 | + $this |
|
339 | + ); |
|
340 | + continue; |
|
341 | + } |
|
342 | + // are they allowed to pay now and is there monies owing? |
|
343 | + if ($registration->owes_monies_and_can_pay()) { |
|
344 | + $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
345 | + do_action( |
|
346 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
347 | + $registration->event(), |
|
348 | + $this |
|
349 | + ); |
|
350 | + } elseif (! $this->checkout->revisit |
|
351 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
352 | + && $registration->ticket()->is_free() |
|
353 | + ) { |
|
354 | + $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
355 | + } |
|
356 | + } |
|
357 | + $subsections = array(); |
|
358 | + // now decide which template to load |
|
359 | + if (! empty($sold_out_events)) { |
|
360 | + $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
361 | + } |
|
362 | + if (! empty($insufficient_spaces_available)) { |
|
363 | + $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
364 | + $insufficient_spaces_available |
|
365 | + ); |
|
366 | + } |
|
367 | + if (! empty($registrations_requiring_pre_approval)) { |
|
368 | + $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
369 | + $registrations_requiring_pre_approval |
|
370 | + ); |
|
371 | + } |
|
372 | + if (! empty($registrations_for_free_events)) { |
|
373 | + $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
374 | + } |
|
375 | + if (! empty($registrations_requiring_payment)) { |
|
376 | + if ($this->checkout->amount_owing > 0) { |
|
377 | + // autoload Line_Item_Display classes |
|
378 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
379 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
380 | + apply_filters( |
|
381 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
382 | + new EE_Line_Item_Filter_Collection() |
|
383 | + ), |
|
384 | + $this->checkout->cart->get_grand_total() |
|
385 | + ); |
|
386 | + /** @var EE_Line_Item $filtered_line_item_tree */ |
|
387 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
388 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
389 | + $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
390 | + $subsections['payment_options'] = $this->_display_payment_options( |
|
391 | + $this->line_item_display->display_line_item( |
|
392 | + $filtered_line_item_tree, |
|
393 | + array('registrations' => $registrations) |
|
394 | + ) |
|
395 | + ); |
|
396 | + $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
397 | + $this->_apply_registration_payments_to_amount_owing($registrations); |
|
398 | + } |
|
399 | + $no_payment_required = false; |
|
400 | + } else { |
|
401 | + $this->_hide_reg_step_submit_button_if_revisit(); |
|
402 | + } |
|
403 | + $this->_save_selected_method_of_payment(); |
|
404 | + |
|
405 | + $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
406 | + $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
407 | + |
|
408 | + return new EE_Form_Section_Proper( |
|
409 | + array( |
|
410 | + 'name' => $this->reg_form_name(), |
|
411 | + 'html_id' => $this->reg_form_name(), |
|
412 | + 'subsections' => $subsections, |
|
413 | + 'layout_strategy' => new EE_No_Layout(), |
|
414 | + ) |
|
415 | + ); |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * add line item filters required for this reg step |
|
421 | + * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
422 | + * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
423 | + * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
424 | + * payment options reg step, can apply these filters via the following: apply_filters( |
|
425 | + * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
426 | + * filter collection by passing that instead of instantiating a new collection |
|
427 | + * |
|
428 | + * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
429 | + * @return EE_Line_Item_Filter_Collection |
|
430 | + * @throws EE_Error |
|
431 | + * @throws InvalidArgumentException |
|
432 | + * @throws ReflectionException |
|
433 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
434 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
435 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
436 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
437 | + */ |
|
438 | + public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
439 | + { |
|
440 | + if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
441 | + return $line_item_filter_collection; |
|
442 | + } |
|
443 | + if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
444 | + return $line_item_filter_collection; |
|
445 | + } |
|
446 | + if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
447 | + return $line_item_filter_collection; |
|
448 | + } |
|
449 | + $line_item_filter_collection->add( |
|
450 | + new EE_Billable_Line_Item_Filter( |
|
451 | + EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
452 | + EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
453 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
454 | + ) |
|
455 | + ) |
|
456 | + ) |
|
457 | + ); |
|
458 | + $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
459 | + return $line_item_filter_collection; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * remove_ejected_registrations |
|
465 | + * if a registrant has lost their potential space at an event due to lack of payment, |
|
466 | + * then this method removes them from the list of registrations being paid for during this request |
|
467 | + * |
|
468 | + * @param \EE_Registration[] $registrations |
|
469 | + * @return EE_Registration[] |
|
470 | + * @throws EE_Error |
|
471 | + * @throws InvalidArgumentException |
|
472 | + * @throws ReflectionException |
|
473 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
474 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
475 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
476 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
477 | + */ |
|
478 | + public static function remove_ejected_registrations(array $registrations) |
|
479 | + { |
|
480 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
481 | + $registrations, |
|
482 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
483 | + ); |
|
484 | + foreach ($registrations as $REG_ID => $registration) { |
|
485 | + // has this registration lost it's space ? |
|
486 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
487 | + unset($registrations[ $REG_ID ]); |
|
488 | + continue; |
|
489 | + } |
|
490 | + } |
|
491 | + return $registrations; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * find_registrations_that_lost_their_space |
|
497 | + * If a registrant chooses an offline payment method like Invoice, |
|
498 | + * then no space is reserved for them at the event until they fully pay fo that site |
|
499 | + * (unless the event's default reg status is set to APPROVED) |
|
500 | + * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
501 | + * then this method will determine which registrations have lost the ability to complete the reg process. |
|
502 | + * |
|
503 | + * @param \EE_Registration[] $registrations |
|
504 | + * @param bool $revisit |
|
505 | + * @return array |
|
506 | + * @throws EE_Error |
|
507 | + * @throws InvalidArgumentException |
|
508 | + * @throws ReflectionException |
|
509 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
510 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
511 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
512 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
513 | + */ |
|
514 | + public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
515 | + { |
|
516 | + // registrations per event |
|
517 | + $event_reg_count = array(); |
|
518 | + // spaces left per event |
|
519 | + $event_spaces_remaining = array(); |
|
520 | + // tickets left sorted by ID |
|
521 | + $tickets_remaining = array(); |
|
522 | + // registrations that have lost their space |
|
523 | + $ejected_registrations = array(); |
|
524 | + foreach ($registrations as $REG_ID => $registration) { |
|
525 | + if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
526 | + || apply_filters( |
|
527 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
528 | + false, |
|
529 | + $registration, |
|
530 | + $revisit |
|
531 | + ) |
|
532 | + ) { |
|
533 | + continue; |
|
534 | + } |
|
535 | + $EVT_ID = $registration->event_ID(); |
|
536 | + $ticket = $registration->ticket(); |
|
537 | + if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
538 | + $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
539 | + } |
|
540 | + if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
541 | + if (! isset($event_reg_count[ $EVT_ID ])) { |
|
542 | + $event_reg_count[ $EVT_ID ] = 0; |
|
543 | + } |
|
544 | + $event_reg_count[ $EVT_ID ]++; |
|
545 | + if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
546 | + $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
547 | + } |
|
548 | + } |
|
549 | + if ($revisit |
|
550 | + && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
551 | + || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
552 | + ) |
|
553 | + ) { |
|
554 | + $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
555 | + if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
556 | + /** @type EE_Registration_Processor $registration_processor */ |
|
557 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
558 | + // at this point, we should have enough details about the registrant to consider the registration |
|
559 | + // NOT incomplete |
|
560 | + $registration_processor->manually_update_registration_status( |
|
561 | + $registration, |
|
562 | + EEM_Registration::status_id_wait_list |
|
563 | + ); |
|
564 | + } |
|
565 | + } |
|
566 | + } |
|
567 | + return $ejected_registrations; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * _hide_reg_step_submit_button |
|
573 | + * removes the html for the reg step submit button |
|
574 | + * by replacing it with an empty string via filter callback |
|
575 | + * |
|
576 | + * @return void |
|
577 | + */ |
|
578 | + protected function _adjust_registration_status_if_event_old_sold() |
|
579 | + { |
|
580 | + } |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * _hide_reg_step_submit_button |
|
585 | + * removes the html for the reg step submit button |
|
586 | + * by replacing it with an empty string via filter callback |
|
587 | + * |
|
588 | + * @return void |
|
589 | + */ |
|
590 | + protected function _hide_reg_step_submit_button_if_revisit() |
|
591 | + { |
|
592 | + if ($this->checkout->revisit) { |
|
593 | + add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
594 | + } |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + /** |
|
599 | + * sold_out_events |
|
600 | + * displays notices regarding events that have sold out since hte registrant first signed up |
|
601 | + * |
|
602 | + * @param \EE_Event[] $sold_out_events_array |
|
603 | + * @return \EE_Form_Section_Proper |
|
604 | + * @throws \EE_Error |
|
605 | + */ |
|
606 | + private function _sold_out_events($sold_out_events_array = array()) |
|
607 | + { |
|
608 | + // set some defaults |
|
609 | + $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
610 | + $sold_out_events = ''; |
|
611 | + foreach ($sold_out_events_array as $sold_out_event) { |
|
612 | + $sold_out_events .= EEH_HTML::li( |
|
613 | + EEH_HTML::span( |
|
614 | + ' ' . $sold_out_event->name(), |
|
615 | + '', |
|
616 | + 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
617 | + ) |
|
618 | + ); |
|
619 | + } |
|
620 | + return new EE_Form_Section_Proper( |
|
621 | + array( |
|
622 | + 'layout_strategy' => new EE_Template_Layout( |
|
623 | + array( |
|
624 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
625 | + . $this->_slug |
|
626 | + . DS |
|
627 | + . 'sold_out_events.template.php', |
|
628 | + 'template_args' => apply_filters( |
|
629 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
630 | + array( |
|
631 | + 'sold_out_events' => $sold_out_events, |
|
632 | + 'sold_out_events_msg' => apply_filters( |
|
633 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
634 | + sprintf( |
|
635 | + esc_html__( |
|
636 | + 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', |
|
637 | + 'event_espresso' |
|
638 | + ), |
|
639 | + '<strong>', |
|
640 | + '</strong>', |
|
641 | + '<br />' |
|
642 | + ) |
|
643 | + ), |
|
644 | + ) |
|
645 | + ), |
|
646 | + ) |
|
647 | + ), |
|
648 | + ) |
|
649 | + ); |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * _insufficient_spaces_available |
|
655 | + * displays notices regarding events that do not have enough remaining spaces |
|
656 | + * to satisfy the current number of registrations looking to pay |
|
657 | + * |
|
658 | + * @param \EE_Event[] $insufficient_spaces_events_array |
|
659 | + * @return \EE_Form_Section_Proper |
|
660 | + * @throws \EE_Error |
|
661 | + */ |
|
662 | + private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
663 | + { |
|
664 | + // set some defaults |
|
665 | + $this->checkout->selected_method_of_payment = 'invoice'; |
|
666 | + $insufficient_space_events = ''; |
|
667 | + foreach ($insufficient_spaces_events_array as $event) { |
|
668 | + if ($event instanceof EE_Event) { |
|
669 | + $insufficient_space_events .= EEH_HTML::li( |
|
670 | + EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
671 | + ); |
|
672 | + } |
|
673 | + } |
|
674 | + return new EE_Form_Section_Proper( |
|
675 | + array( |
|
676 | + 'subsections' => array( |
|
677 | + 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
678 | + 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
679 | + ), |
|
680 | + 'layout_strategy' => new EE_Template_Layout( |
|
681 | + array( |
|
682 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
683 | + . $this->_slug |
|
684 | + . DS |
|
685 | + . 'sold_out_events.template.php', |
|
686 | + 'template_args' => apply_filters( |
|
687 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
688 | + array( |
|
689 | + 'sold_out_events' => $insufficient_space_events, |
|
690 | + 'sold_out_events_msg' => apply_filters( |
|
691 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
692 | + esc_html__( |
|
693 | + 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
694 | + 'event_espresso' |
|
695 | + ) |
|
696 | + ), |
|
697 | + ) |
|
698 | + ), |
|
699 | + ) |
|
700 | + ), |
|
701 | + ) |
|
702 | + ); |
|
703 | + } |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * registrations_requiring_pre_approval |
|
708 | + * |
|
709 | + * @param array $registrations_requiring_pre_approval |
|
710 | + * @return EE_Form_Section_Proper |
|
711 | + * @throws EE_Error |
|
712 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
713 | + */ |
|
714 | + private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
715 | + { |
|
716 | + $events_requiring_pre_approval = array(); |
|
717 | + foreach ($registrations_requiring_pre_approval as $registration) { |
|
718 | + if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
719 | + $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
720 | + EEH_HTML::span( |
|
721 | + '', |
|
722 | + '', |
|
723 | + 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
724 | + ) |
|
725 | + . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
726 | + ); |
|
727 | + } |
|
728 | + } |
|
729 | + return new EE_Form_Section_Proper( |
|
730 | + array( |
|
731 | + 'layout_strategy' => new EE_Template_Layout( |
|
732 | + array( |
|
733 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
734 | + . $this->_slug |
|
735 | + . DS |
|
736 | + . 'events_requiring_pre_approval.template.php', // layout_template |
|
737 | + 'template_args' => apply_filters( |
|
738 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
739 | + array( |
|
740 | + 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
741 | + 'events_requiring_pre_approval_msg' => apply_filters( |
|
742 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
743 | + esc_html__( |
|
744 | + 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
745 | + 'event_espresso' |
|
746 | + ) |
|
747 | + ), |
|
748 | + ) |
|
749 | + ), |
|
750 | + ) |
|
751 | + ), |
|
752 | + ) |
|
753 | + ); |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * _no_payment_required |
|
759 | + * |
|
760 | + * @param \EE_Event[] $registrations_for_free_events |
|
761 | + * @return \EE_Form_Section_Proper |
|
762 | + * @throws \EE_Error |
|
763 | + */ |
|
764 | + private function _no_payment_required($registrations_for_free_events = array()) |
|
765 | + { |
|
766 | + // set some defaults |
|
767 | + $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
768 | + // generate no_payment_required form |
|
769 | + return new EE_Form_Section_Proper( |
|
770 | + array( |
|
771 | + 'layout_strategy' => new EE_Template_Layout( |
|
772 | + array( |
|
773 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
774 | + . $this->_slug |
|
775 | + . DS |
|
776 | + . 'no_payment_required.template.php', // layout_template |
|
777 | + 'template_args' => apply_filters( |
|
778 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
779 | + array( |
|
780 | + 'revisit' => $this->checkout->revisit, |
|
781 | + 'registrations' => array(), |
|
782 | + 'ticket_count' => array(), |
|
783 | + 'registrations_for_free_events' => $registrations_for_free_events, |
|
784 | + 'no_payment_required_msg' => EEH_HTML::p( |
|
785 | + esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
786 | + ), |
|
787 | + ) |
|
788 | + ), |
|
789 | + ) |
|
790 | + ), |
|
791 | + ) |
|
792 | + ); |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * _display_payment_options |
|
798 | + * |
|
799 | + * @param string $transaction_details |
|
800 | + * @return EE_Form_Section_Proper |
|
801 | + * @throws EE_Error |
|
802 | + * @throws InvalidArgumentException |
|
803 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
804 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
805 | + */ |
|
806 | + private function _display_payment_options($transaction_details = '') |
|
807 | + { |
|
808 | + // has method_of_payment been set by no-js user? |
|
809 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
810 | + // build payment options form |
|
811 | + return apply_filters( |
|
812 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
813 | + new EE_Form_Section_Proper( |
|
814 | + array( |
|
815 | + 'subsections' => array( |
|
816 | + 'before_payment_options' => apply_filters( |
|
817 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
818 | + new EE_Form_Section_Proper( |
|
819 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
820 | + ) |
|
821 | + ), |
|
822 | + 'payment_options' => $this->_setup_payment_options(), |
|
823 | + 'after_payment_options' => apply_filters( |
|
824 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
825 | + new EE_Form_Section_Proper( |
|
826 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
827 | + ) |
|
828 | + ), |
|
829 | + ), |
|
830 | + 'layout_strategy' => new EE_Template_Layout( |
|
831 | + array( |
|
832 | + 'layout_template_file' => $this->_template, |
|
833 | + 'template_args' => apply_filters( |
|
834 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
835 | + array( |
|
836 | + 'reg_count' => $this->line_item_display->total_items(), |
|
837 | + 'transaction_details' => $transaction_details, |
|
838 | + 'available_payment_methods' => array(), |
|
839 | + ) |
|
840 | + ), |
|
841 | + ) |
|
842 | + ), |
|
843 | + ) |
|
844 | + ) |
|
845 | + ); |
|
846 | + } |
|
847 | + |
|
848 | + |
|
849 | + /** |
|
850 | + * _extra_hidden_inputs |
|
851 | + * |
|
852 | + * @param bool $no_payment_required |
|
853 | + * @return \EE_Form_Section_Proper |
|
854 | + * @throws \EE_Error |
|
855 | + */ |
|
856 | + private function _extra_hidden_inputs($no_payment_required = true) |
|
857 | + { |
|
858 | + return new EE_Form_Section_Proper( |
|
859 | + array( |
|
860 | + 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
861 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
862 | + 'subsections' => array( |
|
863 | + 'spco_no_payment_required' => new EE_Hidden_Input( |
|
864 | + array( |
|
865 | + 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
866 | + 'html_name' => 'spco_no_payment_required', |
|
867 | + 'html_id' => 'spco-no-payment-required-payment_options', |
|
868 | + 'default' => $no_payment_required, |
|
869 | + ) |
|
870 | + ), |
|
871 | + 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
872 | + array( |
|
873 | + 'normalization_strategy' => new EE_Int_Normalization(), |
|
874 | + 'html_name' => 'spco_transaction_id', |
|
875 | + 'html_id' => 'spco-transaction-id', |
|
876 | + 'default' => $this->checkout->transaction->ID(), |
|
877 | + ) |
|
878 | + ), |
|
879 | + ), |
|
880 | + ) |
|
881 | + ); |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + /** |
|
886 | + * _apply_registration_payments_to_amount_owing |
|
887 | + * |
|
888 | + * @access protected |
|
889 | + * @param array $registrations |
|
890 | + * @throws EE_Error |
|
891 | + */ |
|
892 | + protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
893 | + { |
|
894 | + $payments = array(); |
|
895 | + foreach ($registrations as $registration) { |
|
896 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
897 | + $payments += $registration->registration_payments(); |
|
898 | + } |
|
899 | + } |
|
900 | + if (! empty($payments)) { |
|
901 | + foreach ($payments as $payment) { |
|
902 | + if ($payment instanceof EE_Registration_Payment) { |
|
903 | + $this->checkout->amount_owing -= $payment->amount(); |
|
904 | + } |
|
905 | + } |
|
906 | + } |
|
907 | + } |
|
908 | + |
|
909 | + |
|
910 | + /** |
|
911 | + * _reset_selected_method_of_payment |
|
912 | + * |
|
913 | + * @access private |
|
914 | + * @param bool $force_reset |
|
915 | + * @return void |
|
916 | + * @throws InvalidArgumentException |
|
917 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
918 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
919 | + */ |
|
920 | + private function _reset_selected_method_of_payment($force_reset = false) |
|
921 | + { |
|
922 | + $reset_payment_method = $force_reset |
|
923 | + ? true |
|
924 | + : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
925 | + if ($reset_payment_method) { |
|
926 | + $this->checkout->selected_method_of_payment = null; |
|
927 | + $this->checkout->payment_method = null; |
|
928 | + $this->checkout->billing_form = null; |
|
929 | + $this->_save_selected_method_of_payment(); |
|
930 | + } |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + /** |
|
935 | + * _save_selected_method_of_payment |
|
936 | + * stores the selected_method_of_payment in the session |
|
937 | + * so that it's available for all subsequent requests including AJAX |
|
938 | + * |
|
939 | + * @access private |
|
940 | + * @param string $selected_method_of_payment |
|
941 | + * @return void |
|
942 | + * @throws InvalidArgumentException |
|
943 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
944 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
945 | + */ |
|
946 | + private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
947 | + { |
|
948 | + $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
949 | + ? $selected_method_of_payment |
|
950 | + : $this->checkout->selected_method_of_payment; |
|
951 | + EE_Registry::instance()->SSN->set_session_data( |
|
952 | + array('selected_method_of_payment' => $selected_method_of_payment) |
|
953 | + ); |
|
954 | + } |
|
955 | + |
|
956 | + |
|
957 | + /** |
|
958 | + * _setup_payment_options |
|
959 | + * |
|
960 | + * @return EE_Form_Section_Proper |
|
961 | + * @throws EE_Error |
|
962 | + * @throws InvalidArgumentException |
|
963 | + * @throws ReflectionException |
|
964 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
965 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
966 | + */ |
|
967 | + public function _setup_payment_options() |
|
968 | + { |
|
969 | + // load payment method classes |
|
970 | + $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
971 | + if (empty($this->checkout->available_payment_methods)) { |
|
972 | + EE_Error::add_error( |
|
973 | + apply_filters( |
|
974 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
975 | + sprintf( |
|
976 | + esc_html__( |
|
977 | + 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
978 | + 'event_espresso' |
|
979 | + ), |
|
980 | + '<br>', |
|
981 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
982 | + ) |
|
983 | + ), |
|
984 | + __FILE__, |
|
985 | + __FUNCTION__, |
|
986 | + __LINE__ |
|
987 | + ); |
|
988 | + } |
|
989 | + // switch up header depending on number of available payment methods |
|
990 | + $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
991 | + ? apply_filters( |
|
992 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
993 | + esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
994 | + ) |
|
995 | + : apply_filters( |
|
996 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
997 | + esc_html__('Method of Payment', 'event_espresso') |
|
998 | + ); |
|
999 | + $available_payment_methods = array( |
|
1000 | + // display the "Payment Method" header |
|
1001 | + 'payment_method_header' => new EE_Form_Section_HTML( |
|
1002 | + apply_filters( |
|
1003 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header', |
|
1004 | + EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'), |
|
1005 | + $payment_method_header |
|
1006 | + ) |
|
1007 | + ), |
|
1008 | + ); |
|
1009 | + // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
1010 | + $available_payment_method_options = array(); |
|
1011 | + $default_payment_method_option = array(); |
|
1012 | + // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
1013 | + $payment_methods_billing_info = array( |
|
1014 | + new EE_Form_Section_HTML( |
|
1015 | + EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
1016 | + ), |
|
1017 | + ); |
|
1018 | + // loop through payment methods |
|
1019 | + foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
1020 | + if ($payment_method instanceof EE_Payment_Method) { |
|
1021 | + $payment_method_button = EEH_HTML::img( |
|
1022 | + $payment_method->button_url(), |
|
1023 | + $payment_method->name(), |
|
1024 | + 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
1025 | + 'spco-payment-method-btn-img' |
|
1026 | + ); |
|
1027 | + // check if any payment methods are set as default |
|
1028 | + // if payment method is already selected OR nothing is selected and this payment method should be |
|
1029 | + // open_by_default |
|
1030 | + if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
1031 | + || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1032 | + ) { |
|
1033 | + $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
1034 | + $this->_save_selected_method_of_payment(); |
|
1035 | + $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
1036 | + } else { |
|
1037 | + $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
1038 | + } |
|
1039 | + $payment_methods_billing_info[ $payment_method->slug( |
|
1040 | + ) . '-info' ] = $this->_payment_method_billing_info( |
|
1041 | + $payment_method |
|
1042 | + ); |
|
1043 | + } |
|
1044 | + } |
|
1045 | + // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
1046 | + // of PMs |
|
1047 | + $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
1048 | + // now generate the actual form inputs |
|
1049 | + $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
1050 | + $available_payment_method_options |
|
1051 | + ); |
|
1052 | + $available_payment_methods += $payment_methods_billing_info; |
|
1053 | + // build the available payment methods form |
|
1054 | + return new EE_Form_Section_Proper( |
|
1055 | + array( |
|
1056 | + 'html_id' => 'spco-available-methods-of-payment-dv', |
|
1057 | + 'subsections' => $available_payment_methods, |
|
1058 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1059 | + ) |
|
1060 | + ); |
|
1061 | + } |
|
1062 | + |
|
1063 | + |
|
1064 | + /** |
|
1065 | + * _get_available_payment_methods |
|
1066 | + * |
|
1067 | + * @return EE_Payment_Method[] |
|
1068 | + * @throws EE_Error |
|
1069 | + * @throws InvalidArgumentException |
|
1070 | + * @throws ReflectionException |
|
1071 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1072 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1073 | + */ |
|
1074 | + protected function _get_available_payment_methods() |
|
1075 | + { |
|
1076 | + if (! empty($this->checkout->available_payment_methods)) { |
|
1077 | + return $this->checkout->available_payment_methods; |
|
1078 | + } |
|
1079 | + $available_payment_methods = array(); |
|
1080 | + // load EEM_Payment_Method |
|
1081 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
1082 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
1083 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
1084 | + // get all active payment methods |
|
1085 | + $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
1086 | + $this->checkout->transaction, |
|
1087 | + EEM_Payment_Method::scope_cart |
|
1088 | + ); |
|
1089 | + foreach ($payment_methods as $payment_method) { |
|
1090 | + if ($payment_method instanceof EE_Payment_Method) { |
|
1091 | + $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1092 | + } |
|
1093 | + } |
|
1094 | + return $available_payment_methods; |
|
1095 | + } |
|
1096 | + |
|
1097 | + |
|
1098 | + /** |
|
1099 | + * _available_payment_method_inputs |
|
1100 | + * |
|
1101 | + * @access private |
|
1102 | + * @param array $available_payment_method_options |
|
1103 | + * @return \EE_Form_Section_Proper |
|
1104 | + */ |
|
1105 | + private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
1106 | + { |
|
1107 | + // generate inputs |
|
1108 | + return new EE_Form_Section_Proper( |
|
1109 | + array( |
|
1110 | + 'html_id' => 'ee-available-payment-method-inputs', |
|
1111 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1112 | + 'subsections' => array( |
|
1113 | + '' => new EE_Radio_Button_Input( |
|
1114 | + $available_payment_method_options, |
|
1115 | + array( |
|
1116 | + 'html_name' => 'selected_method_of_payment', |
|
1117 | + 'html_class' => 'spco-payment-method', |
|
1118 | + 'default' => $this->checkout->selected_method_of_payment, |
|
1119 | + 'label_size' => 11, |
|
1120 | + 'enforce_label_size' => true, |
|
1121 | + ) |
|
1122 | + ), |
|
1123 | + ), |
|
1124 | + ) |
|
1125 | + ); |
|
1126 | + } |
|
1127 | + |
|
1128 | + |
|
1129 | + /** |
|
1130 | + * _payment_method_billing_info |
|
1131 | + * |
|
1132 | + * @access private |
|
1133 | + * @param EE_Payment_Method $payment_method |
|
1134 | + * @return EE_Form_Section_Proper |
|
1135 | + * @throws EE_Error |
|
1136 | + * @throws InvalidArgumentException |
|
1137 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1138 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1139 | + */ |
|
1140 | + private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
1141 | + { |
|
1142 | + $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
1143 | + ? true |
|
1144 | + : false; |
|
1145 | + // generate the billing form for payment method |
|
1146 | + $billing_form = $currently_selected |
|
1147 | + ? $this->_get_billing_form_for_payment_method($payment_method) |
|
1148 | + : new EE_Form_Section_HTML(); |
|
1149 | + $this->checkout->billing_form = $currently_selected |
|
1150 | + ? $billing_form |
|
1151 | + : $this->checkout->billing_form; |
|
1152 | + // it's all in the details |
|
1153 | + $info_html = EEH_HTML::h3( |
|
1154 | + esc_html__('Important information regarding your payment', 'event_espresso'), |
|
1155 | + '', |
|
1156 | + 'spco-payment-method-hdr' |
|
1157 | + ); |
|
1158 | + // add some info regarding the step, either from what's saved in the admin, |
|
1159 | + // or a default string depending on whether the PM has a billing form or not |
|
1160 | + if ($payment_method->description()) { |
|
1161 | + $payment_method_info = $payment_method->description(); |
|
1162 | + } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
1163 | + $payment_method_info = sprintf( |
|
1164 | + esc_html__( |
|
1165 | + 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
1166 | + 'event_espresso' |
|
1167 | + ), |
|
1168 | + $this->submit_button_text() |
|
1169 | + ); |
|
1170 | + } else { |
|
1171 | + $payment_method_info = sprintf( |
|
1172 | + esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
1173 | + $this->submit_button_text() |
|
1174 | + ); |
|
1175 | + } |
|
1176 | + $info_html .= EEH_HTML::div( |
|
1177 | + apply_filters( |
|
1178 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
1179 | + $payment_method_info |
|
1180 | + ), |
|
1181 | + '', |
|
1182 | + 'spco-payment-method-desc ee-attention' |
|
1183 | + ); |
|
1184 | + return new EE_Form_Section_Proper( |
|
1185 | + array( |
|
1186 | + 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1187 | + 'html_class' => 'spco-payment-method-info-dv', |
|
1188 | + // only display the selected or default PM |
|
1189 | + 'html_style' => $currently_selected ? '' : 'display:none;', |
|
1190 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1191 | + 'subsections' => array( |
|
1192 | + 'info' => new EE_Form_Section_HTML($info_html), |
|
1193 | + 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
1194 | + ), |
|
1195 | + ) |
|
1196 | + ); |
|
1197 | + } |
|
1198 | + |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * get_billing_form_html_for_payment_method |
|
1202 | + * |
|
1203 | + * @access public |
|
1204 | + * @return string |
|
1205 | + * @throws EE_Error |
|
1206 | + * @throws InvalidArgumentException |
|
1207 | + * @throws ReflectionException |
|
1208 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1209 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1210 | + */ |
|
1211 | + public function get_billing_form_html_for_payment_method() |
|
1212 | + { |
|
1213 | + // how have they chosen to pay? |
|
1214 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1215 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1216 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1217 | + return false; |
|
1218 | + } |
|
1219 | + if (apply_filters( |
|
1220 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1221 | + false |
|
1222 | + )) { |
|
1223 | + EE_Error::add_success( |
|
1224 | + apply_filters( |
|
1225 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1226 | + sprintf( |
|
1227 | + esc_html__( |
|
1228 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1229 | + 'event_espresso' |
|
1230 | + ), |
|
1231 | + $this->checkout->payment_method->name() |
|
1232 | + ) |
|
1233 | + ) |
|
1234 | + ); |
|
1235 | + } |
|
1236 | + // now generate billing form for selected method of payment |
|
1237 | + $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
1238 | + // fill form with attendee info if applicable |
|
1239 | + if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1240 | + && $this->checkout->transaction_has_primary_registrant() |
|
1241 | + ) { |
|
1242 | + $payment_method_billing_form->populate_from_attendee( |
|
1243 | + $this->checkout->transaction->primary_registration()->attendee() |
|
1244 | + ); |
|
1245 | + } |
|
1246 | + // and debug content |
|
1247 | + if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
1248 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1249 | + ) { |
|
1250 | + $payment_method_billing_form = |
|
1251 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1252 | + $payment_method_billing_form |
|
1253 | + ); |
|
1254 | + } |
|
1255 | + $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
1256 | + ? $payment_method_billing_form->get_html() |
|
1257 | + : ''; |
|
1258 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
1259 | + // localize validation rules for main form |
|
1260 | + $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
1261 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1262 | + return true; |
|
1263 | + } |
|
1264 | + |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * _get_billing_form_for_payment_method |
|
1268 | + * |
|
1269 | + * @access private |
|
1270 | + * @param EE_Payment_Method $payment_method |
|
1271 | + * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
1272 | + * @throws EE_Error |
|
1273 | + * @throws InvalidArgumentException |
|
1274 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1275 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1276 | + */ |
|
1277 | + private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
1278 | + { |
|
1279 | + $billing_form = $payment_method->type_obj()->billing_form( |
|
1280 | + $this->checkout->transaction, |
|
1281 | + array('amount_owing' => $this->checkout->amount_owing) |
|
1282 | + ); |
|
1283 | + if ($billing_form instanceof EE_Billing_Info_Form) { |
|
1284 | + if (apply_filters( |
|
1285 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1286 | + false |
|
1287 | + ) |
|
1288 | + && EE_Registry::instance()->REQ->is_set('payment_method') |
|
1289 | + ) { |
|
1290 | + EE_Error::add_success( |
|
1291 | + apply_filters( |
|
1292 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1293 | + sprintf( |
|
1294 | + esc_html__( |
|
1295 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1296 | + 'event_espresso' |
|
1297 | + ), |
|
1298 | + $payment_method->name() |
|
1299 | + ) |
|
1300 | + ) |
|
1301 | + ); |
|
1302 | + } |
|
1303 | + return apply_filters( |
|
1304 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
1305 | + $billing_form, |
|
1306 | + $payment_method |
|
1307 | + ); |
|
1308 | + } |
|
1309 | + // no actual billing form, so return empty HTML form section |
|
1310 | + return new EE_Form_Section_HTML(); |
|
1311 | + } |
|
1312 | + |
|
1313 | + |
|
1314 | + /** |
|
1315 | + * _get_selected_method_of_payment |
|
1316 | + * |
|
1317 | + * @access private |
|
1318 | + * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
1319 | + * is not found in the incoming request |
|
1320 | + * @param string $request_param |
|
1321 | + * @return NULL|string |
|
1322 | + * @throws EE_Error |
|
1323 | + * @throws InvalidArgumentException |
|
1324 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1325 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1326 | + */ |
|
1327 | + private function _get_selected_method_of_payment( |
|
1328 | + $required = false, |
|
1329 | + $request_param = 'selected_method_of_payment' |
|
1330 | + ) { |
|
1331 | + // is selected_method_of_payment set in the request ? |
|
1332 | + $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
1333 | + if ($selected_method_of_payment) { |
|
1334 | + // sanitize it |
|
1335 | + $selected_method_of_payment = is_array($selected_method_of_payment) |
|
1336 | + ? array_shift($selected_method_of_payment) |
|
1337 | + : $selected_method_of_payment; |
|
1338 | + $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
1339 | + // store it in the session so that it's available for all subsequent requests including AJAX |
|
1340 | + $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
1341 | + } else { |
|
1342 | + // or is is set in the session ? |
|
1343 | + $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
1344 | + 'selected_method_of_payment' |
|
1345 | + ); |
|
1346 | + } |
|
1347 | + // do ya really really gotta have it? |
|
1348 | + if (empty($selected_method_of_payment) && $required) { |
|
1349 | + EE_Error::add_error( |
|
1350 | + sprintf( |
|
1351 | + esc_html__( |
|
1352 | + 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
1353 | + 'event_espresso' |
|
1354 | + ), |
|
1355 | + '<br/>', |
|
1356 | + '<br/>', |
|
1357 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1358 | + ), |
|
1359 | + __FILE__, |
|
1360 | + __FUNCTION__, |
|
1361 | + __LINE__ |
|
1362 | + ); |
|
1363 | + return null; |
|
1364 | + } |
|
1365 | + return $selected_method_of_payment; |
|
1366 | + } |
|
1367 | + |
|
1368 | + |
|
1369 | + |
|
1370 | + |
|
1371 | + |
|
1372 | + |
|
1373 | + /********************************************************************************************************/ |
|
1374 | + /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
1375 | + /********************************************************************************************************/ |
|
1376 | + /** |
|
1377 | + * switch_payment_method |
|
1378 | + * |
|
1379 | + * @access public |
|
1380 | + * @return string |
|
1381 | + * @throws EE_Error |
|
1382 | + * @throws InvalidArgumentException |
|
1383 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1384 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1385 | + */ |
|
1386 | + public function switch_payment_method() |
|
1387 | + { |
|
1388 | + if (! $this->_verify_payment_method_is_set()) { |
|
1389 | + return false; |
|
1390 | + } |
|
1391 | + if (apply_filters( |
|
1392 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
1393 | + false |
|
1394 | + )) { |
|
1395 | + EE_Error::add_success( |
|
1396 | + apply_filters( |
|
1397 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
1398 | + sprintf( |
|
1399 | + esc_html__( |
|
1400 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
1401 | + 'event_espresso' |
|
1402 | + ), |
|
1403 | + $this->checkout->payment_method->name() |
|
1404 | + ) |
|
1405 | + ) |
|
1406 | + ); |
|
1407 | + } |
|
1408 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1409 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1410 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1411 | + $this->checkout->payment_method |
|
1412 | + ); |
|
1413 | + } |
|
1414 | + // fill form with attendee info if applicable |
|
1415 | + if (apply_filters( |
|
1416 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
1417 | + ( |
|
1418 | + $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
1419 | + && $this->checkout->transaction_has_primary_registrant() |
|
1420 | + ), |
|
1421 | + $this->checkout->billing_form, |
|
1422 | + $this->checkout->transaction |
|
1423 | + ) |
|
1424 | + ) { |
|
1425 | + $this->checkout->billing_form->populate_from_attendee( |
|
1426 | + $this->checkout->transaction->primary_registration()->attendee() |
|
1427 | + ); |
|
1428 | + } |
|
1429 | + // and debug content |
|
1430 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1431 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1432 | + ) { |
|
1433 | + $this->checkout->billing_form = |
|
1434 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
1435 | + $this->checkout->billing_form |
|
1436 | + ); |
|
1437 | + } |
|
1438 | + // get html and validation rules for form |
|
1439 | + if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
1440 | + $this->checkout->json_response->set_return_data( |
|
1441 | + array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
1442 | + ); |
|
1443 | + // localize validation rules for main form |
|
1444 | + $this->checkout->billing_form->localize_validation_rules(true); |
|
1445 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1446 | + } else { |
|
1447 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
1448 | + } |
|
1449 | + // prevents advancement to next step |
|
1450 | + $this->checkout->continue_reg = false; |
|
1451 | + return true; |
|
1452 | + } |
|
1453 | + |
|
1454 | + |
|
1455 | + /** |
|
1456 | + * _verify_payment_method_is_set |
|
1457 | + * |
|
1458 | + * @return bool |
|
1459 | + * @throws EE_Error |
|
1460 | + * @throws InvalidArgumentException |
|
1461 | + * @throws ReflectionException |
|
1462 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1463 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1464 | + */ |
|
1465 | + protected function _verify_payment_method_is_set() |
|
1466 | + { |
|
1467 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1468 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
1469 | + // how have they chosen to pay? |
|
1470 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1471 | + } else { |
|
1472 | + // choose your own adventure based on method_of_payment |
|
1473 | + switch ($this->checkout->selected_method_of_payment) { |
|
1474 | + case 'events_sold_out': |
|
1475 | + EE_Error::add_attention( |
|
1476 | + apply_filters( |
|
1477 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
1478 | + esc_html__( |
|
1479 | + 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
1480 | + 'event_espresso' |
|
1481 | + ) |
|
1482 | + ), |
|
1483 | + __FILE__, |
|
1484 | + __FUNCTION__, |
|
1485 | + __LINE__ |
|
1486 | + ); |
|
1487 | + return false; |
|
1488 | + break; |
|
1489 | + case 'payments_closed': |
|
1490 | + EE_Error::add_attention( |
|
1491 | + apply_filters( |
|
1492 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
1493 | + esc_html__( |
|
1494 | + 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
1495 | + 'event_espresso' |
|
1496 | + ) |
|
1497 | + ), |
|
1498 | + __FILE__, |
|
1499 | + __FUNCTION__, |
|
1500 | + __LINE__ |
|
1501 | + ); |
|
1502 | + return false; |
|
1503 | + break; |
|
1504 | + case 'no_payment_required': |
|
1505 | + EE_Error::add_attention( |
|
1506 | + apply_filters( |
|
1507 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
1508 | + esc_html__( |
|
1509 | + 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
1510 | + 'event_espresso' |
|
1511 | + ) |
|
1512 | + ), |
|
1513 | + __FILE__, |
|
1514 | + __FUNCTION__, |
|
1515 | + __LINE__ |
|
1516 | + ); |
|
1517 | + return false; |
|
1518 | + break; |
|
1519 | + default: |
|
1520 | + } |
|
1521 | + } |
|
1522 | + // verify payment method |
|
1523 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1524 | + // get payment method for selected method of payment |
|
1525 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
1526 | + } |
|
1527 | + return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
1528 | + } |
|
1529 | + |
|
1530 | + |
|
1531 | + |
|
1532 | + /********************************************************************************************************/ |
|
1533 | + /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
1534 | + /********************************************************************************************************/ |
|
1535 | + /** |
|
1536 | + * save_payer_details_via_ajax |
|
1537 | + * |
|
1538 | + * @return void |
|
1539 | + * @throws EE_Error |
|
1540 | + * @throws InvalidArgumentException |
|
1541 | + * @throws ReflectionException |
|
1542 | + * @throws RuntimeException |
|
1543 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1544 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1545 | + */ |
|
1546 | + public function save_payer_details_via_ajax() |
|
1547 | + { |
|
1548 | + if (! $this->_verify_payment_method_is_set()) { |
|
1549 | + return; |
|
1550 | + } |
|
1551 | + // generate billing form for selected method of payment if it hasn't been done already |
|
1552 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1553 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1554 | + $this->checkout->payment_method |
|
1555 | + ); |
|
1556 | + } |
|
1557 | + // generate primary attendee from payer info if applicable |
|
1558 | + if (! $this->checkout->transaction_has_primary_registrant()) { |
|
1559 | + $attendee = $this->_create_attendee_from_request_data(); |
|
1560 | + if ($attendee instanceof EE_Attendee) { |
|
1561 | + foreach ($this->checkout->transaction->registrations() as $registration) { |
|
1562 | + if ($registration->is_primary_registrant()) { |
|
1563 | + $this->checkout->primary_attendee_obj = $attendee; |
|
1564 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1565 | + $registration->set_attendee_id($attendee->ID()); |
|
1566 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1567 | + } |
|
1568 | + } |
|
1569 | + } |
|
1570 | + } |
|
1571 | + } |
|
1572 | + |
|
1573 | + |
|
1574 | + /** |
|
1575 | + * create_attendee_from_request_data |
|
1576 | + * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
1577 | + * |
|
1578 | + * @return EE_Attendee |
|
1579 | + * @throws EE_Error |
|
1580 | + * @throws InvalidArgumentException |
|
1581 | + * @throws ReflectionException |
|
1582 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1583 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1584 | + */ |
|
1585 | + protected function _create_attendee_from_request_data() |
|
1586 | + { |
|
1587 | + // get State ID |
|
1588 | + $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
1589 | + if (! empty($STA_ID)) { |
|
1590 | + // can we get state object from name ? |
|
1591 | + EE_Registry::instance()->load_model('State'); |
|
1592 | + $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
1593 | + $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
1594 | + } |
|
1595 | + // get Country ISO |
|
1596 | + $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
1597 | + if (! empty($CNT_ISO)) { |
|
1598 | + // can we get country object from name ? |
|
1599 | + EE_Registry::instance()->load_model('Country'); |
|
1600 | + $country = EEM_Country::instance()->get_col( |
|
1601 | + array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
1602 | + 'CNT_ISO' |
|
1603 | + ); |
|
1604 | + $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
1605 | + } |
|
1606 | + // grab attendee data |
|
1607 | + $attendee_data = array( |
|
1608 | + 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
1609 | + 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
1610 | + 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
1611 | + 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
1612 | + 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
1613 | + 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
1614 | + 'STA_ID' => $STA_ID, |
|
1615 | + 'CNT_ISO' => $CNT_ISO, |
|
1616 | + 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
1617 | + 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
1618 | + ); |
|
1619 | + // validate the email address since it is the most important piece of info |
|
1620 | + if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
1621 | + EE_Error::add_error( |
|
1622 | + esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
1623 | + __FILE__, |
|
1624 | + __FUNCTION__, |
|
1625 | + __LINE__ |
|
1626 | + ); |
|
1627 | + } |
|
1628 | + // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
1629 | + // AND email address |
|
1630 | + if (! empty($attendee_data['ATT_fname']) |
|
1631 | + && ! empty($attendee_data['ATT_lname']) |
|
1632 | + && ! empty($attendee_data['ATT_email']) |
|
1633 | + ) { |
|
1634 | + $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
1635 | + array( |
|
1636 | + 'ATT_fname' => $attendee_data['ATT_fname'], |
|
1637 | + 'ATT_lname' => $attendee_data['ATT_lname'], |
|
1638 | + 'ATT_email' => $attendee_data['ATT_email'], |
|
1639 | + ) |
|
1640 | + ); |
|
1641 | + if ($existing_attendee instanceof EE_Attendee) { |
|
1642 | + return $existing_attendee; |
|
1643 | + } |
|
1644 | + } |
|
1645 | + // no existing attendee? kk let's create a new one |
|
1646 | + // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
1647 | + // don't exist |
|
1648 | + $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
1649 | + ? $attendee_data['ATT_fname'] |
|
1650 | + : $attendee_data['ATT_email']; |
|
1651 | + $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
1652 | + ? $attendee_data['ATT_lname'] |
|
1653 | + : $attendee_data['ATT_email']; |
|
1654 | + return EE_Attendee::new_instance($attendee_data); |
|
1655 | + } |
|
1656 | + |
|
1657 | + |
|
1658 | + |
|
1659 | + /********************************************************************************************************/ |
|
1660 | + /**************************************** PROCESS REG STEP *****************************************/ |
|
1661 | + /********************************************************************************************************/ |
|
1662 | + /** |
|
1663 | + * process_reg_step |
|
1664 | + * |
|
1665 | + * @return bool |
|
1666 | + * @throws EE_Error |
|
1667 | + * @throws InvalidArgumentException |
|
1668 | + * @throws ReflectionException |
|
1669 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1670 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1671 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1672 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1673 | + */ |
|
1674 | + public function process_reg_step() |
|
1675 | + { |
|
1676 | + // how have they chosen to pay? |
|
1677 | + $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
1678 | + ? 'no_payment_required' |
|
1679 | + : $this->_get_selected_method_of_payment(true); |
|
1680 | + // choose your own adventure based on method_of_payment |
|
1681 | + switch ($this->checkout->selected_method_of_payment) { |
|
1682 | + case 'events_sold_out': |
|
1683 | + $this->checkout->redirect = true; |
|
1684 | + $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
1685 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1686 | + // mark this reg step as completed |
|
1687 | + $this->set_completed(); |
|
1688 | + return false; |
|
1689 | + break; |
|
1690 | + |
|
1691 | + case 'payments_closed': |
|
1692 | + if (apply_filters( |
|
1693 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
1694 | + false |
|
1695 | + )) { |
|
1696 | + EE_Error::add_success( |
|
1697 | + esc_html__('no payment required at this time.', 'event_espresso'), |
|
1698 | + __FILE__, |
|
1699 | + __FUNCTION__, |
|
1700 | + __LINE__ |
|
1701 | + ); |
|
1702 | + } |
|
1703 | + // mark this reg step as completed |
|
1704 | + $this->set_completed(); |
|
1705 | + return true; |
|
1706 | + break; |
|
1707 | + |
|
1708 | + case 'no_payment_required': |
|
1709 | + if (apply_filters( |
|
1710 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
1711 | + false |
|
1712 | + )) { |
|
1713 | + EE_Error::add_success( |
|
1714 | + esc_html__('no payment required.', 'event_espresso'), |
|
1715 | + __FILE__, |
|
1716 | + __FUNCTION__, |
|
1717 | + __LINE__ |
|
1718 | + ); |
|
1719 | + } |
|
1720 | + // mark this reg step as completed |
|
1721 | + $this->set_completed(); |
|
1722 | + return true; |
|
1723 | + break; |
|
1724 | + |
|
1725 | + default: |
|
1726 | + $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
1727 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
1728 | + ); |
|
1729 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
1730 | + $registrations, |
|
1731 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
1732 | + ); |
|
1733 | + // calculate difference between the two arrays |
|
1734 | + $registrations = array_diff($registrations, $ejected_registrations); |
|
1735 | + if (empty($registrations)) { |
|
1736 | + $this->_redirect_because_event_sold_out(); |
|
1737 | + return false; |
|
1738 | + } |
|
1739 | + $payment_successful = $this->_process_payment(); |
|
1740 | + if ($payment_successful) { |
|
1741 | + $this->checkout->continue_reg = true; |
|
1742 | + $this->_maybe_set_completed($this->checkout->payment_method); |
|
1743 | + } else { |
|
1744 | + $this->checkout->continue_reg = false; |
|
1745 | + } |
|
1746 | + return $payment_successful; |
|
1747 | + } |
|
1748 | + } |
|
1749 | + |
|
1750 | + |
|
1751 | + /** |
|
1752 | + * _redirect_because_event_sold_out |
|
1753 | + * |
|
1754 | + * @access protected |
|
1755 | + * @return void |
|
1756 | + */ |
|
1757 | + protected function _redirect_because_event_sold_out() |
|
1758 | + { |
|
1759 | + $this->checkout->continue_reg = false; |
|
1760 | + // set redirect URL |
|
1761 | + $this->checkout->redirect_url = add_query_arg( |
|
1762 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1763 | + $this->checkout->current_step->reg_step_url() |
|
1764 | + ); |
|
1765 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1766 | + } |
|
1767 | + |
|
1768 | + |
|
1769 | + /** |
|
1770 | + * _maybe_set_completed |
|
1771 | + * |
|
1772 | + * @access protected |
|
1773 | + * @param \EE_Payment_Method $payment_method |
|
1774 | + * @return void |
|
1775 | + * @throws \EE_Error |
|
1776 | + */ |
|
1777 | + protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
1778 | + { |
|
1779 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
1780 | + case EE_PMT_Base::offsite: |
|
1781 | + break; |
|
1782 | + case EE_PMT_Base::onsite: |
|
1783 | + case EE_PMT_Base::offline: |
|
1784 | + // mark this reg step as completed |
|
1785 | + $this->set_completed(); |
|
1786 | + break; |
|
1787 | + } |
|
1788 | + } |
|
1789 | + |
|
1790 | + |
|
1791 | + /** |
|
1792 | + * update_reg_step |
|
1793 | + * this is the final step after a user revisits the site to retry a payment |
|
1794 | + * |
|
1795 | + * @return bool |
|
1796 | + * @throws EE_Error |
|
1797 | + * @throws InvalidArgumentException |
|
1798 | + * @throws ReflectionException |
|
1799 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
1800 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1801 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1802 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
1803 | + */ |
|
1804 | + public function update_reg_step() |
|
1805 | + { |
|
1806 | + $success = true; |
|
1807 | + // if payment required |
|
1808 | + if ($this->checkout->transaction->total() > 0) { |
|
1809 | + do_action( |
|
1810 | + 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
1811 | + $this->checkout->transaction |
|
1812 | + ); |
|
1813 | + // attempt payment via payment method |
|
1814 | + $success = $this->process_reg_step(); |
|
1815 | + } |
|
1816 | + if ($success && ! $this->checkout->redirect) { |
|
1817 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
1818 | + $this->checkout->transaction->ID() |
|
1819 | + ); |
|
1820 | + // set return URL |
|
1821 | + $this->checkout->redirect_url = add_query_arg( |
|
1822 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1823 | + $this->checkout->thank_you_page_url |
|
1824 | + ); |
|
1825 | + } |
|
1826 | + return $success; |
|
1827 | + } |
|
1828 | + |
|
1829 | + |
|
1830 | + /** |
|
1831 | + * _process_payment |
|
1832 | + * |
|
1833 | + * @access private |
|
1834 | + * @return bool |
|
1835 | + * @throws EE_Error |
|
1836 | + * @throws InvalidArgumentException |
|
1837 | + * @throws ReflectionException |
|
1838 | + * @throws RuntimeException |
|
1839 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1840 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1841 | + */ |
|
1842 | + private function _process_payment() |
|
1843 | + { |
|
1844 | + // basically confirm that the event hasn't sold out since they hit the page |
|
1845 | + if (! $this->_last_second_ticket_verifications()) { |
|
1846 | + return false; |
|
1847 | + } |
|
1848 | + // ya gotta make a choice man |
|
1849 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
1850 | + $this->checkout->json_response->set_plz_select_method_of_payment( |
|
1851 | + esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
1852 | + ); |
|
1853 | + return false; |
|
1854 | + } |
|
1855 | + // get EE_Payment_Method object |
|
1856 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1857 | + return false; |
|
1858 | + } |
|
1859 | + // setup billing form |
|
1860 | + if ($this->checkout->payment_method->is_on_site()) { |
|
1861 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
1862 | + $this->checkout->payment_method |
|
1863 | + ); |
|
1864 | + // bad billing form ? |
|
1865 | + if (! $this->_billing_form_is_valid()) { |
|
1866 | + return false; |
|
1867 | + } |
|
1868 | + } |
|
1869 | + // ensure primary registrant has been fully processed |
|
1870 | + if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1871 | + return false; |
|
1872 | + } |
|
1873 | + // if session is close to expiring (under 10 minutes by default) |
|
1874 | + if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
1875 | + // add some time to session expiration so that payment can be completed |
|
1876 | + EE_Registry::instance()->SSN->extend_expiration(); |
|
1877 | + } |
|
1878 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
1879 | + // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
1880 | + // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
1881 | + // for events with a default reg status of Approved |
|
1882 | + // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
1883 | + // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
1884 | + // ); |
|
1885 | + // attempt payment |
|
1886 | + $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
1887 | + // process results |
|
1888 | + $payment = $this->_validate_payment($payment); |
|
1889 | + $payment = $this->_post_payment_processing($payment); |
|
1890 | + // verify payment |
|
1891 | + if ($payment instanceof EE_Payment) { |
|
1892 | + // store that for later |
|
1893 | + $this->checkout->payment = $payment; |
|
1894 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
1895 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1896 | + $payment_status = $payment->status(); |
|
1897 | + if ($payment_status === EEM_Payment::status_id_approved |
|
1898 | + || $payment_status === EEM_Payment::status_id_pending |
|
1899 | + ) { |
|
1900 | + return true; |
|
1901 | + } else { |
|
1902 | + return false; |
|
1903 | + } |
|
1904 | + } elseif ($payment === true) { |
|
1905 | + // please note that offline payment methods will NOT make a payment, |
|
1906 | + // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
1907 | + $this->checkout->payment = $payment; |
|
1908 | + return true; |
|
1909 | + } |
|
1910 | + // where's my money? |
|
1911 | + return false; |
|
1912 | + } |
|
1913 | + |
|
1914 | + |
|
1915 | + /** |
|
1916 | + * _last_second_ticket_verifications |
|
1917 | + * |
|
1918 | + * @access public |
|
1919 | + * @return bool |
|
1920 | + * @throws EE_Error |
|
1921 | + */ |
|
1922 | + protected function _last_second_ticket_verifications() |
|
1923 | + { |
|
1924 | + // don't bother re-validating if not a return visit |
|
1925 | + if (! $this->checkout->revisit) { |
|
1926 | + return true; |
|
1927 | + } |
|
1928 | + $registrations = $this->checkout->transaction->registrations(); |
|
1929 | + if (empty($registrations)) { |
|
1930 | + return false; |
|
1931 | + } |
|
1932 | + foreach ($registrations as $registration) { |
|
1933 | + if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
1934 | + $event = $registration->event_obj(); |
|
1935 | + if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
1936 | + EE_Error::add_error( |
|
1937 | + apply_filters( |
|
1938 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
1939 | + sprintf( |
|
1940 | + esc_html__( |
|
1941 | + 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
1942 | + 'event_espresso' |
|
1943 | + ), |
|
1944 | + $event->name() |
|
1945 | + ) |
|
1946 | + ), |
|
1947 | + __FILE__, |
|
1948 | + __FUNCTION__, |
|
1949 | + __LINE__ |
|
1950 | + ); |
|
1951 | + return false; |
|
1952 | + } |
|
1953 | + } |
|
1954 | + } |
|
1955 | + return true; |
|
1956 | + } |
|
1957 | + |
|
1958 | + |
|
1959 | + /** |
|
1960 | + * redirect_form |
|
1961 | + * |
|
1962 | + * @access public |
|
1963 | + * @return bool |
|
1964 | + * @throws EE_Error |
|
1965 | + * @throws InvalidArgumentException |
|
1966 | + * @throws ReflectionException |
|
1967 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
1968 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
1969 | + */ |
|
1970 | + public function redirect_form() |
|
1971 | + { |
|
1972 | + $payment_method_billing_info = $this->_payment_method_billing_info( |
|
1973 | + $this->_get_payment_method_for_selected_method_of_payment() |
|
1974 | + ); |
|
1975 | + $html = $payment_method_billing_info->get_html(); |
|
1976 | + $html .= $this->checkout->redirect_form; |
|
1977 | + EE_Registry::instance()->REQ->add_output($html); |
|
1978 | + return true; |
|
1979 | + } |
|
1980 | + |
|
1981 | + |
|
1982 | + /** |
|
1983 | + * _billing_form_is_valid |
|
1984 | + * |
|
1985 | + * @access private |
|
1986 | + * @return bool |
|
1987 | + * @throws \EE_Error |
|
1988 | + */ |
|
1989 | + private function _billing_form_is_valid() |
|
1990 | + { |
|
1991 | + if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1992 | + return true; |
|
1993 | + } |
|
1994 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
1995 | + if ($this->checkout->billing_form->was_submitted()) { |
|
1996 | + $this->checkout->billing_form->receive_form_submission(); |
|
1997 | + if ($this->checkout->billing_form->is_valid()) { |
|
1998 | + return true; |
|
1999 | + } |
|
2000 | + $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
2001 | + $error_strings = array(); |
|
2002 | + foreach ($validation_errors as $validation_error) { |
|
2003 | + if ($validation_error instanceof EE_Validation_Error) { |
|
2004 | + $form_section = $validation_error->get_form_section(); |
|
2005 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
2006 | + $label = $form_section->html_label_text(); |
|
2007 | + } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
2008 | + $label = $form_section->name(); |
|
2009 | + } else { |
|
2010 | + $label = esc_html__('Validation Error', 'event_espresso'); |
|
2011 | + } |
|
2012 | + $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
2013 | + } |
|
2014 | + } |
|
2015 | + EE_Error::add_error( |
|
2016 | + sprintf( |
|
2017 | + esc_html__( |
|
2018 | + 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
2019 | + 'event_espresso' |
|
2020 | + ), |
|
2021 | + '<br/>', |
|
2022 | + implode('<br/>', $error_strings) |
|
2023 | + ), |
|
2024 | + __FILE__, |
|
2025 | + __FUNCTION__, |
|
2026 | + __LINE__ |
|
2027 | + ); |
|
2028 | + } else { |
|
2029 | + EE_Error::add_error( |
|
2030 | + esc_html__( |
|
2031 | + 'The billing form was not submitted or something prevented it\'s submission.', |
|
2032 | + 'event_espresso' |
|
2033 | + ), |
|
2034 | + __FILE__, |
|
2035 | + __FUNCTION__, |
|
2036 | + __LINE__ |
|
2037 | + ); |
|
2038 | + } |
|
2039 | + } else { |
|
2040 | + EE_Error::add_error( |
|
2041 | + esc_html__( |
|
2042 | + 'The submitted billing form is invalid possibly due to a technical reason.', |
|
2043 | + 'event_espresso' |
|
2044 | + ), |
|
2045 | + __FILE__, |
|
2046 | + __FUNCTION__, |
|
2047 | + __LINE__ |
|
2048 | + ); |
|
2049 | + } |
|
2050 | + return false; |
|
2051 | + } |
|
2052 | + |
|
2053 | + |
|
2054 | + /** |
|
2055 | + * _setup_primary_registrant_prior_to_payment |
|
2056 | + * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
2057 | + * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
2058 | + * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
2059 | + * yet) |
|
2060 | + * |
|
2061 | + * @access private |
|
2062 | + * @return bool |
|
2063 | + * @throws EE_Error |
|
2064 | + * @throws InvalidArgumentException |
|
2065 | + * @throws ReflectionException |
|
2066 | + * @throws RuntimeException |
|
2067 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2068 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2069 | + */ |
|
2070 | + private function _setup_primary_registrant_prior_to_payment() |
|
2071 | + { |
|
2072 | + // check if transaction has a primary registrant and that it has a related Attendee object |
|
2073 | + // if not, then we need to at least gather some primary registrant data before attempting payment |
|
2074 | + if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
2075 | + && ! $this->checkout->transaction_has_primary_registrant() |
|
2076 | + && ! $this->_capture_primary_registration_data_from_billing_form() |
|
2077 | + ) { |
|
2078 | + return false; |
|
2079 | + } |
|
2080 | + // because saving an object clears it's cache, we need to do the chevy shuffle |
|
2081 | + // grab the primary_registration object |
|
2082 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2083 | + // at this point we'll consider a TXN to not have been failed |
|
2084 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
2085 | + // save the TXN ( which clears cached copy of primary_registration) |
|
2086 | + $this->checkout->transaction->save(); |
|
2087 | + // grab TXN ID and save it to the primary_registration |
|
2088 | + $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
2089 | + // save what we have so far |
|
2090 | + $primary_registration->save(); |
|
2091 | + return true; |
|
2092 | + } |
|
2093 | + |
|
2094 | + |
|
2095 | + /** |
|
2096 | + * _capture_primary_registration_data_from_billing_form |
|
2097 | + * |
|
2098 | + * @access private |
|
2099 | + * @return bool |
|
2100 | + * @throws EE_Error |
|
2101 | + * @throws InvalidArgumentException |
|
2102 | + * @throws ReflectionException |
|
2103 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2104 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2105 | + */ |
|
2106 | + private function _capture_primary_registration_data_from_billing_form() |
|
2107 | + { |
|
2108 | + // convert billing form data into an attendee |
|
2109 | + $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
2110 | + if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2111 | + EE_Error::add_error( |
|
2112 | + sprintf( |
|
2113 | + esc_html__( |
|
2114 | + 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2115 | + 'event_espresso' |
|
2116 | + ), |
|
2117 | + '<br/>', |
|
2118 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2119 | + ), |
|
2120 | + __FILE__, |
|
2121 | + __FUNCTION__, |
|
2122 | + __LINE__ |
|
2123 | + ); |
|
2124 | + return false; |
|
2125 | + } |
|
2126 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
2127 | + if (! $primary_registration instanceof EE_Registration) { |
|
2128 | + EE_Error::add_error( |
|
2129 | + sprintf( |
|
2130 | + esc_html__( |
|
2131 | + 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2132 | + 'event_espresso' |
|
2133 | + ), |
|
2134 | + '<br/>', |
|
2135 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2136 | + ), |
|
2137 | + __FILE__, |
|
2138 | + __FUNCTION__, |
|
2139 | + __LINE__ |
|
2140 | + ); |
|
2141 | + return false; |
|
2142 | + } |
|
2143 | + if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
2144 | + instanceof |
|
2145 | + EE_Attendee |
|
2146 | + ) { |
|
2147 | + EE_Error::add_error( |
|
2148 | + sprintf( |
|
2149 | + esc_html__( |
|
2150 | + 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2151 | + 'event_espresso' |
|
2152 | + ), |
|
2153 | + '<br/>', |
|
2154 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2155 | + ), |
|
2156 | + __FILE__, |
|
2157 | + __FUNCTION__, |
|
2158 | + __LINE__ |
|
2159 | + ); |
|
2160 | + return false; |
|
2161 | + } |
|
2162 | + /** @type EE_Registration_Processor $registration_processor */ |
|
2163 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
2164 | + // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
2165 | + $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
2166 | + return true; |
|
2167 | + } |
|
2168 | + |
|
2169 | + |
|
2170 | + /** |
|
2171 | + * _get_payment_method_for_selected_method_of_payment |
|
2172 | + * retrieves a valid payment method |
|
2173 | + * |
|
2174 | + * @access public |
|
2175 | + * @return EE_Payment_Method |
|
2176 | + * @throws EE_Error |
|
2177 | + * @throws InvalidArgumentException |
|
2178 | + * @throws ReflectionException |
|
2179 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2180 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2181 | + */ |
|
2182 | + private function _get_payment_method_for_selected_method_of_payment() |
|
2183 | + { |
|
2184 | + if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
2185 | + $this->_redirect_because_event_sold_out(); |
|
2186 | + return null; |
|
2187 | + } |
|
2188 | + // get EE_Payment_Method object |
|
2189 | + if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
2190 | + $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2191 | + } else { |
|
2192 | + // load EEM_Payment_Method |
|
2193 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
2194 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
2195 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
2196 | + $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
2197 | + } |
|
2198 | + // verify $payment_method |
|
2199 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
2200 | + // not a payment |
|
2201 | + EE_Error::add_error( |
|
2202 | + sprintf( |
|
2203 | + esc_html__( |
|
2204 | + 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2205 | + 'event_espresso' |
|
2206 | + ), |
|
2207 | + '<br/>', |
|
2208 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2209 | + ), |
|
2210 | + __FILE__, |
|
2211 | + __FUNCTION__, |
|
2212 | + __LINE__ |
|
2213 | + ); |
|
2214 | + return null; |
|
2215 | + } |
|
2216 | + // and verify it has a valid Payment_Method Type object |
|
2217 | + if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2218 | + // not a payment |
|
2219 | + EE_Error::add_error( |
|
2220 | + sprintf( |
|
2221 | + esc_html__( |
|
2222 | + 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2223 | + 'event_espresso' |
|
2224 | + ), |
|
2225 | + '<br/>', |
|
2226 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2227 | + ), |
|
2228 | + __FILE__, |
|
2229 | + __FUNCTION__, |
|
2230 | + __LINE__ |
|
2231 | + ); |
|
2232 | + return null; |
|
2233 | + } |
|
2234 | + return $payment_method; |
|
2235 | + } |
|
2236 | + |
|
2237 | + |
|
2238 | + /** |
|
2239 | + * _attempt_payment |
|
2240 | + * |
|
2241 | + * @access private |
|
2242 | + * @type EE_Payment_Method $payment_method |
|
2243 | + * @return mixed EE_Payment | boolean |
|
2244 | + * @throws EE_Error |
|
2245 | + * @throws InvalidArgumentException |
|
2246 | + * @throws ReflectionException |
|
2247 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2248 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2249 | + */ |
|
2250 | + private function _attempt_payment(EE_Payment_Method $payment_method) |
|
2251 | + { |
|
2252 | + $payment = null; |
|
2253 | + $this->checkout->transaction->save(); |
|
2254 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2255 | + if (! $payment_processor instanceof EE_Payment_Processor) { |
|
2256 | + return false; |
|
2257 | + } |
|
2258 | + try { |
|
2259 | + $payment_processor->set_revisit($this->checkout->revisit); |
|
2260 | + // generate payment object |
|
2261 | + $payment = $payment_processor->process_payment( |
|
2262 | + $payment_method, |
|
2263 | + $this->checkout->transaction, |
|
2264 | + $this->checkout->amount_owing, |
|
2265 | + $this->checkout->billing_form, |
|
2266 | + $this->_get_return_url($payment_method), |
|
2267 | + 'CART', |
|
2268 | + $this->checkout->admin_request, |
|
2269 | + true, |
|
2270 | + $this->reg_step_url() |
|
2271 | + ); |
|
2272 | + } catch (Exception $e) { |
|
2273 | + $this->_handle_payment_processor_exception($e); |
|
2274 | + } |
|
2275 | + return $payment; |
|
2276 | + } |
|
2277 | + |
|
2278 | + |
|
2279 | + /** |
|
2280 | + * _handle_payment_processor_exception |
|
2281 | + * |
|
2282 | + * @access protected |
|
2283 | + * @param \Exception $e |
|
2284 | + * @return void |
|
2285 | + * @throws EE_Error |
|
2286 | + * @throws InvalidArgumentException |
|
2287 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2288 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2289 | + */ |
|
2290 | + protected function _handle_payment_processor_exception(Exception $e) |
|
2291 | + { |
|
2292 | + EE_Error::add_error( |
|
2293 | + sprintf( |
|
2294 | + esc_html__( |
|
2295 | + 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
2296 | + 'event_espresso' |
|
2297 | + ), |
|
2298 | + '<br/>', |
|
2299 | + EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
2300 | + $e->getMessage(), |
|
2301 | + $e->getFile(), |
|
2302 | + $e->getLine() |
|
2303 | + ), |
|
2304 | + __FILE__, |
|
2305 | + __FUNCTION__, |
|
2306 | + __LINE__ |
|
2307 | + ); |
|
2308 | + } |
|
2309 | + |
|
2310 | + |
|
2311 | + /** |
|
2312 | + * _get_return_url |
|
2313 | + * |
|
2314 | + * @access protected |
|
2315 | + * @param \EE_Payment_Method $payment_method |
|
2316 | + * @return string |
|
2317 | + * @throws \EE_Error |
|
2318 | + */ |
|
2319 | + protected function _get_return_url(EE_Payment_Method $payment_method) |
|
2320 | + { |
|
2321 | + $return_url = ''; |
|
2322 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
2323 | + case EE_PMT_Base::offsite: |
|
2324 | + $return_url = add_query_arg( |
|
2325 | + array( |
|
2326 | + 'action' => 'process_gateway_response', |
|
2327 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2328 | + 'spco_txn' => $this->checkout->transaction->ID(), |
|
2329 | + ), |
|
2330 | + $this->reg_step_url() |
|
2331 | + ); |
|
2332 | + break; |
|
2333 | + case EE_PMT_Base::onsite: |
|
2334 | + case EE_PMT_Base::offline: |
|
2335 | + $return_url = $this->checkout->next_step->reg_step_url(); |
|
2336 | + break; |
|
2337 | + } |
|
2338 | + return $return_url; |
|
2339 | + } |
|
2340 | + |
|
2341 | + |
|
2342 | + /** |
|
2343 | + * _validate_payment |
|
2344 | + * |
|
2345 | + * @access private |
|
2346 | + * @param EE_Payment $payment |
|
2347 | + * @return EE_Payment|FALSE |
|
2348 | + * @throws EE_Error |
|
2349 | + * @throws InvalidArgumentException |
|
2350 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2351 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2352 | + */ |
|
2353 | + private function _validate_payment($payment = null) |
|
2354 | + { |
|
2355 | + if ($this->checkout->payment_method->is_off_line()) { |
|
2356 | + return true; |
|
2357 | + } |
|
2358 | + // verify payment object |
|
2359 | + if (! $payment instanceof EE_Payment) { |
|
2360 | + // not a payment |
|
2361 | + EE_Error::add_error( |
|
2362 | + sprintf( |
|
2363 | + esc_html__( |
|
2364 | + 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
2365 | + 'event_espresso' |
|
2366 | + ), |
|
2367 | + '<br/>', |
|
2368 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2369 | + ), |
|
2370 | + __FILE__, |
|
2371 | + __FUNCTION__, |
|
2372 | + __LINE__ |
|
2373 | + ); |
|
2374 | + return false; |
|
2375 | + } |
|
2376 | + return $payment; |
|
2377 | + } |
|
2378 | + |
|
2379 | + |
|
2380 | + /** |
|
2381 | + * _post_payment_processing |
|
2382 | + * |
|
2383 | + * @access private |
|
2384 | + * @param EE_Payment|bool $payment |
|
2385 | + * @return bool |
|
2386 | + * @throws EE_Error |
|
2387 | + * @throws InvalidArgumentException |
|
2388 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2389 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2390 | + */ |
|
2391 | + private function _post_payment_processing($payment = null) |
|
2392 | + { |
|
2393 | + // Off-Line payment? |
|
2394 | + if ($payment === true) { |
|
2395 | + // $this->_setup_redirect_for_next_step(); |
|
2396 | + return true; |
|
2397 | + // On-Site payment? |
|
2398 | + } elseif ($this->checkout->payment_method->is_on_site()) { |
|
2399 | + if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2400 | + // $this->_setup_redirect_for_next_step(); |
|
2401 | + $this->checkout->continue_reg = false; |
|
2402 | + } |
|
2403 | + // Off-Site payment? |
|
2404 | + } elseif ($this->checkout->payment_method->is_off_site()) { |
|
2405 | + // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
2406 | + if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
2407 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
2408 | + $this->checkout->redirect = true; |
|
2409 | + $this->checkout->redirect_form = $payment->redirect_form(); |
|
2410 | + $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
2411 | + // set JSON response |
|
2412 | + $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
2413 | + // and lastly, let's bump the payment status to pending |
|
2414 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
2415 | + $payment->save(); |
|
2416 | + } else { |
|
2417 | + // not a payment |
|
2418 | + $this->checkout->continue_reg = false; |
|
2419 | + EE_Error::add_error( |
|
2420 | + sprintf( |
|
2421 | + esc_html__( |
|
2422 | + 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
2423 | + 'event_espresso' |
|
2424 | + ), |
|
2425 | + '<br/>', |
|
2426 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2427 | + ), |
|
2428 | + __FILE__, |
|
2429 | + __FUNCTION__, |
|
2430 | + __LINE__ |
|
2431 | + ); |
|
2432 | + } |
|
2433 | + } else { |
|
2434 | + // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
2435 | + $this->checkout->continue_reg = false; |
|
2436 | + return false; |
|
2437 | + } |
|
2438 | + return $payment; |
|
2439 | + } |
|
2440 | + |
|
2441 | + |
|
2442 | + /** |
|
2443 | + * _process_payment_status |
|
2444 | + * |
|
2445 | + * @access private |
|
2446 | + * @type EE_Payment $payment |
|
2447 | + * @param string $payment_occurs |
|
2448 | + * @return bool |
|
2449 | + * @throws EE_Error |
|
2450 | + * @throws InvalidArgumentException |
|
2451 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2452 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2453 | + */ |
|
2454 | + private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
2455 | + { |
|
2456 | + // off-line payment? carry on |
|
2457 | + if ($payment_occurs === EE_PMT_Base::offline) { |
|
2458 | + return true; |
|
2459 | + } |
|
2460 | + // verify payment validity |
|
2461 | + if ($payment instanceof EE_Payment) { |
|
2462 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
2463 | + $msg = $payment->gateway_response(); |
|
2464 | + // check results |
|
2465 | + switch ($payment->status()) { |
|
2466 | + // good payment |
|
2467 | + case EEM_Payment::status_id_approved: |
|
2468 | + EE_Error::add_success( |
|
2469 | + esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
2470 | + __FILE__, |
|
2471 | + __FUNCTION__, |
|
2472 | + __LINE__ |
|
2473 | + ); |
|
2474 | + return true; |
|
2475 | + break; |
|
2476 | + // slow payment |
|
2477 | + case EEM_Payment::status_id_pending: |
|
2478 | + if (empty($msg)) { |
|
2479 | + $msg = esc_html__( |
|
2480 | + 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
2481 | + 'event_espresso' |
|
2482 | + ); |
|
2483 | + } |
|
2484 | + EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2485 | + return true; |
|
2486 | + break; |
|
2487 | + // don't wanna payment |
|
2488 | + case EEM_Payment::status_id_cancelled: |
|
2489 | + if (empty($msg)) { |
|
2490 | + $msg = _n( |
|
2491 | + 'Payment cancelled. Please try again.', |
|
2492 | + 'Payment cancelled. Please try again or select another method of payment.', |
|
2493 | + count($this->checkout->available_payment_methods), |
|
2494 | + 'event_espresso' |
|
2495 | + ); |
|
2496 | + } |
|
2497 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2498 | + return false; |
|
2499 | + break; |
|
2500 | + // not enough payment |
|
2501 | + case EEM_Payment::status_id_declined: |
|
2502 | + if (empty($msg)) { |
|
2503 | + $msg = _n( |
|
2504 | + 'We\'re sorry but your payment was declined. Please try again.', |
|
2505 | + 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
2506 | + count($this->checkout->available_payment_methods), |
|
2507 | + 'event_espresso' |
|
2508 | + ); |
|
2509 | + } |
|
2510 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2511 | + return false; |
|
2512 | + break; |
|
2513 | + // bad payment |
|
2514 | + case EEM_Payment::status_id_failed: |
|
2515 | + if (! empty($msg)) { |
|
2516 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2517 | + return false; |
|
2518 | + } |
|
2519 | + // default to error below |
|
2520 | + break; |
|
2521 | + } |
|
2522 | + } |
|
2523 | + // off-site payment gateway responses are too unreliable, so let's just assume that |
|
2524 | + // the payment processing is just running slower than the registrant's request |
|
2525 | + if ($payment_occurs === EE_PMT_Base::offsite) { |
|
2526 | + return true; |
|
2527 | + } |
|
2528 | + EE_Error::add_error( |
|
2529 | + sprintf( |
|
2530 | + esc_html__( |
|
2531 | + 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
2532 | + 'event_espresso' |
|
2533 | + ), |
|
2534 | + '<br/>', |
|
2535 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2536 | + ), |
|
2537 | + __FILE__, |
|
2538 | + __FUNCTION__, |
|
2539 | + __LINE__ |
|
2540 | + ); |
|
2541 | + return false; |
|
2542 | + } |
|
2543 | + |
|
2544 | + |
|
2545 | + |
|
2546 | + |
|
2547 | + |
|
2548 | + |
|
2549 | + /********************************************************************************************************/ |
|
2550 | + /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
2551 | + /********************************************************************************************************/ |
|
2552 | + /** |
|
2553 | + * process_gateway_response |
|
2554 | + * this is the return point for Off-Site Payment Methods |
|
2555 | + * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
2556 | + * otherwise, it will load up the last payment made for the TXN. |
|
2557 | + * If the payment retrieved looks good, it will then either: |
|
2558 | + * complete the current step and allow advancement to the next reg step |
|
2559 | + * or present the payment options again |
|
2560 | + * |
|
2561 | + * @access private |
|
2562 | + * @return EE_Payment|FALSE |
|
2563 | + * @throws EE_Error |
|
2564 | + * @throws InvalidArgumentException |
|
2565 | + * @throws ReflectionException |
|
2566 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2567 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2568 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2569 | + */ |
|
2570 | + public function process_gateway_response() |
|
2571 | + { |
|
2572 | + $payment = null; |
|
2573 | + // how have they chosen to pay? |
|
2574 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
2575 | + // get EE_Payment_Method object |
|
2576 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2577 | + $this->checkout->continue_reg = false; |
|
2578 | + return false; |
|
2579 | + } |
|
2580 | + if (! $this->checkout->payment_method->is_off_site()) { |
|
2581 | + return false; |
|
2582 | + } |
|
2583 | + $this->_validate_offsite_return(); |
|
2584 | + // DEBUG LOG |
|
2585 | + // $this->checkout->log( |
|
2586 | + // __CLASS__, |
|
2587 | + // __FUNCTION__, |
|
2588 | + // __LINE__, |
|
2589 | + // array( |
|
2590 | + // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2591 | + // 'payment_method' => $this->checkout->payment_method, |
|
2592 | + // ), |
|
2593 | + // true |
|
2594 | + // ); |
|
2595 | + // verify TXN |
|
2596 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
2597 | + $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
2598 | + if (! $gateway instanceof EE_Offsite_Gateway) { |
|
2599 | + $this->checkout->continue_reg = false; |
|
2600 | + return false; |
|
2601 | + } |
|
2602 | + $payment = $this->_process_off_site_payment($gateway); |
|
2603 | + $payment = $this->_process_cancelled_payments($payment); |
|
2604 | + $payment = $this->_validate_payment($payment); |
|
2605 | + // if payment was not declined by the payment gateway or cancelled by the registrant |
|
2606 | + if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
2607 | + // $this->_setup_redirect_for_next_step(); |
|
2608 | + // store that for later |
|
2609 | + $this->checkout->payment = $payment; |
|
2610 | + // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
2611 | + // because we will complete this step during the IPN processing then |
|
2612 | + if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
2613 | + $this->set_completed(); |
|
2614 | + } |
|
2615 | + return true; |
|
2616 | + } |
|
2617 | + } |
|
2618 | + // DEBUG LOG |
|
2619 | + // $this->checkout->log( |
|
2620 | + // __CLASS__, |
|
2621 | + // __FUNCTION__, |
|
2622 | + // __LINE__, |
|
2623 | + // array('payment' => $payment) |
|
2624 | + // ); |
|
2625 | + $this->checkout->continue_reg = false; |
|
2626 | + return false; |
|
2627 | + } |
|
2628 | + |
|
2629 | + |
|
2630 | + /** |
|
2631 | + * _validate_return |
|
2632 | + * |
|
2633 | + * @access private |
|
2634 | + * @return void |
|
2635 | + * @throws EE_Error |
|
2636 | + * @throws InvalidArgumentException |
|
2637 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2638 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2639 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
2640 | + */ |
|
2641 | + private function _validate_offsite_return() |
|
2642 | + { |
|
2643 | + $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
2644 | + if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
2645 | + // Houston... we might have a problem |
|
2646 | + $invalid_TXN = false; |
|
2647 | + // first gather some info |
|
2648 | + $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2649 | + $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
2650 | + ? $valid_TXN->primary_registration() |
|
2651 | + : null; |
|
2652 | + // let's start by retrieving the cart for this TXN |
|
2653 | + $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
2654 | + if ($cart instanceof EE_Cart) { |
|
2655 | + // verify that the current cart has tickets |
|
2656 | + $tickets = $cart->get_tickets(); |
|
2657 | + if (empty($tickets)) { |
|
2658 | + $invalid_TXN = true; |
|
2659 | + } |
|
2660 | + } else { |
|
2661 | + $invalid_TXN = true; |
|
2662 | + } |
|
2663 | + $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
2664 | + ? $primary_registrant->session_ID() |
|
2665 | + : null; |
|
2666 | + // validate current Session ID and compare against valid TXN session ID |
|
2667 | + if ($invalid_TXN // if this is already true, then skip other checks |
|
2668 | + || EE_Session::instance()->id() === null |
|
2669 | + || ( |
|
2670 | + // WARNING !!! |
|
2671 | + // this could be PayPal sending back duplicate requests (ya they do that) |
|
2672 | + // or it **could** mean someone is simply registering AGAIN after having just done so |
|
2673 | + // so now we need to determine if this current TXN looks valid or not |
|
2674 | + // and whether this reg step has even been started ? |
|
2675 | + EE_Session::instance()->id() === $valid_TXN_SID |
|
2676 | + // really? you're half way through this reg step, but you never started it ? |
|
2677 | + && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
2678 | + ) |
|
2679 | + ) { |
|
2680 | + $invalid_TXN = true; |
|
2681 | + } |
|
2682 | + if ($invalid_TXN) { |
|
2683 | + // is the valid TXN completed ? |
|
2684 | + if ($valid_TXN instanceof EE_Transaction) { |
|
2685 | + // has this step even been started ? |
|
2686 | + $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
2687 | + if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
2688 | + // so it **looks** like this is a double request from PayPal |
|
2689 | + // so let's try to pick up where we left off |
|
2690 | + $this->checkout->transaction = $valid_TXN; |
|
2691 | + $this->checkout->refresh_all_entities(true); |
|
2692 | + return; |
|
2693 | + } |
|
2694 | + } |
|
2695 | + // you appear to be lost? |
|
2696 | + $this->_redirect_wayward_request($primary_registrant); |
|
2697 | + } |
|
2698 | + } |
|
2699 | + } |
|
2700 | + |
|
2701 | + |
|
2702 | + /** |
|
2703 | + * _redirect_wayward_request |
|
2704 | + * |
|
2705 | + * @access private |
|
2706 | + * @param \EE_Registration|null $primary_registrant |
|
2707 | + * @return bool |
|
2708 | + * @throws EE_Error |
|
2709 | + * @throws InvalidArgumentException |
|
2710 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2711 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2712 | + */ |
|
2713 | + private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
2714 | + { |
|
2715 | + if (! $primary_registrant instanceof EE_Registration) { |
|
2716 | + // try redirecting based on the current TXN |
|
2717 | + $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
2718 | + ? $this->checkout->transaction->primary_registration() |
|
2719 | + : null; |
|
2720 | + } |
|
2721 | + if (! $primary_registrant instanceof EE_Registration) { |
|
2722 | + EE_Error::add_error( |
|
2723 | + sprintf( |
|
2724 | + esc_html__( |
|
2725 | + 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
2726 | + 'event_espresso' |
|
2727 | + ), |
|
2728 | + '<br/>', |
|
2729 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2730 | + ), |
|
2731 | + __FILE__, |
|
2732 | + __FUNCTION__, |
|
2733 | + __LINE__ |
|
2734 | + ); |
|
2735 | + return false; |
|
2736 | + } |
|
2737 | + // make sure transaction is not locked |
|
2738 | + $this->checkout->transaction->unlock(); |
|
2739 | + wp_safe_redirect( |
|
2740 | + add_query_arg( |
|
2741 | + array( |
|
2742 | + 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
2743 | + ), |
|
2744 | + $this->checkout->thank_you_page_url |
|
2745 | + ) |
|
2746 | + ); |
|
2747 | + exit(); |
|
2748 | + } |
|
2749 | + |
|
2750 | + |
|
2751 | + /** |
|
2752 | + * _process_off_site_payment |
|
2753 | + * |
|
2754 | + * @access private |
|
2755 | + * @param \EE_Offsite_Gateway $gateway |
|
2756 | + * @return EE_Payment |
|
2757 | + * @throws EE_Error |
|
2758 | + * @throws InvalidArgumentException |
|
2759 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2760 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2761 | + */ |
|
2762 | + private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
2763 | + { |
|
2764 | + try { |
|
2765 | + $request_data = \EE_Registry::instance()->REQ->params(); |
|
2766 | + // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
2767 | + $this->set_handle_IPN_in_this_request( |
|
2768 | + $gateway->handle_IPN_in_this_request($request_data, false) |
|
2769 | + ); |
|
2770 | + if ($this->handle_IPN_in_this_request()) { |
|
2771 | + // get payment details and process results |
|
2772 | + /** @type EE_Payment_Processor $payment_processor */ |
|
2773 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2774 | + $payment = $payment_processor->process_ipn( |
|
2775 | + $request_data, |
|
2776 | + $this->checkout->transaction, |
|
2777 | + $this->checkout->payment_method, |
|
2778 | + true, |
|
2779 | + false |
|
2780 | + ); |
|
2781 | + // $payment_source = 'process_ipn'; |
|
2782 | + } else { |
|
2783 | + $payment = $this->checkout->transaction->last_payment(); |
|
2784 | + // $payment_source = 'last_payment'; |
|
2785 | + } |
|
2786 | + } catch (Exception $e) { |
|
2787 | + // let's just eat the exception and try to move on using any previously set payment info |
|
2788 | + $payment = $this->checkout->transaction->last_payment(); |
|
2789 | + // $payment_source = 'last_payment after Exception'; |
|
2790 | + // but if we STILL don't have a payment object |
|
2791 | + if (! $payment instanceof EE_Payment) { |
|
2792 | + // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
2793 | + $this->_handle_payment_processor_exception($e); |
|
2794 | + } |
|
2795 | + } |
|
2796 | + // DEBUG LOG |
|
2797 | + // $this->checkout->log( |
|
2798 | + // __CLASS__, |
|
2799 | + // __FUNCTION__, |
|
2800 | + // __LINE__, |
|
2801 | + // array( |
|
2802 | + // 'process_ipn_payment' => $payment, |
|
2803 | + // 'payment_source' => $payment_source, |
|
2804 | + // ) |
|
2805 | + // ); |
|
2806 | + return $payment; |
|
2807 | + } |
|
2808 | + |
|
2809 | + |
|
2810 | + /** |
|
2811 | + * _process_cancelled_payments |
|
2812 | + * just makes sure that the payment status gets updated correctly |
|
2813 | + * so tha tan error isn't generated during payment validation |
|
2814 | + * |
|
2815 | + * @access private |
|
2816 | + * @param EE_Payment $payment |
|
2817 | + * @return EE_Payment | FALSE |
|
2818 | + * @throws \EE_Error |
|
2819 | + */ |
|
2820 | + private function _process_cancelled_payments($payment = null) |
|
2821 | + { |
|
2822 | + if ($payment instanceof EE_Payment |
|
2823 | + && isset($_REQUEST['ee_cancel_payment']) |
|
2824 | + && $payment->status() === EEM_Payment::status_id_failed |
|
2825 | + ) { |
|
2826 | + $payment->set_status(EEM_Payment::status_id_cancelled); |
|
2827 | + } |
|
2828 | + return $payment; |
|
2829 | + } |
|
2830 | + |
|
2831 | + |
|
2832 | + /** |
|
2833 | + * get_transaction_details_for_gateways |
|
2834 | + * |
|
2835 | + * @access public |
|
2836 | + * @return int |
|
2837 | + * @throws EE_Error |
|
2838 | + * @throws InvalidArgumentException |
|
2839 | + * @throws ReflectionException |
|
2840 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2841 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2842 | + */ |
|
2843 | + public function get_transaction_details_for_gateways() |
|
2844 | + { |
|
2845 | + $txn_details = array(); |
|
2846 | + // ya gotta make a choice man |
|
2847 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
2848 | + $txn_details = array( |
|
2849 | + 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
2850 | + ); |
|
2851 | + } |
|
2852 | + // get EE_Payment_Method object |
|
2853 | + if (empty($txn_details) |
|
2854 | + && |
|
2855 | + ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
2856 | + ) { |
|
2857 | + $txn_details = array( |
|
2858 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
2859 | + 'error' => esc_html__( |
|
2860 | + 'A valid Payment Method could not be determined.', |
|
2861 | + 'event_espresso' |
|
2862 | + ), |
|
2863 | + ); |
|
2864 | + } |
|
2865 | + if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
2866 | + $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
2867 | + $txn_details = array( |
|
2868 | + 'TXN_ID' => $this->checkout->transaction->ID(), |
|
2869 | + 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
2870 | + 'TXN_total' => $this->checkout->transaction->total(), |
|
2871 | + 'TXN_paid' => $this->checkout->transaction->paid(), |
|
2872 | + 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
2873 | + 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
2874 | + 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
2875 | + 'payment_amount' => $this->checkout->amount_owing, |
|
2876 | + 'return_url' => $return_url, |
|
2877 | + 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
2878 | + 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
2879 | + array( |
|
2880 | + 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
2881 | + 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
2882 | + ) |
|
2883 | + ), |
|
2884 | + ); |
|
2885 | + } |
|
2886 | + echo wp_json_encode($txn_details); |
|
2887 | + exit(); |
|
2888 | + } |
|
2889 | + |
|
2890 | + |
|
2891 | + /** |
|
2892 | + * __sleep |
|
2893 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
2894 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
2895 | + * reg form, because if needed, it will be regenerated anyways |
|
2896 | + * |
|
2897 | + * @return array |
|
2898 | + */ |
|
2899 | + public function __sleep() |
|
2900 | + { |
|
2901 | + // remove the reg form and the checkout |
|
2902 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
2903 | + } |
|
2904 | 2904 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | { |
130 | 130 | $this->_slug = 'payment_options'; |
131 | 131 | $this->_name = esc_html__('Payment Options', 'event_espresso'); |
132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
132 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'payment_options_main.template.php'; |
|
133 | 133 | $this->checkout = $checkout; |
134 | 134 | $this->_reset_success_message(); |
135 | 135 | $this->set_instructions( |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | { |
213 | 213 | $transaction = $this->checkout->transaction; |
214 | 214 | // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
215 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
215 | + if ( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
216 | 216 | return; |
217 | 217 | } |
218 | 218 | foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
@@ -304,18 +304,18 @@ discard block |
||
304 | 304 | foreach ($registrations as $REG_ID => $registration) { |
305 | 305 | /** @var $registration EE_Registration */ |
306 | 306 | // has this registration lost it's space ? |
307 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
307 | + if (isset($ejected_registrations[$REG_ID])) { |
|
308 | 308 | if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
309 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
309 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
310 | 310 | } else { |
311 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
311 | + $insufficient_spaces_available[$registration->event()->ID()] = $registration->event(); |
|
312 | 312 | } |
313 | 313 | continue; |
314 | 314 | } |
315 | 315 | // event requires admin approval |
316 | 316 | if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
317 | 317 | // add event to list of events with pre-approval reg status |
318 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
318 | + $registrations_requiring_pre_approval[$REG_ID] = $registration; |
|
319 | 319 | do_action( |
320 | 320 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
321 | 321 | $registration->event(), |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | ) |
332 | 332 | ) { |
333 | 333 | // add event to list of events that are sold out |
334 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
334 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
335 | 335 | do_action( |
336 | 336 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
337 | 337 | $registration->event(), |
@@ -341,38 +341,38 @@ discard block |
||
341 | 341 | } |
342 | 342 | // are they allowed to pay now and is there monies owing? |
343 | 343 | if ($registration->owes_monies_and_can_pay()) { |
344 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
344 | + $registrations_requiring_payment[$REG_ID] = $registration; |
|
345 | 345 | do_action( |
346 | 346 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
347 | 347 | $registration->event(), |
348 | 348 | $this |
349 | 349 | ); |
350 | - } elseif (! $this->checkout->revisit |
|
350 | + } elseif ( ! $this->checkout->revisit |
|
351 | 351 | && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
352 | 352 | && $registration->ticket()->is_free() |
353 | 353 | ) { |
354 | - $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration; |
|
354 | + $registrations_for_free_events[$registration->ticket()->ID()] = $registration; |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | $subsections = array(); |
358 | 358 | // now decide which template to load |
359 | - if (! empty($sold_out_events)) { |
|
359 | + if ( ! empty($sold_out_events)) { |
|
360 | 360 | $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
361 | 361 | } |
362 | - if (! empty($insufficient_spaces_available)) { |
|
362 | + if ( ! empty($insufficient_spaces_available)) { |
|
363 | 363 | $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
364 | 364 | $insufficient_spaces_available |
365 | 365 | ); |
366 | 366 | } |
367 | - if (! empty($registrations_requiring_pre_approval)) { |
|
367 | + if ( ! empty($registrations_requiring_pre_approval)) { |
|
368 | 368 | $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
369 | 369 | $registrations_requiring_pre_approval |
370 | 370 | ); |
371 | 371 | } |
372 | - if (! empty($registrations_for_free_events)) { |
|
372 | + if ( ! empty($registrations_for_free_events)) { |
|
373 | 373 | $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
374 | 374 | } |
375 | - if (! empty($registrations_requiring_payment)) { |
|
375 | + if ( ! empty($registrations_requiring_payment)) { |
|
376 | 376 | if ($this->checkout->amount_owing > 0) { |
377 | 377 | // autoload Line_Item_Display classes |
378 | 378 | EEH_Autoloader::register_line_item_filter_autoloaders(); |
@@ -437,13 +437,13 @@ discard block |
||
437 | 437 | */ |
438 | 438 | public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
439 | 439 | { |
440 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
440 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
441 | 441 | return $line_item_filter_collection; |
442 | 442 | } |
443 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
443 | + if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
444 | 444 | return $line_item_filter_collection; |
445 | 445 | } |
446 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
446 | + if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
447 | 447 | return $line_item_filter_collection; |
448 | 448 | } |
449 | 449 | $line_item_filter_collection->add( |
@@ -483,8 +483,8 @@ discard block |
||
483 | 483 | ); |
484 | 484 | foreach ($registrations as $REG_ID => $registration) { |
485 | 485 | // has this registration lost it's space ? |
486 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
487 | - unset($registrations[ $REG_ID ]); |
|
486 | + if (isset($ejected_registrations[$REG_ID])) { |
|
487 | + unset($registrations[$REG_ID]); |
|
488 | 488 | continue; |
489 | 489 | } |
490 | 490 | } |
@@ -534,24 +534,24 @@ discard block |
||
534 | 534 | } |
535 | 535 | $EVT_ID = $registration->event_ID(); |
536 | 536 | $ticket = $registration->ticket(); |
537 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
538 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
537 | + if ( ! isset($tickets_remaining[$ticket->ID()])) { |
|
538 | + $tickets_remaining[$ticket->ID()] = $ticket->remaining(); |
|
539 | 539 | } |
540 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
541 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
542 | - $event_reg_count[ $EVT_ID ] = 0; |
|
540 | + if ($tickets_remaining[$ticket->ID()] > 0) { |
|
541 | + if ( ! isset($event_reg_count[$EVT_ID])) { |
|
542 | + $event_reg_count[$EVT_ID] = 0; |
|
543 | 543 | } |
544 | - $event_reg_count[ $EVT_ID ]++; |
|
545 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
546 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
544 | + $event_reg_count[$EVT_ID]++; |
|
545 | + if ( ! isset($event_spaces_remaining[$EVT_ID])) { |
|
546 | + $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale(); |
|
547 | 547 | } |
548 | 548 | } |
549 | 549 | if ($revisit |
550 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
551 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
550 | + && ($tickets_remaining[$ticket->ID()] === 0 |
|
551 | + || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID] |
|
552 | 552 | ) |
553 | 553 | ) { |
554 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
554 | + $ejected_registrations[$REG_ID] = $registration->event(); |
|
555 | 555 | if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
556 | 556 | /** @type EE_Registration_Processor $registration_processor */ |
557 | 557 | $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | foreach ($sold_out_events_array as $sold_out_event) { |
612 | 612 | $sold_out_events .= EEH_HTML::li( |
613 | 613 | EEH_HTML::span( |
614 | - ' ' . $sold_out_event->name(), |
|
614 | + ' '.$sold_out_event->name(), |
|
615 | 615 | '', |
616 | 616 | 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
617 | 617 | ) |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | foreach ($insufficient_spaces_events_array as $event) { |
668 | 668 | if ($event instanceof EE_Event) { |
669 | 669 | $insufficient_space_events .= EEH_HTML::li( |
670 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
670 | + EEH_HTML::span(' '.$event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
671 | 671 | ); |
672 | 672 | } |
673 | 673 | } |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | $events_requiring_pre_approval = array(); |
717 | 717 | foreach ($registrations_requiring_pre_approval as $registration) { |
718 | 718 | if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
719 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
719 | + $events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li( |
|
720 | 720 | EEH_HTML::span( |
721 | 721 | '', |
722 | 722 | '', |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | { |
858 | 858 | return new EE_Form_Section_Proper( |
859 | 859 | array( |
860 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
860 | + 'html_id' => 'ee-'.$this->slug().'-extra-hidden-inputs', |
|
861 | 861 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
862 | 862 | 'subsections' => array( |
863 | 863 | 'spco_no_payment_required' => new EE_Hidden_Input( |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | $payments += $registration->registration_payments(); |
898 | 898 | } |
899 | 899 | } |
900 | - if (! empty($payments)) { |
|
900 | + if ( ! empty($payments)) { |
|
901 | 901 | foreach ($payments as $payment) { |
902 | 902 | if ($payment instanceof EE_Registration_Payment) { |
903 | 903 | $this->checkout->amount_owing -= $payment->amount(); |
@@ -1021,23 +1021,23 @@ discard block |
||
1021 | 1021 | $payment_method_button = EEH_HTML::img( |
1022 | 1022 | $payment_method->button_url(), |
1023 | 1023 | $payment_method->name(), |
1024 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
1024 | + 'spco-payment-method-'.$payment_method->slug().'-btn-img', |
|
1025 | 1025 | 'spco-payment-method-btn-img' |
1026 | 1026 | ); |
1027 | 1027 | // check if any payment methods are set as default |
1028 | 1028 | // if payment method is already selected OR nothing is selected and this payment method should be |
1029 | 1029 | // open_by_default |
1030 | 1030 | if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
1031 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1031 | + || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
1032 | 1032 | ) { |
1033 | 1033 | $this->checkout->selected_method_of_payment = $payment_method->slug(); |
1034 | 1034 | $this->_save_selected_method_of_payment(); |
1035 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
1035 | + $default_payment_method_option[$payment_method->slug()] = $payment_method_button; |
|
1036 | 1036 | } else { |
1037 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
1037 | + $available_payment_method_options[$payment_method->slug()] = $payment_method_button; |
|
1038 | 1038 | } |
1039 | - $payment_methods_billing_info[ $payment_method->slug( |
|
1040 | - ) . '-info' ] = $this->_payment_method_billing_info( |
|
1039 | + $payment_methods_billing_info[$payment_method->slug( |
|
1040 | + ).'-info'] = $this->_payment_method_billing_info( |
|
1041 | 1041 | $payment_method |
1042 | 1042 | ); |
1043 | 1043 | } |
@@ -1073,7 +1073,7 @@ discard block |
||
1073 | 1073 | */ |
1074 | 1074 | protected function _get_available_payment_methods() |
1075 | 1075 | { |
1076 | - if (! empty($this->checkout->available_payment_methods)) { |
|
1076 | + if ( ! empty($this->checkout->available_payment_methods)) { |
|
1077 | 1077 | return $this->checkout->available_payment_methods; |
1078 | 1078 | } |
1079 | 1079 | $available_payment_methods = array(); |
@@ -1088,7 +1088,7 @@ discard block |
||
1088 | 1088 | ); |
1089 | 1089 | foreach ($payment_methods as $payment_method) { |
1090 | 1090 | if ($payment_method instanceof EE_Payment_Method) { |
1091 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1091 | + $available_payment_methods[$payment_method->slug()] = $payment_method; |
|
1092 | 1092 | } |
1093 | 1093 | } |
1094 | 1094 | return $available_payment_methods; |
@@ -1183,7 +1183,7 @@ discard block |
||
1183 | 1183 | ); |
1184 | 1184 | return new EE_Form_Section_Proper( |
1185 | 1185 | array( |
1186 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1186 | + 'html_id' => 'spco-payment-method-info-'.$payment_method->slug(), |
|
1187 | 1187 | 'html_class' => 'spco-payment-method-info-dv', |
1188 | 1188 | // only display the selected or default PM |
1189 | 1189 | 'html_style' => $currently_selected ? '' : 'display:none;', |
@@ -1213,7 +1213,7 @@ discard block |
||
1213 | 1213 | // how have they chosen to pay? |
1214 | 1214 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
1215 | 1215 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
1216 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1216 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1217 | 1217 | return false; |
1218 | 1218 | } |
1219 | 1219 | if (apply_filters( |
@@ -1385,7 +1385,7 @@ discard block |
||
1385 | 1385 | */ |
1386 | 1386 | public function switch_payment_method() |
1387 | 1387 | { |
1388 | - if (! $this->_verify_payment_method_is_set()) { |
|
1388 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
1389 | 1389 | return false; |
1390 | 1390 | } |
1391 | 1391 | if (apply_filters( |
@@ -1520,7 +1520,7 @@ discard block |
||
1520 | 1520 | } |
1521 | 1521 | } |
1522 | 1522 | // verify payment method |
1523 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1523 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1524 | 1524 | // get payment method for selected method of payment |
1525 | 1525 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
1526 | 1526 | } |
@@ -1545,7 +1545,7 @@ discard block |
||
1545 | 1545 | */ |
1546 | 1546 | public function save_payer_details_via_ajax() |
1547 | 1547 | { |
1548 | - if (! $this->_verify_payment_method_is_set()) { |
|
1548 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
1549 | 1549 | return; |
1550 | 1550 | } |
1551 | 1551 | // generate billing form for selected method of payment if it hasn't been done already |
@@ -1555,7 +1555,7 @@ discard block |
||
1555 | 1555 | ); |
1556 | 1556 | } |
1557 | 1557 | // generate primary attendee from payer info if applicable |
1558 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
1558 | + if ( ! $this->checkout->transaction_has_primary_registrant()) { |
|
1559 | 1559 | $attendee = $this->_create_attendee_from_request_data(); |
1560 | 1560 | if ($attendee instanceof EE_Attendee) { |
1561 | 1561 | foreach ($this->checkout->transaction->registrations() as $registration) { |
@@ -1586,7 +1586,7 @@ discard block |
||
1586 | 1586 | { |
1587 | 1587 | // get State ID |
1588 | 1588 | $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
1589 | - if (! empty($STA_ID)) { |
|
1589 | + if ( ! empty($STA_ID)) { |
|
1590 | 1590 | // can we get state object from name ? |
1591 | 1591 | EE_Registry::instance()->load_model('State'); |
1592 | 1592 | $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
@@ -1594,7 +1594,7 @@ discard block |
||
1594 | 1594 | } |
1595 | 1595 | // get Country ISO |
1596 | 1596 | $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
1597 | - if (! empty($CNT_ISO)) { |
|
1597 | + if ( ! empty($CNT_ISO)) { |
|
1598 | 1598 | // can we get country object from name ? |
1599 | 1599 | EE_Registry::instance()->load_model('Country'); |
1600 | 1600 | $country = EEM_Country::instance()->get_col( |
@@ -1627,7 +1627,7 @@ discard block |
||
1627 | 1627 | } |
1628 | 1628 | // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
1629 | 1629 | // AND email address |
1630 | - if (! empty($attendee_data['ATT_fname']) |
|
1630 | + if ( ! empty($attendee_data['ATT_fname']) |
|
1631 | 1631 | && ! empty($attendee_data['ATT_lname']) |
1632 | 1632 | && ! empty($attendee_data['ATT_email']) |
1633 | 1633 | ) { |
@@ -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 false; |
1847 | 1847 | } |
1848 | 1848 | // ya gotta make a choice man |
@@ -1853,7 +1853,7 @@ discard block |
||
1853 | 1853 | return false; |
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 false; |
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 false; |
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 false; |
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(); |
@@ -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) { |
@@ -2107,7 +2107,7 @@ discard block |
||
2107 | 2107 | { |
2108 | 2108 | // convert billing form data into an attendee |
2109 | 2109 | $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
2110 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2110 | + if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
2111 | 2111 | EE_Error::add_error( |
2112 | 2112 | sprintf( |
2113 | 2113 | esc_html__( |
@@ -2124,7 +2124,7 @@ discard block |
||
2124 | 2124 | return false; |
2125 | 2125 | } |
2126 | 2126 | $primary_registration = $this->checkout->transaction->primary_registration(); |
2127 | - if (! $primary_registration instanceof EE_Registration) { |
|
2127 | + if ( ! $primary_registration instanceof EE_Registration) { |
|
2128 | 2128 | EE_Error::add_error( |
2129 | 2129 | sprintf( |
2130 | 2130 | esc_html__( |
@@ -2140,7 +2140,7 @@ discard block |
||
2140 | 2140 | ); |
2141 | 2141 | return false; |
2142 | 2142 | } |
2143 | - if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
2143 | + if ( ! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
2144 | 2144 | instanceof |
2145 | 2145 | EE_Attendee |
2146 | 2146 | ) { |
@@ -2186,8 +2186,8 @@ discard block |
||
2186 | 2186 | return null; |
2187 | 2187 | } |
2188 | 2188 | // get EE_Payment_Method object |
2189 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
2190 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2189 | + if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) { |
|
2190 | + $payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment]; |
|
2191 | 2191 | } else { |
2192 | 2192 | // load EEM_Payment_Method |
2193 | 2193 | EE_Registry::instance()->load_model('Payment_Method'); |
@@ -2196,7 +2196,7 @@ discard block |
||
2196 | 2196 | $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
2197 | 2197 | } |
2198 | 2198 | // verify $payment_method |
2199 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
2199 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
2200 | 2200 | // not a payment |
2201 | 2201 | EE_Error::add_error( |
2202 | 2202 | sprintf( |
@@ -2214,7 +2214,7 @@ discard block |
||
2214 | 2214 | return null; |
2215 | 2215 | } |
2216 | 2216 | // and verify it has a valid Payment_Method Type object |
2217 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2217 | + if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2218 | 2218 | // not a payment |
2219 | 2219 | EE_Error::add_error( |
2220 | 2220 | sprintf( |
@@ -2252,7 +2252,7 @@ discard block |
||
2252 | 2252 | $payment = null; |
2253 | 2253 | $this->checkout->transaction->save(); |
2254 | 2254 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
2255 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
2255 | + if ( ! $payment_processor instanceof EE_Payment_Processor) { |
|
2256 | 2256 | return false; |
2257 | 2257 | } |
2258 | 2258 | try { |
@@ -2356,7 +2356,7 @@ discard block |
||
2356 | 2356 | return true; |
2357 | 2357 | } |
2358 | 2358 | // verify payment object |
2359 | - if (! $payment instanceof EE_Payment) { |
|
2359 | + if ( ! $payment instanceof EE_Payment) { |
|
2360 | 2360 | // not a payment |
2361 | 2361 | EE_Error::add_error( |
2362 | 2362 | sprintf( |
@@ -2396,7 +2396,7 @@ discard block |
||
2396 | 2396 | return true; |
2397 | 2397 | // On-Site payment? |
2398 | 2398 | } elseif ($this->checkout->payment_method->is_on_site()) { |
2399 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2399 | + if ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2400 | 2400 | // $this->_setup_redirect_for_next_step(); |
2401 | 2401 | $this->checkout->continue_reg = false; |
2402 | 2402 | } |
@@ -2512,7 +2512,7 @@ discard block |
||
2512 | 2512 | break; |
2513 | 2513 | // bad payment |
2514 | 2514 | case EEM_Payment::status_id_failed: |
2515 | - if (! empty($msg)) { |
|
2515 | + if ( ! empty($msg)) { |
|
2516 | 2516 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
2517 | 2517 | return false; |
2518 | 2518 | } |
@@ -2573,11 +2573,11 @@ discard block |
||
2573 | 2573 | // how have they chosen to pay? |
2574 | 2574 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
2575 | 2575 | // get EE_Payment_Method object |
2576 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2576 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2577 | 2577 | $this->checkout->continue_reg = false; |
2578 | 2578 | return false; |
2579 | 2579 | } |
2580 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
2580 | + if ( ! $this->checkout->payment_method->is_off_site()) { |
|
2581 | 2581 | return false; |
2582 | 2582 | } |
2583 | 2583 | $this->_validate_offsite_return(); |
@@ -2595,7 +2595,7 @@ discard block |
||
2595 | 2595 | // verify TXN |
2596 | 2596 | if ($this->checkout->transaction instanceof EE_Transaction) { |
2597 | 2597 | $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
2598 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
2598 | + if ( ! $gateway instanceof EE_Offsite_Gateway) { |
|
2599 | 2599 | $this->checkout->continue_reg = false; |
2600 | 2600 | return false; |
2601 | 2601 | } |
@@ -2712,13 +2712,13 @@ discard block |
||
2712 | 2712 | */ |
2713 | 2713 | private function _redirect_wayward_request(EE_Registration $primary_registrant) |
2714 | 2714 | { |
2715 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2715 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
2716 | 2716 | // try redirecting based on the current TXN |
2717 | 2717 | $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
2718 | 2718 | ? $this->checkout->transaction->primary_registration() |
2719 | 2719 | : null; |
2720 | 2720 | } |
2721 | - if (! $primary_registrant instanceof EE_Registration) { |
|
2721 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
2722 | 2722 | EE_Error::add_error( |
2723 | 2723 | sprintf( |
2724 | 2724 | esc_html__( |
@@ -2788,7 +2788,7 @@ discard block |
||
2788 | 2788 | $payment = $this->checkout->transaction->last_payment(); |
2789 | 2789 | // $payment_source = 'last_payment after Exception'; |
2790 | 2790 | // but if we STILL don't have a payment object |
2791 | - if (! $payment instanceof EE_Payment) { |
|
2791 | + if ( ! $payment instanceof EE_Payment) { |
|
2792 | 2792 | // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
2793 | 2793 | $this->_handle_payment_processor_exception($e); |
2794 | 2794 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.83.rc.022'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.83.rc.022'); |
|
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 | } |