@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use EventEspresso\core\exceptions\InvalidFormSubmissionException; |
16 | 16 | |
17 | 17 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
18 | - exit('No direct script access allowed'); |
|
18 | + exit('No direct script access allowed'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | |
@@ -34,644 +34,644 @@ discard block |
||
34 | 34 | abstract class FormHandler implements FormHandlerInterface |
35 | 35 | { |
36 | 36 | |
37 | - /** |
|
38 | - * will add opening and closing HTML form tags as well as a submit button |
|
39 | - */ |
|
40 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
41 | - |
|
42 | - /** |
|
43 | - * will add opening and closing HTML form tags but NOT a submit button |
|
44 | - */ |
|
45 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
46 | - |
|
47 | - /** |
|
48 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
49 | - */ |
|
50 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
51 | - |
|
52 | - /** |
|
53 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
54 | - */ |
|
55 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
56 | - |
|
57 | - /** |
|
58 | - * if set to false, then this form has no displayable content, |
|
59 | - * and will only be used for processing data sent passed via GET or POST |
|
60 | - * defaults to true ( ie: form has displayable content ) |
|
61 | - * |
|
62 | - * @var boolean $displayable |
|
63 | - */ |
|
64 | - private $displayable = true; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var string $form_name |
|
68 | - */ |
|
69 | - private $form_name; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var string $admin_name |
|
73 | - */ |
|
74 | - private $admin_name; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var string $slug |
|
78 | - */ |
|
79 | - private $slug; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var string $submit_btn_text |
|
83 | - */ |
|
84 | - private $submit_btn_text; |
|
85 | - |
|
86 | - /** |
|
87 | - * @var string $form_action |
|
88 | - */ |
|
89 | - private $form_action; |
|
90 | - |
|
91 | - /** |
|
92 | - * form params in key value pairs |
|
93 | - * can be added to form action URL or as hidden inputs |
|
94 | - * |
|
95 | - * @var array $form_args |
|
96 | - */ |
|
97 | - private $form_args = array(); |
|
98 | - |
|
99 | - /** |
|
100 | - * value of one of the string constant above |
|
101 | - * |
|
102 | - * @var string $form_config |
|
103 | - */ |
|
104 | - private $form_config; |
|
105 | - |
|
106 | - /** |
|
107 | - * whether or not the form was determined to be invalid |
|
108 | - * |
|
109 | - * @var boolean $form_has_errors |
|
110 | - */ |
|
111 | - private $form_has_errors; |
|
112 | - |
|
113 | - /** |
|
114 | - * the absolute top level form section being used on the page |
|
115 | - * |
|
116 | - * @var EE_Form_Section_Proper $form |
|
117 | - */ |
|
118 | - private $form; |
|
119 | - |
|
120 | - /** |
|
121 | - * @var EE_Registry $registry |
|
122 | - */ |
|
123 | - protected $registry; |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Form constructor. |
|
129 | - * |
|
130 | - * @param string $form_name |
|
131 | - * @param string $admin_name |
|
132 | - * @param string $slug |
|
133 | - * @param string $form_action |
|
134 | - * @param string $form_config |
|
135 | - * @param EE_Registry $registry |
|
136 | - * @throws InvalidDataTypeException |
|
137 | - * @throws DomainException |
|
138 | - * @throws InvalidArgumentException |
|
139 | - */ |
|
140 | - public function __construct( |
|
141 | - $form_name, |
|
142 | - $admin_name, |
|
143 | - $slug, |
|
144 | - $form_action = '', |
|
145 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
146 | - EE_Registry $registry |
|
147 | - ) { |
|
148 | - $this->setFormName($form_name); |
|
149 | - $this->setAdminName($admin_name); |
|
150 | - $this->setSlug($slug); |
|
151 | - $this->setFormAction($form_action); |
|
152 | - $this->setFormConfig($form_config); |
|
153 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
154 | - $this->registry = $registry; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - public static function getFormConfigConstants() |
|
163 | - { |
|
164 | - return array( |
|
165 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
166 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
167 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
168 | - FormHandler::DO_NOT_SETUP_FORM, |
|
169 | - ); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @param bool $for_display |
|
176 | - * @return EE_Form_Section_Proper |
|
177 | - * @throws EE_Error |
|
178 | - * @throws LogicException |
|
179 | - */ |
|
180 | - public function form($for_display = false) |
|
181 | - { |
|
182 | - if (! $this->formIsValid()) { |
|
183 | - return null; |
|
184 | - } |
|
185 | - if ($for_display) { |
|
186 | - $form_config = $this->formConfig(); |
|
187 | - if ( |
|
188 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
189 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
190 | - ) { |
|
191 | - $this->appendSubmitButton(); |
|
192 | - $this->clearFormButtonFloats(); |
|
193 | - } |
|
194 | - } |
|
195 | - return $this->form; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @return boolean |
|
202 | - * @throws LogicException |
|
203 | - */ |
|
204 | - public function formIsValid() |
|
205 | - { |
|
206 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
207 | - return true; |
|
208 | - } |
|
209 | - $form = apply_filters( |
|
210 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
211 | - $this->generate(), |
|
212 | - $this |
|
213 | - ); |
|
214 | - if ($this->verifyForm($form)) { |
|
215 | - $this->setForm($form); |
|
216 | - } |
|
217 | - return true; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * @param EE_Form_Section_Proper|null $form |
|
224 | - * @return bool |
|
225 | - * @throws LogicException |
|
226 | - */ |
|
227 | - public function verifyForm(EE_Form_Section_Proper $form = null) |
|
228 | - { |
|
229 | - $form = $form !== null ? $form : $this->form; |
|
230 | - if ($form instanceof EE_Form_Section_Proper) { |
|
231 | - return true; |
|
232 | - } |
|
233 | - throw new LogicException( |
|
234 | - sprintf( |
|
235 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
236 | - $this->form_name, |
|
237 | - var_export($form, true) |
|
238 | - ) |
|
239 | - ); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * @param EE_Form_Section_Proper $form |
|
246 | - */ |
|
247 | - public function setForm(EE_Form_Section_Proper $form) |
|
248 | - { |
|
249 | - $this->form = $form; |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @return boolean |
|
256 | - */ |
|
257 | - public function displayable() |
|
258 | - { |
|
259 | - return $this->displayable; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @param boolean $displayable |
|
266 | - */ |
|
267 | - public function setDisplayable($displayable = false) |
|
268 | - { |
|
269 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * a public name for the form that can be displayed on the frontend of a site |
|
276 | - * |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - public function formName() |
|
280 | - { |
|
281 | - return $this->form_name; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @param string $form_name |
|
288 | - * @throws InvalidDataTypeException |
|
289 | - */ |
|
290 | - public function setFormName($form_name) |
|
291 | - { |
|
292 | - if (! is_string($form_name)) { |
|
293 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
294 | - } |
|
295 | - $this->form_name = $form_name; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * a public name for the form that can be displayed, but only in the admin |
|
302 | - * |
|
303 | - * @return string |
|
304 | - */ |
|
305 | - public function adminName() |
|
306 | - { |
|
307 | - return $this->admin_name; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * @param string $admin_name |
|
314 | - * @throws InvalidDataTypeException |
|
315 | - */ |
|
316 | - public function setAdminName($admin_name) |
|
317 | - { |
|
318 | - if (! is_string($admin_name)) { |
|
319 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
320 | - } |
|
321 | - $this->admin_name = $admin_name; |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * a URL friendly string that can be used for identifying the form |
|
328 | - * |
|
329 | - * @return string |
|
330 | - */ |
|
331 | - public function slug() |
|
332 | - { |
|
333 | - return $this->slug; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @param string $slug |
|
340 | - * @throws InvalidDataTypeException |
|
341 | - */ |
|
342 | - public function setSlug($slug) |
|
343 | - { |
|
344 | - if (! is_string($slug)) { |
|
345 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
346 | - } |
|
347 | - $this->slug = $slug; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * @return string |
|
354 | - */ |
|
355 | - public function submitBtnText() |
|
356 | - { |
|
357 | - return $this->submit_btn_text; |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * @param string $submit_btn_text |
|
364 | - * @throws InvalidDataTypeException |
|
365 | - * @throws InvalidArgumentException |
|
366 | - */ |
|
367 | - public function setSubmitBtnText($submit_btn_text) |
|
368 | - { |
|
369 | - if (! is_string($submit_btn_text)) { |
|
370 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
371 | - } |
|
372 | - if (empty($submit_btn_text)) { |
|
373 | - throw new InvalidArgumentException( |
|
374 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
375 | - ); |
|
376 | - } |
|
377 | - $this->submit_btn_text = $submit_btn_text; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * @return string |
|
384 | - */ |
|
385 | - public function formAction() |
|
386 | - { |
|
387 | - return ! empty($this->form_args) |
|
388 | - ? add_query_arg($this->form_args, $this->form_action) |
|
389 | - : $this->form_action; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * @param string $form_action |
|
396 | - * @throws InvalidDataTypeException |
|
397 | - */ |
|
398 | - public function setFormAction($form_action) |
|
399 | - { |
|
400 | - if (! is_string($form_action)) { |
|
401 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
402 | - } |
|
403 | - $this->form_action = $form_action; |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * @param array $form_args |
|
410 | - * @throws InvalidDataTypeException |
|
411 | - * @throws InvalidArgumentException |
|
412 | - */ |
|
413 | - public function addFormActionArgs($form_args = array()) |
|
414 | - { |
|
415 | - if (is_object($form_args)) { |
|
416 | - throw new InvalidDataTypeException( |
|
417 | - '$form_args', |
|
418 | - $form_args, |
|
419 | - 'anything other than an object was expected.' |
|
420 | - ); |
|
421 | - } |
|
422 | - if (empty($form_args)) { |
|
423 | - throw new InvalidArgumentException( |
|
424 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
425 | - ); |
|
426 | - } |
|
427 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - public function formConfig() |
|
436 | - { |
|
437 | - return $this->form_config; |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * @param string $form_config |
|
444 | - * @throws DomainException |
|
445 | - */ |
|
446 | - public function setFormConfig($form_config) |
|
447 | - { |
|
448 | - if ( |
|
449 | - ! in_array( |
|
450 | - $form_config, |
|
451 | - array( |
|
452 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
453 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
454 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
455 | - FormHandler::DO_NOT_SETUP_FORM, |
|
456 | - ), |
|
457 | - true |
|
458 | - ) |
|
459 | - ) { |
|
460 | - throw new DomainException( |
|
461 | - sprintf( |
|
462 | - esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
463 | - 'event_espresso'), |
|
464 | - $form_config |
|
465 | - ) |
|
466 | - ); |
|
467 | - } |
|
468 | - $this->form_config = $form_config; |
|
469 | - } |
|
470 | - |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * called after the form is instantiated |
|
475 | - * and used for performing any logic that needs to occur early |
|
476 | - * before any of the other methods are called. |
|
477 | - * returns true if everything is ok to proceed, |
|
478 | - * and false if no further form logic should be implemented |
|
479 | - * |
|
480 | - * @return boolean |
|
481 | - */ |
|
482 | - public function initialize() |
|
483 | - { |
|
484 | - $this->form_has_errors = EE_Error::has_error(true); |
|
485 | - return true; |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * used for setting up css and js |
|
492 | - * |
|
493 | - * @return void |
|
494 | - * @throws LogicException |
|
495 | - * @throws EE_Error |
|
496 | - */ |
|
497 | - public function enqueueStylesAndScripts() |
|
498 | - { |
|
499 | - $this->form()->enqueue_js(); |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * creates and returns the actual form |
|
506 | - * |
|
507 | - * @return EE_Form_Section_Proper |
|
508 | - */ |
|
509 | - abstract public function generate(); |
|
510 | - |
|
511 | - |
|
512 | - |
|
513 | - /** |
|
514 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
515 | - * |
|
516 | - * @param string $text |
|
517 | - * @return EE_Submit_Input |
|
518 | - */ |
|
519 | - public function generateSubmitButton($text = '') |
|
520 | - { |
|
521 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
522 | - return new EE_Submit_Input( |
|
523 | - array( |
|
524 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
525 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
526 | - 'html_class' => 'ee-form-submit', |
|
527 | - 'html_label' => ' ', |
|
528 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
529 | - 'default' => $text, |
|
530 | - ) |
|
531 | - ); |
|
532 | - } |
|
533 | - |
|
534 | - |
|
535 | - |
|
536 | - /** |
|
537 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
538 | - * |
|
539 | - * @param string $text |
|
540 | - * @return void |
|
541 | - * @throws EE_Error |
|
542 | - */ |
|
543 | - public function appendSubmitButton($text = '') |
|
544 | - { |
|
545 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
546 | - return; |
|
547 | - } |
|
548 | - $this->form->add_subsections( |
|
549 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
550 | - null, |
|
551 | - false |
|
552 | - ); |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
559 | - * |
|
560 | - * @param string $text |
|
561 | - * @return EE_Submit_Input |
|
562 | - */ |
|
563 | - public function generateCancelButton($text = '') |
|
564 | - { |
|
565 | - $cancel_button = new EE_Submit_Input( |
|
566 | - array( |
|
567 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
568 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
569 | - 'html_class' => 'ee-cancel-form', |
|
570 | - 'html_label' => ' ', |
|
571 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
572 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
573 | - ) |
|
574 | - ); |
|
575 | - $cancel_button->set_button_css_attributes(false); |
|
576 | - return $cancel_button; |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * appends a float clearing div onto end of form |
|
583 | - * |
|
584 | - * @return void |
|
585 | - * @throws EE_Error |
|
586 | - */ |
|
587 | - public function clearFormButtonFloats() |
|
588 | - { |
|
589 | - $this->form->add_subsections( |
|
590 | - array( |
|
591 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
592 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
593 | - ), |
|
594 | - ), |
|
595 | - null, |
|
596 | - false |
|
597 | - ); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
604 | - * returns a string of HTML that can be directly echoed in a template |
|
605 | - * |
|
606 | - * @return string |
|
607 | - * @throws LogicException |
|
608 | - * @throws EE_Error |
|
609 | - */ |
|
610 | - public function display() |
|
611 | - { |
|
612 | - $form_html = apply_filters( |
|
613 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
614 | - '' |
|
615 | - ); |
|
616 | - $form_config = $this->formConfig(); |
|
617 | - if ( |
|
618 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
619 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
620 | - ) { |
|
621 | - $form_html .= $this->form()->form_open($this->formAction()); |
|
622 | - } |
|
623 | - $form_html .= $this->form(true)->get_html($this->form_has_errors); |
|
624 | - if ( |
|
625 | - $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
626 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
627 | - ) { |
|
628 | - $form_html .= $this->form()->form_close(); |
|
629 | - } |
|
630 | - $form_html .= apply_filters( |
|
631 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
632 | - '' |
|
633 | - ); |
|
634 | - return $form_html; |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * handles processing the form submission |
|
641 | - * returns true or false depending on whether the form was processed successfully or not |
|
642 | - * |
|
643 | - * @param array $submitted_form_data |
|
644 | - * @return array |
|
645 | - * @throws EE_Error |
|
646 | - * @throws LogicException |
|
647 | - * @throws InvalidFormSubmissionException |
|
648 | - */ |
|
649 | - public function process($submitted_form_data = array()) |
|
650 | - { |
|
651 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
652 | - throw new InvalidFormSubmissionException($this->form_name); |
|
653 | - } |
|
654 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
655 | - if (! $this->form()->is_valid()) { |
|
656 | - throw new InvalidFormSubmissionException( |
|
657 | - $this->form_name, |
|
658 | - sprintf( |
|
659 | - esc_html__( |
|
660 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
661 | - 'event_espresso' |
|
662 | - ), |
|
663 | - $this->form_name, |
|
664 | - '<br />', |
|
665 | - $this->form()->submission_error_message() |
|
666 | - ) |
|
667 | - ); |
|
668 | - } |
|
669 | - return apply_filters( |
|
670 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
671 | - $this->form()->valid_data(), |
|
672 | - $this |
|
673 | - ); |
|
674 | - } |
|
37 | + /** |
|
38 | + * will add opening and closing HTML form tags as well as a submit button |
|
39 | + */ |
|
40 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
41 | + |
|
42 | + /** |
|
43 | + * will add opening and closing HTML form tags but NOT a submit button |
|
44 | + */ |
|
45 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
46 | + |
|
47 | + /** |
|
48 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
49 | + */ |
|
50 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
51 | + |
|
52 | + /** |
|
53 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
54 | + */ |
|
55 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
56 | + |
|
57 | + /** |
|
58 | + * if set to false, then this form has no displayable content, |
|
59 | + * and will only be used for processing data sent passed via GET or POST |
|
60 | + * defaults to true ( ie: form has displayable content ) |
|
61 | + * |
|
62 | + * @var boolean $displayable |
|
63 | + */ |
|
64 | + private $displayable = true; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var string $form_name |
|
68 | + */ |
|
69 | + private $form_name; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var string $admin_name |
|
73 | + */ |
|
74 | + private $admin_name; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var string $slug |
|
78 | + */ |
|
79 | + private $slug; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var string $submit_btn_text |
|
83 | + */ |
|
84 | + private $submit_btn_text; |
|
85 | + |
|
86 | + /** |
|
87 | + * @var string $form_action |
|
88 | + */ |
|
89 | + private $form_action; |
|
90 | + |
|
91 | + /** |
|
92 | + * form params in key value pairs |
|
93 | + * can be added to form action URL or as hidden inputs |
|
94 | + * |
|
95 | + * @var array $form_args |
|
96 | + */ |
|
97 | + private $form_args = array(); |
|
98 | + |
|
99 | + /** |
|
100 | + * value of one of the string constant above |
|
101 | + * |
|
102 | + * @var string $form_config |
|
103 | + */ |
|
104 | + private $form_config; |
|
105 | + |
|
106 | + /** |
|
107 | + * whether or not the form was determined to be invalid |
|
108 | + * |
|
109 | + * @var boolean $form_has_errors |
|
110 | + */ |
|
111 | + private $form_has_errors; |
|
112 | + |
|
113 | + /** |
|
114 | + * the absolute top level form section being used on the page |
|
115 | + * |
|
116 | + * @var EE_Form_Section_Proper $form |
|
117 | + */ |
|
118 | + private $form; |
|
119 | + |
|
120 | + /** |
|
121 | + * @var EE_Registry $registry |
|
122 | + */ |
|
123 | + protected $registry; |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Form constructor. |
|
129 | + * |
|
130 | + * @param string $form_name |
|
131 | + * @param string $admin_name |
|
132 | + * @param string $slug |
|
133 | + * @param string $form_action |
|
134 | + * @param string $form_config |
|
135 | + * @param EE_Registry $registry |
|
136 | + * @throws InvalidDataTypeException |
|
137 | + * @throws DomainException |
|
138 | + * @throws InvalidArgumentException |
|
139 | + */ |
|
140 | + public function __construct( |
|
141 | + $form_name, |
|
142 | + $admin_name, |
|
143 | + $slug, |
|
144 | + $form_action = '', |
|
145 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
146 | + EE_Registry $registry |
|
147 | + ) { |
|
148 | + $this->setFormName($form_name); |
|
149 | + $this->setAdminName($admin_name); |
|
150 | + $this->setSlug($slug); |
|
151 | + $this->setFormAction($form_action); |
|
152 | + $this->setFormConfig($form_config); |
|
153 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
154 | + $this->registry = $registry; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + public static function getFormConfigConstants() |
|
163 | + { |
|
164 | + return array( |
|
165 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
166 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
167 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
168 | + FormHandler::DO_NOT_SETUP_FORM, |
|
169 | + ); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @param bool $for_display |
|
176 | + * @return EE_Form_Section_Proper |
|
177 | + * @throws EE_Error |
|
178 | + * @throws LogicException |
|
179 | + */ |
|
180 | + public function form($for_display = false) |
|
181 | + { |
|
182 | + if (! $this->formIsValid()) { |
|
183 | + return null; |
|
184 | + } |
|
185 | + if ($for_display) { |
|
186 | + $form_config = $this->formConfig(); |
|
187 | + if ( |
|
188 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
189 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
190 | + ) { |
|
191 | + $this->appendSubmitButton(); |
|
192 | + $this->clearFormButtonFloats(); |
|
193 | + } |
|
194 | + } |
|
195 | + return $this->form; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @return boolean |
|
202 | + * @throws LogicException |
|
203 | + */ |
|
204 | + public function formIsValid() |
|
205 | + { |
|
206 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
207 | + return true; |
|
208 | + } |
|
209 | + $form = apply_filters( |
|
210 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
211 | + $this->generate(), |
|
212 | + $this |
|
213 | + ); |
|
214 | + if ($this->verifyForm($form)) { |
|
215 | + $this->setForm($form); |
|
216 | + } |
|
217 | + return true; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * @param EE_Form_Section_Proper|null $form |
|
224 | + * @return bool |
|
225 | + * @throws LogicException |
|
226 | + */ |
|
227 | + public function verifyForm(EE_Form_Section_Proper $form = null) |
|
228 | + { |
|
229 | + $form = $form !== null ? $form : $this->form; |
|
230 | + if ($form instanceof EE_Form_Section_Proper) { |
|
231 | + return true; |
|
232 | + } |
|
233 | + throw new LogicException( |
|
234 | + sprintf( |
|
235 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
236 | + $this->form_name, |
|
237 | + var_export($form, true) |
|
238 | + ) |
|
239 | + ); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * @param EE_Form_Section_Proper $form |
|
246 | + */ |
|
247 | + public function setForm(EE_Form_Section_Proper $form) |
|
248 | + { |
|
249 | + $this->form = $form; |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @return boolean |
|
256 | + */ |
|
257 | + public function displayable() |
|
258 | + { |
|
259 | + return $this->displayable; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @param boolean $displayable |
|
266 | + */ |
|
267 | + public function setDisplayable($displayable = false) |
|
268 | + { |
|
269 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * a public name for the form that can be displayed on the frontend of a site |
|
276 | + * |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + public function formName() |
|
280 | + { |
|
281 | + return $this->form_name; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @param string $form_name |
|
288 | + * @throws InvalidDataTypeException |
|
289 | + */ |
|
290 | + public function setFormName($form_name) |
|
291 | + { |
|
292 | + if (! is_string($form_name)) { |
|
293 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
294 | + } |
|
295 | + $this->form_name = $form_name; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * a public name for the form that can be displayed, but only in the admin |
|
302 | + * |
|
303 | + * @return string |
|
304 | + */ |
|
305 | + public function adminName() |
|
306 | + { |
|
307 | + return $this->admin_name; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * @param string $admin_name |
|
314 | + * @throws InvalidDataTypeException |
|
315 | + */ |
|
316 | + public function setAdminName($admin_name) |
|
317 | + { |
|
318 | + if (! is_string($admin_name)) { |
|
319 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
320 | + } |
|
321 | + $this->admin_name = $admin_name; |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * a URL friendly string that can be used for identifying the form |
|
328 | + * |
|
329 | + * @return string |
|
330 | + */ |
|
331 | + public function slug() |
|
332 | + { |
|
333 | + return $this->slug; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @param string $slug |
|
340 | + * @throws InvalidDataTypeException |
|
341 | + */ |
|
342 | + public function setSlug($slug) |
|
343 | + { |
|
344 | + if (! is_string($slug)) { |
|
345 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
346 | + } |
|
347 | + $this->slug = $slug; |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * @return string |
|
354 | + */ |
|
355 | + public function submitBtnText() |
|
356 | + { |
|
357 | + return $this->submit_btn_text; |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * @param string $submit_btn_text |
|
364 | + * @throws InvalidDataTypeException |
|
365 | + * @throws InvalidArgumentException |
|
366 | + */ |
|
367 | + public function setSubmitBtnText($submit_btn_text) |
|
368 | + { |
|
369 | + if (! is_string($submit_btn_text)) { |
|
370 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
371 | + } |
|
372 | + if (empty($submit_btn_text)) { |
|
373 | + throw new InvalidArgumentException( |
|
374 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
375 | + ); |
|
376 | + } |
|
377 | + $this->submit_btn_text = $submit_btn_text; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * @return string |
|
384 | + */ |
|
385 | + public function formAction() |
|
386 | + { |
|
387 | + return ! empty($this->form_args) |
|
388 | + ? add_query_arg($this->form_args, $this->form_action) |
|
389 | + : $this->form_action; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * @param string $form_action |
|
396 | + * @throws InvalidDataTypeException |
|
397 | + */ |
|
398 | + public function setFormAction($form_action) |
|
399 | + { |
|
400 | + if (! is_string($form_action)) { |
|
401 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
402 | + } |
|
403 | + $this->form_action = $form_action; |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * @param array $form_args |
|
410 | + * @throws InvalidDataTypeException |
|
411 | + * @throws InvalidArgumentException |
|
412 | + */ |
|
413 | + public function addFormActionArgs($form_args = array()) |
|
414 | + { |
|
415 | + if (is_object($form_args)) { |
|
416 | + throw new InvalidDataTypeException( |
|
417 | + '$form_args', |
|
418 | + $form_args, |
|
419 | + 'anything other than an object was expected.' |
|
420 | + ); |
|
421 | + } |
|
422 | + if (empty($form_args)) { |
|
423 | + throw new InvalidArgumentException( |
|
424 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
425 | + ); |
|
426 | + } |
|
427 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + public function formConfig() |
|
436 | + { |
|
437 | + return $this->form_config; |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * @param string $form_config |
|
444 | + * @throws DomainException |
|
445 | + */ |
|
446 | + public function setFormConfig($form_config) |
|
447 | + { |
|
448 | + if ( |
|
449 | + ! in_array( |
|
450 | + $form_config, |
|
451 | + array( |
|
452 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
453 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
454 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
455 | + FormHandler::DO_NOT_SETUP_FORM, |
|
456 | + ), |
|
457 | + true |
|
458 | + ) |
|
459 | + ) { |
|
460 | + throw new DomainException( |
|
461 | + sprintf( |
|
462 | + esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
463 | + 'event_espresso'), |
|
464 | + $form_config |
|
465 | + ) |
|
466 | + ); |
|
467 | + } |
|
468 | + $this->form_config = $form_config; |
|
469 | + } |
|
470 | + |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * called after the form is instantiated |
|
475 | + * and used for performing any logic that needs to occur early |
|
476 | + * before any of the other methods are called. |
|
477 | + * returns true if everything is ok to proceed, |
|
478 | + * and false if no further form logic should be implemented |
|
479 | + * |
|
480 | + * @return boolean |
|
481 | + */ |
|
482 | + public function initialize() |
|
483 | + { |
|
484 | + $this->form_has_errors = EE_Error::has_error(true); |
|
485 | + return true; |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * used for setting up css and js |
|
492 | + * |
|
493 | + * @return void |
|
494 | + * @throws LogicException |
|
495 | + * @throws EE_Error |
|
496 | + */ |
|
497 | + public function enqueueStylesAndScripts() |
|
498 | + { |
|
499 | + $this->form()->enqueue_js(); |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * creates and returns the actual form |
|
506 | + * |
|
507 | + * @return EE_Form_Section_Proper |
|
508 | + */ |
|
509 | + abstract public function generate(); |
|
510 | + |
|
511 | + |
|
512 | + |
|
513 | + /** |
|
514 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
515 | + * |
|
516 | + * @param string $text |
|
517 | + * @return EE_Submit_Input |
|
518 | + */ |
|
519 | + public function generateSubmitButton($text = '') |
|
520 | + { |
|
521 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
522 | + return new EE_Submit_Input( |
|
523 | + array( |
|
524 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
525 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
526 | + 'html_class' => 'ee-form-submit', |
|
527 | + 'html_label' => ' ', |
|
528 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
529 | + 'default' => $text, |
|
530 | + ) |
|
531 | + ); |
|
532 | + } |
|
533 | + |
|
534 | + |
|
535 | + |
|
536 | + /** |
|
537 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
538 | + * |
|
539 | + * @param string $text |
|
540 | + * @return void |
|
541 | + * @throws EE_Error |
|
542 | + */ |
|
543 | + public function appendSubmitButton($text = '') |
|
544 | + { |
|
545 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
546 | + return; |
|
547 | + } |
|
548 | + $this->form->add_subsections( |
|
549 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
550 | + null, |
|
551 | + false |
|
552 | + ); |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
559 | + * |
|
560 | + * @param string $text |
|
561 | + * @return EE_Submit_Input |
|
562 | + */ |
|
563 | + public function generateCancelButton($text = '') |
|
564 | + { |
|
565 | + $cancel_button = new EE_Submit_Input( |
|
566 | + array( |
|
567 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
568 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
569 | + 'html_class' => 'ee-cancel-form', |
|
570 | + 'html_label' => ' ', |
|
571 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
572 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
573 | + ) |
|
574 | + ); |
|
575 | + $cancel_button->set_button_css_attributes(false); |
|
576 | + return $cancel_button; |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * appends a float clearing div onto end of form |
|
583 | + * |
|
584 | + * @return void |
|
585 | + * @throws EE_Error |
|
586 | + */ |
|
587 | + public function clearFormButtonFloats() |
|
588 | + { |
|
589 | + $this->form->add_subsections( |
|
590 | + array( |
|
591 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
592 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
593 | + ), |
|
594 | + ), |
|
595 | + null, |
|
596 | + false |
|
597 | + ); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
604 | + * returns a string of HTML that can be directly echoed in a template |
|
605 | + * |
|
606 | + * @return string |
|
607 | + * @throws LogicException |
|
608 | + * @throws EE_Error |
|
609 | + */ |
|
610 | + public function display() |
|
611 | + { |
|
612 | + $form_html = apply_filters( |
|
613 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
614 | + '' |
|
615 | + ); |
|
616 | + $form_config = $this->formConfig(); |
|
617 | + if ( |
|
618 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
619 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
620 | + ) { |
|
621 | + $form_html .= $this->form()->form_open($this->formAction()); |
|
622 | + } |
|
623 | + $form_html .= $this->form(true)->get_html($this->form_has_errors); |
|
624 | + if ( |
|
625 | + $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
626 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
627 | + ) { |
|
628 | + $form_html .= $this->form()->form_close(); |
|
629 | + } |
|
630 | + $form_html .= apply_filters( |
|
631 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
632 | + '' |
|
633 | + ); |
|
634 | + return $form_html; |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * handles processing the form submission |
|
641 | + * returns true or false depending on whether the form was processed successfully or not |
|
642 | + * |
|
643 | + * @param array $submitted_form_data |
|
644 | + * @return array |
|
645 | + * @throws EE_Error |
|
646 | + * @throws LogicException |
|
647 | + * @throws InvalidFormSubmissionException |
|
648 | + */ |
|
649 | + public function process($submitted_form_data = array()) |
|
650 | + { |
|
651 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
652 | + throw new InvalidFormSubmissionException($this->form_name); |
|
653 | + } |
|
654 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
655 | + if (! $this->form()->is_valid()) { |
|
656 | + throw new InvalidFormSubmissionException( |
|
657 | + $this->form_name, |
|
658 | + sprintf( |
|
659 | + esc_html__( |
|
660 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
661 | + 'event_espresso' |
|
662 | + ), |
|
663 | + $this->form_name, |
|
664 | + '<br />', |
|
665 | + $this->form()->submission_error_message() |
|
666 | + ) |
|
667 | + ); |
|
668 | + } |
|
669 | + return apply_filters( |
|
670 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
671 | + $this->form()->valid_data(), |
|
672 | + $this |
|
673 | + ); |
|
674 | + } |
|
675 | 675 | |
676 | 676 | |
677 | 677 |
@@ -15,214 +15,214 @@ |
||
15 | 15 | class EEH_Money extends EEH_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * This removes all localized money formatting from the incoming value |
|
20 | - * Note: uses this site's currency settings for deciding what is considered a |
|
21 | - * "thousands separator" (usually the character "," ) |
|
22 | - * and what is a "decimal mark" (usually the character ".") |
|
23 | - * |
|
24 | - * @param int|float|string $money_value |
|
25 | - * @param string $CNT_ISO |
|
26 | - * @return float |
|
27 | - * @throws EE_Error |
|
28 | - */ |
|
29 | - public static function strip_localized_money_formatting($money_value, $CNT_ISO = '') |
|
30 | - { |
|
31 | - $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
32 | - $money_value = str_replace( |
|
33 | - array( |
|
34 | - $currency_config->thsnds, |
|
35 | - $currency_config->dec_mrk, |
|
36 | - ), |
|
37 | - array( |
|
38 | - '', // remove thousands separator |
|
39 | - '.', // convert decimal mark to what PHP expects |
|
40 | - ), |
|
41 | - $money_value |
|
42 | - ); |
|
43 | - $money_value = filter_var( |
|
44 | - $money_value, |
|
45 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
46 | - FILTER_FLAG_ALLOW_FRACTION |
|
47 | - ); |
|
48 | - return $money_value; |
|
49 | - } |
|
18 | + /** |
|
19 | + * This removes all localized money formatting from the incoming value |
|
20 | + * Note: uses this site's currency settings for deciding what is considered a |
|
21 | + * "thousands separator" (usually the character "," ) |
|
22 | + * and what is a "decimal mark" (usually the character ".") |
|
23 | + * |
|
24 | + * @param int|float|string $money_value |
|
25 | + * @param string $CNT_ISO |
|
26 | + * @return float |
|
27 | + * @throws EE_Error |
|
28 | + */ |
|
29 | + public static function strip_localized_money_formatting($money_value, $CNT_ISO = '') |
|
30 | + { |
|
31 | + $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
32 | + $money_value = str_replace( |
|
33 | + array( |
|
34 | + $currency_config->thsnds, |
|
35 | + $currency_config->dec_mrk, |
|
36 | + ), |
|
37 | + array( |
|
38 | + '', // remove thousands separator |
|
39 | + '.', // convert decimal mark to what PHP expects |
|
40 | + ), |
|
41 | + $money_value |
|
42 | + ); |
|
43 | + $money_value = filter_var( |
|
44 | + $money_value, |
|
45 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
46 | + FILTER_FLAG_ALLOW_FRACTION |
|
47 | + ); |
|
48 | + return $money_value; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * This converts an incoming localized money value into a standard float item (to three decimal places) |
|
54 | - * Only use this if you know the $money_value follows your currency configuration's |
|
55 | - * settings. Note: this uses this site's currency settings for deciding what is considered a |
|
56 | - * "thousands separator" (usually the character "," ) |
|
57 | - * and what is a "decimal mark" (usually the character ".") |
|
58 | - * |
|
59 | - * @param int|string $money_value |
|
60 | - * @return float |
|
61 | - * @throws EE_Error |
|
62 | - */ |
|
63 | - public static function convert_to_float_from_localized_money($money_value) |
|
64 | - { |
|
65 | - //float it! and round to three decimal places |
|
66 | - return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3); |
|
67 | - } |
|
52 | + /** |
|
53 | + * This converts an incoming localized money value into a standard float item (to three decimal places) |
|
54 | + * Only use this if you know the $money_value follows your currency configuration's |
|
55 | + * settings. Note: this uses this site's currency settings for deciding what is considered a |
|
56 | + * "thousands separator" (usually the character "," ) |
|
57 | + * and what is a "decimal mark" (usually the character ".") |
|
58 | + * |
|
59 | + * @param int|string $money_value |
|
60 | + * @return float |
|
61 | + * @throws EE_Error |
|
62 | + */ |
|
63 | + public static function convert_to_float_from_localized_money($money_value) |
|
64 | + { |
|
65 | + //float it! and round to three decimal places |
|
66 | + return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3); |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
72 | - * This should be used to compare floats instead of normal '==' because floats |
|
73 | - * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
74 | - * but actually differ by 0.00000001. |
|
75 | - * |
|
76 | - * @see http://biostall.com/php-function-to-compare-floating-point-numbers |
|
77 | - * @param float $float1 |
|
78 | - * @param float $float2 |
|
79 | - * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
80 | - * @return bool whether the equation is true or false |
|
81 | - * @throws EE_Error |
|
82 | - */ |
|
83 | - public static function compare_floats($float1, $float2, $operator = '=') |
|
84 | - { |
|
85 | - // Check numbers to 5 digits of precision |
|
86 | - $epsilon = 0.00001; |
|
87 | - $float1 = (float) $float1; |
|
88 | - $float2 = (float) $float2; |
|
89 | - switch ($operator) { |
|
90 | - // equal |
|
91 | - case "=": |
|
92 | - case "==": |
|
93 | - case "===": |
|
94 | - case "eq": |
|
95 | - if (abs($float1 - $float2) < $epsilon) { |
|
96 | - return true; |
|
97 | - } |
|
98 | - break; |
|
99 | - // less than |
|
100 | - case "<": |
|
101 | - case "lt": |
|
102 | - if (abs($float1 - $float2) < $epsilon) { |
|
103 | - return false; |
|
104 | - } else { |
|
105 | - if ($float1 < $float2) { |
|
106 | - return true; |
|
107 | - } |
|
108 | - } |
|
109 | - break; |
|
110 | - // less than or equal |
|
111 | - case "<=": |
|
112 | - case "lte": |
|
113 | - if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) { |
|
114 | - return true; |
|
115 | - } |
|
116 | - break; |
|
117 | - // greater than |
|
118 | - case ">": |
|
119 | - case "gt": |
|
120 | - if (abs($float1 - $float2) < $epsilon) { |
|
121 | - return false; |
|
122 | - } else { |
|
123 | - if ($float1 > $float2) { |
|
124 | - return true; |
|
125 | - } |
|
126 | - } |
|
127 | - break; |
|
128 | - // greater than or equal |
|
129 | - case ">=": |
|
130 | - case "gte": |
|
131 | - if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) { |
|
132 | - return true; |
|
133 | - } |
|
134 | - break; |
|
135 | - case "<>": |
|
136 | - case "!=": |
|
137 | - case "ne": |
|
138 | - if (abs($float1 - $float2) > $epsilon) { |
|
139 | - return true; |
|
140 | - } |
|
141 | - break; |
|
142 | - default: |
|
143 | - throw new EE_Error(__("Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", |
|
144 | - 'event_espresso')); |
|
145 | - } |
|
146 | - return false; |
|
147 | - } |
|
70 | + /** |
|
71 | + * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
72 | + * This should be used to compare floats instead of normal '==' because floats |
|
73 | + * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
74 | + * but actually differ by 0.00000001. |
|
75 | + * |
|
76 | + * @see http://biostall.com/php-function-to-compare-floating-point-numbers |
|
77 | + * @param float $float1 |
|
78 | + * @param float $float2 |
|
79 | + * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
80 | + * @return bool whether the equation is true or false |
|
81 | + * @throws EE_Error |
|
82 | + */ |
|
83 | + public static function compare_floats($float1, $float2, $operator = '=') |
|
84 | + { |
|
85 | + // Check numbers to 5 digits of precision |
|
86 | + $epsilon = 0.00001; |
|
87 | + $float1 = (float) $float1; |
|
88 | + $float2 = (float) $float2; |
|
89 | + switch ($operator) { |
|
90 | + // equal |
|
91 | + case "=": |
|
92 | + case "==": |
|
93 | + case "===": |
|
94 | + case "eq": |
|
95 | + if (abs($float1 - $float2) < $epsilon) { |
|
96 | + return true; |
|
97 | + } |
|
98 | + break; |
|
99 | + // less than |
|
100 | + case "<": |
|
101 | + case "lt": |
|
102 | + if (abs($float1 - $float2) < $epsilon) { |
|
103 | + return false; |
|
104 | + } else { |
|
105 | + if ($float1 < $float2) { |
|
106 | + return true; |
|
107 | + } |
|
108 | + } |
|
109 | + break; |
|
110 | + // less than or equal |
|
111 | + case "<=": |
|
112 | + case "lte": |
|
113 | + if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) { |
|
114 | + return true; |
|
115 | + } |
|
116 | + break; |
|
117 | + // greater than |
|
118 | + case ">": |
|
119 | + case "gt": |
|
120 | + if (abs($float1 - $float2) < $epsilon) { |
|
121 | + return false; |
|
122 | + } else { |
|
123 | + if ($float1 > $float2) { |
|
124 | + return true; |
|
125 | + } |
|
126 | + } |
|
127 | + break; |
|
128 | + // greater than or equal |
|
129 | + case ">=": |
|
130 | + case "gte": |
|
131 | + if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) { |
|
132 | + return true; |
|
133 | + } |
|
134 | + break; |
|
135 | + case "<>": |
|
136 | + case "!=": |
|
137 | + case "ne": |
|
138 | + if (abs($float1 - $float2) > $epsilon) { |
|
139 | + return true; |
|
140 | + } |
|
141 | + break; |
|
142 | + default: |
|
143 | + throw new EE_Error(__("Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", |
|
144 | + 'event_espresso')); |
|
145 | + } |
|
146 | + return false; |
|
147 | + } |
|
148 | 148 | |
149 | 149 | |
150 | - /** |
|
151 | - * This returns a localized format string suitable for jQplot. |
|
152 | - * |
|
153 | - * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
154 | - * Otherwise will use currency settings for current active country on site. |
|
155 | - * @return string |
|
156 | - * @throws EE_Error |
|
157 | - */ |
|
158 | - public static function get_format_for_jqplot($CNT_ISO = '') |
|
159 | - { |
|
160 | - //default format |
|
161 | - $format = 'f'; |
|
162 | - $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
163 | - //first get the decimal place and number of places |
|
164 | - $format = "%'." . $currency_config->dec_plc . $format; |
|
165 | - //currency symbol on right side. |
|
166 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
167 | - return $format; |
|
168 | - } |
|
150 | + /** |
|
151 | + * This returns a localized format string suitable for jQplot. |
|
152 | + * |
|
153 | + * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
154 | + * Otherwise will use currency settings for current active country on site. |
|
155 | + * @return string |
|
156 | + * @throws EE_Error |
|
157 | + */ |
|
158 | + public static function get_format_for_jqplot($CNT_ISO = '') |
|
159 | + { |
|
160 | + //default format |
|
161 | + $format = 'f'; |
|
162 | + $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
163 | + //first get the decimal place and number of places |
|
164 | + $format = "%'." . $currency_config->dec_plc . $format; |
|
165 | + //currency symbol on right side. |
|
166 | + $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
167 | + return $format; |
|
168 | + } |
|
169 | 169 | |
170 | 170 | |
171 | - /** |
|
172 | - * This returns a localized format string suitable for usage with the Google Charts API format param. |
|
173 | - * |
|
174 | - * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
175 | - * Otherwise will use currency settings for current active country on site. |
|
176 | - * Note: GoogleCharts uses ICU pattern set |
|
177 | - * (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) |
|
178 | - * @return string |
|
179 | - * @throws EE_Error |
|
180 | - */ |
|
181 | - public static function get_format_for_google_charts($CNT_ISO = '') |
|
182 | - { |
|
183 | - $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
184 | - $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
|
185 | - //first get the decimal place and number of places |
|
186 | - $format = '#,##0.' . $decimal_places_placeholder; |
|
187 | - //currency symbol on right side. |
|
188 | - $format = $currency_config->sign_b4 |
|
189 | - ? $currency_config->sign . $format |
|
190 | - : $format |
|
191 | - . $currency_config->sign; |
|
192 | - $formatterObject = array( |
|
193 | - 'decimalSymbol' => $currency_config->dec_mrk, |
|
194 | - 'groupingSymbol' => $currency_config->thsnds, |
|
195 | - 'fractionDigits' => $currency_config->dec_plc, |
|
196 | - ); |
|
197 | - if ($currency_config->sign_b4) { |
|
198 | - $formatterObject['prefix'] = $currency_config->sign; |
|
199 | - } else { |
|
200 | - $formatterObject['suffix'] = $currency_config->sign; |
|
201 | - } |
|
202 | - return array( |
|
203 | - 'format' => $format, |
|
204 | - 'formatterObject' => $formatterObject, |
|
205 | - ); |
|
206 | - } |
|
171 | + /** |
|
172 | + * This returns a localized format string suitable for usage with the Google Charts API format param. |
|
173 | + * |
|
174 | + * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
175 | + * Otherwise will use currency settings for current active country on site. |
|
176 | + * Note: GoogleCharts uses ICU pattern set |
|
177 | + * (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) |
|
178 | + * @return string |
|
179 | + * @throws EE_Error |
|
180 | + */ |
|
181 | + public static function get_format_for_google_charts($CNT_ISO = '') |
|
182 | + { |
|
183 | + $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
184 | + $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
|
185 | + //first get the decimal place and number of places |
|
186 | + $format = '#,##0.' . $decimal_places_placeholder; |
|
187 | + //currency symbol on right side. |
|
188 | + $format = $currency_config->sign_b4 |
|
189 | + ? $currency_config->sign . $format |
|
190 | + : $format |
|
191 | + . $currency_config->sign; |
|
192 | + $formatterObject = array( |
|
193 | + 'decimalSymbol' => $currency_config->dec_mrk, |
|
194 | + 'groupingSymbol' => $currency_config->thsnds, |
|
195 | + 'fractionDigits' => $currency_config->dec_plc, |
|
196 | + ); |
|
197 | + if ($currency_config->sign_b4) { |
|
198 | + $formatterObject['prefix'] = $currency_config->sign; |
|
199 | + } else { |
|
200 | + $formatterObject['suffix'] = $currency_config->sign; |
|
201 | + } |
|
202 | + return array( |
|
203 | + 'format' => $format, |
|
204 | + 'formatterObject' => $formatterObject, |
|
205 | + ); |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | - /** |
|
210 | - * @param string $CNT_ISO |
|
211 | - * @return EE_Currency_Config|null |
|
212 | - * @throws EE_Error |
|
213 | - */ |
|
214 | - public static function get_currency_config($CNT_ISO = '') |
|
215 | - { |
|
216 | - //if CNT_ISO passed lets try to get currency settings for it. |
|
217 | - $currency_config = $CNT_ISO !== '' |
|
218 | - ? new EE_Currency_Config($CNT_ISO) |
|
219 | - : null; |
|
220 | - //default currency settings for site if not set |
|
221 | - if (! $currency_config instanceof EE_Currency_Config) { |
|
222 | - $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
223 | - ? EE_Registry::instance()->CFG->currency |
|
224 | - : new EE_Currency_Config(); |
|
225 | - } |
|
226 | - return $currency_config; |
|
227 | - } |
|
209 | + /** |
|
210 | + * @param string $CNT_ISO |
|
211 | + * @return EE_Currency_Config|null |
|
212 | + * @throws EE_Error |
|
213 | + */ |
|
214 | + public static function get_currency_config($CNT_ISO = '') |
|
215 | + { |
|
216 | + //if CNT_ISO passed lets try to get currency settings for it. |
|
217 | + $currency_config = $CNT_ISO !== '' |
|
218 | + ? new EE_Currency_Config($CNT_ISO) |
|
219 | + : null; |
|
220 | + //default currency settings for site if not set |
|
221 | + if (! $currency_config instanceof EE_Currency_Config) { |
|
222 | + $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
223 | + ? EE_Registry::instance()->CFG->currency |
|
224 | + : new EE_Currency_Config(); |
|
225 | + } |
|
226 | + return $currency_config; |
|
227 | + } |
|
228 | 228 | } //end class EEH_Money |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | ), |
41 | 41 | $money_value |
42 | 42 | ); |
43 | - $money_value = filter_var( |
|
43 | + $money_value = filter_var( |
|
44 | 44 | $money_value, |
45 | 45 | FILTER_SANITIZE_NUMBER_FLOAT, |
46 | 46 | FILTER_FLAG_ALLOW_FRACTION |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | } |
141 | 141 | break; |
142 | 142 | default: |
143 | - throw new EE_Error(__("Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", |
|
143 | + throw new EE_Error(__("Unknown operator '".$operator."' in EEH_Money::compare_floats()", |
|
144 | 144 | 'event_espresso')); |
145 | 145 | } |
146 | 146 | return false; |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | $format = 'f'; |
162 | 162 | $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
163 | 163 | //first get the decimal place and number of places |
164 | - $format = "%'." . $currency_config->dec_plc . $format; |
|
164 | + $format = "%'.".$currency_config->dec_plc.$format; |
|
165 | 165 | //currency symbol on right side. |
166 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
166 | + $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign; |
|
167 | 167 | return $format; |
168 | 168 | } |
169 | 169 | |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
184 | 184 | $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
185 | 185 | //first get the decimal place and number of places |
186 | - $format = '#,##0.' . $decimal_places_placeholder; |
|
186 | + $format = '#,##0.'.$decimal_places_placeholder; |
|
187 | 187 | //currency symbol on right side. |
188 | - $format = $currency_config->sign_b4 |
|
189 | - ? $currency_config->sign . $format |
|
188 | + $format = $currency_config->sign_b4 |
|
189 | + ? $currency_config->sign.$format |
|
190 | 190 | : $format |
191 | 191 | . $currency_config->sign; |
192 | 192 | $formatterObject = array( |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | ? new EE_Currency_Config($CNT_ISO) |
219 | 219 | : null; |
220 | 220 | //default currency settings for site if not set |
221 | - if (! $currency_config instanceof EE_Currency_Config) { |
|
221 | + if ( ! $currency_config instanceof EE_Currency_Config) { |
|
222 | 222 | $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
223 | 223 | ? EE_Registry::instance()->CFG->currency |
224 | 224 | : new EE_Currency_Config(); |
@@ -15,139 +15,139 @@ |
||
15 | 15 | trait RegistrationsAdmin |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * This will select all checkboxes on a registration list table for the given array of |
|
20 | - * registration ids. |
|
21 | - * Assumes the actor is on a list table page for registrations. |
|
22 | - * @param $registration_ids |
|
23 | - */ |
|
24 | - public function selectBulkActionCheckboxesForRegistrationIds(array $registration_ids) |
|
25 | - { |
|
26 | - foreach ($registration_ids as $registration_id) { |
|
27 | - $this->actor()->checkOption( |
|
28 | - RegistrationsAdminPage::listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
29 | - ); |
|
30 | - } |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Navigates the actor to the default registration list table page. |
|
36 | - * @param string $additional_params |
|
37 | - */ |
|
38 | - public function amOnDefaultRegistrationsListTableAdminPage($additional_params = '') |
|
39 | - { |
|
40 | - $this->actor()->amOnAdminPage( |
|
41 | - RegistrationsAdminPage::registrationsDefaultAdminListTableUrl($additional_params) |
|
42 | - ); |
|
43 | - //wait for page to fully load |
|
44 | - $this->actor()->wait(5); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Will enter the provided value in the registration list table search field and execute a search for that value. |
|
50 | - * @param string $search_text |
|
51 | - */ |
|
52 | - public function searchForRegistrationOnRegistrationListTableWithText($search_text) |
|
53 | - { |
|
54 | - $this->amOnDefaultRegistrationsListTableAdminPage(); |
|
55 | - $this->actor()->fillField(RegistrationsAdminPage::SEARCH_INPUT_SELECTOR_LIST_TABLE_REGISTRATION, $search_text); |
|
56 | - $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
57 | - $this->actor()->waitForText('Displaying search results for'); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * This will filter the registration list table to view registrations for the given event id. |
|
64 | - * Assumption is made that you are logged into the admin but you do not need to be on the registration list table |
|
65 | - * page. |
|
66 | - * |
|
67 | - * @param int $event_id The id of the event viewing registrations for. |
|
68 | - */ |
|
69 | - public function amViewingRegistrationsForEvent($event_id) |
|
70 | - { |
|
71 | - $this->actor()->amOnDefaultEventsListTablePage(); |
|
72 | - $this->actor()->click(EventsAdmin::listTableActionLinkRegistrationsForEvent($event_id)); |
|
73 | - $this->actor()->waitForText('Viewing registrations for the event'); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * This helper will initiate registering for the given event via the backend. |
|
79 | - * @param int $event_id The event to initiate registration for. |
|
80 | - */ |
|
81 | - public function amOnAdminRegistrationPageForEvent($event_id) |
|
82 | - { |
|
83 | - $this->actor()->amViewingRegistrationsForEvent($event_id); |
|
84 | - $this->actor()->click(RegistrationsAdminPage::BUTTON_ADD_NEW_REGISTRATION); |
|
85 | - $this->actor()->waitForText('Adding Registration For'); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * This clicks the View Details Link for Registration with the given Id |
|
92 | - * @param $registration_id |
|
93 | - */ |
|
94 | - public function clickViewDetailsLinkForRegistrationWithId($registration_id) |
|
95 | - { |
|
96 | - $this->actor()->click(RegistrationsAdminPage::viewDetailsLinkSelectorForRegistrationId($registration_id)); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * /** |
|
102 | - * This assumes you are on the admin details page for a registration in EE. It selects the given status in the |
|
103 | - * dropdown for changing registration status. |
|
104 | - * |
|
105 | - * @param string $status_label_or_value Either the label for the dropdown option or the value for the option. |
|
106 | - * @param $status_label_or_value |
|
107 | - */ |
|
108 | - public function selectRegistrationStatusOnRegistrationDetailsPageFor($status_label_or_value) |
|
109 | - { |
|
110 | - $this->actor()->selectOption( |
|
111 | - RegistrationsAdminPage::DROPDOWN_REGISTRATION_STATUS, |
|
112 | - $status_label_or_value |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * This selects (or deselects) the "Send Related Messages" checkbox on the Registration Details page. |
|
119 | - * @param bool $send_related_messages |
|
120 | - */ |
|
121 | - public function selectSendRelatedMessagesOptionOnRegistrationDetailsPage($send_related_messages = true) |
|
122 | - { |
|
123 | - $send_related_messages |
|
124 | - ? $this->actor()->selectOption( |
|
125 | - RegistrationsAdminPage::DROPDOWN_SEND_RELATED_MESSAGES, |
|
126 | - 'Yes' |
|
127 | - ) |
|
128 | - : $this->actor()->selecOption( |
|
129 | - RegistrationsAdminPage::DROPDOWN_SEND_RELATED_MESSAGES, |
|
130 | - 'No' |
|
131 | - ); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * This assumes you are on the admin details page for a registration in EE. It selects the given status in the |
|
138 | - * dropdown for changing registration status and submits the change. |
|
139 | - * |
|
140 | - * @param string $status_label_or_value Either the label for the dropdown option or the value for the option. |
|
141 | - * @param bool $send_related_messages Whether or not to send related messages after changing the bulk action. |
|
142 | - */ |
|
143 | - public function changeRegistrationStatusOnRegistrationDetailsPageTo( |
|
144 | - $status_label_or_value, |
|
145 | - $send_related_messages = true |
|
146 | - ) { |
|
147 | - $this->actor()->selectRegistrationStatusOnRegistrationDetailsPageFor($status_label_or_value); |
|
148 | - $this->actor()->selectSendRelatedMessagesOptionOnRegistrationDetailsPage($send_related_messages); |
|
149 | - $this->actor()->click(RegistrationsAdminPage::BUTTON_UPDATE_REGISTRATION_STATUS); |
|
150 | - $this->actor()->waitForText('Registration status has been set to'); |
|
151 | - } |
|
18 | + /** |
|
19 | + * This will select all checkboxes on a registration list table for the given array of |
|
20 | + * registration ids. |
|
21 | + * Assumes the actor is on a list table page for registrations. |
|
22 | + * @param $registration_ids |
|
23 | + */ |
|
24 | + public function selectBulkActionCheckboxesForRegistrationIds(array $registration_ids) |
|
25 | + { |
|
26 | + foreach ($registration_ids as $registration_id) { |
|
27 | + $this->actor()->checkOption( |
|
28 | + RegistrationsAdminPage::listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
29 | + ); |
|
30 | + } |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Navigates the actor to the default registration list table page. |
|
36 | + * @param string $additional_params |
|
37 | + */ |
|
38 | + public function amOnDefaultRegistrationsListTableAdminPage($additional_params = '') |
|
39 | + { |
|
40 | + $this->actor()->amOnAdminPage( |
|
41 | + RegistrationsAdminPage::registrationsDefaultAdminListTableUrl($additional_params) |
|
42 | + ); |
|
43 | + //wait for page to fully load |
|
44 | + $this->actor()->wait(5); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Will enter the provided value in the registration list table search field and execute a search for that value. |
|
50 | + * @param string $search_text |
|
51 | + */ |
|
52 | + public function searchForRegistrationOnRegistrationListTableWithText($search_text) |
|
53 | + { |
|
54 | + $this->amOnDefaultRegistrationsListTableAdminPage(); |
|
55 | + $this->actor()->fillField(RegistrationsAdminPage::SEARCH_INPUT_SELECTOR_LIST_TABLE_REGISTRATION, $search_text); |
|
56 | + $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
57 | + $this->actor()->waitForText('Displaying search results for'); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * This will filter the registration list table to view registrations for the given event id. |
|
64 | + * Assumption is made that you are logged into the admin but you do not need to be on the registration list table |
|
65 | + * page. |
|
66 | + * |
|
67 | + * @param int $event_id The id of the event viewing registrations for. |
|
68 | + */ |
|
69 | + public function amViewingRegistrationsForEvent($event_id) |
|
70 | + { |
|
71 | + $this->actor()->amOnDefaultEventsListTablePage(); |
|
72 | + $this->actor()->click(EventsAdmin::listTableActionLinkRegistrationsForEvent($event_id)); |
|
73 | + $this->actor()->waitForText('Viewing registrations for the event'); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * This helper will initiate registering for the given event via the backend. |
|
79 | + * @param int $event_id The event to initiate registration for. |
|
80 | + */ |
|
81 | + public function amOnAdminRegistrationPageForEvent($event_id) |
|
82 | + { |
|
83 | + $this->actor()->amViewingRegistrationsForEvent($event_id); |
|
84 | + $this->actor()->click(RegistrationsAdminPage::BUTTON_ADD_NEW_REGISTRATION); |
|
85 | + $this->actor()->waitForText('Adding Registration For'); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * This clicks the View Details Link for Registration with the given Id |
|
92 | + * @param $registration_id |
|
93 | + */ |
|
94 | + public function clickViewDetailsLinkForRegistrationWithId($registration_id) |
|
95 | + { |
|
96 | + $this->actor()->click(RegistrationsAdminPage::viewDetailsLinkSelectorForRegistrationId($registration_id)); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * /** |
|
102 | + * This assumes you are on the admin details page for a registration in EE. It selects the given status in the |
|
103 | + * dropdown for changing registration status. |
|
104 | + * |
|
105 | + * @param string $status_label_or_value Either the label for the dropdown option or the value for the option. |
|
106 | + * @param $status_label_or_value |
|
107 | + */ |
|
108 | + public function selectRegistrationStatusOnRegistrationDetailsPageFor($status_label_or_value) |
|
109 | + { |
|
110 | + $this->actor()->selectOption( |
|
111 | + RegistrationsAdminPage::DROPDOWN_REGISTRATION_STATUS, |
|
112 | + $status_label_or_value |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * This selects (or deselects) the "Send Related Messages" checkbox on the Registration Details page. |
|
119 | + * @param bool $send_related_messages |
|
120 | + */ |
|
121 | + public function selectSendRelatedMessagesOptionOnRegistrationDetailsPage($send_related_messages = true) |
|
122 | + { |
|
123 | + $send_related_messages |
|
124 | + ? $this->actor()->selectOption( |
|
125 | + RegistrationsAdminPage::DROPDOWN_SEND_RELATED_MESSAGES, |
|
126 | + 'Yes' |
|
127 | + ) |
|
128 | + : $this->actor()->selecOption( |
|
129 | + RegistrationsAdminPage::DROPDOWN_SEND_RELATED_MESSAGES, |
|
130 | + 'No' |
|
131 | + ); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * This assumes you are on the admin details page for a registration in EE. It selects the given status in the |
|
138 | + * dropdown for changing registration status and submits the change. |
|
139 | + * |
|
140 | + * @param string $status_label_or_value Either the label for the dropdown option or the value for the option. |
|
141 | + * @param bool $send_related_messages Whether or not to send related messages after changing the bulk action. |
|
142 | + */ |
|
143 | + public function changeRegistrationStatusOnRegistrationDetailsPageTo( |
|
144 | + $status_label_or_value, |
|
145 | + $send_related_messages = true |
|
146 | + ) { |
|
147 | + $this->actor()->selectRegistrationStatusOnRegistrationDetailsPageFor($status_label_or_value); |
|
148 | + $this->actor()->selectSendRelatedMessagesOptionOnRegistrationDetailsPage($send_related_messages); |
|
149 | + $this->actor()->click(RegistrationsAdminPage::BUTTON_UPDATE_REGISTRATION_STATUS); |
|
150 | + $this->actor()->waitForText('Registration status has been set to'); |
|
151 | + } |
|
152 | 152 | |
153 | 153 | } |
154 | 154 | \ No newline at end of file |
@@ -13,75 +13,75 @@ |
||
13 | 13 | */ |
14 | 14 | trait Checkout |
15 | 15 | { |
16 | - /** |
|
17 | - * @param $value |
|
18 | - * @param int $attendee_number |
|
19 | - * @param bool $admin Used to indicate whether we're filling out the field from the context of the admin or not. |
|
20 | - */ |
|
21 | - public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1, $admin = false) |
|
22 | - { |
|
23 | - $this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number, $admin), $value); |
|
24 | - } |
|
16 | + /** |
|
17 | + * @param $value |
|
18 | + * @param int $attendee_number |
|
19 | + * @param bool $admin Used to indicate whether we're filling out the field from the context of the admin or not. |
|
20 | + */ |
|
21 | + public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1, $admin = false) |
|
22 | + { |
|
23 | + $this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number, $admin), $value); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param $value |
|
28 | - * @param int $attendee_number |
|
29 | - * @param bool $admin Used to indicate whether we're filling out the field from the context of the admin or not. |
|
30 | - */ |
|
31 | - public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1, $admin = false) |
|
32 | - { |
|
33 | - $this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number, $admin), $value); |
|
34 | - } |
|
26 | + /** |
|
27 | + * @param $value |
|
28 | + * @param int $attendee_number |
|
29 | + * @param bool $admin Used to indicate whether we're filling out the field from the context of the admin or not. |
|
30 | + */ |
|
31 | + public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1, $admin = false) |
|
32 | + { |
|
33 | + $this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number, $admin), $value); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param $value |
|
38 | - * @param int $attendee_number |
|
39 | - * @param bool $admin Used to indicate whether we're filling out the field from the context of the admin or not. |
|
40 | - */ |
|
41 | - public function fillOutEmailFieldForAttendee($value, $attendee_number = 1, $admin = false) |
|
42 | - { |
|
43 | - $this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number, $admin), $value); |
|
44 | - } |
|
36 | + /** |
|
37 | + * @param $value |
|
38 | + * @param int $attendee_number |
|
39 | + * @param bool $admin Used to indicate whether we're filling out the field from the context of the admin or not. |
|
40 | + */ |
|
41 | + public function fillOutEmailFieldForAttendee($value, $attendee_number = 1, $admin = false) |
|
42 | + { |
|
43 | + $this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number, $admin), $value); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Clicks the next registration step button. |
|
49 | - */ |
|
50 | - public function goToNextRegistrationStep() |
|
51 | - { |
|
52 | - $this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR); |
|
53 | - } |
|
47 | + /** |
|
48 | + * Clicks the next registration step button. |
|
49 | + */ |
|
50 | + public function goToNextRegistrationStep() |
|
51 | + { |
|
52 | + $this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Selects the payment option for the given payment method slug. |
|
58 | - * |
|
59 | - * @param string $payment_method_slug |
|
60 | - * @param bool $verify_selected If true, this will wait for the "Important Information" info box after the |
|
61 | - * payment option select box is complete. Otherwise its up to calling code to |
|
62 | - * wait for whatever is needed after selecting the payment method. |
|
63 | - */ |
|
64 | - public function selectPaymentOptionFor($payment_method_slug = 'invoice', $verify_selected = true) |
|
65 | - { |
|
66 | - $this->waitForElementVisible(CheckoutPage::SELECTOR_PAYMENT_OPTIONS_CONTAINER); |
|
67 | - $this->wait(5); |
|
68 | - $this->actor()->selectOption( |
|
69 | - CheckoutPage::PAYMENT_METHOD_STEP_FORM, |
|
70 | - $payment_method_slug |
|
71 | - ); |
|
72 | - if ($verify_selected) { |
|
73 | - $this->actor()->waitForText('Important information regarding your payment'); |
|
74 | - } |
|
75 | - } |
|
56 | + /** |
|
57 | + * Selects the payment option for the given payment method slug. |
|
58 | + * |
|
59 | + * @param string $payment_method_slug |
|
60 | + * @param bool $verify_selected If true, this will wait for the "Important Information" info box after the |
|
61 | + * payment option select box is complete. Otherwise its up to calling code to |
|
62 | + * wait for whatever is needed after selecting the payment method. |
|
63 | + */ |
|
64 | + public function selectPaymentOptionFor($payment_method_slug = 'invoice', $verify_selected = true) |
|
65 | + { |
|
66 | + $this->waitForElementVisible(CheckoutPage::SELECTOR_PAYMENT_OPTIONS_CONTAINER); |
|
67 | + $this->wait(5); |
|
68 | + $this->actor()->selectOption( |
|
69 | + CheckoutPage::PAYMENT_METHOD_STEP_FORM, |
|
70 | + $payment_method_slug |
|
71 | + ); |
|
72 | + if ($verify_selected) { |
|
73 | + $this->actor()->waitForText('Important information regarding your payment'); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * Submits the payment options step form. |
|
80 | - * Assumes the actor is in the context of the payment options SPCO step. |
|
81 | - */ |
|
82 | - public function submitPaymentOptionsRegistrationStepForm() |
|
83 | - { |
|
84 | - $this->actor()->submitForm(CheckoutPage::PAYMENT_METHOD_STEP_FORM, array()); |
|
85 | - } |
|
78 | + /** |
|
79 | + * Submits the payment options step form. |
|
80 | + * Assumes the actor is in the context of the payment options SPCO step. |
|
81 | + */ |
|
82 | + public function submitPaymentOptionsRegistrationStepForm() |
|
83 | + { |
|
84 | + $this->actor()->submitForm(CheckoutPage::PAYMENT_METHOD_STEP_FORM, array()); |
|
85 | + } |
|
86 | 86 | |
87 | 87 | } |
88 | 88 | \ No newline at end of file |
@@ -14,280 +14,280 @@ |
||
14 | 14 | class EventsAdmin extends CoreAdmin |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Selector for the Add new Event button in the admin. |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * Selector for the Event Title field in the event editor |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - const EVENT_EDITOR_TITLE_FIELD_SELECTOR = ['xpath' => "//input[@id='title']"]; |
|
29 | - |
|
30 | - /** |
|
31 | - * Selector for the publish submit button in the event editor. |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = ['xpath'=>"//div[@id='major-publishing-actions']//input[@id='publish']"]; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * Selector for the save button in the event editor |
|
39 | - */ |
|
40 | - const EVENT_EDITOR_SAVE_BUTTON_SELECTOR = ['xpath' => "//div[@id='minor-publishing-actions']//input[@id='save-post']"]; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
47 | - |
|
48 | - /** |
|
49 | - * Selector for the view link after publishing an event. |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//span[@id='sample-permalink']/a"; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Selector for the ID of the event in the event editor |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Selector for the search input on the event list table page. |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $additional_params |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public static function defaultEventsListTableUrl($additional_params = '') |
|
76 | - { |
|
77 | - return self::adminUrl('espresso_events', 'default', $additional_params); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * The selector for the DTTname field for the given row in the event editor. |
|
83 | - * @param int $row_number |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
87 | - { |
|
88 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
94 | - * @param int $row_number |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
98 | - { |
|
99 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
105 | - * |
|
106 | - * @param string $field_name |
|
107 | - * @param int $row_number |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
111 | - { |
|
112 | - return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * The selector for the TKT_name field for the given display row in the event editor. |
|
118 | - * @param int $row_number |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
122 | - { |
|
123 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Selector for the TKT_base_price field for the given display row in the event editor. |
|
129 | - * @param int $row_number |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public static function eventEditorTicketPriceFieldSelector($row_number = 1) |
|
133 | - { |
|
134 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * Selector for the TKT_qty field for the given display row in the event editor. |
|
140 | - * @param int $row_number |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public static function eventEditorTicketQuantityFieldSelector($row_number = 1) |
|
144 | - { |
|
145 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_qty', $row_number); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * Selector for the advanced details toggle for the ticket for the given display row in the event editor. |
|
151 | - * @param int $row_number |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1) |
|
155 | - { |
|
156 | - return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]"; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * Selector for the subtotal amount for the given display row of the ticket in the event editor. |
|
162 | - * @param int $row_number |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1) |
|
166 | - { |
|
167 | - return "//span[@id='price-total-amount-$row_number']"; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * Selector for the Total element for the given display row of the ticket in the event editor. |
|
173 | - * @param int $row_number |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1) |
|
177 | - { |
|
178 | - return "//span[@id='price-total-amount-$row_number']"; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Selector for the taxable selector for the ticket for the given display row in the event editor. |
|
184 | - * @param int $row_number |
|
185 | - * @return string |
|
186 | - */ |
|
187 | - public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1) |
|
188 | - { |
|
189 | - return "//input[@id='edit-ticket-TKT_taxable-$row_number']"; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * This returns the xpath locater for the Tax amount display container within the advanced settings view for the |
|
195 | - * given ticket (row) and the given tax id (PRC_ID). |
|
196 | - * |
|
197 | - * @param int $tax_id The PRC_ID for the tax you want the locater for. Note, this defaults to the default tax |
|
198 | - * setup on a fresh install. |
|
199 | - * @param int $row_number What row representing the ticket you want the locator for. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1) |
|
203 | - { |
|
204 | - return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']"; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
210 | - * @param $field_name |
|
211 | - * @param int $row_number |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
215 | - { |
|
216 | - return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]"; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
222 | - * @param string $event_title |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
226 | - { |
|
227 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * Locator for for the ID column in the event list table for a given event title. |
|
233 | - * @param string $event_title |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public static function eventListTableEventIdSelectorForTitle($event_title) |
|
237 | - { |
|
238 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
239 | - . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Locator for the view link in the row of an event list table for the given event title. |
|
245 | - * @param string $event_title |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
249 | - { |
|
250 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
251 | - . "//ancestor::td//span[@class='view']/a"; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * Locator for the messenger tab in the Notifications metabox in the event editor. |
|
257 | - * @param string $messenger_slug The slug for the messenger (it's reference slug). |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug) |
|
261 | - { |
|
262 | - return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
263 | - . "//a[@rel='ee-tab-$messenger_slug']"; |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * Locator for the select input within the notifications metabox. |
|
269 | - * Note, this assumes the tab content for the related messenger is already visible. |
|
270 | - * @param string $message_type_label The message type label (visible string in the table) you want the selector for. |
|
271 | - * @return string |
|
272 | - */ |
|
273 | - public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label) |
|
274 | - { |
|
275 | - return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
276 | - . "//table[@class='messages-custom-template-switcher']" |
|
277 | - . "//tr/td[contains(.,'Registration Approved')]" |
|
278 | - . "//ancestor::tr//select[contains(@class,'message-template-selector')]"; |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * Returns the selector for the action link to the registrations list table view filtered by the given event_id. |
|
284 | - * Assumes one is in the context of the Events List Table |
|
285 | - * @param int $event_id |
|
286 | - * @return string |
|
287 | - */ |
|
288 | - public static function listTableActionLinkRegistrationsForEvent($event_id) |
|
289 | - { |
|
290 | - return "//tbody[@id='the-list']/tr/td[contains(@class, 'column-id') and contains(.,$event_id)]" |
|
291 | - . "//ancestor::tr/td//a[div[contains(@class, 'dashicons-groups')]]"; |
|
292 | - } |
|
17 | + /** |
|
18 | + * Selector for the Add new Event button in the admin. |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * Selector for the Event Title field in the event editor |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + const EVENT_EDITOR_TITLE_FIELD_SELECTOR = ['xpath' => "//input[@id='title']"]; |
|
29 | + |
|
30 | + /** |
|
31 | + * Selector for the publish submit button in the event editor. |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = ['xpath'=>"//div[@id='major-publishing-actions']//input[@id='publish']"]; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * Selector for the save button in the event editor |
|
39 | + */ |
|
40 | + const EVENT_EDITOR_SAVE_BUTTON_SELECTOR = ['xpath' => "//div[@id='minor-publishing-actions']//input[@id='save-post']"]; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
47 | + |
|
48 | + /** |
|
49 | + * Selector for the view link after publishing an event. |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//span[@id='sample-permalink']/a"; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Selector for the ID of the event in the event editor |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Selector for the search input on the event list table page. |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $additional_params |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public static function defaultEventsListTableUrl($additional_params = '') |
|
76 | + { |
|
77 | + return self::adminUrl('espresso_events', 'default', $additional_params); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * The selector for the DTTname field for the given row in the event editor. |
|
83 | + * @param int $row_number |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
87 | + { |
|
88 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
94 | + * @param int $row_number |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
98 | + { |
|
99 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
105 | + * |
|
106 | + * @param string $field_name |
|
107 | + * @param int $row_number |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
111 | + { |
|
112 | + return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * The selector for the TKT_name field for the given display row in the event editor. |
|
118 | + * @param int $row_number |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
122 | + { |
|
123 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Selector for the TKT_base_price field for the given display row in the event editor. |
|
129 | + * @param int $row_number |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public static function eventEditorTicketPriceFieldSelector($row_number = 1) |
|
133 | + { |
|
134 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * Selector for the TKT_qty field for the given display row in the event editor. |
|
140 | + * @param int $row_number |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public static function eventEditorTicketQuantityFieldSelector($row_number = 1) |
|
144 | + { |
|
145 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_qty', $row_number); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * Selector for the advanced details toggle for the ticket for the given display row in the event editor. |
|
151 | + * @param int $row_number |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1) |
|
155 | + { |
|
156 | + return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]"; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * Selector for the subtotal amount for the given display row of the ticket in the event editor. |
|
162 | + * @param int $row_number |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1) |
|
166 | + { |
|
167 | + return "//span[@id='price-total-amount-$row_number']"; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * Selector for the Total element for the given display row of the ticket in the event editor. |
|
173 | + * @param int $row_number |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1) |
|
177 | + { |
|
178 | + return "//span[@id='price-total-amount-$row_number']"; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Selector for the taxable selector for the ticket for the given display row in the event editor. |
|
184 | + * @param int $row_number |
|
185 | + * @return string |
|
186 | + */ |
|
187 | + public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1) |
|
188 | + { |
|
189 | + return "//input[@id='edit-ticket-TKT_taxable-$row_number']"; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * This returns the xpath locater for the Tax amount display container within the advanced settings view for the |
|
195 | + * given ticket (row) and the given tax id (PRC_ID). |
|
196 | + * |
|
197 | + * @param int $tax_id The PRC_ID for the tax you want the locater for. Note, this defaults to the default tax |
|
198 | + * setup on a fresh install. |
|
199 | + * @param int $row_number What row representing the ticket you want the locator for. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1) |
|
203 | + { |
|
204 | + return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']"; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
210 | + * @param $field_name |
|
211 | + * @param int $row_number |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
215 | + { |
|
216 | + return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]"; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
222 | + * @param string $event_title |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
226 | + { |
|
227 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * Locator for for the ID column in the event list table for a given event title. |
|
233 | + * @param string $event_title |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public static function eventListTableEventIdSelectorForTitle($event_title) |
|
237 | + { |
|
238 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
239 | + . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Locator for the view link in the row of an event list table for the given event title. |
|
245 | + * @param string $event_title |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
249 | + { |
|
250 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
251 | + . "//ancestor::td//span[@class='view']/a"; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * Locator for the messenger tab in the Notifications metabox in the event editor. |
|
257 | + * @param string $messenger_slug The slug for the messenger (it's reference slug). |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug) |
|
261 | + { |
|
262 | + return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
263 | + . "//a[@rel='ee-tab-$messenger_slug']"; |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * Locator for the select input within the notifications metabox. |
|
269 | + * Note, this assumes the tab content for the related messenger is already visible. |
|
270 | + * @param string $message_type_label The message type label (visible string in the table) you want the selector for. |
|
271 | + * @return string |
|
272 | + */ |
|
273 | + public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label) |
|
274 | + { |
|
275 | + return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
276 | + . "//table[@class='messages-custom-template-switcher']" |
|
277 | + . "//tr/td[contains(.,'Registration Approved')]" |
|
278 | + . "//ancestor::tr//select[contains(@class,'message-template-selector')]"; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * Returns the selector for the action link to the registrations list table view filtered by the given event_id. |
|
284 | + * Assumes one is in the context of the Events List Table |
|
285 | + * @param int $event_id |
|
286 | + * @return string |
|
287 | + */ |
|
288 | + public static function listTableActionLinkRegistrationsForEvent($event_id) |
|
289 | + { |
|
290 | + return "//tbody[@id='the-list']/tr/td[contains(@class, 'column-id') and contains(.,$event_id)]" |
|
291 | + . "//ancestor::tr/td//a[div[contains(@class, 'dashicons-groups')]]"; |
|
292 | + } |
|
293 | 293 | } |
@@ -12,27 +12,27 @@ |
||
12 | 12 | class TicketSelector |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Return the selector for the ticket option select input for the given event id. |
|
17 | - * @param int|string $event_id |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public static function ticketOptionByEventIdSelector($event_id) |
|
21 | - { |
|
22 | - return "//select[@id='ticket-selector-tbl-qty-slct-$event_id-1']"; |
|
23 | - } |
|
15 | + /** |
|
16 | + * Return the selector for the ticket option select input for the given event id. |
|
17 | + * @param int|string $event_id |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public static function ticketOptionByEventIdSelector($event_id) |
|
21 | + { |
|
22 | + return "//select[@id='ticket-selector-tbl-qty-slct-$event_id-1']"; |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Return the selector for the submit button for the ticket selector for the given event id. |
|
28 | - * @param int|string $event_id |
|
29 | - * @param bool $admin Used to return the selector from the context of the admin (true) or frontend (false) |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public static function ticketSelectionSubmitSelectorByEventId($event_id, $admin = false) |
|
33 | - { |
|
34 | - return $admin |
|
35 | - ? "#ee-new-registration-step-button" |
|
36 | - : "#ticket-selector-submit-$event_id-btn"; |
|
37 | - } |
|
26 | + /** |
|
27 | + * Return the selector for the submit button for the ticket selector for the given event id. |
|
28 | + * @param int|string $event_id |
|
29 | + * @param bool $admin Used to return the selector from the context of the admin (true) or frontend (false) |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public static function ticketSelectionSubmitSelectorByEventId($event_id, $admin = false) |
|
33 | + { |
|
34 | + return $admin |
|
35 | + ? "#ee-new-registration-step-button" |
|
36 | + : "#ticket-selector-submit-$event_id-btn"; |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | \ No newline at end of file |
@@ -12,47 +12,47 @@ |
||
12 | 12 | class RegistrationsAdmin extends CoreAdmin |
13 | 13 | { |
14 | 14 | |
15 | - const REGISTRATION_STATUS_NOT_APPROVED = 'RNA'; |
|
16 | - const REGISTRATION_STATUS_APPROVED = 'RAP'; |
|
17 | - const REGISTRATION_STATUS_PENDING_PAYMENT = 'RPP'; |
|
18 | - const SEARCH_INPUT_SELECTOR_LIST_TABLE_REGISTRATION = '#event-espresso_page_espresso_registrations-search-input'; |
|
19 | - const BUTTON_ADD_NEW_REGISTRATION = '#add-new-registration'; |
|
20 | - const DROPDOWN_REGISTRATION_STATUS = '#reg-status-change-form-reg-status'; |
|
21 | - const BUTTON_UPDATE_REGISTRATION_STATUS = '#reg-status-change-form-submit-submit'; |
|
22 | - const DROPDOWN_SEND_RELATED_MESSAGES = '#reg-status-change-form-send-notifications'; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @param string $additional_params |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public static function registrationsDefaultAdminListTableUrl($additional_params = '') |
|
30 | - { |
|
31 | - return self::adminUrl('espresso_registrations', 'default', $additional_params); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Given a registration id, this will return the selector for all the checkbox for that id. |
|
37 | - * Assumes the view is the default registrations list table. |
|
38 | - * @param int $registration_id |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public static function listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
42 | - { |
|
43 | - return "//input[@name='_REG_ID[]' and @value='{$registration_id}']"; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Given a registration id, this will return the selector for the link to the registration details. |
|
49 | - * Assumes the view is the default registrations list table. |
|
50 | - * @param int $registration_id |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public static function viewDetailsLinkSelectorForRegistrationId($registration_id) |
|
54 | - { |
|
55 | - return "//tbody[@id='the-list']/tr/td[contains(@class, 'column-_REG_ID') and contains(., $registration_id)]" |
|
56 | - . "//ancestor::tr/td[contains(@class, 'column-ATT_fname')]/a[1]"; |
|
57 | - } |
|
15 | + const REGISTRATION_STATUS_NOT_APPROVED = 'RNA'; |
|
16 | + const REGISTRATION_STATUS_APPROVED = 'RAP'; |
|
17 | + const REGISTRATION_STATUS_PENDING_PAYMENT = 'RPP'; |
|
18 | + const SEARCH_INPUT_SELECTOR_LIST_TABLE_REGISTRATION = '#event-espresso_page_espresso_registrations-search-input'; |
|
19 | + const BUTTON_ADD_NEW_REGISTRATION = '#add-new-registration'; |
|
20 | + const DROPDOWN_REGISTRATION_STATUS = '#reg-status-change-form-reg-status'; |
|
21 | + const BUTTON_UPDATE_REGISTRATION_STATUS = '#reg-status-change-form-submit-submit'; |
|
22 | + const DROPDOWN_SEND_RELATED_MESSAGES = '#reg-status-change-form-send-notifications'; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @param string $additional_params |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public static function registrationsDefaultAdminListTableUrl($additional_params = '') |
|
30 | + { |
|
31 | + return self::adminUrl('espresso_registrations', 'default', $additional_params); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Given a registration id, this will return the selector for all the checkbox for that id. |
|
37 | + * Assumes the view is the default registrations list table. |
|
38 | + * @param int $registration_id |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public static function listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
42 | + { |
|
43 | + return "//input[@name='_REG_ID[]' and @value='{$registration_id}']"; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Given a registration id, this will return the selector for the link to the registration details. |
|
49 | + * Assumes the view is the default registrations list table. |
|
50 | + * @param int $registration_id |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public static function viewDetailsLinkSelectorForRegistrationId($registration_id) |
|
54 | + { |
|
55 | + return "//tbody[@id='the-list']/tr/td[contains(@class, 'column-_REG_ID') and contains(., $registration_id)]" |
|
56 | + . "//ancestor::tr/td[contains(@class, 'column-ATT_fname')]/a[1]"; |
|
57 | + } |
|
58 | 58 | } |
59 | 59 | \ No newline at end of file |
@@ -13,71 +13,71 @@ |
||
13 | 13 | class Checkout |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * The class selector for the next step button in the checkout. |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - const NEXT_STEP_BUTTON_SELECTOR = '.spco-next-step-btn'; |
|
21 | - |
|
22 | - |
|
23 | - const PAYMENT_METHOD_STEP_FORM = '#ee-spco-payment_options-reg-step-form'; |
|
24 | - |
|
25 | - |
|
26 | - const SELECTOR_PAYMENT_OPTIONS_CONTAINER = '#spco-available-methods-of-payment-dv'; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @param int $attendee_number |
|
31 | - * @param bool $admin Used to indicate whether we're retrieving the selector from the context of the admin or not. |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public static function firstNameFieldSelectorForAttendeeNumber($attendee_number = 1, $admin = false) |
|
35 | - { |
|
36 | - return self::fieldSelectorForAttendeeNumber('fname', $attendee_number, $admin); |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * @param int $attendee_number |
|
42 | - * @param bool $admin Used to indicate whether we're retrieving the selector from the context of the admin or not. |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public static function lastNameFieldSelectorForAttendeeNumber($attendee_number = 1, $admin = false) |
|
46 | - { |
|
47 | - return self::fieldSelectorForAttendeeNumber('lname', $attendee_number, $admin); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @param int $attendee_number |
|
53 | - * @param bool $admin Used to indicate whether we're retrieving the selector from the context of the admin or not. |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public static function emailFieldSelectorForAttendeeNumber($attendee_number = 1, $admin = false) |
|
57 | - { |
|
58 | - return self::fieldSelectorForAttendeeNumber('email', $attendee_number, $admin); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param string $field_name |
|
63 | - * @param int $attendee_number |
|
64 | - * @param bool $admin Used to indicate whether we're retrieving the selector from the context of the admin or not. |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public static function fieldSelectorForAttendeeNumber($field_name, $attendee_number = 1, $admin = false) |
|
68 | - { |
|
69 | - return $admin |
|
70 | - ? "//fieldset[starts-with(@id, 'ee-registration-$attendee_number')]//input[contains(@class, 'ee-reg-qstn-$field_name')]" |
|
71 | - : "//div[starts-with(@id, 'spco-attendee-panel-dv-$attendee_number')]//input[contains(@class, 'ee-reg-qstn-$field_name')]"; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @param string $payment_method_slug Slug for the payment method. |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public static function fieldSelectorForPaymentOption($payment_method_slug) |
|
80 | - { |
|
81 | - return "#ee-available-payment-method-inputs-{$payment_method_slug}"; |
|
82 | - } |
|
16 | + /** |
|
17 | + * The class selector for the next step button in the checkout. |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + const NEXT_STEP_BUTTON_SELECTOR = '.spco-next-step-btn'; |
|
21 | + |
|
22 | + |
|
23 | + const PAYMENT_METHOD_STEP_FORM = '#ee-spco-payment_options-reg-step-form'; |
|
24 | + |
|
25 | + |
|
26 | + const SELECTOR_PAYMENT_OPTIONS_CONTAINER = '#spco-available-methods-of-payment-dv'; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @param int $attendee_number |
|
31 | + * @param bool $admin Used to indicate whether we're retrieving the selector from the context of the admin or not. |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public static function firstNameFieldSelectorForAttendeeNumber($attendee_number = 1, $admin = false) |
|
35 | + { |
|
36 | + return self::fieldSelectorForAttendeeNumber('fname', $attendee_number, $admin); |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * @param int $attendee_number |
|
42 | + * @param bool $admin Used to indicate whether we're retrieving the selector from the context of the admin or not. |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public static function lastNameFieldSelectorForAttendeeNumber($attendee_number = 1, $admin = false) |
|
46 | + { |
|
47 | + return self::fieldSelectorForAttendeeNumber('lname', $attendee_number, $admin); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @param int $attendee_number |
|
53 | + * @param bool $admin Used to indicate whether we're retrieving the selector from the context of the admin or not. |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public static function emailFieldSelectorForAttendeeNumber($attendee_number = 1, $admin = false) |
|
57 | + { |
|
58 | + return self::fieldSelectorForAttendeeNumber('email', $attendee_number, $admin); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param string $field_name |
|
63 | + * @param int $attendee_number |
|
64 | + * @param bool $admin Used to indicate whether we're retrieving the selector from the context of the admin or not. |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public static function fieldSelectorForAttendeeNumber($field_name, $attendee_number = 1, $admin = false) |
|
68 | + { |
|
69 | + return $admin |
|
70 | + ? "//fieldset[starts-with(@id, 'ee-registration-$attendee_number')]//input[contains(@class, 'ee-reg-qstn-$field_name')]" |
|
71 | + : "//div[starts-with(@id, 'spco-attendee-panel-dv-$attendee_number')]//input[contains(@class, 'ee-reg-qstn-$field_name')]"; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @param string $payment_method_slug Slug for the payment method. |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public static function fieldSelectorForPaymentOption($payment_method_slug) |
|
80 | + { |
|
81 | + return "#ee-available-payment-method-inputs-{$payment_method_slug}"; |
|
82 | + } |
|
83 | 83 | } |
@@ -1596,7 +1596,7 @@ discard block |
||
1596 | 1596 | * @param EE_Transaction $transaction |
1597 | 1597 | * @param \EE_Payment $payment |
1598 | 1598 | * @param array $REG_IDs |
1599 | - * @return bool |
|
1599 | + * @return boolean|null |
|
1600 | 1600 | */ |
1601 | 1601 | protected function _update_registration_payments( |
1602 | 1602 | EE_Transaction $transaction, |
@@ -1797,6 +1797,7 @@ discard block |
||
1797 | 1797 | * |
1798 | 1798 | * @access protected |
1799 | 1799 | * @param \EE_Payment | null $payment |
1800 | + * @param EE_Payment $payment |
|
1800 | 1801 | */ |
1801 | 1802 | protected function _maybe_send_notifications($payment = null) |
1802 | 1803 | { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | /** |
@@ -22,1960 +22,1960 @@ discard block |
||
22 | 22 | class Transactions_Admin_Page extends EE_Admin_Page |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var EE_Transaction |
|
27 | - */ |
|
28 | - private $_transaction; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var EE_Session |
|
32 | - */ |
|
33 | - private $_session; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array $_txn_status |
|
37 | - */ |
|
38 | - private static $_txn_status; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var array $_pay_status |
|
42 | - */ |
|
43 | - private static $_pay_status; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var array $_existing_reg_payment_REG_IDs |
|
47 | - */ |
|
48 | - protected $_existing_reg_payment_REG_IDs = null; |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @Constructor |
|
53 | - * @access public |
|
54 | - * @param bool $routing |
|
55 | - * @return Transactions_Admin_Page |
|
56 | - */ |
|
57 | - public function __construct($routing = true) |
|
58 | - { |
|
59 | - parent::__construct($routing); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * _init_page_props |
|
65 | - * |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - protected function _init_page_props() |
|
69 | - { |
|
70 | - $this->page_slug = TXN_PG_SLUG; |
|
71 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
72 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
73 | - $this->_admin_base_path = TXN_ADMIN; |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * _ajax_hooks |
|
79 | - * |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - protected function _ajax_hooks() |
|
83 | - { |
|
84 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
85 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
86 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * _define_page_props |
|
92 | - * |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - protected function _define_page_props() |
|
96 | - { |
|
97 | - $this->_admin_page_title = $this->page_label; |
|
98 | - $this->_labels = array( |
|
99 | - 'buttons' => array( |
|
100 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
101 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
102 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
103 | - ), |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * grab url requests and route them |
|
110 | - * |
|
111 | - * @access private |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - public function _set_page_routes() |
|
115 | - { |
|
116 | - |
|
117 | - $this->_set_transaction_status_array(); |
|
118 | - |
|
119 | - $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0; |
|
120 | - |
|
121 | - $this->_page_routes = array( |
|
122 | - |
|
123 | - 'default' => array( |
|
124 | - 'func' => '_transactions_overview_list_table', |
|
125 | - 'capability' => 'ee_read_transactions', |
|
126 | - ), |
|
127 | - |
|
128 | - 'view_transaction' => array( |
|
129 | - 'func' => '_transaction_details', |
|
130 | - 'capability' => 'ee_read_transaction', |
|
131 | - 'obj_id' => $txn_id, |
|
132 | - ), |
|
133 | - |
|
134 | - 'send_payment_reminder' => array( |
|
135 | - 'func' => '_send_payment_reminder', |
|
136 | - 'noheader' => true, |
|
137 | - 'capability' => 'ee_send_message', |
|
138 | - ), |
|
139 | - |
|
140 | - 'espresso_apply_payment' => array( |
|
141 | - 'func' => 'apply_payments_or_refunds', |
|
142 | - 'noheader' => true, |
|
143 | - 'capability' => 'ee_edit_payments', |
|
144 | - ), |
|
145 | - |
|
146 | - 'espresso_apply_refund' => array( |
|
147 | - 'func' => 'apply_payments_or_refunds', |
|
148 | - 'noheader' => true, |
|
149 | - 'capability' => 'ee_edit_payments', |
|
150 | - ), |
|
151 | - |
|
152 | - 'espresso_delete_payment' => array( |
|
153 | - 'func' => 'delete_payment', |
|
154 | - 'noheader' => true, |
|
155 | - 'capability' => 'ee_delete_payments', |
|
156 | - ), |
|
157 | - |
|
158 | - ); |
|
159 | - |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - protected function _set_page_config() |
|
164 | - { |
|
165 | - $this->_page_config = array( |
|
166 | - 'default' => array( |
|
167 | - 'nav' => array( |
|
168 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
169 | - 'order' => 10, |
|
170 | - ), |
|
171 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
172 | - 'help_tabs' => array( |
|
173 | - 'transactions_overview_help_tab' => array( |
|
174 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
175 | - 'filename' => 'transactions_overview', |
|
176 | - ), |
|
177 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
178 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
179 | - 'filename' => 'transactions_overview_table_column_headings', |
|
180 | - ), |
|
181 | - 'transactions_overview_views_filters_help_tab' => array( |
|
182 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
183 | - 'filename' => 'transactions_overview_views_filters_search', |
|
184 | - ), |
|
185 | - ), |
|
186 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
187 | - /** |
|
188 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
189 | - * may change in a later iteration so want to keep the code for then. |
|
190 | - */ |
|
191 | - //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
192 | - 'require_nonce' => false, |
|
193 | - ), |
|
194 | - 'view_transaction' => array( |
|
195 | - 'nav' => array( |
|
196 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
197 | - 'order' => 5, |
|
198 | - 'url' => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), |
|
199 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
200 | - 'persistent' => false, |
|
201 | - ), |
|
202 | - 'help_tabs' => array( |
|
203 | - 'transactions_view_transaction_help_tab' => array( |
|
204 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
205 | - 'filename' => 'transactions_view_transaction', |
|
206 | - ), |
|
207 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
208 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
209 | - 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
210 | - ), |
|
211 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
212 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
213 | - 'filename' => 'transactions_view_transaction_attendees_registered', |
|
214 | - ), |
|
215 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
216 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
217 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
218 | - ), |
|
219 | - ), |
|
220 | - 'qtips' => array('Transaction_Details_Tips'), |
|
221 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
222 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
223 | - |
|
224 | - 'require_nonce' => false, |
|
225 | - ), |
|
226 | - ); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * The below methods aren't used by this class currently |
|
232 | - */ |
|
233 | - protected function _add_screen_options() |
|
234 | - { |
|
235 | - } |
|
236 | - |
|
237 | - protected function _add_feature_pointers() |
|
238 | - { |
|
239 | - } |
|
240 | - |
|
241 | - public function admin_init() |
|
242 | - { |
|
243 | - // IF a registration was JUST added via the admin... |
|
244 | - if ( |
|
245 | - isset( |
|
246 | - $this->_req_data['redirect_from'], |
|
247 | - $this->_req_data['EVT_ID'], |
|
248 | - $this->_req_data['event_name'] |
|
249 | - ) |
|
250 | - ) { |
|
251 | - // then set a cookie so that we can block any attempts to use |
|
252 | - // the back button as a way to enter another registration. |
|
253 | - setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'); |
|
254 | - // and update the global |
|
255 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
256 | - } |
|
257 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
258 | - 'event_espresso'); |
|
259 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__('An error occurred! Please refresh the page and try again.', |
|
260 | - 'event_espresso'); |
|
261 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
262 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
263 | - EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
264 | - EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__('This transaction has been overpaid ! Payments Total', |
|
265 | - 'event_espresso'); |
|
266 | - } |
|
267 | - |
|
268 | - public function admin_notices() |
|
269 | - { |
|
270 | - } |
|
271 | - |
|
272 | - public function admin_footer_scripts() |
|
273 | - { |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * _set_transaction_status_array |
|
279 | - * sets list of transaction statuses |
|
280 | - * |
|
281 | - * @access private |
|
282 | - * @return void |
|
283 | - */ |
|
284 | - private function _set_transaction_status_array() |
|
285 | - { |
|
286 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * get_transaction_status_array |
|
292 | - * return the transaction status array for wp_list_table |
|
293 | - * |
|
294 | - * @access public |
|
295 | - * @return array |
|
296 | - */ |
|
297 | - public function get_transaction_status_array() |
|
298 | - { |
|
299 | - return self::$_txn_status; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * get list of payment statuses |
|
305 | - * |
|
306 | - * @access private |
|
307 | - * @return void |
|
308 | - */ |
|
309 | - private function _get_payment_status_array() |
|
310 | - { |
|
311 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
312 | - $this->_template_args['payment_status'] = self::$_pay_status; |
|
313 | - |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * _add_screen_options_default |
|
319 | - * |
|
320 | - * @access protected |
|
321 | - * @return void |
|
322 | - */ |
|
323 | - protected function _add_screen_options_default() |
|
324 | - { |
|
325 | - $this->_per_page_screen_option(); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * load_scripts_styles |
|
331 | - * |
|
332 | - * @access public |
|
333 | - * @return void |
|
334 | - */ |
|
335 | - public function load_scripts_styles() |
|
336 | - { |
|
337 | - //enqueue style |
|
338 | - wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), |
|
339 | - EVENT_ESPRESSO_VERSION); |
|
340 | - wp_enqueue_style('espresso_txn'); |
|
341 | - //scripts |
|
342 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
343 | - 'ee_admin_js', |
|
344 | - 'ee-datepicker', |
|
345 | - 'jquery-ui-datepicker', |
|
346 | - 'jquery-ui-draggable', |
|
347 | - 'ee-dialog', |
|
348 | - 'ee-accounting', |
|
349 | - 'ee-serialize-full-array', |
|
350 | - ), EVENT_ESPRESSO_VERSION, true); |
|
351 | - wp_enqueue_script('espresso_txn'); |
|
352 | - |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * load_scripts_styles_view_transaction |
|
358 | - * |
|
359 | - * @access public |
|
360 | - * @return void |
|
361 | - */ |
|
362 | - public function load_scripts_styles_view_transaction() |
|
363 | - { |
|
364 | - //styles |
|
365 | - wp_enqueue_style('espresso-ui-theme'); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * load_scripts_styles_default |
|
371 | - * |
|
372 | - * @access public |
|
373 | - * @return void |
|
374 | - */ |
|
375 | - public function load_scripts_styles_default() |
|
376 | - { |
|
377 | - //styles |
|
378 | - wp_enqueue_style('espresso-ui-theme'); |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * _set_list_table_views_default |
|
384 | - * |
|
385 | - * @access protected |
|
386 | - * @return void |
|
387 | - */ |
|
388 | - protected function _set_list_table_views_default() |
|
389 | - { |
|
390 | - $this->_views = array( |
|
391 | - 'all' => array( |
|
392 | - 'slug' => 'all', |
|
393 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
394 | - 'count' => 0, |
|
395 | - ), |
|
396 | - 'abandoned' => array( |
|
397 | - 'slug' => 'abandoned', |
|
398 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
399 | - 'count' => 0, |
|
400 | - ), |
|
401 | - 'failed' => array( |
|
402 | - 'slug' => 'failed', |
|
403 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
404 | - 'count' => 0, |
|
405 | - ), |
|
406 | - ); |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * _set_transaction_object |
|
412 | - * This sets the _transaction property for the transaction details screen |
|
413 | - * |
|
414 | - * @access private |
|
415 | - * @return void |
|
416 | - */ |
|
417 | - private function _set_transaction_object() |
|
418 | - { |
|
419 | - if (is_object($this->_transaction)) { |
|
420 | - return; |
|
421 | - } //get out we've already set the object |
|
422 | - |
|
423 | - $TXN = EEM_Transaction::instance(); |
|
424 | - |
|
425 | - $TXN_ID = (! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
426 | - |
|
427 | - //get transaction object |
|
428 | - $this->_transaction = $TXN->get_one_by_ID($TXN_ID); |
|
429 | - $this->_session = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null; |
|
430 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
431 | - |
|
432 | - if (empty($this->_transaction)) { |
|
433 | - $error_msg = esc_html__('An error occurred and the details for Transaction ID #', |
|
434 | - 'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); |
|
435 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
436 | - } |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * _transaction_legend_items |
|
442 | - * |
|
443 | - * @access protected |
|
444 | - * @return array |
|
445 | - */ |
|
446 | - protected function _transaction_legend_items() |
|
447 | - { |
|
448 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
449 | - $items = array(); |
|
450 | - |
|
451 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
452 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
453 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
454 | - $items['view_related_messages'] = array( |
|
455 | - 'class' => $related_for_icon['css_class'], |
|
456 | - 'desc' => $related_for_icon['label'], |
|
457 | - ); |
|
458 | - } |
|
459 | - } |
|
460 | - |
|
461 | - $items = apply_filters( |
|
462 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
463 | - array_merge($items, |
|
464 | - array( |
|
465 | - 'view_details' => array( |
|
466 | - 'class' => 'dashicons dashicons-cart', |
|
467 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
468 | - ), |
|
469 | - 'view_invoice' => array( |
|
470 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
471 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
472 | - ), |
|
473 | - 'view_receipt' => array( |
|
474 | - 'class' => 'dashicons dashicons-media-default', |
|
475 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
476 | - ), |
|
477 | - 'view_registration' => array( |
|
478 | - 'class' => 'dashicons dashicons-clipboard', |
|
479 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
480 | - ), |
|
481 | - 'payment_overview_link' => array( |
|
482 | - 'class' => 'dashicons dashicons-money', |
|
483 | - 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
484 | - ), |
|
485 | - ) |
|
486 | - ) |
|
487 | - ); |
|
488 | - |
|
489 | - if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
490 | - 'espresso_transactions_send_payment_reminder') |
|
491 | - ) { |
|
492 | - if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
493 | - $items['send_payment_reminder'] = array( |
|
494 | - 'class' => 'dashicons dashicons-email-alt', |
|
495 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
496 | - ); |
|
497 | - } else { |
|
498 | - $items['blank*'] = array( |
|
499 | - 'class' => '', |
|
500 | - 'desc' => '', |
|
501 | - ); |
|
502 | - } |
|
503 | - } else { |
|
504 | - $items['blank*'] = array( |
|
505 | - 'class' => '', |
|
506 | - 'desc' => '', |
|
507 | - ); |
|
508 | - } |
|
509 | - $more_items = apply_filters( |
|
510 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
511 | - array( |
|
512 | - 'overpaid' => array( |
|
513 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
514 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence'), |
|
515 | - ), |
|
516 | - 'complete' => array( |
|
517 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
518 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence'), |
|
519 | - ), |
|
520 | - 'incomplete' => array( |
|
521 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
522 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence'), |
|
523 | - ), |
|
524 | - 'abandoned' => array( |
|
525 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
526 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence'), |
|
527 | - ), |
|
528 | - 'failed' => array( |
|
529 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
530 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence'), |
|
531 | - ), |
|
532 | - ) |
|
533 | - ); |
|
534 | - |
|
535 | - return array_merge($items, $more_items); |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * _transactions_overview_list_table |
|
541 | - * |
|
542 | - * @access protected |
|
543 | - * @return void |
|
544 | - */ |
|
545 | - protected function _transactions_overview_list_table() |
|
546 | - { |
|
547 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
548 | - $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; |
|
549 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', |
|
550 | - 'event_espresso'), '<h3>', |
|
551 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
552 | - EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', |
|
553 | - 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; |
|
554 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
555 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * _transaction_details |
|
561 | - * generates HTML for the View Transaction Details Admin page |
|
562 | - * |
|
563 | - * @access protected |
|
564 | - * @return void |
|
565 | - */ |
|
566 | - protected function _transaction_details() |
|
567 | - { |
|
568 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
569 | - |
|
570 | - $this->_set_transaction_status_array(); |
|
571 | - |
|
572 | - $this->_template_args = array(); |
|
573 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
574 | - |
|
575 | - $this->_set_transaction_object(); |
|
576 | - |
|
577 | - $primary_registration = $this->_transaction->primary_registration(); |
|
578 | - $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null; |
|
579 | - |
|
580 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
581 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
582 | - |
|
583 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
584 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
585 | - |
|
586 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
587 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
588 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
589 | - |
|
590 | - $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
591 | - $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
592 | - |
|
593 | - if ( |
|
594 | - $attendee instanceof EE_Attendee |
|
595 | - && EE_Registry::instance()->CAP->current_user_can( |
|
596 | - 'ee_send_message', |
|
597 | - 'espresso_transactions_send_payment_reminder' |
|
598 | - ) |
|
599 | - ) { |
|
600 | - $this->_template_args['send_payment_reminder_button'] = |
|
601 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
602 | - && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code |
|
603 | - && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code |
|
604 | - ? EEH_Template::get_button_or_link( |
|
605 | - EE_Admin_Page::add_query_args_and_nonce( |
|
606 | - array( |
|
607 | - 'action' => 'send_payment_reminder', |
|
608 | - 'TXN_ID' => $this->_transaction->ID(), |
|
609 | - 'redirect_to' => 'view_transaction', |
|
610 | - ), |
|
611 | - TXN_ADMIN_URL |
|
612 | - ), |
|
613 | - __(' Send Payment Reminder', 'event_espresso'), |
|
614 | - 'button secondary-button right', |
|
615 | - 'dashicons dashicons-email-alt' |
|
616 | - ) |
|
617 | - : ''; |
|
618 | - } else { |
|
619 | - $this->_template_args['send_payment_reminder_button'] = ''; |
|
620 | - } |
|
621 | - |
|
622 | - $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
623 | - $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); |
|
624 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
625 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
626 | - } else { |
|
627 | - $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
628 | - } |
|
629 | - $this->_template_args['amount_due_class'] = ''; |
|
630 | - |
|
631 | - if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
632 | - // paid in full |
|
633 | - $this->_template_args['amount_due'] = false; |
|
634 | - } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
635 | - // overpaid |
|
636 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
637 | - } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) { |
|
638 | - // monies owing |
|
639 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
640 | - } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) { |
|
641 | - // no payments made yet |
|
642 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
643 | - } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
644 | - // free event |
|
645 | - $this->_template_args['amount_due'] = false; |
|
646 | - } |
|
647 | - |
|
648 | - $payment_method = $this->_transaction->payment_method(); |
|
649 | - |
|
650 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
651 | - ? $payment_method->admin_name() |
|
652 | - : esc_html__('Unknown', 'event_espresso'); |
|
653 | - |
|
654 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
655 | - // link back to overview |
|
656 | - $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER']) |
|
657 | - ? $_SERVER['HTTP_REFERER'] |
|
658 | - : TXN_ADMIN_URL; |
|
659 | - |
|
660 | - |
|
661 | - // next link |
|
662 | - $next_txn = $this->_transaction->next( |
|
663 | - null, |
|
664 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
665 | - 'TXN_ID' |
|
666 | - ); |
|
667 | - $this->_template_args['next_transaction'] = $next_txn |
|
668 | - ? $this->_next_link( |
|
669 | - EE_Admin_Page::add_query_args_and_nonce( |
|
670 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
671 | - TXN_ADMIN_URL |
|
672 | - ), |
|
673 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
674 | - ) |
|
675 | - : ''; |
|
676 | - // previous link |
|
677 | - $previous_txn = $this->_transaction->previous( |
|
678 | - null, |
|
679 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
680 | - 'TXN_ID' |
|
681 | - ); |
|
682 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
683 | - ? $this->_previous_link( |
|
684 | - EE_Admin_Page::add_query_args_and_nonce( |
|
685 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
686 | - TXN_ADMIN_URL |
|
687 | - ), |
|
688 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
689 | - ) |
|
690 | - : ''; |
|
691 | - |
|
692 | - // were we just redirected here after adding a new registration ??? |
|
693 | - if ( |
|
694 | - isset( |
|
695 | - $this->_req_data['redirect_from'], |
|
696 | - $this->_req_data['EVT_ID'], |
|
697 | - $this->_req_data['event_name'] |
|
698 | - ) |
|
699 | - ) { |
|
700 | - if ( |
|
701 | - EE_Registry::instance()->CAP->current_user_can( |
|
702 | - 'ee_edit_registrations', |
|
703 | - 'espresso_registrations_new_registration', |
|
704 | - $this->_req_data['EVT_ID'] |
|
705 | - ) |
|
706 | - ) { |
|
707 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
708 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
709 | - array( |
|
710 | - 'page' => 'espresso_registrations', |
|
711 | - 'action' => 'new_registration', |
|
712 | - 'return' => 'default', |
|
713 | - 'TXN_ID' => $this->_transaction->ID(), |
|
714 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
715 | - ), |
|
716 | - REG_ADMIN_URL |
|
717 | - ); |
|
718 | - $this->_admin_page_title .= '">'; |
|
719 | - |
|
720 | - $this->_admin_page_title .= sprintf( |
|
721 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
722 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
723 | - ); |
|
724 | - $this->_admin_page_title .= '</a>'; |
|
725 | - } |
|
726 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
727 | - } |
|
728 | - // grab messages at the last second |
|
729 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
730 | - // path to template |
|
731 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
732 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
733 | - $this->_template_args, true); |
|
734 | - |
|
735 | - // the details template wrapper |
|
736 | - $this->display_admin_page_with_sidebar(); |
|
737 | - |
|
738 | - } |
|
739 | - |
|
740 | - |
|
741 | - /** |
|
742 | - * _transaction_details_metaboxes |
|
743 | - * |
|
744 | - * @access protected |
|
745 | - * @return void |
|
746 | - */ |
|
747 | - protected function _transaction_details_metaboxes() |
|
748 | - { |
|
749 | - |
|
750 | - $this->_set_transaction_object(); |
|
751 | - |
|
752 | - add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'), |
|
753 | - array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high'); |
|
754 | - add_meta_box( |
|
755 | - 'edit-txn-attendees-mbox', |
|
756 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
757 | - array($this, 'txn_attendees_meta_box'), |
|
758 | - $this->_wp_page_slug, |
|
759 | - 'normal', |
|
760 | - 'high', |
|
761 | - array('TXN_ID' => $this->_transaction->ID()) |
|
762 | - ); |
|
763 | - add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'), |
|
764 | - array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
765 | - add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'), |
|
766 | - array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
767 | - |
|
768 | - } |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * txn_details_meta_box |
|
773 | - * generates HTML for the Transaction main meta box |
|
774 | - * |
|
775 | - * @access public |
|
776 | - * @return void |
|
777 | - */ |
|
778 | - public function txn_details_meta_box() |
|
779 | - { |
|
780 | - |
|
781 | - $this->_set_transaction_object(); |
|
782 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
783 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null; |
|
784 | - |
|
785 | - //get line table |
|
786 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
787 | - $Line_Item_Display = new EE_Line_Item_Display('admin_table', |
|
788 | - 'EE_Admin_Table_Line_Item_Display_Strategy'); |
|
789 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item()); |
|
790 | - $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')->get('REG_code'); |
|
791 | - |
|
792 | - // process taxes |
|
793 | - $taxes = $this->_transaction->get_many_related('Line_Item', |
|
794 | - array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
795 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
796 | - |
|
797 | - $this->_template_args['grand_total'] = EEH_Template::format_currency($this->_transaction->get('TXN_total'), |
|
798 | - false, false); |
|
799 | - $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
800 | - $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
25 | + /** |
|
26 | + * @var EE_Transaction |
|
27 | + */ |
|
28 | + private $_transaction; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var EE_Session |
|
32 | + */ |
|
33 | + private $_session; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array $_txn_status |
|
37 | + */ |
|
38 | + private static $_txn_status; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var array $_pay_status |
|
42 | + */ |
|
43 | + private static $_pay_status; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var array $_existing_reg_payment_REG_IDs |
|
47 | + */ |
|
48 | + protected $_existing_reg_payment_REG_IDs = null; |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @Constructor |
|
53 | + * @access public |
|
54 | + * @param bool $routing |
|
55 | + * @return Transactions_Admin_Page |
|
56 | + */ |
|
57 | + public function __construct($routing = true) |
|
58 | + { |
|
59 | + parent::__construct($routing); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * _init_page_props |
|
65 | + * |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + protected function _init_page_props() |
|
69 | + { |
|
70 | + $this->page_slug = TXN_PG_SLUG; |
|
71 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
72 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
73 | + $this->_admin_base_path = TXN_ADMIN; |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * _ajax_hooks |
|
79 | + * |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + protected function _ajax_hooks() |
|
83 | + { |
|
84 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
85 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
86 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * _define_page_props |
|
92 | + * |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + protected function _define_page_props() |
|
96 | + { |
|
97 | + $this->_admin_page_title = $this->page_label; |
|
98 | + $this->_labels = array( |
|
99 | + 'buttons' => array( |
|
100 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
101 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
102 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
103 | + ), |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * grab url requests and route them |
|
110 | + * |
|
111 | + * @access private |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + public function _set_page_routes() |
|
115 | + { |
|
116 | + |
|
117 | + $this->_set_transaction_status_array(); |
|
118 | + |
|
119 | + $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0; |
|
120 | + |
|
121 | + $this->_page_routes = array( |
|
122 | + |
|
123 | + 'default' => array( |
|
124 | + 'func' => '_transactions_overview_list_table', |
|
125 | + 'capability' => 'ee_read_transactions', |
|
126 | + ), |
|
127 | + |
|
128 | + 'view_transaction' => array( |
|
129 | + 'func' => '_transaction_details', |
|
130 | + 'capability' => 'ee_read_transaction', |
|
131 | + 'obj_id' => $txn_id, |
|
132 | + ), |
|
133 | + |
|
134 | + 'send_payment_reminder' => array( |
|
135 | + 'func' => '_send_payment_reminder', |
|
136 | + 'noheader' => true, |
|
137 | + 'capability' => 'ee_send_message', |
|
138 | + ), |
|
139 | + |
|
140 | + 'espresso_apply_payment' => array( |
|
141 | + 'func' => 'apply_payments_or_refunds', |
|
142 | + 'noheader' => true, |
|
143 | + 'capability' => 'ee_edit_payments', |
|
144 | + ), |
|
145 | + |
|
146 | + 'espresso_apply_refund' => array( |
|
147 | + 'func' => 'apply_payments_or_refunds', |
|
148 | + 'noheader' => true, |
|
149 | + 'capability' => 'ee_edit_payments', |
|
150 | + ), |
|
151 | + |
|
152 | + 'espresso_delete_payment' => array( |
|
153 | + 'func' => 'delete_payment', |
|
154 | + 'noheader' => true, |
|
155 | + 'capability' => 'ee_delete_payments', |
|
156 | + ), |
|
157 | + |
|
158 | + ); |
|
159 | + |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + protected function _set_page_config() |
|
164 | + { |
|
165 | + $this->_page_config = array( |
|
166 | + 'default' => array( |
|
167 | + 'nav' => array( |
|
168 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
169 | + 'order' => 10, |
|
170 | + ), |
|
171 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
172 | + 'help_tabs' => array( |
|
173 | + 'transactions_overview_help_tab' => array( |
|
174 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
175 | + 'filename' => 'transactions_overview', |
|
176 | + ), |
|
177 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
178 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
179 | + 'filename' => 'transactions_overview_table_column_headings', |
|
180 | + ), |
|
181 | + 'transactions_overview_views_filters_help_tab' => array( |
|
182 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
183 | + 'filename' => 'transactions_overview_views_filters_search', |
|
184 | + ), |
|
185 | + ), |
|
186 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
187 | + /** |
|
188 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
189 | + * may change in a later iteration so want to keep the code for then. |
|
190 | + */ |
|
191 | + //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
192 | + 'require_nonce' => false, |
|
193 | + ), |
|
194 | + 'view_transaction' => array( |
|
195 | + 'nav' => array( |
|
196 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
197 | + 'order' => 5, |
|
198 | + 'url' => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), |
|
199 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
200 | + 'persistent' => false, |
|
201 | + ), |
|
202 | + 'help_tabs' => array( |
|
203 | + 'transactions_view_transaction_help_tab' => array( |
|
204 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
205 | + 'filename' => 'transactions_view_transaction', |
|
206 | + ), |
|
207 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
208 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
209 | + 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
210 | + ), |
|
211 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
212 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
213 | + 'filename' => 'transactions_view_transaction_attendees_registered', |
|
214 | + ), |
|
215 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
216 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
217 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
218 | + ), |
|
219 | + ), |
|
220 | + 'qtips' => array('Transaction_Details_Tips'), |
|
221 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
222 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
223 | + |
|
224 | + 'require_nonce' => false, |
|
225 | + ), |
|
226 | + ); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * The below methods aren't used by this class currently |
|
232 | + */ |
|
233 | + protected function _add_screen_options() |
|
234 | + { |
|
235 | + } |
|
236 | + |
|
237 | + protected function _add_feature_pointers() |
|
238 | + { |
|
239 | + } |
|
240 | + |
|
241 | + public function admin_init() |
|
242 | + { |
|
243 | + // IF a registration was JUST added via the admin... |
|
244 | + if ( |
|
245 | + isset( |
|
246 | + $this->_req_data['redirect_from'], |
|
247 | + $this->_req_data['EVT_ID'], |
|
248 | + $this->_req_data['event_name'] |
|
249 | + ) |
|
250 | + ) { |
|
251 | + // then set a cookie so that we can block any attempts to use |
|
252 | + // the back button as a way to enter another registration. |
|
253 | + setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'); |
|
254 | + // and update the global |
|
255 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
256 | + } |
|
257 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
258 | + 'event_espresso'); |
|
259 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__('An error occurred! Please refresh the page and try again.', |
|
260 | + 'event_espresso'); |
|
261 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
262 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
263 | + EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
264 | + EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__('This transaction has been overpaid ! Payments Total', |
|
265 | + 'event_espresso'); |
|
266 | + } |
|
267 | + |
|
268 | + public function admin_notices() |
|
269 | + { |
|
270 | + } |
|
271 | + |
|
272 | + public function admin_footer_scripts() |
|
273 | + { |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * _set_transaction_status_array |
|
279 | + * sets list of transaction statuses |
|
280 | + * |
|
281 | + * @access private |
|
282 | + * @return void |
|
283 | + */ |
|
284 | + private function _set_transaction_status_array() |
|
285 | + { |
|
286 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * get_transaction_status_array |
|
292 | + * return the transaction status array for wp_list_table |
|
293 | + * |
|
294 | + * @access public |
|
295 | + * @return array |
|
296 | + */ |
|
297 | + public function get_transaction_status_array() |
|
298 | + { |
|
299 | + return self::$_txn_status; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * get list of payment statuses |
|
305 | + * |
|
306 | + * @access private |
|
307 | + * @return void |
|
308 | + */ |
|
309 | + private function _get_payment_status_array() |
|
310 | + { |
|
311 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
312 | + $this->_template_args['payment_status'] = self::$_pay_status; |
|
313 | + |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * _add_screen_options_default |
|
319 | + * |
|
320 | + * @access protected |
|
321 | + * @return void |
|
322 | + */ |
|
323 | + protected function _add_screen_options_default() |
|
324 | + { |
|
325 | + $this->_per_page_screen_option(); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * load_scripts_styles |
|
331 | + * |
|
332 | + * @access public |
|
333 | + * @return void |
|
334 | + */ |
|
335 | + public function load_scripts_styles() |
|
336 | + { |
|
337 | + //enqueue style |
|
338 | + wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), |
|
339 | + EVENT_ESPRESSO_VERSION); |
|
340 | + wp_enqueue_style('espresso_txn'); |
|
341 | + //scripts |
|
342 | + wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
343 | + 'ee_admin_js', |
|
344 | + 'ee-datepicker', |
|
345 | + 'jquery-ui-datepicker', |
|
346 | + 'jquery-ui-draggable', |
|
347 | + 'ee-dialog', |
|
348 | + 'ee-accounting', |
|
349 | + 'ee-serialize-full-array', |
|
350 | + ), EVENT_ESPRESSO_VERSION, true); |
|
351 | + wp_enqueue_script('espresso_txn'); |
|
352 | + |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * load_scripts_styles_view_transaction |
|
358 | + * |
|
359 | + * @access public |
|
360 | + * @return void |
|
361 | + */ |
|
362 | + public function load_scripts_styles_view_transaction() |
|
363 | + { |
|
364 | + //styles |
|
365 | + wp_enqueue_style('espresso-ui-theme'); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * load_scripts_styles_default |
|
371 | + * |
|
372 | + * @access public |
|
373 | + * @return void |
|
374 | + */ |
|
375 | + public function load_scripts_styles_default() |
|
376 | + { |
|
377 | + //styles |
|
378 | + wp_enqueue_style('espresso-ui-theme'); |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * _set_list_table_views_default |
|
384 | + * |
|
385 | + * @access protected |
|
386 | + * @return void |
|
387 | + */ |
|
388 | + protected function _set_list_table_views_default() |
|
389 | + { |
|
390 | + $this->_views = array( |
|
391 | + 'all' => array( |
|
392 | + 'slug' => 'all', |
|
393 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
394 | + 'count' => 0, |
|
395 | + ), |
|
396 | + 'abandoned' => array( |
|
397 | + 'slug' => 'abandoned', |
|
398 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
399 | + 'count' => 0, |
|
400 | + ), |
|
401 | + 'failed' => array( |
|
402 | + 'slug' => 'failed', |
|
403 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
404 | + 'count' => 0, |
|
405 | + ), |
|
406 | + ); |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * _set_transaction_object |
|
412 | + * This sets the _transaction property for the transaction details screen |
|
413 | + * |
|
414 | + * @access private |
|
415 | + * @return void |
|
416 | + */ |
|
417 | + private function _set_transaction_object() |
|
418 | + { |
|
419 | + if (is_object($this->_transaction)) { |
|
420 | + return; |
|
421 | + } //get out we've already set the object |
|
422 | + |
|
423 | + $TXN = EEM_Transaction::instance(); |
|
424 | + |
|
425 | + $TXN_ID = (! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
426 | + |
|
427 | + //get transaction object |
|
428 | + $this->_transaction = $TXN->get_one_by_ID($TXN_ID); |
|
429 | + $this->_session = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null; |
|
430 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
431 | + |
|
432 | + if (empty($this->_transaction)) { |
|
433 | + $error_msg = esc_html__('An error occurred and the details for Transaction ID #', |
|
434 | + 'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); |
|
435 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
436 | + } |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * _transaction_legend_items |
|
442 | + * |
|
443 | + * @access protected |
|
444 | + * @return array |
|
445 | + */ |
|
446 | + protected function _transaction_legend_items() |
|
447 | + { |
|
448 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
449 | + $items = array(); |
|
450 | + |
|
451 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
452 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
453 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
454 | + $items['view_related_messages'] = array( |
|
455 | + 'class' => $related_for_icon['css_class'], |
|
456 | + 'desc' => $related_for_icon['label'], |
|
457 | + ); |
|
458 | + } |
|
459 | + } |
|
460 | + |
|
461 | + $items = apply_filters( |
|
462 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
463 | + array_merge($items, |
|
464 | + array( |
|
465 | + 'view_details' => array( |
|
466 | + 'class' => 'dashicons dashicons-cart', |
|
467 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
468 | + ), |
|
469 | + 'view_invoice' => array( |
|
470 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
471 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
472 | + ), |
|
473 | + 'view_receipt' => array( |
|
474 | + 'class' => 'dashicons dashicons-media-default', |
|
475 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
476 | + ), |
|
477 | + 'view_registration' => array( |
|
478 | + 'class' => 'dashicons dashicons-clipboard', |
|
479 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
480 | + ), |
|
481 | + 'payment_overview_link' => array( |
|
482 | + 'class' => 'dashicons dashicons-money', |
|
483 | + 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
484 | + ), |
|
485 | + ) |
|
486 | + ) |
|
487 | + ); |
|
488 | + |
|
489 | + if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
490 | + 'espresso_transactions_send_payment_reminder') |
|
491 | + ) { |
|
492 | + if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
493 | + $items['send_payment_reminder'] = array( |
|
494 | + 'class' => 'dashicons dashicons-email-alt', |
|
495 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
496 | + ); |
|
497 | + } else { |
|
498 | + $items['blank*'] = array( |
|
499 | + 'class' => '', |
|
500 | + 'desc' => '', |
|
501 | + ); |
|
502 | + } |
|
503 | + } else { |
|
504 | + $items['blank*'] = array( |
|
505 | + 'class' => '', |
|
506 | + 'desc' => '', |
|
507 | + ); |
|
508 | + } |
|
509 | + $more_items = apply_filters( |
|
510 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
511 | + array( |
|
512 | + 'overpaid' => array( |
|
513 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
514 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence'), |
|
515 | + ), |
|
516 | + 'complete' => array( |
|
517 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
518 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence'), |
|
519 | + ), |
|
520 | + 'incomplete' => array( |
|
521 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
522 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence'), |
|
523 | + ), |
|
524 | + 'abandoned' => array( |
|
525 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
526 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence'), |
|
527 | + ), |
|
528 | + 'failed' => array( |
|
529 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
530 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence'), |
|
531 | + ), |
|
532 | + ) |
|
533 | + ); |
|
534 | + |
|
535 | + return array_merge($items, $more_items); |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * _transactions_overview_list_table |
|
541 | + * |
|
542 | + * @access protected |
|
543 | + * @return void |
|
544 | + */ |
|
545 | + protected function _transactions_overview_list_table() |
|
546 | + { |
|
547 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
548 | + $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; |
|
549 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', |
|
550 | + 'event_espresso'), '<h3>', |
|
551 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
552 | + EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', |
|
553 | + 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; |
|
554 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
555 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * _transaction_details |
|
561 | + * generates HTML for the View Transaction Details Admin page |
|
562 | + * |
|
563 | + * @access protected |
|
564 | + * @return void |
|
565 | + */ |
|
566 | + protected function _transaction_details() |
|
567 | + { |
|
568 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
569 | + |
|
570 | + $this->_set_transaction_status_array(); |
|
571 | + |
|
572 | + $this->_template_args = array(); |
|
573 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
574 | + |
|
575 | + $this->_set_transaction_object(); |
|
576 | + |
|
577 | + $primary_registration = $this->_transaction->primary_registration(); |
|
578 | + $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null; |
|
579 | + |
|
580 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
581 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
582 | + |
|
583 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
584 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
585 | + |
|
586 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
587 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
588 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
589 | + |
|
590 | + $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
591 | + $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
592 | + |
|
593 | + if ( |
|
594 | + $attendee instanceof EE_Attendee |
|
595 | + && EE_Registry::instance()->CAP->current_user_can( |
|
596 | + 'ee_send_message', |
|
597 | + 'espresso_transactions_send_payment_reminder' |
|
598 | + ) |
|
599 | + ) { |
|
600 | + $this->_template_args['send_payment_reminder_button'] = |
|
601 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
602 | + && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code |
|
603 | + && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code |
|
604 | + ? EEH_Template::get_button_or_link( |
|
605 | + EE_Admin_Page::add_query_args_and_nonce( |
|
606 | + array( |
|
607 | + 'action' => 'send_payment_reminder', |
|
608 | + 'TXN_ID' => $this->_transaction->ID(), |
|
609 | + 'redirect_to' => 'view_transaction', |
|
610 | + ), |
|
611 | + TXN_ADMIN_URL |
|
612 | + ), |
|
613 | + __(' Send Payment Reminder', 'event_espresso'), |
|
614 | + 'button secondary-button right', |
|
615 | + 'dashicons dashicons-email-alt' |
|
616 | + ) |
|
617 | + : ''; |
|
618 | + } else { |
|
619 | + $this->_template_args['send_payment_reminder_button'] = ''; |
|
620 | + } |
|
621 | + |
|
622 | + $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
623 | + $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); |
|
624 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
625 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
626 | + } else { |
|
627 | + $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
628 | + } |
|
629 | + $this->_template_args['amount_due_class'] = ''; |
|
630 | + |
|
631 | + if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
632 | + // paid in full |
|
633 | + $this->_template_args['amount_due'] = false; |
|
634 | + } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
635 | + // overpaid |
|
636 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
637 | + } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) { |
|
638 | + // monies owing |
|
639 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
640 | + } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) { |
|
641 | + // no payments made yet |
|
642 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
643 | + } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
644 | + // free event |
|
645 | + $this->_template_args['amount_due'] = false; |
|
646 | + } |
|
647 | + |
|
648 | + $payment_method = $this->_transaction->payment_method(); |
|
649 | + |
|
650 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
651 | + ? $payment_method->admin_name() |
|
652 | + : esc_html__('Unknown', 'event_espresso'); |
|
653 | + |
|
654 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
655 | + // link back to overview |
|
656 | + $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER']) |
|
657 | + ? $_SERVER['HTTP_REFERER'] |
|
658 | + : TXN_ADMIN_URL; |
|
659 | + |
|
660 | + |
|
661 | + // next link |
|
662 | + $next_txn = $this->_transaction->next( |
|
663 | + null, |
|
664 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
665 | + 'TXN_ID' |
|
666 | + ); |
|
667 | + $this->_template_args['next_transaction'] = $next_txn |
|
668 | + ? $this->_next_link( |
|
669 | + EE_Admin_Page::add_query_args_and_nonce( |
|
670 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
671 | + TXN_ADMIN_URL |
|
672 | + ), |
|
673 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
674 | + ) |
|
675 | + : ''; |
|
676 | + // previous link |
|
677 | + $previous_txn = $this->_transaction->previous( |
|
678 | + null, |
|
679 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
680 | + 'TXN_ID' |
|
681 | + ); |
|
682 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
683 | + ? $this->_previous_link( |
|
684 | + EE_Admin_Page::add_query_args_and_nonce( |
|
685 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
686 | + TXN_ADMIN_URL |
|
687 | + ), |
|
688 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
689 | + ) |
|
690 | + : ''; |
|
691 | + |
|
692 | + // were we just redirected here after adding a new registration ??? |
|
693 | + if ( |
|
694 | + isset( |
|
695 | + $this->_req_data['redirect_from'], |
|
696 | + $this->_req_data['EVT_ID'], |
|
697 | + $this->_req_data['event_name'] |
|
698 | + ) |
|
699 | + ) { |
|
700 | + if ( |
|
701 | + EE_Registry::instance()->CAP->current_user_can( |
|
702 | + 'ee_edit_registrations', |
|
703 | + 'espresso_registrations_new_registration', |
|
704 | + $this->_req_data['EVT_ID'] |
|
705 | + ) |
|
706 | + ) { |
|
707 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
708 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
709 | + array( |
|
710 | + 'page' => 'espresso_registrations', |
|
711 | + 'action' => 'new_registration', |
|
712 | + 'return' => 'default', |
|
713 | + 'TXN_ID' => $this->_transaction->ID(), |
|
714 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
715 | + ), |
|
716 | + REG_ADMIN_URL |
|
717 | + ); |
|
718 | + $this->_admin_page_title .= '">'; |
|
719 | + |
|
720 | + $this->_admin_page_title .= sprintf( |
|
721 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
722 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
723 | + ); |
|
724 | + $this->_admin_page_title .= '</a>'; |
|
725 | + } |
|
726 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
727 | + } |
|
728 | + // grab messages at the last second |
|
729 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
730 | + // path to template |
|
731 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
732 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
733 | + $this->_template_args, true); |
|
734 | + |
|
735 | + // the details template wrapper |
|
736 | + $this->display_admin_page_with_sidebar(); |
|
737 | + |
|
738 | + } |
|
739 | + |
|
740 | + |
|
741 | + /** |
|
742 | + * _transaction_details_metaboxes |
|
743 | + * |
|
744 | + * @access protected |
|
745 | + * @return void |
|
746 | + */ |
|
747 | + protected function _transaction_details_metaboxes() |
|
748 | + { |
|
749 | + |
|
750 | + $this->_set_transaction_object(); |
|
751 | + |
|
752 | + add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'), |
|
753 | + array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high'); |
|
754 | + add_meta_box( |
|
755 | + 'edit-txn-attendees-mbox', |
|
756 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
757 | + array($this, 'txn_attendees_meta_box'), |
|
758 | + $this->_wp_page_slug, |
|
759 | + 'normal', |
|
760 | + 'high', |
|
761 | + array('TXN_ID' => $this->_transaction->ID()) |
|
762 | + ); |
|
763 | + add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'), |
|
764 | + array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
765 | + add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'), |
|
766 | + array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
767 | + |
|
768 | + } |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * txn_details_meta_box |
|
773 | + * generates HTML for the Transaction main meta box |
|
774 | + * |
|
775 | + * @access public |
|
776 | + * @return void |
|
777 | + */ |
|
778 | + public function txn_details_meta_box() |
|
779 | + { |
|
780 | + |
|
781 | + $this->_set_transaction_object(); |
|
782 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
783 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null; |
|
784 | + |
|
785 | + //get line table |
|
786 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
787 | + $Line_Item_Display = new EE_Line_Item_Display('admin_table', |
|
788 | + 'EE_Admin_Table_Line_Item_Display_Strategy'); |
|
789 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item()); |
|
790 | + $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')->get('REG_code'); |
|
791 | + |
|
792 | + // process taxes |
|
793 | + $taxes = $this->_transaction->get_many_related('Line_Item', |
|
794 | + array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
795 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
796 | + |
|
797 | + $this->_template_args['grand_total'] = EEH_Template::format_currency($this->_transaction->get('TXN_total'), |
|
798 | + false, false); |
|
799 | + $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
800 | + $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
801 | 801 | |
802 | 802 | // $txn_status_class = 'status-' . $this->_transaction->get('STS_ID'); |
803 | 803 | |
804 | - // process payment details |
|
805 | - $payments = $this->_transaction->get_many_related('Payment'); |
|
806 | - if (! empty($payments)) { |
|
807 | - $this->_template_args['payments'] = $payments; |
|
808 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
809 | - } else { |
|
810 | - $this->_template_args['payments'] = false; |
|
811 | - $this->_template_args['existing_reg_payments'] = array(); |
|
812 | - } |
|
813 | - |
|
814 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
815 | - $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'), |
|
816 | - TXN_ADMIN_URL); |
|
817 | - |
|
818 | - if (isset($txn_details['invoice_number'])) { |
|
819 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
820 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number', |
|
821 | - 'event_espresso'); |
|
822 | - } |
|
823 | - |
|
824 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); |
|
825 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session', |
|
826 | - 'event_espresso'); |
|
827 | - |
|
828 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : ''; |
|
829 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP', |
|
830 | - 'event_espresso'); |
|
831 | - |
|
832 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : ''; |
|
833 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
834 | - 'event_espresso'); |
|
835 | - |
|
836 | - $reg_steps = '<ul>'; |
|
837 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
838 | - if ($reg_step_status === true) { |
|
839 | - $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
840 | - ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
841 | - } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
842 | - $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
843 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
844 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
845 | - date(get_option('date_format') . ' ' . get_option('time_format'), |
|
846 | - ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
|
847 | - ) . '</li>'; |
|
848 | - } else { |
|
849 | - $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', |
|
850 | - 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
851 | - } |
|
852 | - } |
|
853 | - $reg_steps .= '</ul>'; |
|
854 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
855 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress', |
|
856 | - 'event_espresso'); |
|
857 | - |
|
858 | - |
|
859 | - $this->_get_registrations_to_apply_payment_to(); |
|
860 | - $this->_get_payment_methods($payments); |
|
861 | - $this->_get_payment_status_array(); |
|
862 | - $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
863 | - |
|
864 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
865 | - 'action' => 'edit_transaction', |
|
866 | - 'process' => 'transaction', |
|
867 | - ), TXN_ADMIN_URL); |
|
868 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
869 | - 'page' => 'espresso_transactions', |
|
870 | - 'action' => 'espresso_apply_payment', |
|
871 | - ), WP_AJAX_URL); |
|
872 | - $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
873 | - 'page' => 'espresso_transactions', |
|
874 | - 'action' => 'espresso_delete_payment', |
|
875 | - ), WP_AJAX_URL); |
|
876 | - |
|
877 | - // 'espresso_delete_payment_nonce' |
|
878 | - |
|
879 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
880 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
881 | - |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - /** |
|
886 | - * _get_registration_payment_IDs |
|
887 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
888 | - * |
|
889 | - * @access protected |
|
890 | - * @param EE_Payment[] $payments |
|
891 | - * @return array |
|
892 | - */ |
|
893 | - protected function _get_registration_payment_IDs($payments = array()) |
|
894 | - { |
|
895 | - $existing_reg_payments = array(); |
|
896 | - // get all reg payments for these payments |
|
897 | - $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
898 | - array( |
|
899 | - 'PAY_ID' => array( |
|
900 | - 'IN', |
|
901 | - array_keys($payments), |
|
902 | - ), |
|
903 | - ), |
|
904 | - )); |
|
905 | - if (! empty($reg_payments)) { |
|
906 | - foreach ($payments as $payment) { |
|
907 | - if (! $payment instanceof EE_Payment) { |
|
908 | - continue; |
|
909 | - } else if (! isset($existing_reg_payments[$payment->ID()])) { |
|
910 | - $existing_reg_payments[$payment->ID()] = array(); |
|
911 | - } |
|
912 | - foreach ($reg_payments as $reg_payment) { |
|
913 | - if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) { |
|
914 | - $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
915 | - } |
|
916 | - } |
|
917 | - } |
|
918 | - } |
|
919 | - |
|
920 | - return $existing_reg_payments; |
|
921 | - } |
|
922 | - |
|
923 | - |
|
924 | - /** |
|
925 | - * _get_registrations_to_apply_payment_to |
|
926 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
927 | - * which allows the admin to only apply the payment to the specific registrations |
|
928 | - * |
|
929 | - * @access protected |
|
930 | - * @return void |
|
931 | - * @throws \EE_Error |
|
932 | - */ |
|
933 | - protected function _get_registrations_to_apply_payment_to() |
|
934 | - { |
|
935 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
936 | - $query_params = array( |
|
937 | - array( |
|
938 | - 'STS_ID' => array( |
|
939 | - 'IN', |
|
940 | - array( |
|
941 | - EEM_Registration::status_id_approved, |
|
942 | - EEM_Registration::status_id_pending_payment, |
|
943 | - EEM_Registration::status_id_not_approved, |
|
944 | - ), |
|
945 | - ), |
|
946 | - ), |
|
947 | - ); |
|
948 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
949 | - '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' |
|
950 | - ); |
|
951 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
952 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
953 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
954 | - EEH_HTML::tr( |
|
955 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
956 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
957 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
958 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
959 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
960 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
961 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
962 | - ) |
|
963 | - ); |
|
964 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
965 | - // get registrations for TXN |
|
966 | - $registrations = $this->_transaction->registrations($query_params); |
|
967 | - foreach ($registrations as $registration) { |
|
968 | - if ($registration instanceof EE_Registration) { |
|
969 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
970 | - ? $registration->attendee()->full_name() |
|
971 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
972 | - $owing = $registration->final_price() - $registration->paid(); |
|
973 | - $taxable = $registration->ticket()->taxable() |
|
974 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
975 | - : ''; |
|
976 | - $checked = empty($existing_reg_payments) || in_array($registration->ID(), |
|
977 | - $existing_reg_payments) |
|
978 | - ? ' checked="checked"' |
|
979 | - : ''; |
|
980 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
981 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
982 | - EEH_HTML::td($registration->ID()) . |
|
983 | - EEH_HTML::td($attendee_name) . |
|
984 | - EEH_HTML::td( |
|
985 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
986 | - ) . |
|
987 | - EEH_HTML::td($registration->event_name()) . |
|
988 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
989 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
990 | - EEH_HTML::td( |
|
991 | - '<input type="checkbox" value="' . $registration->ID() |
|
992 | - . '" name="txn_admin_payment[registrations]"' |
|
993 | - . $checked . $disabled . '>', |
|
994 | - '', 'jst-cntr' |
|
995 | - ), |
|
996 | - 'apply-payment-registration-row-' . $registration->ID() |
|
997 | - ); |
|
998 | - } |
|
999 | - } |
|
1000 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
1001 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
1002 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1003 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
1004 | - esc_html__( |
|
1005 | - 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
1006 | - 'event_espresso' |
|
1007 | - ), |
|
1008 | - '', 'clear description' |
|
1009 | - ); |
|
1010 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1011 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
1012 | - } |
|
1013 | - |
|
1014 | - |
|
1015 | - /** |
|
1016 | - * _get_reg_status_selection |
|
1017 | - * |
|
1018 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
1019 | - * instead of events. |
|
1020 | - * @access protected |
|
1021 | - * @return void |
|
1022 | - */ |
|
1023 | - protected function _get_reg_status_selection() |
|
1024 | - { |
|
1025 | - //first get all possible statuses |
|
1026 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
1027 | - //let's add a "don't change" option. |
|
1028 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
1029 | - $status_array = array_merge($status_array, $statuses); |
|
1030 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]', |
|
1031 | - $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status'); |
|
1032 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]', |
|
1033 | - $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status'); |
|
1034 | - |
|
1035 | - } |
|
1036 | - |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * _get_payment_methods |
|
1040 | - * Gets all the payment methods available generally, or the ones that are already |
|
1041 | - * selected on these payments (in case their payment methods are no longer active). |
|
1042 | - * Has the side-effect of updating the template args' payment_methods item |
|
1043 | - * |
|
1044 | - * @access private |
|
1045 | - * @param EE_Payment[] to show on this page |
|
1046 | - * @return void |
|
1047 | - */ |
|
1048 | - private function _get_payment_methods($payments = array()) |
|
1049 | - { |
|
1050 | - $payment_methods_of_payments = array(); |
|
1051 | - foreach ($payments as $payment) { |
|
1052 | - if ($payment instanceof EE_Payment) { |
|
1053 | - $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
1054 | - } |
|
1055 | - } |
|
1056 | - if ($payment_methods_of_payments) { |
|
1057 | - $query_args = array( |
|
1058 | - array( |
|
1059 | - 'OR*payment_method_for_payment' => array( |
|
1060 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
1061 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
1062 | - ), |
|
1063 | - ), |
|
1064 | - ); |
|
1065 | - } else { |
|
1066 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
1067 | - } |
|
1068 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
1069 | - } |
|
1070 | - |
|
1071 | - |
|
1072 | - /** |
|
1073 | - * txn_attendees_meta_box |
|
1074 | - * generates HTML for the Attendees Transaction main meta box |
|
1075 | - * |
|
1076 | - * @access public |
|
1077 | - * @param WP_Post $post |
|
1078 | - * @param array $metabox |
|
1079 | - * @return void |
|
1080 | - */ |
|
1081 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
1082 | - { |
|
1083 | - |
|
1084 | - extract($metabox['args']); |
|
1085 | - $this->_template_args['post'] = $post; |
|
1086 | - $this->_template_args['event_attendees'] = array(); |
|
1087 | - // process items in cart |
|
1088 | - $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); |
|
1089 | - if (! empty($line_items)) { |
|
1090 | - foreach ($line_items as $item) { |
|
1091 | - if ($item instanceof EE_Line_Item) { |
|
1092 | - switch ($item->OBJ_type()) { |
|
1093 | - |
|
1094 | - case 'Event' : |
|
1095 | - break; |
|
1096 | - |
|
1097 | - case 'Ticket' : |
|
1098 | - $ticket = $item->ticket(); |
|
1099 | - //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? |
|
1100 | - if (! $ticket instanceof EE_Ticket) { |
|
1101 | - continue; |
|
1102 | - } |
|
1103 | - try { |
|
1104 | - $event_name = $ticket->get_event_name(); |
|
1105 | - } catch (Exception $e) { |
|
1106 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1107 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
1108 | - } |
|
1109 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
1110 | - $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
1111 | - // now get all of the registrations for this transaction that use this ticket |
|
1112 | - $registrations = $ticket->get_many_related('Registration', |
|
1113 | - array(array('TXN_ID' => $this->_transaction->ID()))); |
|
1114 | - foreach ($registrations as $registration) { |
|
1115 | - if (! $registration instanceof EE_Registration) { |
|
1116 | - continue; |
|
1117 | - } |
|
1118 | - $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] = $registration->status_ID(); |
|
1119 | - $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->count(); |
|
1120 | - $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; |
|
1121 | - $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; |
|
1122 | - // attendee info |
|
1123 | - $attendee = $registration->get_first_related('Attendee'); |
|
1124 | - if ($attendee instanceof EE_Attendee) { |
|
1125 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
|
1126 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
|
1127 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', |
|
1128 | - 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
1129 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, |
|
1130 | - 'inline', false, false); |
|
1131 | - } else { |
|
1132 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
1133 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
1134 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
1135 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
1136 | - } |
|
1137 | - } |
|
1138 | - break; |
|
1139 | - |
|
1140 | - } |
|
1141 | - } |
|
1142 | - } |
|
1143 | - |
|
1144 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
1145 | - 'action' => 'edit_transaction', |
|
1146 | - 'process' => 'attendees', |
|
1147 | - ), TXN_ADMIN_URL); |
|
1148 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
1149 | - $this->_template_args, true); |
|
1150 | - |
|
1151 | - } else { |
|
1152 | - echo sprintf( |
|
1153 | - esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
1154 | - 'event_espresso'), |
|
1155 | - '<p class="important-notice">', |
|
1156 | - '</p>' |
|
1157 | - ); |
|
1158 | - } |
|
1159 | - } |
|
1160 | - |
|
1161 | - |
|
1162 | - /** |
|
1163 | - * txn_registrant_side_meta_box |
|
1164 | - * generates HTML for the Edit Transaction side meta box |
|
1165 | - * |
|
1166 | - * @access public |
|
1167 | - * @throws \EE_Error |
|
1168 | - * @return void |
|
1169 | - */ |
|
1170 | - public function txn_registrant_side_meta_box() |
|
1171 | - { |
|
1172 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; |
|
1173 | - if (! $primary_att instanceof EE_Attendee) { |
|
1174 | - $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
1175 | - 'event_espresso'); |
|
1176 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
1177 | - } |
|
1178 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
1179 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
1180 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
1181 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
1182 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
1183 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1184 | - 'action' => 'edit_attendee', |
|
1185 | - 'post' => $primary_att->ID(), |
|
1186 | - ), REG_ADMIN_URL); |
|
1187 | - // get formatted address for registrant |
|
1188 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
1189 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
1190 | - $this->_template_args, true); |
|
1191 | - } |
|
1192 | - |
|
1193 | - |
|
1194 | - /** |
|
1195 | - * txn_billing_info_side_meta_box |
|
1196 | - * generates HTML for the Edit Transaction side meta box |
|
1197 | - * |
|
1198 | - * @access public |
|
1199 | - * @return void |
|
1200 | - */ |
|
1201 | - public function txn_billing_info_side_meta_box() |
|
1202 | - { |
|
1203 | - |
|
1204 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
1205 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
1206 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
1207 | - TXN_ADMIN_URL |
|
1208 | - ); |
|
1209 | - |
|
1210 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
1211 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
1212 | - } |
|
1213 | - |
|
1214 | - |
|
1215 | - /** |
|
1216 | - * apply_payments_or_refunds |
|
1217 | - * registers a payment or refund made towards a transaction |
|
1218 | - * |
|
1219 | - * @access public |
|
1220 | - * @return void |
|
1221 | - */ |
|
1222 | - public function apply_payments_or_refunds() |
|
1223 | - { |
|
1224 | - $json_response_data = array('return_data' => false); |
|
1225 | - $valid_data = $this->_validate_payment_request_data(); |
|
1226 | - if (! empty($valid_data) |
|
1227 | - |
|
1228 | - ) { |
|
1229 | - $PAY_ID = $valid_data['PAY_ID']; |
|
1230 | - //save the new payment |
|
1231 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
1232 | - // get the TXN for this payment |
|
1233 | - $transaction = $payment->transaction(); |
|
1234 | - // verify transaction |
|
1235 | - if ($transaction instanceof EE_Transaction) { |
|
1236 | - // calculate_total_payments_and_update_status |
|
1237 | - $this->_process_transaction_payments($transaction); |
|
1238 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
1239 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
1240 | - // apply payment to registrations (if applicable) |
|
1241 | - if (! empty($REG_IDs)) { |
|
1242 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
1243 | - $this->_maybe_send_notifications(); |
|
1244 | - // now process status changes for the same registrations |
|
1245 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
1246 | - } |
|
1247 | - $this->_maybe_send_notifications($payment); |
|
1248 | - //prepare to render page |
|
1249 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
1250 | - do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, |
|
1251 | - $payment); |
|
1252 | - } else { |
|
1253 | - EE_Error::add_error( |
|
1254 | - esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'), |
|
1255 | - __FILE__, __FUNCTION__, __LINE__ |
|
1256 | - ); |
|
1257 | - } |
|
1258 | - } else { |
|
1259 | - EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.', |
|
1260 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1261 | - } |
|
1262 | - |
|
1263 | - $notices = EE_Error::get_notices(false, false, false); |
|
1264 | - $this->_template_args = array( |
|
1265 | - 'data' => $json_response_data, |
|
1266 | - 'error' => $notices['errors'], |
|
1267 | - 'success' => $notices['success'], |
|
1268 | - ); |
|
1269 | - $this->_return_json(); |
|
1270 | - } |
|
1271 | - |
|
1272 | - |
|
1273 | - /** |
|
1274 | - * _validate_payment_request_data |
|
1275 | - * |
|
1276 | - * @return array |
|
1277 | - */ |
|
1278 | - protected function _validate_payment_request_data() |
|
1279 | - { |
|
1280 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
1281 | - return false; |
|
1282 | - } |
|
1283 | - $payment_form = $this->_generate_payment_form_section(); |
|
1284 | - try { |
|
1285 | - if ($payment_form->was_submitted()) { |
|
1286 | - $payment_form->receive_form_submission(); |
|
1287 | - if (! $payment_form->is_valid()) { |
|
1288 | - $submission_error_messages = array(); |
|
1289 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
1290 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1291 | - $submission_error_messages[] = sprintf( |
|
1292 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
1293 | - $validation_error->get_form_section()->html_label_text(), |
|
1294 | - $validation_error->getMessage() |
|
1295 | - ); |
|
1296 | - } |
|
1297 | - } |
|
1298 | - EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
1299 | - |
|
1300 | - return array(); |
|
1301 | - } |
|
1302 | - } |
|
1303 | - } catch (EE_Error $e) { |
|
1304 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1305 | - |
|
1306 | - return array(); |
|
1307 | - } |
|
1308 | - |
|
1309 | - return $payment_form->valid_data(); |
|
1310 | - } |
|
1311 | - |
|
1312 | - |
|
1313 | - /** |
|
1314 | - * _generate_payment_form_section |
|
1315 | - * |
|
1316 | - * @return EE_Form_Section_Proper |
|
1317 | - */ |
|
1318 | - protected function _generate_payment_form_section() |
|
1319 | - { |
|
1320 | - return new EE_Form_Section_Proper( |
|
1321 | - array( |
|
1322 | - 'name' => 'txn_admin_payment', |
|
1323 | - 'subsections' => array( |
|
1324 | - 'PAY_ID' => new EE_Text_Input( |
|
1325 | - array( |
|
1326 | - 'default' => 0, |
|
1327 | - 'required' => false, |
|
1328 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
1329 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1330 | - ) |
|
1331 | - ), |
|
1332 | - 'TXN_ID' => new EE_Text_Input( |
|
1333 | - array( |
|
1334 | - 'default' => 0, |
|
1335 | - 'required' => true, |
|
1336 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
1337 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1338 | - ) |
|
1339 | - ), |
|
1340 | - 'type' => new EE_Text_Input( |
|
1341 | - array( |
|
1342 | - 'default' => 1, |
|
1343 | - 'required' => true, |
|
1344 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
1345 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1346 | - ) |
|
1347 | - ), |
|
1348 | - 'amount' => new EE_Text_Input( |
|
1349 | - array( |
|
1350 | - 'default' => 0, |
|
1351 | - 'required' => true, |
|
1352 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
1353 | - 'validation_strategies' => array(new EE_Float_Normalization()), |
|
1354 | - ) |
|
1355 | - ), |
|
1356 | - 'status' => new EE_Text_Input( |
|
1357 | - array( |
|
1358 | - 'default' => EEM_Payment::status_id_approved, |
|
1359 | - 'required' => true, |
|
1360 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
1361 | - ) |
|
1362 | - ), |
|
1363 | - 'PMD_ID' => new EE_Text_Input( |
|
1364 | - array( |
|
1365 | - 'default' => 2, |
|
1366 | - 'required' => true, |
|
1367 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
1368 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1369 | - ) |
|
1370 | - ), |
|
1371 | - 'date' => new EE_Text_Input( |
|
1372 | - array( |
|
1373 | - 'default' => time(), |
|
1374 | - 'required' => true, |
|
1375 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
1376 | - ) |
|
1377 | - ), |
|
1378 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
1379 | - array( |
|
1380 | - 'default' => '', |
|
1381 | - 'required' => false, |
|
1382 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
1383 | - 'validation_strategies' => array( |
|
1384 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
1385 | - 100), |
|
1386 | - ), |
|
1387 | - ) |
|
1388 | - ), |
|
1389 | - 'po_number' => new EE_Text_Input( |
|
1390 | - array( |
|
1391 | - 'default' => '', |
|
1392 | - 'required' => false, |
|
1393 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
1394 | - 'validation_strategies' => array( |
|
1395 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
1396 | - 100), |
|
1397 | - ), |
|
1398 | - ) |
|
1399 | - ), |
|
1400 | - 'accounting' => new EE_Text_Input( |
|
1401 | - array( |
|
1402 | - 'default' => '', |
|
1403 | - 'required' => false, |
|
1404 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
1405 | - 'validation_strategies' => array( |
|
1406 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
1407 | - 100), |
|
1408 | - ), |
|
1409 | - ) |
|
1410 | - ), |
|
1411 | - ), |
|
1412 | - ) |
|
1413 | - ); |
|
1414 | - } |
|
1415 | - |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * _create_payment_from_request_data |
|
1419 | - * |
|
1420 | - * @param array $valid_data |
|
1421 | - * @return EE_Payment |
|
1422 | - */ |
|
1423 | - protected function _create_payment_from_request_data($valid_data) |
|
1424 | - { |
|
1425 | - $PAY_ID = $valid_data['PAY_ID']; |
|
1426 | - // get payment amount |
|
1427 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
1428 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
1429 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
1430 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
1431 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
1432 | - $date = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a', |
|
1433 | - current_time('timestamp')); |
|
1434 | - $payment = EE_Payment::new_instance( |
|
1435 | - array( |
|
1436 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
1437 | - 'STS_ID' => $valid_data['status'], |
|
1438 | - 'PAY_timestamp' => $date, |
|
1439 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
1440 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
1441 | - 'PAY_amount' => $amount, |
|
1442 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
1443 | - 'PAY_po_number' => $valid_data['po_number'], |
|
1444 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
1445 | - 'PAY_details' => $valid_data, |
|
1446 | - 'PAY_ID' => $PAY_ID, |
|
1447 | - ), |
|
1448 | - '', |
|
1449 | - array('Y-m-d', 'g:i a') |
|
1450 | - ); |
|
1451 | - |
|
1452 | - if (! $payment->save()) { |
|
1453 | - EE_Error::add_error( |
|
1454 | - sprintf( |
|
1455 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
1456 | - $payment->ID() |
|
1457 | - ), |
|
1458 | - __FILE__, __FUNCTION__, __LINE__ |
|
1459 | - ); |
|
1460 | - } |
|
1461 | - |
|
1462 | - return $payment; |
|
1463 | - } |
|
1464 | - |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * _process_transaction_payments |
|
1468 | - * |
|
1469 | - * @param \EE_Transaction $transaction |
|
1470 | - * @return array |
|
1471 | - */ |
|
1472 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
1473 | - { |
|
1474 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
1475 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1476 | - //update the transaction with this payment |
|
1477 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
1478 | - EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'), |
|
1479 | - __FILE__, __FUNCTION__, __LINE__); |
|
1480 | - } else { |
|
1481 | - EE_Error::add_error( |
|
1482 | - esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
1483 | - 'event_espresso') |
|
1484 | - , __FILE__, __FUNCTION__, __LINE__ |
|
1485 | - ); |
|
1486 | - } |
|
1487 | - } |
|
1488 | - |
|
1489 | - |
|
1490 | - /** |
|
1491 | - * _get_REG_IDs_to_apply_payment_to |
|
1492 | - * returns a list of registration IDs that the payment will apply to |
|
1493 | - * |
|
1494 | - * @param \EE_Payment $payment |
|
1495 | - * @return array |
|
1496 | - */ |
|
1497 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
1498 | - { |
|
1499 | - $REG_IDs = array(); |
|
1500 | - // grab array of IDs for specific registrations to apply changes to |
|
1501 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
1502 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
1503 | - } |
|
1504 | - //nothing specified ? then get all reg IDs |
|
1505 | - if (empty($REG_IDs)) { |
|
1506 | - $registrations = $payment->transaction()->registrations(); |
|
1507 | - $REG_IDs = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1508 | - } |
|
1509 | - |
|
1510 | - // ensure that REG_IDs are integers and NOT strings |
|
1511 | - return array_map('intval', $REG_IDs); |
|
1512 | - } |
|
1513 | - |
|
1514 | - |
|
1515 | - /** |
|
1516 | - * @return array |
|
1517 | - */ |
|
1518 | - public function existing_reg_payment_REG_IDs() |
|
1519 | - { |
|
1520 | - return $this->_existing_reg_payment_REG_IDs; |
|
1521 | - } |
|
1522 | - |
|
1523 | - |
|
1524 | - /** |
|
1525 | - * @param array $existing_reg_payment_REG_IDs |
|
1526 | - */ |
|
1527 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
1528 | - { |
|
1529 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
1530 | - } |
|
1531 | - |
|
1532 | - |
|
1533 | - /** |
|
1534 | - * _get_existing_reg_payment_REG_IDs |
|
1535 | - * returns a list of registration IDs that the payment is currently related to |
|
1536 | - * as recorded in the database |
|
1537 | - * |
|
1538 | - * @param \EE_Payment $payment |
|
1539 | - * @return array |
|
1540 | - */ |
|
1541 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
1542 | - { |
|
1543 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
1544 | - // let's get any existing reg payment records for this payment |
|
1545 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
1546 | - // but we only want the REG IDs, so grab the array keys |
|
1547 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array(); |
|
1548 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
1549 | - } |
|
1550 | - |
|
1551 | - return $this->existing_reg_payment_REG_IDs(); |
|
1552 | - } |
|
1553 | - |
|
1554 | - |
|
1555 | - /** |
|
1556 | - * _remove_existing_registration_payments |
|
1557 | - * this calculates the difference between existing relations |
|
1558 | - * to the supplied payment and the new list registration IDs, |
|
1559 | - * removes any related registrations that no longer apply, |
|
1560 | - * and then updates the registration paid fields |
|
1561 | - * |
|
1562 | - * @param \EE_Payment $payment |
|
1563 | - * @param int $PAY_ID |
|
1564 | - * @return bool; |
|
1565 | - */ |
|
1566 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
1567 | - { |
|
1568 | - // newly created payments will have nothing recorded for $PAY_ID |
|
1569 | - if ($PAY_ID == 0) { |
|
1570 | - return false; |
|
1571 | - } |
|
1572 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1573 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
1574 | - return false; |
|
1575 | - } |
|
1576 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
1577 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1578 | - |
|
1579 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
1580 | - $payment, |
|
1581 | - array( |
|
1582 | - array( |
|
1583 | - 'PAY_ID' => $payment->ID(), |
|
1584 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
1585 | - ), |
|
1586 | - ) |
|
1587 | - ); |
|
1588 | - } |
|
1589 | - |
|
1590 | - |
|
1591 | - /** |
|
1592 | - * _update_registration_payments |
|
1593 | - * this applies the payments to the selected registrations |
|
1594 | - * but only if they have not already been paid for |
|
1595 | - * |
|
1596 | - * @param EE_Transaction $transaction |
|
1597 | - * @param \EE_Payment $payment |
|
1598 | - * @param array $REG_IDs |
|
1599 | - * @return bool |
|
1600 | - */ |
|
1601 | - protected function _update_registration_payments( |
|
1602 | - EE_Transaction $transaction, |
|
1603 | - EE_Payment $payment, |
|
1604 | - $REG_IDs = array() |
|
1605 | - ) { |
|
1606 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
1607 | - // so let's do that using our set of REG_IDs from the form |
|
1608 | - $registration_query_where_params = array( |
|
1609 | - 'REG_ID' => array('IN', $REG_IDs), |
|
1610 | - ); |
|
1611 | - // but add in some conditions regarding payment, |
|
1612 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
1613 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
1614 | - if (! $payment->is_a_refund()) { |
|
1615 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
1616 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
1617 | - } |
|
1618 | - //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); |
|
1619 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
1620 | - if (! empty($registrations)) { |
|
1621 | - /** @type EE_Payment_Processor $payment_processor */ |
|
1622 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
1623 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
1624 | - } |
|
1625 | - } |
|
1626 | - |
|
1627 | - |
|
1628 | - /** |
|
1629 | - * _process_registration_status_change |
|
1630 | - * This processes requested registration status changes for all the registrations |
|
1631 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
1632 | - * |
|
1633 | - * @param EE_Transaction $transaction |
|
1634 | - * @param array $REG_IDs |
|
1635 | - * @return bool |
|
1636 | - */ |
|
1637 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
1638 | - { |
|
1639 | - // first if there is no change in status then we get out. |
|
1640 | - if ( |
|
1641 | - ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status']) |
|
1642 | - || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' |
|
1643 | - ) { |
|
1644 | - //no error message, no change requested, just nothing to do man. |
|
1645 | - return false; |
|
1646 | - } |
|
1647 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
1648 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
1649 | - |
|
1650 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
1651 | - return $transaction_processor->manually_update_registration_statuses( |
|
1652 | - $transaction, |
|
1653 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
1654 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
1655 | - ); |
|
1656 | - } |
|
1657 | - |
|
1658 | - |
|
1659 | - /** |
|
1660 | - * _build_payment_json_response |
|
1661 | - * |
|
1662 | - * @access public |
|
1663 | - * @param \EE_Payment $payment |
|
1664 | - * @param array $REG_IDs |
|
1665 | - * @param bool | null $delete_txn_reg_status_change |
|
1666 | - * @return array |
|
1667 | - */ |
|
1668 | - protected function _build_payment_json_response( |
|
1669 | - EE_Payment $payment, |
|
1670 | - $REG_IDs = array(), |
|
1671 | - $delete_txn_reg_status_change = null |
|
1672 | - ) { |
|
1673 | - // was the payment deleted ? |
|
1674 | - if (is_bool($delete_txn_reg_status_change)) { |
|
1675 | - return array( |
|
1676 | - 'PAY_ID' => $payment->ID(), |
|
1677 | - 'amount' => $payment->amount(), |
|
1678 | - 'total_paid' => $payment->transaction()->paid(), |
|
1679 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
1680 | - 'pay_status' => $payment->STS_ID(), |
|
1681 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
1682 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
1683 | - ); |
|
1684 | - } else { |
|
1685 | - $this->_get_payment_status_array(); |
|
1686 | - |
|
1687 | - return array( |
|
1688 | - 'amount' => $payment->amount(), |
|
1689 | - 'total_paid' => $payment->transaction()->paid(), |
|
1690 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
1691 | - 'pay_status' => $payment->STS_ID(), |
|
1692 | - 'PAY_ID' => $payment->ID(), |
|
1693 | - 'STS_ID' => $payment->STS_ID(), |
|
1694 | - 'status' => self::$_pay_status[$payment->STS_ID()], |
|
1695 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
1696 | - 'method' => strtoupper($payment->source()), |
|
1697 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
1698 | - 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", |
|
1699 | - 'event_espresso'), |
|
1700 | - 'gateway_response' => $payment->gateway_response(), |
|
1701 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
1702 | - 'po_number' => $payment->po_number(), |
|
1703 | - 'extra_accntng' => $payment->extra_accntng(), |
|
1704 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
1705 | - ); |
|
1706 | - } |
|
1707 | - } |
|
1708 | - |
|
1709 | - |
|
1710 | - /** |
|
1711 | - * delete_payment |
|
1712 | - * delete a payment or refund made towards a transaction |
|
1713 | - * |
|
1714 | - * @access public |
|
1715 | - * @return void |
|
1716 | - */ |
|
1717 | - public function delete_payment() |
|
1718 | - { |
|
1719 | - $json_response_data = array('return_data' => false); |
|
1720 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0; |
|
1721 | - if ($PAY_ID) { |
|
1722 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false; |
|
1723 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
1724 | - if ($payment instanceof EE_Payment) { |
|
1725 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1726 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
1727 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1728 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
1729 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs, |
|
1730 | - $delete_txn_reg_status_change); |
|
1731 | - if ($delete_txn_reg_status_change) { |
|
1732 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
1733 | - //MAKE sure we also add the delete_txn_req_status_change to the |
|
1734 | - //$_REQUEST global because that's how messages will be looking for it. |
|
1735 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
1736 | - $this->_maybe_send_notifications(); |
|
1737 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
1738 | - } |
|
1739 | - } |
|
1740 | - } else { |
|
1741 | - EE_Error::add_error( |
|
1742 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
1743 | - __FILE__, __FUNCTION__, __LINE__ |
|
1744 | - ); |
|
1745 | - } |
|
1746 | - } else { |
|
1747 | - EE_Error::add_error( |
|
1748 | - esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
1749 | - 'event_espresso'), |
|
1750 | - __FILE__, __FUNCTION__, __LINE__ |
|
1751 | - ); |
|
1752 | - } |
|
1753 | - $notices = EE_Error::get_notices(false, false, false); |
|
1754 | - $this->_template_args = array( |
|
1755 | - 'data' => $json_response_data, |
|
1756 | - 'success' => $notices['success'], |
|
1757 | - 'error' => $notices['errors'], |
|
1758 | - 'attention' => $notices['attention'], |
|
1759 | - ); |
|
1760 | - $this->_return_json(); |
|
1761 | - } |
|
1762 | - |
|
1763 | - |
|
1764 | - /** |
|
1765 | - * _registration_payment_data_array |
|
1766 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
1767 | - * |
|
1768 | - * @access protected |
|
1769 | - * @param array $REG_IDs |
|
1770 | - * @return array |
|
1771 | - */ |
|
1772 | - protected function _registration_payment_data_array($REG_IDs) |
|
1773 | - { |
|
1774 | - $registration_payment_data = array(); |
|
1775 | - //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
1776 | - if (! empty($REG_IDs)) { |
|
1777 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
1778 | - foreach ($registrations as $registration) { |
|
1779 | - if ($registration instanceof EE_Registration) { |
|
1780 | - $registration_payment_data[$registration->ID()] = array( |
|
1781 | - 'paid' => $registration->pretty_paid(), |
|
1782 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
1783 | - ); |
|
1784 | - } |
|
1785 | - } |
|
1786 | - } |
|
1787 | - |
|
1788 | - return $registration_payment_data; |
|
1789 | - } |
|
1790 | - |
|
1791 | - |
|
1792 | - /** |
|
1793 | - * _maybe_send_notifications |
|
1794 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
1795 | - * If so, will toggle a filter switch for delivering registration notices. |
|
1796 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
1797 | - * |
|
1798 | - * @access protected |
|
1799 | - * @param \EE_Payment | null $payment |
|
1800 | - */ |
|
1801 | - protected function _maybe_send_notifications($payment = null) |
|
1802 | - { |
|
1803 | - switch ($payment instanceof EE_Payment) { |
|
1804 | - // payment notifications |
|
1805 | - case true : |
|
1806 | - if ( |
|
1807 | - isset( |
|
1808 | - $this->_req_data['txn_payments'], |
|
1809 | - $this->_req_data['txn_payments']['send_notifications'] |
|
1810 | - ) && |
|
1811 | - filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
1812 | - ) { |
|
1813 | - $this->_process_payment_notification($payment); |
|
1814 | - } |
|
1815 | - break; |
|
1816 | - // registration notifications |
|
1817 | - case false : |
|
1818 | - if ( |
|
1819 | - isset( |
|
1820 | - $this->_req_data['txn_reg_status_change'], |
|
1821 | - $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
1822 | - ) && |
|
1823 | - filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
1824 | - ) { |
|
1825 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
1826 | - } |
|
1827 | - break; |
|
1828 | - } |
|
1829 | - } |
|
1830 | - |
|
1831 | - |
|
1832 | - /** |
|
1833 | - * _send_payment_reminder |
|
1834 | - * generates HTML for the View Transaction Details Admin page |
|
1835 | - * |
|
1836 | - * @access protected |
|
1837 | - * @return void |
|
1838 | - */ |
|
1839 | - protected function _send_payment_reminder() |
|
1840 | - { |
|
1841 | - $TXN_ID = (! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
1842 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
1843 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
1844 | - 'action' => $this->_req_data['redirect_to'], |
|
1845 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
1846 | - ) : array(); |
|
1847 | - do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
1848 | - $transaction); |
|
1849 | - $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'), |
|
1850 | - esc_html__('sent', 'event_espresso'), $query_args, true); |
|
1851 | - } |
|
1852 | - |
|
1853 | - |
|
1854 | - /** |
|
1855 | - * get_transactions |
|
1856 | - * get transactions for given parameters (used by list table) |
|
1857 | - * |
|
1858 | - * @param int $perpage how many transactions displayed per page |
|
1859 | - * @param boolean $count return the count or objects |
|
1860 | - * @param string $view |
|
1861 | - * @return mixed int = count || array of transaction objects |
|
1862 | - */ |
|
1863 | - public function get_transactions($perpage, $count = false, $view = '') |
|
1864 | - { |
|
1865 | - |
|
1866 | - $TXN = EEM_Transaction::instance(); |
|
1867 | - |
|
1868 | - $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', |
|
1869 | - strtotime('-10 year')); |
|
1870 | - $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
|
1871 | - |
|
1872 | - //make sure our timestamps start and end right at the boundaries for each day |
|
1873 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
1874 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
1875 | - |
|
1876 | - |
|
1877 | - //convert to timestamps |
|
1878 | - $start_date = strtotime($start_date); |
|
1879 | - $end_date = strtotime($end_date); |
|
1880 | - |
|
1881 | - //makes sure start date is the lowest value and vice versa |
|
1882 | - $start_date = min($start_date, $end_date); |
|
1883 | - $end_date = max($start_date, $end_date); |
|
1884 | - |
|
1885 | - //convert to correct format for query |
|
1886 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
1887 | - date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); |
|
1888 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
1889 | - date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); |
|
1890 | - |
|
1891 | - |
|
1892 | - //set orderby |
|
1893 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
1894 | - |
|
1895 | - switch ($this->_req_data['orderby']) { |
|
1896 | - case 'TXN_ID': |
|
1897 | - $orderby = 'TXN_ID'; |
|
1898 | - break; |
|
1899 | - case 'ATT_fname': |
|
1900 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
1901 | - break; |
|
1902 | - case 'event_name': |
|
1903 | - $orderby = 'Registration.Event.EVT_name'; |
|
1904 | - break; |
|
1905 | - default: //'TXN_timestamp' |
|
1906 | - $orderby = 'TXN_timestamp'; |
|
1907 | - } |
|
1908 | - |
|
1909 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; |
|
1910 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
1911 | - $per_page = isset($perpage) && ! empty($perpage) ? $perpage : 10; |
|
1912 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
1913 | - |
|
1914 | - $offset = ($current_page - 1) * $per_page; |
|
1915 | - $limit = array($offset, $per_page); |
|
1916 | - |
|
1917 | - $_where = array( |
|
1918 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
1919 | - 'Registration.REG_count' => 1, |
|
1920 | - ); |
|
1921 | - |
|
1922 | - if (isset($this->_req_data['EVT_ID'])) { |
|
1923 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
1924 | - } |
|
1925 | - |
|
1926 | - if (isset($this->_req_data['s'])) { |
|
1927 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1928 | - $_where['OR'] = array( |
|
1929 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
1930 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
1931 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
1932 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
1933 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
1934 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
1935 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
1936 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
1937 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
1938 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
1939 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
1940 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
1941 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
1942 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
1943 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
1944 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
1945 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
1946 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
1947 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
1948 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
1949 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
1950 | - ); |
|
1951 | - } |
|
1952 | - |
|
1953 | - //failed transactions |
|
1954 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; |
|
1955 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; |
|
1956 | - |
|
1957 | - if ($failed) { |
|
1958 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
1959 | - } else if ($abandoned) { |
|
1960 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
1961 | - } else { |
|
1962 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
1963 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
1964 | - } |
|
1965 | - |
|
1966 | - $query_params = array( |
|
1967 | - $_where, |
|
1968 | - 'order_by' => array($orderby => $sort), |
|
1969 | - 'limit' => $limit, |
|
1970 | - 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
1971 | - ); |
|
1972 | - |
|
1973 | - $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params); |
|
1974 | - |
|
1975 | - |
|
1976 | - return $transactions; |
|
1977 | - |
|
1978 | - } |
|
804 | + // process payment details |
|
805 | + $payments = $this->_transaction->get_many_related('Payment'); |
|
806 | + if (! empty($payments)) { |
|
807 | + $this->_template_args['payments'] = $payments; |
|
808 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
809 | + } else { |
|
810 | + $this->_template_args['payments'] = false; |
|
811 | + $this->_template_args['existing_reg_payments'] = array(); |
|
812 | + } |
|
813 | + |
|
814 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
815 | + $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'), |
|
816 | + TXN_ADMIN_URL); |
|
817 | + |
|
818 | + if (isset($txn_details['invoice_number'])) { |
|
819 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
820 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number', |
|
821 | + 'event_espresso'); |
|
822 | + } |
|
823 | + |
|
824 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); |
|
825 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session', |
|
826 | + 'event_espresso'); |
|
827 | + |
|
828 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : ''; |
|
829 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP', |
|
830 | + 'event_espresso'); |
|
831 | + |
|
832 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : ''; |
|
833 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
834 | + 'event_espresso'); |
|
835 | + |
|
836 | + $reg_steps = '<ul>'; |
|
837 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
838 | + if ($reg_step_status === true) { |
|
839 | + $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
840 | + ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
841 | + } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
842 | + $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
843 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
844 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
845 | + date(get_option('date_format') . ' ' . get_option('time_format'), |
|
846 | + ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
|
847 | + ) . '</li>'; |
|
848 | + } else { |
|
849 | + $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', |
|
850 | + 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
851 | + } |
|
852 | + } |
|
853 | + $reg_steps .= '</ul>'; |
|
854 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
855 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress', |
|
856 | + 'event_espresso'); |
|
857 | + |
|
858 | + |
|
859 | + $this->_get_registrations_to_apply_payment_to(); |
|
860 | + $this->_get_payment_methods($payments); |
|
861 | + $this->_get_payment_status_array(); |
|
862 | + $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
863 | + |
|
864 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
865 | + 'action' => 'edit_transaction', |
|
866 | + 'process' => 'transaction', |
|
867 | + ), TXN_ADMIN_URL); |
|
868 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
869 | + 'page' => 'espresso_transactions', |
|
870 | + 'action' => 'espresso_apply_payment', |
|
871 | + ), WP_AJAX_URL); |
|
872 | + $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
873 | + 'page' => 'espresso_transactions', |
|
874 | + 'action' => 'espresso_delete_payment', |
|
875 | + ), WP_AJAX_URL); |
|
876 | + |
|
877 | + // 'espresso_delete_payment_nonce' |
|
878 | + |
|
879 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
880 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
881 | + |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + /** |
|
886 | + * _get_registration_payment_IDs |
|
887 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
888 | + * |
|
889 | + * @access protected |
|
890 | + * @param EE_Payment[] $payments |
|
891 | + * @return array |
|
892 | + */ |
|
893 | + protected function _get_registration_payment_IDs($payments = array()) |
|
894 | + { |
|
895 | + $existing_reg_payments = array(); |
|
896 | + // get all reg payments for these payments |
|
897 | + $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
898 | + array( |
|
899 | + 'PAY_ID' => array( |
|
900 | + 'IN', |
|
901 | + array_keys($payments), |
|
902 | + ), |
|
903 | + ), |
|
904 | + )); |
|
905 | + if (! empty($reg_payments)) { |
|
906 | + foreach ($payments as $payment) { |
|
907 | + if (! $payment instanceof EE_Payment) { |
|
908 | + continue; |
|
909 | + } else if (! isset($existing_reg_payments[$payment->ID()])) { |
|
910 | + $existing_reg_payments[$payment->ID()] = array(); |
|
911 | + } |
|
912 | + foreach ($reg_payments as $reg_payment) { |
|
913 | + if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) { |
|
914 | + $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
915 | + } |
|
916 | + } |
|
917 | + } |
|
918 | + } |
|
919 | + |
|
920 | + return $existing_reg_payments; |
|
921 | + } |
|
922 | + |
|
923 | + |
|
924 | + /** |
|
925 | + * _get_registrations_to_apply_payment_to |
|
926 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
927 | + * which allows the admin to only apply the payment to the specific registrations |
|
928 | + * |
|
929 | + * @access protected |
|
930 | + * @return void |
|
931 | + * @throws \EE_Error |
|
932 | + */ |
|
933 | + protected function _get_registrations_to_apply_payment_to() |
|
934 | + { |
|
935 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
936 | + $query_params = array( |
|
937 | + array( |
|
938 | + 'STS_ID' => array( |
|
939 | + 'IN', |
|
940 | + array( |
|
941 | + EEM_Registration::status_id_approved, |
|
942 | + EEM_Registration::status_id_pending_payment, |
|
943 | + EEM_Registration::status_id_not_approved, |
|
944 | + ), |
|
945 | + ), |
|
946 | + ), |
|
947 | + ); |
|
948 | + $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
949 | + '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' |
|
950 | + ); |
|
951 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
952 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
953 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
954 | + EEH_HTML::tr( |
|
955 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
956 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
957 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
958 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
959 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
960 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
961 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
962 | + ) |
|
963 | + ); |
|
964 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
965 | + // get registrations for TXN |
|
966 | + $registrations = $this->_transaction->registrations($query_params); |
|
967 | + foreach ($registrations as $registration) { |
|
968 | + if ($registration instanceof EE_Registration) { |
|
969 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
970 | + ? $registration->attendee()->full_name() |
|
971 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
972 | + $owing = $registration->final_price() - $registration->paid(); |
|
973 | + $taxable = $registration->ticket()->taxable() |
|
974 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
975 | + : ''; |
|
976 | + $checked = empty($existing_reg_payments) || in_array($registration->ID(), |
|
977 | + $existing_reg_payments) |
|
978 | + ? ' checked="checked"' |
|
979 | + : ''; |
|
980 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
981 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
982 | + EEH_HTML::td($registration->ID()) . |
|
983 | + EEH_HTML::td($attendee_name) . |
|
984 | + EEH_HTML::td( |
|
985 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
986 | + ) . |
|
987 | + EEH_HTML::td($registration->event_name()) . |
|
988 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
989 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
990 | + EEH_HTML::td( |
|
991 | + '<input type="checkbox" value="' . $registration->ID() |
|
992 | + . '" name="txn_admin_payment[registrations]"' |
|
993 | + . $checked . $disabled . '>', |
|
994 | + '', 'jst-cntr' |
|
995 | + ), |
|
996 | + 'apply-payment-registration-row-' . $registration->ID() |
|
997 | + ); |
|
998 | + } |
|
999 | + } |
|
1000 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
1001 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
1002 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1003 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
1004 | + esc_html__( |
|
1005 | + 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
1006 | + 'event_espresso' |
|
1007 | + ), |
|
1008 | + '', 'clear description' |
|
1009 | + ); |
|
1010 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1011 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
1012 | + } |
|
1013 | + |
|
1014 | + |
|
1015 | + /** |
|
1016 | + * _get_reg_status_selection |
|
1017 | + * |
|
1018 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
1019 | + * instead of events. |
|
1020 | + * @access protected |
|
1021 | + * @return void |
|
1022 | + */ |
|
1023 | + protected function _get_reg_status_selection() |
|
1024 | + { |
|
1025 | + //first get all possible statuses |
|
1026 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
1027 | + //let's add a "don't change" option. |
|
1028 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
1029 | + $status_array = array_merge($status_array, $statuses); |
|
1030 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]', |
|
1031 | + $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status'); |
|
1032 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]', |
|
1033 | + $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status'); |
|
1034 | + |
|
1035 | + } |
|
1036 | + |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * _get_payment_methods |
|
1040 | + * Gets all the payment methods available generally, or the ones that are already |
|
1041 | + * selected on these payments (in case their payment methods are no longer active). |
|
1042 | + * Has the side-effect of updating the template args' payment_methods item |
|
1043 | + * |
|
1044 | + * @access private |
|
1045 | + * @param EE_Payment[] to show on this page |
|
1046 | + * @return void |
|
1047 | + */ |
|
1048 | + private function _get_payment_methods($payments = array()) |
|
1049 | + { |
|
1050 | + $payment_methods_of_payments = array(); |
|
1051 | + foreach ($payments as $payment) { |
|
1052 | + if ($payment instanceof EE_Payment) { |
|
1053 | + $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
1054 | + } |
|
1055 | + } |
|
1056 | + if ($payment_methods_of_payments) { |
|
1057 | + $query_args = array( |
|
1058 | + array( |
|
1059 | + 'OR*payment_method_for_payment' => array( |
|
1060 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
1061 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
1062 | + ), |
|
1063 | + ), |
|
1064 | + ); |
|
1065 | + } else { |
|
1066 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
1067 | + } |
|
1068 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
1069 | + } |
|
1070 | + |
|
1071 | + |
|
1072 | + /** |
|
1073 | + * txn_attendees_meta_box |
|
1074 | + * generates HTML for the Attendees Transaction main meta box |
|
1075 | + * |
|
1076 | + * @access public |
|
1077 | + * @param WP_Post $post |
|
1078 | + * @param array $metabox |
|
1079 | + * @return void |
|
1080 | + */ |
|
1081 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
1082 | + { |
|
1083 | + |
|
1084 | + extract($metabox['args']); |
|
1085 | + $this->_template_args['post'] = $post; |
|
1086 | + $this->_template_args['event_attendees'] = array(); |
|
1087 | + // process items in cart |
|
1088 | + $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); |
|
1089 | + if (! empty($line_items)) { |
|
1090 | + foreach ($line_items as $item) { |
|
1091 | + if ($item instanceof EE_Line_Item) { |
|
1092 | + switch ($item->OBJ_type()) { |
|
1093 | + |
|
1094 | + case 'Event' : |
|
1095 | + break; |
|
1096 | + |
|
1097 | + case 'Ticket' : |
|
1098 | + $ticket = $item->ticket(); |
|
1099 | + //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? |
|
1100 | + if (! $ticket instanceof EE_Ticket) { |
|
1101 | + continue; |
|
1102 | + } |
|
1103 | + try { |
|
1104 | + $event_name = $ticket->get_event_name(); |
|
1105 | + } catch (Exception $e) { |
|
1106 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1107 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
1108 | + } |
|
1109 | + $event_name .= ' - ' . $item->get('LIN_name'); |
|
1110 | + $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
1111 | + // now get all of the registrations for this transaction that use this ticket |
|
1112 | + $registrations = $ticket->get_many_related('Registration', |
|
1113 | + array(array('TXN_ID' => $this->_transaction->ID()))); |
|
1114 | + foreach ($registrations as $registration) { |
|
1115 | + if (! $registration instanceof EE_Registration) { |
|
1116 | + continue; |
|
1117 | + } |
|
1118 | + $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] = $registration->status_ID(); |
|
1119 | + $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->count(); |
|
1120 | + $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; |
|
1121 | + $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; |
|
1122 | + // attendee info |
|
1123 | + $attendee = $registration->get_first_related('Attendee'); |
|
1124 | + if ($attendee instanceof EE_Attendee) { |
|
1125 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
|
1126 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
|
1127 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', |
|
1128 | + 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
1129 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, |
|
1130 | + 'inline', false, false); |
|
1131 | + } else { |
|
1132 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
1133 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
1134 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
1135 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
1136 | + } |
|
1137 | + } |
|
1138 | + break; |
|
1139 | + |
|
1140 | + } |
|
1141 | + } |
|
1142 | + } |
|
1143 | + |
|
1144 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
1145 | + 'action' => 'edit_transaction', |
|
1146 | + 'process' => 'attendees', |
|
1147 | + ), TXN_ADMIN_URL); |
|
1148 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
1149 | + $this->_template_args, true); |
|
1150 | + |
|
1151 | + } else { |
|
1152 | + echo sprintf( |
|
1153 | + esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
1154 | + 'event_espresso'), |
|
1155 | + '<p class="important-notice">', |
|
1156 | + '</p>' |
|
1157 | + ); |
|
1158 | + } |
|
1159 | + } |
|
1160 | + |
|
1161 | + |
|
1162 | + /** |
|
1163 | + * txn_registrant_side_meta_box |
|
1164 | + * generates HTML for the Edit Transaction side meta box |
|
1165 | + * |
|
1166 | + * @access public |
|
1167 | + * @throws \EE_Error |
|
1168 | + * @return void |
|
1169 | + */ |
|
1170 | + public function txn_registrant_side_meta_box() |
|
1171 | + { |
|
1172 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; |
|
1173 | + if (! $primary_att instanceof EE_Attendee) { |
|
1174 | + $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
1175 | + 'event_espresso'); |
|
1176 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
1177 | + } |
|
1178 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
1179 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
1180 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
1181 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
1182 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
1183 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1184 | + 'action' => 'edit_attendee', |
|
1185 | + 'post' => $primary_att->ID(), |
|
1186 | + ), REG_ADMIN_URL); |
|
1187 | + // get formatted address for registrant |
|
1188 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
1189 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
1190 | + $this->_template_args, true); |
|
1191 | + } |
|
1192 | + |
|
1193 | + |
|
1194 | + /** |
|
1195 | + * txn_billing_info_side_meta_box |
|
1196 | + * generates HTML for the Edit Transaction side meta box |
|
1197 | + * |
|
1198 | + * @access public |
|
1199 | + * @return void |
|
1200 | + */ |
|
1201 | + public function txn_billing_info_side_meta_box() |
|
1202 | + { |
|
1203 | + |
|
1204 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
1205 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
1206 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
1207 | + TXN_ADMIN_URL |
|
1208 | + ); |
|
1209 | + |
|
1210 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
1211 | + echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
1212 | + } |
|
1213 | + |
|
1214 | + |
|
1215 | + /** |
|
1216 | + * apply_payments_or_refunds |
|
1217 | + * registers a payment or refund made towards a transaction |
|
1218 | + * |
|
1219 | + * @access public |
|
1220 | + * @return void |
|
1221 | + */ |
|
1222 | + public function apply_payments_or_refunds() |
|
1223 | + { |
|
1224 | + $json_response_data = array('return_data' => false); |
|
1225 | + $valid_data = $this->_validate_payment_request_data(); |
|
1226 | + if (! empty($valid_data) |
|
1227 | + |
|
1228 | + ) { |
|
1229 | + $PAY_ID = $valid_data['PAY_ID']; |
|
1230 | + //save the new payment |
|
1231 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
1232 | + // get the TXN for this payment |
|
1233 | + $transaction = $payment->transaction(); |
|
1234 | + // verify transaction |
|
1235 | + if ($transaction instanceof EE_Transaction) { |
|
1236 | + // calculate_total_payments_and_update_status |
|
1237 | + $this->_process_transaction_payments($transaction); |
|
1238 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
1239 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
1240 | + // apply payment to registrations (if applicable) |
|
1241 | + if (! empty($REG_IDs)) { |
|
1242 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
1243 | + $this->_maybe_send_notifications(); |
|
1244 | + // now process status changes for the same registrations |
|
1245 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
1246 | + } |
|
1247 | + $this->_maybe_send_notifications($payment); |
|
1248 | + //prepare to render page |
|
1249 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
1250 | + do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, |
|
1251 | + $payment); |
|
1252 | + } else { |
|
1253 | + EE_Error::add_error( |
|
1254 | + esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'), |
|
1255 | + __FILE__, __FUNCTION__, __LINE__ |
|
1256 | + ); |
|
1257 | + } |
|
1258 | + } else { |
|
1259 | + EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.', |
|
1260 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1261 | + } |
|
1262 | + |
|
1263 | + $notices = EE_Error::get_notices(false, false, false); |
|
1264 | + $this->_template_args = array( |
|
1265 | + 'data' => $json_response_data, |
|
1266 | + 'error' => $notices['errors'], |
|
1267 | + 'success' => $notices['success'], |
|
1268 | + ); |
|
1269 | + $this->_return_json(); |
|
1270 | + } |
|
1271 | + |
|
1272 | + |
|
1273 | + /** |
|
1274 | + * _validate_payment_request_data |
|
1275 | + * |
|
1276 | + * @return array |
|
1277 | + */ |
|
1278 | + protected function _validate_payment_request_data() |
|
1279 | + { |
|
1280 | + if (! isset($this->_req_data['txn_admin_payment'])) { |
|
1281 | + return false; |
|
1282 | + } |
|
1283 | + $payment_form = $this->_generate_payment_form_section(); |
|
1284 | + try { |
|
1285 | + if ($payment_form->was_submitted()) { |
|
1286 | + $payment_form->receive_form_submission(); |
|
1287 | + if (! $payment_form->is_valid()) { |
|
1288 | + $submission_error_messages = array(); |
|
1289 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
1290 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1291 | + $submission_error_messages[] = sprintf( |
|
1292 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
1293 | + $validation_error->get_form_section()->html_label_text(), |
|
1294 | + $validation_error->getMessage() |
|
1295 | + ); |
|
1296 | + } |
|
1297 | + } |
|
1298 | + EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
1299 | + |
|
1300 | + return array(); |
|
1301 | + } |
|
1302 | + } |
|
1303 | + } catch (EE_Error $e) { |
|
1304 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1305 | + |
|
1306 | + return array(); |
|
1307 | + } |
|
1308 | + |
|
1309 | + return $payment_form->valid_data(); |
|
1310 | + } |
|
1311 | + |
|
1312 | + |
|
1313 | + /** |
|
1314 | + * _generate_payment_form_section |
|
1315 | + * |
|
1316 | + * @return EE_Form_Section_Proper |
|
1317 | + */ |
|
1318 | + protected function _generate_payment_form_section() |
|
1319 | + { |
|
1320 | + return new EE_Form_Section_Proper( |
|
1321 | + array( |
|
1322 | + 'name' => 'txn_admin_payment', |
|
1323 | + 'subsections' => array( |
|
1324 | + 'PAY_ID' => new EE_Text_Input( |
|
1325 | + array( |
|
1326 | + 'default' => 0, |
|
1327 | + 'required' => false, |
|
1328 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
1329 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1330 | + ) |
|
1331 | + ), |
|
1332 | + 'TXN_ID' => new EE_Text_Input( |
|
1333 | + array( |
|
1334 | + 'default' => 0, |
|
1335 | + 'required' => true, |
|
1336 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
1337 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1338 | + ) |
|
1339 | + ), |
|
1340 | + 'type' => new EE_Text_Input( |
|
1341 | + array( |
|
1342 | + 'default' => 1, |
|
1343 | + 'required' => true, |
|
1344 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
1345 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1346 | + ) |
|
1347 | + ), |
|
1348 | + 'amount' => new EE_Text_Input( |
|
1349 | + array( |
|
1350 | + 'default' => 0, |
|
1351 | + 'required' => true, |
|
1352 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
1353 | + 'validation_strategies' => array(new EE_Float_Normalization()), |
|
1354 | + ) |
|
1355 | + ), |
|
1356 | + 'status' => new EE_Text_Input( |
|
1357 | + array( |
|
1358 | + 'default' => EEM_Payment::status_id_approved, |
|
1359 | + 'required' => true, |
|
1360 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
1361 | + ) |
|
1362 | + ), |
|
1363 | + 'PMD_ID' => new EE_Text_Input( |
|
1364 | + array( |
|
1365 | + 'default' => 2, |
|
1366 | + 'required' => true, |
|
1367 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
1368 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1369 | + ) |
|
1370 | + ), |
|
1371 | + 'date' => new EE_Text_Input( |
|
1372 | + array( |
|
1373 | + 'default' => time(), |
|
1374 | + 'required' => true, |
|
1375 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
1376 | + ) |
|
1377 | + ), |
|
1378 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
1379 | + array( |
|
1380 | + 'default' => '', |
|
1381 | + 'required' => false, |
|
1382 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
1383 | + 'validation_strategies' => array( |
|
1384 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
1385 | + 100), |
|
1386 | + ), |
|
1387 | + ) |
|
1388 | + ), |
|
1389 | + 'po_number' => new EE_Text_Input( |
|
1390 | + array( |
|
1391 | + 'default' => '', |
|
1392 | + 'required' => false, |
|
1393 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
1394 | + 'validation_strategies' => array( |
|
1395 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
1396 | + 100), |
|
1397 | + ), |
|
1398 | + ) |
|
1399 | + ), |
|
1400 | + 'accounting' => new EE_Text_Input( |
|
1401 | + array( |
|
1402 | + 'default' => '', |
|
1403 | + 'required' => false, |
|
1404 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
1405 | + 'validation_strategies' => array( |
|
1406 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
1407 | + 100), |
|
1408 | + ), |
|
1409 | + ) |
|
1410 | + ), |
|
1411 | + ), |
|
1412 | + ) |
|
1413 | + ); |
|
1414 | + } |
|
1415 | + |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * _create_payment_from_request_data |
|
1419 | + * |
|
1420 | + * @param array $valid_data |
|
1421 | + * @return EE_Payment |
|
1422 | + */ |
|
1423 | + protected function _create_payment_from_request_data($valid_data) |
|
1424 | + { |
|
1425 | + $PAY_ID = $valid_data['PAY_ID']; |
|
1426 | + // get payment amount |
|
1427 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
1428 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
1429 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
1430 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
1431 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
1432 | + $date = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a', |
|
1433 | + current_time('timestamp')); |
|
1434 | + $payment = EE_Payment::new_instance( |
|
1435 | + array( |
|
1436 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
1437 | + 'STS_ID' => $valid_data['status'], |
|
1438 | + 'PAY_timestamp' => $date, |
|
1439 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
1440 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
1441 | + 'PAY_amount' => $amount, |
|
1442 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
1443 | + 'PAY_po_number' => $valid_data['po_number'], |
|
1444 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
1445 | + 'PAY_details' => $valid_data, |
|
1446 | + 'PAY_ID' => $PAY_ID, |
|
1447 | + ), |
|
1448 | + '', |
|
1449 | + array('Y-m-d', 'g:i a') |
|
1450 | + ); |
|
1451 | + |
|
1452 | + if (! $payment->save()) { |
|
1453 | + EE_Error::add_error( |
|
1454 | + sprintf( |
|
1455 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
1456 | + $payment->ID() |
|
1457 | + ), |
|
1458 | + __FILE__, __FUNCTION__, __LINE__ |
|
1459 | + ); |
|
1460 | + } |
|
1461 | + |
|
1462 | + return $payment; |
|
1463 | + } |
|
1464 | + |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * _process_transaction_payments |
|
1468 | + * |
|
1469 | + * @param \EE_Transaction $transaction |
|
1470 | + * @return array |
|
1471 | + */ |
|
1472 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
1473 | + { |
|
1474 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
1475 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1476 | + //update the transaction with this payment |
|
1477 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
1478 | + EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'), |
|
1479 | + __FILE__, __FUNCTION__, __LINE__); |
|
1480 | + } else { |
|
1481 | + EE_Error::add_error( |
|
1482 | + esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
1483 | + 'event_espresso') |
|
1484 | + , __FILE__, __FUNCTION__, __LINE__ |
|
1485 | + ); |
|
1486 | + } |
|
1487 | + } |
|
1488 | + |
|
1489 | + |
|
1490 | + /** |
|
1491 | + * _get_REG_IDs_to_apply_payment_to |
|
1492 | + * returns a list of registration IDs that the payment will apply to |
|
1493 | + * |
|
1494 | + * @param \EE_Payment $payment |
|
1495 | + * @return array |
|
1496 | + */ |
|
1497 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
1498 | + { |
|
1499 | + $REG_IDs = array(); |
|
1500 | + // grab array of IDs for specific registrations to apply changes to |
|
1501 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
1502 | + $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
1503 | + } |
|
1504 | + //nothing specified ? then get all reg IDs |
|
1505 | + if (empty($REG_IDs)) { |
|
1506 | + $registrations = $payment->transaction()->registrations(); |
|
1507 | + $REG_IDs = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1508 | + } |
|
1509 | + |
|
1510 | + // ensure that REG_IDs are integers and NOT strings |
|
1511 | + return array_map('intval', $REG_IDs); |
|
1512 | + } |
|
1513 | + |
|
1514 | + |
|
1515 | + /** |
|
1516 | + * @return array |
|
1517 | + */ |
|
1518 | + public function existing_reg_payment_REG_IDs() |
|
1519 | + { |
|
1520 | + return $this->_existing_reg_payment_REG_IDs; |
|
1521 | + } |
|
1522 | + |
|
1523 | + |
|
1524 | + /** |
|
1525 | + * @param array $existing_reg_payment_REG_IDs |
|
1526 | + */ |
|
1527 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
1528 | + { |
|
1529 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
1530 | + } |
|
1531 | + |
|
1532 | + |
|
1533 | + /** |
|
1534 | + * _get_existing_reg_payment_REG_IDs |
|
1535 | + * returns a list of registration IDs that the payment is currently related to |
|
1536 | + * as recorded in the database |
|
1537 | + * |
|
1538 | + * @param \EE_Payment $payment |
|
1539 | + * @return array |
|
1540 | + */ |
|
1541 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
1542 | + { |
|
1543 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
1544 | + // let's get any existing reg payment records for this payment |
|
1545 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
1546 | + // but we only want the REG IDs, so grab the array keys |
|
1547 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array(); |
|
1548 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
1549 | + } |
|
1550 | + |
|
1551 | + return $this->existing_reg_payment_REG_IDs(); |
|
1552 | + } |
|
1553 | + |
|
1554 | + |
|
1555 | + /** |
|
1556 | + * _remove_existing_registration_payments |
|
1557 | + * this calculates the difference between existing relations |
|
1558 | + * to the supplied payment and the new list registration IDs, |
|
1559 | + * removes any related registrations that no longer apply, |
|
1560 | + * and then updates the registration paid fields |
|
1561 | + * |
|
1562 | + * @param \EE_Payment $payment |
|
1563 | + * @param int $PAY_ID |
|
1564 | + * @return bool; |
|
1565 | + */ |
|
1566 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
1567 | + { |
|
1568 | + // newly created payments will have nothing recorded for $PAY_ID |
|
1569 | + if ($PAY_ID == 0) { |
|
1570 | + return false; |
|
1571 | + } |
|
1572 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1573 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
1574 | + return false; |
|
1575 | + } |
|
1576 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
1577 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1578 | + |
|
1579 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
1580 | + $payment, |
|
1581 | + array( |
|
1582 | + array( |
|
1583 | + 'PAY_ID' => $payment->ID(), |
|
1584 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
1585 | + ), |
|
1586 | + ) |
|
1587 | + ); |
|
1588 | + } |
|
1589 | + |
|
1590 | + |
|
1591 | + /** |
|
1592 | + * _update_registration_payments |
|
1593 | + * this applies the payments to the selected registrations |
|
1594 | + * but only if they have not already been paid for |
|
1595 | + * |
|
1596 | + * @param EE_Transaction $transaction |
|
1597 | + * @param \EE_Payment $payment |
|
1598 | + * @param array $REG_IDs |
|
1599 | + * @return bool |
|
1600 | + */ |
|
1601 | + protected function _update_registration_payments( |
|
1602 | + EE_Transaction $transaction, |
|
1603 | + EE_Payment $payment, |
|
1604 | + $REG_IDs = array() |
|
1605 | + ) { |
|
1606 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
1607 | + // so let's do that using our set of REG_IDs from the form |
|
1608 | + $registration_query_where_params = array( |
|
1609 | + 'REG_ID' => array('IN', $REG_IDs), |
|
1610 | + ); |
|
1611 | + // but add in some conditions regarding payment, |
|
1612 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
1613 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
1614 | + if (! $payment->is_a_refund()) { |
|
1615 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
1616 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
1617 | + } |
|
1618 | + //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); |
|
1619 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
1620 | + if (! empty($registrations)) { |
|
1621 | + /** @type EE_Payment_Processor $payment_processor */ |
|
1622 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
1623 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
1624 | + } |
|
1625 | + } |
|
1626 | + |
|
1627 | + |
|
1628 | + /** |
|
1629 | + * _process_registration_status_change |
|
1630 | + * This processes requested registration status changes for all the registrations |
|
1631 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
1632 | + * |
|
1633 | + * @param EE_Transaction $transaction |
|
1634 | + * @param array $REG_IDs |
|
1635 | + * @return bool |
|
1636 | + */ |
|
1637 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
1638 | + { |
|
1639 | + // first if there is no change in status then we get out. |
|
1640 | + if ( |
|
1641 | + ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status']) |
|
1642 | + || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' |
|
1643 | + ) { |
|
1644 | + //no error message, no change requested, just nothing to do man. |
|
1645 | + return false; |
|
1646 | + } |
|
1647 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
1648 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
1649 | + |
|
1650 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
1651 | + return $transaction_processor->manually_update_registration_statuses( |
|
1652 | + $transaction, |
|
1653 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
1654 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
1655 | + ); |
|
1656 | + } |
|
1657 | + |
|
1658 | + |
|
1659 | + /** |
|
1660 | + * _build_payment_json_response |
|
1661 | + * |
|
1662 | + * @access public |
|
1663 | + * @param \EE_Payment $payment |
|
1664 | + * @param array $REG_IDs |
|
1665 | + * @param bool | null $delete_txn_reg_status_change |
|
1666 | + * @return array |
|
1667 | + */ |
|
1668 | + protected function _build_payment_json_response( |
|
1669 | + EE_Payment $payment, |
|
1670 | + $REG_IDs = array(), |
|
1671 | + $delete_txn_reg_status_change = null |
|
1672 | + ) { |
|
1673 | + // was the payment deleted ? |
|
1674 | + if (is_bool($delete_txn_reg_status_change)) { |
|
1675 | + return array( |
|
1676 | + 'PAY_ID' => $payment->ID(), |
|
1677 | + 'amount' => $payment->amount(), |
|
1678 | + 'total_paid' => $payment->transaction()->paid(), |
|
1679 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
1680 | + 'pay_status' => $payment->STS_ID(), |
|
1681 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
1682 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
1683 | + ); |
|
1684 | + } else { |
|
1685 | + $this->_get_payment_status_array(); |
|
1686 | + |
|
1687 | + return array( |
|
1688 | + 'amount' => $payment->amount(), |
|
1689 | + 'total_paid' => $payment->transaction()->paid(), |
|
1690 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
1691 | + 'pay_status' => $payment->STS_ID(), |
|
1692 | + 'PAY_ID' => $payment->ID(), |
|
1693 | + 'STS_ID' => $payment->STS_ID(), |
|
1694 | + 'status' => self::$_pay_status[$payment->STS_ID()], |
|
1695 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
1696 | + 'method' => strtoupper($payment->source()), |
|
1697 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
1698 | + 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", |
|
1699 | + 'event_espresso'), |
|
1700 | + 'gateway_response' => $payment->gateway_response(), |
|
1701 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
1702 | + 'po_number' => $payment->po_number(), |
|
1703 | + 'extra_accntng' => $payment->extra_accntng(), |
|
1704 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
1705 | + ); |
|
1706 | + } |
|
1707 | + } |
|
1708 | + |
|
1709 | + |
|
1710 | + /** |
|
1711 | + * delete_payment |
|
1712 | + * delete a payment or refund made towards a transaction |
|
1713 | + * |
|
1714 | + * @access public |
|
1715 | + * @return void |
|
1716 | + */ |
|
1717 | + public function delete_payment() |
|
1718 | + { |
|
1719 | + $json_response_data = array('return_data' => false); |
|
1720 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0; |
|
1721 | + if ($PAY_ID) { |
|
1722 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false; |
|
1723 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
1724 | + if ($payment instanceof EE_Payment) { |
|
1725 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1726 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
1727 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1728 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
1729 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs, |
|
1730 | + $delete_txn_reg_status_change); |
|
1731 | + if ($delete_txn_reg_status_change) { |
|
1732 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
1733 | + //MAKE sure we also add the delete_txn_req_status_change to the |
|
1734 | + //$_REQUEST global because that's how messages will be looking for it. |
|
1735 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
1736 | + $this->_maybe_send_notifications(); |
|
1737 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
1738 | + } |
|
1739 | + } |
|
1740 | + } else { |
|
1741 | + EE_Error::add_error( |
|
1742 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
1743 | + __FILE__, __FUNCTION__, __LINE__ |
|
1744 | + ); |
|
1745 | + } |
|
1746 | + } else { |
|
1747 | + EE_Error::add_error( |
|
1748 | + esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
1749 | + 'event_espresso'), |
|
1750 | + __FILE__, __FUNCTION__, __LINE__ |
|
1751 | + ); |
|
1752 | + } |
|
1753 | + $notices = EE_Error::get_notices(false, false, false); |
|
1754 | + $this->_template_args = array( |
|
1755 | + 'data' => $json_response_data, |
|
1756 | + 'success' => $notices['success'], |
|
1757 | + 'error' => $notices['errors'], |
|
1758 | + 'attention' => $notices['attention'], |
|
1759 | + ); |
|
1760 | + $this->_return_json(); |
|
1761 | + } |
|
1762 | + |
|
1763 | + |
|
1764 | + /** |
|
1765 | + * _registration_payment_data_array |
|
1766 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
1767 | + * |
|
1768 | + * @access protected |
|
1769 | + * @param array $REG_IDs |
|
1770 | + * @return array |
|
1771 | + */ |
|
1772 | + protected function _registration_payment_data_array($REG_IDs) |
|
1773 | + { |
|
1774 | + $registration_payment_data = array(); |
|
1775 | + //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
1776 | + if (! empty($REG_IDs)) { |
|
1777 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
1778 | + foreach ($registrations as $registration) { |
|
1779 | + if ($registration instanceof EE_Registration) { |
|
1780 | + $registration_payment_data[$registration->ID()] = array( |
|
1781 | + 'paid' => $registration->pretty_paid(), |
|
1782 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
1783 | + ); |
|
1784 | + } |
|
1785 | + } |
|
1786 | + } |
|
1787 | + |
|
1788 | + return $registration_payment_data; |
|
1789 | + } |
|
1790 | + |
|
1791 | + |
|
1792 | + /** |
|
1793 | + * _maybe_send_notifications |
|
1794 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
1795 | + * If so, will toggle a filter switch for delivering registration notices. |
|
1796 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
1797 | + * |
|
1798 | + * @access protected |
|
1799 | + * @param \EE_Payment | null $payment |
|
1800 | + */ |
|
1801 | + protected function _maybe_send_notifications($payment = null) |
|
1802 | + { |
|
1803 | + switch ($payment instanceof EE_Payment) { |
|
1804 | + // payment notifications |
|
1805 | + case true : |
|
1806 | + if ( |
|
1807 | + isset( |
|
1808 | + $this->_req_data['txn_payments'], |
|
1809 | + $this->_req_data['txn_payments']['send_notifications'] |
|
1810 | + ) && |
|
1811 | + filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
1812 | + ) { |
|
1813 | + $this->_process_payment_notification($payment); |
|
1814 | + } |
|
1815 | + break; |
|
1816 | + // registration notifications |
|
1817 | + case false : |
|
1818 | + if ( |
|
1819 | + isset( |
|
1820 | + $this->_req_data['txn_reg_status_change'], |
|
1821 | + $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
1822 | + ) && |
|
1823 | + filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
1824 | + ) { |
|
1825 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
1826 | + } |
|
1827 | + break; |
|
1828 | + } |
|
1829 | + } |
|
1830 | + |
|
1831 | + |
|
1832 | + /** |
|
1833 | + * _send_payment_reminder |
|
1834 | + * generates HTML for the View Transaction Details Admin page |
|
1835 | + * |
|
1836 | + * @access protected |
|
1837 | + * @return void |
|
1838 | + */ |
|
1839 | + protected function _send_payment_reminder() |
|
1840 | + { |
|
1841 | + $TXN_ID = (! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
1842 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
1843 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
1844 | + 'action' => $this->_req_data['redirect_to'], |
|
1845 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
1846 | + ) : array(); |
|
1847 | + do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
1848 | + $transaction); |
|
1849 | + $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'), |
|
1850 | + esc_html__('sent', 'event_espresso'), $query_args, true); |
|
1851 | + } |
|
1852 | + |
|
1853 | + |
|
1854 | + /** |
|
1855 | + * get_transactions |
|
1856 | + * get transactions for given parameters (used by list table) |
|
1857 | + * |
|
1858 | + * @param int $perpage how many transactions displayed per page |
|
1859 | + * @param boolean $count return the count or objects |
|
1860 | + * @param string $view |
|
1861 | + * @return mixed int = count || array of transaction objects |
|
1862 | + */ |
|
1863 | + public function get_transactions($perpage, $count = false, $view = '') |
|
1864 | + { |
|
1865 | + |
|
1866 | + $TXN = EEM_Transaction::instance(); |
|
1867 | + |
|
1868 | + $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', |
|
1869 | + strtotime('-10 year')); |
|
1870 | + $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
|
1871 | + |
|
1872 | + //make sure our timestamps start and end right at the boundaries for each day |
|
1873 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
1874 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
1875 | + |
|
1876 | + |
|
1877 | + //convert to timestamps |
|
1878 | + $start_date = strtotime($start_date); |
|
1879 | + $end_date = strtotime($end_date); |
|
1880 | + |
|
1881 | + //makes sure start date is the lowest value and vice versa |
|
1882 | + $start_date = min($start_date, $end_date); |
|
1883 | + $end_date = max($start_date, $end_date); |
|
1884 | + |
|
1885 | + //convert to correct format for query |
|
1886 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
1887 | + date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); |
|
1888 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
1889 | + date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); |
|
1890 | + |
|
1891 | + |
|
1892 | + //set orderby |
|
1893 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
1894 | + |
|
1895 | + switch ($this->_req_data['orderby']) { |
|
1896 | + case 'TXN_ID': |
|
1897 | + $orderby = 'TXN_ID'; |
|
1898 | + break; |
|
1899 | + case 'ATT_fname': |
|
1900 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
1901 | + break; |
|
1902 | + case 'event_name': |
|
1903 | + $orderby = 'Registration.Event.EVT_name'; |
|
1904 | + break; |
|
1905 | + default: //'TXN_timestamp' |
|
1906 | + $orderby = 'TXN_timestamp'; |
|
1907 | + } |
|
1908 | + |
|
1909 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; |
|
1910 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
1911 | + $per_page = isset($perpage) && ! empty($perpage) ? $perpage : 10; |
|
1912 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
1913 | + |
|
1914 | + $offset = ($current_page - 1) * $per_page; |
|
1915 | + $limit = array($offset, $per_page); |
|
1916 | + |
|
1917 | + $_where = array( |
|
1918 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
1919 | + 'Registration.REG_count' => 1, |
|
1920 | + ); |
|
1921 | + |
|
1922 | + if (isset($this->_req_data['EVT_ID'])) { |
|
1923 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
1924 | + } |
|
1925 | + |
|
1926 | + if (isset($this->_req_data['s'])) { |
|
1927 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1928 | + $_where['OR'] = array( |
|
1929 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
1930 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
1931 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
1932 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
1933 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
1934 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
1935 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
1936 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
1937 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
1938 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
1939 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
1940 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
1941 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
1942 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
1943 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
1944 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
1945 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
1946 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
1947 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
1948 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
1949 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
1950 | + ); |
|
1951 | + } |
|
1952 | + |
|
1953 | + //failed transactions |
|
1954 | + $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; |
|
1955 | + $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; |
|
1956 | + |
|
1957 | + if ($failed) { |
|
1958 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
1959 | + } else if ($abandoned) { |
|
1960 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
1961 | + } else { |
|
1962 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
1963 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
1964 | + } |
|
1965 | + |
|
1966 | + $query_params = array( |
|
1967 | + $_where, |
|
1968 | + 'order_by' => array($orderby => $sort), |
|
1969 | + 'limit' => $limit, |
|
1970 | + 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
1971 | + ); |
|
1972 | + |
|
1973 | + $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params); |
|
1974 | + |
|
1975 | + |
|
1976 | + return $transactions; |
|
1977 | + |
|
1978 | + } |
|
1979 | 1979 | |
1980 | 1980 | |
1981 | 1981 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -335,11 +335,11 @@ discard block |
||
335 | 335 | public function load_scripts_styles() |
336 | 336 | { |
337 | 337 | //enqueue style |
338 | - wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), |
|
338 | + wp_register_style('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.css', array(), |
|
339 | 339 | EVENT_ESPRESSO_VERSION); |
340 | 340 | wp_enqueue_style('espresso_txn'); |
341 | 341 | //scripts |
342 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
342 | + wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array( |
|
343 | 343 | 'ee_admin_js', |
344 | 344 | 'ee-datepicker', |
345 | 345 | 'jquery-ui-datepicker', |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | |
423 | 423 | $TXN = EEM_Transaction::instance(); |
424 | 424 | |
425 | - $TXN_ID = (! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
425 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
426 | 426 | |
427 | 427 | //get transaction object |
428 | 428 | $this->_transaction = $TXN->get_one_by_ID($TXN_ID); |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | |
432 | 432 | if (empty($this->_transaction)) { |
433 | 433 | $error_msg = esc_html__('An error occurred and the details for Transaction ID #', |
434 | - 'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); |
|
434 | + 'event_espresso').$TXN_ID.esc_html__(' could not be retrieved.', 'event_espresso'); |
|
435 | 435 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
436 | 436 | } |
437 | 437 | } |
@@ -510,23 +510,23 @@ discard block |
||
510 | 510 | 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
511 | 511 | array( |
512 | 512 | 'overpaid' => array( |
513 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
513 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code, |
|
514 | 514 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence'), |
515 | 515 | ), |
516 | 516 | 'complete' => array( |
517 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
517 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code, |
|
518 | 518 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence'), |
519 | 519 | ), |
520 | 520 | 'incomplete' => array( |
521 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
521 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code, |
|
522 | 522 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence'), |
523 | 523 | ), |
524 | 524 | 'abandoned' => array( |
525 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
525 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code, |
|
526 | 526 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence'), |
527 | 527 | ), |
528 | 528 | 'failed' => array( |
529 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
529 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code, |
|
530 | 530 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence'), |
531 | 531 | ), |
532 | 532 | ) |
@@ -548,10 +548,10 @@ discard block |
||
548 | 548 | $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; |
549 | 549 | $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', |
550 | 550 | 'event_espresso'), '<h3>', |
551 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
552 | - EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', |
|
553 | - 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; |
|
554 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
551 | + '<a href="'.EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
552 | + EVENTS_ADMIN_URL).'" title="'.esc_attr__('Click to Edit event', |
|
553 | + 'event_espresso').'">'.$event->get('EVT_name').'</a>', '</h3>') : ''; |
|
554 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
555 | 555 | $this->display_admin_list_table_page_with_no_sidebar(); |
556 | 556 | } |
557 | 557 | |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | |
586 | 586 | $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
587 | 587 | $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
588 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
588 | + $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID'); |
|
589 | 589 | |
590 | 590 | $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
591 | 591 | $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
@@ -622,9 +622,9 @@ discard block |
||
622 | 622 | $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
623 | 623 | $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); |
624 | 624 | if (EE_Registry::instance()->CFG->currency->sign_b4) { |
625 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
625 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign.$this->_template_args['amount_due']; |
|
626 | 626 | } else { |
627 | - $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
627 | + $this->_template_args['amount_due'] = $this->_template_args['amount_due'].EE_Registry::instance()->CFG->currency->sign; |
|
628 | 628 | } |
629 | 629 | $this->_template_args['amount_due_class'] = ''; |
630 | 630 | |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | |
660 | 660 | |
661 | 661 | // next link |
662 | - $next_txn = $this->_transaction->next( |
|
662 | + $next_txn = $this->_transaction->next( |
|
663 | 663 | null, |
664 | 664 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
665 | 665 | 'TXN_ID' |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | ) |
675 | 675 | : ''; |
676 | 676 | // previous link |
677 | - $previous_txn = $this->_transaction->previous( |
|
677 | + $previous_txn = $this->_transaction->previous( |
|
678 | 678 | null, |
679 | 679 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
680 | 680 | 'TXN_ID' |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | // grab messages at the last second |
729 | 729 | $this->_template_args['notices'] = EE_Error::get_notices(); |
730 | 730 | // path to template |
731 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
731 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php'; |
|
732 | 732 | $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
733 | 733 | $this->_template_args, true); |
734 | 734 | |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | |
804 | 804 | // process payment details |
805 | 805 | $payments = $this->_transaction->get_many_related('Payment'); |
806 | - if (! empty($payments)) { |
|
806 | + if ( ! empty($payments)) { |
|
807 | 807 | $this->_template_args['payments'] = $payments; |
808 | 808 | $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
809 | 809 | } else { |
@@ -836,21 +836,21 @@ discard block |
||
836 | 836 | $reg_steps = '<ul>'; |
837 | 837 | foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
838 | 838 | if ($reg_step_status === true) { |
839 | - $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
840 | - ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
839 | + $reg_steps .= '<li style="color:#70cc50">'.sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
840 | + ucwords(str_replace('_', ' ', $reg_step))).'</li>'; |
|
841 | 841 | } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
842 | - $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
842 | + $reg_steps .= '<li style="color:#2EA2CC">'.sprintf( |
|
843 | 843 | esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
844 | 844 | ucwords(str_replace('_', ' ', $reg_step)), |
845 | - date(get_option('date_format') . ' ' . get_option('time_format'), |
|
845 | + date(get_option('date_format').' '.get_option('time_format'), |
|
846 | 846 | ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
847 | - ) . '</li>'; |
|
847 | + ).'</li>'; |
|
848 | 848 | } else { |
849 | - $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', |
|
850 | - 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
849 | + $reg_steps .= '<li style="color:#E76700">'.sprintf(esc_html__('%1$s : Never Initiated', |
|
850 | + 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))).'</li>'; |
|
851 | 851 | } |
852 | 852 | } |
853 | - $reg_steps .= '</ul>'; |
|
853 | + $reg_steps .= '</ul>'; |
|
854 | 854 | $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
855 | 855 | $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress', |
856 | 856 | 'event_espresso'); |
@@ -861,11 +861,11 @@ discard block |
||
861 | 861 | $this->_get_payment_status_array(); |
862 | 862 | $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
863 | 863 | |
864 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
864 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
865 | 865 | 'action' => 'edit_transaction', |
866 | 866 | 'process' => 'transaction', |
867 | 867 | ), TXN_ADMIN_URL); |
868 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
868 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
869 | 869 | 'page' => 'espresso_transactions', |
870 | 870 | 'action' => 'espresso_apply_payment', |
871 | 871 | ), WP_AJAX_URL); |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | |
877 | 877 | // 'espresso_delete_payment_nonce' |
878 | 878 | |
879 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
879 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
880 | 880 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
881 | 881 | |
882 | 882 | } |
@@ -902,11 +902,11 @@ discard block |
||
902 | 902 | ), |
903 | 903 | ), |
904 | 904 | )); |
905 | - if (! empty($reg_payments)) { |
|
905 | + if ( ! empty($reg_payments)) { |
|
906 | 906 | foreach ($payments as $payment) { |
907 | - if (! $payment instanceof EE_Payment) { |
|
907 | + if ( ! $payment instanceof EE_Payment) { |
|
908 | 908 | continue; |
909 | - } else if (! isset($existing_reg_payments[$payment->ID()])) { |
|
909 | + } else if ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
910 | 910 | $existing_reg_payments[$payment->ID()] = array(); |
911 | 911 | } |
912 | 912 | foreach ($reg_payments as $reg_payment) { |
@@ -933,7 +933,7 @@ discard block |
||
933 | 933 | protected function _get_registrations_to_apply_payment_to() |
934 | 934 | { |
935 | 935 | // we want any registration with an active status (ie: not deleted or cancelled) |
936 | - $query_params = array( |
|
936 | + $query_params = array( |
|
937 | 937 | array( |
938 | 938 | 'STS_ID' => array( |
939 | 939 | 'IN', |
@@ -945,19 +945,19 @@ discard block |
||
945 | 945 | ), |
946 | 946 | ), |
947 | 947 | ); |
948 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
948 | + $registrations_to_apply_payment_to = EEH_HTML::br().EEH_HTML::div( |
|
949 | 949 | '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' |
950 | 950 | ); |
951 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
951 | + $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
952 | 952 | $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
953 | 953 | $registrations_to_apply_payment_to .= EEH_HTML::thead( |
954 | 954 | EEH_HTML::tr( |
955 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
956 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
957 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
958 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
959 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
960 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
955 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')). |
|
956 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')). |
|
957 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')). |
|
958 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')). |
|
959 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
960 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
961 | 961 | EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
962 | 962 | ) |
963 | 963 | ); |
@@ -971,29 +971,29 @@ discard block |
||
971 | 971 | : esc_html__('Unknown Attendee', 'event_espresso'); |
972 | 972 | $owing = $registration->final_price() - $registration->paid(); |
973 | 973 | $taxable = $registration->ticket()->taxable() |
974 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
974 | + ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>' |
|
975 | 975 | : ''; |
976 | 976 | $checked = empty($existing_reg_payments) || in_array($registration->ID(), |
977 | 977 | $existing_reg_payments) |
978 | 978 | ? ' checked="checked"' |
979 | 979 | : ''; |
980 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
980 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
981 | 981 | $registrations_to_apply_payment_to .= EEH_HTML::tr( |
982 | - EEH_HTML::td($registration->ID()) . |
|
983 | - EEH_HTML::td($attendee_name) . |
|
982 | + EEH_HTML::td($registration->ID()). |
|
983 | + EEH_HTML::td($attendee_name). |
|
984 | 984 | EEH_HTML::td( |
985 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
986 | - ) . |
|
987 | - EEH_HTML::td($registration->event_name()) . |
|
988 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
989 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
985 | + $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable |
|
986 | + ). |
|
987 | + EEH_HTML::td($registration->event_name()). |
|
988 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
989 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
990 | 990 | EEH_HTML::td( |
991 | - '<input type="checkbox" value="' . $registration->ID() |
|
991 | + '<input type="checkbox" value="'.$registration->ID() |
|
992 | 992 | . '" name="txn_admin_payment[registrations]"' |
993 | - . $checked . $disabled . '>', |
|
993 | + . $checked.$disabled.'>', |
|
994 | 994 | '', 'jst-cntr' |
995 | 995 | ), |
996 | - 'apply-payment-registration-row-' . $registration->ID() |
|
996 | + 'apply-payment-registration-row-'.$registration->ID() |
|
997 | 997 | ); |
998 | 998 | } |
999 | 999 | } |
@@ -1007,7 +1007,7 @@ discard block |
||
1007 | 1007 | ), |
1008 | 1008 | '', 'clear description' |
1009 | 1009 | ); |
1010 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1010 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1011 | 1011 | $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
1012 | 1012 | } |
1013 | 1013 | |
@@ -1058,12 +1058,12 @@ discard block |
||
1058 | 1058 | array( |
1059 | 1059 | 'OR*payment_method_for_payment' => array( |
1060 | 1060 | 'PMD_ID' => array('IN', $payment_methods_of_payments), |
1061 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
1061 | + 'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'), |
|
1062 | 1062 | ), |
1063 | 1063 | ), |
1064 | 1064 | ); |
1065 | 1065 | } else { |
1066 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
1066 | + $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'))); |
|
1067 | 1067 | } |
1068 | 1068 | $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
1069 | 1069 | } |
@@ -1086,7 +1086,7 @@ discard block |
||
1086 | 1086 | $this->_template_args['event_attendees'] = array(); |
1087 | 1087 | // process items in cart |
1088 | 1088 | $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); |
1089 | - if (! empty($line_items)) { |
|
1089 | + if ( ! empty($line_items)) { |
|
1090 | 1090 | foreach ($line_items as $item) { |
1091 | 1091 | if ($item instanceof EE_Line_Item) { |
1092 | 1092 | switch ($item->OBJ_type()) { |
@@ -1097,7 +1097,7 @@ discard block |
||
1097 | 1097 | case 'Ticket' : |
1098 | 1098 | $ticket = $item->ticket(); |
1099 | 1099 | //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? |
1100 | - if (! $ticket instanceof EE_Ticket) { |
|
1100 | + if ( ! $ticket instanceof EE_Ticket) { |
|
1101 | 1101 | continue; |
1102 | 1102 | } |
1103 | 1103 | try { |
@@ -1106,13 +1106,13 @@ discard block |
||
1106 | 1106 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
1107 | 1107 | $event_name = esc_html__('Unknown Event', 'event_espresso'); |
1108 | 1108 | } |
1109 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
1109 | + $event_name .= ' - '.$item->get('LIN_name'); |
|
1110 | 1110 | $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
1111 | 1111 | // now get all of the registrations for this transaction that use this ticket |
1112 | 1112 | $registrations = $ticket->get_many_related('Registration', |
1113 | 1113 | array(array('TXN_ID' => $this->_transaction->ID()))); |
1114 | 1114 | foreach ($registrations as $registration) { |
1115 | - if (! $registration instanceof EE_Registration) { |
|
1115 | + if ( ! $registration instanceof EE_Registration) { |
|
1116 | 1116 | continue; |
1117 | 1117 | } |
1118 | 1118 | $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] = $registration->status_ID(); |
@@ -1124,8 +1124,8 @@ discard block |
||
1124 | 1124 | if ($attendee instanceof EE_Attendee) { |
1125 | 1125 | $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
1126 | 1126 | $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
1127 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', |
|
1128 | - 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
1127 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:'.$attendee->email().'?subject='.$event_name.esc_html__(' Event', |
|
1128 | + 'event_espresso').'">'.$attendee->email().'</a>'; |
|
1129 | 1129 | $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, |
1130 | 1130 | 'inline', false, false); |
1131 | 1131 | } else { |
@@ -1145,7 +1145,7 @@ discard block |
||
1145 | 1145 | 'action' => 'edit_transaction', |
1146 | 1146 | 'process' => 'attendees', |
1147 | 1147 | ), TXN_ADMIN_URL); |
1148 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
1148 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php', |
|
1149 | 1149 | $this->_template_args, true); |
1150 | 1150 | |
1151 | 1151 | } else { |
@@ -1170,7 +1170,7 @@ discard block |
||
1170 | 1170 | public function txn_registrant_side_meta_box() |
1171 | 1171 | { |
1172 | 1172 | $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; |
1173 | - if (! $primary_att instanceof EE_Attendee) { |
|
1173 | + if ( ! $primary_att instanceof EE_Attendee) { |
|
1174 | 1174 | $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
1175 | 1175 | 'event_espresso'); |
1176 | 1176 | $primary_att = EEM_Attendee::instance()->create_default_object(); |
@@ -1186,7 +1186,7 @@ discard block |
||
1186 | 1186 | ), REG_ADMIN_URL); |
1187 | 1187 | // get formatted address for registrant |
1188 | 1188 | $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
1189 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
1189 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php', |
|
1190 | 1190 | $this->_template_args, true); |
1191 | 1191 | } |
1192 | 1192 | |
@@ -1207,8 +1207,8 @@ discard block |
||
1207 | 1207 | TXN_ADMIN_URL |
1208 | 1208 | ); |
1209 | 1209 | |
1210 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
1211 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
1210 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
1211 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/ |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | |
@@ -1223,7 +1223,7 @@ discard block |
||
1223 | 1223 | { |
1224 | 1224 | $json_response_data = array('return_data' => false); |
1225 | 1225 | $valid_data = $this->_validate_payment_request_data(); |
1226 | - if (! empty($valid_data) |
|
1226 | + if ( ! empty($valid_data) |
|
1227 | 1227 | |
1228 | 1228 | ) { |
1229 | 1229 | $PAY_ID = $valid_data['PAY_ID']; |
@@ -1238,7 +1238,7 @@ discard block |
||
1238 | 1238 | $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
1239 | 1239 | $this->_remove_existing_registration_payments($payment, $PAY_ID); |
1240 | 1240 | // apply payment to registrations (if applicable) |
1241 | - if (! empty($REG_IDs)) { |
|
1241 | + if ( ! empty($REG_IDs)) { |
|
1242 | 1242 | $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
1243 | 1243 | $this->_maybe_send_notifications(); |
1244 | 1244 | // now process status changes for the same registrations |
@@ -1277,14 +1277,14 @@ discard block |
||
1277 | 1277 | */ |
1278 | 1278 | protected function _validate_payment_request_data() |
1279 | 1279 | { |
1280 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
1280 | + if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
1281 | 1281 | return false; |
1282 | 1282 | } |
1283 | 1283 | $payment_form = $this->_generate_payment_form_section(); |
1284 | 1284 | try { |
1285 | 1285 | if ($payment_form->was_submitted()) { |
1286 | 1286 | $payment_form->receive_form_submission(); |
1287 | - if (! $payment_form->is_valid()) { |
|
1287 | + if ( ! $payment_form->is_valid()) { |
|
1288 | 1288 | $submission_error_messages = array(); |
1289 | 1289 | foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
1290 | 1290 | if ($validation_error instanceof EE_Validation_Error) { |
@@ -1449,7 +1449,7 @@ discard block |
||
1449 | 1449 | array('Y-m-d', 'g:i a') |
1450 | 1450 | ); |
1451 | 1451 | |
1452 | - if (! $payment->save()) { |
|
1452 | + if ( ! $payment->save()) { |
|
1453 | 1453 | EE_Error::add_error( |
1454 | 1454 | sprintf( |
1455 | 1455 | esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
@@ -1499,7 +1499,7 @@ discard block |
||
1499 | 1499 | $REG_IDs = array(); |
1500 | 1500 | // grab array of IDs for specific registrations to apply changes to |
1501 | 1501 | if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
1502 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
1502 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
1503 | 1503 | } |
1504 | 1504 | //nothing specified ? then get all reg IDs |
1505 | 1505 | if (empty($REG_IDs)) { |
@@ -1611,13 +1611,13 @@ discard block |
||
1611 | 1611 | // but add in some conditions regarding payment, |
1612 | 1612 | // so that we don't apply payments to registrations that are free or have already been paid for |
1613 | 1613 | // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
1614 | - if (! $payment->is_a_refund()) { |
|
1614 | + if ( ! $payment->is_a_refund()) { |
|
1615 | 1615 | $registration_query_where_params['REG_final_price'] = array('!=', 0); |
1616 | 1616 | $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
1617 | 1617 | } |
1618 | 1618 | //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); |
1619 | 1619 | $registrations = $transaction->registrations(array($registration_query_where_params)); |
1620 | - if (! empty($registrations)) { |
|
1620 | + if ( ! empty($registrations)) { |
|
1621 | 1621 | /** @type EE_Payment_Processor $payment_processor */ |
1622 | 1622 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
1623 | 1623 | $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
@@ -1773,7 +1773,7 @@ discard block |
||
1773 | 1773 | { |
1774 | 1774 | $registration_payment_data = array(); |
1775 | 1775 | //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
1776 | - if (! empty($REG_IDs)) { |
|
1776 | + if ( ! empty($REG_IDs)) { |
|
1777 | 1777 | $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
1778 | 1778 | foreach ($registrations as $registration) { |
1779 | 1779 | if ($registration instanceof EE_Registration) { |
@@ -1838,7 +1838,7 @@ discard block |
||
1838 | 1838 | */ |
1839 | 1839 | protected function _send_payment_reminder() |
1840 | 1840 | { |
1841 | - $TXN_ID = (! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
1841 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
1842 | 1842 | $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
1843 | 1843 | $query_args = isset($this->_req_data['redirect_to']) ? array( |
1844 | 1844 | 'action' => $this->_req_data['redirect_to'], |
@@ -1870,8 +1870,8 @@ discard block |
||
1870 | 1870 | $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
1871 | 1871 | |
1872 | 1872 | //make sure our timestamps start and end right at the boundaries for each day |
1873 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
1874 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
1873 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
1874 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
1875 | 1875 | |
1876 | 1876 | |
1877 | 1877 | //convert to timestamps |
@@ -1924,7 +1924,7 @@ discard block |
||
1924 | 1924 | } |
1925 | 1925 | |
1926 | 1926 | if (isset($this->_req_data['s'])) { |
1927 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1927 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
1928 | 1928 | $_where['OR'] = array( |
1929 | 1929 | 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
1930 | 1930 | 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
@@ -1951,8 +1951,8 @@ discard block |
||
1951 | 1951 | } |
1952 | 1952 | |
1953 | 1953 | //failed transactions |
1954 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; |
|
1955 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; |
|
1954 | + $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; |
|
1955 | + $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; |
|
1956 | 1956 | |
1957 | 1957 | if ($failed) { |
1958 | 1958 | $_where['STS_ID'] = EEM_Transaction::failed_status_code; |