Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Transactions_Admin_Page often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Transactions_Admin_Page, and based on these observations, apply Extract Interface, too.
1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
||
24 | class Transactions_Admin_Page extends EE_Admin_Page { |
||
25 | |||
26 | /** |
||
27 | * @var EE_Transaction |
||
28 | */ |
||
29 | private $_transaction; |
||
30 | |||
31 | /** |
||
32 | * @var EE_Session |
||
33 | */ |
||
34 | private $_session; |
||
35 | |||
36 | /** |
||
37 | * @var array $_txn_status |
||
38 | */ |
||
39 | private static $_txn_status; |
||
40 | |||
41 | /** |
||
42 | * @var array $_pay_status |
||
43 | */ |
||
44 | private static $_pay_status; |
||
45 | |||
46 | /** |
||
47 | * @var array $_existing_reg_payment_REG_IDs |
||
48 | */ |
||
49 | protected $_existing_reg_payment_REG_IDs = null; |
||
50 | |||
51 | |||
52 | |||
53 | /** |
||
54 | * @Constructor |
||
55 | * @access public |
||
56 | * @param bool $routing |
||
57 | * @return Transactions_Admin_Page |
||
|
|||
58 | */ |
||
59 | public function __construct( $routing = TRUE ) { |
||
62 | |||
63 | |||
64 | |||
65 | /** |
||
66 | * _init_page_props |
||
67 | * @return void |
||
68 | */ |
||
69 | View Code Duplication | protected function _init_page_props() { |
|
70 | $this->page_slug = TXN_PG_SLUG; |
||
71 | $this->page_label = __('Transactions', 'event_espresso'); |
||
72 | $this->_admin_base_url = TXN_ADMIN_URL; |
||
73 | $this->_admin_base_path = TXN_ADMIN; |
||
74 | } |
||
75 | |||
76 | |||
77 | |||
78 | /** |
||
79 | * _ajax_hooks |
||
80 | * @return void |
||
81 | */ |
||
82 | protected function _ajax_hooks() { |
||
83 | add_action('wp_ajax_espresso_apply_payment', array( $this, 'apply_payments_or_refunds')); |
||
84 | add_action('wp_ajax_espresso_apply_refund', array( $this, 'apply_payments_or_refunds')); |
||
85 | add_action('wp_ajax_espresso_delete_payment', array( $this, 'delete_payment')); |
||
86 | } |
||
87 | |||
88 | |||
89 | |||
90 | /** |
||
91 | * _define_page_props |
||
92 | * @return void |
||
93 | */ |
||
94 | View Code Duplication | protected function _define_page_props() { |
|
95 | $this->_admin_page_title = $this->page_label; |
||
96 | $this->_labels = array( |
||
97 | 'buttons' => array( |
||
98 | 'add' => __('Add New Transaction', 'event_espresso'), |
||
99 | 'edit' => __('Edit Transaction', 'event_espresso'), |
||
100 | 'delete' => __('Delete Transaction','event_espresso'), |
||
101 | ) |
||
102 | ); |
||
103 | } |
||
104 | |||
105 | |||
106 | |||
107 | /** |
||
108 | * grab url requests and route them |
||
109 | * @access private |
||
110 | * @return void |
||
111 | */ |
||
112 | public function _set_page_routes() { |
||
113 | |||
114 | $this->_set_transaction_status_array(); |
||
115 | |||
116 | $txn_id = ! empty( $this->_req_data['TXN_ID'] ) && ! is_array( $this->_req_data['TXN_ID'] ) ? $this->_req_data['TXN_ID'] : 0; |
||
117 | |||
118 | $this->_page_routes = array( |
||
119 | |||
120 | 'default' => array( |
||
121 | 'func' => '_transactions_overview_list_table', |
||
122 | 'capability' => 'ee_read_transactions' |
||
123 | ), |
||
124 | |||
125 | 'view_transaction' => array( |
||
126 | 'func' => '_transaction_details', |
||
127 | 'capability' => 'ee_read_transaction', |
||
128 | 'obj_id' => $txn_id |
||
129 | ), |
||
130 | |||
131 | 'send_payment_reminder' => array( |
||
132 | 'func' => '_send_payment_reminder', |
||
133 | 'noheader' => TRUE, |
||
134 | 'capability' => 'ee_send_message' |
||
135 | ), |
||
136 | |||
137 | 'espresso_apply_payment' => array( |
||
138 | 'func' => 'apply_payments_or_refunds', |
||
139 | 'noheader' => TRUE, |
||
140 | 'capability' => 'ee_edit_payments' |
||
141 | ), |
||
142 | |||
143 | 'espresso_apply_refund' => array( |
||
144 | 'func' => 'apply_payments_or_refunds', |
||
145 | 'noheader' => TRUE, |
||
146 | 'capability' => 'ee_edit_payments' |
||
147 | ), |
||
148 | |||
149 | 'espresso_delete_payment' => array( |
||
150 | 'func' => 'delete_payment', |
||
151 | 'noheader' => TRUE, |
||
152 | 'capability' => 'ee_delete_payments' |
||
153 | ), |
||
154 | |||
155 | ); |
||
156 | |||
157 | } |
||
158 | |||
159 | |||
160 | |||
161 | |||
162 | |||
163 | |||
164 | |||
165 | |||
166 | protected function _set_page_config() { |
||
167 | $this->_page_config = array( |
||
168 | 'default' => array( |
||
169 | 'nav' => array( |
||
170 | 'label' => __('Overview', 'event_espresso'), |
||
171 | 'order' => 10 |
||
172 | ), |
||
173 | 'list_table' => 'EE_Admin_Transactions_List_Table', |
||
174 | 'help_tabs' => array( |
||
175 | 'transactions_overview_help_tab' => array( |
||
176 | 'title' => __('Transactions Overview', 'event_espresso'), |
||
177 | 'filename' => 'transactions_overview' |
||
178 | ), |
||
179 | 'transactions_overview_table_column_headings_help_tab' => array( |
||
180 | 'title' => __('Transactions Table Column Headings', 'event_espresso'), |
||
181 | 'filename' => 'transactions_overview_table_column_headings' |
||
182 | ), |
||
183 | 'transactions_overview_views_filters_help_tab' => array( |
||
184 | 'title' => __('Transaction Views & Filters & Search', 'event_espresso'), |
||
185 | 'filename' => 'transactions_overview_views_filters_search' |
||
186 | ), |
||
187 | ), |
||
188 | 'help_tour' => array( 'Transactions_Overview_Help_Tour' ), |
||
189 | /** |
||
190 | * commented out because currently we are not displaying tips for transaction list table status but this |
||
191 | * may change in a later iteration so want to keep the code for then. |
||
192 | */ |
||
193 | //'qtips' => array( 'Transactions_List_Table_Tips' ), |
||
194 | 'require_nonce' => FALSE |
||
195 | ), |
||
196 | 'view_transaction' => array( |
||
197 | 'nav' => array( |
||
198 | 'label' => __('View Transaction', 'event_espresso'), |
||
199 | 'order' => 5, |
||
200 | 'url' => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID'] ), $this->_current_page_view_url ) : $this->_admin_base_url, |
||
201 | 'persistent' => FALSE |
||
202 | ), |
||
203 | 'help_tabs' => array( |
||
204 | 'transactions_view_transaction_help_tab' => array( |
||
205 | 'title' => __('View Transaction', 'event_espresso'), |
||
206 | 'filename' => 'transactions_view_transaction' |
||
207 | ), |
||
208 | 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
||
209 | 'title' => __('Transaction Details Table', 'event_espresso'), |
||
210 | 'filename' => 'transactions_view_transaction_transaction_details_table' |
||
211 | ), |
||
212 | 'transactions_view_transaction_attendees_registered_help_tab' => array( |
||
213 | 'title' => __('Attendees Registered', 'event_espresso'), |
||
214 | 'filename' => 'transactions_view_transaction_attendees_registered' |
||
215 | ), |
||
216 | 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
||
217 | 'title' => __('Primary Registrant & Billing Information', 'event_espresso'), |
||
218 | 'filename' => 'transactions_view_transaction_primary_registrant_billing_information' |
||
219 | ), |
||
220 | ), |
||
221 | 'qtips' => array( 'Transaction_Details_Tips' ), |
||
222 | 'help_tour' => array( 'Transaction_Details_Help_Tour' ), |
||
223 | 'metaboxes' => array('_transaction_details_metaboxes'), |
||
224 | |||
225 | 'require_nonce' => FALSE |
||
226 | ) |
||
227 | ); |
||
228 | } |
||
229 | |||
230 | |||
231 | /** |
||
232 | * The below methods aren't used by this class currently |
||
233 | */ |
||
234 | protected function _add_screen_options() {} |
||
236 | public function admin_init() { |
||
237 | // IF a registration was JUST added via the admin... |
||
238 | if ( |
||
239 | isset( |
||
240 | $this->_req_data[ 'redirect_from' ], |
||
241 | $this->_req_data[ 'EVT_ID' ], |
||
242 | $this->_req_data[ 'event_name' ] |
||
243 | ) |
||
244 | ) { |
||
245 | // then set a cookie so that we can block any attempts to use |
||
246 | // the back button as a way to enter another registration. |
||
247 | setcookie( 'ee_registration_added', $this->_req_data[ 'EVT_ID' ], time() + WEEK_IN_SECONDS, '/' ); |
||
248 | // and update the global |
||
249 | $_COOKIE[ 'ee_registration_added' ] = $this->_req_data[ 'EVT_ID' ]; |
||
250 | } |
||
251 | EE_Registry::$i18n_js_strings[ 'invalid_server_response' ] = __( '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.', 'event_espresso' ); |
||
252 | EE_Registry::$i18n_js_strings[ 'error_occurred' ] = __( 'An error occurred! Please refresh the page and try again.', 'event_espresso' ); |
||
253 | EE_Registry::$i18n_js_strings[ 'txn_status_array' ] = self::$_txn_status; |
||
254 | EE_Registry::$i18n_js_strings[ 'pay_status_array' ] = self::$_pay_status; |
||
255 | } |
||
256 | public function admin_notices() {} |
||
258 | |||
259 | |||
260 | |||
261 | /** |
||
262 | * _set_transaction_status_array |
||
263 | * sets list of transaction statuses |
||
264 | * |
||
265 | * @access private |
||
266 | * @return void |
||
267 | */ |
||
268 | private function _set_transaction_status_array() { |
||
271 | |||
272 | |||
273 | |||
274 | /** |
||
275 | * get_transaction_status_array |
||
276 | * return the transaction status array for wp_list_table |
||
277 | * |
||
278 | * @access public |
||
279 | * @return array |
||
280 | */ |
||
281 | public function get_transaction_status_array() { |
||
284 | |||
285 | |||
286 | |||
287 | /** |
||
288 | * get list of payment statuses |
||
289 | * |
||
290 | * @access private |
||
291 | * @return void |
||
292 | */ |
||
293 | private function _get_payment_status_array() { |
||
298 | |||
299 | |||
300 | |||
301 | /** |
||
302 | * _add_screen_options_default |
||
303 | * |
||
304 | * @access protected |
||
305 | * @return void |
||
306 | */ |
||
307 | protected function _add_screen_options_default() { |
||
310 | |||
311 | |||
312 | |||
313 | /** |
||
314 | * load_scripts_styles |
||
315 | * |
||
316 | * @access public |
||
317 | * @return void |
||
318 | */ |
||
319 | public function load_scripts_styles() { |
||
332 | |||
333 | |||
334 | |||
335 | /** |
||
336 | * load_scripts_styles_view_transaction |
||
337 | * |
||
338 | * @access public |
||
339 | * @return void |
||
340 | */ |
||
341 | public function load_scripts_styles_view_transaction() { |
||
345 | |||
346 | |||
347 | |||
348 | /** |
||
349 | * load_scripts_styles_default |
||
350 | * |
||
351 | * @access public |
||
352 | * @return void |
||
353 | */ |
||
354 | public function load_scripts_styles_default() { |
||
358 | |||
359 | |||
360 | |||
361 | /** |
||
362 | * _set_list_table_views_default |
||
363 | * |
||
364 | * @access protected |
||
365 | * @return void |
||
366 | */ |
||
367 | protected function _set_list_table_views_default() { |
||
386 | |||
387 | |||
388 | |||
389 | /** |
||
390 | * _set_transaction_object |
||
391 | * This sets the _transaction property for the transaction details screen |
||
392 | * |
||
393 | * @access private |
||
394 | * @return void |
||
395 | */ |
||
396 | private function _set_transaction_object() { |
||
413 | |||
414 | |||
415 | |||
416 | /** |
||
417 | * _transaction_legend_items |
||
418 | * |
||
419 | * @access protected |
||
420 | * @return array |
||
421 | */ |
||
422 | protected function _transaction_legend_items() { |
||
505 | |||
506 | |||
507 | |||
508 | /** |
||
509 | * _transactions_overview_list_table |
||
510 | * |
||
511 | * @access protected |
||
512 | * @return void |
||
513 | */ |
||
514 | protected function _transactions_overview_list_table() { |
||
521 | |||
522 | |||
523 | |||
524 | /** |
||
525 | * _transaction_details |
||
526 | * generates HTML for the View Transaction Details Admin page |
||
527 | * |
||
528 | * @access protected |
||
529 | * @return void |
||
530 | */ |
||
531 | protected function _transaction_details() { |
||
532 | do_action( 'AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction ); |
||
533 | |||
534 | $this->_set_transaction_status_array(); |
||
535 | |||
536 | $this->_template_args = array(); |
||
537 | $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
||
538 | |||
539 | $this->_set_transaction_object(); |
||
540 | |||
541 | $primary_registration = $this->_transaction->primary_registration(); |
||
542 | $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : NULL; |
||
543 | |||
544 | $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
||
545 | $this->_template_args['txn_nmbr']['label'] = __( 'Transaction Number', 'event_espresso' ); |
||
546 | |||
547 | $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
||
548 | $this->_template_args['txn_datetime']['label'] = __( 'Date', 'event_espresso' ); |
||
549 | |||
550 | $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->get('STS_ID') ]; |
||
551 | $this->_template_args['txn_status']['label'] = __( 'Transaction Status', 'event_espresso' ); |
||
552 | $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
||
553 | |||
554 | $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
||
555 | $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
||
556 | |||
557 | if ( |
||
558 | $attendee instanceof EE_Attendee |
||
559 | && EE_Registry::instance()->CAP->current_user_can( |
||
560 | 'ee_send_message', |
||
561 | 'espresso_transactions_send_payment_reminder' |
||
562 | ) |
||
563 | ) { |
||
564 | $this->_template_args['send_payment_reminder_button'] = |
||
565 | EEH_MSG_Template::is_mt_active( 'payment_reminder' ) |
||
566 | && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code |
||
567 | && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code |
||
568 | ? EEH_Template::get_button_or_link( |
||
569 | EE_Admin_Page::add_query_args_and_nonce( |
||
570 | array( |
||
571 | 'action'=>'send_payment_reminder', |
||
572 | 'TXN_ID'=>$this->_transaction->ID(), |
||
573 | 'redirect_to' => 'view_transaction' |
||
574 | ), |
||
575 | TXN_ADMIN_URL |
||
576 | ), |
||
577 | __(' Send Payment Reminder', 'event_espresso'), |
||
578 | 'button secondary-button right', |
||
579 | 'dashicons dashicons-email-alt' |
||
580 | ) |
||
581 | : ''; |
||
582 | } else { |
||
583 | $this->_template_args['send_payment_reminder_button'] = ''; |
||
584 | } |
||
585 | |||
586 | $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
||
587 | $this->_template_args['amount_due'] = EEH_Template::format_currency( $amount_due, TRUE ); |
||
588 | if ( EE_Registry::instance()->CFG->currency->sign_b4 ) { |
||
589 | $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
||
590 | } else { |
||
591 | $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
||
592 | } |
||
593 | $this->_template_args['amount_due_class'] = ''; |
||
594 | |||
595 | if ( $this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total') ) { |
||
596 | // paid in full |
||
597 | $this->_template_args['amount_due'] = FALSE; |
||
598 | View Code Duplication | } elseif ( $this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total') ) { |
|
599 | // overpaid |
||
600 | $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
||
601 | } elseif (( $this->_transaction->get('TXN_total') > 0 ) && ( $this->_transaction->get('TXN_paid') > 0 )) { |
||
602 | // monies owing |
||
603 | $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
||
604 | View Code Duplication | } elseif (( $this->_transaction->get('TXN_total') > 0 ) && ( $this->_transaction->get('TXN_paid') == 0 )) { |
|
605 | // no payments made yet |
||
606 | $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
||
607 | } elseif ( $this->_transaction->get('TXN_total') == 0 ) { |
||
608 | // free event |
||
609 | $this->_template_args['amount_due'] = FALSE; |
||
610 | } |
||
611 | |||
612 | $payment_method = $this->_transaction->payment_method(); |
||
613 | |||
614 | $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
||
615 | ? $payment_method->admin_name() |
||
616 | : __( 'Unknown', 'event_espresso' ); |
||
617 | |||
618 | $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
||
619 | // link back to overview |
||
620 | $this->_template_args['txn_overview_url'] = ! empty ( $_SERVER['HTTP_REFERER'] ) |
||
621 | ? $_SERVER['HTTP_REFERER'] |
||
622 | : TXN_ADMIN_URL; |
||
623 | |||
624 | |||
625 | // next link |
||
626 | $next_txn = $this->_transaction->next( |
||
627 | null, |
||
628 | array( array( 'STS_ID' => array( '!=', EEM_Transaction::failed_status_code ) ) ), |
||
629 | 'TXN_ID' |
||
630 | ); |
||
631 | $this->_template_args['next_transaction'] = $next_txn |
||
632 | ? $this->_next_link( |
||
633 | EE_Admin_Page::add_query_args_and_nonce( |
||
634 | array( 'action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID'] ), |
||
635 | TXN_ADMIN_URL |
||
636 | ), |
||
637 | 'dashicons dashicons-arrow-right ee-icon-size-22' |
||
638 | ) |
||
639 | : ''; |
||
640 | // previous link |
||
641 | $previous_txn = $this->_transaction->previous( |
||
642 | null, |
||
643 | array( array( 'STS_ID' => array( '!=', EEM_Transaction::failed_status_code ) ) ), |
||
644 | 'TXN_ID' |
||
645 | ); |
||
646 | $this->_template_args['previous_transaction'] = $previous_txn |
||
647 | ? $this->_previous_link( |
||
648 | EE_Admin_Page::add_query_args_and_nonce( |
||
649 | array( 'action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID'] ), |
||
650 | TXN_ADMIN_URL |
||
651 | ), |
||
652 | 'dashicons dashicons-arrow-left ee-icon-size-22' |
||
653 | ) |
||
654 | : ''; |
||
655 | |||
656 | // were we just redirected here after adding a new registration ??? |
||
657 | if ( |
||
658 | isset( |
||
659 | $this->_req_data[ 'redirect_from' ], |
||
660 | $this->_req_data[ 'EVT_ID' ], |
||
661 | $this->_req_data[ 'event_name' ] |
||
662 | ) |
||
663 | ) { |
||
664 | if ( |
||
665 | EE_Registry::instance()->CAP->current_user_can( |
||
666 | 'ee_edit_registrations', |
||
667 | 'espresso_registrations_new_registration', |
||
668 | $this->_req_data[ 'EVT_ID' ] |
||
669 | ) |
||
670 | ) { |
||
671 | $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
||
672 | $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
||
673 | array( |
||
674 | 'page' => 'espresso_registrations', |
||
675 | 'action' => 'new_registration', |
||
676 | 'return' => 'default', |
||
677 | 'TXN_ID' => $this->_transaction->ID(), |
||
678 | 'event_id' => $this->_req_data[ 'EVT_ID' ], |
||
679 | ), |
||
680 | REG_ADMIN_URL |
||
681 | ); |
||
682 | $this->_admin_page_title .= '">'; |
||
683 | |||
684 | $this->_admin_page_title .= sprintf( |
||
685 | __('Add Another New Registration to Event: "%1$s" ?'), |
||
686 | htmlentities( urldecode( $this->_req_data[ 'event_name' ] ), ENT_QUOTES, 'UTF-8' ) |
||
687 | ); |
||
688 | $this->_admin_page_title .= '</a>'; |
||
689 | } |
||
690 | EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ ); |
||
691 | } |
||
692 | // grab messages at the last second |
||
693 | $this->_template_args['notices'] = EE_Error::get_notices(); |
||
694 | // path to template |
||
695 | $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
||
696 | $this->_template_args['admin_page_header'] = EEH_Template::display_template( $template_path, $this->_template_args, TRUE ); |
||
697 | |||
698 | // the details template wrapper |
||
699 | $this->display_admin_page_with_sidebar(); |
||
700 | |||
701 | } |
||
702 | |||
703 | |||
704 | |||
705 | /** |
||
706 | * _transaction_details_metaboxes |
||
707 | * |
||
708 | * @access protected |
||
709 | * @return void |
||
710 | */ |
||
711 | protected function _transaction_details_metaboxes() { |
||
729 | |||
730 | |||
731 | |||
732 | /** |
||
733 | * txn_details_meta_box |
||
734 | * generates HTML for the Transaction main meta box |
||
735 | * |
||
736 | * @access public |
||
737 | * @return void |
||
738 | */ |
||
739 | public function txn_details_meta_box() { |
||
822 | |||
823 | |||
824 | |||
825 | /** |
||
826 | * _get_registration_payment_IDs |
||
827 | * |
||
828 | * generates an array of Payment IDs and their corresponding Registration IDs |
||
829 | * |
||
830 | * @access protected |
||
831 | * @param EE_Payment[] $payments |
||
832 | * @return array |
||
833 | */ |
||
834 | protected function _get_registration_payment_IDs( $payments = array() ) { |
||
861 | |||
862 | |||
863 | |||
864 | /** |
||
865 | * _get_registrations_to_apply_payment_to |
||
866 | * |
||
867 | * generates HTML for displaying a series of checkboxes in the admin payment modal window |
||
868 | * which allows the admin to only apply the payment to the specific registrations |
||
869 | * |
||
870 | * @access protected |
||
871 | * @return void |
||
872 | */ |
||
873 | protected function _get_registrations_to_apply_payment_to() { |
||
925 | |||
926 | |||
927 | |||
928 | /** |
||
929 | * _get_reg_status_selection |
||
930 | * |
||
931 | * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets instead of events. |
||
932 | * @access protected |
||
933 | * @return void |
||
934 | */ |
||
935 | protected function _get_reg_status_selection() { |
||
945 | |||
946 | |||
947 | |||
948 | /** |
||
949 | * _get_payment_methods |
||
950 | * Gets all the payment methods available generally, or the ones that are already |
||
951 | * selected on these payments (in case their payment methods are no longer active). |
||
952 | * Has the side-effect of updating the template args' payment_methods item |
||
953 | * @access private |
||
954 | * @param EE_Payment[] to show on this page |
||
955 | * @return void |
||
956 | */ |
||
957 | private function _get_payment_methods( $payments = array() ) { |
||
973 | |||
974 | |||
975 | |||
976 | /** |
||
977 | * txn_attendees_meta_box |
||
978 | * generates HTML for the Attendees Transaction main meta box |
||
979 | * |
||
980 | * @access public |
||
981 | * @param WP_Post $post |
||
982 | * @param array $metabox |
||
983 | * @return void |
||
984 | */ |
||
985 | public function txn_attendees_meta_box( $post, $metabox = array( 'args' => array() )) { |
||
1045 | |||
1046 | |||
1047 | |||
1048 | /** |
||
1049 | * txn_registrant_side_meta_box |
||
1050 | * generates HTML for the Edit Transaction side meta box |
||
1051 | * |
||
1052 | * @access public |
||
1053 | * @throws \EE_Error |
||
1054 | * @return void |
||
1055 | */ |
||
1056 | public function txn_registrant_side_meta_box() { |
||
1072 | |||
1073 | |||
1074 | |||
1075 | /** |
||
1076 | * txn_billing_info_side_meta_box |
||
1077 | * generates HTML for the Edit Transaction side meta box |
||
1078 | * |
||
1079 | * @access public |
||
1080 | * @return void |
||
1081 | */ |
||
1082 | public function txn_billing_info_side_meta_box() { |
||
1093 | |||
1094 | |||
1095 | |||
1096 | /** |
||
1097 | * apply_payments_or_refunds |
||
1098 | * registers a payment or refund made towards a transaction |
||
1099 | * |
||
1100 | * @access public |
||
1101 | * @return void |
||
1102 | */ |
||
1103 | public function apply_payments_or_refunds() { |
||
1147 | |||
1148 | |||
1149 | |||
1150 | /** |
||
1151 | * _validate_payment_request_data |
||
1152 | * |
||
1153 | * @return array |
||
1154 | */ |
||
1155 | protected function _validate_payment_request_data() { |
||
1184 | |||
1185 | |||
1186 | |||
1187 | /** |
||
1188 | * _generate_payment_form_section |
||
1189 | * |
||
1190 | * @return EE_Form_Section_Proper |
||
1191 | */ |
||
1192 | protected function _generate_payment_form_section() { |
||
1285 | |||
1286 | |||
1287 | |||
1288 | /** |
||
1289 | * _create_payment_from_request_data |
||
1290 | * |
||
1291 | * @param array $valid_data |
||
1292 | * @return EE_Payment |
||
1293 | */ |
||
1294 | protected function _create_payment_from_request_data( $valid_data ) { |
||
1332 | |||
1333 | |||
1334 | |||
1335 | /** |
||
1336 | * _process_transaction_payments |
||
1337 | * |
||
1338 | * @param \EE_Transaction $transaction |
||
1339 | * @return array |
||
1340 | */ |
||
1341 | protected function _process_transaction_payments( EE_Transaction $transaction ) { |
||
1354 | |||
1355 | |||
1356 | |||
1357 | /** |
||
1358 | * _get_REG_IDs_to_apply_payment_to |
||
1359 | * |
||
1360 | * returns a list of registration IDs that the payment will apply to |
||
1361 | * |
||
1362 | * @param \EE_Payment $payment |
||
1363 | * @return array |
||
1364 | */ |
||
1365 | protected function _get_REG_IDs_to_apply_payment_to( EE_Payment $payment ) { |
||
1379 | |||
1380 | |||
1381 | |||
1382 | /** |
||
1383 | * @return array |
||
1384 | */ |
||
1385 | public function existing_reg_payment_REG_IDs() { |
||
1388 | |||
1389 | |||
1390 | |||
1391 | /** |
||
1392 | * @param array $existing_reg_payment_REG_IDs |
||
1393 | */ |
||
1394 | public function set_existing_reg_payment_REG_IDs( $existing_reg_payment_REG_IDs = null ) { |
||
1397 | |||
1398 | |||
1399 | |||
1400 | /** |
||
1401 | * _get_existing_reg_payment_REG_IDs |
||
1402 | * |
||
1403 | * returns a list of registration IDs that the payment is currently related to |
||
1404 | * as recorded in the database |
||
1405 | * |
||
1406 | * @param \EE_Payment $payment |
||
1407 | * @return array |
||
1408 | */ |
||
1409 | protected function _get_existing_reg_payment_REG_IDs( EE_Payment $payment ) { |
||
1419 | |||
1420 | |||
1421 | |||
1422 | /** |
||
1423 | * _remove_existing_registration_payments |
||
1424 | * |
||
1425 | * this calculates the difference between existing relations |
||
1426 | * to the supplied payment and the new list registration IDs, |
||
1427 | * removes any related registrations that no longer apply, |
||
1428 | * and then updates the registration paid fields |
||
1429 | * |
||
1430 | * @param \EE_Payment $payment |
||
1431 | * @param int $PAY_ID |
||
1432 | * @return bool; |
||
1433 | */ |
||
1434 | protected function _remove_existing_registration_payments( EE_Payment $payment, $PAY_ID = 0 ) { |
||
1455 | |||
1456 | |||
1457 | |||
1458 | /** |
||
1459 | * _update_registration_payments |
||
1460 | * |
||
1461 | * this applies the payments to the selected registrations |
||
1462 | * but only if they have not already been paid for |
||
1463 | * |
||
1464 | * @param EE_Transaction $transaction |
||
1465 | * @param \EE_Payment $payment |
||
1466 | * @param array $REG_IDs |
||
1467 | * @return bool |
||
1468 | */ |
||
1469 | protected function _update_registration_payments( EE_Transaction $transaction, EE_Payment $payment, $REG_IDs = array() ) { |
||
1490 | |||
1491 | |||
1492 | |||
1493 | /** |
||
1494 | * _process_registration_status_change |
||
1495 | * |
||
1496 | * This processes requested registration status changes for all the registrations |
||
1497 | * on a given transaction and (optionally) sends out notifications for the changes. |
||
1498 | * |
||
1499 | * @param EE_Transaction $transaction |
||
1500 | * @param array $REG_IDs |
||
1501 | * @return bool |
||
1502 | */ |
||
1503 | protected function _process_registration_status_change( EE_Transaction $transaction, $REG_IDs = array() ) { |
||
1521 | |||
1522 | |||
1523 | |||
1524 | /** |
||
1525 | * _build_payment_json_response |
||
1526 | * |
||
1527 | * @access public |
||
1528 | * @param \EE_Payment $payment |
||
1529 | * @param array $REG_IDs |
||
1530 | * @param bool | null $delete_txn_reg_status_change |
||
1531 | * @return array |
||
1532 | */ |
||
1533 | protected function _build_payment_json_response( EE_Payment $payment, $REG_IDs = array(), $delete_txn_reg_status_change = null ) { |
||
1567 | |||
1568 | |||
1569 | |||
1570 | /** |
||
1571 | * delete_payment |
||
1572 | * delete a payment or refund made towards a transaction |
||
1573 | * |
||
1574 | * @access public |
||
1575 | * @return void |
||
1576 | */ |
||
1577 | public function delete_payment() { |
||
1619 | |||
1620 | |||
1621 | |||
1622 | /** |
||
1623 | * _registration_payment_data_array |
||
1624 | * adds info for 'owing' and 'paid' for each registration to the json response |
||
1625 | * |
||
1626 | * @access protected |
||
1627 | * @param array $REG_IDs |
||
1628 | * @return array |
||
1629 | */ |
||
1630 | protected function _registration_payment_data_array( $REG_IDs ) { |
||
1631 | $registration_payment_data = array(); |
||
1632 | //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
||
1633 | if ( ! empty( $REG_IDs ) ) { |
||
1634 | $registrations = EEM_Registration::instance()->get_all( array( array( 'REG_ID' => array( 'IN', $REG_IDs ) ) ) ); |
||
1635 | foreach ( $registrations as $registration ) { |
||
1636 | if ( $registration instanceof EE_Registration ) { |
||
1637 | $registration_payment_data[ $registration->ID() ] = array( |
||
1638 | 'paid' => $registration->pretty_paid(), |
||
1639 | 'owing' => EEH_Template::format_currency( $registration->final_price() - $registration->paid() ), |
||
1640 | ); |
||
1641 | } |
||
1642 | } |
||
1643 | } |
||
1644 | return $registration_payment_data; |
||
1645 | } |
||
1646 | |||
1647 | |||
1648 | |||
1649 | /** |
||
1650 | * _maybe_send_notifications |
||
1651 | * |
||
1652 | * determines whether or not the admin has indicated that notifications should be sent. |
||
1653 | * If so, will toggle a filter switch for delivering registration notices. |
||
1654 | * If passed an EE_Payment object, then it will trigger payment notifications instead. |
||
1655 | * |
||
1656 | * @access protected |
||
1657 | * @param \EE_Payment | null $payment |
||
1658 | */ |
||
1659 | protected function _maybe_send_notifications( $payment = null ) { |
||
1687 | |||
1688 | |||
1689 | |||
1690 | /** |
||
1691 | * _send_payment_reminder |
||
1692 | * generates HTML for the View Transaction Details Admin page |
||
1693 | * |
||
1694 | * @access protected |
||
1695 | * @return void |
||
1696 | */ |
||
1697 | protected function _send_payment_reminder() { |
||
1704 | |||
1705 | |||
1706 | |||
1707 | /** |
||
1708 | * get_transactions |
||
1709 | * get transactions for given parameters (used by list table) |
||
1710 | * |
||
1711 | * @param int $perpage how many transactions displayed per page |
||
1712 | * @param boolean $count return the count or objects |
||
1713 | * @param string $view |
||
1714 | * @return mixed int = count || array of transaction objects |
||
1715 | */ |
||
1716 | public function get_transactions( $perpage, $count = FALSE, $view = '' ) { |
||
1824 | |||
1825 | |||
1826 | |||
1827 | } |
||
1828 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.