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 | 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' ); |
||
238 | EE_Registry::$i18n_js_strings[ 'error_occurred' ] = __( 'An error occurred! Please refresh the page and try again.', 'event_espresso' ); |
||
239 | EE_Registry::$i18n_js_strings[ 'txn_status_array' ] = self::$_txn_status; |
||
240 | EE_Registry::$i18n_js_strings[ 'pay_status_array' ] = self::$_pay_status; |
||
241 | } |
||
242 | public function admin_notices() {} |
||
244 | |||
245 | |||
246 | |||
247 | /** |
||
248 | * _set_transaction_status_array |
||
249 | * sets list of transaction statuses |
||
250 | * |
||
251 | * @access private |
||
252 | * @return void |
||
253 | */ |
||
254 | private function _set_transaction_status_array() { |
||
257 | |||
258 | |||
259 | |||
260 | /** |
||
261 | * get_transaction_status_array |
||
262 | * return the transaction status array for wp_list_table |
||
263 | * |
||
264 | * @access public |
||
265 | * @return array |
||
266 | */ |
||
267 | public function get_transaction_status_array() { |
||
270 | |||
271 | |||
272 | |||
273 | /** |
||
274 | * get list of payment statuses |
||
275 | * |
||
276 | * @access private |
||
277 | * @return void |
||
278 | */ |
||
279 | private function _get_payment_status_array() { |
||
280 | self::$_pay_status = EEM_Payment::instance()->status_array(TRUE); |
||
281 | $this->_template_args['payment_status'] = self::$_pay_status; |
||
282 | |||
283 | } |
||
284 | |||
285 | |||
286 | |||
287 | /** |
||
288 | * _add_screen_options_default |
||
289 | * |
||
290 | * @access protected |
||
291 | * @return void |
||
292 | */ |
||
293 | protected function _add_screen_options_default() { |
||
296 | |||
297 | |||
298 | |||
299 | /** |
||
300 | * load_scripts_styles |
||
301 | * |
||
302 | * @access public |
||
303 | * @return void |
||
304 | */ |
||
305 | public function load_scripts_styles() { |
||
306 | //enqueue style |
||
307 | wp_register_style( 'espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), EVENT_ESPRESSO_VERSION ); |
||
308 | wp_enqueue_style('espresso_txn'); |
||
309 | |||
310 | //scripts |
||
311 | add_filter('FHEE_load_accounting_js', '__return_true'); |
||
312 | |||
313 | //scripts |
||
314 | wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array('ee_admin_js', 'ee-datepicker', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'ee-dialog', 'ee-accounting', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, TRUE); |
||
315 | wp_enqueue_script('espresso_txn'); |
||
316 | |||
317 | } |
||
318 | |||
319 | |||
320 | |||
321 | /** |
||
322 | * load_scripts_styles_view_transaction |
||
323 | * |
||
324 | * @access public |
||
325 | * @return void |
||
326 | */ |
||
327 | public function load_scripts_styles_view_transaction() { |
||
331 | |||
332 | |||
333 | |||
334 | /** |
||
335 | * load_scripts_styles_default |
||
336 | * |
||
337 | * @access public |
||
338 | * @return void |
||
339 | */ |
||
340 | public function load_scripts_styles_default() { |
||
344 | |||
345 | |||
346 | |||
347 | /** |
||
348 | * _set_list_table_views_default |
||
349 | * |
||
350 | * @access protected |
||
351 | * @return void |
||
352 | */ |
||
353 | protected function _set_list_table_views_default() { |
||
354 | $this->_views = array ( |
||
355 | 'all' => array ( |
||
356 | 'slug' => 'all', |
||
357 | 'label' => __('View All Transactions', 'event_espresso'), |
||
358 | 'count' => 0 |
||
359 | ), |
||
360 | 'abandoned' => array( |
||
361 | 'slug' => 'abandoned', |
||
362 | 'label' => __('Abandoned Transactions', 'event_espresso'), |
||
363 | 'count' => 0 |
||
364 | ), |
||
365 | 'failed' => array( |
||
366 | 'slug' => 'failed', |
||
367 | 'label' => __('Failed Transactions', 'event_espresso'), |
||
368 | 'count' => 0 |
||
369 | ) |
||
370 | ); |
||
371 | } |
||
372 | |||
373 | |||
374 | |||
375 | /** |
||
376 | * _set_transaction_object |
||
377 | * This sets the _transaction property for the transaction details screen |
||
378 | * |
||
379 | * @access private |
||
380 | * @return void |
||
381 | */ |
||
382 | private function _set_transaction_object() { |
||
383 | if ( is_object( $this->_transaction) ) |
||
384 | return; //get out we've already set the object |
||
385 | |||
386 | $TXN = EEM_Transaction::instance(); |
||
387 | |||
388 | $TXN_ID = ( ! empty( $this->_req_data['TXN_ID'] )) ? absint( $this->_req_data['TXN_ID'] ) : FALSE; |
||
389 | |||
390 | //get transaction object |
||
391 | $this->_transaction = $TXN->get_one_by_ID($TXN_ID); |
||
392 | $this->_session = !empty( $this->_transaction ) ? $this->_transaction->get('TXN_session_data') : NULL; |
||
393 | |||
394 | if ( empty( $this->_transaction ) ) { |
||
395 | $error_msg = __('An error occurred and the details for Transaction ID #', 'event_espresso') . $TXN_ID . __(' could not be retrieved.', 'event_espresso'); |
||
396 | EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
||
397 | } |
||
398 | } |
||
399 | |||
400 | |||
401 | |||
402 | /** |
||
403 | * _transaction_legend_items |
||
404 | * |
||
405 | * @access protected |
||
406 | * @return array |
||
407 | */ |
||
408 | protected function _transaction_legend_items() { |
||
409 | $items = apply_filters( |
||
410 | 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
||
411 | array( |
||
412 | 'view_details' => array( |
||
413 | 'class' => 'dashicons dashicons-cart', |
||
414 | 'desc' => __('View Transaction Details', 'event_espresso') |
||
415 | ), |
||
416 | 'view_invoice' => array( |
||
417 | 'class' => 'dashicons dashicons-media-spreadsheet', |
||
418 | 'desc' => __('View Transaction Invoice', 'event_espresso') |
||
419 | ), |
||
420 | 'view_receipt' => array( |
||
421 | 'class' => 'dashicons dashicons-media-default', |
||
422 | 'desc' => __('View Transaction Receipt', 'event_espresso' ) |
||
423 | ), |
||
424 | 'view_registration' => array( |
||
425 | 'class' => 'dashicons dashicons-clipboard', |
||
426 | 'desc' => __('View Registration Details', 'event_espresso') |
||
427 | ) |
||
428 | ) |
||
429 | ); |
||
430 | |||
431 | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_send_message', 'espresso_transactions_send_payment_reminder' ) ) { |
||
432 | |||
433 | EE_Registry::instance()->load_helper( 'MSG_Template' ); |
||
434 | if ( EEH_MSG_Template::is_mt_active( 'payment_reminder' ) ) { |
||
435 | $items['send_payment_reminder'] = array( |
||
436 | 'class' => 'dashicons dashicons-email-alt', |
||
437 | 'desc' => __('Send Payment Reminder', 'event_espresso') |
||
438 | ); |
||
439 | } else { |
||
440 | $items['blank*'] = array( |
||
441 | 'class'=> '', |
||
442 | 'desc' => '' |
||
443 | ); |
||
444 | } |
||
445 | } else { |
||
446 | $items['blank*'] = array( |
||
447 | 'class'=> '', |
||
448 | 'desc' => '' |
||
449 | ); |
||
450 | } |
||
451 | $more_items = apply_filters( |
||
452 | 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
||
453 | array( |
||
454 | 'overpaid' => array( |
||
455 | 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
||
456 | 'desc' => EEH_Template::pretty_status( EEM_Transaction::overpaid_status_code, FALSE, 'sentence' ) |
||
457 | ), |
||
458 | 'complete' => array( |
||
459 | 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
||
460 | 'desc' => EEH_Template::pretty_status( EEM_Transaction::complete_status_code, FALSE, 'sentence' ) |
||
461 | ), |
||
462 | 'incomplete' => array( |
||
463 | 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
||
464 | 'desc' => EEH_Template::pretty_status( EEM_Transaction::incomplete_status_code, FALSE, 'sentence' ) |
||
465 | ), |
||
466 | 'abandoned' => array( |
||
467 | 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
||
468 | 'desc' => EEH_Template::pretty_status( EEM_Transaction::abandoned_status_code, FALSE, 'sentence' ) |
||
469 | ), |
||
470 | 'failed' => array( |
||
471 | 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
||
472 | 'desc' => EEH_Template::pretty_status( EEM_Transaction::failed_status_code, FALSE, 'sentence' ) |
||
473 | ) |
||
474 | ) |
||
475 | ); |
||
476 | |||
477 | return array_merge( $items, $more_items); |
||
478 | } |
||
479 | |||
480 | |||
481 | |||
482 | /** |
||
483 | * _transactions_overview_list_table |
||
484 | * |
||
485 | * @access protected |
||
486 | * @return void |
||
487 | */ |
||
488 | protected function _transactions_overview_list_table() { |
||
489 | $this->_admin_page_title = __('Transactions', 'event_espresso'); |
||
490 | $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'] ) : NULL; |
||
491 | $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf( __('%sViewing Transactions for the Event: %s%s', 'event_espresso'), '<h3>', '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), EVENTS_ADMIN_URL ) . '" title="' . esc_attr__('Click to Edit event', 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>' ) : ''; |
||
492 | $this->_template_args['after_list_table'] = $this->_display_legend( $this->_transaction_legend_items() ); |
||
493 | $this->display_admin_list_table_page_with_no_sidebar(); |
||
494 | } |
||
495 | |||
496 | |||
497 | |||
498 | /** |
||
499 | * _transaction_details |
||
500 | * generates HTML for the View Transaction Details Admin page |
||
501 | * |
||
502 | * @access protected |
||
503 | * @return void |
||
504 | */ |
||
505 | protected function _transaction_details() { |
||
594 | |||
595 | |||
596 | |||
597 | /** |
||
598 | * _transaction_details_metaboxes |
||
599 | * |
||
600 | * @access protected |
||
601 | * @return void |
||
602 | */ |
||
603 | protected function _transaction_details_metaboxes() { |
||
604 | |||
605 | $this->_set_transaction_object(); |
||
606 | |||
607 | add_meta_box( 'edit-txn-details-mbox', __( 'Transaction Details', 'event_espresso' ), array( $this, 'txn_details_meta_box' ), $this->_wp_page_slug, 'normal', 'high' ); |
||
608 | add_meta_box( |
||
609 | 'edit-txn-attendees-mbox', |
||
610 | __( 'Attendees Registered in this Transaction', 'event_espresso' ), |
||
611 | array( $this, 'txn_attendees_meta_box' ), |
||
612 | $this->_wp_page_slug, |
||
613 | 'normal', |
||
614 | 'high', |
||
615 | array( 'TXN_ID' => $this->_transaction->ID() ) |
||
616 | ); |
||
617 | add_meta_box( 'edit-txn-registrant-mbox', __( 'Primary Contact', 'event_espresso' ), array( $this, 'txn_registrant_side_meta_box' ), $this->_wp_page_slug, 'side', 'high' ); |
||
618 | add_meta_box( 'edit-txn-billing-info-mbox', __( 'Billing Information', 'event_espresso' ), array( $this, 'txn_billing_info_side_meta_box' ), $this->_wp_page_slug, 'side', 'high' ); |
||
619 | |||
620 | } |
||
621 | |||
622 | |||
623 | |||
624 | /** |
||
625 | * txn_details_meta_box |
||
626 | * generates HTML for the Transaction main meta box |
||
627 | * |
||
628 | * @access public |
||
629 | * @return void |
||
630 | */ |
||
631 | public function txn_details_meta_box() { |
||
632 | |||
633 | $this->_set_transaction_object(); |
||
634 | $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
||
635 | $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null; |
||
636 | |||
637 | //get line table |
||
638 | EEH_Autoloader::register_line_item_display_autoloaders(); |
||
639 | $Line_Item_Display = new EE_Line_Item_Display( 'admin_table', 'EE_Admin_Table_Line_Item_Display_Strategy' ); |
||
640 | $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( $this->_transaction->total_line_item() ); |
||
641 | $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')->get('REG_code'); |
||
642 | |||
643 | // process taxes |
||
644 | $taxes = $this->_transaction->get_many_related( 'Line_Item', array( array( 'LIN_type' => EEM_Line_Item::type_tax ))); |
||
645 | $this->_template_args['taxes'] = ! empty( $taxes ) ? $taxes : FALSE; |
||
646 | |||
647 | $this->_template_args['grand_total'] = EEH_Template::format_currency($this->_transaction->get('TXN_total'), FALSE, FALSE ); |
||
648 | $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
||
649 | $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
||
650 | |||
651 | // $txn_status_class = 'status-' . $this->_transaction->get('STS_ID'); |
||
652 | |||
653 | // process payment details |
||
654 | $payments = $this->_transaction->get_many_related('Payment'); |
||
655 | if( ! empty( $payments ) ) { |
||
656 | $this->_template_args[ 'payments' ] = $payments; |
||
657 | $this->_template_args[ 'existing_reg_payments' ] = $this->_get_registration_payment_IDs( $payments ); |
||
658 | } else { |
||
659 | $this->_template_args[ 'payments' ] = false; |
||
660 | $this->_template_args[ 'existing_reg_payments' ] = array(); |
||
661 | } |
||
662 | |||
663 | $this->_template_args['edit_payment_url'] = add_query_arg( array( 'action' => 'edit_payment' ), TXN_ADMIN_URL ); |
||
664 | $this->_template_args['delete_payment_url'] = add_query_arg( array( 'action' => 'espresso_delete_payment' ), TXN_ADMIN_URL ); |
||
665 | |||
666 | if ( isset( $txn_details['invoice_number'] )) { |
||
667 | $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
||
668 | $this->_template_args['txn_details']['invoice_number']['label'] = __( 'Invoice Number', 'event_espresso' ); |
||
669 | } |
||
670 | |||
671 | $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); |
||
672 | $this->_template_args['txn_details']['registration_session']['label'] = __( 'Registration Session', 'event_espresso' ); |
||
673 | |||
674 | $this->_template_args['txn_details']['ip_address']['value'] = isset( $this->_session['ip_address'] ) ? $this->_session['ip_address'] : ''; |
||
675 | $this->_template_args['txn_details']['ip_address']['label'] = __( 'Transaction placed from IP', 'event_espresso' ); |
||
676 | |||
677 | $this->_template_args['txn_details']['user_agent']['value'] = isset( $this->_session['user_agent'] ) ? $this->_session['user_agent'] : ''; |
||
678 | $this->_template_args['txn_details']['user_agent']['label'] = __( 'Registrant User Agent', 'event_espresso' ); |
||
679 | |||
680 | $reg_steps = '<ul>'; |
||
681 | foreach ( $this->_transaction->reg_steps() as $reg_step => $reg_step_status ) { |
||
682 | if ( $reg_step_status === true ) { |
||
683 | $reg_steps .= '<li style="color:#70cc50">' . sprintf( __( '%1$s : Completed', 'event_espresso' ), ucwords( str_replace( '_', ' ', $reg_step ) ) ) . '</li>'; |
||
684 | } else if ( is_numeric( $reg_step_status ) && $reg_step_status !== false ) { |
||
685 | $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
||
686 | __( '%1$s : Initiated %2$s', 'event_espresso' ), |
||
687 | ucwords( str_replace( '_', ' ', $reg_step ) ), |
||
688 | gmdate( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), ( $reg_step_status + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) ) |
||
689 | ) . '</li>'; |
||
690 | } else { |
||
691 | $reg_steps .= '<li style="color:#E76700">' . sprintf( __( '%1$s : Never Initiated', 'event_espresso' ), ucwords( str_replace( '_', ' ', $reg_step ) ) ) . '</li>'; |
||
692 | } |
||
693 | } |
||
694 | $reg_steps .= '</ul>'; |
||
695 | $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
||
696 | $this->_template_args['txn_details']['reg_steps']['label'] = __( 'Registration Step Progress', 'event_espresso' ); |
||
697 | |||
698 | |||
699 | $this->_get_registrations_to_apply_payment_to(); |
||
700 | $this->_get_payment_methods( $payments ); |
||
701 | $this->_get_payment_status_array(); |
||
702 | $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
||
703 | |||
704 | $this->_template_args['transaction_form_url'] = add_query_arg( array( 'action' => 'edit_transaction', 'process' => 'transaction' ), TXN_ADMIN_URL ); |
||
705 | $this->_template_args['apply_payment_form_url'] = add_query_arg( array( 'page' => 'espresso_transactions', 'action' => 'espresso_apply_payment' ), WP_AJAX_URL ); |
||
706 | $this->_template_args['delete_payment_form_url'] = add_query_arg( array( 'page' => 'espresso_transactions', 'action' => 'espresso_delete_payment' ), WP_AJAX_URL ); |
||
707 | |||
708 | // 'espresso_delete_payment_nonce' |
||
709 | |||
710 | $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
||
711 | echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE ); |
||
712 | |||
713 | } |
||
714 | |||
715 | |||
716 | |||
717 | /** |
||
718 | * _get_registration_payment_IDs |
||
719 | * |
||
720 | * generates an array of Payment IDs and their corresponding Registration IDs |
||
721 | * |
||
722 | * @access protected |
||
723 | * @param EE_Payment[] $payments |
||
724 | * @return array |
||
725 | */ |
||
726 | protected function _get_registration_payment_IDs( $payments = array() ) { |
||
727 | $existing_reg_payments = array(); |
||
728 | // get all reg payments for these payments |
||
729 | $reg_payments = EEM_Registration_Payment::instance()->get_all( array( |
||
730 | array( |
||
731 | 'PAY_ID' => array( |
||
732 | 'IN', |
||
733 | array_keys( $payments ) |
||
734 | ) |
||
735 | ) |
||
736 | ) ); |
||
737 | if ( ! empty( $reg_payments ) ) { |
||
738 | foreach ( $payments as $payment ) { |
||
739 | if ( ! $payment instanceof EE_Payment ) { |
||
740 | continue; |
||
741 | } else if ( ! isset( $existing_reg_payments[ $payment->ID() ] ) ) { |
||
742 | $existing_reg_payments[ $payment->ID() ] = array(); |
||
743 | } |
||
744 | foreach ( $reg_payments as $reg_payment ) { |
||
745 | if ( $reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID() ) { |
||
746 | $existing_reg_payments[ $payment->ID() ][ ] = $reg_payment->registration_ID(); |
||
747 | } |
||
748 | } |
||
749 | } |
||
750 | } |
||
751 | return $existing_reg_payments; |
||
752 | } |
||
753 | |||
754 | |||
755 | |||
756 | /** |
||
757 | * _get_registrations_to_apply_payment_to |
||
758 | * |
||
759 | * generates HTML for displaying a series of checkboxes in the admin payment modal window |
||
760 | * which allows the admin to only apply the payment to the specific registrations |
||
761 | * |
||
762 | * @access protected |
||
763 | * @return void |
||
764 | */ |
||
765 | protected function _get_registrations_to_apply_payment_to() { |
||
766 | // we want any registration with an active status (ie: not deleted or cancelled) |
||
767 | $query_params = array( |
||
768 | array( |
||
769 | 'STS_ID' => array( |
||
770 | 'IN', |
||
771 | array( |
||
772 | EEM_Registration::status_id_approved, |
||
773 | EEM_Registration::status_id_pending_payment, |
||
774 | EEM_Registration::status_id_not_approved, |
||
775 | ) |
||
776 | ) |
||
777 | ) |
||
778 | ); |
||
779 | $registrations_to_apply_payment_to = '<br /><div id="txn-admin-apply-payment-to-registrations-dv" style="clear: both; margin: 1.5em 0 0; display: none;">'; |
||
780 | $registrations_to_apply_payment_to .= '<br /><div class="admin-primary-mbox-tbl-wrap">'; |
||
781 | $registrations_to_apply_payment_to .= '<table class="admin-primary-mbox-tbl">'; |
||
782 | $registrations_to_apply_payment_to .= '<thead><tr>'; |
||
783 | $registrations_to_apply_payment_to .= '<td>' . __( 'ID', 'event_espresso' ) . '</td>'; |
||
784 | $registrations_to_apply_payment_to .= '<td>' . __( 'Registrant', 'event_espresso' ) . '</td>'; |
||
785 | $registrations_to_apply_payment_to .= '<td>' . __( 'Ticket', 'event_espresso' ) . '</td>'; |
||
786 | $registrations_to_apply_payment_to .= '<td>' . __( 'Event', 'event_espresso' ) . '</td>'; |
||
787 | $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-paid-td jst-cntr">' . __( 'Paid', 'event_espresso' ) . '</td>'; |
||
788 | $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-owing-td jst-cntr">' . __( 'Owing', 'event_espresso' ) . '</td>'; |
||
789 | $registrations_to_apply_payment_to .= '<td class="jst-cntr">' . __( 'Apply', 'event_espresso' ) . '</td>'; |
||
790 | $registrations_to_apply_payment_to .= '</tr></thead><tbody>'; |
||
791 | // get registrations for TXN |
||
792 | $registrations = $this->_transaction->registrations( $query_params ); |
||
793 | foreach ( $registrations as $registration ) { |
||
794 | if ( $registration instanceof EE_Registration ) { |
||
795 | $owing = $registration->final_price() - $registration->paid(); |
||
796 | $taxable = $registration->ticket()->taxable() ? ' <span class="smaller-text lt-grey-text"> ' . __( '+ tax', 'event_espresso' ) . '</span>' : ''; |
||
797 | $checked = empty( $existing_reg_payments ) || in_array( $registration->ID(), $existing_reg_payments ) ? ' checked="checked"' : ''; |
||
798 | $registrations_to_apply_payment_to .= '<tr id="apply-payment-registration-row-' . $registration->ID() . '">'; |
||
799 | // add html for checkbox input and label |
||
800 | $registrations_to_apply_payment_to .= '<td>' . $registration->ID() . '</td>'; |
||
801 | $registrations_to_apply_payment_to .= '<td>' . $registration->attendee() instanceof EE_Attendee ? $registration->attendee()->full_name() : __( 'Unknown Attendee', 'event_espresso' ) . '</td>'; |
||
802 | $registrations_to_apply_payment_to .= '<td>' . $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable . '</td>'; |
||
803 | $registrations_to_apply_payment_to .= '<td>' . $registration->event_name() . '</td>'; |
||
804 | $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-paid-td jst-rght">' . $registration->pretty_paid() . '</td>'; |
||
805 | $registrations_to_apply_payment_to .= '<td class="txn-admin-payment-owing-td jst-rght">' . EEH_Template::format_currency( $owing ) . '</td>'; |
||
806 | $registrations_to_apply_payment_to .= '<td class="jst-cntr">'; |
||
807 | $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
||
808 | $registrations_to_apply_payment_to .= '<input type="checkbox" value="' . $registration->ID() . '" name="txn_admin_payment[registrations]"' . $checked . $disabled . '>'; |
||
809 | $registrations_to_apply_payment_to .= '</td>'; |
||
810 | $registrations_to_apply_payment_to .= '</tr>'; |
||
811 | } |
||
812 | } |
||
813 | $registrations_to_apply_payment_to .= '</tbody></table></div>'; |
||
814 | $registrations_to_apply_payment_to .= '<p class="clear description">' . __( '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.', 'event_espresso' ) . '</p></div>'; |
||
815 | $this->_template_args[ 'registrations_to_apply_payment_to' ] = $registrations_to_apply_payment_to; |
||
816 | } |
||
817 | |||
818 | |||
819 | |||
820 | /** |
||
821 | * _get_reg_status_selection |
||
822 | * |
||
823 | * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets instead of events. |
||
824 | * @access protected |
||
825 | * @return void |
||
826 | */ |
||
827 | protected function _get_reg_status_selection() { |
||
828 | //first get all possible statuses |
||
829 | $statuses = EEM_Registration::reg_status_array(array(), TRUE); |
||
830 | //let's add a "don't change" option. |
||
831 | $status_array['NAN'] = __('Leave the Same', 'event_espresso'); |
||
832 | $status_array = array_merge( $status_array, $statuses ); |
||
833 | $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( 'txn_reg_status_change[reg_status]', $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status' ); |
||
834 | $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( 'delete_txn_reg_status_change[reg_status]', $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status' ); |
||
835 | |||
836 | } |
||
837 | |||
838 | |||
839 | |||
840 | /** |
||
841 | * _get_payment_methods |
||
842 | * Gets all the payment methods available generally, or the ones that are already |
||
843 | * selected on these payments (in case their payment methods are no longer active). |
||
844 | * Has the side-effect of updating the template args' payment_methods item |
||
845 | * @access private |
||
846 | * @param EE_Payment[] to show on this page |
||
847 | * @return void |
||
848 | */ |
||
849 | private function _get_payment_methods( $payments = array() ) { |
||
865 | |||
866 | |||
867 | |||
868 | /** |
||
869 | * txn_attendees_meta_box |
||
870 | * generates HTML for the Attendees Transaction main meta box |
||
871 | * |
||
872 | * @access public |
||
873 | * @param WP_Post $post |
||
874 | * @param array $metabox |
||
875 | * @return void |
||
876 | */ |
||
877 | public function txn_attendees_meta_box( $post, $metabox = array( 'args' => array() )) { |
||
878 | |||
879 | extract( $metabox['args'] ); |
||
880 | $this->_template_args['post'] = $post; |
||
881 | $this->_template_args['event_attendees'] = array(); |
||
882 | // process items in cart |
||
883 | $line_items = $this->_transaction->get_many_related('Line_Item', array( array( 'LIN_type' => 'line-item' ) ) ); |
||
884 | if ( ! empty( $line_items )) { |
||
885 | foreach ( $line_items as $item ) { |
||
886 | if ( $item instanceof EE_Line_Item ) { |
||
887 | switch( $item->OBJ_type() ) { |
||
888 | |||
889 | case 'Event' : |
||
890 | break; |
||
891 | |||
892 | case 'Ticket' : |
||
893 | $ticket = $item->ticket(); |
||
894 | if ( empty( $ticket )) { |
||
895 | continue; //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? |
||
896 | } |
||
897 | $ticket_price = EEH_Template::format_currency( $item->get( 'LIN_unit_price' )); |
||
898 | $event = $ticket->get_first_related('Registration')->get_first_related('Event'); |
||
899 | $event_name = $event instanceof EE_Event ? $event->get('EVT_name') . ' - ' . $item->get('LIN_name') : ''; |
||
900 | |||
901 | $registrations = $ticket->get_many_related('Registration', array( array('TXN_ID' => $this->_transaction->ID() ))); |
||
902 | foreach( $registrations as $registration ) { |
||
903 | $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->get('REG_count'); |
||
904 | $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; |
||
905 | $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; |
||
906 | // attendee info |
||
907 | $attendee = $registration->get_first_related('Attendee'); |
||
908 | if ( $attendee instanceof EE_Attendee ) { |
||
909 | $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
||
910 | $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
||
911 | $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event->get('EVT_name') . __(' Event', 'event_espresso') . '">' . $attendee->email() . '</a>'; |
||
912 | $this->_template_args['event_attendees'][$registration->ID()]['address'] = implode(',<br>', $attendee->full_address_as_array() ); |
||
913 | } else { |
||
914 | $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
||
915 | $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
||
916 | $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
||
917 | $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
||
918 | } |
||
919 | } |
||
920 | break; |
||
921 | |||
922 | } |
||
923 | } |
||
924 | } |
||
925 | |||
926 | $this->_template_args['transaction_form_url'] = add_query_arg( array( 'action' => 'edit_transaction', 'process' => 'attendees' ), TXN_ADMIN_URL ); |
||
927 | echo EEH_Template::display_template( TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', $this->_template_args, TRUE ); |
||
928 | |||
929 | } else { |
||
930 | echo sprintf( |
||
931 | __( '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', 'event_espresso' ), |
||
932 | '<p class="important-notice">', |
||
933 | '</p>' |
||
934 | ); |
||
935 | } |
||
936 | } |
||
937 | |||
938 | |||
939 | |||
940 | /** |
||
941 | * txn_registrant_side_meta_box |
||
942 | * generates HTML for the Edit Transaction side meta box |
||
943 | * |
||
944 | * @access public |
||
945 | * @throws \EE_Error |
||
946 | * @return void |
||
947 | */ |
||
948 | public function txn_registrant_side_meta_box() { |
||
949 | $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; |
||
950 | if ( ! $primary_att instanceof EE_Attendee ) { |
||
951 | $this->_template_args['no_attendee_message'] = __('There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', 'event_espresso'); |
||
952 | $primary_att = EEM_Attendee::instance()->create_default_object(); |
||
953 | } |
||
954 | $this->_template_args['ATT_ID'] = $primary_att->ID(); |
||
955 | $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
||
956 | $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
||
957 | $this->_template_args['prime_reg_email'] = $primary_att->email(); |
||
958 | $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
||
959 | $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'edit_attendee', 'post' => $primary_att->ID() ), REG_ADMIN_URL ); |
||
960 | // get formatted address for registrant |
||
961 | EE_Registry::instance()->load_helper( 'Formatter' ); |
||
962 | $this->_template_args[ 'formatted_address' ] = EEH_Address::format( $primary_att ); |
||
963 | echo EEH_Template::display_template( TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', $this->_template_args, TRUE ); |
||
964 | } |
||
965 | |||
966 | |||
967 | |||
968 | /** |
||
969 | * txn_billing_info_side_meta_box |
||
970 | * generates HTML for the Edit Transaction side meta box |
||
971 | * |
||
972 | * @access public |
||
973 | * @return void |
||
974 | */ |
||
975 | public function txn_billing_info_side_meta_box() { |
||
976 | |||
977 | $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
||
978 | $this->_template_args['billing_form_url'] = add_query_arg( |
||
979 | array( 'action' => 'edit_transaction', 'process' => 'billing' ), |
||
980 | TXN_ADMIN_URL |
||
981 | ); |
||
982 | |||
983 | $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
||
984 | echo EEH_Template::display_template( $template_path, $this->_template_args, TRUE );/**/ |
||
985 | } |
||
986 | |||
987 | |||
988 | |||
989 | /** |
||
990 | * apply_payments_or_refunds |
||
991 | * registers a payment or refund made towards a transaction |
||
992 | * |
||
993 | * @access public |
||
994 | * @return void |
||
995 | */ |
||
996 | public function apply_payments_or_refunds() { |
||
997 | $json_response_data = array( 'return_data' => FALSE ); |
||
998 | $valid_data = $this->_validate_payment_request_data(); |
||
999 | if ( ! empty( $valid_data ) ) { |
||
1000 | $PAY_ID = $valid_data[ 'PAY_ID' ]; |
||
1001 | //save the new payment |
||
1002 | $payment = $this->_create_payment_from_request_data( $valid_data ); |
||
1003 | // get the TXN for this payment |
||
1004 | $transaction = $payment->transaction(); |
||
1005 | // verify transaction |
||
1006 | if ( $transaction instanceof EE_Transaction ) { |
||
1007 | // calculate_total_payments_and_update_status |
||
1008 | $this->_process_transaction_payments( $transaction ); |
||
1009 | $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to( $payment ); |
||
1010 | $this->_remove_existing_registration_payments( $payment, $PAY_ID ); |
||
1011 | // apply payment to registrations (if applicable) |
||
1012 | if ( ! empty( $REG_IDs ) ) { |
||
1013 | $this->_update_registration_payments( $transaction, $payment, $REG_IDs ); |
||
1014 | $this->_maybe_send_notifications(); |
||
1015 | // now process status changes for the same registrations |
||
1016 | $this->_process_registration_status_change( $transaction, $REG_IDs ); |
||
1017 | } |
||
1018 | $this->_maybe_send_notifications( $payment ); |
||
1019 | //prepare to render page |
||
1020 | $json_response_data[ 'return_data' ] = $this->_build_payment_json_response( $payment, $REG_IDs ); |
||
1021 | do_action( 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, $payment ); |
||
1022 | } else { |
||
1023 | EE_Error::add_error( |
||
1024 | __( 'A valid Transaction for this payment could not be retrieved.', 'event_espresso' ), |
||
1025 | __FILE__, __FUNCTION__, __LINE__ |
||
1026 | ); |
||
1027 | } |
||
1028 | } else { |
||
1029 | EE_Error::add_error( __( 'The payment form data could not be processed. Please try again.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
||
1030 | } |
||
1031 | |||
1032 | $notices = EE_Error::get_notices( FALSE, FALSE, FALSE ); |
||
1033 | echo json_encode( array_merge( $json_response_data, $notices )); |
||
1034 | die(); |
||
1035 | } |
||
1036 | |||
1037 | |||
1038 | |||
1039 | /** |
||
1040 | * _validate_payment_request_data |
||
1041 | * |
||
1042 | * @return array |
||
1043 | */ |
||
1044 | protected function _validate_payment_request_data() { |
||
1045 | if ( ! isset( $this->_req_data[ 'txn_admin_payment' ] ) ) { |
||
1046 | return false; |
||
1047 | } |
||
1048 | $payment_form = $this->_generate_payment_form_section(); |
||
1049 | try { |
||
1050 | if ( $payment_form->was_submitted() ) { |
||
1051 | $payment_form->receive_form_submission(); |
||
1052 | if ( ! $payment_form->is_valid() ) { |
||
1053 | $submission_error_messages = array(); |
||
1054 | foreach ( $payment_form->get_validation_errors_accumulated() as $validation_error ) { |
||
1055 | View Code Duplication | if ( $validation_error instanceof EE_Validation_Error ) { |
|
1056 | $submission_error_messages[] = sprintf( |
||
1057 | _x( '%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso' ), |
||
1058 | $validation_error->get_form_section()->html_label_text(), |
||
1059 | $validation_error->getMessage() |
||
1060 | ); |
||
1061 | } |
||
1062 | } |
||
1063 | EE_Error::add_error( join( '<br />', $submission_error_messages ), __FILE__, __FUNCTION__, __LINE__ ); |
||
1064 | return array(); |
||
1065 | } |
||
1066 | } |
||
1067 | } catch ( EE_Error $e ) { |
||
1068 | EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__ ); |
||
1069 | return array(); |
||
1070 | } |
||
1071 | return $payment_form->valid_data(); |
||
1072 | } |
||
1073 | |||
1074 | |||
1075 | |||
1076 | /** |
||
1077 | * _generate_payment_form_section |
||
1078 | * |
||
1079 | * @return EE_Form_Section_Proper |
||
1080 | */ |
||
1081 | protected function _generate_payment_form_section() { |
||
1082 | return new EE_Form_Section_Proper( |
||
1083 | array( |
||
1084 | 'name' => 'txn_admin_payment', |
||
1085 | 'subsections' => array( |
||
1086 | 'PAY_ID' => new EE_Text_Input( |
||
1087 | array( |
||
1088 | 'default' => 0, |
||
1089 | 'required' => false, |
||
1090 | 'html_label_text' => __( 'Payment ID', 'event_espresso' ), |
||
1091 | 'validation_strategies' => array( new EE_Int_Normalization() ) |
||
1092 | ) |
||
1093 | ), |
||
1094 | 'TXN_ID' => new EE_Text_Input( |
||
1095 | array( |
||
1096 | 'default' => 0, |
||
1097 | 'required' => true, |
||
1098 | 'html_label_text' => __( 'Transaction ID', 'event_espresso' ), |
||
1099 | 'validation_strategies' => array( new EE_Int_Normalization() ) |
||
1100 | ) |
||
1101 | ), |
||
1102 | 'type' => new EE_Text_Input( |
||
1103 | array( |
||
1104 | 'default' => 1, |
||
1105 | 'required' => true, |
||
1106 | 'html_label_text' => __( 'Payment or Refund', 'event_espresso' ), |
||
1107 | 'validation_strategies' => array( new EE_Int_Normalization() ) |
||
1108 | ) |
||
1109 | ), |
||
1110 | 'amount' => new EE_Text_Input( |
||
1111 | array( |
||
1112 | 'default' => 0, |
||
1113 | 'required' => true, |
||
1114 | 'html_label_text' => __( 'Payment amount', 'event_espresso' ), |
||
1115 | 'validation_strategies' => array( new EE_Float_Normalization() ) |
||
1116 | ) |
||
1117 | ), |
||
1118 | 'status' => new EE_Text_Input( |
||
1119 | array( |
||
1120 | 'default' => EEM_Payment::status_id_approved, |
||
1121 | 'required' => true, |
||
1122 | 'html_label_text' => __( 'Payment status', 'event_espresso' ), |
||
1123 | ) |
||
1124 | ), |
||
1125 | 'PMD_ID' => new EE_Text_Input( |
||
1126 | array( |
||
1127 | 'default' => 2, |
||
1128 | 'required' => true, |
||
1129 | 'html_label_text' => __( 'Payment Method', 'event_espresso' ), |
||
1130 | 'validation_strategies' => array( new EE_Int_Normalization() ) |
||
1131 | ) |
||
1132 | ), |
||
1133 | 'date' => new EE_Text_Input( |
||
1134 | array( |
||
1135 | 'default' => time(), |
||
1136 | 'required' => true, |
||
1137 | 'html_label_text' => __( 'Payment date', 'event_espresso' ), |
||
1138 | ) |
||
1139 | ), |
||
1140 | 'txn_id_chq_nmbr' => new EE_Text_Input( |
||
1141 | array( |
||
1142 | 'default' => '', |
||
1143 | 'required' => false, |
||
1144 | 'html_label_text' => __( 'Transaction or Cheque Number', 'event_espresso' ), |
||
1145 | 'validation_strategies' => array( |
||
1146 | new EE_Max_Length_Validation_Strategy( __('Input too long', 'event_espresso'), 100 ), |
||
1147 | ) |
||
1148 | ) |
||
1149 | ), |
||
1150 | 'po_number' => new EE_Text_Input( |
||
1151 | array( |
||
1152 | 'default' => '', |
||
1153 | 'required' => false, |
||
1154 | 'html_label_text' => __( 'Purchase Order Number', 'event_espresso' ), |
||
1155 | 'validation_strategies' => array( |
||
1156 | new EE_Max_Length_Validation_Strategy( __('Input too long', 'event_espresso'), 100 ), |
||
1157 | ) |
||
1158 | ) |
||
1159 | ), |
||
1160 | 'accounting' => new EE_Text_Input( |
||
1161 | array( |
||
1162 | 'default' => '', |
||
1163 | 'required' => false, |
||
1164 | 'html_label_text' => __( 'Extra Field for Accounting', 'event_espresso' ), |
||
1165 | 'validation_strategies' => array( |
||
1166 | new EE_Max_Length_Validation_Strategy( __('Input too long', 'event_espresso'), 100 ), |
||
1167 | ) |
||
1168 | ) |
||
1169 | ), |
||
1170 | ) |
||
1171 | ) |
||
1172 | ); |
||
1173 | } |
||
1174 | |||
1175 | |||
1176 | |||
1177 | /** |
||
1178 | * _create_payment_from_request_data |
||
1179 | * |
||
1180 | * @param array $valid_data |
||
1181 | * @return EE_Payment |
||
1182 | */ |
||
1183 | protected function _create_payment_from_request_data( $valid_data ) { |
||
1184 | $PAY_ID = $valid_data[ 'PAY_ID' ]; |
||
1185 | // get payment amount |
||
1186 | $amount = $valid_data[ 'amount' ] ? abs( $valid_data[ 'amount' ] ) : 0; |
||
1187 | // payments have a type value of 1 and refunds have a type value of -1 |
||
1188 | // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
||
1189 | $amount = $valid_data[ 'type' ] < 0 ? $amount * -1 : $amount; |
||
1190 | $payment = EE_Payment::new_instance( |
||
1191 | array( |
||
1192 | 'TXN_ID' => $valid_data[ 'TXN_ID' ], |
||
1193 | 'STS_ID' => $valid_data[ 'status' ], |
||
1194 | 'PAY_timestamp' => $valid_data[ 'date' ], |
||
1195 | 'PAY_source' => EEM_Payment_Method::scope_admin, |
||
1196 | 'PMD_ID' => $valid_data[ 'PMD_ID' ], |
||
1197 | 'PAY_amount' => $amount, |
||
1198 | 'PAY_txn_id_chq_nmbr' => $valid_data[ 'txn_id_chq_nmbr' ], |
||
1199 | 'PAY_po_number' => $valid_data[ 'po_number' ], |
||
1200 | 'PAY_extra_accntng' => $valid_data[ 'accounting' ], |
||
1201 | 'PAY_details' => $valid_data, |
||
1202 | 'PAY_ID' => $PAY_ID |
||
1203 | ), |
||
1204 | '', |
||
1205 | array( 'Y-m-d', 'H:i a' ) |
||
1206 | ); |
||
1207 | if ( ! $payment->save() ) { |
||
1208 | EE_Error::add_error( |
||
1209 | sprintf( |
||
1210 | __( 'Payment %1$d has not been successfully saved to the database.', 'event_espresso' ), |
||
1211 | $payment->ID() |
||
1212 | ), |
||
1213 | __FILE__, __FUNCTION__, __LINE__ |
||
1214 | ); |
||
1215 | } |
||
1216 | return $payment; |
||
1217 | } |
||
1218 | |||
1219 | |||
1220 | |||
1221 | /** |
||
1222 | * _process_transaction_payments |
||
1223 | * |
||
1224 | * @param \EE_Transaction $transaction |
||
1225 | * @return array |
||
1226 | */ |
||
1227 | protected function _process_transaction_payments( EE_Transaction $transaction ) { |
||
1228 | /** @type EE_Transaction_Payments $transaction_payments */ |
||
1229 | $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
||
1230 | //update the transaction with this payment |
||
1231 | if ( $transaction_payments->calculate_total_payments_and_update_status( $transaction ) ) { |
||
1232 | EE_Error::add_success( __( 'The payment has been processed successfully.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
||
1233 | } else { |
||
1234 | EE_Error::add_error( |
||
1235 | __( 'The payment was processed successfully but the amount paid for the transaction was not updated.', 'event_espresso' ) |
||
1236 | , __FILE__, __FUNCTION__, __LINE__ |
||
1237 | ); |
||
1238 | } |
||
1239 | } |
||
1240 | |||
1241 | |||
1242 | |||
1243 | /** |
||
1244 | * _get_REG_IDs_to_apply_payment_to |
||
1245 | * |
||
1246 | * returns a list of registration IDs that the payment will apply to |
||
1247 | * |
||
1248 | * @param \EE_Payment $payment |
||
1249 | * @return array |
||
1250 | */ |
||
1251 | protected function _get_REG_IDs_to_apply_payment_to( EE_Payment $payment ) { |
||
1265 | |||
1266 | |||
1267 | |||
1268 | /** |
||
1269 | * @return array |
||
1270 | */ |
||
1271 | public function existing_reg_payment_REG_IDs() { |
||
1274 | |||
1275 | |||
1276 | |||
1277 | /** |
||
1278 | * @param array $existing_reg_payment_REG_IDs |
||
1279 | */ |
||
1280 | public function set_existing_reg_payment_REG_IDs( $existing_reg_payment_REG_IDs = null ) { |
||
1283 | |||
1284 | |||
1285 | |||
1286 | /** |
||
1287 | * _get_existing_reg_payment_REG_IDs |
||
1288 | * |
||
1289 | * returns a list of registration IDs that the payment is currently related to |
||
1290 | * as recorded in the database |
||
1291 | * |
||
1292 | * @param \EE_Payment $payment |
||
1293 | * @return array |
||
1294 | */ |
||
1295 | protected function _get_existing_reg_payment_REG_IDs( EE_Payment $payment ) { |
||
1296 | if ( $this->existing_reg_payment_REG_IDs() === null ) { |
||
1297 | // let's get any existing reg payment records for this payment |
||
1298 | $existing_reg_payment_REG_IDs = $payment->get_many_related( 'Registration' ); |
||
1299 | // but we only want the REG IDs, so grab the array keys |
||
1300 | $existing_reg_payment_REG_IDs = ! empty( $existing_reg_payment_REG_IDs ) ? array_keys( $existing_reg_payment_REG_IDs ) : array(); |
||
1301 | $this->set_existing_reg_payment_REG_IDs( $existing_reg_payment_REG_IDs ); |
||
1302 | } |
||
1303 | return $this->existing_reg_payment_REG_IDs(); |
||
1304 | } |
||
1305 | |||
1306 | |||
1307 | |||
1308 | /** |
||
1309 | * _remove_existing_registration_payments |
||
1310 | * |
||
1311 | * this calculates the difference between existing relations |
||
1312 | * to the supplied payment and the new list registration IDs, |
||
1313 | * removes any related registrations that no longer apply, |
||
1314 | * and then updates the registration paid fields |
||
1315 | * |
||
1316 | * @param \EE_Payment $payment |
||
1317 | * @param int $PAY_ID |
||
1318 | * @return bool; |
||
1319 | */ |
||
1320 | protected function _remove_existing_registration_payments( EE_Payment $payment, $PAY_ID = 0 ) { |
||
1321 | // newly created payments will have nothing recorded for $PAY_ID |
||
1322 | if ( $PAY_ID == 0 ) { |
||
1323 | return false; |
||
1324 | } |
||
1325 | $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs( $payment ); |
||
1326 | if ( empty( $existing_reg_payment_REG_IDs )) { |
||
1327 | return false; |
||
1328 | } |
||
1329 | /** @type EE_Transaction_Payments $transaction_payments */ |
||
1330 | $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
||
1331 | return $transaction_payments->delete_registration_payments_and_update_registrations( |
||
1332 | $payment, |
||
1333 | array( |
||
1334 | array( |
||
1335 | 'PAY_ID' => $payment->ID(), |
||
1336 | 'REG_ID' => array( 'IN', $existing_reg_payment_REG_IDs ), |
||
1337 | ) |
||
1338 | ) |
||
1339 | ); |
||
1340 | } |
||
1341 | |||
1342 | |||
1343 | |||
1344 | /** |
||
1345 | * _update_registration_payments |
||
1346 | * |
||
1347 | * this applies the payments to the selected registrations |
||
1348 | * but only if they have not already been paid for |
||
1349 | * |
||
1350 | * @param EE_Transaction $transaction |
||
1351 | * @param \EE_Payment $payment |
||
1352 | * @param array $REG_IDs |
||
1353 | * @return bool |
||
1354 | */ |
||
1355 | protected function _update_registration_payments( EE_Transaction $transaction, EE_Payment $payment, $REG_IDs = array() ) { |
||
1356 | // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
||
1357 | // so let's do that using our set of REG_IDs from the form |
||
1358 | $registration_query_where_params = array( |
||
1359 | 'REG_ID' => array( 'IN', $REG_IDs ) |
||
1360 | ); |
||
1361 | // but add in some conditions regarding payment, |
||
1362 | // so that we don't apply payments to registrations that are free or have already been paid for |
||
1363 | // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
||
1364 | if ( ! $payment->is_a_refund() ) { |
||
1365 | $registration_query_where_params[ 'REG_final_price' ] = array( '!=', 0 ); |
||
1366 | $registration_query_where_params[ 'REG_final_price*' ] = array( '!=', 'REG_paid', true ); |
||
1367 | } |
||
1368 | //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); |
||
1369 | $registrations = $transaction->registrations( array( $registration_query_where_params ) ); |
||
1370 | if ( ! empty( $registrations ) ) { |
||
1371 | /** @type EE_Payment_Processor $payment_processor */ |
||
1372 | $payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' ); |
||
1373 | $payment_processor->process_registration_payments( $transaction, $payment, $registrations ); |
||
1374 | } |
||
1375 | } |
||
1376 | |||
1377 | |||
1378 | |||
1379 | /** |
||
1380 | * _process_registration_status_change |
||
1381 | * |
||
1382 | * This processes requested registration status changes for all the registrations |
||
1383 | * on a given transaction and (optionally) sends out notifications for the changes. |
||
1384 | * |
||
1385 | * @param EE_Transaction $transaction |
||
1386 | * @param array $REG_IDs |
||
1387 | * @return bool |
||
1388 | */ |
||
1389 | protected function _process_registration_status_change( EE_Transaction $transaction, $REG_IDs = array() ) { |
||
1390 | // first if there is no change in status then we get out. |
||
1391 | if ( |
||
1392 | ! isset( $this->_req_data['txn_reg_status_change'], $this->_req_data[ 'txn_reg_status_change' ][ 'reg_status' ] ) |
||
1393 | || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' |
||
1394 | ) { |
||
1395 | //no error message, no change requested, just nothing to do man. |
||
1396 | return FALSE; |
||
1397 | } |
||
1398 | /** @type EE_Transaction_Processor $transaction_processor */ |
||
1399 | $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
||
1400 | // made it here dude? Oh WOW. K, let's take care of changing the statuses |
||
1401 | return $transaction_processor->manually_update_registration_statuses( |
||
1402 | $transaction, |
||
1403 | sanitize_text_field( $this->_req_data[ 'txn_reg_status_change' ][ 'reg_status' ] ), |
||
1404 | array( array( 'REG_ID' => array( 'IN', $REG_IDs ) ) ) |
||
1405 | ); |
||
1406 | } |
||
1407 | |||
1408 | |||
1409 | |||
1410 | /** |
||
1411 | * _build_payment_json_response |
||
1412 | * |
||
1413 | * @access public |
||
1414 | * @param \EE_Payment $payment |
||
1415 | * @param array $REG_IDs |
||
1416 | * @param bool | null $delete_txn_reg_status_change |
||
1417 | * @return array |
||
1418 | */ |
||
1419 | protected function _build_payment_json_response( EE_Payment $payment, $REG_IDs = array(), $delete_txn_reg_status_change = null ) { |
||
1420 | // was the payment deleted ? |
||
1421 | if ( is_bool( $delete_txn_reg_status_change )) { |
||
1422 | return array( |
||
1423 | 'PAY_ID' => $payment->ID(), |
||
1424 | 'amount' => $payment->amount(), |
||
1425 | 'total_paid' => $payment->transaction()->paid(), |
||
1426 | 'txn_status' => $payment->transaction()->status_ID(), |
||
1427 | 'pay_status' => $payment->STS_ID(), |
||
1428 | 'registrations' => $this->_registration_payment_data_array( $REG_IDs ), |
||
1429 | 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
||
1430 | ); |
||
1431 | } else { |
||
1432 | $this->_get_payment_status_array(); |
||
1433 | return array( |
||
1434 | 'amount' => $payment->amount(), |
||
1435 | 'total_paid' => $payment->transaction()->paid(), |
||
1436 | 'txn_status' => $payment->transaction()->status_ID(), |
||
1437 | 'pay_status' => $payment->STS_ID(), |
||
1438 | 'PAY_ID' => $payment->ID(), |
||
1439 | 'STS_ID' => $payment->STS_ID(), |
||
1440 | 'status' => self::$_pay_status[ $payment->STS_ID() ], |
||
1441 | 'date' => $payment->timestamp( 'Y-m-d', 'h:i a' ), |
||
1442 | 'method' => strtoupper( $payment->source() ), |
||
1443 | 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
||
1444 | 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : __( "Unknown", 'event_espresso' ), |
||
1445 | 'gateway_response' => $payment->gateway_response(), |
||
1446 | 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
||
1447 | 'po_number' => $payment->po_number(), |
||
1448 | 'extra_accntng' => $payment->extra_accntng(), |
||
1449 | 'registrations' => $this->_registration_payment_data_array( $REG_IDs ), |
||
1450 | ); |
||
1451 | } |
||
1452 | } |
||
1453 | |||
1454 | |||
1455 | |||
1456 | /** |
||
1457 | * delete_payment |
||
1458 | * delete a payment or refund made towards a transaction |
||
1459 | * |
||
1460 | * @access public |
||
1461 | * @return void |
||
1462 | */ |
||
1463 | public function delete_payment() { |
||
1464 | $json_response_data = array( 'return_data' => FALSE ); |
||
1465 | $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; |
||
1466 | if ( $PAY_ID ) { |
||
1467 | $delete_txn_reg_status_change = isset( $this->_req_data[ 'delete_txn_reg_status_change' ] ) ? $this->_req_data[ 'delete_txn_reg_status_change' ] : false; |
||
1468 | $payment = EEM_Payment::instance()->get_one_by_ID( $PAY_ID ); |
||
1469 | if ( $payment instanceof EE_Payment ) { |
||
1470 | $REG_IDs = $this->_get_existing_reg_payment_REG_IDs( $payment ); |
||
1471 | /** @type EE_Transaction_Payments $transaction_payments */ |
||
1472 | $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
||
1473 | if ( $transaction_payments->delete_payment_and_update_transaction( $payment )) { |
||
1474 | EE_Error::add_success( __( 'The Payment was successfully deleted.', 'event_espresso' ) ); |
||
1475 | $json_response_data['return_data'] = $this->_build_payment_json_response( $payment, $REG_IDs, $delete_txn_reg_status_change ); |
||
1476 | if ( $delete_txn_reg_status_change ) { |
||
1477 | $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
||
1478 | //MAKE sure we also add the delete_txn_req_status_change to the |
||
1479 | //$_REQUEST global because that's how messages will be looking for it. |
||
1480 | $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
||
1481 | $this->_maybe_send_notifications(); |
||
1482 | $this->_process_registration_status_change( $payment->transaction(), $REG_IDs ); |
||
1483 | //$this->_maybe_send_notifications( $payment ); |
||
1484 | } |
||
1485 | } |
||
1486 | } else { |
||
1487 | EE_Error::add_error( |
||
1488 | __( 'Valid Payment data could not be retrieved from the database.', 'event_espresso' ), |
||
1489 | __FILE__, __FUNCTION__, __LINE__ |
||
1490 | ); |
||
1491 | } |
||
1492 | } else { |
||
1493 | EE_Error::add_error( |
||
1494 | __( 'A valid Payment ID was not received, therefore payment form data could not be loaded.', 'event_espresso' ), |
||
1495 | __FILE__, __FUNCTION__, __LINE__ |
||
1496 | ); |
||
1497 | } |
||
1498 | $notices = EE_Error::get_notices( FALSE, FALSE, FALSE ); |
||
1499 | echo json_encode( array_merge( $json_response_data, $notices )); |
||
1500 | die(); |
||
1501 | } |
||
1502 | |||
1503 | |||
1504 | |||
1505 | /** |
||
1506 | * _registration_payment_data_array |
||
1507 | * adds info for 'owing' and 'paid' for each registration to the json response |
||
1508 | * |
||
1509 | * @access protected |
||
1510 | * @param array $REG_IDs |
||
1511 | * @return array |
||
1512 | */ |
||
1513 | protected function _registration_payment_data_array( $REG_IDs ) { |
||
1530 | |||
1531 | |||
1532 | |||
1533 | /** |
||
1534 | * _maybe_send_notifications |
||
1535 | * |
||
1536 | * determines whether or not the admin has indicated that notifications should be sent. |
||
1537 | * If so, will toggle a filter switch for delivering registration notices. |
||
1538 | * If passed an EE_Payment object, then it will trigger payment notifications instead. |
||
1539 | * |
||
1540 | * @access protected |
||
1541 | * @param \EE_Payment | null $payment |
||
1542 | */ |
||
1543 | protected function _maybe_send_notifications( $payment = null ) { |
||
1544 | switch ( $payment instanceof EE_Payment ) { |
||
1545 | // payment notifications |
||
1546 | View Code Duplication | case true : |
|
1547 | if ( |
||
1548 | isset( |
||
1549 | $this->_req_data[ 'txn_payments' ], |
||
1550 | $this->_req_data[ 'txn_payments' ][ 'send_notifications' ] |
||
1551 | ) && |
||
1552 | filter_var( $this->_req_data[ 'txn_payments' ][ 'send_notifications' ], FILTER_VALIDATE_BOOLEAN ) |
||
1553 | ) { |
||
1554 | $this->_process_payment_notification( $payment ); |
||
1555 | } |
||
1556 | break; |
||
1557 | // registration notifications |
||
1558 | View Code Duplication | case false : |
|
1559 | if ( |
||
1560 | isset( |
||
1561 | $this->_req_data[ 'txn_reg_status_change' ], |
||
1562 | $this->_req_data[ 'txn_reg_status_change' ][ 'send_notifications' ] |
||
1563 | ) && |
||
1564 | filter_var( $this->_req_data[ 'txn_reg_status_change' ][ 'send_notifications' ], FILTER_VALIDATE_BOOLEAN ) |
||
1565 | ) { |
||
1566 | add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true' ); |
||
1567 | } |
||
1568 | break; |
||
1569 | } |
||
1570 | } |
||
1571 | |||
1572 | |||
1573 | |||
1574 | /** |
||
1575 | * _send_payment_reminder |
||
1576 | * generates HTML for the View Transaction Details Admin page |
||
1577 | * |
||
1578 | * @access protected |
||
1579 | * @return void |
||
1580 | */ |
||
1581 | protected function _send_payment_reminder() { |
||
1582 | $TXN_ID = ( ! empty( $this->_req_data['TXN_ID'] )) ? absint( $this->_req_data['TXN_ID'] ) : FALSE; |
||
1583 | $transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
||
1584 | $query_args = isset($this->_req_data['redirect_to'] ) ? array('action' => $this->_req_data['redirect_to'], 'TXN_ID' => $this->_req_data['TXN_ID'] ) : array(); |
||
1585 | do_action( 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', $transaction ); |
||
1586 | $this->_redirect_after_action( FALSE, __('payment reminder', 'event_espresso'), __('sent', 'event_espresso'), $query_args, TRUE ); |
||
1587 | } |
||
1588 | |||
1589 | |||
1590 | |||
1591 | /** |
||
1592 | * get_transactions |
||
1593 | * get transactions for given parameters (used by list table) |
||
1594 | * |
||
1595 | * @param int $perpage how many transactions displayed per page |
||
1596 | * @param boolean $count return the count or objects |
||
1597 | * @param string $view |
||
1598 | * @return mixed int = count || array of transaction objects |
||
1599 | */ |
||
1600 | public function get_transactions( $perpage, $count = FALSE, $view = '' ) { |
||
1708 | |||
1709 | |||
1710 | |||
1711 | } |
||
1712 |
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.